Merge branch 'development' of
authorFabian Stemmler <stemmler@in.tum.de>
Sun, 15 Sep 2019 11:10:22 +0000 (13:10 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Sun, 15 Sep 2019 11:10:22 +0000 (13:10 +0200)
https://gitlab.lrz.de/lrr-tum/students/eragp-misim-2019.git into
development

Conflicts:
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/standardComponentIDMapping.json

25 files changed:
net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVector.java
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/ModelAm2900MainMemory.java [new file with mode: 0644]
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/ModelAm2900MainMemoryAdapter.java [new file with mode: 0644]
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/ModelAm2900MicroInstructionMemory.java [new file with mode: 0644]
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/ModelAm2900MicroInstructionMemoryAdapter.java [new file with mode: 0644]
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MachineDefinition.java
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MicroInstructionDefinition.java
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/standardComponentIDMapping.json
net.mograsim.machine/META-INF/MANIFEST.MF
net.mograsim.machine/src/net/mograsim/machine/ModelMemory.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/mi/MicroInstruction.java
net.mograsim.machine/src/net/mograsim/machine/mi/MicroInstructionDefinition.java
net.mograsim.machine/src/net/mograsim/machine/mi/StandardMicroInstructionDefinition.java [deleted file]
net.mograsim.machine/src/net/mograsim/machine/mi/components/CoreMicroInstructionMemory.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/mi/components/ModelMicroInstructionMemory.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java
net.mograsim.machine/src/net/mograsim/machine/standard/memory/CoreWordAddressableMemory.java
net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelMemoryWA.java [deleted file]
net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelWordAddressableMemory.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemoryAdapter.java [deleted file]
net.mograsim.machine/src/net/mograsim/machine/standardComponentIDMapping.json
net.mograsim.machine/test/net/mograsim/machine/standard/memory/WordAddressableMemoryTest.java
net.mograsim.plugin.core/src/net/mograsim/plugin/tables/LazyTableViewer.java
net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryView.java
net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java

index 4d5f911..ee95756 100644 (file)
@@ -491,4 +491,15 @@ public final class BitVector implements StrictLogicType<BitVector>, Iterable<Bit
                        }
                };
        }
+
+       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);
+       }
 }
diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/ModelAm2900MainMemory.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/ModelAm2900MainMemory.java
new file mode 100644 (file)
index 0000000..a673bc4
--- /dev/null
@@ -0,0 +1,32 @@
+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";
+       }
+
+}
diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/ModelAm2900MainMemoryAdapter.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/ModelAm2900MainMemoryAdapter.java
new file mode 100644 (file)
index 0000000..5c4f52f
--- /dev/null
@@ -0,0 +1,36 @@
+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);
+       }
+}
diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/ModelAm2900MicroInstructionMemory.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/ModelAm2900MicroInstructionMemory.java
new file mode 100644 (file)
index 0000000..ffaaf51
--- /dev/null
@@ -0,0 +1,31 @@
+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";
+       }
+}
diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/ModelAm2900MicroInstructionMemoryAdapter.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/ModelAm2900MicroInstructionMemoryAdapter.java
new file mode 100644 (file)
index 0000000..fde7321
--- /dev/null
@@ -0,0 +1,36 @@
+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);
+       }
+
+}
index 134997d..0ac06ea 100644 (file)
@@ -1,10 +1,12 @@
 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;
@@ -13,6 +15,13 @@ public class Am2900MachineDefinition implements MachineDefinition
 {
        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()
index d61b751..12cbd37 100644 (file)
@@ -1,5 +1,8 @@
 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;
@@ -11,32 +14,45 @@ import net.mograsim.machine.mi.parameters.ParameterClassification;
 
 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()
@@ -50,4 +66,22 @@ public class Am2900MicroInstructionDefinition implements MicroInstructionDefinit
                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)));
+       }
 }
index 85391ac..e042b3c 100644 (file)
@@ -1,6 +1,8 @@
 {
   "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",
index d604d94..afbfc4c 100644 (file)
@@ -15,6 +15,7 @@ Export-Package: net.mograsim.machine,
  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
diff --git a/net.mograsim.machine/src/net/mograsim/machine/ModelMemory.java b/net.mograsim.machine/src/net/mograsim/machine/ModelMemory.java
new file mode 100644 (file)
index 0000000..4150318
--- /dev/null
@@ -0,0 +1,45 @@
+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);
+       }
+}
index 07a15d2..d88a8ef 100644 (file)
@@ -1,5 +1,6 @@
 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;
 
@@ -17,4 +18,13 @@ public interface MicroInstruction {
        {
                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;
+       }
 }
index 229c761..b9cd2ef 100644 (file)
@@ -1,7 +1,10 @@
 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;
@@ -30,6 +33,14 @@ public interface MicroInstructionDefinition
                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();
@@ -56,9 +67,6 @@ public interface MicroInstructionDefinition
                }
                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
diff --git a/net.mograsim.machine/src/net/mograsim/machine/mi/StandardMicroInstructionDefinition.java b/net.mograsim.machine/src/net/mograsim/machine/mi/StandardMicroInstructionDefinition.java
deleted file mode 100644 (file)
index 2def5e1..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-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];
-       }
-
-}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/mi/components/CoreMicroInstructionMemory.java b/net.mograsim.machine/src/net/mograsim/machine/mi/components/CoreMicroInstructionMemory.java
new file mode 100644 (file)
index 0000000..29793c5
--- /dev/null
@@ -0,0 +1,61 @@
+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);
+       }
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/mi/components/ModelMicroInstructionMemory.java b/net.mograsim.machine/src/net/mograsim/machine/mi/components/ModelMicroInstructionMemory.java
new file mode 100644 (file)
index 0000000..34e7e80
--- /dev/null
@@ -0,0 +1,55 @@
+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;
+       }
+}
index 54c275b..f4343bd 100644 (file)
@@ -15,20 +15,39 @@ public class MnemonicFamily implements ParameterClassification
        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();
@@ -41,20 +60,30 @@ public class MnemonicFamily implements ParameterClassification
                        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];
@@ -62,11 +91,11 @@ public class MnemonicFamily implements ParameterClassification
                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);
        }
        
index 8181283..addb34c 100644 (file)
@@ -9,6 +9,7 @@ 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.MainMemory;
 import net.mograsim.machine.MainMemoryDefinition;
 
 /**
@@ -16,7 +17,7 @@ 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;
@@ -28,10 +29,11 @@ public class CoreWordAddressableMemory extends BasicCoreComponent
         * @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)
@@ -47,7 +49,7 @@ public class CoreWordAddressableMemory extends BasicCoreComponent
                address.registerObserver(this);
                clock.registerObserver(this);
                
-               memory = new WordAddressableMemory(definition);
+               this.memory = memory;
        }
 
        @Override
diff --git a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelMemoryWA.java b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelMemoryWA.java
deleted file mode 100644 (file)
index 20f27fb..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-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;
-       }
-}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelWordAddressableMemory.java b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelWordAddressableMemory.java
new file mode 100644 (file)
index 0000000..7e5296d
--- /dev/null
@@ -0,0 +1,62 @@
+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;
+       }
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemoryAdapter.java b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemoryAdapter.java
deleted file mode 100644 (file)
index a227266..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-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);
-       }
-
-}
index 7570da8..8202b0c 100644 (file)
@@ -1,6 +1,5 @@
 {
   "version": "0.1.0",
   "map": {
-    "MemoryWA": "resloader:MachineLoader:class:net.mograsim.machine.standard.memory.ModelMemoryWA"
-  }
+   }
 }
\ No newline at end of file
index e23ec2d..02a4090 100644 (file)
@@ -31,7 +31,7 @@ class WordAddressableMemoryTest {
                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);
index e00742f..1b371e2 100644 (file)
@@ -4,11 +4,14 @@ import org.eclipse.jface.viewers.IContentProvider;
 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)
        {
@@ -25,6 +28,16 @@ public class LazyTableViewer extends TableViewer
                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)
        {
@@ -33,14 +46,15 @@ public class LazyTableViewer extends TableViewer
                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++)
                {
index 356428b..1bcc3bc 100644 (file)
@@ -46,7 +46,7 @@ public class MemoryView extends ViewPart implements ContextObserver
                createHeader(parent);
                createViewer(parent);
 
-               displaySettings.addObserver(() -> viewer.refreshLazy());
+               displaySettings.addObserver(() -> viewer.refresh());
 
                setupContextBinding();
        }
index 35b6933..68e8329 100644 (file)
@@ -40,6 +40,7 @@ public class InstructionView extends ViewPart implements ContextObserver
        private MicroInstructionMemory memory;
        private DisplaySettings displaySettings;
        private InstructionTableContentProvider provider;
+       private int highlighted = 0;
 
        @SuppressWarnings("unused")
        @Override
@@ -66,10 +67,17 @@ public class InstructionView extends ViewPart implements ContextObserver
                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)
        {
@@ -167,6 +175,7 @@ public class InstructionView extends ViewPart implements ContextObserver
                }
                col.setEditingSupport(support);
                col.setLabelProvider(provider);
+               col.getColumn().setToolTipText(miDef.getParameterDescription(index).orElse(""));
        }
 
        private TableViewerColumn createTableViewerColumn(String title, int bound)