}
};
}
+
+ public BitVector reverse()
+ {
+ int length = length();
+ Bit[] other = new Bit[length];
+ for (int i = 0, j = length - 1; i < length; i++, j--)
+ {
+ other[i] = bits[j];
+ }
+ return new BitVector(other);
+ }
}
--- /dev/null
+package net.mograsim.logic.model.am2900.components;
+
+import net.mograsim.logic.model.am2900.machine.Am2900MachineDefinition;
+import net.mograsim.logic.model.model.LogicModelModifiable;
+import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
+import net.mograsim.logic.model.serializing.IdentifyParams;
+import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
+import net.mograsim.machine.standard.memory.ModelWordAddressableMemory;
+
+public class ModelAm2900MainMemory extends ModelWordAddressableMemory
+{
+ public ModelAm2900MainMemory(LogicModelModifiable model, String name)
+ {
+ super(model, Am2900MachineDefinition.getInstance().getMainMemoryDefinition(), name);
+ }
+
+ static
+ {
+ LogicCoreAdapter.addComponentAdapter(new ModelAm2900MicroInstructionMemoryAdapter());
+ IndirectModelComponentCreator.setComponentSupplier(ModelAm2900MainMemory.class.getCanonicalName(), (m, p, n) ->
+ {
+ return new ModelAm2900MainMemory(m, n);
+ });
+ }
+
+ @Override
+ public String getIDForSerializing(IdentifyParams idParams)
+ {
+ return "Am2900MainMemory";
+ }
+
+}
--- /dev/null
+package net.mograsim.logic.model.am2900.components;
+
+import java.util.Map;
+
+import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.wires.CoreWire;
+import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
+import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.modeladapter.CoreModelParameters;
+import net.mograsim.logic.model.modeladapter.componentadapters.ComponentAdapter;
+import net.mograsim.machine.standard.memory.CoreWordAddressableMemory;
+import net.mograsim.machine.standard.memory.WordAddressableMemory;
+
+public class ModelAm2900MainMemoryAdapter implements ComponentAdapter<ModelAm2900MainMemory>
+{
+
+ @Override
+ public Class<ModelAm2900MainMemory> getSupportedClass()
+ {
+ return ModelAm2900MainMemory.class;
+ }
+
+ @Override
+ public void createAndLinkComponent(Timeline timeline, CoreModelParameters params, ModelAm2900MainMemory modelComponent,
+ Map<Pin, CoreWire> logicWiresPerPin)
+ {
+ ReadWriteEnd data = logicWiresPerPin.get(modelComponent.getDataPin()).createReadWriteEnd();
+ ReadEnd address = logicWiresPerPin.get(modelComponent.getAddressPin()).createReadOnlyEnd();
+ ReadEnd mode = logicWiresPerPin.get(modelComponent.getReadWritePin()).createReadOnlyEnd();
+ ReadEnd clock = logicWiresPerPin.get(modelComponent.getClockPin()).createReadOnlyEnd();
+ CoreWordAddressableMemory mem = new CoreWordAddressableMemory(timeline, 2,
+ new WordAddressableMemory(modelComponent.getDefinition()), data, mode, address, clock);
+ modelComponent.setCoreModelBinding(mem);
+ }
+}
--- /dev/null
+package net.mograsim.logic.model.am2900.components;
+
+import net.mograsim.logic.model.am2900.machine.Am2900MachineDefinition;
+import net.mograsim.logic.model.model.LogicModelModifiable;
+import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
+import net.mograsim.logic.model.serializing.IdentifyParams;
+import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
+import net.mograsim.machine.mi.components.ModelMicroInstructionMemory;
+
+public class ModelAm2900MicroInstructionMemory extends ModelMicroInstructionMemory
+{
+ public ModelAm2900MicroInstructionMemory(LogicModelModifiable model, String name)
+ {
+ super(model, Am2900MachineDefinition.getInstance().getMicroInstructionMemoryDefinition(), name);
+ }
+
+ static
+ {
+ LogicCoreAdapter.addComponentAdapter(new ModelAm2900MicroInstructionMemoryAdapter());
+ IndirectModelComponentCreator.setComponentSupplier(ModelAm2900MicroInstructionMemory.class.getCanonicalName(), (m, p, n) ->
+ {
+ return new ModelAm2900MicroInstructionMemory(m, n);
+ });
+ }
+
+ @Override
+ public String getIDForSerializing(IdentifyParams idParams)
+ {
+ return "Am2900MicroInstructionMemory";
+ }
+}
--- /dev/null
+package net.mograsim.logic.model.am2900.components;
+
+import java.util.Map;
+
+import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.wires.CoreWire;
+import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
+import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.modeladapter.CoreModelParameters;
+import net.mograsim.logic.model.modeladapter.componentadapters.ComponentAdapter;
+import net.mograsim.machine.mi.StandardMicroInstructionMemory;
+import net.mograsim.machine.mi.components.CoreMicroInstructionMemory;
+
+public class ModelAm2900MicroInstructionMemoryAdapter implements ComponentAdapter<ModelAm2900MicroInstructionMemory>
+{
+
+ @Override
+ public Class<ModelAm2900MicroInstructionMemory> getSupportedClass()
+ {
+ return ModelAm2900MicroInstructionMemory.class;
+ }
+
+ @Override
+ public void createAndLinkComponent(Timeline timeline, CoreModelParameters params, ModelAm2900MicroInstructionMemory modelComponent,
+ Map<Pin, CoreWire> logicWiresPerPin)
+ {
+ ReadWriteEnd data = logicWiresPerPin.get(modelComponent.getDataPin()).createReadWriteEnd();
+ ReadEnd address = logicWiresPerPin.get(modelComponent.getAddressPin()).createReadOnlyEnd();
+ ReadEnd clock = logicWiresPerPin.get(modelComponent.getClockPin()).createReadOnlyEnd();
+ CoreMicroInstructionMemory mem = new CoreMicroInstructionMemory(timeline, 2,
+ new StandardMicroInstructionMemory(modelComponent.getDefinition()), data, address, clock);
+ modelComponent.setCoreModelBinding(mem);
+ }
+
+}
package net.mograsim.logic.model.am2900.machine;
+import java.util.Objects;
import java.util.Set;
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;
{
private MainMemoryDefinition memoryDefinition = new Am2900MainMemoryDefinition();
private MicroInstructionMemoryDefinition microInstMemoryDefinition = new Am2900MicroInstructionMemoryDefinition();
+ private final static Am2900MachineDefinition instance = new Am2900MachineDefinition();
+
+ public static Am2900MachineDefinition getInstance()
+ {
+ return Objects.requireNonNullElseGet((Am2900MachineDefinition) MachineRegistry.getinstalledMachines().get("Am2900"),
+ () -> instance);
+ }
@Override
public Machine createNew()
package net.mograsim.logic.model.am2900.machine;
+import java.util.Arrays;
+import java.util.Optional;
+
import net.mograsim.logic.core.types.Bit;
import net.mograsim.logic.core.types.BitVector;
import net.mograsim.machine.mi.MicroInstructionDefinition;
public class Am2900MicroInstructionDefinition implements MicroInstructionDefinition
{
- private final static MnemonicFamily am2910Instructions = new MnemonicFamily("JZ", "CJS", "JMAP", "PUSH", "JSRP", "CJV", "JRP", "RFCT",
- "RPCT", "CRTN", "CJPP", "LDCT", "LOOP", "CONT", "TWB");
- private final static MnemonicFamily am2904StatusInstructions = new MnemonicFamily(
- new String[] { "Zero", "NotZero", "UGTEQ", "ULT", "UGT", "ULTEQ", "SGTEQ", "SLT", "SGT", "SLTEQ" },
- new long[] { 0x5, 0x4, 0xB, 0xA, 0xC, 0xD, 0x2, 0x3, 0x0, 0x1 }, 4);
- private final static MnemonicFamily am2904ShiftInstructions = new MnemonicFamily("SL", "SH", "SCONI", "SDH", "SDC", "SDN", "SDL",
+ private final static MnemonicFamily am2910Instructions = new MnemonicFamily(true, "JZ", "CJS", "JMAP", "PUSH", "JSRP", "CJV", "JRP",
+ "RFCT", "RPCT", "CRTN", "CJPP", "LDCT", "LOOP", "CONT", "TWB");
+ private final static MnemonicFamily am2904StatusInstructions = new MnemonicFamily(true,
+ new String[] { "MI_Zero", "MI_NotZero", "MI_UGTEQ", "MI_ULT", "MI_UGT", "MI_ULTEQ", "MI_SGTEQ", "MI_SLT", "MI_SGT", "MI_SLTEQ",
+ "MA_Zero", "MA_NotZero", "MA_UGTEQ", "MA_ULT", "MA_UGT", "MA_ULTEQ", "MA_SGTEQ", "MA_SLT", "MA_SGT", "MA_SLTEQ" },
+ new long[] { 0b01_0101, 0b01_0100, 0b01_1101, 0b01_1100, 0b01_1110, 0b01_1111, 0b01_0010, 0b01_0011, 0b01_0000, 0b01_0001,
+ 0b10_0101, 0b10_0100, 0b10_1101, 0b10_1100, 0b10_1110, 0b10_1111, 0b10_0010, 0b10_0011, 0b10_0000, 0b10_0001 },
+ 6);
+ private final static MnemonicFamily am2904ShiftInstructions = new MnemonicFamily(true, "SL", "SH", "SCONI", "SDH", "SDC", "SDN", "SDL",
"SDCO", "SRCO", "SRCIO", "SR", "SDIC", "SDRCI", "SDRCO", "SDXOR", "SDR");
- private final static MnemonicFamily am2904CarryInstructions = new MnemonicFamily(new String[] { "0", "1", "Cx", "µ", "!µ", "M", "!M" },
- new long[] { 0b000000, 0b010000, 0b100000, 0b110000, 0b110100, 0b111000, 0b111100 }, 6);
- private final static MnemonicFamily am2901DestInstructions = new MnemonicFamily("QREG", "NOP", "RAMA", "RAMF", "RAMQD", "RAMD", "RAMQU",
- "RAMU");
- private final static MnemonicFamily am2901FuncInstructions = new MnemonicFamily("ADD", "SUBR", "SUBS", "OR", "AND", "NOTRS", "EXOR",
- "EXNOR");
- private final static MnemonicFamily am2901SrcInstructions = new MnemonicFamily("AQ", "AB", "ZQ", "ZB", "ZA", "DA", "DQ", "DZ");
+ private final static MnemonicFamily am2904CarryInstructions = new MnemonicFamily(true, new String[] { "CI0", "CI1", "CIX", "CIC" },
+ new long[] { 0b00, 0b01, 0b10, 0b11 }, 2);
+ private final static MnemonicFamily am2901DestInstructions = new MnemonicFamily(true, "QREG", "NOP", "RAMA", "RAMF", "RAMQD", "RAMD",
+ "RAMQU", "RAMU");
+ private final static MnemonicFamily am2901FuncInstructions = new MnemonicFamily(true, "ADD", "SUBR", "SUBS", "OR", "AND", "NOTRS",
+ "EXOR", "EXNOR");
+ private final static MnemonicFamily am2901SrcInstructions = new MnemonicFamily(true, "AQ", "AB", "ZQ", "ZB", "ZA", "DA", "DQ", "DZ");
private final static MnemonicFamily interruptInstructions = new MnemonicFamily(
new MnemonicPair("X", BitVector.of(Bit.ZERO, 4))/* TODO */);
private final static BooleanClassification hL = new BooleanClassification("H", "L");
private final static BooleanClassification registerSelect = new BooleanClassification("MR", "IR");
private final static IntegerClassification register = new IntegerClassification(4);
- private final static ParameterClassification[] classes = { new BooleanClassification("R", "W"), hL, new BooleanClassification("H", "E"),
- new BooleanClassification("H", "I"), new BooleanClassification("H", "E"), hL, new IntegerClassification(11), am2910Instructions,
- new BooleanClassification("PS", "C"), am2904StatusInstructions, hL, hL, am2904ShiftInstructions, am2904CarryInstructions,
- new BooleanClassification("H", "DB"), new BooleanClassification("H", "AB"), registerSelect, register, registerSelect, register,
- am2901DestInstructions, am2901FuncInstructions, am2901SrcInstructions, new IntegerClassification(16),
- new BooleanClassification("D", "K"), interruptInstructions, new BooleanClassification("Dis", "IE") };
+ private final static ParameterClassification[] classes = { new BooleanClassification("Dis", "IE"), new IntegerClassification(16),
+ new BooleanClassification("D", "K"), interruptInstructions, new BooleanClassification("H", "AB"), registerSelect, register,
+ registerSelect, register, am2901DestInstructions, am2901FuncInstructions, am2901SrcInstructions, new IntegerClassification(12),
+ am2910Instructions, new BooleanClassification("PS", "C"), am2904StatusInstructions, hL, hL, am2904ShiftInstructions,
+ am2904CarryInstructions, new BooleanClassification("H", "DB"), new BooleanClassification("H", "E"), hL,
+ new BooleanClassification("H", "E"), new BooleanClassification("H", "I"), new BooleanClassification("R", "W"), hL };
+
+ private final static String[] paramDesc = { "Allow interrupts?", "Interrupt instructions; omitted for simplicity",
+ "Get D-input from data bus/constant value", "Constant value", "Operand sources for ALU operation", "ALU operation",
+ "Destination of ALU calculation", "Register for A-operand", "Get A-operand from instruction register/micro instruction?",
+ "Register for B-operand", "Get B-operand from instruction register/micro instruction?",
+ "Put data from Y-output on address bus?", "Put data from Y-output on data bus?", "Source for carry-in", "Shift instructions",
+ "Modify micro status register?", "Modify macro status register?", "Operations on the status register",
+ "Is conditional jump enabled?", "Instructions for the micro instruction pointer", "Absolute address of a micro instruction",
+ "Load instruction pointer from data bus?", "Put instruction pointer on data bus?", "Increment instruction pointer?",
+ "Put instruction pointer on address bus?", "Load instruction register from data bus?", "Read from/Write to main memory?" };
@Override
public ParameterClassification[] getParameterClassifications()
return classes[index];
}
+ @Override
+ public Optional<String> getParameterDescription(int index)
+ {
+ return Optional.of(paramDesc[index]);
+ }
+
+ public static void main(String[] args)
+ {
+ String s = "new BooleanClassification(\"R\", \"W\"), hL, new BooleanClassification(\"H\", \"E\"),\r\n"
+ + " new BooleanClassification(\"H\", \"I\"), new BooleanClassification(\"H\", \"E\"), hL, new IntegerClassification(12), am2910Instructions,\r\n"
+ + " new BooleanClassification(\"PS\", \"C\"), am2904StatusInstructions, hL, hL, am2904ShiftInstructions, am2904CarryInstructions,\r\n"
+ + " new BooleanClassification(\"H\", \"DB\"), new BooleanClassification(\"H\", \"AB\"), registerSelect, register, registerSelect, register,\r\n"
+ + " am2901DestInstructions, am2901FuncInstructions, am2901SrcInstructions, new IntegerClassification(16),\r\n"
+ + " new BooleanClassification(\"D\", \"K\"), interruptInstructions, new BooleanClassification(\"Dis\", \"IE\")";
+ s = s.replaceAll("[\r\n\t]", "");
+ System.out.print(Arrays.stream(s.split(", new")).reduce((a, b) -> b + ", new" + a));
+// System.out.println(Arrays.stream(paramDesc).reduce("", (a, b) -> String.format("\"%s\", %s", b, a)));
+ }
}
{
"version": "0.1.0",
"map": {
+ "Am2900MainMemory": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.ModelAm2900MainMemory",
+ "Am2900MicroInstructionMemory": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.ModelAm2900MicroInstructionMemory",
"Am2904RegCTInstrDecode": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2904.ModelAm2904RegCTInstrDecode",
"Am2904ShiftInstrDecode": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2904.ModelAm2904ShiftInstrDecode",
"Am2910InstrPLA": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2910.ModelAm2910InstrPLA",
net.mograsim.machine.isa,
net.mograsim.machine.isa.types,
net.mograsim.machine.mi,
+ net.mograsim.machine.mi.components,
net.mograsim.machine.mi.parameters,
net.mograsim.machine.standard.memory
Bundle-Activator: net.mograsim.machine.MachineLoader
--- /dev/null
+package net.mograsim.machine;
+
+import net.haspamelodica.swt.helper.gcs.GeneralGC;
+import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
+import net.mograsim.logic.model.model.LogicModelModifiable;
+import net.mograsim.logic.model.model.components.ModelComponent;
+import net.mograsim.logic.model.snippets.Renderer;
+import net.mograsim.logic.model.snippets.outlinerenderers.DefaultOutlineRenderer;
+import net.mograsim.logic.model.snippets.symbolrenderers.SimpleRectangularLikeSymbolRenderer;
+import net.mograsim.logic.model.snippets.symbolrenderers.SimpleRectangularLikeSymbolRenderer.SimpleRectangularLikeParams;
+
+public abstract class ModelMemory extends ModelComponent
+{
+ private Renderer symbolRenderer;
+ private Renderer outlineRenderer;
+ protected final int width, height;
+
+ protected ModelMemory(LogicModelModifiable model, int width, int height, String name, String centerText, boolean callInit)
+ {
+ super(model, name, false);
+ this.width = width;
+ this.height = height;
+
+ SimpleRectangularLikeParams rendererParams = new SimpleRectangularLikeParams();
+ rendererParams.centerText = centerText;
+ rendererParams.centerTextHeight = 24;
+ rendererParams.horizontalComponentCenter = width / 100;
+ rendererParams.pinLabelHeight = 17.5;
+ rendererParams.pinLabelMargin = 2.5;
+ this.symbolRenderer = new SimpleRectangularLikeSymbolRenderer(this, rendererParams);
+ this.outlineRenderer = new DefaultOutlineRenderer(this);
+
+ setSize(width, height);
+
+ if (callInit)
+ init();
+ }
+
+ @Override
+ public void render(GeneralGC gc, Rectangle visibleRegion)
+ {
+ symbolRenderer.render(gc, visibleRegion);
+ outlineRenderer.render(gc, visibleRegion);
+ }
+}
package net.mograsim.machine.mi;
+import net.mograsim.logic.core.types.BitVector;
import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
import net.mograsim.machine.mi.parameters.Mnemonic;
{
return new StandardMicroInstruction(parameters);
}
+
+ default BitVector toBitVector()
+ {
+ BitVector vector = BitVector.of();
+ int size = getSize();
+ for(int i = 0; i < size; i++)
+ vector.concat(getParameter(i).getValue());
+ return vector;
+ }
}
package net.mograsim.machine.mi;
import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Optional;
+import net.mograsim.logic.core.types.Bit;
import net.mograsim.machine.mi.parameters.IntegerClassification;
import net.mograsim.machine.mi.parameters.IntegerImmediate;
import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
return getParameterClassifications().length;
}
+ /**
+ * @return The amount of {@link Bit}s in a {@link MicroInstruction} that follows this definition.
+ */
+ public default int sizeInBits()
+ {
+ return Arrays.stream(getParameterClassifications()).mapToInt(e -> e.getExpectedBits()).reduce(0, (a, b) -> a + b);
+ }
+
public default MicroInstruction createDefaultInstruction()
{
int size = size();
}
return new StandardMicroInstruction(params);
}
-
- public static MicroInstructionDefinition create(ParameterClassification... classes)
- {
- return new StandardMicroInstructionDefinition(classes);
- }
+
+ public Optional<String> getParameterDescription(int index);
}
\ No newline at end of file
+++ /dev/null
-package net.mograsim.machine.mi;
-
-import net.mograsim.machine.mi.parameters.ParameterClassification;
-
-class StandardMicroInstructionDefinition implements MicroInstructionDefinition
-{
- private ParameterClassification[] classes;
-
- public StandardMicroInstructionDefinition(ParameterClassification... classes)
- {
- this.classes = classes;
- }
-
- @Override
- public ParameterClassification[] getParameterClassifications()
- {
- return classes.clone();
- }
-
- @Override
- public ParameterClassification getParameterClassification(int index)
- {
- return classes[index];
- }
-
-}
--- /dev/null
+package net.mograsim.machine.mi.components;
+
+import java.util.List;
+
+import net.mograsim.logic.core.components.BasicCoreComponent;
+import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
+import net.mograsim.logic.core.types.Bit;
+import net.mograsim.logic.core.types.BitVector;
+import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
+import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
+import net.mograsim.machine.mi.MicroInstructionMemory;
+
+public class CoreMicroInstructionMemory extends BasicCoreComponent
+{
+ private final ReadWriteEnd data;
+ private final ReadEnd address, clock;
+ private final MicroInstructionMemory memory;
+
+
+ public CoreMicroInstructionMemory(Timeline timeline, int processTime, MicroInstructionMemory memory, ReadWriteEnd data, ReadEnd address, ReadEnd clock)
+ {
+ super(timeline, processTime);
+ this.memory = memory;
+ this.data = data;
+ this.address = address;
+ this.clock = clock;
+ }
+
+ public MicroInstructionMemory getMemory()
+ {
+ return memory;
+ }
+
+ @Override
+ public List<ReadEnd> getAllInputs()
+ {
+ return List.of(address, clock);
+ }
+
+ @Override
+ public List<ReadWriteEnd> getAllOutputs()
+ {
+ return List.of(data);
+ }
+
+ @Override
+ protected TimelineEventHandler compute()
+ {
+ if(clock.getValue() != Bit.ONE)
+ return null;
+
+ if (!address.hasNumericValue())
+ {
+ return e -> data.feedSignals(Bit.U.toVector(data.width()));
+ }
+ long addressed = address.getUnsignedValue();
+ BitVector storedData = memory.getCell(addressed).toBitVector();
+ return e -> data.feedSignals(storedData);
+ }
+}
--- /dev/null
+package net.mograsim.machine.mi.components;
+
+import net.mograsim.logic.model.model.LogicModelModifiable;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.model.wires.PinUsage;
+import net.mograsim.machine.ModelMemory;
+import net.mograsim.machine.mi.MicroInstructionMemoryDefinition;
+
+public abstract class ModelMicroInstructionMemory extends ModelMemory
+{
+ private final Pin addrPin, dataPin, clock;
+ private CoreMicroInstructionMemory memory;
+ private final MicroInstructionMemoryDefinition definition;
+
+ public ModelMicroInstructionMemory(LogicModelModifiable model, MicroInstructionMemoryDefinition definition, String name)
+ {
+ super(model, 200, 100, name, "MPM", false);
+ this.definition = definition;
+ addPin(addrPin = new Pin(model, this, "A", definition.getMemoryAddressBits(), PinUsage.INPUT, width / 2, 0));
+ addPin(dataPin = new Pin(model, this, "D", definition.getMicroInstructionDefinition().sizeInBits(), PinUsage.OUTPUT, 0, 30));
+ addPin(clock = new Pin(model, this, "C", 1, PinUsage.INPUT, 0, 60));
+
+ init();
+ }
+
+ public MicroInstructionMemoryDefinition getDefinition()
+ {
+ return definition;
+ }
+
+ public Pin getAddressPin()
+ {
+ return addrPin;
+ }
+
+ public Pin getDataPin()
+ {
+ return dataPin;
+ }
+
+ public Pin getClockPin()
+ {
+ return clock;
+ }
+
+ public CoreMicroInstructionMemory getCoreMemory()
+ {
+ return memory;
+ }
+
+ public void setCoreModelBinding(CoreMicroInstructionMemory memory)
+ {
+ this.memory = memory;
+ }
+}
private int vectorLength;
public MnemonicFamily(String... names)
+ {
+ this(false, (int) Math.round(Math.ceil(Math.log(names.length) / Math.log(2))), names);
+ }
+
+ public MnemonicFamily(boolean reverse, String... names)
+ {
+ this(reverse, (int) Math.round(Math.ceil(Math.log(names.length) / Math.log(2))), names);
+ }
+
+ public MnemonicFamily(int bits, String... names)
+ {
+ this(false, bits, names);
+ }
+
+ public MnemonicFamily(boolean reverse, int bits, String... names)
{
this.values = new Mnemonic[names.length];
this.stringValues = new String[names.length];
BitVector[] values = new BitVector[names.length];
- int bits = (int) Math.ceil(Math.log(names.length));
for(int i = 0; i < names.length; i++)
{
values[i] = BitVector.from(i, bits);
}
- setup(names, values);
+ setup(names, values, reverse);
}
public MnemonicFamily(String[] names, long[] values, int bits)
+ {
+ this(false, names, values, bits);
+ }
+
+ public MnemonicFamily(boolean reverse, String[] names, long[] values, int bits)
{
if(names.length != values.length)
throw new IllegalArgumentException();
vectors[i] = BitVector.from(values[i], bits);
}
- setup(names, vectors);
+ setup(names, vectors, reverse);
}
public MnemonicFamily(String[] names, BitVector[] values)
+ {
+ this(false, names, values);
+ }
+
+ public MnemonicFamily(boolean reverse, String[] names, BitVector[] values)
{
if(names.length != values.length)
throw new IllegalArgumentException();
this.values = new Mnemonic[values.length];
this.stringValues = new String[values.length];
- setup(names, values);
+ setup(names, values, reverse);
}
public MnemonicFamily(MnemonicPair... values)
+ {
+ this(false, values);
+ }
+
+ public MnemonicFamily(boolean reverse, MnemonicPair... values)
{
this.values = new Mnemonic[values.length];
this.stringValues = new String[values.length];
setup(values);
}
- private void setup(String[] names, BitVector[] values)
+ private void setup(String[] names, BitVector[] values, boolean reverse)
{
MnemonicPair[] mnemonics = new MnemonicPair[values.length];
for(int i = 0; i < values.length; i++)
- mnemonics[i] = new MnemonicPair(names[i], values[i]);
+ mnemonics[i] = new MnemonicPair(names[i], reverse ? values[i].reverse() : values[i]);
setup(mnemonics);
}
import net.mograsim.logic.core.types.BitVector;
import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
+import net.mograsim.machine.MainMemory;
import net.mograsim.machine.MainMemoryDefinition;
/**
*/
public class CoreWordAddressableMemory extends BasicCoreComponent
{
- private final WordAddressableMemory memory;
+ private final MainMemory memory;
private final static Bit read = Bit.ONE;
private ReadWriteEnd data;
* @param rWBit The value of the 0th bit dictates the mode: 0: Write, 1: Read
* @param address The bits of this ReadEnd address the memory cell to read/write
*/
- public CoreWordAddressableMemory(Timeline timeline, int processTime, MainMemoryDefinition definition, ReadWriteEnd data,
+ public CoreWordAddressableMemory(Timeline timeline, int processTime, MainMemory memory, ReadWriteEnd data,
ReadEnd rWBit, ReadEnd address, ReadEnd clock)
{
super(timeline, processTime);
+ MainMemoryDefinition definition = memory.getDefinition();
if(data.width() != definition.getCellWidth())
throw new IllegalArgumentException(String.format("Bit width of data wire does not match main memory definition. Expected: %d Actual: %d", definition.getCellWidth(), data.width()));
if(rWBit.width() != 1)
address.registerObserver(this);
clock.registerObserver(this);
- memory = new WordAddressableMemory(definition);
+ this.memory = memory;
}
@Override
+++ /dev/null
-package net.mograsim.machine.standard.memory;
-
-import net.haspamelodica.swt.helper.gcs.GeneralGC;
-import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
-import net.mograsim.logic.model.model.LogicModelModifiable;
-import net.mograsim.logic.model.model.components.ModelComponent;
-import net.mograsim.logic.model.model.wires.Pin;
-import net.mograsim.logic.model.model.wires.PinUsage;
-import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
-import net.mograsim.logic.model.serializing.IdentifyParams;
-import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
-import net.mograsim.logic.model.snippets.Renderer;
-import net.mograsim.logic.model.snippets.outlinerenderers.DefaultOutlineRenderer;
-import net.mograsim.logic.model.snippets.symbolrenderers.SimpleRectangularLikeSymbolRenderer;
-import net.mograsim.logic.model.snippets.symbolrenderers.SimpleRectangularLikeSymbolRenderer.SimpleRectangularLikeParams;
-import net.mograsim.logic.model.util.JsonHandler;
-import net.mograsim.machine.MainMemoryDefinition;
-
-public class ModelMemoryWA extends ModelComponent
-{
- private final MainMemoryDefinition definition;
- private final Pin addrPin, dataPin, rWPin, clock;
- private CoreWordAddressableMemory memory;
- private final static int width = 100, height = 300;
- private Renderer symbolRenderer;
- private Renderer outlineRenderer;
-
- public ModelMemoryWA(LogicModelModifiable model, MainMemoryDefinition definition, String name)
- {
- super(model, name, false);
- this.definition = definition;
-
- SimpleRectangularLikeParams rendererParams = new SimpleRectangularLikeParams();
- rendererParams.centerText = "RAM";
- rendererParams.centerTextHeight = 24;
- rendererParams.horizontalComponentCenter = width / 100;
- rendererParams.pinLabelHeight = 17.5;
- rendererParams.pinLabelMargin = 2.5;
- this.symbolRenderer = new SimpleRectangularLikeSymbolRenderer(this, rendererParams);
- this.outlineRenderer = new DefaultOutlineRenderer(this);
-
- setSize(width, height);
- //TODO check the usages
- addPin(addrPin = new Pin(model, this, "A", definition.getMemoryAddressBits(), PinUsage.INPUT, 0, 10));
- addPin(dataPin = new Pin(model, this, "D", definition.getCellWidth(), PinUsage.TRISTATE, 0, 30));
- addPin(rWPin = new Pin(model, this, "RW", 1, PinUsage.INPUT, 0, 50));
- addPin(clock = new Pin(model, this, "C", 1, PinUsage.INPUT, 0, 70));
-
- init();
- }
-
- public Pin getAddressPin()
- {
- return addrPin;
- }
-
- public Pin getDataPin()
- {
- return dataPin;
- }
-
- public Pin getReadWritePin()
- {
- return rWPin;
- }
-
- public Pin getClockPin()
- {
- return clock;
- }
-
- public void setCoreModelBinding(CoreWordAddressableMemory memory)
- {
- this.memory = memory;
- }
-
- public MainMemoryDefinition getDefinition()
- {
- return definition;
- }
-
- public CoreWordAddressableMemory getMemory()
- {
- return memory;
- }
-
- @Override
- public void render(GeneralGC gc, Rectangle visibleRegion)
- {
- symbolRenderer.render(gc, visibleRegion);
- outlineRenderer.render(gc, visibleRegion);
- }
-
- @Override
- public String getIDForSerializing(IdentifyParams idParams)
- {
- return "MemoryWA";
- }
-
- @Override
- public ModelMemoryWAParams getParamsForSerializing(IdentifyParams idParams)
- {
- ModelMemoryWAParams params = new ModelMemoryWAParams();
- params.addrBits = definition.getMemoryAddressBits();
- params.cellWidth = definition.getCellWidth();
- params.minAddr = definition.getMinimalAddress();
- params.maxAddr = definition.getMaximalAddress();
- return params;
- }
-
- static
- {
- LogicCoreAdapter.addComponentAdapter(new WordAddressableMemoryAdapter());
- IndirectModelComponentCreator.setComponentSupplier(ModelMemoryWA.class.getCanonicalName(), (m, p, n) ->
- {
- ModelMemoryWAParams params = JsonHandler.fromJsonTree(p, ModelMemoryWAParams.class);
- return new ModelMemoryWA(m, MainMemoryDefinition.create(params.addrBits, params.cellWidth, params.minAddr, params.maxAddr), n);
- });
- }
-
- public static class ModelMemoryWAParams
- {
- public int addrBits;
- public int cellWidth;
- public long minAddr;
- public long maxAddr;
- }
-}
--- /dev/null
+package net.mograsim.machine.standard.memory;
+
+import net.mograsim.logic.model.model.LogicModelModifiable;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.model.wires.PinUsage;
+import net.mograsim.machine.MainMemoryDefinition;
+import net.mograsim.machine.ModelMemory;
+
+public abstract class ModelWordAddressableMemory extends ModelMemory
+{
+ private final Pin addrPin, dataPin, rWPin, clock;
+ private CoreWordAddressableMemory memory;
+ private MainMemoryDefinition definition;
+
+ public ModelWordAddressableMemory(LogicModelModifiable model, MainMemoryDefinition definition, String name)
+ {
+ super(model, 100, 300, name, "RAM", false);
+ this.definition = definition;
+
+ addPin(addrPin = new Pin(model, this, "A", definition.getMemoryAddressBits(), PinUsage.INPUT, width, 20));
+ addPin(dataPin = new Pin(model, this, "D", definition.getCellWidth(), PinUsage.TRISTATE, width, 50));
+ addPin(rWPin = new Pin(model, this, "RW", 1, PinUsage.INPUT, width, 80));
+ addPin(clock = new Pin(model, this, "C", 1, PinUsage.INPUT, width, 110));
+
+ init();
+ }
+
+ public MainMemoryDefinition getDefinition()
+ {
+ return definition;
+ }
+
+ public Pin getAddressPin()
+ {
+ return addrPin;
+ }
+
+ public Pin getDataPin()
+ {
+ return dataPin;
+ }
+
+ public Pin getReadWritePin()
+ {
+ return rWPin;
+ }
+
+ public Pin getClockPin()
+ {
+ return clock;
+ }
+
+ public void setCoreModelBinding(CoreWordAddressableMemory memory)
+ {
+ this.memory = memory;
+ }
+
+ public CoreWordAddressableMemory getCoreMemory()
+ {
+ return memory;
+ }
+}
+++ /dev/null
-package net.mograsim.machine.standard.memory;
-
-import java.util.Map;
-
-import net.mograsim.logic.core.timeline.Timeline;
-import net.mograsim.logic.core.wires.CoreWire;
-import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
-import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
-import net.mograsim.logic.model.model.wires.Pin;
-import net.mograsim.logic.model.modeladapter.CoreModelParameters;
-import net.mograsim.logic.model.modeladapter.componentadapters.ComponentAdapter;
-
-public class WordAddressableMemoryAdapter implements ComponentAdapter<ModelMemoryWA>
-{
-
- @Override
- public Class<ModelMemoryWA> getSupportedClass()
- {
- return ModelMemoryWA.class;
- }
-
- @Override
- public void createAndLinkComponent(Timeline timeline, CoreModelParameters params, ModelMemoryWA modelComponent,
- Map<Pin, CoreWire> logicWiresPerPin)
- {
- ReadWriteEnd data = logicWiresPerPin.get(modelComponent.getDataPin()).createReadWriteEnd();
- ReadEnd address = logicWiresPerPin.get(modelComponent.getAddressPin()).createReadOnlyEnd();
- ReadEnd mode = logicWiresPerPin.get(modelComponent.getReadWritePin()).createReadOnlyEnd();
- ReadEnd clock = logicWiresPerPin.get(modelComponent.getClockPin()).createReadOnlyEnd();
- CoreWordAddressableMemory mem = new CoreWordAddressableMemory(timeline, 2, modelComponent.getDefinition(), data, mode, address, clock);
- modelComponent.setCoreModelBinding(mem);
- }
-
-}
{
"version": "0.1.0",
"map": {
- "MemoryWA": "resloader:MachineLoader:class:net.mograsim.machine.standard.memory.ModelMemoryWA"
- }
+ }
}
\ No newline at end of file
ReadWriteEnd clockI = clock.createReadWriteEnd();
@SuppressWarnings("unused")
- CoreWordAddressableMemory memory = new CoreWordAddressableMemory(t, 4, MainMemoryDefinition.create(64, 16, 4096L, Long.MAX_VALUE), data.createReadWriteEnd(),
+ CoreWordAddressableMemory memory = new CoreWordAddressableMemory(t, 4, new WordAddressableMemory(MainMemoryDefinition.create(64, 16, 4096L, Long.MAX_VALUE)), data.createReadWriteEnd(),
rW.createReadOnlyEnd(), address.createReadOnlyEnd(), clock.createReadOnlyEnd());
clockI.feedSignals(Bit.ONE);
import org.eclipse.jface.viewers.ILazyContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Table;
public class LazyTableViewer extends TableViewer
{
+ public static Color highlightColor = Display.getDefault().getSystemColor(SWT.COLOR_YELLOW);
public LazyTableViewer(Composite parent, int style)
{
super(table);
}
+ public void highlightRow(int index, boolean highlight)
+ {
+ Table table = getTable();
+ if (index < 0 || index >= table.getItemCount())
+ return;
+ table.getItem(index).setBackground(highlight ? highlightColor : table.getBackground());
+ System.out.println("Infinite loop!!!");
+ ((ILazyContentProvider) getContentProvider()).updateElement(index);
+ }
+
@Override
public void setContentProvider(IContentProvider provider)
{
super.setContentProvider(provider);
}
- public void refreshLazy()
+ @Override
+ public void refresh()
{
Table t = getTable();
ILazyContentProvider provider = (ILazyContentProvider) getContentProvider();
doClearAll();
int startIndex = t.getTopIndex();
int numRows = t.getBounds().height / t.getItemHeight();
- int endIndex = startIndex + numRows + 5;
+ int endIndex = Integer.min(startIndex + numRows + 5, doGetItemCount());
for (int i = startIndex; i < endIndex; i++)
{
createHeader(parent);
createViewer(parent);
- displaySettings.addObserver(() -> viewer.refreshLazy());
+ displaySettings.addObserver(() -> viewer.refresh());
setupContextBinding();
}
private MicroInstructionMemory memory;
private DisplaySettings displaySettings;
private InstructionTableContentProvider provider;
+ private int highlighted = 0;
@SuppressWarnings("unused")
@Override
viewerData.horizontalSpan = 3;
viewer.getTable().setLayoutData(viewerData);
- displaySettings.addObserver(() -> viewer.refreshLazy());
+ displaySettings.addObserver(() -> viewer.refresh());
MachineContext.getInstance().registerObserver(this);
}
+ public void highlight(int index)
+ {
+ viewer.highlightRow(highlighted, false);
+ viewer.highlightRow(index, true);
+ viewer.getTable().setTopIndex(index);
+ }
+
@SuppressWarnings("unused")
private void setupMenuButtons(Composite parent)
{
}
col.setEditingSupport(support);
col.setLabelProvider(provider);
+ col.getColumn().setToolTipText(miDef.getParameterDescription(index).orElse(""));
}
private TableViewerColumn createTableViewerColumn(String title, int bound)