From 167ed9b8bbd1e82c7851b8417fae7a1a04b95d8b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 11 Jun 2016 14:00:12 -0400 Subject: [PATCH] Added enough to load a PRG as a ROM. --- Machines/Vic-20/Vic20.cpp | 15 ++++++++++++++- Machines/Vic-20/Vic20.hpp | 5 +++++ OSBindings/Mac/Clock Signal/Wrappers/CSVic20.mm | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Machines/Vic-20/Vic20.cpp b/Machines/Vic-20/Vic20.cpp index 313330df2..a9088de17 100644 --- a/Machines/Vic-20/Vic20.cpp +++ b/Machines/Vic-20/Vic20.cpp @@ -14,13 +14,19 @@ using namespace Vic20; Machine::Machine() : _userPortVIA(new UserPortVIA()), - _keyboardVIA(new KeyboardVIA()) + _keyboardVIA(new KeyboardVIA()), + _rom(nullptr) { _userPortVIA->set_delegate(this); _keyboardVIA->set_delegate(this); set_reset_line(true); } +Machine::~Machine() +{ + delete[] _rom; +} + unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { set_reset_line(false); @@ -115,4 +121,11 @@ void Machine::set_rom(ROMSlot slot, size_t length, const uint8_t *data) void Machine::add_prg(size_t length, const uint8_t *data) { + if(length > 2) + { + _rom_address = (uint16_t)(data[0] | (data[1] << 8)); + _rom_length = (uint16_t)(length - 2); + _rom = new uint8_t[length - 2]; + memcpy(_rom, &data[2], length - 2); + } } diff --git a/Machines/Vic-20/Vic20.hpp b/Machines/Vic-20/Vic20.hpp index 715ac228e..3d62adc20 100644 --- a/Machines/Vic-20/Vic20.hpp +++ b/Machines/Vic-20/Vic20.hpp @@ -94,6 +94,7 @@ class KeyboardVIA: public MOS::MOS6522 { class Machine: public CPU6502::Processor, public CRTMachine::Machine, public MOS::MOS6522Delegate { public: Machine(); + ~Machine(); void set_rom(ROMSlot slot, size_t length, const uint8_t *data); void add_prg(size_t length, const uint8_t *data); @@ -118,6 +119,9 @@ class Machine: public CPU6502::Processor, public CRTMachine::Machine, p uint8_t _basicROM[0x2000]; uint8_t _kernelROM[0x2000]; + uint8_t *_rom; + uint16_t _rom_address, _rom_length; + uint8_t _userBASICMemory[0x0400]; uint8_t _screenMemory[0x1000]; uint8_t _colorMemory[0x0400]; @@ -135,6 +139,7 @@ class Machine: public CPU6502::Processor, public CRTMachine::Machine, p 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]; + else if(address >= _rom_address && address < _rom_address+_rom_length) return _rom[address - _rom_address]; return 0xff; } diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSVic20.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSVic20.mm index d5227614e..6354cfd16 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSVic20.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSVic20.mm @@ -83,6 +83,8 @@ { _vic20.set_key_state((Vic20::Key)targetKey.integerValue, isPressed); } + else + NSLog(@"Unmapped: %02x", key); } break; case VK_Shift: