Revisited some hardcoded components
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Mon, 2 Sep 2019 10:50:43 +0000 (12:50 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Mon, 2 Sep 2019 10:50:43 +0000 (12:50 +0200)
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIinc12.java
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIram5_12.java
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2904/GUIAm2904ShiftInstrDecode.java
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910RegCntr.java
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910SP.java

index a20745b..c3848d4 100644 (file)
@@ -47,7 +47,6 @@ public class GUIinc12 extends SimpleRectangularHardcodedGUIComponent
                {
                        Bit carry = Bit.ONE;
                        // TODO extract to helper. This code almost also exists in GUIAM2910RegCntr.
-                       // TODO maybe invert loop direction
                        for (int i = 11; i >= 0; i--)
                        {
                                Bit a = ABits[i];
index adce29a..7a1409e 100644 (file)
@@ -81,7 +81,6 @@ public class GUIram5_12 extends SimpleRectangularHardcodedGUIComponent
                for (int i = 0; i < 3; i++)
                        if (bits[i] == Z)
                                return -1;
-               // TODO maybe this is the wrong way around
                return (bits[0] == ONE ? 4 : 0) + (bits[1] == ONE ? 2 : 0) + (bits[2] == ONE ? 1 : 0);
        }
 
index 2a3ce4e..dae7ae4 100644 (file)
@@ -9,6 +9,7 @@ import static net.mograsim.logic.core.types.Bit.ZERO;
 import java.util.Map;
 
 import net.mograsim.logic.core.types.Bit;
+import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.core.wires.Wire.ReadEnd;
 import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
 import net.mograsim.logic.model.model.ViewModelModifiable;
@@ -70,9 +71,9 @@ public class GUIAm2904ShiftInstrDecode extends SimpleRectangularHardcodedGUIComp
        public Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
        {
                Bit _SE = readEnds.get("_SE").getValue();
-               Bit[] IBits = readEnds.get("I").getValues().getBits();
-               readWriteEnds.get("OEn").feedSignals(IBits[0].not().and(_SE.not()));
-               readWriteEnds.get("OE0").feedSignals(IBits[0].and(_SE.not()));
+               BitVector I = readEnds.get("I").getValues();
+               readWriteEnds.get("OEn").feedSignals(I.getMSBit(0).not().and(_SE.not()));
+               readWriteEnds.get("OE0").feedSignals(I.getMSBit(0).and(_SE.not()));
                if (_SE == Z || _SE == X)
                {
                        readWriteEnds.get("SIO0_MUX").feedSignals(X, X, X);
@@ -102,36 +103,24 @@ public class GUIAm2904ShiftInstrDecode extends SimpleRectangularHardcodedGUIComp
                        readWriteEnds.get("MC_EN").feedSignals(ZERO);
                        return null;
                }
-               // TODO move the following loop to BitVector.
-               int IAsInt = 0;
-               for (int i = 0; i < 5; i++)
-                       switch (IBits[4 - i])
-                       {
-                       case ONE:
-                               IAsInt |= 1 << i;
-                               break;
-                       case U:
-                               readWriteEnds.get("SIO0_MUX").feedSignals(U, U, U);
-                               readWriteEnds.get("SIOn_MUX").feedSignals(U, U, U);
-                               readWriteEnds.get("QIO0_MUX").feedSignals(U, U, U);
-                               readWriteEnds.get("QIOn_MUX").feedSignals(U, U, U);
-                               readWriteEnds.get("MC_MUX").feedSignals(U, U);
-                               readWriteEnds.get("MC_EN").feedSignals(U);
-                               return null;
-                       case X:
-                       case Z:
-                               readWriteEnds.get("SIO0_MUX").feedSignals(X, X, X);
-                               readWriteEnds.get("SIOn_MUX").feedSignals(X, X, X);
-                               readWriteEnds.get("QIO0_MUX").feedSignals(X, X, X);
-                               readWriteEnds.get("QIOn_MUX").feedSignals(X, X, X);
-                               readWriteEnds.get("MC_MUX").feedSignals(X, X);
-                               readWriteEnds.get("MC_EN").feedSignals(X);
-                               return null;
-                       case ZERO:
-                               break;
-                       default:
-                               throw new IllegalArgumentException("Unknown enum constant: " + IBits[i]);
-                       }
+               if (!I.isBinary())
+               {
+                       Bit val = null;
+                       for (Bit b : I.getBits())
+                               if (!b.isBinary())
+                               {
+                                       val = b;
+                                       break;
+                               }
+                       readWriteEnds.get("SIO0_MUX").feedSignals(val, val, val);
+                       readWriteEnds.get("SIOn_MUX").feedSignals(val, val, val);
+                       readWriteEnds.get("QIO0_MUX").feedSignals(val, val, val);
+                       readWriteEnds.get("QIOn_MUX").feedSignals(val, val, val);
+                       readWriteEnds.get("MC_MUX").feedSignals(val, val);
+                       readWriteEnds.get("MC_EN").feedSignals(val);
+                       return null;
+               }
+               int IAsInt = I.getUnsignedValue().intValue();
                if (IAsInt < 16)
                {
                        readWriteEnds.get("SIO0_MUX").feedSignals(X, X, X);
index 5a13ebc..00635bf 100644 (file)
@@ -61,7 +61,6 @@ public class GUIAm2910RegCntr extends SimpleRectangularHardcodedGUIComponent
                        {
                                Bit carry = Bit.ZERO;
                                // TODO extract to helper. This code almost also exists in GUIinc12.
-                               // TODO maybe invert loop direction
                                for (int i = 11; i >= 0; i--)
                                {
                                        Bit a = QC[i];
index fb449d2..0e89cca 100644 (file)
@@ -122,7 +122,6 @@ public class GUIAm2910SP extends SimpleRectangularHardcodedGUIComponent
                        return BitVector.of(X, 3);
                if (i == -2)
                        return BitVector.of(U, 3);
-               // TODO maybe this is the wrong way around
                return BitVector.of((i & 0b100) > 0 ? ONE : ZERO, (i & 0b10) > 0 ? ONE : ZERO, (i & 0b1) > 0 ? ONE : ZERO);
        }