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)
407} 407}
408 408
409static void 409static void
410jmp(uint8_t arg) 410jmp(uint16_t arg)
411{ 411{
412 regs.pc = arg; 412 regs.pc = arg;
413} 413}
414 414
415static void 415static void
416jsr(uint8_t arg) 416jsr(uint16_t arg)
417{ 417{
418/* TODO: complete this */ 418 uint16_t tmp = regs.pc + 2;
419
420 /*
421 * first push high-byte of return address then low-byte
422 * https://www.masswerk.at/6502/6502_instruction_set.html
423 */
424 PUSH((tmp & 0xFF00) >> 8);
425 PUSH(tmp & 0xFF);
426 regs.pc = arg;
419} 427}
420 428
421static void 429static void
@@ -547,13 +555,14 @@ ror(uint8_t arg)
547static void 555static void
548rti(uint8_t arg) 556rti(uint8_t arg)
549{ 557{
550/* TODO: complete this */ 558 plp();
559 regs.pc = PULL();
551} 560}
552 561
553static void 562static void
554rts(uint8_t arg) 563rts(void)
555{ 564{
556/* TODO: complete this */ 565 regs.pc = PULL() + 1;
557} 566}
558 567
559static void 568static void
@@ -1186,7 +1195,7 @@ interpret(void)
1186 cycles += 6; 1195 cycles += 6;
1187 break; 1196 break;
1188 case 0x60: 1197 case 0x60:
1189 rts(opcode_arg(AM_ACC)); 1198 rts();
1190 cycles += 6; 1199 cycles += 6;
1191 break; 1200 break;
1192 case 0xe9: 1201 case 0xe9: