ARM: Fix edge case with Thumb SBC flags (fixes #1818)
Vicki Pfau vi@endrift.com
Sun, 12 Jul 2020 14:26:13 -0700
2 files changed,
12 insertions(+),
3 deletions(-)
M
CHANGES
→
CHANGES
@@ -8,6 +8,7 @@ - ARM: Fix ALU reading PC after shifting
- ARM: Fix STR storing PC after address calculation - ARM: Fix LDM^ writeback to user-mode register - ARM: Fix LDM^ {pc} differences (fixes mgba.io/i/1698) + - ARM: Fix edge case with Thumb SBC flags (fixes mgba.io/i/1818) - GB: Partially fix timing for skipped BIOS - GB Memory: Fix OAM DMA from top 8 kB - GB MBC: Fix MBC1 mode changing behavior
M
src/arm/isa-thumb.c
→
src/arm/isa-thumb.c
@@ -25,6 +25,13 @@ cpu->cpsr.z = !(D); \
cpu->cpsr.c = ARM_BORROW_FROM(M, N, D); \ cpu->cpsr.v = ARM_V_SUBTRACTION(M, N, D); +#define THUMB_SUBTRACTION_CARRY_S(M, N, D, C) \ + cpu->cpsr.flags = 0; \ + cpu->cpsr.n = ARM_SIGN(D); \ + cpu->cpsr.z = !(D); \ + cpu->cpsr.c = ARM_BORROW_FROM_CARRY(M, N, D, C); \ + cpu->cpsr.v = ARM_V_SUBTRACTION(M, N, D); + #define THUMB_NEUTRAL_S(M, N, D) \ cpu->cpsr.n = ARM_SIGN(D); \ cpu->cpsr.z = !(D);@@ -203,10 +210,11 @@ cpu->gprs[rd] = d + n + cpu->cpsr.c;
THUMB_ADDITION_S(d, n, cpu->gprs[rd]);) DEFINE_DATA_FORM_5_INSTRUCTION_THUMB(SBC, - int n = cpu->gprs[rn] + !cpu->cpsr.c; + int n = cpu->gprs[rn]; int d = cpu->gprs[rd]; - cpu->gprs[rd] = d - n; - THUMB_SUBTRACTION_S(d, n, cpu->gprs[rd]);) + cpu->gprs[rd] = d - n - !cpu->cpsr.c; + THUMB_SUBTRACTION_CARRY_S(d, n, cpu->gprs[rd], !cpu->cpsr.c);) + DEFINE_DATA_FORM_5_INSTRUCTION_THUMB(ROR, int rs = cpu->gprs[rn] & 0xFF; if (rs) {