diff options
| author | vin <git@vineetk.net> | 2024-07-04 15:06:15 -0400 |
|---|---|---|
| committer | vin <git@vineetk.net> | 2024-07-04 15:06:15 -0400 |
| commit | e1cdd7386807050bdd7db7debb902425a78e2970 (patch) | |
| tree | d304c8a346d8ca991c83525cf9c3a0814469791d /cpu.c | |
| parent | 4ccf9f5cee97c8c2191660a5632ab2da60757f97 (diff) | |
implement all of the nestest unofficial opcodes and fix branch cycles
Diffstat (limited to 'cpu.c')
| -rw-r--r-- | cpu.c | 19 |
1 files changed, 10 insertions, 9 deletions
| @@ -127,9 +127,7 @@ opcode_mem(enum addressing_mode mode) | |||
| 127 | val = (arg + regs.y) % 256; | 127 | val = (arg + regs.y) % 256; |
| 128 | break; | 128 | break; |
| 129 | case AM_REL: | 129 | case AM_REL: |
| 130 | val = arg + regs.pc; | 130 | val = (int8_t)arg + regs.pc; |
| 131 | if (((regs.pc + 1) & 0xFF00) != (val & 0xFF00)) | ||
| 132 | val -= 0x0100; | ||
| 133 | break; | 131 | break; |
| 134 | case AM_IMM: | 132 | case AM_IMM: |
| 135 | case AM_ABS: | 133 | case AM_ABS: |
| @@ -174,6 +172,9 @@ branch(uint16_t addr, bool cond) | |||
| 174 | return; | 172 | return; |
| 175 | cycles++; | 173 | cycles++; |
| 176 | 174 | ||
| 175 | if (((regs.pc + 1) & 0xFF00) != (addr & 0xFF00)) | ||
| 176 | cycles++; | ||
| 177 | |||
| 177 | regs.pc = addr; | 178 | regs.pc = addr; |
| 178 | } | 179 | } |
| 179 | 180 | ||
| @@ -277,7 +278,7 @@ BRK(uint16_t arg) | |||
| 277 | { | 278 | { |
| 278 | /* TODO: push regs.pc and regs.status to stack and load IRQ vector */ | 279 | /* TODO: push regs.pc and regs.status to stack and load IRQ vector */ |
| 279 | regs.status.brk = 1; | 280 | regs.status.brk = 1; |
| 280 | // exit(0); | 281 | exit(0); |
| 281 | } | 282 | } |
| 282 | 283 | ||
| 283 | void | 284 | void |
| @@ -771,11 +772,11 @@ DCP(uint16_t arg) | |||
| 771 | memwrite(arg, tmp); | 772 | memwrite(arg, tmp); |
| 772 | 773 | ||
| 773 | regs.status.carry = tmp <= regs.a; | 774 | regs.status.carry = tmp <= regs.a; |
| 774 | STATUS_UPDATE_NZ(tmp); | 775 | STATUS_UPDATE_NZ(regs.a - tmp); |
| 775 | } | 776 | } |
| 776 | 777 | ||
| 777 | void | 778 | void |
| 778 | ISC(uint16_t arg) | 779 | ISB(uint16_t arg) |
| 779 | { | 780 | { |
| 780 | INC(arg); | 781 | INC(arg); |
| 781 | SBC(peek(arg)); | 782 | SBC(peek(arg)); |
| @@ -807,7 +808,7 @@ void | |||
| 807 | RLA(uint16_t arg) | 808 | RLA(uint16_t arg) |
| 808 | { | 809 | { |
| 809 | ROL(arg); | 810 | ROL(arg); |
| 810 | AND(arg); | 811 | AND(peek(arg)); |
| 811 | } | 812 | } |
| 812 | 813 | ||
| 813 | void | 814 | void |
| @@ -821,14 +822,14 @@ void | |||
| 821 | SLO(uint16_t arg) | 822 | SLO(uint16_t arg) |
| 822 | { | 823 | { |
| 823 | ASL(arg); | 824 | ASL(arg); |
| 824 | ORA(arg); | 825 | ORA(peek(arg)); |
| 825 | } | 826 | } |
| 826 | 827 | ||
| 827 | void | 828 | void |
| 828 | SRE(uint16_t arg) | 829 | SRE(uint16_t arg) |
| 829 | { | 830 | { |
| 830 | LSR(arg); | 831 | LSR(arg); |
| 831 | EOR(arg); | 832 | EOR(peek(arg)); |
| 832 | } | 833 | } |
| 833 | 834 | ||
| 834 | void | 835 | void |
