return bitVector.toString();
}
- // TODO doesn't this belong to logic.ui?
+ // TODO doesn't this belong to logic.model?
public static ColorDefinition formatAsColor(ReadEnd end)
{
return formatAsColor(end == null ? null : end.getValues());
switch (bitVector.getLSBit(0))
{
case ONE:
- return Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.bit.one");
+ return Preferences.current().getColorDefinition("net.mograsim.logic.model.color.bit.one");
case U:
- return Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.bit.u");
+ return Preferences.current().getColorDefinition("net.mograsim.logic.model.color.bit.u");
case X:
- return Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.bit.x");
+ return Preferences.current().getColorDefinition("net.mograsim.logic.model.color.bit.x");
case Z:
- return Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.bit.z");
+ return Preferences.current().getColorDefinition("net.mograsim.logic.model.color.bit.z");
case ZERO:
- return Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.bit.zero");
+ return Preferences.current().getColorDefinition("net.mograsim.logic.model.color.bit.zero");
default:
throw new IllegalArgumentException("Unknown enum constant: " + bitVector.getLSBit(0));
}
<name>net.mograsim.logic.model.am2900</name>
<comment></comment>
<projects>
- <project>net.mograsim.logic.ui</project>
+ <project>net.mograsim.logic.model</project>
<project>SWTZoomableCanvas</project>
</projects>
<buildSpec>
"x": 5.0,
"y": 40.0
},
- "type": "class:net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder",
+ "type": "class:net.mograsim.logic.model.model.components.mi.nandbased.GUIhalfadder",
"params": {}
},
{
"x": 45.0,
"y": 7.5
},
- "type": "class:net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder",
+ "type": "class:net.mograsim.logic.model.model.components.mi.nandbased.GUIhalfadder",
"params": {}
},
{
"x": 57.5,
"y": 40.0
},
- "type": "class:net.mograsim.logic.ui.model.components.GUINandGate",
+ "type": "class:net.mograsim.logic.model.model.components.GUINandGate",
"params": {
"logicWidth": 1
}
"x": 10.0,
"y": 15.0
},
- "type": "class:net.mograsim.logic.ui.model.components.GUINandGate",
+ "type": "class:net.mograsim.logic.model.model.components.GUINandGate",
"params": {
"logicWidth": 1
}
"x": 40.0,
"y": 2.5
},
- "type": "class:net.mograsim.logic.ui.model.components.GUINandGate",
+ "type": "class:net.mograsim.logic.model.model.components.GUINandGate",
"params": {
"logicWidth": 1
}
"x": 40.0,
"y": 27.5
},
- "type": "class:net.mograsim.logic.ui.model.components.GUINandGate",
+ "type": "class:net.mograsim.logic.model.model.components.GUINandGate",
"params": {
"logicWidth": 1
}
"x": 65.0,
"y": 2.5
},
- "type": "class:net.mograsim.logic.ui.model.components.GUINandGate",
+ "type": "class:net.mograsim.logic.model.model.components.GUINandGate",
"params": {
"logicWidth": 1
}
"x": 4.0,
"y": 11.5
},
- "type": "class:net.mograsim.logic.ui.model.wires.WireCrossPoint",
+ "type": "class:net.mograsim.logic.model.model.wires.WireCrossPoint",
"params": {
"logicWidth": 1
}
"x": 4.0,
"y": 36.5
},
- "type": "class:net.mograsim.logic.ui.model.wires.WireCrossPoint",
+ "type": "class:net.mograsim.logic.model.model.wires.WireCrossPoint",
"params": {
"logicWidth": 1
}
"x": 34.0,
"y": 24.0
},
- "type": "class:net.mograsim.logic.ui.model.wires.WireCrossPoint",
+ "type": "class:net.mograsim.logic.model.model.wires.WireCrossPoint",
"params": {
"logicWidth": 1
}
net.mograsim.logic.model.model.components.mi.nandbased.am2901
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: net.mograsim.logic.model;bundle-version="0.1.0";visibility:=reexport
-Automatic-Module-Name: net.mograsim.logic.ui
+Automatic-Module-Name: net.mograsim.logic.model.am2900
Bundle-Vendor: Mograsim Team
-#Properties file for net.mograsim.logic.ui
+#Properties file for net.mograsim.logic.model.am2900
Bundle-Vendor = Mograsim Team
Bundle-Name = Mograsim Am2900 logic
\ No newline at end of file
--- /dev/null
+package net.mograsim.logic.model.am2900;
+
+import static net.mograsim.logic.model.am2900.TestUtil.*;
+import static net.mograsim.logic.model.am2900.TestableAm2901.Am2901_Dest.*;
+import static net.mograsim.logic.model.am2900.TestableAm2901.Am2901_Func.*;
+import static net.mograsim.logic.model.am2900.TestableAm2901.Am2901_Src.*;
+import static net.mograsim.logic.model.am2900.TestableAm2901.Register.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+import java.awt.Point;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+
+import net.mograsim.logic.model.am2900.TestableAm2901.Register;
+
+@DisplayName("Am2901 Tests")
+@TestMethodOrder(OrderAnnotation.class)
+public class Am2901Test
+{
+ private TestableAm2901 am2901;
+
+ @BeforeEach
+ void initialize()
+ {
+ createAndSetup();
+ setInputsToZero();
+ }
+
+ void createAndSetup()
+ {
+ am2901 = new TestableAm2901Impl();
+ am2901.setup();
+ }
+
+ void setRegistersToZero()
+ {
+ setInputsToZero();
+ for (Register r : Register.values())
+ {
+ setRegisterToZero(r);
+ }
+ }
+
+ void setRegisterToZero(Register r)
+ {
+ am2901.setD("0000");
+ am2901.setSrc(DZ);
+ am2901.setFunc(AND);
+ setRegOutput(r);
+
+ am2901.assertFullCycleSuccess();
+ }
+
+ void setRegOutput(Register r)
+ {
+ if (r == Q)
+ {
+ am2901.setDest(QREG);
+ } else
+ {
+ am2901.setReg_B(r.toBitString());
+ am2901.setDest(RAMF);
+ }
+ }
+
+ void setInputsToZero()
+ {
+ am2901.setCarryIn("0");
+ am2901.setQ_0("0");
+ am2901.setQ_3("0");
+ am2901.setRAM_0("0");
+ am2901.setRAM_3("0");
+ am2901.setReg_A("0000");
+ am2901.setReg_B("0000");
+ am2901.setD("0000");
+ am2901.setSrc(AB);
+ am2901.setFunc(ADD);
+ am2901.setDest(QREG);
+// am2901.setNotOutEnable("0"); TODO
+ am2901.clockOn(true);
+ am2901.assertRunSuccess();
+ }
+
+ @ParameterizedTest(name = "{0}")
+ @Order(1)
+ @DisplayName("Direct / high level access")
+ @EnumSource(Register.class)
+ void testDirectAccess(Register r)
+ {
+ assertEquals("UUUU", am2901.getDirectly(r));
+
+ am2901.setDirectly(r, "1011");
+
+ assertEquals("1011", am2901.getDirectly(r));
+ }
+
+ @ParameterizedTest(name = "{0}")
+ @Order(2)
+ @DisplayName("Setting each register to 0")
+ @EnumSource(Register.class)
+ void testSetToZero(Register r)
+ {
+ assertEquals("UUUU", am2901.getDirectly(r));
+
+ setRegisterToZero(r);
+
+ assertEquals("0000", am2901.getDirectly(r));
+ assertEquals("0000", am2901.getY());
+ assertEquals("0", am2901.getCarryOut());
+ assertEquals("0", am2901.getOverflow());
+ assertEquals("0", am2901.getSign());
+ assertEquals("1", am2901.getZero());
+ }
+
+ @Test
+ @Order(3)
+ @DisplayName("Setting all registers to 0")
+ void testSetAllToZero()
+ {
+ setRegistersToZero();
+
+ assertEquals("0000", am2901.getY());
+ assertEquals("0", am2901.getCarryOut());
+ assertEquals("0", am2901.getOverflow());
+ assertEquals("0", am2901.getSign());
+ assertEquals("1", am2901.getZero());
+ assertEquals("0", am2901.getQ_0());
+ assertEquals("0", am2901.getQ_3());
+ assertEquals("0", am2901.getRAM_0());
+ assertEquals("0", am2901.getRAM_3());
+
+ assertAll("register values", Register.stream().map(r -> () ->
+ {
+ assertEquals("0000", am2901.getDirectly(r), r.name());
+ }));
+ }
+
+ @Test
+ @Order(4)
+ @DisplayName("ADD operation")
+ void testADD()
+ {
+ am2901.setSrc(DA);
+ am2901.setFunc(ADD);
+ am2901.setDest(NOP);
+ am2901.setReg_A(r0.toBitString());
+
+ assertAll(getAll4BitPairs().map(xy -> () ->
+ {
+ am2901.setDirectly(r0, to4bitBin(xy.x));
+ am2901.setD(to4bitBin(xy.y));
+
+ am2901.assertFullCycleSuccess();
+
+ int res32Bit = xy.x + xy.y;
+ int res4Bit = res32Bit & 0b1111;
+ int res32Bit_sgn = signed4ToSigned32(xy.x) + signed4ToSigned32(xy.y);
+ int res4Bit_sgn = signed4ToSigned32(res32Bit_sgn);
+
+ assertAll("Result of " + xy.x + " + " + xy.y + " = " + res32Bit,
+ () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"),
+ () -> assertEquals(to1bitBin(res4Bit == 0), am2901.getZero(), " F=0"),
+ () -> assertEquals(to1bitBin(res4Bit & 0b1000), am2901.getSign(), " F3"),
+ () -> assertEquals(to1bitBin(res32Bit > 15), am2901.getCarryOut(), " Cn+4"),
+ () -> assertEquals(to1bitBin(res4Bit_sgn != res32Bit_sgn), am2901.getOverflow(), " OVR"));
+ }));
+ }
+
+ @Test
+ @Order(4)
+ @DisplayName("AND operation")
+ void testAND()
+ {
+ am2901.setSrc(DA);
+ am2901.setFunc(AND);
+ am2901.setDest(NOP);
+ am2901.setReg_A(r0.toBitString());
+
+ assertAll(getAll4BitPairs().map(xy -> () ->
+ {
+ am2901.setDirectly(r0, to4bitBin(xy.x));
+ am2901.setD(to4bitBin(xy.y));
+
+ am2901.assertFullCycleSuccess();
+
+ int res32Bit = xy.x & xy.y;
+
+ assertAll("Result of " + xy.x + " & " + xy.y + " = " + res32Bit,
+ () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"),
+ () -> assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), " F=0"),
+ () -> assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), " F3")
+// () -> assertEquals(to1bitBin(res32Bit), am2901.getCarryOut(), " Cn+4"), // TODO
+// () -> assertEquals(to1bitBin(res32Bit), am2901.getOverflow(), " OVR") // TODO
+ );
+ }));
+ }
+
+ @Test
+ @Order(4)
+ @DisplayName("OR operation")
+ void testOR()
+ {
+ am2901.setSrc(DA);
+ am2901.setFunc(OR);
+ am2901.setDest(NOP);
+ am2901.setReg_A(r0.toBitString());
+
+ assertAll(getAll4BitPairs().map(xy -> () ->
+ {
+ am2901.setDirectly(r0, to4bitBin(xy.x));
+ am2901.setD(to4bitBin(xy.y));
+
+ am2901.assertFullCycleSuccess();
+
+ int res32Bit = xy.x | xy.y;
+
+ assertAll("Result of " + xy.x + " | " + xy.y + " = " + res32Bit,
+ () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"),
+ () -> assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), " F=0"),
+ () -> assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), " F3")
+// () -> assertEquals(to1bitBin(res32Bit != 0b1111), am2901.getCarryOut(), " Cn+4"), // TODO
+// () -> assertEquals(to1bitBin(res32Bit != 0b1111), am2901.getOverflow(), " OVR") // TODO
+ );
+ }));
+ }
+
+ @Test
+ @Order(4)
+ @DisplayName("XOR operation")
+ void testXOR()
+ {
+ am2901.setSrc(DA);
+ am2901.setFunc(EXOR);
+ am2901.setDest(NOP);
+ am2901.setReg_A(r0.toBitString());
+
+ assertAll(getAll4BitPairs().map(xy -> () ->
+ {
+ am2901.setDirectly(r0, to4bitBin(xy.x));
+ am2901.setD(to4bitBin(xy.y));
+
+ am2901.assertFullCycleSuccess();
+
+ int res32Bit = xy.x ^ xy.y;
+
+ assertAll("Result of " + xy.x + " ^ " + xy.y + " = " + res32Bit,
+ () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"),
+ () -> assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), " F=0"),
+ () -> assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), " F3"));
+ }));
+ }
+
+ @Test
+ @Order(4)
+ @DisplayName("SUB operation")
+ void testSUB()
+ {
+ am2901.setSrc(DA);
+ am2901.setCarryIn("1");
+ am2901.setFunc(SUBR);
+ am2901.setDest(NOP);
+ am2901.setReg_A(r0.toBitString());
+
+ assertAll(getAll4BitPairs().map(xy -> () ->
+ {
+ am2901.setDirectly(r0, to4bitBin(xy.x));
+ am2901.setD(to4bitBin(xy.y));
+
+ am2901.assertFullCycleSuccess();
+
+ int res32Bit = xy.x - xy.y;
+ int res4Bit = res32Bit & 0b1111;
+ int res32Bit_sgn = signed4ToSigned32(xy.x) - signed4ToSigned32(xy.y);
+ int res4Bit_sgn = signed4ToSigned32(res32Bit_sgn);
+
+ assertAll("Result of " + xy.x + " - " + xy.y + " = " + res32Bit,
+ () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"),
+ () -> assertEquals(to1bitBin(res4Bit == 0), am2901.getZero(), " F=0"),
+ () -> assertEquals(to1bitBin(res4Bit & 0b1000), am2901.getSign(), " F3"),
+ () -> assertEquals(to1bitBin(xy.x >= xy.y), am2901.getCarryOut(), " Cn+4"),
+ () -> assertEquals(to1bitBin(res4Bit_sgn != res32Bit_sgn), am2901.getOverflow(), " OVR"));
+ }));
+ }
+
+ static Stream<Point> getAll4BitPairs()
+ {
+ return IntStream.range(0, 16).boxed().flatMap(x -> IntStream.range(0, 16).mapToObj(y -> new Point(x, y)));
+ }
+}
--- /dev/null
+package net.mograsim.logic.model.am2900;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.mograsim.logic.model.SimpleLogicUIStandalone;
+import net.mograsim.logic.model.model.ViewModelModifiable;
+import net.mograsim.logic.model.model.components.GUIComponent;
+import net.mograsim.logic.model.model.components.atomic.GUIAndGate;
+import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay;
+import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch;
+import net.mograsim.logic.model.model.components.atomic.GUINotGate;
+import net.mograsim.logic.model.model.components.atomic.TextComponent;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.model.wires.WireCrossPoint;
+import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
+import net.mograsim.logic.model.util.ModellingTool;
+
+public class Am2901Testbench
+{
+ public static void main(String[] args)
+ {
+ SimpleLogicUIStandalone.executeVisualisation(Am2901Testbench::createTestbench);
+ }
+
+ public static void createTestbench(ViewModelModifiable model)
+ {
+ GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "GUIAm2901");
+ ModellingTool tool = ModellingTool.createFor(model);
+
+ comp.moveTo(240, 0);
+
+ GUIManualSwitch enable = new GUIManualSwitch(model);
+ WireCrossPoint wcp0 = new WireCrossPoint(model, 1);
+ GUINotGate not1 = new GUINotGate(model, 1);
+ GUINotGate not2 = new GUINotGate(model, 1);
+ GUINotGate not3 = new GUINotGate(model, 1);
+ GUIAndGate and = new GUIAndGate(model, 1);
+ tool.connect(wcp0, enable, "");
+ tool.connect(wcp0, and, "A");
+ tool.connect(wcp0, not1, "A");
+ tool.connect(not1, not2, "Y", "A");
+ tool.connect(not2, not3, "Y", "A");
+ tool.connect(not3, and, "Y", "B");
+ enable.moveTo(20, -32.5);
+ wcp0.moveTo(35, -26);
+ not1.moveTo(50, -20);
+ not2.moveTo(80, -20);
+ not3.moveTo(110, -20);
+ and.moveTo(135, -30);
+ Pin last = and.getPin("Y");
+
+ // guess which pins are outputs and which are inputs
+ // TODO this code exists three times... but it seems too "hacky" to put it in a helper class
+ List<String> inputPinNames = new ArrayList<>();
+ List<String> outputPinNames = new ArrayList<>();
+ for (Pin p : comp.getPins().values())
+ if (p.getRelX() == 0)
+ inputPinNames.add(p.name);
+ else
+ outputPinNames.add(p.name);
+
+ for (int i = 0; i < inputPinNames.size(); i++)
+ {
+ double x = 55 + 70 * (i % 2);
+ double y = 10 * i;
+
+ WireCrossPoint wcp = new WireCrossPoint(model, 1);
+ GUIComponent d_ff = IndirectGUIComponentCreator.createComponent(model, "GUIdff");
+ GUIManualSwitch sw = new GUIManualSwitch(model);
+
+ tool.connect(last, wcp);
+ tool.connect(wcp, d_ff, "C");
+ tool.connect(sw, d_ff, "", "D");
+ tool.connect(d_ff, comp, "Q", inputPinNames.get(i));
+ last = wcp.getPin();
+
+ TextComponent label = new TextComponent(model, inputPinNames.get(i));
+
+ sw.moveTo(x, y + 7.5);
+ wcp.moveTo(160, y);
+ d_ff.moveTo(170, y);
+ label.moveTo(x - 25, y + 15);
+ }
+
+ for (int i = 0; i < outputPinNames.size(); i++)
+ {
+ double x = 300 + 75 * (i % 2);
+ double y = 10 * i - 2.5;
+ GUIBitDisplay bd = new GUIBitDisplay(model);
+ bd.moveTo(x, y);
+ tool.connect(bd.getInputPin(), comp, outputPinNames.get(i));
+
+ TextComponent label = new TextComponent(model, outputPinNames.get(i));
+ label.moveTo(x + 50, y + 8);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.mograsim.logic.model.am2900;
+
+public final class TestUtil
+{
+ private TestUtil()
+ {
+
+ }
+
+ /**
+ * Transforms the last four bits of an int to a string that contains the binary ('1' and '0') representation of the 4 bits
+ *
+ * @author Christian Femers
+ */
+ public static String to4bitBin(int x)
+ {
+ StringBuilder sb = new StringBuilder(4);
+ sb.append((x & 0b1000) == 0 ? '0' : '1');
+ sb.append((x & 0b0100) == 0 ? '0' : '1');
+ sb.append((x & 0b0010) == 0 ? '0' : '1');
+ sb.append((x & 0b0001) == 0 ? '0' : '1');
+ return sb.toString();
+ }
+
+ /**
+ * Transforms the given boolean to a string that contains the binary ('1' and '0') representation of the bit
+ *
+ * @author Christian Femers
+ */
+ public static String to1bitBin(boolean bitIsSet)
+ {
+ return bitIsSet ? "1" : "0";
+ }
+
+ /**
+ * Transforms the given int to a string that contains the binary ('1' and '0') representation of the int. "0" is only returned when the
+ * int is equal to zero.
+ *
+ * @author Christian Femers
+ */
+ public static String to1bitBin(int someInt)
+ {
+ return someInt != 0 ? "1" : "0";
+ }
+
+ /**
+ * Transforms a 4 bit signed integer (-8 to 7) to a int representing the same number. (Adding leading 1-bits if the 4 bit int is
+ * negative)
+ *
+ * @author Christian Femers
+ */
+ public static int signed4ToSigned32(int signed4bit)
+ {
+ if ((signed4bit & 0b1000) > 0)
+ return signed4bit | 0xFF_FF_FF_F0;
+ return signed4bit & 0x00_00_00_0F;
+ }
+
+ /**
+ * Transforms a 16 bit signed integer (-32768 to 32767 - a short) to a int representing the same number. (Adding leading 1-bits if the
+ * 16 bit int is negative)
+ *
+ * @author Christian Femers
+ */
+ public static int signed16ToSigned32(int signed16bit)
+ {
+ return (short) signed16bit;
+ }
+
+ /**
+ * Transforms the last n bits of an int to a string that contains the binary ('1' and '0') representation of the n bits
+ *
+ * @author Christian Femers
+ */
+ public static String toNbitString(int x, int n)
+ {
+ StringBuilder sb = new StringBuilder(n);
+ for (int i = 0; i < n; i++)
+ {
+ sb.append((x >> i) & 1);
+ }
+ return sb.reverse().toString();
+ }
+}
--- /dev/null
+package net.mograsim.logic.model.am2900;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Arrays;
+import java.util.stream.Stream;
+
+public interface TestableAm2901
+{
+ void setup();
+
+ Result run();
+
+ void setDest(Am2901_Dest dest);
+
+ void setFunc(Am2901_Func func);
+
+ void setSrc(Am2901_Src src);
+
+ void setReg_A(String val_4_bit);
+
+ void setReg_B(String val_4_bit);
+
+ void setCarryIn(String val_1_bit);
+
+ void setNotOutEnable(String val_1_bit);
+
+ void setD(String val_4_bit);
+
+ void setQ_0(String val_1_bit);
+
+ void setQ_3(String val_1_bit);
+
+ void setRAM_0(String val_1_bit);
+
+ void setRAM_3(String val_1_bit);
+
+ void clockOn(boolean isClockOn);
+
+ void setDirectly(Register r, String val_4_bit);
+
+ String getQ_0();
+
+ String getQ_3();
+
+ String getRAM_0();
+
+ String getRAM_3();
+
+ String getNotP();
+
+ String getNotG();
+
+ String getCarryOut();
+
+ String getSign();
+
+ String getZero();
+
+ String getOverflow();
+
+ String getY();
+
+ String getDirectly(Register r);
+
+ default void assertRunSuccess()
+ {
+ assertEquals(Result.SUCCESS, run());
+ }
+
+ default void assertFullCycleSuccess()
+ {
+ assertRunSuccess();
+ clockOn(false);
+ assertRunSuccess();
+ clockOn(true);
+ assertRunSuccess();
+ }
+
+ public enum Result
+ {
+ SUCCESS, OUT_OF_TIME, ERROR;
+ }
+
+ public enum Am2901_Dest
+ {
+ QREG, NOP, RAMA, RAMF, RAMQD, RAMD, RAMQU, RAMU;
+
+ public boolean doesShift()
+ {
+ return ordinal() >= 4;
+ }
+
+ public int getShiftDir()
+ {
+ return doesShift() ? (ordinal() < 6 ? -1 : 1) : 0;
+ }
+
+ public int getI7()
+ {
+ return this.ordinal() >> 1 & 1;
+ }
+ }
+
+ public enum Am2901_Func
+ {
+ ADD, SUBR, SUBS, OR, AND, NOTRS, EXOR, EXNOR;
+ }
+
+ public enum Am2901_Src
+ {
+ AQ, AB, ZQ, ZB, ZA, DA, DQ, DZ;
+ }
+
+ public enum Register
+ {
+ r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, rA, rB, rC, rD, rE, rF, Q;
+
+ public String toBitString()
+ {
+ if (this.ordinal() > 0xF)
+ throw new UnsupportedOperationException();
+ return TestUtil.to4bitBin(this.ordinal());
+ }
+
+ public static Stream<Register> stream()
+ {
+ return Arrays.stream(values());
+ }
+ }
+}
--- /dev/null
+package net.mograsim.logic.model.am2900;
+
+import static org.junit.jupiter.api.Assertions.fail;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Queue;
+import java.util.Set;
+import java.util.TreeSet;
+
+import net.mograsim.logic.core.components.BitDisplay;
+import net.mograsim.logic.core.components.ManualSwitch;
+import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.types.Bit;
+import net.mograsim.logic.core.types.BitVector;
+import net.mograsim.logic.core.types.BitVector.BitVectorMutator;
+import net.mograsim.logic.model.model.ViewModel;
+import net.mograsim.logic.model.model.ViewModelModifiable;
+import net.mograsim.logic.model.model.components.GUIComponent;
+import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay;
+import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch;
+import net.mograsim.logic.model.model.components.mi.nandbased.am2901.GUIAm2901;
+import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
+import net.mograsim.logic.model.model.wires.GUIWire;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.modeladapter.LogicModelParameters;
+import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter;
+
+public class TestableAm2901Impl implements TestableAm2901
+{
+ private GUIComponent am2901;
+ private Timeline timeline;
+ private ManualSwitch I8, I7, I6, I5, I4, I3, I2, I1, I0;
+ private ManualSwitch C;
+ private ManualSwitch Cn;
+ private ManualSwitch D1, D2, D3, D4;
+ private ManualSwitch A0, A1, A2, A3;
+ private ManualSwitch B0, B1, B2, B3;
+ private ManualSwitch IRAMn, IRAMn_3, IQn, IQn_3;
+ private BitDisplay Y1, Y2, Y3, Y4;
+ private BitDisplay F_0, Cn_4, OVR, F3;
+ private BitDisplay ORAMn, ORAMn_3, OQn, OQn_3;
+
+ private Set<String> wireDebugChangeSet;
+ private boolean debugWires = false;
+ public int debugEventThreshold = 10_000;
+ public int debugEventCount = 500;
+
+ private int eventCounter;
+
+ @Override
+ public Result run()
+ {
+ // Normal execution until completion or eventLimit
+ int eventLimit = debugEventThreshold;
+ eventCounter = 0;
+ debugWires = false;
+ while (eventCounter < eventLimit)
+ {
+ timeline.executeNext();
+ if (!timeline.hasNext())
+ {
+// System.out.println("run() took " + eventCounter + " events");
+ return Result.SUCCESS;
+ }
+ }
+ // Start debugging if event limit is reached
+ debugWires = true;
+ wireDebugChangeSet = new TreeSet<>();
+ Set<String> oldChangeSet;
+ // observe wire changes to detect, if we are really stuck in an endless loop
+ do
+ {
+ eventLimit += debugEventCount;
+ oldChangeSet = wireDebugChangeSet;
+ wireDebugChangeSet = new TreeSet<>();
+ while (eventCounter < eventLimit)
+ {
+ timeline.executeNext();
+ if (!timeline.hasNext())
+ {
+ // no endless loop, but more events needed than expected
+ System.out.println("run() took longer than expected: " + eventCounter);
+ return Result.SUCCESS;
+ }
+ }
+ } while (!oldChangeSet.equals(wireDebugChangeSet));
+ // if stuck, abort execution and print wires
+ System.err.print("Problematic Wire updates:");
+ wireDebugChangeSet.forEach(System.out::println);
+ System.err.println("run() failed: " + eventCounter);
+ return Result.OUT_OF_TIME;
+ }
+
+ @SuppressWarnings("unused")
+ @Override
+ public void setup()
+ {
+ // Create view model
+ ViewModelModifiable viewModel = new ViewModelModifiable();
+ // TODO replace with deserialized version as soon as high level states work for deserialized components
+ am2901 = new GUIAm2901(viewModel);
+// am2901 = IndirectGUIComponentCreator.createComponent(viewModel, "GUIAm2901");
+ // guess which pins are outputs and which are inputs
+ // TODO this code exists three times... but it seems too "hacky" to put it in a helper class
+ List<String> inputPinNames = new ArrayList<>();
+ List<String> outputPinNames = new ArrayList<>();
+ for (Pin p : am2901.getPins().values())
+ if (p.getRelX() == 0)
+ inputPinNames.add(p.name);
+ else
+ outputPinNames.add(p.name);
+ // Get switches
+ HashMap<String, GUIManualSwitch> idSwitchMap = new HashMap<>();
+ for (String id : inputPinNames)
+ {
+ GUIManualSwitch sw = new GUIManualSwitch(viewModel);
+ new GUIWire(viewModel, am2901.getPin(id), sw.getOutputPin());
+ idSwitchMap.put(id, sw);
+ }
+ // Get displays
+ HashMap<String, GUIBitDisplay> idDisplayMap = new HashMap<>();
+ for (String id : outputPinNames)
+ {
+ GUIBitDisplay bd = new GUIBitDisplay(viewModel);
+// bd.addRedrawListener(() -> System.out.println(id + " " + bd.getBitDisplay().getDisplayedValue()));
+ new GUIWire(viewModel, am2901.getPin(id), bd.getInputPin());
+ idDisplayMap.put(id, bd);
+ }
+ // Create logic model
+ LogicModelParameters params = new LogicModelParameters();
+ params.gateProcessTime = 50;
+ params.wireTravelTime = 10;
+ timeline = ViewLogicModelAdapter.convert(viewModel, params);
+ // Bind switches/displays to this test class
+ for (var entry : idSwitchMap.entrySet())
+ setField(entry.getKey().replaceAll("\\+|=", "_"), entry.getValue().getManualSwitch());
+ for (var entry : idDisplayMap.entrySet())
+ setField(entry.getKey().replaceAll("\\+|=", "_"), entry.getValue().getBitDisplay());
+
+ // Debug code
+ HashSet<GUIWire> wiresIncludingSubmodels = new HashSet<>();
+ Queue<ViewModel> modelsToIterate = new LinkedList<>();
+ modelsToIterate.add(viewModel);
+ while (modelsToIterate.size() > 0)
+ {
+ ViewModel model = modelsToIterate.poll();
+ wiresIncludingSubmodels.addAll(model.getWiresByName().values());
+ for (GUIComponent comp : model.getComponentsByName().values())
+ if (comp instanceof SubmodelComponent)
+ modelsToIterate.offer(((SubmodelComponent) comp).submodel);
+ }
+ wiresIncludingSubmodels.forEach(w -> w.addRedrawListener(() ->
+ {
+ if (debugWires)
+ {
+ wireDebugChangeSet.add(w.toString());
+ }
+ }));
+ timeline.addEventAddedListener(te -> eventCounter++);
+ }
+
+ @Override
+ public void setDest(Am2901_Dest dest)
+ {
+ var bits = of(dest.ordinal(), 3);
+ I8.setToValueOf(bits.getLSBit(2));
+ I7.setToValueOf(bits.getLSBit(1));
+ I6.setToValueOf(bits.getLSBit(0));
+ }
+
+ @Override
+ public void setFunc(Am2901_Func func)
+ {
+ var bits = of(func.ordinal(), 3);
+ I5.setToValueOf(bits.getLSBit(2));
+ I4.setToValueOf(bits.getLSBit(1));
+ I3.setToValueOf(bits.getLSBit(0));
+ }
+
+ @Override
+ public void setSrc(Am2901_Src src)
+ {
+ var bits = of(src.ordinal(), 3);
+ I2.setToValueOf(bits.getLSBit(2));
+ I1.setToValueOf(bits.getLSBit(1));
+ I0.setToValueOf(bits.getLSBit(0));
+ }
+
+ @Override
+ public void setReg_A(String val_4_bit)
+ {
+ var bits = BitVector.parse(val_4_bit);
+ A3.setToValueOf(bits.getLSBit(3));
+ A2.setToValueOf(bits.getLSBit(2));
+ A1.setToValueOf(bits.getLSBit(1));
+ A0.setToValueOf(bits.getLSBit(0));
+ }
+
+ @Override
+ public void setReg_B(String val_4_bit)
+ {
+ var bits = BitVector.parse(val_4_bit);
+ B3.setToValueOf(bits.getLSBit(3));
+ B2.setToValueOf(bits.getLSBit(2));
+ B1.setToValueOf(bits.getLSBit(1));
+ B0.setToValueOf(bits.getLSBit(0));
+ }
+
+ @Override
+ public void setCarryIn(String val_1_bit)
+ {
+ Cn.setToValueOf(Bit.parse(val_1_bit));
+ }
+
+ @Override
+ public void setNotOutEnable(String val_1_bit)
+ {
+ throw new UnsupportedOperationException(); // TODO
+ }
+
+ @Override
+ public void setD(String val_4_bit)
+ {
+ var bits = BitVector.parse(val_4_bit);
+ D4.setToValueOf(bits.getLSBit(3));
+ D3.setToValueOf(bits.getLSBit(2));
+ D2.setToValueOf(bits.getLSBit(1));
+ D1.setToValueOf(bits.getLSBit(0));
+ }
+
+ @Override
+ public void setQ_0(String val_1_bit)
+ {
+ IQn.setToValueOf(Bit.parse(val_1_bit));
+ }
+
+ @Override
+ public void setQ_3(String val_1_bit)
+ {
+ IQn_3.setToValueOf(Bit.parse(val_1_bit));
+ }
+
+ @Override
+ public void setRAM_0(String val_1_bit)
+ {
+ IRAMn.setToValueOf(Bit.parse(val_1_bit));
+ }
+
+ @Override
+ public void setRAM_3(String val_1_bit)
+ {
+ IRAMn_3.setToValueOf(Bit.parse(val_1_bit));
+ }
+
+ @Override
+ public void clockOn(boolean isClockOn)
+ {
+ C.setState(isClockOn);
+ }
+
+ @Override
+ public String getQ_0()
+ {
+ return OQn.getDisplayedValue().toString();
+ }
+
+ @Override
+ public String getQ_3()
+ {
+ return OQn_3.getDisplayedValue().toString();
+ }
+
+ @Override
+ public String getRAM_0()
+ {
+ return ORAMn.getDisplayedValue().toString();
+ }
+
+ @Override
+ public String getRAM_3()
+ {
+ return ORAMn_3.getDisplayedValue().toString();
+ }
+
+ @Override
+ public String getNotP()
+ {
+ throw new UnsupportedOperationException(); // TODO
+ }
+
+ @Override
+ public String getNotG()
+ {
+ throw new UnsupportedOperationException(); // TODO
+ }
+
+ @Override
+ public String getCarryOut()
+ {
+ return Cn_4.getDisplayedValue().toString();
+ }
+
+ @Override
+ public String getSign()
+ {
+ return F3.getDisplayedValue().toString();
+ }
+
+ @Override
+ public String getZero()
+ {
+ return F_0.getDisplayedValue().toString();
+ }
+
+ @Override
+ public String getOverflow()
+ {
+ return OVR.getDisplayedValue().toString();
+ }
+
+ @Override
+ public String getY()
+ {
+ var y3 = Y4.getDisplayedValue();
+ var y2 = Y3.getDisplayedValue();
+ var y1 = Y2.getDisplayedValue();
+ var y0 = Y1.getDisplayedValue();
+ return y3.concat(y2).concat(y1).concat(y0).toString();
+ }
+
+ private void setField(String name, Object value)
+ {
+ try
+ {
+ Field f = TestableAm2901Impl.class.getDeclaredField(name);
+ f.setAccessible(true);
+ f.set(this, Objects.requireNonNull(value));
+ }
+ catch (Exception e)
+ {
+ fail(e);
+ }
+ }
+
+ private static BitVector of(int value, int length)
+ {
+ BitVectorMutator mutator = BitVectorMutator.ofLength(length);
+ int val = value;
+ for (int i = length - 1; i >= 0; i--)
+ {
+ mutator.setMSBit(i, Bit.lastBitOf(val));
+ val >>>= 1;
+ }
+ return mutator.toBitVector();
+ }
+
+ @Override
+ public void setDirectly(Register r, String val_4_bit)
+ {
+ am2901.setHighLevelState(regToStateID(r), BitVector.parse(val_4_bit));
+ }
+
+ @Override
+ public String getDirectly(Register r)
+ {
+ return ((BitVector) am2901.getHighLevelState(regToStateID(r))).toString();
+ }
+
+ private static String regToStateID(Register r)
+ {
+ if (r == Register.Q)
+ return "qreg.q";
+ return "regs.c" + r.toBitString() + ".q";
+ }
+}
+++ /dev/null
-package net.mograsim.logic.ui.am2900;
-
-import static net.mograsim.logic.ui.am2900.TestUtil.*;
-import static net.mograsim.logic.ui.am2900.TestableAm2901.Am2901_Dest.*;
-import static net.mograsim.logic.ui.am2900.TestableAm2901.Am2901_Func.*;
-import static net.mograsim.logic.ui.am2900.TestableAm2901.Am2901_Src.*;
-import static net.mograsim.logic.ui.am2900.TestableAm2901.Register.*;
-import static org.junit.jupiter.api.Assertions.*;
-
-import java.awt.Point;
-import java.util.stream.IntStream;
-import java.util.stream.Stream;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.DisplayName;
-import org.junit.jupiter.api.Order;
-import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestMethodOrder;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.EnumSource;
-
-import net.mograsim.logic.ui.am2900.TestableAm2901.Register;
-
-@DisplayName("Am2901 Tests")
-@TestMethodOrder(OrderAnnotation.class)
-public class Am2901Test
-{
- private TestableAm2901 am2901;
-
- @BeforeEach
- void initialize()
- {
- createAndSetup();
- setInputsToZero();
- }
-
- void createAndSetup()
- {
- am2901 = new TestableAm2901Impl();
- am2901.setup();
- }
-
- void setRegistersToZero()
- {
- setInputsToZero();
- for (Register r : Register.values())
- {
- setRegisterToZero(r);
- }
- }
-
- void setRegisterToZero(Register r)
- {
- am2901.setD("0000");
- am2901.setSrc(DZ);
- am2901.setFunc(AND);
- setRegOutput(r);
-
- am2901.assertFullCycleSuccess();
- }
-
- void setRegOutput(Register r)
- {
- if (r == Q)
- {
- am2901.setDest(QREG);
- } else
- {
- am2901.setReg_B(r.toBitString());
- am2901.setDest(RAMF);
- }
- }
-
- void setInputsToZero()
- {
- am2901.setCarryIn("0");
- am2901.setQ_0("0");
- am2901.setQ_3("0");
- am2901.setRAM_0("0");
- am2901.setRAM_3("0");
- am2901.setReg_A("0000");
- am2901.setReg_B("0000");
- am2901.setD("0000");
- am2901.setSrc(AB);
- am2901.setFunc(ADD);
- am2901.setDest(QREG);
-// am2901.setNotOutEnable("0"); TODO
- am2901.clockOn(true);
- am2901.assertRunSuccess();
- }
-
- @ParameterizedTest(name = "{0}")
- @Order(1)
- @DisplayName("Direct / high level access")
- @EnumSource(Register.class)
- void testDirectAccess(Register r)
- {
- assertEquals("UUUU", am2901.getDirectly(r));
-
- am2901.setDirectly(r, "1011");
-
- assertEquals("1011", am2901.getDirectly(r));
- }
-
- @ParameterizedTest(name = "{0}")
- @Order(2)
- @DisplayName("Setting each register to 0")
- @EnumSource(Register.class)
- void testSetToZero(Register r)
- {
- assertEquals("UUUU", am2901.getDirectly(r));
-
- setRegisterToZero(r);
-
- assertEquals("0000", am2901.getDirectly(r));
- assertEquals("0000", am2901.getY());
- assertEquals("0", am2901.getCarryOut());
- assertEquals("0", am2901.getOverflow());
- assertEquals("0", am2901.getSign());
- assertEquals("1", am2901.getZero());
- }
-
- @Test
- @Order(3)
- @DisplayName("Setting all registers to 0")
- void testSetAllToZero()
- {
- setRegistersToZero();
-
- assertEquals("0000", am2901.getY());
- assertEquals("0", am2901.getCarryOut());
- assertEquals("0", am2901.getOverflow());
- assertEquals("0", am2901.getSign());
- assertEquals("1", am2901.getZero());
- assertEquals("0", am2901.getQ_0());
- assertEquals("0", am2901.getQ_3());
- assertEquals("0", am2901.getRAM_0());
- assertEquals("0", am2901.getRAM_3());
-
- assertAll("register values", Register.stream().map(r -> () ->
- {
- assertEquals("0000", am2901.getDirectly(r), r.name());
- }));
- }
-
- @Test
- @Order(4)
- @DisplayName("ADD operation")
- void testADD()
- {
- am2901.setSrc(DA);
- am2901.setFunc(ADD);
- am2901.setDest(NOP);
- am2901.setReg_A(r0.toBitString());
-
- assertAll(getAll4BitPairs().map(xy -> () ->
- {
- am2901.setDirectly(r0, to4bitBin(xy.x));
- am2901.setD(to4bitBin(xy.y));
-
- am2901.assertFullCycleSuccess();
-
- int res32Bit = xy.x + xy.y;
- int res4Bit = res32Bit & 0b1111;
- int res32Bit_sgn = signed4ToSigned32(xy.x) + signed4ToSigned32(xy.y);
- int res4Bit_sgn = signed4ToSigned32(res32Bit_sgn);
-
- assertAll("Result of " + xy.x + " + " + xy.y + " = " + res32Bit,
- () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"),
- () -> assertEquals(to1bitBin(res4Bit == 0), am2901.getZero(), " F=0"),
- () -> assertEquals(to1bitBin(res4Bit & 0b1000), am2901.getSign(), " F3"),
- () -> assertEquals(to1bitBin(res32Bit > 15), am2901.getCarryOut(), " Cn+4"),
- () -> assertEquals(to1bitBin(res4Bit_sgn != res32Bit_sgn), am2901.getOverflow(), " OVR"));
- }));
- }
-
- @Test
- @Order(4)
- @DisplayName("AND operation")
- void testAND()
- {
- am2901.setSrc(DA);
- am2901.setFunc(AND);
- am2901.setDest(NOP);
- am2901.setReg_A(r0.toBitString());
-
- assertAll(getAll4BitPairs().map(xy -> () ->
- {
- am2901.setDirectly(r0, to4bitBin(xy.x));
- am2901.setD(to4bitBin(xy.y));
-
- am2901.assertFullCycleSuccess();
-
- int res32Bit = xy.x & xy.y;
-
- assertAll("Result of " + xy.x + " & " + xy.y + " = " + res32Bit,
- () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"),
- () -> assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), " F=0"),
- () -> assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), " F3")
-// () -> assertEquals(to1bitBin(res32Bit), am2901.getCarryOut(), " Cn+4"), // TODO
-// () -> assertEquals(to1bitBin(res32Bit), am2901.getOverflow(), " OVR") // TODO
- );
- }));
- }
-
- @Test
- @Order(4)
- @DisplayName("OR operation")
- void testOR()
- {
- am2901.setSrc(DA);
- am2901.setFunc(OR);
- am2901.setDest(NOP);
- am2901.setReg_A(r0.toBitString());
-
- assertAll(getAll4BitPairs().map(xy -> () ->
- {
- am2901.setDirectly(r0, to4bitBin(xy.x));
- am2901.setD(to4bitBin(xy.y));
-
- am2901.assertFullCycleSuccess();
-
- int res32Bit = xy.x | xy.y;
-
- assertAll("Result of " + xy.x + " | " + xy.y + " = " + res32Bit,
- () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"),
- () -> assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), " F=0"),
- () -> assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), " F3")
-// () -> assertEquals(to1bitBin(res32Bit != 0b1111), am2901.getCarryOut(), " Cn+4"), // TODO
-// () -> assertEquals(to1bitBin(res32Bit != 0b1111), am2901.getOverflow(), " OVR") // TODO
- );
- }));
- }
-
- @Test
- @Order(4)
- @DisplayName("XOR operation")
- void testXOR()
- {
- am2901.setSrc(DA);
- am2901.setFunc(EXOR);
- am2901.setDest(NOP);
- am2901.setReg_A(r0.toBitString());
-
- assertAll(getAll4BitPairs().map(xy -> () ->
- {
- am2901.setDirectly(r0, to4bitBin(xy.x));
- am2901.setD(to4bitBin(xy.y));
-
- am2901.assertFullCycleSuccess();
-
- int res32Bit = xy.x ^ xy.y;
-
- assertAll("Result of " + xy.x + " ^ " + xy.y + " = " + res32Bit,
- () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"),
- () -> assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), " F=0"),
- () -> assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), " F3"));
- }));
- }
-
- @Test
- @Order(4)
- @DisplayName("SUB operation")
- void testSUB()
- {
- am2901.setSrc(DA);
- am2901.setCarryIn("1");
- am2901.setFunc(SUBR);
- am2901.setDest(NOP);
- am2901.setReg_A(r0.toBitString());
-
- assertAll(getAll4BitPairs().map(xy -> () ->
- {
- am2901.setDirectly(r0, to4bitBin(xy.x));
- am2901.setD(to4bitBin(xy.y));
-
- am2901.assertFullCycleSuccess();
-
- int res32Bit = xy.x - xy.y;
- int res4Bit = res32Bit & 0b1111;
- int res32Bit_sgn = signed4ToSigned32(xy.x) - signed4ToSigned32(xy.y);
- int res4Bit_sgn = signed4ToSigned32(res32Bit_sgn);
-
- assertAll("Result of " + xy.x + " - " + xy.y + " = " + res32Bit,
- () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"),
- () -> assertEquals(to1bitBin(res4Bit == 0), am2901.getZero(), " F=0"),
- () -> assertEquals(to1bitBin(res4Bit & 0b1000), am2901.getSign(), " F3"),
- () -> assertEquals(to1bitBin(xy.x >= xy.y), am2901.getCarryOut(), " Cn+4"),
- () -> assertEquals(to1bitBin(res4Bit_sgn != res32Bit_sgn), am2901.getOverflow(), " OVR"));
- }));
- }
-
- static Stream<Point> getAll4BitPairs()
- {
- return IntStream.range(0, 16).boxed().flatMap(x -> IntStream.range(0, 16).mapToObj(y -> new Point(x, y)));
- }
-}
+++ /dev/null
-package net.mograsim.logic.ui.am2900;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import net.mograsim.logic.model.SimpleLogicUIStandalone;
-import net.mograsim.logic.model.model.ViewModelModifiable;
-import net.mograsim.logic.model.model.components.GUIComponent;
-import net.mograsim.logic.model.model.components.atomic.GUIAndGate;
-import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay;
-import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch;
-import net.mograsim.logic.model.model.components.atomic.GUINotGate;
-import net.mograsim.logic.model.model.components.atomic.TextComponent;
-import net.mograsim.logic.model.model.wires.Pin;
-import net.mograsim.logic.model.model.wires.WireCrossPoint;
-import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
-import net.mograsim.logic.model.util.ModellingTool;
-
-public class Am2901Testbench
-{
- public static void main(String[] args)
- {
- SimpleLogicUIStandalone.executeVisualisation(Am2901Testbench::createTestbench);
- }
-
- public static void createTestbench(ViewModelModifiable model)
- {
- GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "GUIAm2901");
- ModellingTool tool = ModellingTool.createFor(model);
-
- comp.moveTo(240, 0);
-
- GUIManualSwitch enable = new GUIManualSwitch(model);
- WireCrossPoint wcp0 = new WireCrossPoint(model, 1);
- GUINotGate not1 = new GUINotGate(model, 1);
- GUINotGate not2 = new GUINotGate(model, 1);
- GUINotGate not3 = new GUINotGate(model, 1);
- GUIAndGate and = new GUIAndGate(model, 1);
- tool.connect(wcp0, enable, "");
- tool.connect(wcp0, and, "A");
- tool.connect(wcp0, not1, "A");
- tool.connect(not1, not2, "Y", "A");
- tool.connect(not2, not3, "Y", "A");
- tool.connect(not3, and, "Y", "B");
- enable.moveTo(20, -32.5);
- wcp0.moveTo(35, -26);
- not1.moveTo(50, -20);
- not2.moveTo(80, -20);
- not3.moveTo(110, -20);
- and.moveTo(135, -30);
- Pin last = and.getPin("Y");
-
- // guess which pins are outputs and which are inputs
- // TODO this code exists three times... but it seems too "hacky" to put it in a helper class
- List<String> inputPinNames = new ArrayList<>();
- List<String> outputPinNames = new ArrayList<>();
- for (Pin p : comp.getPins().values())
- if (p.getRelX() == 0)
- inputPinNames.add(p.name);
- else
- outputPinNames.add(p.name);
-
- for (int i = 0; i < inputPinNames.size(); i++)
- {
- double x = 55 + 70 * (i % 2);
- double y = 10 * i;
-
- WireCrossPoint wcp = new WireCrossPoint(model, 1);
- GUIComponent d_ff = IndirectGUIComponentCreator.createComponent(model, "GUIdff");
- GUIManualSwitch sw = new GUIManualSwitch(model);
-
- tool.connect(last, wcp);
- tool.connect(wcp, d_ff, "C");
- tool.connect(sw, d_ff, "", "D");
- tool.connect(d_ff, comp, "Q", inputPinNames.get(i));
- last = wcp.getPin();
-
- TextComponent label = new TextComponent(model, inputPinNames.get(i));
-
- sw.moveTo(x, y + 7.5);
- wcp.moveTo(160, y);
- d_ff.moveTo(170, y);
- label.moveTo(x - 25, y + 15);
- }
-
- for (int i = 0; i < outputPinNames.size(); i++)
- {
- double x = 300 + 75 * (i % 2);
- double y = 10 * i - 2.5;
- GUIBitDisplay bd = new GUIBitDisplay(model);
- bd.moveTo(x, y);
- tool.connect(bd.getInputPin(), comp, outputPinNames.get(i));
-
- TextComponent label = new TextComponent(model, outputPinNames.get(i));
- label.moveTo(x + 50, y + 8);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-package net.mograsim.logic.ui.am2900;
-
-public final class TestUtil
-{
- private TestUtil()
- {
-
- }
-
- /**
- * Transforms the last four bits of an int to a string that contains the binary ('1' and '0') representation of the 4 bits
- *
- * @author Christian Femers
- */
- public static String to4bitBin(int x)
- {
- StringBuilder sb = new StringBuilder(4);
- sb.append((x & 0b1000) == 0 ? '0' : '1');
- sb.append((x & 0b0100) == 0 ? '0' : '1');
- sb.append((x & 0b0010) == 0 ? '0' : '1');
- sb.append((x & 0b0001) == 0 ? '0' : '1');
- return sb.toString();
- }
-
- /**
- * Transforms the given boolean to a string that contains the binary ('1' and '0') representation of the bit
- *
- * @author Christian Femers
- */
- public static String to1bitBin(boolean bitIsSet)
- {
- return bitIsSet ? "1" : "0";
- }
-
- /**
- * Transforms the given int to a string that contains the binary ('1' and '0') representation of the int. "0" is only returned when the
- * int is equal to zero.
- *
- * @author Christian Femers
- */
- public static String to1bitBin(int someInt)
- {
- return someInt != 0 ? "1" : "0";
- }
-
- /**
- * Transforms a 4 bit signed integer (-8 to 7) to a int representing the same number. (Adding leading 1-bits if the 4 bit int is
- * negative)
- *
- * @author Christian Femers
- */
- public static int signed4ToSigned32(int signed4bit)
- {
- if ((signed4bit & 0b1000) > 0)
- return signed4bit | 0xFF_FF_FF_F0;
- return signed4bit & 0x00_00_00_0F;
- }
-
- /**
- * Transforms a 16 bit signed integer (-32768 to 32767 - a short) to a int representing the same number. (Adding leading 1-bits if the
- * 16 bit int is negative)
- *
- * @author Christian Femers
- */
- public static int signed16ToSigned32(int signed16bit)
- {
- return (short) signed16bit;
- }
-
- /**
- * Transforms the last n bits of an int to a string that contains the binary ('1' and '0') representation of the n bits
- *
- * @author Christian Femers
- */
- public static String toNbitString(int x, int n)
- {
- StringBuilder sb = new StringBuilder(n);
- for (int i = 0; i < n; i++)
- {
- sb.append((x >> i) & 1);
- }
- return sb.reverse().toString();
- }
-}
+++ /dev/null
-package net.mograsim.logic.ui.am2900;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.Arrays;
-import java.util.stream.Stream;
-
-public interface TestableAm2901
-{
- void setup();
-
- Result run();
-
- void setDest(Am2901_Dest dest);
-
- void setFunc(Am2901_Func func);
-
- void setSrc(Am2901_Src src);
-
- void setReg_A(String val_4_bit);
-
- void setReg_B(String val_4_bit);
-
- void setCarryIn(String val_1_bit);
-
- void setNotOutEnable(String val_1_bit);
-
- void setD(String val_4_bit);
-
- void setQ_0(String val_1_bit);
-
- void setQ_3(String val_1_bit);
-
- void setRAM_0(String val_1_bit);
-
- void setRAM_3(String val_1_bit);
-
- void clockOn(boolean isClockOn);
-
- void setDirectly(Register r, String val_4_bit);
-
- String getQ_0();
-
- String getQ_3();
-
- String getRAM_0();
-
- String getRAM_3();
-
- String getNotP();
-
- String getNotG();
-
- String getCarryOut();
-
- String getSign();
-
- String getZero();
-
- String getOverflow();
-
- String getY();
-
- String getDirectly(Register r);
-
- default void assertRunSuccess()
- {
- assertEquals(Result.SUCCESS, run());
- }
-
- default void assertFullCycleSuccess()
- {
- assertRunSuccess();
- clockOn(false);
- assertRunSuccess();
- clockOn(true);
- assertRunSuccess();
- }
-
- public enum Result
- {
- SUCCESS, OUT_OF_TIME, ERROR;
- }
-
- public enum Am2901_Dest
- {
- QREG, NOP, RAMA, RAMF, RAMQD, RAMD, RAMQU, RAMU;
-
- public boolean doesShift()
- {
- return ordinal() >= 4;
- }
-
- public int getShiftDir()
- {
- return doesShift() ? (ordinal() < 6 ? -1 : 1) : 0;
- }
-
- public int getI7()
- {
- return this.ordinal() >> 1 & 1;
- }
- }
-
- public enum Am2901_Func
- {
- ADD, SUBR, SUBS, OR, AND, NOTRS, EXOR, EXNOR;
- }
-
- public enum Am2901_Src
- {
- AQ, AB, ZQ, ZB, ZA, DA, DQ, DZ;
- }
-
- public enum Register
- {
- r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, rA, rB, rC, rD, rE, rF, Q;
-
- public String toBitString()
- {
- if (this.ordinal() > 0xF)
- throw new UnsupportedOperationException();
- return TestUtil.to4bitBin(this.ordinal());
- }
-
- public static Stream<Register> stream()
- {
- return Arrays.stream(values());
- }
- }
-}
+++ /dev/null
-package net.mograsim.logic.ui.am2900;
-
-import static org.junit.jupiter.api.Assertions.fail;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Objects;
-import java.util.Queue;
-import java.util.Set;
-import java.util.TreeSet;
-
-import net.mograsim.logic.core.components.BitDisplay;
-import net.mograsim.logic.core.components.ManualSwitch;
-import net.mograsim.logic.core.timeline.Timeline;
-import net.mograsim.logic.core.types.Bit;
-import net.mograsim.logic.core.types.BitVector;
-import net.mograsim.logic.core.types.BitVector.BitVectorMutator;
-import net.mograsim.logic.model.model.ViewModel;
-import net.mograsim.logic.model.model.ViewModelModifiable;
-import net.mograsim.logic.model.model.components.GUIComponent;
-import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay;
-import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch;
-import net.mograsim.logic.model.model.components.mi.nandbased.am2901.GUIAm2901;
-import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
-import net.mograsim.logic.model.model.wires.GUIWire;
-import net.mograsim.logic.model.model.wires.Pin;
-import net.mograsim.logic.model.modeladapter.LogicModelParameters;
-import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter;
-
-public class TestableAm2901Impl implements TestableAm2901
-{
- private GUIComponent am2901;
- private Timeline timeline;
- private ManualSwitch I8, I7, I6, I5, I4, I3, I2, I1, I0;
- private ManualSwitch C;
- private ManualSwitch Cn;
- private ManualSwitch D1, D2, D3, D4;
- private ManualSwitch A0, A1, A2, A3;
- private ManualSwitch B0, B1, B2, B3;
- private ManualSwitch IRAMn, IRAMn_3, IQn, IQn_3;
- private BitDisplay Y1, Y2, Y3, Y4;
- private BitDisplay F_0, Cn_4, OVR, F3;
- private BitDisplay ORAMn, ORAMn_3, OQn, OQn_3;
-
- private Set<String> wireDebugChangeSet;
- private boolean debugWires = false;
- public int debugEventThreshold = 10_000;
- public int debugEventCount = 500;
-
- private int eventCounter;
-
- @Override
- public Result run()
- {
- // Normal execution until completion or eventLimit
- int eventLimit = debugEventThreshold;
- eventCounter = 0;
- debugWires = false;
- while (eventCounter < eventLimit)
- {
- timeline.executeNext();
- if (!timeline.hasNext())
- {
-// System.out.println("run() took " + eventCounter + " events");
- return Result.SUCCESS;
- }
- }
- // Start debugging if event limit is reached
- debugWires = true;
- wireDebugChangeSet = new TreeSet<>();
- Set<String> oldChangeSet;
- // observe wire changes to detect, if we are really stuck in an endless loop
- do
- {
- eventLimit += debugEventCount;
- oldChangeSet = wireDebugChangeSet;
- wireDebugChangeSet = new TreeSet<>();
- while (eventCounter < eventLimit)
- {
- timeline.executeNext();
- if (!timeline.hasNext())
- {
- // no endless loop, but more events needed than expected
- System.out.println("run() took longer than expected: " + eventCounter);
- return Result.SUCCESS;
- }
- }
- } while (!oldChangeSet.equals(wireDebugChangeSet));
- // if stuck, abort execution and print wires
- System.err.print("Problematic Wire updates:");
- wireDebugChangeSet.forEach(System.out::println);
- System.err.println("run() failed: " + eventCounter);
- return Result.OUT_OF_TIME;
- }
-
- @SuppressWarnings("unused")
- @Override
- public void setup()
- {
- // Create view model
- ViewModelModifiable viewModel = new ViewModelModifiable();
- // TODO replace with deserialized version as soon as high level states work for deserialized components
- am2901 = new GUIAm2901(viewModel);
-// am2901 = IndirectGUIComponentCreator.createComponent(viewModel, "GUIAm2901");
- // guess which pins are outputs and which are inputs
- // TODO this code exists three times... but it seems too "hacky" to put it in a helper class
- List<String> inputPinNames = new ArrayList<>();
- List<String> outputPinNames = new ArrayList<>();
- for (Pin p : am2901.getPins().values())
- if (p.getRelX() == 0)
- inputPinNames.add(p.name);
- else
- outputPinNames.add(p.name);
- // Get switches
- HashMap<String, GUIManualSwitch> idSwitchMap = new HashMap<>();
- for (String id : inputPinNames)
- {
- GUIManualSwitch sw = new GUIManualSwitch(viewModel);
- new GUIWire(viewModel, am2901.getPin(id), sw.getOutputPin());
- idSwitchMap.put(id, sw);
- }
- // Get displays
- HashMap<String, GUIBitDisplay> idDisplayMap = new HashMap<>();
- for (String id : outputPinNames)
- {
- GUIBitDisplay bd = new GUIBitDisplay(viewModel);
-// bd.addRedrawListener(() -> System.out.println(id + " " + bd.getBitDisplay().getDisplayedValue()));
- new GUIWire(viewModel, am2901.getPin(id), bd.getInputPin());
- idDisplayMap.put(id, bd);
- }
- // Create logic model
- LogicModelParameters params = new LogicModelParameters();
- params.gateProcessTime = 50;
- params.wireTravelTime = 10;
- timeline = ViewLogicModelAdapter.convert(viewModel, params);
- // Bind switches/displays to this test class
- for (var entry : idSwitchMap.entrySet())
- setField(entry.getKey().replaceAll("\\+|=", "_"), entry.getValue().getManualSwitch());
- for (var entry : idDisplayMap.entrySet())
- setField(entry.getKey().replaceAll("\\+|=", "_"), entry.getValue().getBitDisplay());
-
- // Debug code
- HashSet<GUIWire> wiresIncludingSubmodels = new HashSet<>();
- Queue<ViewModel> modelsToIterate = new LinkedList<>();
- modelsToIterate.add(viewModel);
- while (modelsToIterate.size() > 0)
- {
- ViewModel model = modelsToIterate.poll();
- wiresIncludingSubmodels.addAll(model.getWiresByName().values());
- for (GUIComponent comp : model.getComponentsByName().values())
- if (comp instanceof SubmodelComponent)
- modelsToIterate.offer(((SubmodelComponent) comp).submodel);
- }
- wiresIncludingSubmodels.forEach(w -> w.addRedrawListener(() ->
- {
- if (debugWires)
- {
- wireDebugChangeSet.add(w.toString());
- }
- }));
- timeline.addEventAddedListener(te -> eventCounter++);
- }
-
- @Override
- public void setDest(Am2901_Dest dest)
- {
- var bits = of(dest.ordinal(), 3);
- I8.setToValueOf(bits.getLSBit(2));
- I7.setToValueOf(bits.getLSBit(1));
- I6.setToValueOf(bits.getLSBit(0));
- }
-
- @Override
- public void setFunc(Am2901_Func func)
- {
- var bits = of(func.ordinal(), 3);
- I5.setToValueOf(bits.getLSBit(2));
- I4.setToValueOf(bits.getLSBit(1));
- I3.setToValueOf(bits.getLSBit(0));
- }
-
- @Override
- public void setSrc(Am2901_Src src)
- {
- var bits = of(src.ordinal(), 3);
- I2.setToValueOf(bits.getLSBit(2));
- I1.setToValueOf(bits.getLSBit(1));
- I0.setToValueOf(bits.getLSBit(0));
- }
-
- @Override
- public void setReg_A(String val_4_bit)
- {
- var bits = BitVector.parse(val_4_bit);
- A3.setToValueOf(bits.getLSBit(3));
- A2.setToValueOf(bits.getLSBit(2));
- A1.setToValueOf(bits.getLSBit(1));
- A0.setToValueOf(bits.getLSBit(0));
- }
-
- @Override
- public void setReg_B(String val_4_bit)
- {
- var bits = BitVector.parse(val_4_bit);
- B3.setToValueOf(bits.getLSBit(3));
- B2.setToValueOf(bits.getLSBit(2));
- B1.setToValueOf(bits.getLSBit(1));
- B0.setToValueOf(bits.getLSBit(0));
- }
-
- @Override
- public void setCarryIn(String val_1_bit)
- {
- Cn.setToValueOf(Bit.parse(val_1_bit));
- }
-
- @Override
- public void setNotOutEnable(String val_1_bit)
- {
- throw new UnsupportedOperationException(); // TODO
- }
-
- @Override
- public void setD(String val_4_bit)
- {
- var bits = BitVector.parse(val_4_bit);
- D4.setToValueOf(bits.getLSBit(3));
- D3.setToValueOf(bits.getLSBit(2));
- D2.setToValueOf(bits.getLSBit(1));
- D1.setToValueOf(bits.getLSBit(0));
- }
-
- @Override
- public void setQ_0(String val_1_bit)
- {
- IQn.setToValueOf(Bit.parse(val_1_bit));
- }
-
- @Override
- public void setQ_3(String val_1_bit)
- {
- IQn_3.setToValueOf(Bit.parse(val_1_bit));
- }
-
- @Override
- public void setRAM_0(String val_1_bit)
- {
- IRAMn.setToValueOf(Bit.parse(val_1_bit));
- }
-
- @Override
- public void setRAM_3(String val_1_bit)
- {
- IRAMn_3.setToValueOf(Bit.parse(val_1_bit));
- }
-
- @Override
- public void clockOn(boolean isClockOn)
- {
- C.setState(isClockOn);
- }
-
- @Override
- public String getQ_0()
- {
- return OQn.getDisplayedValue().toString();
- }
-
- @Override
- public String getQ_3()
- {
- return OQn_3.getDisplayedValue().toString();
- }
-
- @Override
- public String getRAM_0()
- {
- return ORAMn.getDisplayedValue().toString();
- }
-
- @Override
- public String getRAM_3()
- {
- return ORAMn_3.getDisplayedValue().toString();
- }
-
- @Override
- public String getNotP()
- {
- throw new UnsupportedOperationException(); // TODO
- }
-
- @Override
- public String getNotG()
- {
- throw new UnsupportedOperationException(); // TODO
- }
-
- @Override
- public String getCarryOut()
- {
- return Cn_4.getDisplayedValue().toString();
- }
-
- @Override
- public String getSign()
- {
- return F3.getDisplayedValue().toString();
- }
-
- @Override
- public String getZero()
- {
- return F_0.getDisplayedValue().toString();
- }
-
- @Override
- public String getOverflow()
- {
- return OVR.getDisplayedValue().toString();
- }
-
- @Override
- public String getY()
- {
- var y3 = Y4.getDisplayedValue();
- var y2 = Y3.getDisplayedValue();
- var y1 = Y2.getDisplayedValue();
- var y0 = Y1.getDisplayedValue();
- return y3.concat(y2).concat(y1).concat(y0).toString();
- }
-
- private void setField(String name, Object value)
- {
- try
- {
- Field f = TestableAm2901Impl.class.getDeclaredField(name);
- f.setAccessible(true);
- f.set(this, Objects.requireNonNull(value));
- }
- catch (Exception e)
- {
- fail(e);
- }
- }
-
- private static BitVector of(int value, int length)
- {
- BitVectorMutator mutator = BitVectorMutator.ofLength(length);
- int val = value;
- for (int i = length - 1; i >= 0; i--)
- {
- mutator.setMSBit(i, Bit.lastBitOf(val));
- val >>>= 1;
- }
- return mutator.toBitVector();
- }
-
- @Override
- public void setDirectly(Register r, String val_4_bit)
- {
- am2901.setHighLevelState(regToStateID(r), BitVector.parse(val_4_bit));
- }
-
- @Override
- public String getDirectly(Register r)
- {
- return ((BitVector) am2901.getHighLevelState(regToStateID(r))).toString();
- }
-
- private static String regToStateID(Register r)
- {
- if (r == Register.Q)
- return "qreg.q";
- return "regs.c" + r.toBitString() + ".q";
- }
-}
Require-Bundle: net.mograsim.logic.model;bundle-version="0.1.0",
net.mograsim.preferences;bundle-version="0.1.0"
Bundle-RequiredExecutionEnvironment: JavaSE-11
-Automatic-Module-Name: net.mograsim.logic.ui
+Automatic-Module-Name: net.mograsim.logic.model.editor
Bundle-Vendor: Mograsim Team
addZoomedRenderer(gc ->
{
Rectangle visibleRegion = new Rectangle(-offX / zoom, -offY / zoom, gW / zoom, gH / zoom);
- Color background = Preferences.current().getColor("net.mograsim.logic.ui.color.background");
+ Color background = Preferences.current().getColor("net.mograsim.logic.model.color.background");
if (background != null)
setBackground(background);// this.setBackground, not gc.setBackground to have the background fill the
// canvas
net.mograsim.logic.core;bundle-version="0.1.0";visibility:=reexport,
com.google.gson;bundle-version="2.8.2";visibility:=reexport,
net.mograsim.preferences;bundle-version="0.1.0"
-Automatic-Module-Name: net.mograsim.logic.ui
+Automatic-Module-Name: net.mograsim.logic.model
Bundle-Vendor: Mograsim Team
-#Properties file for net.mograsim.logic.ui
+#Properties file for net.mograsim.logic.model
Bundle-Vendor = Mograsim Team
Bundle-Name = Mograsim logic user interface
\ No newline at end of file
LogicUIRenderer renderer = new LogicUIRenderer(model);
addZoomedRenderer(gc ->
{
- Color background = Preferences.current().getColor("net.mograsim.logic.ui.color.background");
+ Color background = Preferences.current().getColor("net.mograsim.logic.model.color.background");
if (background != null)
setBackground(background);// this.setBackground, not gc.setBackground to have the background fill the canvas
renderer.render(gc, new Rectangle(-offX / zoom, -offY / zoom, gW / zoom, gH / zoom));
@Override
public void render(GeneralGC gc, Rectangle visibleRegion)
{
- Color foreground = Preferences.current().getColor("net.mograsim.logic.ui.color.foreground");
+ Color foreground = Preferences.current().getColor("net.mograsim.logic.model.color.foreground");
if (foreground != null)
gc.setForeground(foreground);
gc.drawRectangle(getBounds());
Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle());
gc.setFont(labelFont);
Point textExtent = gc.textExtent(label);
- Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text");
+ Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text");
if (textColor != null)
gc.setForeground(textColor);
gc.drawText(label, getPosX() + (width - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true);
public void render(GeneralGC gc, Rectangle visibleRegion)
{
// TODO maybe draw switch state too?
- Color foreground = Preferences.current().getColor("net.mograsim.logic.ui.color.foreground");
+ Color foreground = Preferences.current().getColor("net.mograsim.logic.model.color.foreground");
if (foreground != null)
gc.setForeground(foreground);
gc.drawRectangle(getBounds());
Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle());
gc.setFont(labelFont);
Point textExtent = gc.textExtent(label);
- Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text");
+ Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text");
if (textColor != null)
gc.setForeground(textColor);
gc.drawText(label, getPosX() + (width - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true);
@Override
public void render(GeneralGC gc, Rectangle visibleRegion)
{
- Color foreground = Preferences.current().getColor("net.mograsim.logic.ui.color.foreground");
+ Color foreground = Preferences.current().getColor("net.mograsim.logic.model.color.foreground");
if (foreground != null)
gc.setForeground(foreground);
double height = (getPins().size() - 1) * pinDistance;
Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle());
gc.setFont(labelFont);
Point textExtent = gc.textExtent(label);
- Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text");
+ Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text");
if (textColor != null)
gc.setForeground(textColor);
gc.drawText(label, getPosX() + (rectWidth - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true);
Point textExtent = gc.textExtent(text);
setSize(textExtent.x, textExtent.y);
- Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text");
+ Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text");
if (textColor != null)
gc.setForeground(textColor);
gc.drawText(text, getPosX(), getPosY(), true);
@Override
protected void renderOutline(GeneralGC gc, Rectangle visibleRegion)
{
- Color foreground = Preferences.current().getColor("net.mograsim.logic.ui.color.foreground");
+ Color foreground = Preferences.current().getColor("net.mograsim.logic.model.color.foreground");
if (foreground != null)
gc.setForeground(foreground);
gc.drawRectangle(getBounds());
@Override
public void render(GeneralGC gc, Rectangle visibleRegion)
{
- ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.foreground");
+ ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.model.color.foreground");
if (fg != null)
gc.setForeground(ColorManager.current().toColor(fg));
gc.drawRectangle(component.getBounds());
{
Font oldFont = gc.getFont();
gc.setFont(new Font(oldFont.getName(), params.fontHeight, oldFont.getStyle()));
- ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.text");
+ ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.model.color.text");
if (fg != null)
gc.setForeground(ColorManager.current().toColor(fg));
Point idSize = gc.textExtent(params.text);
@Override
public void render(GeneralGC gc, Rectangle visibleRegion)
{
- ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.text");
+ ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.model.color.text");
if (fg != null)
gc.setForeground(ColorManager.current().toColor(fg));
Point idSize = gc.textExtent(id);
Font oldFont = gc.getFont();
gc.setFont(new Font(oldFont.getName(), params.centerTextHeight, oldFont.getStyle()));
Point textExtent = gc.textExtent(params.centerText);
- Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text");
+ Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text");
if (textColor != null)
gc.setForeground(textColor);
gc.drawText(params.centerText, posX + (width - textExtent.x) / 2, posY + (height - textExtent.y) / 2, true);
<name>net.mograsim.plugin.core</name>
<comment></comment>
<projects>
- <project>net.mograsim.logic.ui</project>
- <project>net.mograsim.logic.ui.am2900</project>
+ <project>net.mograsim.logic.model</project>
+ <project>net.mograsim.logic.model.am2900</project>
</projects>
<buildSpec>
<buildCommand>
</themeElementCategory>
<themeElementCategory
class="net.mograsim.plugin.SimulationPreview"
- id="net.mograsim.logic.ui"
+ id="net.mograsim.logic.model"
label="%themeElementCategory.label.0"
parentId="net.mograsim.plugin.mograsim">
</themeElementCategory>
<colorDefinition
- categoryId="net.mograsim.logic.ui"
- id="net.mograsim.logic.ui.color.background"
+ categoryId="net.mograsim.logic.model"
+ id="net.mograsim.logic.model.color.background"
isEditable="true"
label="%colorDefinition.label"
value="COLOR_WHITE">
</description>
</colorDefinition>
<colorDefinition
- categoryId="net.mograsim.logic.ui"
- id="net.mograsim.logic.ui.color.foreground"
+ categoryId="net.mograsim.logic.model"
+ id="net.mograsim.logic.model.color.foreground"
isEditable="true"
label="%colorDefinition.label.0"
value="COLOR_BLACK">
</colorDefinition>
<colorDefinition
- categoryId="net.mograsim.logic.ui"
- id="net.mograsim.logic.ui.color.text"
+ categoryId="net.mograsim.logic.model"
+ id="net.mograsim.logic.model.color.text"
label="%colorDefinition.label.10"
value="COLOR_BLACK">
</colorDefinition>
<colorDefinition
- categoryId="net.mograsim.logic.ui"
- id="net.mograsim.logic.ui.color.bit.one"
+ categoryId="net.mograsim.logic.model"
+ id="net.mograsim.logic.model.color.bit.one"
isEditable="true"
label="%colorDefinition.label.5"
value="COLOR_GREEN">
</colorDefinition>
<colorDefinition
- categoryId="net.mograsim.logic.ui"
- id="net.mograsim.logic.ui.color.bit.u"
+ categoryId="net.mograsim.logic.model"
+ id="net.mograsim.logic.model.color.bit.u"
isEditable="true"
label="%colorDefinition.label.6"
value="COLOR_CYAN">
</colorDefinition>
<colorDefinition
- categoryId="net.mograsim.logic.ui"
- id="net.mograsim.logic.ui.color.bit.x"
+ categoryId="net.mograsim.logic.model"
+ id="net.mograsim.logic.model.color.bit.x"
isEditable="true"
label="%colorDefinition.label.7"
value="COLOR_RED">
</colorDefinition>
<colorDefinition
- categoryId="net.mograsim.logic.ui"
- id="net.mograsim.logic.ui.color.bit.z"
+ categoryId="net.mograsim.logic.model"
+ id="net.mograsim.logic.model.color.bit.z"
isEditable="true"
label="%colorDefinition.label.8"
value="COLOR_YELLOW">
</colorDefinition>
<colorDefinition
- categoryId="net.mograsim.logic.ui"
- id="net.mograsim.logic.ui.color.bit.zero"
+ categoryId="net.mograsim.logic.model"
+ id="net.mograsim.logic.model.color.bit.zero"
isEditable="true"
label="%colorDefinition.label.9"
value="COLOR_GRAY">
<name>net.mograsim.plugin.feature</name>
<comment></comment>
<projects>
- <project>net.mograsim.logic.ui.am2900</project>
+ <project>net.mograsim.logic.model.am2900</project>
<project>net.mograsim.plugin.branding</project>
<project>net.mograsim.plugin.core</project>
<project>net.mograsim.plugin.docs</project>
unpack="false"/>
<plugin
- id="net.mograsim.logic.ui"
+ id="net.mograsim.logic.model"
download-size="100"
install-size="100"
version="0.1.0.qualifier"
unpack="false"/>
<plugin
- id="net.mograsim.logic.ui.am2900"
+ id="net.mograsim.logic.model.am2900"
download-size="58"
install-size="58"
version="0.1.0.qualifier"
{
switch (name)
{
- case "net.mograsim.logic.ui.color.bit.one":
+ case "net.mograsim.logic.model.color.bit.one":
return new ColorDefinition(BuiltInColor.COLOR_GREEN);
- case "net.mograsim.logic.ui.color.bit.u":
+ case "net.mograsim.logic.model.color.bit.u":
return new ColorDefinition(BuiltInColor.COLOR_CYAN);
- case "net.mograsim.logic.ui.color.bit.x":
+ case "net.mograsim.logic.model.color.bit.x":
return new ColorDefinition(BuiltInColor.COLOR_RED);
- case "net.mograsim.logic.ui.color.bit.z":
+ case "net.mograsim.logic.model.color.bit.z":
return new ColorDefinition(BuiltInColor.COLOR_YELLOW);
- case "net.mograsim.logic.ui.color.bit.zero":
+ case "net.mograsim.logic.model.color.bit.zero":
return new ColorDefinition(BuiltInColor.COLOR_GRAY);
- case "net.mograsim.logic.ui.color.background":
+ case "net.mograsim.logic.model.color.background":
return new ColorDefinition(BuiltInColor.COLOR_WHITE);
- case "net.mograsim.logic.ui.color.foreground":
+ case "net.mograsim.logic.model.color.foreground":
return new ColorDefinition(BuiltInColor.COLOR_BLACK);
- case "net.mograsim.logic.ui.color.text":
+ case "net.mograsim.logic.model.color.text":
return new ColorDefinition(BuiltInColor.COLOR_BLACK);
default:
// TODO proper logging here...