diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index f47d5b53d..bf7ba3f6c 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -54,8 +54,8 @@ 4B8FE21E1DA19D5F0090D3CE /* Vic20Options.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B8FE2191DA19D5F0090D3CE /* Vic20Options.xib */; }; 4B8FE2201DA19D7C0090D3CE /* Atari2600OptionsPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8FE21F1DA19D7C0090D3CE /* Atari2600OptionsPanel.swift */; }; 4B8FE2221DA19FB20090D3CE /* MachinePanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8FE2211DA19FB20090D3CE /* MachinePanel.swift */; }; - 4B8FE2241DA1DC2D0090D3CE /* Bundle+DataForResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8FE2231DA1DC2D0090D3CE /* Bundle+DataForResource.swift */; }; 4B8FE2271DA1DE2D0090D3CE /* NSBundle+DataResource.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B8FE2261DA1DE2D0090D3CE /* NSBundle+DataResource.m */; }; + 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 */; }; 4BA22B071D8817CE0008C640 /* Disk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BA22B051D8817CE0008C640 /* Disk.cpp */; }; @@ -477,9 +477,9 @@ 4B8FE21A1DA19D5F0090D3CE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Clock Signal/Base.lproj/Vic20Options.xib"; sourceTree = SOURCE_ROOT; }; 4B8FE21F1DA19D7C0090D3CE /* Atari2600OptionsPanel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Atari2600OptionsPanel.swift; sourceTree = ""; }; 4B8FE2211DA19FB20090D3CE /* MachinePanel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MachinePanel.swift; sourceTree = ""; }; - 4B8FE2231DA1DC2D0090D3CE /* Bundle+DataForResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Bundle+DataForResource.swift"; sourceTree = ""; }; 4B8FE2251DA1DE2D0090D3CE /* NSBundle+DataResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSBundle+DataResource.h"; sourceTree = ""; }; 4B8FE2261DA1DE2D0090D3CE /* NSBundle+DataResource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSBundle+DataResource.m"; sourceTree = ""; }; + 4B8FE2281DA1EDDF0090D3CE /* ElectronOptionsPanel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ElectronOptionsPanel.swift; sourceTree = ""; }; 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 = ""; }; @@ -1053,6 +1053,7 @@ 4B55CE561C3B7D360093A61B /* Atari2600Document.swift */, 4B8FE21F1DA19D7C0090D3CE /* Atari2600OptionsPanel.swift */, 4B55CE571C3B7D360093A61B /* ElectronDocument.swift */, + 4B8FE2281DA1EDDF0090D3CE /* ElectronOptionsPanel.swift */, 4B55CE5E1C3B7D960093A61B /* MachineDocument.swift */, 4B8FE2211DA19FB20090D3CE /* MachinePanel.swift */, 4B73C7191D036BD90074D992 /* Vic20Document.swift */, @@ -1060,7 +1061,6 @@ 4B8FE2171DA19D5F0090D3CE /* ElectronOptions.xib */, 4B8FE2151DA19D5F0090D3CE /* MachineDocument.xib */, 4B8FE2191DA19D5F0090D3CE /* Vic20Options.xib */, - 4B8FE2231DA1DC2D0090D3CE /* Bundle+DataForResource.swift */, ); path = Documents; sourceTree = ""; @@ -2152,7 +2152,6 @@ 4BA799951D8B656E0045123D /* StaticAnalyser.cpp in Sources */, 4BF829601D8F3C87001BAE39 /* CRC.cpp in Sources */, 4B55CE591C3B7D360093A61B /* ElectronDocument.swift in Sources */, - 4B8FE2241DA1DC2D0090D3CE /* Bundle+DataForResource.swift in Sources */, 4B4DC82B1D2C27A4003C5BF8 /* SerialBus.cpp in Sources */, 4BC3B74F1CD194CC00F86E85 /* Shader.cpp in Sources */, 4B8FE2221DA19FB20090D3CE /* MachinePanel.swift in Sources */, @@ -2188,6 +2187,7 @@ 4B2E2D9D1C3A070400138695 /* Electron.cpp in Sources */, 4BAB62B81D3302CA00DF5BA0 /* PCMTrack.cpp in Sources */, 4B69FB3D1C4D908A00B5F0AA /* Tape.cpp in Sources */, + 4B8FE2291DA1EDDF0090D3CE /* ElectronOptionsPanel.swift in Sources */, 4B55CE5D1C3B7D6F0093A61B /* CSOpenGLView.m in Sources */, 4BB697CB1D4B6D3E00248BDF /* TimedEventLoop.cpp in Sources */, 4BF1354C1D6D2C300054B2EA /* StaticAnalyser.cpp in Sources */, diff --git a/OSBindings/Mac/Clock Signal/Base.lproj/ElectronOptions.xib b/OSBindings/Mac/Clock Signal/Base.lproj/ElectronOptions.xib index 325d629c3..39521bbd1 100644 --- a/OSBindings/Mac/Clock Signal/Base.lproj/ElectronOptions.xib +++ b/OSBindings/Mac/Clock Signal/Base.lproj/ElectronOptions.xib @@ -4,16 +4,14 @@ - + - - - + @@ -31,7 +29,7 @@ - + @@ -47,7 +45,7 @@ - + @@ -60,6 +58,10 @@ + + + + diff --git a/OSBindings/Mac/Clock Signal/Documents/Atari2600OptionsPanel.swift b/OSBindings/Mac/Clock Signal/Documents/Atari2600OptionsPanel.swift index 2ceabf863..7f343a200 100644 --- a/OSBindings/Mac/Clock Signal/Documents/Atari2600OptionsPanel.swift +++ b/OSBindings/Mac/Clock Signal/Documents/Atari2600OptionsPanel.swift @@ -6,17 +6,12 @@ // Copyright © 2016 Thomas Harte. All rights reserved. // -import Cocoa - class Atari2600OptionsPanel: MachinePanel { - override var machine: CSMachine! { - didSet { - if let atari2600 = machine as? CSAtari2600 { - self.atari2600 = atari2600 - } + var atari2600: CSAtari2600! { + get { + return self.machine as! CSAtari2600 } } - var atari2600: CSAtari2600! @IBOutlet var resetButton: NSButton! @IBOutlet var selectButton: NSButton! diff --git a/OSBindings/Mac/Clock Signal/Documents/Bundle+DataForResource.swift b/OSBindings/Mac/Clock Signal/Documents/Bundle+DataForResource.swift deleted file mode 100644 index 8dcb5ac96..000000000 --- a/OSBindings/Mac/Clock Signal/Documents/Bundle+DataForResource.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// Bundle+DataForResource.swift -// Clock Signal -// -// Created by Thomas Harte on 02/10/2016. -// Copyright © 2016 Thomas Harte. All rights reserved. -// - -import Foundation - -extension Bundle { - func dataForResource(_ name : String, ofType type: String, inDirectory directory: String) -> Data? { - if let path = self.path(forResource: name, ofType: type, inDirectory: directory) { - return try? Data(contentsOf: URL(fileURLWithPath: path)) - } - return nil - } - -} diff --git a/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift b/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift index a3f04455e..a2fc79874 100644 --- a/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift @@ -15,35 +15,6 @@ class ElectronDocument: MachineDocument { return NSSize(width: 11.0, height: 10.0) } - fileprivate func rom(_ name: String) -> Data? { - return dataForResource(name, ofType: "rom", inDirectory: "ROMImages/Electron") - } - - override init() { - super.init(); - - if let os = rom("os"), let basic = rom("basic") { - self.electron.setOSROM(os) - self.electron.setBASICROM(basic) - } - if let dfs = rom("DFS-1770-2.20") { - self.electron.setDFSROM(dfs) - } - if let adfs1 = rom("ADFS-E00_1"), let adfs2 = rom("ADFS-E00_2") { - var fullADFS = adfs1 - fullADFS.append(adfs2) - self.electron.setADFSROM(fullADFS as Data) - } - } - - - // MARK: IBActions - @IBOutlet var displayTypeButton: NSPopUpButton? - @IBAction func setDisplayType(_ sender: NSPopUpButton!) { - electron.useTelevisionOutput = (sender.indexOfSelectedItem == 1) - UserDefaults.standard.set(sender.indexOfSelectedItem, forKey: self.displayTypeUserDefaultsKey) - } - fileprivate let displayTypeUserDefaultsKey = "electron.displayType" override func establishStoredOptions() { super.establishStoredOptions() diff --git a/OSBindings/Mac/Clock Signal/Documents/ElectronOptionsPanel.swift b/OSBindings/Mac/Clock Signal/Documents/ElectronOptionsPanel.swift new file mode 100644 index 000000000..d0b81f395 --- /dev/null +++ b/OSBindings/Mac/Clock Signal/Documents/ElectronOptionsPanel.swift @@ -0,0 +1,21 @@ +// +// ElectronOptionsPanel.swift +// Clock Signal +// +// Created by Thomas Harte on 02/10/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +class ElectronOptionsPanel: MachinePanel { + var electron: CSElectron! { + get { + return self.machine as! CSElectron + } + } + + @IBOutlet var displayTypeButton: NSPopUpButton? + @IBAction func setDisplayType(_ sender: NSPopUpButton!) { + electron.useTelevisionOutput = (sender.indexOfSelectedItem == 1) +// UserDefaults.standard.set(sender.indexOfSelectedItem, forKey: self.displayTypeUserDefaultsKey) + } +} diff --git a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift index 7bf604a0b..8dff55f92 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift @@ -66,7 +66,6 @@ class MachineDocument: setupClockRate() self.machine.delegate = self - establishStoredOptions() } func machineDidChangeClockRate(_ machine: CSMachine!) { @@ -190,36 +189,4 @@ class MachineDocument: $0.setKey(VK_Option, isPressed: newModifiers.modifierFlags.contains(.option)) } } - - // MARK: IBActions - final func prefixedUserDefaultsKey(_ key: String) -> String { - return "\(self.name).\(key)" - } - var fastLoadingUserDefaultsKey: String { - get { - return prefixedUserDefaultsKey("fastLoading") - } - } - - @IBOutlet var fastLoadingButton: NSButton? - @IBAction func setFastLoading(_ sender: NSButton!) { - if let fastLoadingMachine = machine as? CSFastLoading { - let useFastLoadingHack = sender.state == NSOnState - fastLoadingMachine.useFastLoadingHack = useFastLoadingHack - UserDefaults.standard.set(useFastLoadingHack, forKey: fastLoadingUserDefaultsKey) - } - } - - func establishStoredOptions() { - let standardUserDefaults = UserDefaults.standard - standardUserDefaults.register(defaults: [ - fastLoadingUserDefaultsKey: true - ]) - - if let fastLoadingMachine = machine as? CSFastLoading { - let useFastLoadingHack = standardUserDefaults.bool(forKey: self.fastLoadingUserDefaultsKey) - fastLoadingMachine.useFastLoadingHack = useFastLoadingHack - self.fastLoadingButton?.state = useFastLoadingHack ? NSOnState : NSOffState - } - } } diff --git a/OSBindings/Mac/Clock Signal/Documents/MachinePanel.swift b/OSBindings/Mac/Clock Signal/Documents/MachinePanel.swift index 2722e9081..ff3dbc826 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachinePanel.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachinePanel.swift @@ -10,4 +10,36 @@ import Cocoa class MachinePanel: NSPanel { var machine: CSMachine! + + // MARK: IBActions + final func prefixedUserDefaultsKey(_ key: String) -> String { + return "\(self.machine.userDefaultsPrefix).\(key)" + } + var fastLoadingUserDefaultsKey: String { + get { + return prefixedUserDefaultsKey("fastLoading") + } + } + + @IBOutlet var fastLoadingButton: NSButton? + @IBAction func setFastLoading(_ sender: NSButton!) { + if let fastLoadingMachine = machine as? CSFastLoading { + let useFastLoadingHack = sender.state == NSOnState + fastLoadingMachine.useFastLoadingHack = useFastLoadingHack + UserDefaults.standard.set(useFastLoadingHack, forKey: fastLoadingUserDefaultsKey) + } + } + + func establishStoredOptions() { + let standardUserDefaults = UserDefaults.standard + standardUserDefaults.register(defaults: [ + fastLoadingUserDefaultsKey: true + ]) + + if let fastLoadingMachine = machine as? CSFastLoading { + let useFastLoadingHack = standardUserDefaults.bool(forKey: self.fastLoadingUserDefaultsKey) + fastLoadingMachine.useFastLoadingHack = useFastLoadingHack + self.fastLoadingButton?.state = useFastLoadingHack ? NSOnState : NSOffState + } + } } diff --git a/OSBindings/Mac/Clock Signal/Machine/CSMachine.h b/OSBindings/Mac/Clock Signal/Machine/CSMachine.h index 843644503..8b601279c 100644 --- a/OSBindings/Mac/Clock Signal/Machine/CSMachine.h +++ b/OSBindings/Mac/Clock Signal/Machine/CSMachine.h @@ -33,6 +33,8 @@ @property (nonatomic, readonly) double clockRate; @property (nonatomic, readonly) BOOL clockIsUnlimited; +@property (nonatomic, readonly) NSString *userDefaultsPrefix; + - (void)paste:(NSString *)string; @end diff --git a/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.h b/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.h index 7469da920..90bf509a6 100644 --- a/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.h +++ b/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.h @@ -15,7 +15,6 @@ - (instancetype)initWithFileAtURL:(NSURL *)url; @property(nonatomic, readonly) NSString *optionsPanelNibName; -@property(nonatomic, readonly) NSString *userDefaultsPrefix; - (CSMachine *)newMachine; @property(nonatomic, readonly) NSString *displayName; diff --git a/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm b/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm index db5607320..f3b69b8e5 100644 --- a/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm +++ b/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm @@ -38,7 +38,7 @@ { switch(_target.machine) { - case StaticAnalyser::Target::Electron: return nil; + case StaticAnalyser::Target::Electron: return @"ElectronOptions"; case StaticAnalyser::Target::Vic20: return nil; case StaticAnalyser::Target::Atari2600: return @"Atari2600Options"; } @@ -56,18 +56,6 @@ } } -- (NSString *)userDefaultsPrefix -{ - switch(_target.machine) - { - case StaticAnalyser::Target::Electron: return @"electron"; - case StaticAnalyser::Target::Vic20: return @"vic20"; - case StaticAnalyser::Target::Atari2600: return @"atari2600"; - } - - return nil; -} - - (void)applyToMachine:(CSMachine *)machine { [machine applyTarget:_target]; diff --git a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSAtari2600.mm b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSAtari2600.mm index 44a16dee9..13865638a 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSAtari2600.mm +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSAtari2600.mm @@ -115,4 +115,6 @@ struct CRTDelegate: public Outputs::CRT::Delegate { [self toggleSwitch:Atari2600SwitchSelect]; } +- (NSString *)userDefaultsPrefix { return @"atari2600"; } + @end diff --git a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSElectron.mm b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSElectron.mm index 6717b826e..0cca591bd 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSElectron.mm +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSElectron.mm @@ -148,6 +148,8 @@ } } +- (NSString *)userDefaultsPrefix { return @"electron"; } + #pragma mark - Options - (void)setUseFastLoadingHack:(BOOL)useFastLoadingHack { diff --git a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm index 41aed0e6b..04f7c6a65 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm @@ -182,4 +182,6 @@ using namespace Commodore::Vic20; } } +- (NSString *)userDefaultsPrefix { return @"vic20"; } + @end