Bug fix: after TSX, X got a value >= 0x100

This commit is contained in:
Takashi Toyoshima 2014-12-08 00:36:42 +09:00
parent d0ad06c86a
commit 42cb53c0ad
2 changed files with 14 additions and 2 deletions

5
6502.S
View File

@ -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

11
test.c
View File

@ -1,3 +1,4 @@
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
@ -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,