Re-added Am2901 registers
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Sun, 6 Oct 2019 23:28:44 +0000 (01:28 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Sun, 6 Oct 2019 23:28:44 +0000 (01:28 +0200)
plugins/net.mograsim.logic.model.am2900/META-INF/MANIFEST.MF
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/AbstractAm2900MachineDefinition.java
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/NumberedRegister.java [deleted file]
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/QRegister.java [deleted file]
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/Am2901Register.java [new file with mode: 0644]
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/Am2901RegisterGroup.java [new file with mode: 0644]
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/NumberedRegister.java [new file with mode: 0644]
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/QRegister.java [new file with mode: 0644]

index 82e0a34..302a687 100644 (file)
@@ -10,6 +10,7 @@ Export-Package: net.mograsim.logic.model.am2900,
  net.mograsim.logic.model.am2900.components.am2910,
  net.mograsim.logic.model.am2900.machine,
  net.mograsim.logic.model.am2900.machine.registers,
+ net.mograsim.logic.model.am2900.machine.registers.am2901,
  net.mograsim.logic.model.examples
 Bundle-RequiredExecutionEnvironment: JavaSE-11
 Require-Bundle: org.eclipse.osgi,
index aed5356..3469b2d 100644 (file)
@@ -4,6 +4,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import net.mograsim.logic.model.am2900.machine.registers.am2901.Am2901RegisterGroup;
 import net.mograsim.logic.model.model.LogicModelModifiable;
 import net.mograsim.machine.ISASchema;
 import net.mograsim.machine.MachineDefinition;
@@ -26,7 +27,8 @@ public class AbstractAm2900MachineDefinition implements MachineDefinition
                // TODO MIR, IR, PC/BZ...
                unsortedRegisters = Collections.unmodifiableList(unsortedRegistersModifiable);
                List<RegisterGroup> registerGroupsModifiable = new ArrayList<>();
-               // TODO Am2901, Am2904, Am2910
+               registerGroupsModifiable.add(Am2901RegisterGroup.instance);
+               // TODO Am2904, Am2910
                registerGroups = Collections.unmodifiableList(registerGroupsModifiable);
        }
 
diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/NumberedRegister.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/NumberedRegister.java
deleted file mode 100644 (file)
index 7ca3d38..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-package net.mograsim.logic.model.am2900.machine.registers;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-
-import net.mograsim.machine.StandardRegister;
-
-public class NumberedRegister extends StandardRegister
-{
-       public static final List<NumberedRegister> instancesCorrectOrder;
-
-       static
-       {
-               List<NumberedRegister> instancesCorrectOrderModifiable = new ArrayList<>();
-               for (int i = 0; i < 16; i++)
-                       instancesCorrectOrderModifiable.add(new NumberedRegister(i));
-               instancesCorrectOrder = Collections.unmodifiableList(instancesCorrectOrderModifiable);
-       }
-
-       private final int index;
-       private final String indexBitstring;
-
-       private NumberedRegister(int i)
-       {
-               super("R" + i, new HashSet<>(Arrays.asList(new String[] { "R" + i, "Register #" + i, "Register " + i })), 16, new HashMap<>());
-               this.index = i;
-
-               StringBuilder sb = new StringBuilder();
-               sb.append((index & 0b1000) != 0 ? '1' : '0');
-               sb.append((index & 0b0100) != 0 ? '1' : '0');
-               sb.append((index & 0b0010) != 0 ? '1' : '0');
-               sb.append((index & 0b0001) != 0 ? '1' : '0');
-               this.indexBitstring = sb.toString();
-       }
-
-       public int getIndex()
-       {
-               return index;
-       }
-
-       public String getIndexAsBitstring()
-       {
-               return indexBitstring;
-       }
-}
\ No newline at end of file
diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/QRegister.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/QRegister.java
deleted file mode 100644 (file)
index b5d3540..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-package net.mograsim.logic.model.am2900.machine.registers;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-
-import net.mograsim.machine.StandardRegister;
-
-public class QRegister extends StandardRegister
-{
-       public static final QRegister instance = new QRegister();
-
-       private QRegister()
-       {
-               super("qreg", new HashSet<>(Arrays.asList(new String[] { "qreg", "Q register" })), 16, new HashMap<>());
-       }
-}
\ No newline at end of file
diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/Am2901Register.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/Am2901Register.java
new file mode 100644 (file)
index 0000000..c16a4d2
--- /dev/null
@@ -0,0 +1,21 @@
+package net.mograsim.logic.model.am2900.machine.registers.am2901;
+
+import net.mograsim.logic.model.am2900.machine.registers.Am2900Register;
+import net.mograsim.machine.registers.HighLevelStateBasedRegister;
+
+public class Am2901Register extends HighLevelStateBasedRegister implements Am2900Register
+{
+       public Am2901Register(String id, String cellSuffix, int logicWidthPerAm2901)
+       {
+               super(id, new int[] { logicWidthPerAm2901, logicWidthPerAm2901, logicWidthPerAm2901, logicWidthPerAm2901 },
+                               prefixWithAm2901s(cellSuffix));
+       }
+
+       private static String[] prefixWithAm2901s(String suffix)
+       {
+               String[] prefixed = new String[4];
+               for (int i = 0, b = 0; i < 4; i++, b += 4)
+                       prefixed[i] = String.format("am2901_%d-%d.%s", (b + 3), b, suffix);
+               return prefixed;
+       }
+}
\ No newline at end of file
diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/Am2901RegisterGroup.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/Am2901RegisterGroup.java
new file mode 100644 (file)
index 0000000..88766b1
--- /dev/null
@@ -0,0 +1,25 @@
+package net.mograsim.logic.model.am2900.machine.registers.am2901;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.mograsim.machine.registers.Register;
+import net.mograsim.machine.registers.SimpleRegisterGroup;
+
+public class Am2901RegisterGroup extends SimpleRegisterGroup
+{
+       public static final Am2901RegisterGroup instance = new Am2901RegisterGroup();
+
+       private Am2901RegisterGroup()
+       {
+               super("Am2901", getAllRegisters());
+       }
+
+       private static Register[] getAllRegisters()
+       {
+               List<Register> allRegistersModifiable = new ArrayList<>();
+               allRegistersModifiable.addAll(NumberedRegister.instancesCorrectOrder);
+               allRegistersModifiable.add(QRegister.instance);
+               return allRegistersModifiable.toArray(Register[]::new);
+       }
+}
\ No newline at end of file
diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/NumberedRegister.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/NumberedRegister.java
new file mode 100644 (file)
index 0000000..e98e594
--- /dev/null
@@ -0,0 +1,34 @@
+package net.mograsim.logic.model.am2900.machine.registers.am2901;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class NumberedRegister extends Am2901Register
+{
+       public static final List<NumberedRegister> instancesCorrectOrder;
+
+       static
+       {
+               List<NumberedRegister> instancesCorrectOrderModifiable = new ArrayList<>();
+               for (int i = 0; i < 16; i++)
+                       instancesCorrectOrderModifiable.add(new NumberedRegister(i));
+               instancesCorrectOrder = Collections.unmodifiableList(instancesCorrectOrderModifiable);
+       }
+
+       private NumberedRegister(int index)
+       {
+               super("R" + index, "regs.c" + getIndexAsBitstring(index) + ".q", 4);
+
+       }
+
+       private static String getIndexAsBitstring(int index)
+       {
+               StringBuilder sb = new StringBuilder();
+               sb.append((index & 0b1000) != 0 ? '1' : '0');
+               sb.append((index & 0b0100) != 0 ? '1' : '0');
+               sb.append((index & 0b0010) != 0 ? '1' : '0');
+               sb.append((index & 0b0001) != 0 ? '1' : '0');
+               return sb.toString();
+       }
+}
\ No newline at end of file
diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/QRegister.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/QRegister.java
new file mode 100644 (file)
index 0000000..4e426cc
--- /dev/null
@@ -0,0 +1,11 @@
+package net.mograsim.logic.model.am2900.machine.registers.am2901;
+
+public class QRegister extends Am2901Register
+{
+       public static final QRegister instance = new QRegister();
+
+       private QRegister()
+       {
+               super("Q", "qreg.q", 4);
+       }
+}
\ No newline at end of file