From b35d280f12bc2233a32e546a4bc9c34ca65f3f59 Mon Sep 17 00:00:00 2001 From: 0xmac Date: Mon, 2 Dec 2024 14:06:20 +0100 Subject: [PATCH] Added memory manager --- src/memory.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/memory.h | 21 +++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/memory.c create mode 100644 src/memory.h diff --git a/src/memory.c b/src/memory.c new file mode 100644 index 0000000..73543c9 --- /dev/null +++ b/src/memory.c @@ -0,0 +1,64 @@ +#include +#include "memory.h" + +uint8_t read6502(uint16_t address){ + switch (address){ + case RAMLOC ... RAMLOC + RAMSIZE: + return ram[address - RAMLOC]; + break; + + case ROMLOC ... ROMLOC + ROMSIZE: + return rom[address - ROMLOC]; + break; + + case VIDADDRS ... VIDADDRS + PAGESIZE: + if ((address - VIDADDRS) % 4 == 3) return readVideo(); + else return 0; + break; + + case 0xBD00: + scanKeyboard(); + return keyboardResult; + break; + + default: + return NOP; + break; + } +} + +void write6502(uint16_t address, uint8_t value){ + switch (address){ + case RAMLOC ... RAMLOC + RAMSIZE: + ram[address - RAMLOC] = value; + break; + + case ROMLOC ... ROMLOC + ROMSIZE: + rom[address - ROMLOC] = value; + break; + + case VIDADDRS ... VIDADDRS + PAGESIZE: + switch ((address - VIDADDRS) % 4){ + case 0: /* Video X Register */ + videoX = value; + break; + case 1: /* Video Y Register */ + videoY = value; + break; + case 2: /* Video M Register */ + videoMode = value; + break; + case 3: /* Video A Register */ + videoA = value; + writeVideo(); + break; + } + break; + case 0xBC00: + systemRegister = value; + break; + + default: + break; + } +} diff --git a/src/memory.h b/src/memory.h new file mode 100644 index 0000000..e3b3e18 --- /dev/null +++ b/src/memory.h @@ -0,0 +1,21 @@ +#include + +#include "config.h" + +extern void scanKeyboard(); +extern void writeVideo(); +extern uint8_t readVideo(); +extern uint8_t videoX; +extern uint8_t videoY; +extern uint8_t videoMode; +extern uint8_t videoA; + +static int8_t ram[RAMSIZE + 1]; +static int8_t rom[ROMSIZE + 1]; + +static uint8_t systemRegister; +static uint8_t keyboardResult; + + +uint8_t read6502(uint16_t address); +void write6502(uint16_t address, uint8_t value);