From 42cb53c0ad6d58cbed7df9e057f0ed86e68c164c Mon Sep 17 00:00:00 2001 From: Takashi Toyoshima Date: Mon, 8 Dec 2014 00:36:42 +0900 Subject: [PATCH] Bug fix: after TSX, X got a value >= 0x100 --- 6502.S | 5 +++++ test.c | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/6502.S b/6502.S index 82978d1..ef0f76d 100644 --- a/6502.S +++ b/6502.S @@ -452,6 +452,8 @@ .endm .macro _cp reg + prn r0 + prn \reg __cl (FLAG_N | FLAG_Z | FLAG_C) mov r1, \reg subs r0, r1, r0 @@ -1372,6 +1374,9 @@ opb9: // LDA - Absolute, Y opba: // TSX _t SP, RX + mov r0, RX + uxtb r0, r0 + mov RX, r0 _decode opbc: // LDY - Absolute, X diff --git a/test.c b/test.c index 46be5be..9fd41a2 100644 --- a/test.c +++ b/test.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -15,10 +16,16 @@ void prn(int c) { __asm__("movs r12, %0":: "r"(fp)); } -void cpu6502_dump( - uint16_t pc, uint8_t a, uint8_t x, uint8_t y, uint8_t sp, uint8_t sr) { +void cpu6502_dump(uint32_t pc, uint32_t a, uint32_t x, uint32_t y, + uint32_t sp, uint32_t sr) { uint8_t fp; __asm__("movs %0, r12": "=r"(fp)); + assert(pc < 0x1000); + assert(a < 0x100); + assert(x < 0x100); + assert(y < 0x100); + assert(sr < 0x100); + assert(0x100 <= sp && sp < 0x200); fprintf(stderr, "*** dump *** PC=$%04x A=$%02x X=$%02x Y=$%02x SP=$%02x " "NV-B_DIZC=%d%d-%d_%d%d%d%d\n", pc, a, x, y, sp, (sr >> 7) & 1, (sr >> 6) & 1, (sr >> 4) & 1,