Files
6502PC/src/memoryMap.c
T
2026-09-27 01:21:42 +02:00

62 lines
1.4 KiB
C

#include "memoryMap.h"
uint8_t readMemory(uint16_t address, uint8_t *ram, uint8_t *rom) {
if ((address < RAM_SIZE && address < IO_BASE) || address >= ROM_BASE) {
if (address >= ROM_BASE && ram[IO_BASE + ROM_BANKED_OUT] == 0) {
return rom[address - ROM_BASE];
}
return ram[address];
} else {
uint16_t _address = address - IO_BASE;
switch (_address) {
case KEYBOARD_ADDRESS: {
return getChar();
}
case ROM_BANKED_OUT: {
return ram[IO_BASE + ROM_BANKED_OUT];
}
default:
break;
}
return 0;
}
}
void writeMemory(uint16_t address, uint8_t value, uint8_t *ram) {
/* Normal RAM */
if (address < IO_BASE) {
ram[address] = value;
return;
}
/* ROM area */
if (address >= ROM_BASE) {
if (ram[IO_BASE + ROM_BANKED_OUT] != 0) {
ram[address] = value;
}
return;
}
/* I/O area */
uint16_t _address = address - IO_BASE;
switch (_address) {
case SCREEN_ADDRESS:
putChar(value);
break;
case ROM_BANKED_OUT:
ram[IO_BASE + ROM_BANKED_OUT] = value;
break;
default:
break;
}
}
uint8_t readStack(uint8_t address, uint8_t *ram) { return ram[0x100 + address]; }
void writeStack(uint8_t address, uint8_t value, uint8_t *ram) { ram[0x100 + address] = value; }