add jsr, rti, rts

This commit is contained in:
Vineet K 2024-06-10 23:25:49 +05:30
parent 3412a03a5e
commit a3189d90af

23
cpu.c
View File

@ -407,15 +407,23 @@ iny(uint8_t arg)
} }
static void static void
jmp(uint8_t arg) jmp(uint16_t arg)
{ {
regs.pc = arg; regs.pc = arg;
} }
static void 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 static void
@ -547,13 +555,14 @@ ror(uint8_t arg)
static void static void
rti(uint8_t arg) rti(uint8_t arg)
{ {
/* TODO: complete this */ plp();
regs.pc = PULL();
} }
static void static void
rts(uint8_t arg) rts(void)
{ {
/* TODO: complete this */ regs.pc = PULL() + 1;
} }
static void static void
@ -1186,7 +1195,7 @@ interpret(void)
cycles += 6; cycles += 6;
break; break;
case 0x60: case 0x60:
rts(opcode_arg(AM_ACC)); rts();
cycles += 6; cycles += 6;
break; break;
case 0xe9: case 0xe9: