From a547b7e1d82796fccae0a48e31540749a863190f Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 13 Aug 2016 17:21:25 -0400 Subject: [PATCH 1/9] Took basic steps towards supporting memory expansions. --- Machines/Commodore/Vic-20/Vic20.cpp | 28 ++++++++++++++++++++++++---- Machines/Commodore/Vic-20/Vic20.hpp | 8 ++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp index 097d63cfe..3050216e8 100644 --- a/Machines/Commodore/Vic-20/Vic20.cpp +++ b/Machines/Commodore/Vic-20/Vic20.cpp @@ -35,9 +35,33 @@ Machine::Machine() : _tape.set_delegate(this); // establish the memory maps + set_memory_size(MemorySize::Default); + +// _debugPort.reset(new ::Commodore::Serial::DebugPort); +// _debugPort->set_serial_bus(_serialBus); +// _serialBus->add_port(_debugPort); +} + +void Machine::set_memory_size(MemorySize size) +{ memset(_processorReadMemoryMap, 0, sizeof(_processorReadMemoryMap)); memset(_processorWriteMemoryMap, 0, sizeof(_processorWriteMemoryMap)); + switch(size) + { + default: break; + case ThreeKB: + write_to_map(_processorReadMemoryMap, _expansionRAM, 0x0000, 0x1000); + write_to_map(_processorWriteMemoryMap, _expansionRAM, 0x0000, 0x1000); + break; + case ThirtyTwoKB: + write_to_map(_processorReadMemoryMap, _expansionRAM, 0x0000, 0x8000); + write_to_map(_processorWriteMemoryMap, _expansionRAM, 0x0000, 0x8000); + break; + } + + + // install the ROMs and VIC-visible memory write_to_map(_processorReadMemoryMap, _userBASICMemory, 0x0000, sizeof(_userBASICMemory)); write_to_map(_processorReadMemoryMap, _screenMemory, 0x1000, sizeof(_screenMemory)); write_to_map(_processorReadMemoryMap, _colorMemory, 0x9400, sizeof(_colorMemory)); @@ -48,10 +72,6 @@ Machine::Machine() : write_to_map(_processorWriteMemoryMap, _userBASICMemory, 0x0000, sizeof(_userBASICMemory)); write_to_map(_processorWriteMemoryMap, _screenMemory, 0x1000, sizeof(_screenMemory)); write_to_map(_processorWriteMemoryMap, _colorMemory, 0x9400, sizeof(_colorMemory)); - -// _debugPort.reset(new ::Commodore::Serial::DebugPort); -// _debugPort->set_serial_bus(_serialBus); -// _serialBus->add_port(_debugPort); } void Machine::write_to_map(uint8_t **map, uint8_t *area, uint16_t address, uint16_t length) diff --git a/Machines/Commodore/Vic-20/Vic20.hpp b/Machines/Commodore/Vic-20/Vic20.hpp index 29a1fe3e5..e1b4b8a3c 100644 --- a/Machines/Commodore/Vic-20/Vic20.hpp +++ b/Machines/Commodore/Vic-20/Vic20.hpp @@ -32,6 +32,12 @@ enum ROMSlot { Drive }; +enum MemorySize { + Default, + ThreeKB, + ThirtyTwoKB +}; + #define key(line, mask) (((mask) << 3) | (line)) enum Key: uint16_t { @@ -259,6 +265,7 @@ class Machine: _userPortVIA->set_joystick_state(input, isPressed); _keyboardVIA->set_joystick_state(input, isPressed); } + void set_memory_size(MemorySize size); inline void set_use_fast_tape_hack(bool activate) { _use_fast_tape_hack = activate; } inline void set_should_automatically_load_media(bool activate) { _should_automatically_load_media = activate; } @@ -291,6 +298,7 @@ class Machine: uint8_t _characterROM[0x1000]; uint8_t _basicROM[0x2000]; uint8_t _kernelROM[0x2000]; + uint8_t _expansionRAM[0x8000]; uint8_t *_rom; uint16_t _rom_address, _rom_length; From d9016909edbd341a0c3dce7c97e94c62778bc11a Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 14 Aug 2016 13:33:20 -0400 Subject: [PATCH 2/9] Added some wiring for PAL/NTSC mode switching on the Vic, making an attempt to simplify the whole loop of having different clock rates. --- Machines/Atari2600/Atari2600.cpp | 11 ++++------- Machines/Atari2600/Atari2600.hpp | 1 - Machines/CRTMachine.hpp | 17 ++++++++++++++--- Machines/Commodore/Vic-20/Vic20.cpp | 20 +++++++++++++++++++- Machines/Commodore/Vic-20/Vic20.hpp | 10 +++++++++- Machines/Electron/Electron.cpp | 1 + Machines/Electron/Electron.hpp | 1 - 7 files changed, 47 insertions(+), 14 deletions(-) diff --git a/Machines/Atari2600/Atari2600.cpp b/Machines/Atari2600/Atari2600.cpp index 9260e22e5..6d76cdadb 100644 --- a/Machines/Atari2600/Atari2600.cpp +++ b/Machines/Atari2600/Atari2600.cpp @@ -13,6 +13,8 @@ using namespace Atari2600; namespace { static const unsigned int horizontalTimerPeriod = 228; + static const double NTSC_clock_rate = 1194720; + static const double PAL_clock_rate = 1182298; } Machine::Machine() : @@ -52,6 +54,7 @@ Machine::Machine() : _stateByExtendTime[vbextend][c] = state; } } + set_clock_rate(NTSC_clock_rate); } void Machine::setup_output(float aspect_ratio) @@ -94,8 +97,7 @@ void Machine::switch_region() _is_pal_region = true; _speaker->set_input_rate((float)(get_clock_rate() / 38.0)); - - if(delegate) delegate->machine_did_change_clock_rate(this); + set_clock_rate(PAL_clock_rate); } void Machine::close_output() @@ -109,11 +111,6 @@ Machine::~Machine() close_output(); } -double Machine::get_clock_rate() -{ - return _is_pal_region ? 1182298 : 1194720; -} - void Machine::update_timers(int mask) { unsigned int upcomingPointerPlus4 = (_upcomingEventsPointer + 4)%number_of_upcoming_events; diff --git a/Machines/Atari2600/Atari2600.hpp b/Machines/Atari2600/Atari2600.hpp index 4a1778b14..3b9fa0131 100644 --- a/Machines/Atari2600/Atari2600.hpp +++ b/Machines/Atari2600/Atari2600.hpp @@ -94,7 +94,6 @@ class Machine: public CPU6502::Processor, public CRTMachine::Machine { virtual std::shared_ptr get_crt() { return _crt; } virtual std::shared_ptr get_speaker() { return _speaker; } virtual void run_for_cycles(int number_of_cycles) { CPU6502::Processor::run_for_cycles(number_of_cycles); } - virtual double get_clock_rate(); // TODO: different rate for PAL private: diff --git a/Machines/CRTMachine.hpp b/Machines/CRTMachine.hpp index c193199c4..6e00b482f 100644 --- a/Machines/CRTMachine.hpp +++ b/Machines/CRTMachine.hpp @@ -30,15 +30,26 @@ class Machine { virtual void run_for_cycles(int number_of_cycles) = 0; // TODO: sever the clock-rate stuff. - virtual double get_clock_rate() = 0; + double get_clock_rate() { + return clock_rate_; + } class Delegate { public: virtual void machine_did_change_clock_rate(Machine *machine) = 0; }; - void set_delegate(Delegate *delegate) { this->delegate = delegate; } + void set_delegate(Delegate *delegate) { this->delegate_ = delegate; } protected: - Delegate *delegate; + double clock_rate_; + void set_clock_rate(double clock_rate) { + if(clock_rate_ != clock_rate) { + clock_rate_ = clock_rate; + if(delegate_) delegate_->machine_did_change_clock_rate(this); + } + } + + private: + Delegate *delegate_; }; } diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp index 3050216e8..664277c44 100644 --- a/Machines/Commodore/Vic-20/Vic20.cpp +++ b/Machines/Commodore/Vic-20/Vic20.cpp @@ -37,6 +37,8 @@ Machine::Machine() : // establish the memory maps set_memory_size(MemorySize::Default); + // set the NTSC clock rate + set_region(NTSC); // _debugPort.reset(new ::Commodore::Serial::DebugPort); // _debugPort->set_serial_bus(_serialBus); // _serialBus->add_port(_debugPort); @@ -60,7 +62,6 @@ void Machine::set_memory_size(MemorySize size) break; } - // install the ROMs and VIC-visible memory write_to_map(_processorReadMemoryMap, _userBASICMemory, 0x0000, sizeof(_userBASICMemory)); write_to_map(_processorReadMemoryMap, _screenMemory, 0x1000, sizeof(_screenMemory)); @@ -161,9 +162,26 @@ void Machine::mos6522_did_change_interrupt_status(void *mos6522) #pragma mark - Setup +void Machine::set_region(Commodore::Vic20::Region region) +{ + _region = region; + switch(region) + { + case PAL: + set_clock_rate(1108404); + if(_mos6560) _mos6560->set_output_mode(MOS::MOS6560::OutputMode::PAL); + break; + case NTSC: + set_clock_rate(1022727); + if(_mos6560) _mos6560->set_output_mode(MOS::MOS6560::OutputMode::NTSC); + break; + } +} + void Machine::setup_output(float aspect_ratio) { _mos6560.reset(new Vic6560()); + set_region(_region); memset(_mos6560->_videoMemoryMap, 0, sizeof(_mos6560->_videoMemoryMap)); write_to_map(_mos6560->_videoMemoryMap, _characterROM, 0x0000, sizeof(_characterROM)); diff --git a/Machines/Commodore/Vic-20/Vic20.hpp b/Machines/Commodore/Vic-20/Vic20.hpp index e1b4b8a3c..e4fb58386 100644 --- a/Machines/Commodore/Vic-20/Vic20.hpp +++ b/Machines/Commodore/Vic-20/Vic20.hpp @@ -38,6 +38,11 @@ enum MemorySize { ThirtyTwoKB }; +enum Region { + NTSC, + PAL +}; + #define key(line, mask) (((mask) << 3) | (line)) enum Key: uint16_t { @@ -265,7 +270,9 @@ class Machine: _userPortVIA->set_joystick_state(input, isPressed); _keyboardVIA->set_joystick_state(input, isPressed); } + void set_memory_size(MemorySize size); + void set_region(Region region); inline void set_use_fast_tape_hack(bool activate) { _use_fast_tape_hack = activate; } inline void set_should_automatically_load_media(bool activate) { _should_automatically_load_media = activate; } @@ -280,7 +287,6 @@ class Machine: virtual std::shared_ptr get_crt() { return _mos6560->get_crt(); } virtual std::shared_ptr get_speaker() { return _mos6560->get_speaker(); } virtual void run_for_cycles(int number_of_cycles) { CPU6502::Processor::run_for_cycles(number_of_cycles); } - virtual double get_clock_rate() { return 1022727; } // TODO: or 1108405 for PAL; see http://www.antimon.org/dl/c64/code/stable.txt // to satisfy MOS::MOS6522::Delegate @@ -313,6 +319,8 @@ class Machine: uint8_t *_processorWriteMemoryMap[64]; void write_to_map(uint8_t **map, uint8_t *area, uint16_t address, uint16_t length); + Region _region; + std::unique_ptr _mos6560; std::shared_ptr _userPortVIA; std::shared_ptr _keyboardVIA; diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index bf07f869d..30c9a0ad4 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -55,6 +55,7 @@ Machine::Machine() : memset(_roms[c], 0xff, 16384); _tape.set_delegate(this); + set_clock_rate(2000000); } void Machine::setup_output(float aspect_ratio) diff --git a/Machines/Electron/Electron.hpp b/Machines/Electron/Electron.hpp index d5f593e1a..6ec7b81a2 100644 --- a/Machines/Electron/Electron.hpp +++ b/Machines/Electron/Electron.hpp @@ -162,7 +162,6 @@ class Machine: virtual std::shared_ptr get_crt() { return _crt; } virtual std::shared_ptr get_speaker() { return _speaker; } virtual void run_for_cycles(int number_of_cycles) { CPU6502::Processor::run_for_cycles(number_of_cycles); } - virtual double get_clock_rate() { return 2000000; } // to satisfy Tape::Delegate virtual void tape_did_change_interrupt_status(Tape *tape); From df77c2a20afb91540bfc9245bd46121497532d88 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 14 Aug 2016 13:53:14 -0400 Subject: [PATCH 3/9] Added the XIB side of wiring for region and memory size options. --- .../Clock Signal/Base.lproj/Vic20Document.xib | 38 ++++++++++++++++--- .../Documents/Vic20Document.swift | 24 ++++++++++++ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Base.lproj/Vic20Document.xib b/OSBindings/Mac/Clock Signal/Base.lproj/Vic20Document.xib index cd45e6cb1..b50cdf757 100644 --- a/OSBindings/Mac/Clock Signal/Base.lproj/Vic20Document.xib +++ b/OSBindings/Mac/Clock Signal/Base.lproj/Vic20Document.xib @@ -6,8 +6,10 @@ + + @@ -44,16 +46,16 @@ - + - + - + + + + + + + + + + + + + + + + + + @@ -87,21 +106,28 @@ + + + + + + + - + diff --git a/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift b/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift index 7ad6b8c32..d911e2f24 100644 --- a/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift +++ b/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift @@ -69,15 +69,39 @@ class Vic20Document: MachineDocument { vic20.setPRG(data) } + // MARK: automatic loading tick box @IBOutlet var loadAutomaticallyButton: NSButton? var autoloadingUserDefaultsKey: String { get { return prefixedUserDefaultsKey("autoload") } } + @IBAction func setShouldLoadAutomatically(sender: NSButton!) { let loadAutomatically = sender.state == NSOnState vic20.shouldLoadAutomatically = loadAutomatically NSUserDefaults.standardUserDefaults().setBool(loadAutomatically, forKey: self.autoloadingUserDefaultsKey) } + + // MARK: country selector + @IBOutlet var countryButton: NSPopUpButton? + var countryUserDefaultsKey: String { + get { return prefixedUserDefaultsKey("country") } + } + + @IBAction func setCountry(sender: NSPopUpButton!) { + print("Country should be \(sender.indexOfSelectedItem)") + } + + // MARK: memory model selector + @IBOutlet var memorySizeButton: NSPopUpButton? + var memorySizeUserDefaultsKey: String { + get { return prefixedUserDefaultsKey("memorySize") } + } + + @IBAction func setMemorySize(sender: NSPopUpButton!) { + print("Memory size should be \(sender.indexOfSelectedItem)") + } + + // MARK: option restoration override func establishStoredOptions() { super.establishStoredOptions() From f15d89239fd9db0fd8628105260c6d540739631b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 14 Aug 2016 14:00:08 -0400 Subject: [PATCH 4/9] Made a stab at storage and restoration of country and memory size. --- .../Documents/Vic20Document.swift | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift b/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift index d911e2f24..e2e622f6d 100644 --- a/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift +++ b/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift @@ -88,7 +88,11 @@ class Vic20Document: MachineDocument { } @IBAction func setCountry(sender: NSPopUpButton!) { - print("Country should be \(sender.indexOfSelectedItem)") + NSUserDefaults.standardUserDefaults().setInteger(sender.indexOfSelectedItem, forKey: self.countryUserDefaultsKey) + setCountry(sender.indexOfSelectedItem) + } + + private func setCountry(countryID: Int) { } // MARK: memory model selector @@ -98,6 +102,16 @@ class Vic20Document: MachineDocument { } @IBAction func setMemorySize(sender: NSPopUpButton!) { + var selectedSize: Int? + switch sender.indexOfSelectedItem { + case 0: selectedSize = 5 + case 1: selectedSize = 8 + case 2: selectedSize = 32 + default: break + } + if let selectedSize = selectedSize { + NSUserDefaults.standardUserDefaults().setInteger(selectedSize, forKey: self.memorySizeUserDefaultsKey) + } print("Memory size should be \(sender.indexOfSelectedItem)") } @@ -107,11 +121,24 @@ class Vic20Document: MachineDocument { let standardUserDefaults = NSUserDefaults.standardUserDefaults() standardUserDefaults.registerDefaults([ - autoloadingUserDefaultsKey: true + self.autoloadingUserDefaultsKey: true, + self.memorySizeUserDefaultsKey: 5, + self.countryUserDefaultsKey: 4 ]) let loadAutomatically = standardUserDefaults.boolForKey(self.autoloadingUserDefaultsKey) vic20.shouldLoadAutomatically = loadAutomatically self.loadAutomaticallyButton?.state = loadAutomatically ? NSOnState : NSOffState + + let memorySize = standardUserDefaults.integerForKey(self.memorySizeUserDefaultsKey) + switch memorySize { + case 32: self.memorySizeButton?.selectItemAtIndex(2) + case 8: self.memorySizeButton?.selectItemAtIndex(1) + default: self.memorySizeButton?.selectItemAtIndex(0) + } + + let country = standardUserDefaults.integerForKey(self.countryUserDefaultsKey) + setCountry(country) + self.countryButton?.selectItemAtIndex(country) } } From b5af1746d51614b491bc09f1e7ad60396f3e361e Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 14 Aug 2016 14:14:59 -0400 Subject: [PATCH 5/9] Added a through path to the Objective-C for setting region and memory size. --- .../Clock Signal/Machine/Wrappers/CSVic20.h | 15 ++++++++++++ .../Clock Signal/Machine/Wrappers/CSVic20.mm | 24 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.h b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.h index daaee4c06..c8ade6c34 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.h +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.h @@ -10,6 +10,19 @@ #import "CSKeyboardMachine.h" #import "CSFastLoading.h" +typedef NS_ENUM(NSInteger, CSVic20Region) +{ + CSVic20RegionPAL, + CSVic20RegionNTSC +}; + +typedef NS_ENUM(NSInteger, CSVic20MemorySize) +{ + CSVic20MemorySize5Kb, + CSVic20MemorySize8Kb, + CSVic20MemorySize32Kb, +}; + @interface CSVic20 : CSMachine - (void)setKernelROM:(nonnull NSData *)rom; @@ -24,5 +37,7 @@ @property (nonatomic, assign) BOOL useFastLoadingHack; @property (nonatomic, assign) BOOL shouldLoadAutomatically; +@property (nonatomic, assign) CSVic20Region region; +@property (nonatomic, assign) CSVic20MemorySize memorySize; @end diff --git a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm index 1ad7165f9..5108741a1 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm @@ -190,18 +190,38 @@ using namespace Commodore::Vic20; } } +#pragma mark - Public configuration options + - (void)setUseFastLoadingHack:(BOOL)useFastLoadingHack { + _useFastLoadingHack = useFastLoadingHack; @synchronized(self) { - _useFastLoadingHack = useFastLoadingHack; _vic20.set_use_fast_tape_hack(useFastLoadingHack ? true : false); } } - (void)setShouldLoadAutomatically:(BOOL)shouldLoadAutomatically { + _shouldLoadAutomatically = shouldLoadAutomatically; @synchronized(self) { - _shouldLoadAutomatically = shouldLoadAutomatically; _vic20.set_should_automatically_load_media(shouldLoadAutomatically ? true : false); } } +- (void)setRegion:(CSVic20Region)region { + _region = region; + @synchronized(self) { + _vic20.set_region( (region == CSVic20RegionPAL) ? Commodore::Vic20::Region::PAL : Commodore::Vic20::Region::NTSC); + } +} + +- (void)setMemorySize:(CSVic20MemorySize)memorySize { + _memorySize = memorySize; + @synchronized(self) { + switch(memorySize) { + case CSVic20MemorySize5Kb: _vic20.set_memory_size(Commodore::Vic20::Default); break; + case CSVic20MemorySize8Kb: _vic20.set_memory_size(Commodore::Vic20::ThreeKB); break; + case CSVic20MemorySize32Kb: _vic20.set_memory_size(Commodore::Vic20::ThirtyTwoKB); break; + } + } +} + @end From 5373f6cc57e37163f0787928230bbe2fa3ef70d9 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 14 Aug 2016 14:23:08 -0400 Subject: [PATCH 6/9] Completed setting of options, including mapping from country to ROM + television standard. --- .../Documents/Vic20Document.swift | 59 +++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift b/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift index e2e622f6d..ed113cc29 100644 --- a/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift +++ b/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift @@ -26,12 +26,6 @@ class Vic20Document: MachineDocument { override init() { super.init() - if let kernel = rom("kernel-ntsc"), basic = rom("basic"), characters = rom("characters-english") { - vic20.setKernelROM(kernel) - vic20.setBASICROM(basic) - vic20.setCharactersROM(characters) - } - if let drive = dataForResource("1540", ofType: "bin", inDirectory: "ROMImages/Commodore1540") { vic20.setDriveROM(drive) } @@ -93,6 +87,39 @@ class Vic20Document: MachineDocument { } private func setCountry(countryID: Int) { + var charactersROM: String? + var kernelROM: String? + switch countryID { + case 0: // Danish + charactersROM = "characters-danish" + kernelROM = "kernel-danish" + vic20.region = .PAL + case 1: // European + charactersROM = "characters-english" + kernelROM = "kernel-pal" + vic20.region = .PAL + case 2: // Japanese + charactersROM = "characters-japanese" + kernelROM = "kernel-japanese" + vic20.region = .NTSC + case 3: // Swedish + charactersROM = "characters-swedish" + kernelROM = "kernel-swedish" + vic20.region = .PAL + case 4: // US + charactersROM = "characters-english" + kernelROM = "kernel-ntsc" + vic20.region = .NTSC + default: break + } + + if let charactersROM = charactersROM, kernelROM = kernelROM { + if let kernel = rom(kernelROM), basic = rom("basic"), characters = rom(charactersROM) { + vic20.setKernelROM(kernel) + vic20.setBASICROM(basic) + vic20.setCharactersROM(characters) + } + } } // MARK: memory model selector @@ -111,8 +138,15 @@ class Vic20Document: MachineDocument { } if let selectedSize = selectedSize { NSUserDefaults.standardUserDefaults().setInteger(selectedSize, forKey: self.memorySizeUserDefaultsKey) + setMemorySize(sender.indexOfSelectedItem) + } + } + private func setMemorySize(sizeIndex: Int) { + switch sizeIndex { + case 2: vic20.memorySize = .Size32Kb + case 1: vic20.memorySize = .Size8Kb + default: vic20.memorySize = .Size5Kb } - print("Memory size should be \(sender.indexOfSelectedItem)") } // MARK: option restoration @@ -131,10 +165,15 @@ class Vic20Document: MachineDocument { self.loadAutomaticallyButton?.state = loadAutomatically ? NSOnState : NSOffState let memorySize = standardUserDefaults.integerForKey(self.memorySizeUserDefaultsKey) + var indexToSelect: Int? switch memorySize { - case 32: self.memorySizeButton?.selectItemAtIndex(2) - case 8: self.memorySizeButton?.selectItemAtIndex(1) - default: self.memorySizeButton?.selectItemAtIndex(0) + case 32: indexToSelect = 2 + case 8: indexToSelect = 1 + default: indexToSelect = 0 + } + if let indexToSelect = indexToSelect { + self.memorySizeButton?.selectItemAtIndex(indexToSelect) + setMemorySize(indexToSelect) } let country = standardUserDefaults.integerForKey(self.countryUserDefaultsKey) From 48a00d9e0592411e9e17205d64aebd62129db920 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 14 Aug 2016 14:24:03 -0400 Subject: [PATCH 7/9] ... which means that all files are now expected. --- ROMImages/Vic20/readme.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ROMImages/Vic20/readme.txt b/ROMImages/Vic20/readme.txt index ce0e24f6b..551904779 100644 --- a/ROMImages/Vic20/readme.txt +++ b/ROMImages/Vic20/readme.txt @@ -3,15 +3,12 @@ ROM files would ordinarily go here; the copyright status of these is uncertain s Expected files: basic.bin -characters-english.bin -kernel-ntsc.bin - -Likely to be desired in the future: - characters-danish.bin +characters-english.bin characters-japanese.bin characters-swedish.bin kernel-danish.bin kernel-japanese.bin +kernel-ntsc.bin kernel-pal.bin kernel-swedish.bin From 6079d30e58dc47b7ee1f8754bdaaee4f67ea5bf7 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 14 Aug 2016 16:20:24 -0400 Subject: [PATCH 8/9] =?UTF-8?q?Eliminated=20waiting=20here=20=E2=80=94=20e?= =?UTF-8?q?ither=20the=20buffer=20can=20be=20enqueued=20now=20or=20it=20is?= =?UTF-8?q?=20dropped.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OSBindings/Mac/Clock Signal/Audio/CSAudioQueue.m | 4 +--- OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Audio/CSAudioQueue.m b/OSBindings/Mac/Clock Signal/Audio/CSAudioQueue.m index 267ecee96..47507b332 100644 --- a/OSBindings/Mac/Clock Signal/Audio/CSAudioQueue.m +++ b/OSBindings/Mac/Clock Signal/Audio/CSAudioQueue.m @@ -174,9 +174,8 @@ static void audioOutputCallback( - (void)enqueueAudioBuffer:(const int16_t *)buffer numberOfSamples:(size_t)lengthInSamples { - while(1) + if([_writeLock tryLockWhenCondition:AudioQueueCanProceed]) { - [_writeLock lockWhenCondition:AudioQueueCanProceed]; if((_audioStreamReadPosition + _streamLength) - _audioStreamWritePosition >= lengthInSamples) { size_t samplesBeforeOverflow = _streamLength - (_audioStreamWritePosition % _streamLength); @@ -193,7 +192,6 @@ static void audioOutputCallback( _audioStreamWritePosition += lengthInSamples; [_writeLock unlockWithCondition:[self writeLockCondition]]; - break; } else { diff --git a/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift b/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift index ed113cc29..b55a42427 100644 --- a/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift +++ b/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift @@ -157,7 +157,7 @@ class Vic20Document: MachineDocument { standardUserDefaults.registerDefaults([ self.autoloadingUserDefaultsKey: true, self.memorySizeUserDefaultsKey: 5, - self.countryUserDefaultsKey: 4 + self.countryUserDefaultsKey: 1 ]) let loadAutomatically = standardUserDefaults.boolForKey(self.autoloadingUserDefaultsKey) From 547aefb696943467ac3ca90363d3274228ff227d Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 14 Aug 2016 16:36:42 -0400 Subject: [PATCH 9/9] Slightly adjusted PRG strategy, made a note about where next. --- Machines/Commodore/Vic-20/Vic20.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp index 664277c44..555ae488c 100644 --- a/Machines/Commodore/Vic-20/Vic20.cpp +++ b/Machines/Commodore/Vic-20/Vic20.cpp @@ -229,9 +229,25 @@ void Machine::add_prg(size_t length, const uint8_t *data) set_typer_for_string("RUN\n"); } - _rom = new uint8_t[length - 2]; - memcpy(_rom, &data[2], length - 2); - write_to_map(_processorReadMemoryMap, _rom, _rom_address, _rom_length); + if(_rom_address == 0xa000) + { + _rom = new uint8_t[length - 2]; + memcpy(_rom, &data[2], length - 2); + write_to_map(_processorReadMemoryMap, _rom, _rom_address, _rom_length); + } + else + { + // TODO: write to virtual media (tape, probably?), load normally. + data += 2; + while(_rom_length) + { + uint8_t *ram = _processorWriteMemoryMap[_rom_address >> 10]; + if(ram) ram[_rom_address & 0x3ff] = *data; + data++; + _rom_length--; + _rom_address++; + } + } } }