diff --git a/Machines/Vic-20/Vic20.cpp b/Machines/Vic-20/Vic20.cpp index 38217047f..7d0ab6922 100644 --- a/Machines/Vic-20/Vic20.cpp +++ b/Machines/Vic-20/Vic20.cpp @@ -31,7 +31,8 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin } else { - if(address < sizeof(_ram)) _ram[address] = *value; + uint8_t *ram = ram_pointer(address); + if(ram) *ram = *value; else if((address&0xfff0) == 0x9000) { _mos6560->set_register(address - 0x9000, *value); diff --git a/Machines/Vic-20/Vic20.hpp b/Machines/Vic-20/Vic20.hpp index 1d528977f..2516ada94 100644 --- a/Machines/Vic-20/Vic20.hpp +++ b/Machines/Vic-20/Vic20.hpp @@ -43,10 +43,21 @@ class Machine: public CPU6502::Processor, public CRTMachine::Machine { uint8_t _characterROM[0x1000]; uint8_t _basicROM[0x2000]; uint8_t _kernelROM[0x2000]; - uint8_t _ram[0x2000]; + + uint8_t _userBASICMemory[0x0400]; + uint8_t _screenMemory[0x1000]; + uint8_t _colorMemory[0x0200]; + + inline uint8_t *ram_pointer(uint16_t address) { + if(address < sizeof(_userBASICMemory)) return &_userBASICMemory[address]; + if(address >= 0x1000 && address < 0x1200) return &_screenMemory[address&0x0fff]; + if(address >= 0x9400 && address < 0x9600) return &_colorMemory[0x01ff]; + return nullptr; + } inline uint8_t read_memory(uint16_t address) { - if(address < sizeof(_ram)) return _ram[address]; + uint8_t *ram = ram_pointer(address); + if(ram) return *ram; else if(address >= 0x8000 && address < 0x9000) return _characterROM[address&0x0fff]; else if(address >= 0xc000 && address < 0xe000) return _basicROM[address&0x1fff]; else if(address >= 0xe000) return _kernelROM[address&0x1fff];