+ assertEquals("0000", am2901.getDirectly(r), r.name());
+ }));
+ }
+
+ @Order(4)
+ @Test
+ 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);
+
+ String desc = xy.x + " + " + xy.y + " = " + res4Bit + ": ";
+
+ assertEquals(to4bitBin(res4Bit & 0b1111), am2901.getY(), desc + "Y");
+ assertEquals(to1bitBin(res4Bit == 0), am2901.getZero(), desc + "F=0");
+ assertEquals(to1bitBin(res4Bit & 0b1000), am2901.getSign(), desc + "F3");
+ assertEquals(to1bitBin(res32Bit & 0b1_0000), am2901.getCarryOut(), desc + "Cn+4");
+ assertEquals(to1bitBin(res4Bit_sgn != res32Bit_sgn), am2901.getOverflow(), desc + "OVR");
+ }));
+ }
+
+ @Order(4)
+ @Test
+ 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;
+
+ String desc = xy.x + " & " + xy.y + " = " + res32Bit + ": ";
+
+ assertEquals(to4bitBin(res32Bit), am2901.getY(), desc + "Y");
+ assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), desc + "F=0");
+ assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), desc + "F3");
+// assertEquals(to1bitBin(res32Bit), am2901.getCarryOut(), desc + "Cn+4"); // TODO
+// assertEquals(to1bitBin(res32Bit), am2901.getOverflow(), desc + "OVR"); // TODO
+ }));
+ }
+
+ @Order(4)
+ @Test
+ 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;
+
+ String desc = xy.x + " | " + xy.y + " = " + res32Bit + ": ";
+
+ assertEquals(to4bitBin(res32Bit), am2901.getY(), desc + "Y");
+ assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), desc + "F=0");
+ assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), desc + "F3");
+// assertEquals(to1bitBin(res32Bit != 0b1111), am2901.getCarryOut(), desc + "Cn+4"); // TODO
+// assertEquals(to1bitBin(res32Bit != 0b1111), am2901.getOverflow(), desc + "OVR"); // TODO
+ }));
+ }
+
+ @Order(4)
+ @Test
+ 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;
+
+ String desc = xy.x + " ^ " + xy.y + " = " + res32Bit + ": ";
+
+ assertEquals(to4bitBin(res32Bit), am2901.getY(), desc + "Y");
+ assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), desc + "F=0");
+ assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), desc + "F3");
+// assertEquals(to1bitBin(res32Bit != 0b1111), am2901.getCarryOut(), desc + "Cn+4"); // TODO
+// assertEquals(to1bitBin(res32Bit != 0b1111), am2901.getOverflow(), desc + "OVR"); // TODO
+ }));
+ }
+
+ @Order(4)
+ @Test
+ 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);
+
+ String desc = xy.x + " - " + xy.y + " = " + res4Bit + ": ";
+
+ assertEquals(to4bitBin(res4Bit & 0b1111), am2901.getY(), desc + "Y");
+ assertEquals(to1bitBin(res4Bit == 0), am2901.getZero(), desc + "F=0");
+ assertEquals(to1bitBin(res4Bit & 0b1000), am2901.getSign(), desc + "F3");
+ assertEquals(to1bitBin(xy.x >= xy.y), am2901.getCarryOut(), desc + "Cn+4");
+ assertEquals(to1bitBin(res4Bit_sgn != res32Bit_sgn), am2901.getOverflow(), desc + "OVR");
+ }));
+ }
+
+ static Stream<Point> getAll4BitPairs()
+ {
+ return IntStream.range(0, 16).boxed().flatMap(x -> IntStream.range(0, 16).mapToObj(y -> new Point(x, y)));