diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index a1f349381..d5c0e2b9e 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -46,7 +46,6 @@ 4B69FB441C4D941400B5F0AA /* TapeUEF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B69FB421C4D941400B5F0AA /* TapeUEF.cpp */; }; 4B69FB461C4D950F00B5F0AA /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B69FB451C4D950F00B5F0AA /* libz.tbd */; }; 4B6C73BD1D387AE500AFCFCA /* DiskController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B6C73BB1D387AE500AFCFCA /* DiskController.cpp */; }; - 4B73C71A1D036BD90074D992 /* Vic20Document.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B73C7191D036BD90074D992 /* Vic20Document.swift */; }; 4B8FE21B1DA19D5F0090D3CE /* Atari2600Options.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B8FE2131DA19D5F0090D3CE /* Atari2600Options.xib */; }; 4B8FE21C1DA19D5F0090D3CE /* MachineDocument.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B8FE2151DA19D5F0090D3CE /* MachineDocument.xib */; }; 4B8FE21D1DA19D5F0090D3CE /* ElectronOptions.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B8FE2171DA19D5F0090D3CE /* ElectronOptions.xib */; }; @@ -57,6 +56,7 @@ 4B8FE2291DA1EDDF0090D3CE /* ElectronOptionsPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8FE2281DA1EDDF0090D3CE /* ElectronOptionsPanel.swift */; }; 4B92EACA1B7C112B00246143 /* 6502TimingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B92EAC91B7C112B00246143 /* 6502TimingTests.swift */; }; 4B96F7221D75119A0058BB2D /* Tape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B96F7201D75119A0058BB2D /* Tape.cpp */; }; + 4B9CCDA11DA279CA0098B625 /* Vic20OptionsPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B9CCDA01DA279CA0098B625 /* Vic20OptionsPanel.swift */; }; 4BA22B071D8817CE0008C640 /* Disk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BA22B051D8817CE0008C640 /* Disk.cpp */; }; 4BA61EB01D91515900B3C876 /* NSData+StdVector.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BA61EAF1D91515900B3C876 /* NSData+StdVector.mm */; }; 4BA799951D8B656E0045123D /* StaticAnalyser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BA799931D8B656E0045123D /* StaticAnalyser.cpp */; }; @@ -468,7 +468,6 @@ 4B69FB451C4D950F00B5F0AA /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; 4B6C73BB1D387AE500AFCFCA /* DiskController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DiskController.cpp; sourceTree = ""; }; 4B6C73BC1D387AE500AFCFCA /* DiskController.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = DiskController.hpp; sourceTree = ""; }; - 4B73C7191D036BD90074D992 /* Vic20Document.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Vic20Document.swift; sourceTree = ""; }; 4B8FE2141DA19D5F0090D3CE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Clock Signal/Base.lproj/Atari2600Options.xib"; sourceTree = SOURCE_ROOT; }; 4B8FE2161DA19D5F0090D3CE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Clock Signal/Base.lproj/MachineDocument.xib"; sourceTree = SOURCE_ROOT; }; 4B8FE2181DA19D5F0090D3CE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Clock Signal/Base.lproj/ElectronOptions.xib"; sourceTree = SOURCE_ROOT; }; @@ -481,6 +480,7 @@ 4B92EAC91B7C112B00246143 /* 6502TimingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 6502TimingTests.swift; sourceTree = ""; }; 4B96F7201D75119A0058BB2D /* Tape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Tape.cpp; path = ../../StaticAnalyser/Acorn/Tape.cpp; sourceTree = ""; }; 4B96F7211D75119A0058BB2D /* Tape.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Tape.hpp; path = ../../StaticAnalyser/Acorn/Tape.hpp; sourceTree = ""; }; + 4B9CCDA01DA279CA0098B625 /* Vic20OptionsPanel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Vic20OptionsPanel.swift; sourceTree = ""; }; 4BA22B051D8817CE0008C640 /* Disk.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Disk.cpp; path = ../../StaticAnalyser/Commodore/Disk.cpp; sourceTree = ""; }; 4BA22B061D8817CE0008C640 /* Disk.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Disk.hpp; path = ../../StaticAnalyser/Commodore/Disk.hpp; sourceTree = ""; }; 4BA61EAE1D91515900B3C876 /* NSData+StdVector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+StdVector.h"; sourceTree = ""; }; @@ -1053,7 +1053,7 @@ 4B8FE2281DA1EDDF0090D3CE /* ElectronOptionsPanel.swift */, 4B55CE5E1C3B7D960093A61B /* MachineDocument.swift */, 4B8FE2211DA19FB20090D3CE /* MachinePanel.swift */, - 4B73C7191D036BD90074D992 /* Vic20Document.swift */, + 4B9CCDA01DA279CA0098B625 /* Vic20OptionsPanel.swift */, 4B8FE2131DA19D5F0090D3CE /* Atari2600Options.xib */, 4B8FE2171DA19D5F0090D3CE /* ElectronOptions.xib */, 4B8FE2151DA19D5F0090D3CE /* MachineDocument.xib */, @@ -2157,7 +2157,6 @@ 4B96F7221D75119A0058BB2D /* Tape.cpp in Sources */, 4B0BE4281D3481E700D5256B /* DigitalPhaseLockedLoop.cpp in Sources */, 4BD69F941D98760000243FE1 /* AcornADF.cpp in Sources */, - 4B73C71A1D036BD90074D992 /* Vic20Document.swift in Sources */, 4BBF99181C8FBA6F0075DAFB /* TextureTarget.cpp in Sources */, 4BC76E691C98E31700E6EF73 /* FIRFilter.cpp in Sources */, 4B55CE5F1C3B7D960093A61B /* MachineDocument.swift in Sources */, @@ -2191,6 +2190,7 @@ 4B2A53A21D117D36003C6002 /* CSElectron.mm in Sources */, 4B8FE2201DA19D7C0090D3CE /* Atari2600OptionsPanel.swift in Sources */, 4B2E2D9A1C3A06EC00138695 /* Atari2600.cpp in Sources */, + 4B9CCDA11DA279CA0098B625 /* Vic20OptionsPanel.swift in Sources */, 4B3051301D98ACC600B4FED8 /* Plus3.cpp in Sources */, 4B30512D1D989E2200B4FED8 /* Drive.cpp in Sources */, 4BCA6CC81D9DD9F000C2D7B2 /* CommodoreROM.cpp in Sources */, diff --git a/OSBindings/Mac/Clock Signal/Base.lproj/Vic20Options.xib b/OSBindings/Mac/Clock Signal/Base.lproj/Vic20Options.xib index db06efdb5..4c477e080 100644 --- a/OSBindings/Mac/Clock Signal/Base.lproj/Vic20Options.xib +++ b/OSBindings/Mac/Clock Signal/Base.lproj/Vic20Options.xib @@ -4,18 +4,14 @@ - + - - - - - + @@ -31,7 +27,7 @@ - + @@ -58,7 +54,7 @@ - + @@ -77,7 +73,7 @@ - + @@ -97,6 +93,12 @@ + + + + + + diff --git a/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift b/OSBindings/Mac/Clock Signal/Documents/Vic20OptionsPanel.swift similarity index 65% rename from OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift rename to OSBindings/Mac/Clock Signal/Documents/Vic20OptionsPanel.swift index 21d96228f..f491b6e1c 100644 --- a/OSBindings/Mac/Clock Signal/Documents/Vic20Document.swift +++ b/OSBindings/Mac/Clock Signal/Documents/Vic20OptionsPanel.swift @@ -1,50 +1,17 @@ // -// Vic20Document.swift +// Vic20OptionsPanel.swift // Clock Signal // -// Created by Thomas Harte on 04/06/2016. +// Created by Thomas Harte on 03/10/2016. // Copyright © 2016 Thomas Harte. All rights reserved. // -import Foundation - -class Vic20Document: MachineDocument { - -/* fileprivate lazy var vic20 = CSVic20() - override var machine: CSMachine! { +class Vic20OptionsPanel: MachinePanel { + var vic20: CSVic20! { get { - return vic20 + return self.machine as! CSVic20 } } - override var name: String! { - get { - return "vic20" - } - } - - // MARK: NSDocument overrides - override init() { - super.init() - - if let drive = dataForResource("1540", ofType: "bin", inDirectory: "ROMImages/Commodore1540") { - vic20.setDriveROM(drive) - } - - establishStoredOptions() - } - - override class func autosavesInPlace() -> Bool { - return true - } - - override var windowNibName: String? { - return "Vic20Document" - } - - // MARK: machine setup - fileprivate func rom(_ name: String) -> Data? { - return dataForResource(name, ofType: "bin", inDirectory: "ROMImages/Vic20") - } // MARK: automatic loading tick box @IBOutlet var loadAutomaticallyButton: NSButton? @@ -70,39 +37,19 @@ class Vic20Document: MachineDocument { } fileprivate func setCountry(_ countryID: Int) { - var charactersROM: String? - var kernelROM: String? switch countryID { case 0: // Danish - charactersROM = "characters-danish" - kernelROM = "kernel-danish" - vic20.region = .PAL + vic20.country = .danish case 1: // European - charactersROM = "characters-english" - kernelROM = "kernel-pal" - vic20.region = .PAL + vic20.country = .european case 2: // Japanese - charactersROM = "characters-japanese" - kernelROM = "kernel-japanese" - vic20.region = .NTSC + vic20.country = .japanese case 3: // Swedish - charactersROM = "characters-swedish" - kernelROM = "kernel-swedish" - vic20.region = .PAL + vic20.country = .swedish case 4: // US - charactersROM = "characters-english" - kernelROM = "kernel-ntsc" - vic20.region = .NTSC + vic20.country = .american default: break } - - if let charactersROM = charactersROM, let kernelROM = kernelROM { - if let kernel = rom(kernelROM), let basic = rom("basic"), let characters = rom(charactersROM) { - vic20.setKernelROM(kernel) - vic20.setBASICROM(basic) - vic20.setCharactersROM(characters) - } - } } // MARK: memory model selector @@ -165,5 +112,5 @@ class Vic20Document: MachineDocument { let country = standardUserDefaults.integer(forKey: self.countryUserDefaultsKey) setCountry(country) self.countryButton?.selectItem(at: country) - }*/ + } } diff --git a/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm b/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm index f3b69b8e5..1cf33e3ee 100644 --- a/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm +++ b/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm @@ -39,7 +39,7 @@ switch(_target.machine) { case StaticAnalyser::Target::Electron: return @"ElectronOptions"; - case StaticAnalyser::Target::Vic20: return nil; + case StaticAnalyser::Target::Vic20: return @"Vic20Options"; case StaticAnalyser::Target::Atari2600: return @"Atari2600Options"; } diff --git a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.h b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.h index 42d0aaee0..5ec512dc9 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.h +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.h @@ -10,10 +10,13 @@ #import "CSKeyboardMachine.h" #import "CSFastLoading.h" -typedef NS_ENUM(NSInteger, CSVic20Region) +typedef NS_ENUM(NSInteger, CSVic20Country) { - CSVic20RegionPAL, - CSVic20RegionNTSC + CSVic20CountryDanish, + CSVic20CountryEuropean, + CSVic20CountryJapanese, + CSVic20CountrySwedish, + CSVic20CountryAmerican }; typedef NS_ENUM(NSInteger, CSVic20MemorySize) @@ -25,14 +28,9 @@ typedef NS_ENUM(NSInteger, CSVic20MemorySize) @interface CSVic20 : CSMachine -- (void)setKernelROM:(nonnull NSData *)rom; -- (void)setBASICROM:(nonnull NSData *)rom; -- (void)setCharactersROM:(nonnull NSData *)rom; -- (void)setDriveROM:(nonnull NSData *)rom; - @property (nonatomic, assign) BOOL useFastLoadingHack; @property (nonatomic, assign) BOOL shouldLoadAutomatically; -@property (nonatomic, assign) CSVic20Region region; +@property (nonatomic, assign) CSVic20Country country; @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 04f7c6a65..bcc3866c5 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm @@ -13,6 +13,8 @@ #include "G64.hpp" #include "D64.hpp" +#import "NSBundle+DataResource.h" + using namespace Commodore::Vic20; @implementation CSVic20 { @@ -20,10 +22,27 @@ using namespace Commodore::Vic20; BOOL _joystickMode; } -- (CRTMachine::Machine * const)machine { - return &_vic20; +- (CRTMachine::Machine * const)machine { return &_vic20; } +- (NSString *)userDefaultsPrefix { return @"vic20"; } + +- (instancetype)init { + self = [super init]; + if(self) + { + [self setDriveROM:[[NSBundle mainBundle] dataForResource:@"1540" withExtension:@"bin" subdirectory:@"ROMImages/Commodore1540"]]; + [self setBASICROM:[self rom:@"basic"]]; + [self setCountry:CSVic20CountryEuropean]; + } + return self; } +- (NSData *)rom:(NSString *)name +{ + return [[NSBundle mainBundle] dataForResource:name withExtension:@"bin" subdirectory:@"ROMImages/Vic20"]; +} + +#pragma mark - ROM setting + - (void)setROM:(nonnull NSData *)rom slot:(ROMSlot)slot { @synchronized(self) { _vic20.set_rom(slot, rom.length, (const uint8_t *)rom.bytes); @@ -46,6 +65,8 @@ using namespace Commodore::Vic20; [self setROM:rom slot:Drive]; } +#pragma mark - Keyboard map + - (void)setKey:(uint16_t)key isPressed:(BOOL)isPressed { static NSDictionary *vicKeysByKeys = @{ @(VK_ANSI_1): @(Key::Key1), @(VK_ANSI_2): @(Key::Key2), @@ -164,10 +185,43 @@ using namespace Commodore::Vic20; } } -- (void)setRegion:(CSVic20Region)region { - _region = region; +- (void)setCountry:(CSVic20Country)country { + _country = country; + NSString *charactersROM, *kernelROM; + Commodore::Vic20::Region region; + switch(country) + { + case CSVic20CountryDanish: + region = Commodore::Vic20::Region::PAL; + charactersROM = @"characters-danish"; + kernelROM = @"kernel-danish"; + break; + case CSVic20CountryEuropean: + region = Commodore::Vic20::Region::PAL; + charactersROM = @"characters-english"; + kernelROM = @"kernel-pal"; + break; + case CSVic20CountryJapanese: + region = Commodore::Vic20::Region::NTSC; + charactersROM = @"characters-japanese"; + kernelROM = @"kernel-japanese"; + break; + case CSVic20CountrySwedish: + region = Commodore::Vic20::Region::PAL; + charactersROM = @"characters-swedish"; + kernelROM = @"kernel-swedish"; + break; + case CSVic20CountryAmerican: + region = Commodore::Vic20::Region::NTSC; + charactersROM = @"characters-english"; + kernelROM = @"kernel-ntsc"; + break; + } + @synchronized(self) { - _vic20.set_region( (region == CSVic20RegionPAL) ? Commodore::Vic20::Region::PAL : Commodore::Vic20::Region::NTSC); + _vic20.set_region(region); + [self setCharactersROM:[self rom:charactersROM]]; + [self setKernelROM:[self rom:kernelROM]]; } } @@ -182,6 +236,4 @@ using namespace Commodore::Vic20; } } -- (NSString *)userDefaultsPrefix { return @"vic20"; } - @end