diff options
| author | vin <git@vineetk.net> | 2024-06-30 07:56:08 -0400 |
|---|---|---|
| committer | vin <git@vineetk.net> | 2024-06-30 07:56:08 -0400 |
| commit | 99082b55287ecd0378935d31a289c05e1110c7b8 (patch) | |
| tree | c85ea72feb124aefe2f0b1ee4fca0eb201eebbd2 | |
| parent | 5535e5de70684dd8406e53d6ce928faf9011336c (diff) | |
fix JSR, RTS, and RTI
JSR was pushing 1 too high PC and RTS was 1 too low
RTI was only pulling the low byte of PC
| -rw-r--r-- | cpu.c | 6 |
1 files changed, 3 insertions, 3 deletions
| @@ -472,7 +472,7 @@ jmp(uint16_t arg) | |||
| 472 | static void | 472 | static void |
| 473 | jsr(uint16_t arg) | 473 | jsr(uint16_t arg) |
| 474 | { | 474 | { |
| 475 | uint16_t tmp = regs.pc; | 475 | uint16_t tmp = regs.pc - 1; |
| 476 | 476 | ||
| 477 | /* | 477 | /* |
| 478 | * first push high-byte of return address then low-byte | 478 | * first push high-byte of return address then low-byte |
| @@ -651,13 +651,13 @@ static void | |||
| 651 | rti(void) | 651 | rti(void) |
| 652 | { | 652 | { |
| 653 | plp(); | 653 | plp(); |
| 654 | regs.pc = PULL(); | 654 | regs.pc = PULL() | (PULL() << 8); |
| 655 | } | 655 | } |
| 656 | 656 | ||
| 657 | static void | 657 | static void |
| 658 | rts(void) | 658 | rts(void) |
| 659 | { | 659 | { |
| 660 | regs.pc = PULL() | (PULL() << 8); | 660 | regs.pc = (PULL() | (PULL() << 8)) + 1; |
| 661 | } | 661 | } |
| 662 | 662 | ||
| 663 | static void | 663 | static void |
