completed game

This commit is contained in:
2026-07-20 12:29:15 +03:00
parent 758fac98f6
commit c6e1c5b3b5
26 changed files with 1263 additions and 607 deletions
+28 -20
View File
@@ -1,29 +1,37 @@
#ifndef CPU_H
#define CPU_H
#include <stdbool.h>
#include <stdint.h>
typedef struct
{
uint8_t A; // accumulator
uint8_t X; // index X
uint8_t Y; // index y
uint8_t SP; // stack pointer
uint8_t PC; // program counter
uint8_t P; // status flags
typedef struct Bus6502 Bus6502;
typedef struct CPU6502 {
uint8_t A, X, Y;
uint8_t SP;
uint16_t PC;
uint8_t P;
bool nmi_pending;
bool irq_asserted;
} CPU6502;
// status flag masks
#define FLAG_C 0x01
#define FLAG_Z 0x02
#define FLAG_I 0x04
#define FLAG_D 0x08
#define FLAG_B 0x10
#define FLAG_U 0x20
#define FLAG_V 0x40
#define FLAG_N 0x80
enum {
FLAG_C = 0x01, FLAG_Z = 0x02, FLAG_I = 0x04, FLAG_D = 0x08,
FLAG_B = 0x10, FLAG_U = 0x20, FLAG_V = 0x40, FLAG_N = 0x80
};
void cpu_reset(CPU6502 *cpu);
void cpu_print_state(CPU6502 *cpu);
typedef enum { CPU_STEP_OK = 0, CPU_STEP_ILLEGAL_OPCODE } cpu_step_status_t;
#endif
typedef struct {
cpu_step_status_t status;
uint8_t opcode;
uint8_t cycles;
} cpu_step_result_t;
void cpu_reset(CPU6502 *cpu, Bus6502 *bus);
cpu_step_result_t cpu_step(CPU6502 *cpu, Bus6502 *bus);
void cpu_request_nmi(CPU6502 *cpu);
void cpu_set_irq(CPU6502 *cpu, bool asserted);
void cpu_print_state(const CPU6502 *cpu);
#endif