From: Daniel Kirschten Date: Mon, 15 Jul 2019 19:18:30 +0000 (+0200) Subject: Finished renaming logic.ui to logic.model X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=a1fd9f900021ba654a565394708552a3ad911142;p=Mograsim.git Finished renaming logic.ui to logic.model --- diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVectorFormatter.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVectorFormatter.java index 858f28a3..1085addd 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVectorFormatter.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVectorFormatter.java @@ -19,7 +19,7 @@ public class BitVectorFormatter 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()); @@ -33,15 +33,15 @@ public class BitVectorFormatter 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)); } diff --git a/net.mograsim.logic.model.am2900/.project b/net.mograsim.logic.model.am2900/.project index 5ac21380..494b451f 100644 --- a/net.mograsim.logic.model.am2900/.project +++ b/net.mograsim.logic.model.am2900/.project @@ -3,7 +3,7 @@ net.mograsim.logic.model.am2900 - net.mograsim.logic.ui + net.mograsim.logic.model SWTZoomableCanvas diff --git a/net.mograsim.logic.model.am2900/FullAdder.json b/net.mograsim.logic.model.am2900/FullAdder.json index 40c51c76..a027c43c 100644 --- a/net.mograsim.logic.model.am2900/FullAdder.json +++ b/net.mograsim.logic.model.am2900/FullAdder.json @@ -53,7 +53,7 @@ mograsim version: 0.1.1 "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": {} }, { @@ -61,7 +61,7 @@ mograsim version: 0.1.1 "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": {} }, { @@ -69,7 +69,7 @@ mograsim version: 0.1.1 "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 } diff --git a/net.mograsim.logic.model.am2900/HalfAdder.json b/net.mograsim.logic.model.am2900/HalfAdder.json index 48c19802..9eb7057f 100644 --- a/net.mograsim.logic.model.am2900/HalfAdder.json +++ b/net.mograsim.logic.model.am2900/HalfAdder.json @@ -45,7 +45,7 @@ mograsim version: 0.1.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 } @@ -55,7 +55,7 @@ mograsim version: 0.1.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 } @@ -65,7 +65,7 @@ mograsim version: 0.1.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 } @@ -75,7 +75,7 @@ mograsim version: 0.1.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 } @@ -85,7 +85,7 @@ mograsim version: 0.1.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 } @@ -95,7 +95,7 @@ mograsim version: 0.1.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 } @@ -105,7 +105,7 @@ mograsim version: 0.1.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 } diff --git a/net.mograsim.logic.model.am2900/META-INF/MANIFEST.MF b/net.mograsim.logic.model.am2900/META-INF/MANIFEST.MF index 71d5a3b6..4854d0b9 100644 --- a/net.mograsim.logic.model.am2900/META-INF/MANIFEST.MF +++ b/net.mograsim.logic.model.am2900/META-INF/MANIFEST.MF @@ -8,5 +8,5 @@ Export-Package: net.mograsim.logic.model.examples, 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 diff --git a/net.mograsim.logic.model.am2900/OSGI-INF/l10n/bundle.properties b/net.mograsim.logic.model.am2900/OSGI-INF/l10n/bundle.properties index f1ecb432..3fe36700 100644 --- a/net.mograsim.logic.model.am2900/OSGI-INF/l10n/bundle.properties +++ b/net.mograsim.logic.model.am2900/OSGI-INF/l10n/bundle.properties @@ -1,3 +1,3 @@ -#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 diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/Am2901Test.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/Am2901Test.java new file mode 100644 index 00000000..7d87f39b --- /dev/null +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/Am2901Test.java @@ -0,0 +1,298 @@ +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 getAll4BitPairs() + { + return IntStream.range(0, 16).boxed().flatMap(x -> IntStream.range(0, 16).mapToObj(y -> new Point(x, y))); + } +} diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/Am2901Testbench.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/Am2901Testbench.java new file mode 100644 index 00000000..d6057f80 --- /dev/null +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/Am2901Testbench.java @@ -0,0 +1,98 @@ +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 inputPinNames = new ArrayList<>(); + List 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 diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestUtil.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestUtil.java new file mode 100644 index 00000000..f85ae04a --- /dev/null +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestUtil.java @@ -0,0 +1,84 @@ +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(); + } +} diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestableAm2901.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestableAm2901.java new file mode 100644 index 00000000..d898b399 --- /dev/null +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestableAm2901.java @@ -0,0 +1,131 @@ +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 stream() + { + return Arrays.stream(values()); + } + } +} diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestableAm2901Impl.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestableAm2901Impl.java new file mode 100644 index 00000000..98a6d109 --- /dev/null +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestableAm2901Impl.java @@ -0,0 +1,381 @@ +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 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 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 inputPinNames = new ArrayList<>(); + List 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 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 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 wiresIncludingSubmodels = new HashSet<>(); + Queue 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"; + } +} diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/Am2901Test.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/Am2901Test.java deleted file mode 100644 index 03790ec5..00000000 --- a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/Am2901Test.java +++ /dev/null @@ -1,298 +0,0 @@ -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 getAll4BitPairs() - { - return IntStream.range(0, 16).boxed().flatMap(x -> IntStream.range(0, 16).mapToObj(y -> new Point(x, y))); - } -} diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/Am2901Testbench.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/Am2901Testbench.java deleted file mode 100644 index 7c68cc1a..00000000 --- a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/Am2901Testbench.java +++ /dev/null @@ -1,98 +0,0 @@ -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 inputPinNames = new ArrayList<>(); - List 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 diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestUtil.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestUtil.java deleted file mode 100644 index 937e566a..00000000 --- a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestUtil.java +++ /dev/null @@ -1,84 +0,0 @@ -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(); - } -} diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901.java deleted file mode 100644 index ad0a0b87..00000000 --- a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901.java +++ /dev/null @@ -1,131 +0,0 @@ -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 stream() - { - return Arrays.stream(values()); - } - } -} diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901Impl.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901Impl.java deleted file mode 100644 index af838d10..00000000 --- a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901Impl.java +++ /dev/null @@ -1,381 +0,0 @@ -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 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 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 inputPinNames = new ArrayList<>(); - List 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 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 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 wiresIncludingSubmodels = new HashSet<>(); - Queue 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"; - } -} diff --git a/net.mograsim.logic.model.editor/META-INF/MANIFEST.MF b/net.mograsim.logic.model.editor/META-INF/MANIFEST.MF index a666cdec..728aa67e 100644 --- a/net.mograsim.logic.model.editor/META-INF/MANIFEST.MF +++ b/net.mograsim.logic.model.editor/META-INF/MANIFEST.MF @@ -10,5 +10,5 @@ Export-Package: net.mograsim.logic.model.editor, 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 diff --git a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/ui/EditorCanvas.java b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/ui/EditorCanvas.java index 98aefbb4..641aaa46 100644 --- a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/ui/EditorCanvas.java +++ b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/ui/EditorCanvas.java @@ -29,7 +29,7 @@ public class EditorCanvas extends LogicUICanvas 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 diff --git a/net.mograsim.logic.model/META-INF/MANIFEST.MF b/net.mograsim.logic.model/META-INF/MANIFEST.MF index 6da2e2a9..e6b077ab 100644 --- a/net.mograsim.logic.model/META-INF/MANIFEST.MF +++ b/net.mograsim.logic.model/META-INF/MANIFEST.MF @@ -27,5 +27,5 @@ Require-Bundle: org.eclipse.swt;bundle-version="3.0.0";visibility:=reexport, 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 diff --git a/net.mograsim.logic.model/OSGI-INF/l10n/bundle.properties b/net.mograsim.logic.model/OSGI-INF/l10n/bundle.properties index 4eac2829..420d2fc2 100644 --- a/net.mograsim.logic.model/OSGI-INF/l10n/bundle.properties +++ b/net.mograsim.logic.model/OSGI-INF/l10n/bundle.properties @@ -1,3 +1,3 @@ -#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 diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUICanvas.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUICanvas.java index 609bf74f..9aa80565 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUICanvas.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUICanvas.java @@ -48,7 +48,7 @@ public class LogicUICanvas extends ZoomableCanvas 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)); diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIBitDisplay.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIBitDisplay.java index 46c85460..2c541f8b 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIBitDisplay.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIBitDisplay.java @@ -45,7 +45,7 @@ public class GUIBitDisplay extends GUIComponent @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()); @@ -55,7 +55,7 @@ public class GUIBitDisplay extends GUIComponent 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); diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIManualSwitch.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIManualSwitch.java index b79ec2fd..e4c18331 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIManualSwitch.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIManualSwitch.java @@ -50,7 +50,7 @@ public class GUIManualSwitch extends GUIComponent 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()); @@ -59,7 +59,7 @@ public class GUIManualSwitch extends GUIComponent 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); diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularGUIGate.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularGUIGate.java index 9535d3b8..b14aaec4 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularGUIGate.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularGUIGate.java @@ -67,7 +67,7 @@ public class SimpleRectangularGUIGate extends GUIComponent @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; @@ -78,7 +78,7 @@ public class SimpleRectangularGUIGate extends GUIComponent 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); diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/TextComponent.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/TextComponent.java index 87c3cf47..4429b0e3 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/TextComponent.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/TextComponent.java @@ -40,7 +40,7 @@ public class TextComponent extends GUIComponent 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); diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SimpleRectangularSubmodelComponent.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SimpleRectangularSubmodelComponent.java index 039cdab6..aae72e29 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SimpleRectangularSubmodelComponent.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SimpleRectangularSubmodelComponent.java @@ -115,7 +115,7 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent @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()); diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/outlinerenderers/DefaultOutlineRenderer.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/outlinerenderers/DefaultOutlineRenderer.java index f7841dd6..a72b20cd 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/outlinerenderers/DefaultOutlineRenderer.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/outlinerenderers/DefaultOutlineRenderer.java @@ -23,7 +23,7 @@ public class DefaultOutlineRenderer implements Renderer @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()); diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/CenteredTextSymbolRenderer.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/CenteredTextSymbolRenderer.java index e1a68508..bf406396 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/CenteredTextSymbolRenderer.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/CenteredTextSymbolRenderer.java @@ -35,7 +35,7 @@ public class CenteredTextSymbolRenderer implements Renderer { 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); diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/DefaultSymbolRenderer.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/DefaultSymbolRenderer.java index 3faf0b91..3ae52082 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/DefaultSymbolRenderer.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/DefaultSymbolRenderer.java @@ -26,7 +26,7 @@ public class DefaultSymbolRenderer implements Renderer @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); diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/SimpleRectangularLikeSymbolRenderer.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/SimpleRectangularLikeSymbolRenderer.java index d3173851..d6386e35 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/SimpleRectangularLikeSymbolRenderer.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/SimpleRectangularLikeSymbolRenderer.java @@ -46,7 +46,7 @@ public class SimpleRectangularLikeSymbolRenderer implements Renderer 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); diff --git a/net.mograsim.plugin.core/.project b/net.mograsim.plugin.core/.project index 02db9630..82112b2b 100644 --- a/net.mograsim.plugin.core/.project +++ b/net.mograsim.plugin.core/.project @@ -3,8 +3,8 @@ net.mograsim.plugin.core - net.mograsim.logic.ui - net.mograsim.logic.ui.am2900 + net.mograsim.logic.model + net.mograsim.logic.model.am2900 diff --git a/net.mograsim.plugin.core/plugin.xml b/net.mograsim.plugin.core/plugin.xml index cee540e5..381fb4f0 100644 --- a/net.mograsim.plugin.core/plugin.xml +++ b/net.mograsim.plugin.core/plugin.xml @@ -227,13 +227,13 @@ @@ -242,49 +242,49 @@ diff --git a/net.mograsim.plugin.feature/.project b/net.mograsim.plugin.feature/.project index 6b417898..3399c4cd 100644 --- a/net.mograsim.plugin.feature/.project +++ b/net.mograsim.plugin.feature/.project @@ -3,7 +3,7 @@ net.mograsim.plugin.feature - net.mograsim.logic.ui.am2900 + net.mograsim.logic.model.am2900 net.mograsim.plugin.branding net.mograsim.plugin.core net.mograsim.plugin.docs diff --git a/net.mograsim.plugin.feature/feature.xml b/net.mograsim.plugin.feature/feature.xml index b06daf50..0832d13e 100644 --- a/net.mograsim.plugin.feature/feature.xml +++ b/net.mograsim.plugin.feature/feature.xml @@ -720,7 +720,7 @@ exception as provided by Oracle in the LICENSE file that accompanied this code.& unpack="false"/>