emu_nes

An NES emulator for learning how the 6502 and similar computers of the era worked
Log | Files | Refs | README | LICENSE

commit a3189d90af2c675086e6dd629cfa071e4d75d4c9
parent 3412a03a5ec20e1d3fb5dbd38888cf0c0eae09fc
Author: vin <git@vineetk.net>
Date:   Mon, 10 Jun 2024 23:25:49 +0530

add jsr, rti, rts

Diffstat:
Mcpu.c | 23++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/cpu.c b/cpu.c @@ -407,15 +407,23 @@ iny(uint8_t arg) } static void -jmp(uint8_t arg) +jmp(uint16_t arg) { regs.pc = arg; } static void -jsr(uint8_t arg) +jsr(uint16_t arg) { -/* TODO: complete this */ + uint16_t tmp = regs.pc + 2; + + /* + * first push high-byte of return address then low-byte + * https://www.masswerk.at/6502/6502_instruction_set.html + */ + PUSH((tmp & 0xFF00) >> 8); + PUSH(tmp & 0xFF); + regs.pc = arg; } static void @@ -547,13 +555,14 @@ ror(uint8_t arg) static void rti(uint8_t arg) { -/* TODO: complete this */ + plp(); + regs.pc = PULL(); } static void -rts(uint8_t arg) +rts(void) { -/* TODO: complete this */ + regs.pc = PULL() + 1; } static void @@ -1186,7 +1195,7 @@ interpret(void) cycles += 6; break; case 0x60: - rts(opcode_arg(AM_ACC)); + rts(); cycles += 6; break; case 0xe9: