diff options
| author | vin <git@vineetk.net> | 2024-07-21 13:53:04 -0400 |
|---|---|---|
| committer | vin <git@vineetk.net> | 2024-07-21 13:53:04 -0400 |
| commit | 7d148924e2fee1a2692d2c49a01e6770b630f906 (patch) | |
| tree | 0fc1abc86a7dae9c249f9a796f4af2e9ebbaffff /cpu.c | |
| parent | 2df7df5f5b0f325864f92c5a58f3c132cfff989e (diff) | |
start implementing PPU
Diffstat (limited to 'cpu.c')
| -rw-r--r-- | cpu.c | 27 |
1 files changed, 21 insertions, 6 deletions
| @@ -8,6 +8,7 @@ | |||
| 8 | #include "cpu.h" | 8 | #include "cpu.h" |
| 9 | #include "opcodes.h" | 9 | #include "opcodes.h" |
| 10 | #include "rom.h" | 10 | #include "rom.h" |
| 11 | #include "ppu.h" | ||
| 11 | 12 | ||
| 12 | #define MAX(a, b) ((a > b) ? a : b) | 13 | #define MAX(a, b) ((a > b) ? a : b) |
| 13 | 14 | ||
| @@ -146,14 +147,23 @@ opcode_mem(enum addressing_mode mode) | |||
| 146 | } | 147 | } |
| 147 | 148 | ||
| 148 | static void | 149 | static void |
| 150 | tick(void) | ||
| 151 | { | ||
| 152 | cycles++; | ||
| 153 | ppu_tick(); | ||
| 154 | ppu_tick(); | ||
| 155 | ppu_tick(); | ||
| 156 | } | ||
| 157 | |||
| 158 | static void | ||
| 149 | branch(uint16_t addr, bool cond) | 159 | branch(uint16_t addr, bool cond) |
| 150 | { | 160 | { |
| 151 | if (!cond) | 161 | if (!cond) |
| 152 | return; | 162 | return; |
| 153 | cycles++; | 163 | tick(); |
| 154 | 164 | ||
| 155 | if (((regs.pc + 1) & 0xFF00) != (addr & 0xFF00)) | 165 | if (((regs.pc + 1) & 0xFF00) != (addr & 0xFF00)) |
| 156 | cycles++; | 166 | tick(); |
| 157 | 167 | ||
| 158 | regs.pc = addr; | 168 | regs.pc = addr; |
| 159 | } | 169 | } |
| @@ -946,18 +956,21 @@ interpret(void) | |||
| 946 | 956 | ||
| 947 | while (spaces--) putchar(' '); | 957 | while (spaces--) putchar(' '); |
| 948 | 958 | ||
| 949 | printf("A:%02X X:%02X Y:%02X P:%02X SP:%02X CYC:%d\n", | 959 | printf("A:%02X X:%02X Y:%02X P:%02X SP:%02X PPU:%3d,%3d CYC:%d\n", |
| 950 | regs.a, regs.x, regs.y, STATUS_TO_INT(), regs.sp, cycles); | 960 | regs.a, regs.x, regs.y, STATUS_TO_INT(), regs.sp, |
| 961 | ppu.scanlines, ppu.cycles, cycles); | ||
| 951 | 962 | ||
| 952 | if (opcodes[op].memread) | 963 | if (opcodes[op].memread) |
| 953 | opcodes[op].instr(peek(arg)); | 964 | opcodes[op].instr(peek(arg)); |
| 954 | else | 965 | else |
| 955 | opcodes[op].instr(arg); | 966 | opcodes[op].instr(arg); |
| 956 | 967 | ||
| 957 | cycles += opcodes[op].cycles; | 968 | for (uint8_t i = 0; i < opcodes[op].cycles; i++) |
| 969 | tick(); | ||
| 970 | |||
| 958 | if (page_crossed) { | 971 | if (page_crossed) { |
| 959 | if (opcodes[op].page_cross) | 972 | if (opcodes[op].page_cross) |
| 960 | cycles++; | 973 | tick(); |
| 961 | page_crossed = false; | 974 | page_crossed = false; |
| 962 | } | 975 | } |
| 963 | } | 976 | } |
| @@ -976,6 +989,8 @@ cpu_init(void) | |||
| 976 | regs.status.unused = 1; | 989 | regs.status.unused = 1; |
| 977 | 990 | ||
| 978 | cycles += 7; | 991 | cycles += 7; |
| 992 | for (uint8_t i = 0; i < 7 * 3; i++) | ||
| 993 | ppu_tick(); | ||
| 979 | } | 994 | } |
| 980 | 995 | ||
| 981 | int | 996 | int |
