From c684c194bccdb08df75423680ba334739a945fe5 Mon Sep 17 00:00:00 2001 From: Maxwell Beck Date: Tue, 24 Dec 2024 10:54:02 -0600 Subject: Initial commit --- src/6502.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/6502.h (limited to 'src/6502.h') diff --git a/src/6502.h b/src/6502.h new file mode 100644 index 0000000..1333623 --- /dev/null +++ b/src/6502.h @@ -0,0 +1,38 @@ +#ifndef MOS6502_H +#define MOS6502_H + +#include +#include + +#define FLAG_C_BIT 0 +#define FLAG_Z_BIT 1 +#define FLAG_I_BIT 2 +#define FLAG_D_BIT 3 +#define FLAG_B_BIT 4 +#define FLAG_U_BIT 5 +#define FLAG_N_BIT 6 +#define FLAG_V_BIT 7 + +#define FLAG_GET(f) ((cpu->flags & (1 << FLAG_##f##_BIT)) >> FLAG_##f##_BIT) +#define FLAG_SET(f, v) (cpu->flags = (cpu->flags & ~(1 << FLAG_##f##_BIT)) | ((v) << FLAG_##f##_BIT)) + +extern uint8_t bus_read(uint16_t addr, uint8_t cycle); +extern void bus_write(uint16_t addr, uint8_t v, uint8_t cycle); + +typedef struct cpu_s { + uint16_t pc; + uint8_t a; + uint8_t x; + uint8_t y; + uint8_t sp; + uint8_t flags; + + bool irq; + bool nmi; + bool jammed; +} cpu_t; + +void cpu_reset(cpu_t *cpu); +uint8_t cpu_step(cpu_t *cpu); + +#endif \ No newline at end of file -- cgit 1.4.1