fix warnings and move cpu registers+flags to header

This commit is contained in:
Vineet K 2024-07-07 13:04:10 -04:00
parent 3e0563ce05
commit ca5a09cd94
2 changed files with 28 additions and 23 deletions

25
cpu.c
View File

@ -35,29 +35,7 @@
#define PULL() \
(peek(0x0100 + ++regs.sp))
struct cpu_flags {
uint8_t carry : 1;
uint8_t zero : 1;
uint8_t interrupt_disable : 1;
uint8_t decimal_mode : 1;
uint8_t brk : 1;
uint8_t unused : 1;
uint8_t overflow : 1;
uint8_t negative : 1;
};
struct registers {
uint8_t a, x, y, sp;
struct cpu_flags status;
uint16_t pc;
};
struct registers regs = {0};
struct Rom rom = {0};
/* 64K address space, 16bit words */
uint8_t memory[0x16000];
uint32_t cycles = 0;
bool page_crossed = false;
@ -72,6 +50,8 @@ peek(uint16_t addr)
return rom.prg_rom[(addr - 0x8000) % 0x4000];
else if (rom.prg_rom_size == 0x8000)
return rom.prg_rom[addr - 0x8000];
else
fprintf(stderr, "PRG ROG size is not 0x4000 nor 0x8000\n"), exit(1);
} else {
return memory[addr];
}
@ -953,7 +933,6 @@ interpret(void)
page_crossed = false;
}
}
loop_exit:
}
/* https://www.nesdev.org/wiki/CPU_power_up_state */

26
cpu.h
View File

@ -1,5 +1,29 @@
#ifndef CPU_H
#define CPU_H
#include <stdint.h>
struct cpu_flags {
uint8_t carry : 1;
uint8_t zero : 1;
uint8_t interrupt_disable : 1;
uint8_t decimal_mode : 1;
uint8_t brk : 1;
uint8_t unused : 1;
uint8_t overflow : 1;
uint8_t negative : 1;
};
struct registers {
uint8_t a, x, y, sp;
struct cpu_flags status;
uint16_t pc;
};
struct registers regs = {0};
/* 64K address space, 16bit words */
uint8_t memory[0x16000];
/* OFFICIAL OPCODES */
void ADC(uint16_t arg);
void AND(uint16_t arg);
@ -87,3 +111,5 @@ void SYA(uint16_t arg);
void TOP(uint16_t arg);
void XAA(uint16_t arg);
void XAS(uint16_t arg);
#endif /* CPU_H */