diff options
| author | vin <git@vineetk.net> | 2024-06-28 10:18:01 -0400 |
|---|---|---|
| committer | vin <git@vineetk.net> | 2024-06-28 10:18:01 -0400 |
| commit | 09692f45f62a76ce0418bbf4762885990d9860ef (patch) | |
| tree | fc848e7ae0997ce3b49786a21a9c9b18ad142e76 /cpu.c | |
| parent | 3ebdeab784d8ecd6d6d3a531693ad285577f32e0 (diff) | |
fix JSR and RTS bug
The stack's PUSH and PULL weren't proper and JSR was reading wrong
argument it seems.
Diffstat (limited to 'cpu.c')
| -rw-r--r-- | cpu.c | 8 |
1 files changed, 4 insertions, 4 deletions
| @@ -27,7 +27,7 @@ | |||
| 27 | #define PUSH(b) \ | 27 | #define PUSH(b) \ |
| 28 | (memwrite(0x0100 + regs.sp--, b)) | 28 | (memwrite(0x0100 + regs.sp--, b)) |
| 29 | #define PULL() \ | 29 | #define PULL() \ |
| 30 | (peek(0x0100 + regs.sp++)) | 30 | (peek(0x0100 + ++regs.sp)) |
| 31 | 31 | ||
| 32 | struct cpu_flags { | 32 | struct cpu_flags { |
| 33 | uint8_t carry : 1; | 33 | uint8_t carry : 1; |
| @@ -465,7 +465,7 @@ jmp(uint16_t arg) | |||
| 465 | static void | 465 | static void |
| 466 | jsr(uint16_t arg) | 466 | jsr(uint16_t arg) |
| 467 | { | 467 | { |
| 468 | uint16_t tmp = regs.pc + 2; | 468 | uint16_t tmp = regs.pc; |
| 469 | 469 | ||
| 470 | /* | 470 | /* |
| 471 | * first push high-byte of return address then low-byte | 471 | * first push high-byte of return address then low-byte |
| @@ -654,7 +654,7 @@ rti(void) | |||
| 654 | static void | 654 | static void |
| 655 | rts(void) | 655 | rts(void) |
| 656 | { | 656 | { |
| 657 | regs.pc = PULL() + 1; | 657 | regs.pc = PULL() | (PULL() << 8); |
| 658 | } | 658 | } |
| 659 | 659 | ||
| 660 | static void | 660 | static void |
| @@ -1164,7 +1164,7 @@ interpret(void) | |||
| 1164 | printf("JMP"); | 1164 | printf("JMP"); |
| 1165 | break; | 1165 | break; |
| 1166 | case 0x20: | 1166 | case 0x20: |
| 1167 | jsr(opcode_arg(AM_ABS)); | 1167 | jsr(opcode_mem(AM_ABS)); |
| 1168 | cycles += 6; | 1168 | cycles += 6; |
| 1169 | printf("JSR"); | 1169 | printf("JSR"); |
| 1170 | break; | 1170 | break; |
