Made Am2900 work again in ModelComponentTestbench
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Tue, 17 Sep 2019 12:31:40 +0000 (14:31 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Tue, 17 Sep 2019 13:10:41 +0000 (15:10 +0200)
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900Machine.java
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MachineDefinition.java
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ModelComponentTestbench.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/MachineContext.java

index 0a0787c..5683b8e 100644 (file)
@@ -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
index 0ac06ea..0ed024f 100644 (file)
@@ -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;
        }
index 1e654c8..297075a 100644 (file)
@@ -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<String> inputPinNames = new ArrayList<>();
                List<String> outputPinNames = new ArrayList<>();
index cc96edb..2e7a9c1 100644 (file)
@@ -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;
        }