Added simple version of Am2900Machine
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Fri, 4 Oct 2019 11:06:55 +0000 (13:06 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Fri, 4 Oct 2019 11:06:55 +0000 (13:06 +0200)
plugins/net.mograsim.logic.model.am2900/plugin.xml
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/AbstractAm2900MachineDefinition.java [new file with mode: 0644]
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 [deleted file]
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/SimpleAm2900MachineDefinition.java [new file with mode: 0644]
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/StrictAm2900MachineDefinition.java [new file with mode: 0644]
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ModelComponentTestbench.java

index 7a324ad..a3376d5 100644 (file)
@@ -4,8 +4,12 @@
    <extension
          point="net.mograsim.machine.machine_definition">
       <machineDefinitionImplementation
-            class="net.mograsim.logic.model.am2900.machine.Am2900MachineDefinition"
-            unique_id="Am2900">
+            class="net.mograsim.logic.model.am2900.machine.SimpleAm2900MachineDefinition"
+            unique_id="Am2900Simple">
+      </machineDefinitionImplementation>
+      <machineDefinitionImplementation
+            class="net.mograsim.logic.model.am2900.machine.StrictAm2900MachineDefinition"
+            unique_id="Am2900Strict">
       </machineDefinitionImplementation>
    </extension>
 
diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/AbstractAm2900MachineDefinition.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/AbstractAm2900MachineDefinition.java
new file mode 100644 (file)
index 0000000..37d9315
--- /dev/null
@@ -0,0 +1,99 @@
+package net.mograsim.logic.model.am2900.machine;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import net.mograsim.logic.model.am2900.machine.registers.NumberedRegister;
+import net.mograsim.logic.model.am2900.machine.registers.QRegister;
+import net.mograsim.logic.model.model.LogicModelModifiable;
+import net.mograsim.machine.ISASchema;
+import net.mograsim.machine.MachineDefinition;
+import net.mograsim.machine.Register;
+
+//we can't use the Singleton pattern here because a MachineDefinition needs a public parameterless constructor
+//(used for detecting installed machines in plugin.core)
+public class AbstractAm2900MachineDefinition implements MachineDefinition
+{
+       public static final String SIMPLE_AM2900_MACHINE_ID = "Am2900Simple";
+       public static final String STRICT_AM2900_MACHINE_ID = "Am2900Strict";
+
+       public static final Set<Register> allRegisters;
+
+       static
+       {
+               Set<Register> allRegistersModifiable = new HashSet<>();
+               allRegistersModifiable.add(QRegister.instance);
+               allRegistersModifiable.addAll(NumberedRegister.instancesCorrectOrder);
+               allRegisters = Collections.unmodifiableSet(allRegistersModifiable);
+       }
+
+       public final boolean strict;
+
+       protected AbstractAm2900MachineDefinition(boolean strict)
+       {
+               this.strict = strict;
+       }
+
+       @Override
+       public String getId()
+       {
+               return strict ? STRICT_AM2900_MACHINE_ID : SIMPLE_AM2900_MACHINE_ID;
+       }
+
+       @Override
+       public Am2900Machine createNew()
+       {
+               return createNew(new LogicModelModifiable());
+       }
+
+       public Am2900Machine createNew(LogicModelModifiable model)
+       {
+               return new Am2900Machine(model, this);
+       }
+
+       @Override
+       public ISASchema getISASchema()
+       {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Set<Register> getRegisters()
+       {
+               return allRegisters;
+       }
+
+       @Override
+       public int getAddressBits()
+       {
+               return 16;
+       }
+
+       @Override
+       public Am2900MainMemoryDefinition getMainMemoryDefinition()
+       {
+               return Am2900MainMemoryDefinition.instance;
+       }
+
+       @Override
+       public int hashCode()
+       {
+               return strict ? 12345 : 54321;
+       }
+
+       @Override
+       public boolean equals(Object obj)
+       {
+               return obj != null && obj instanceof AbstractAm2900MachineDefinition
+                               && ((AbstractAm2900MachineDefinition) obj).strict == this.strict;
+       }
+
+       @Override
+       public Am2900MicroInstructionMemoryDefinition getMicroInstructionMemoryDefinition()
+       {
+               return Am2900MicroInstructionMemoryDefinition.instance;
+       }
+
+}
index 3d6db31..352ce12 100644 (file)
@@ -8,6 +8,7 @@ import java.util.function.Consumer;
 
 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.machine.registers.NumberedRegister;
 import net.mograsim.logic.model.am2900.machine.registers.QRegister;
@@ -32,7 +33,7 @@ import net.mograsim.machine.standard.memory.WordAddressableMemory;
 
 public class Am2900Machine implements Machine
 {
-       private Am2900MachineDefinition machineDefinition;
+       private AbstractAm2900MachineDefinition machineDefinition;
        private LogicModelModifiable logicModel;
        private ModelComponent am2900;
        private Timeline timeline;
@@ -44,7 +45,7 @@ public class Am2900Machine implements Machine
        private final Set<ActiveMicroInstructionChangedListener> amicListeners;
        private final Map<Register, Map<Consumer<BitVector>, Consumer<Object>>> modelListenersPerRegisterListenerPerRegister;
 
-       public Am2900Machine(LogicModelModifiable model, Am2900MachineDefinition am2900MachineDefinition)
+       public Am2900Machine(LogicModelModifiable model, AbstractAm2900MachineDefinition am2900MachineDefinition)
        {
                this.machineDefinition = am2900MachineDefinition;
                this.logicModel = model;
@@ -89,6 +90,12 @@ public class Am2900Machine implements Machine
                defaultParams[19] = paramClassifications[19].parse("JZ");
                MicroInstruction jzMI = MicroInstruction.create(defaultParams);
                am2900.setHighLevelState("muir_2.q", jzMI.toBitVector());
+               if (!machineDefinition.strict)
+               {
+                       for (Register r : machineDefinition.getRegisters())
+                               setRegister(r, BitVector.of(Bit.ZERO, r.getWidth()));
+                       // TODO reset latches?
+               }
        }
 
        @Override
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
deleted file mode 100644 (file)
index 325f63f..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-package net.mograsim.logic.model.am2900.machine;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import net.mograsim.logic.model.am2900.machine.registers.NumberedRegister;
-import net.mograsim.logic.model.am2900.machine.registers.QRegister;
-import net.mograsim.logic.model.model.LogicModelModifiable;
-import net.mograsim.machine.ISASchema;
-import net.mograsim.machine.MachineDefinition;
-import net.mograsim.machine.Register;
-
-//we can't use the Singleton pattern here because a MachineDefinition needs a public parameterless constructor
-//(used for detecting installed machines in plugin.core)
-public class Am2900MachineDefinition implements MachineDefinition
-{
-       public static final String AM2900_MACHINE_ID = "Am2900";
-
-       public static final Set<Register> allRegisters;
-
-       static
-       {
-               Set<Register> allRegistersModifiable = new HashSet<>();
-               allRegistersModifiable.add(QRegister.instance);
-               allRegistersModifiable.addAll(NumberedRegister.instancesCorrectOrder);
-               allRegisters = Collections.unmodifiableSet(allRegistersModifiable);
-       }
-
-       @Override
-       public String getId()
-       {
-               return AM2900_MACHINE_ID;
-       }
-
-       @Override
-       public Am2900Machine createNew()
-       {
-               return createNew(new LogicModelModifiable());
-       }
-
-       public Am2900Machine createNew(LogicModelModifiable model)
-       {
-               return new Am2900Machine(model, this);
-       }
-
-       @Override
-       public ISASchema getISASchema()
-       {
-               // TODO Auto-generated method stub
-               return null;
-       }
-
-       @Override
-       public Set<Register> getRegisters()
-       {
-               return allRegisters;
-       }
-
-       @Override
-       public int getAddressBits()
-       {
-               return 16;
-       }
-
-       @Override
-       public Am2900MainMemoryDefinition getMainMemoryDefinition()
-       {
-               return Am2900MainMemoryDefinition.instance;
-       }
-
-       @Override
-       public int hashCode()
-       {
-               return 12345;
-       }
-
-       @Override
-       public boolean equals(Object obj)
-       {
-               return obj != null && obj instanceof Am2900MachineDefinition;
-       }
-
-       @Override
-       public Am2900MicroInstructionMemoryDefinition getMicroInstructionMemoryDefinition()
-       {
-               return Am2900MicroInstructionMemoryDefinition.instance;
-       }
-
-}
diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/SimpleAm2900MachineDefinition.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/SimpleAm2900MachineDefinition.java
new file mode 100644 (file)
index 0000000..895b1c2
--- /dev/null
@@ -0,0 +1,9 @@
+package net.mograsim.logic.model.am2900.machine;
+
+public class SimpleAm2900MachineDefinition extends AbstractAm2900MachineDefinition
+{
+       public SimpleAm2900MachineDefinition()
+       {
+               super(false);
+       }
+}
\ No newline at end of file
diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/StrictAm2900MachineDefinition.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/StrictAm2900MachineDefinition.java
new file mode 100644 (file)
index 0000000..ace5fb2
--- /dev/null
@@ -0,0 +1,9 @@
+package net.mograsim.logic.model.am2900.machine;
+
+public class StrictAm2900MachineDefinition extends AbstractAm2900MachineDefinition
+{
+       public StrictAm2900MachineDefinition()
+       {
+               super(true);
+       }
+}
\ No newline at end of file
index 297075a..eb3f0b2 100644 (file)
@@ -6,7 +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.am2900.machine.StrictAm2900MachineDefinition;
 import net.mograsim.logic.model.model.LogicModelModifiable;
 import net.mograsim.logic.model.model.components.ModelComponent;
 import net.mograsim.logic.model.model.components.atomic.ModelBitDisplay;
@@ -26,7 +26,7 @@ public class ModelComponentTestbench
        public static void createTestbench(LogicModelModifiable model)
        {
                Am2900Loader.setup();
-               ModelComponent comp = new Am2900MachineDefinition().createNew(model).getAm2900();
+               ModelComponent comp = new StrictAm2900MachineDefinition().createNew(model).getAm2900();
 
                List<String> inputPinNames = new ArrayList<>();
                List<String> outputPinNames = new ArrayList<>();