Added memory manager

This commit is contained in:
0xmac 2024-12-02 14:06:20 +01:00
parent 0227bc634f
commit b35d280f12
2 changed files with 85 additions and 0 deletions

64
src/memory.c Normal file
View File

@ -0,0 +1,64 @@
#include <stdint.h>
#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;
}
}

21
src/memory.h Normal file
View File

@ -0,0 +1,21 @@
#include <stdint.h>
#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);