add CPU and memory modules with associated header files; update README and .gitignore

This commit is contained in:
2025-12-21 18:45:56 +03:00
parent 7d607ec86d
commit 45b96c4390
7 changed files with 39 additions and 2 deletions
+18
View File
@@ -0,0 +1,18 @@
#ifndef ADDRESSING_H
#define ADDRESSING_H
#include <stdint.h>
#include <stddef.h>
typedef struct
{
uint8_t (*read8)(uint16_t addr, void *userdata);
void (*read16)(uint16_t addr, void *userdata);
void *userdata;
// cpu registers
} addr_ctx_t;
#endif
+29
View File
@@ -0,0 +1,29 @@
#ifndef CPU_H
#define CPU_H
#include <stdint.h>
typedef struct
{
uint8_t A; // accumulator
uint8_t X; // index X
uint8_t Y; // index y
uint8_t S; // stack pointer
uint8_t PC; // program counter
uint8_t P; // status flags
} 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
void cpu_reset(CPU6502 *cpu);
void cpu_print_state(CPU6502 *cpu);
#endif
+17
View File
@@ -0,0 +1,17 @@
#ifndef MEMORY_H
#define MEMORY_H
#include <stdint.h>
#define MEM_SIZE 65536 // 64KB memory size
typedef struct
{
uint8_t data[MEM_SIZE];
} Memory;
uint8_t mem_read(Memory *mem, uint16_t addr);
void mem_write(Memory *mem, uint16_t addr, uint8_t value);
void mem_reset(Memory *mem);
#endif
View File