diff --git a/miggy-emu/src/main/java/miggy/cpupoet/CoreALU.java b/miggy-emu/src/main/java/miggy/cpupoet/CoreALU.java index 46ae2ce..38f1df1 100644 --- a/miggy-emu/src/main/java/miggy/cpupoet/CoreALU.java +++ b/miggy-emu/src/main/java/miggy/cpupoet/CoreALU.java @@ -814,16 +814,25 @@ public class CoreALU { byte res = (byte) dst; if (shift > 0) { - int mask = -1 << (8 - Math.min(shift, 8)); - int vout = res & mask; int cx = 0; - int v = (vout == 0) || (vout == mask) ? 0 : FL_V; + int v = 0; + + if (shift < 8) { + int mask = -1 << (8 - Math.min(shift + 1, 8)); + int vout = res & mask; - if (shift <= 8) { res <<= shift - 1; + + v = (vout == 0) || (vout == mask) ? 0 : FL_V; cx = (res >> 31) & (FL_C | FL_X); res <<= 1; + } else if (shift == 8) { + cx = res & FL_C; /* set carry */ + cx |= cx << 4; /* also set eXtend */ + v = ((res | -res) >> 31) & FL_V; + res = 0; } else { + v = ((res | -res) >> 31) & FL_V; res = 0; } @@ -847,16 +856,25 @@ public class CoreALU { short res = (short) dst; if (shift > 0) { - int mask = -1 << (16 - Math.min(shift, 16)); - int vout = res & mask; int cx = 0; - int v = (vout == 0) || (vout == mask) ? 0 : FL_V; + int v = 0; + + if (shift < 16) { + int mask = -1 << (16 - Math.min(shift + 1, 16)); + int vout = res & mask; - if (shift <= 16) { res <<= shift - 1; + + v = (vout == 0) || (vout == mask) ? 0 : FL_V; cx = (res >> 31) & (FL_C | FL_X); res <<= 1; + } else if (shift == 16) { + cx = res & FL_C; /* set carry */ + cx |= cx << 4; /* also set eXtend */ + v = ((res | -res) >> 31) & FL_V; + res = 0; } else { + v = ((res | -res) >> 31) & FL_V; res = 0; } @@ -880,16 +898,25 @@ public class CoreALU { int res = dst; if (shift > 0) { - int mask = -1 << (32 - Math.min(shift, 32)); - int vout = res & mask; int cx = 0; - int v = (vout == 0) || (vout == mask) ? 0 : FL_V; + int v = 0; + + if (shift < 32) { + int mask = -1 << (32 - Math.min(shift + 1, 32)); + int vout = res & mask; - if (shift <= 32) { res <<= shift - 1; + + v = (vout == 0) || (vout == mask) ? 0 : FL_V; cx = (res >> 31) & (FL_C | FL_X); res <<= 1; + } else if (shift == 32) { + cx = res & FL_C; /* set carry */ + cx |= cx << 4; /* also set eXtend */ + v = ((res | -res) >> 31) & FL_V; + res = 0; } else { + v = ((res | -res) >> 31) & FL_V; res = 0; } diff --git a/miggy-emu/src/test/java/miggy/cpupoet/InstructionTests.java b/miggy-emu/src/test/java/miggy/cpupoet/InstructionTests.java index 1895834..6c94a37 100644 --- a/miggy-emu/src/test/java/miggy/cpupoet/InstructionTests.java +++ b/miggy-emu/src/test/java/miggy/cpupoet/InstructionTests.java @@ -74,6 +74,12 @@ public class InstructionTests extends TestCase { public void testShift() { CoreTest test = new CoreTest(0xffffff + 1, true); + test.executeBinTest("ASL.b"); + test.executeBinTest("ASL.w"); + test.executeBinTest("ASL.l"); + test.executeBinTest("ASR.b"); + test.executeBinTest("ASR.w"); + test.executeBinTest("ASR.l"); test.executeBinTest("LSL.b"); test.executeBinTest("LSL.w"); test.executeBinTest("LSL.l"); @@ -164,22 +170,13 @@ public class InstructionTests extends TestCase { test.executeBinTest("MOVE.b"); /* - * 295 is not compatible (post incremented value is written by design) 342 is - * not compatible (post incremented value is written by design) 494 is not - * compatible (post incremented value is written by design) 994 is not - * compatible (pre decremented value is written by design) 1225 is not - * compatible (pre decremented value is written by design) 1846 is not - * compatible (post incremented value is written by design) + * skipped cases are incompatible (move address register to pre/post + * dec/increment with same address register) */ test.executeBinTest("MOVE.w", 295, 342, 494, 994, 1225, 1846); /* - * 217 is not compatible (post incremented value is written by design) 502 is - * not compatible (post incremented value is written by design) 1152 is not - * compatible (post incremented value is written by design) 1691 is not - * compatible (post incremented value is written by design) 1830 is not - * compatible (pre decremented value is written by design) 2057 is not - * compatible (post incremented value is written by design) 2135 is not - * compatible (post incremented value is written by design) + * skipped cases are incompatible (move address register to pre/post + * dec/increment with same address register) */ test.executeBinTest("MOVE.l", 217, 502, 1152, 1691, 1830, 2057, 2135); test.executeBinTest("MOVE.q"); diff --git a/miggy-emu/src/test/resources/miggy/cpupoet/ASL.b.json.bin b/miggy-emu/src/test/resources/miggy/cpupoet/ASL.b.json.bin new file mode 100644 index 0000000..75a7b5b Binary files /dev/null and b/miggy-emu/src/test/resources/miggy/cpupoet/ASL.b.json.bin differ diff --git a/miggy-emu/src/test/resources/miggy/cpupoet/ASL.l.json.bin b/miggy-emu/src/test/resources/miggy/cpupoet/ASL.l.json.bin new file mode 100644 index 0000000..1e5a354 Binary files /dev/null and b/miggy-emu/src/test/resources/miggy/cpupoet/ASL.l.json.bin differ diff --git a/miggy-emu/src/test/resources/miggy/cpupoet/ASL.w.json.bin b/miggy-emu/src/test/resources/miggy/cpupoet/ASL.w.json.bin new file mode 100644 index 0000000..dc255e1 Binary files /dev/null and b/miggy-emu/src/test/resources/miggy/cpupoet/ASL.w.json.bin differ diff --git a/miggy-emu/src/test/resources/miggy/cpupoet/ASR.b.json.bin b/miggy-emu/src/test/resources/miggy/cpupoet/ASR.b.json.bin new file mode 100644 index 0000000..4a549b8 Binary files /dev/null and b/miggy-emu/src/test/resources/miggy/cpupoet/ASR.b.json.bin differ diff --git a/miggy-emu/src/test/resources/miggy/cpupoet/ASR.l.json.bin b/miggy-emu/src/test/resources/miggy/cpupoet/ASR.l.json.bin new file mode 100644 index 0000000..747c4b6 Binary files /dev/null and b/miggy-emu/src/test/resources/miggy/cpupoet/ASR.l.json.bin differ diff --git a/miggy-emu/src/test/resources/miggy/cpupoet/ASR.w.json.bin b/miggy-emu/src/test/resources/miggy/cpupoet/ASR.w.json.bin new file mode 100644 index 0000000..cd52378 Binary files /dev/null and b/miggy-emu/src/test/resources/miggy/cpupoet/ASR.w.json.bin differ