summaryrefslogtreecommitdiff
path: root/cpu.c
diff options
context:
space:
mode:
authorvin <git@vineetk.net>2024-06-10 23:25:49 +0530
committervin <git@vineetk.net>2024-06-10 23:27:14 +0530
commita3189d90af2c675086e6dd629cfa071e4d75d4c9 (patch)
tree165325a8ffddd24bf0ccbe71bacf05604f70b8cb /cpu.c
parent3412a03a5ec20e1d3fb5dbd38888cf0c0eae09fc (diff)
add jsr, rti, rts
Diffstat (limited to 'cpu.c')
-rw-r--r--cpu.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/cpu.c b/cpu.c
index e63760c..87d68c8 100644
--- 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: