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
+10 -11
View File
@@ -1,18 +1,17 @@
#ifndef ADDRESSING_H
#define ADDRESSING_H
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
typedef struct
{
uint8_t (*read8)(uint16_t addr, void *userdata);
void (*read16)(uint16_t addr, void *userdata);
typedef enum {
AM_IMP, AM_ACC, AM_IMM, AM_ZP, AM_ZPX, AM_ZPY, AM_ABS, AM_ABSX,
AM_ABSY, AM_IND, AM_INDX, AM_INDY, AM_REL
} addr_mode_t;
void *userdata;
typedef struct {
uint16_t address;
bool page_crossed;
} addr_result_t;
// cpu registers
} addr_ctx_t;
#endif
#endif
+24
View File
@@ -0,0 +1,24 @@
#ifndef BUS_H
#define BUS_H
#include <stdbool.h>
#include <stdint.h>
#include "memory.h"
typedef struct Bus6502 {
Memory memory;
uint8_t keyboard;
uint32_t rng_state;
bool easy6502_io;
bool framebuffer_dirty;
} Bus6502;
void bus_init(Bus6502 *bus);
uint8_t bus_read(Bus6502 *bus, uint16_t addr);
void bus_write(Bus6502 *bus, uint16_t addr, uint8_t value);
uint16_t bus_read16(Bus6502 *bus, uint16_t addr);
void bus_write16(Bus6502 *bus, uint16_t addr, uint16_t value);
void bus_set_keyboard(Bus6502 *bus, uint8_t key);
void bus_seed_rng(Bus6502 *bus, uint32_t seed);
#endif
+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
+6
View File
@@ -0,0 +1,6 @@
#ifndef FRONTEND_H
#define FRONTEND_H
#include "bus.h"
#include "cpu.h"
int frontend_run(CPU6502 *cpu, Bus6502 *bus, unsigned hz, unsigned scale);
#endif
+11
View File
@@ -0,0 +1,11 @@
#ifndef LOADER_H
#define LOADER_H
#include <stddef.h>
#include <stdint.h>
#include "bus.h"
int load_binary(Bus6502 *bus, const char *path, uint16_t address,
size_t *bytes_loaded);
#endif
+11
View File
@@ -0,0 +1,11 @@
#ifndef OPCODE_H
#define OPCODE_H
#include <stddef.h>
#include <stdint.h>
#include "bus.h"
#include "cpu.h"
size_t cpu_disassemble(Bus6502 *bus, uint16_t pc, char *output, size_t size);
#endif