From 8715b7b869a0786adb2a853770d23fa9352d9072 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Tue, 17 Sep 2019 14:31:40 +0200 Subject: [PATCH] Made Am2900 work again in ModelComponentTestbench --- .../model/am2900/machine/Am2900Machine.java | 30 ++++++++++++++----- .../machine/Am2900MachineDefinition.java | 21 +++++++------ .../examples/ModelComponentTestbench.java | 4 +-- .../net/mograsim/plugin/MachineContext.java | 4 +-- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900Machine.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900Machine.java index 0a0787cc..5683b8ea 100644 --- a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900Machine.java +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900Machine.java @@ -2,11 +2,13 @@ package net.mograsim.logic.model.am2900.machine; import net.mograsim.logic.core.components.CoreClock; import net.mograsim.logic.core.timeline.Timeline; +import net.mograsim.logic.core.types.Bit; import net.mograsim.logic.core.types.BitVector; import net.mograsim.logic.model.am2900.components.ModelAm2900MainMemory; import net.mograsim.logic.model.am2900.components.ModelAm2900MicroInstructionMemory; import net.mograsim.logic.model.model.LogicModel; import net.mograsim.logic.model.model.LogicModelModifiable; +import net.mograsim.logic.model.model.components.ModelComponent; import net.mograsim.logic.model.modeladapter.CoreModelParameters; import net.mograsim.logic.model.modeladapter.LogicCoreAdapter; import net.mograsim.logic.model.serializing.IndirectModelComponentCreator; @@ -14,24 +16,29 @@ import net.mograsim.machine.Machine; import net.mograsim.machine.MachineDefinition; import net.mograsim.machine.MainMemory; import net.mograsim.machine.Register; +import net.mograsim.machine.mi.MicroInstruction; +import net.mograsim.machine.mi.MicroInstructionDefinition; import net.mograsim.machine.mi.MicroInstructionMemory; import net.mograsim.machine.mi.StandardMicroInstructionMemory; +import net.mograsim.machine.mi.parameters.MicroInstructionParameter; +import net.mograsim.machine.mi.parameters.ParameterClassification; import net.mograsim.machine.standard.memory.WordAddressableMemory; public class Am2900Machine implements Machine { private Am2900MachineDefinition machineDefinition; private LogicModelModifiable logicModel; + private ModelComponent am2900; private Timeline timeline; private MainMemory mainMemory; private MicroInstructionMemory instMemory; private CoreClock clock; - public Am2900Machine(Am2900MachineDefinition am2900MachineDefinition) + public Am2900Machine(LogicModelModifiable model, Am2900MachineDefinition am2900MachineDefinition) { this.machineDefinition = am2900MachineDefinition; - logicModel = new LogicModelModifiable(); - IndirectModelComponentCreator.createComponent(logicModel, + this.logicModel = model; + this.am2900 = IndirectModelComponentCreator.createComponent(logicModel, "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/Am2900.json", "Am2900"); CoreModelParameters params = new CoreModelParameters(); params.gateProcessTime = 50; @@ -53,8 +60,13 @@ public class Am2900Machine implements Machine @Override public void reset() { - // TODO Auto-generated method stub - + logicModel.getComponentByName("Am2900").setHighLevelState("c.out", BitVector.of(Bit.ZERO)); + MicroInstructionDefinition muiDef = getDefinition().getMicroInstructionMemoryDefinition().getMicroInstructionDefinition(); + ParameterClassification[] paramClassifications = muiDef.getParameterClassifications(); + MicroInstructionParameter[] defaultParams = muiDef.createDefaultInstruction().getParameters(); + defaultParams[19] = paramClassifications[19].parse("JZ"); + MicroInstruction jzMI = MicroInstruction.create(defaultParams); + logicModel.getComponentByName("Am2900").setHighLevelState("muir_2.q", jzMI.toBitVector()); } @Override @@ -63,6 +75,11 @@ public class Am2900Machine implements Machine return logicModel; } + public ModelComponent getAm2900() + { + return am2900; + } + @Override public Timeline getTimeline() { @@ -100,5 +117,4 @@ public class Am2900Machine implements Machine { return instMemory; } - -} +} \ No newline at end of file diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MachineDefinition.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MachineDefinition.java index 0ac06ea7..0ed024f4 100644 --- a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MachineDefinition.java +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MachineDefinition.java @@ -3,18 +3,16 @@ package net.mograsim.logic.model.am2900.machine; import java.util.Objects; import java.util.Set; +import net.mograsim.logic.model.model.LogicModelModifiable; import net.mograsim.machine.ISASchema; -import net.mograsim.machine.Machine; import net.mograsim.machine.MachineDefinition; import net.mograsim.machine.MachineRegistry; -import net.mograsim.machine.MainMemoryDefinition; import net.mograsim.machine.Register; -import net.mograsim.machine.mi.MicroInstructionMemoryDefinition; public class Am2900MachineDefinition implements MachineDefinition { - private MainMemoryDefinition memoryDefinition = new Am2900MainMemoryDefinition(); - private MicroInstructionMemoryDefinition microInstMemoryDefinition = new Am2900MicroInstructionMemoryDefinition(); + private Am2900MainMemoryDefinition memoryDefinition = new Am2900MainMemoryDefinition(); + private Am2900MicroInstructionMemoryDefinition microInstMemoryDefinition = new Am2900MicroInstructionMemoryDefinition(); private final static Am2900MachineDefinition instance = new Am2900MachineDefinition(); public static Am2900MachineDefinition getInstance() @@ -24,9 +22,14 @@ public class Am2900MachineDefinition implements MachineDefinition } @Override - public Machine createNew() + public Am2900Machine createNew() { - return new Am2900Machine(this); + return createNew(new LogicModelModifiable()); + } + + public Am2900Machine createNew(LogicModelModifiable model) + { + return new Am2900Machine(model, this); } @Override @@ -50,13 +53,13 @@ public class Am2900MachineDefinition implements MachineDefinition } @Override - public MainMemoryDefinition getMainMemoryDefinition() + public Am2900MainMemoryDefinition getMainMemoryDefinition() { return memoryDefinition; } @Override - public MicroInstructionMemoryDefinition getMicroInstructionMemoryDefinition() + public Am2900MicroInstructionMemoryDefinition getMicroInstructionMemoryDefinition() { return microInstMemoryDefinition; } diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ModelComponentTestbench.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ModelComponentTestbench.java index 1e654c80..297075a8 100644 --- a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ModelComponentTestbench.java +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ModelComponentTestbench.java @@ -6,6 +6,7 @@ import java.util.List; import net.mograsim.logic.model.SimpleLogicUIStandalone; import net.mograsim.logic.model.am2900.Am2900Loader; +import net.mograsim.logic.model.am2900.machine.Am2900MachineDefinition; import net.mograsim.logic.model.model.LogicModelModifiable; import net.mograsim.logic.model.model.components.ModelComponent; import net.mograsim.logic.model.model.components.atomic.ModelBitDisplay; @@ -13,7 +14,6 @@ import net.mograsim.logic.model.model.components.atomic.ModelManualSwitch; import net.mograsim.logic.model.model.wires.ModelWire; import net.mograsim.logic.model.model.wires.Pin; import net.mograsim.logic.model.model.wires.PinUsage; -import net.mograsim.logic.model.serializing.IndirectModelComponentCreator; public class ModelComponentTestbench { @@ -26,7 +26,7 @@ public class ModelComponentTestbench public static void createTestbench(LogicModelModifiable model) { Am2900Loader.setup(); - ModelComponent comp = IndirectModelComponentCreator.createComponent(model, "Am2900"); + ModelComponent comp = new Am2900MachineDefinition().createNew(model).getAm2900(); List inputPinNames = new ArrayList<>(); List outputPinNames = new ArrayList<>(); diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/MachineContext.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/MachineContext.java index cc96edbb..2e7a9c1d 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/MachineContext.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/MachineContext.java @@ -4,8 +4,6 @@ import java.util.HashSet; import java.util.Optional; import java.util.Set; -import net.mograsim.logic.model.am2900.machine.Am2900Machine; -import net.mograsim.logic.model.am2900.machine.Am2900MachineDefinition; import net.mograsim.machine.Machine; import net.mograsim.machine.MachineRegistry; @@ -26,7 +24,7 @@ public class MachineContext { instance = new MachineContext(); // TODO don't hardcode the Am2900 - instance.setMachine(new Am2900Machine((Am2900MachineDefinition) MachineRegistry.getinstalledMachines().get("Am2900"))); + instance.setMachine(MachineRegistry.getinstalledMachines().get("Am2900").createNew()); } return instance; } -- 2.17.1