diff options
Diffstat (limited to 'emu/6502.h')
-rw-r--r-- | emu/6502.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/emu/6502.h b/emu/6502.h new file mode 100644 index 0000000..1af25bc --- /dev/null +++ b/emu/6502.h @@ -0,0 +1,60 @@ +#ifndef CPU_6502_H +#define CPU_6502_H + +#include <inttypes.h> +#include <stdbool.h> + +typedef struct +{ + uint8_t A; + uint8_t X; + uint8_t Y; + uint8_t SP; + uint16_t PC; + uint8_t PS; + + struct memory_t *memory; + + bool debug; +} cpu_6502_t; + +enum { + PS_N = 0x80, + PS_V = 0x40, + PS_B = 0x10, + PS_D = 0x08, + PS_I = 0x04, + PS_Z = 0x02, + PS_C = 0x01 +}; + +enum { + LDX_IMM = 0xA2, + LDX_ZERO = 0xA6, + LDY_IMM = 0xA0, + LDY_ZERO = 0xA4, + LDA_IMM = 0xA9, + LDA_ZERO = 0xA5, + JMP_ABS = 0x4C, + JSR_ABS = 0x20, + RTS_IMPL = 0x60, + TXS_IMPL = 0x9A +}; + +void cpu_6502_init( cpu_6502_t *cpu, struct memory_t *memory ); +void cpu_6502_reset( cpu_6502_t *cpu ); +uint8_t cpu_6502_read_byte( cpu_6502_t *cpu, uint16_t addr ); +uint16_t cpu_6502_read_word( cpu_6502_t *cpu, uint16_t addr ); +void cpu_6502_write_byte( cpu_6502_t *cpu, uint16_t addr, uint8_t data ); +void cpu_6502_push_byte( cpu_6502_t *cpu, uint8_t data ); +void cpu_6502_push_word( cpu_6502_t *cpu, uint16_t data ); +uint8_t cpu_6502_pop_byte( cpu_6502_t *cpu ); +uint16_t cpu_6502_pop_word( cpu_6502_t *cpu ); +void cpu_6502_run( cpu_6502_t *cpu ); +void cpu_6502_print_state( cpu_6502_t *cpu, uint8_t opcode ); +void cpu_6502_print_memory( cpu_6502_t *cpu, uint16_t base, uint8_t size ); +void cpu_6502_print_stack( cpu_6502_t *cpu ); +void cpu_6502_print_zerop_page( cpu_6502_t *cpu ); +void cpu_6502_step( cpu_6502_t *cpu ); + +#endif |