From: Daniel Kirschten Date: Fri, 4 Oct 2019 11:06:55 +0000 (+0200) Subject: Added simple version of Am2900Machine X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=5145372e475b764b56745909726ba64749e067b0;p=Mograsim.git Added simple version of Am2900Machine --- diff --git a/plugins/net.mograsim.logic.model.am2900/plugin.xml b/plugins/net.mograsim.logic.model.am2900/plugin.xml index 7a324ad9..a3376d51 100644 --- a/plugins/net.mograsim.logic.model.am2900/plugin.xml +++ b/plugins/net.mograsim.logic.model.am2900/plugin.xml @@ -4,8 +4,12 @@ + class="net.mograsim.logic.model.am2900.machine.SimpleAm2900MachineDefinition" + unique_id="Am2900Simple"> + + 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 index 00000000..37d93153 --- /dev/null +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/AbstractAm2900MachineDefinition.java @@ -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 allRegisters; + + static + { + Set 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 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; + } + +} 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 3d6db31c..352ce123 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 @@ -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 amicListeners; private final Map, Consumer>> 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 index 325f63fb..00000000 --- a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MachineDefinition.java +++ /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 allRegisters; - - static - { - Set 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 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 index 00000000..895b1c2c --- /dev/null +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/SimpleAm2900MachineDefinition.java @@ -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 index 00000000..ace5fb27 --- /dev/null +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/StrictAm2900MachineDefinition.java @@ -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 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 297075a8..eb3f0b2c 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,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 inputPinNames = new ArrayList<>(); List outputPinNames = new ArrayList<>();