summary refs log tree commit diff
path: root/src/6502.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/6502.h')
-rw-r--r--src/6502.h38
1 files changed, 38 insertions, 0 deletions
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 <stdint.h>
+#include <stdbool.h>
+
+#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