fix JSR and RTS bug

The stack's PUSH and PULL weren't proper and JSR was reading wrong
argument it seems.
This commit is contained in:
Vineet K 2024-06-28 10:18:01 -04:00
parent 3ebdeab784
commit 09692f45f6

8
cpu.c
View File

@ -27,7 +27,7 @@
#define PUSH(b) \ #define PUSH(b) \
(memwrite(0x0100 + regs.sp--, b)) (memwrite(0x0100 + regs.sp--, b))
#define PULL() \ #define PULL() \
(peek(0x0100 + regs.sp++)) (peek(0x0100 + ++regs.sp))
struct cpu_flags { struct cpu_flags {
uint8_t carry : 1; uint8_t carry : 1;
@ -465,7 +465,7 @@ jmp(uint16_t arg)
static void static void
jsr(uint16_t arg) jsr(uint16_t arg)
{ {
uint16_t tmp = regs.pc + 2; uint16_t tmp = regs.pc;
/* /*
* first push high-byte of return address then low-byte * first push high-byte of return address then low-byte
@ -654,7 +654,7 @@ rti(void)
static void static void
rts(void) rts(void)
{ {
regs.pc = PULL() + 1; regs.pc = PULL() | (PULL() << 8);
} }
static void static void
@ -1164,7 +1164,7 @@ interpret(void)
printf("JMP"); printf("JMP");
break; break;
case 0x20: case 0x20:
jsr(opcode_arg(AM_ABS)); jsr(opcode_mem(AM_ABS));
cycles += 6; cycles += 6;
printf("JSR"); printf("JSR");
break; break;