diff options
| author | vin <git@vineetk.net> | 2024-07-07 13:04:10 -0400 |
|---|---|---|
| committer | vin <git@vineetk.net> | 2024-07-07 13:04:16 -0400 |
| commit | ca5a09cd94a5fc92e727cd69fb89f58760f34176 (patch) | |
| tree | 75d4c030de9f07115dfd1b3ddaf46f284a16d6f4 /cpu.c | |
| parent | 3e0563ce059172001d06688809096972696f83a4 (diff) | |
fix warnings and move cpu registers+flags to header
Diffstat (limited to 'cpu.c')
| -rw-r--r-- | cpu.c | 25 |
1 files changed, 2 insertions, 23 deletions
| @@ -35,29 +35,7 @@ | |||
| 35 | #define PULL() \ | 35 | #define PULL() \ |
| 36 | (peek(0x0100 + ++regs.sp)) | 36 | (peek(0x0100 + ++regs.sp)) |
| 37 | 37 | ||
| 38 | struct cpu_flags { | ||
| 39 | uint8_t carry : 1; | ||
| 40 | uint8_t zero : 1; | ||
| 41 | uint8_t interrupt_disable : 1; | ||
| 42 | uint8_t decimal_mode : 1; | ||
| 43 | uint8_t brk : 1; | ||
| 44 | uint8_t unused : 1; | ||
| 45 | uint8_t overflow : 1; | ||
| 46 | uint8_t negative : 1; | ||
| 47 | }; | ||
| 48 | |||
| 49 | struct registers { | ||
| 50 | uint8_t a, x, y, sp; | ||
| 51 | struct cpu_flags status; | ||
| 52 | uint16_t pc; | ||
| 53 | }; | ||
| 54 | struct registers regs = {0}; | ||
| 55 | |||
| 56 | struct Rom rom = {0}; | 38 | struct Rom rom = {0}; |
| 57 | |||
| 58 | /* 64K address space, 16bit words */ | ||
| 59 | uint8_t memory[0x16000]; | ||
| 60 | |||
| 61 | uint32_t cycles = 0; | 39 | uint32_t cycles = 0; |
| 62 | 40 | ||
| 63 | bool page_crossed = false; | 41 | bool page_crossed = false; |
| @@ -72,6 +50,8 @@ peek(uint16_t addr) | |||
| 72 | return rom.prg_rom[(addr - 0x8000) % 0x4000]; | 50 | return rom.prg_rom[(addr - 0x8000) % 0x4000]; |
| 73 | else if (rom.prg_rom_size == 0x8000) | 51 | else if (rom.prg_rom_size == 0x8000) |
| 74 | return rom.prg_rom[addr - 0x8000]; | 52 | return rom.prg_rom[addr - 0x8000]; |
| 53 | else | ||
| 54 | fprintf(stderr, "PRG ROG size is not 0x4000 nor 0x8000\n"), exit(1); | ||
| 75 | } else { | 55 | } else { |
| 76 | return memory[addr]; | 56 | return memory[addr]; |
| 77 | } | 57 | } |
| @@ -953,7 +933,6 @@ interpret(void) | |||
| 953 | page_crossed = false; | 933 | page_crossed = false; |
| 954 | } | 934 | } |
| 955 | } | 935 | } |
| 956 | loop_exit: | ||
| 957 | } | 936 | } |
| 958 | 937 | ||
| 959 | /* https://www.nesdev.org/wiki/CPU_power_up_state */ | 938 | /* https://www.nesdev.org/wiki/CPU_power_up_state */ |
