2016-06-05 01:43:50 +00:00
|
|
|
//
|
2016-10-03 11:42:05 +00:00
|
|
|
// Vic20OptionsPanel.swift
|
2016-06-05 01:43:50 +00:00
|
|
|
// Clock Signal
|
|
|
|
//
|
2016-10-03 11:42:05 +00:00
|
|
|
// Created by Thomas Harte on 03/10/2016.
|
2016-06-05 01:43:50 +00:00
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2016-10-03 11:42:05 +00:00
|
|
|
class Vic20OptionsPanel: MachinePanel {
|
|
|
|
var vic20: CSVic20! {
|
2016-06-28 01:38:14 +00:00
|
|
|
get {
|
2016-10-03 11:42:05 +00:00
|
|
|
return self.machine as! CSVic20
|
2016-06-28 01:38:14 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-05 01:43:50 +00:00
|
|
|
|
2016-08-14 17:53:14 +00:00
|
|
|
// MARK: country selector
|
|
|
|
@IBOutlet var countryButton: NSPopUpButton?
|
|
|
|
var countryUserDefaultsKey: String {
|
|
|
|
get { return prefixedUserDefaultsKey("country") }
|
|
|
|
}
|
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
@IBAction func setCountry(_ sender: NSPopUpButton!) {
|
|
|
|
UserDefaults.standard.set(sender.indexOfSelectedItem, forKey: self.countryUserDefaultsKey)
|
2016-08-14 18:00:08 +00:00
|
|
|
setCountry(sender.indexOfSelectedItem)
|
|
|
|
}
|
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
fileprivate func setCountry(_ countryID: Int) {
|
2016-08-14 18:23:08 +00:00
|
|
|
switch countryID {
|
|
|
|
case 0: // Danish
|
2016-10-03 11:42:05 +00:00
|
|
|
vic20.country = .danish
|
2016-08-14 18:23:08 +00:00
|
|
|
case 1: // European
|
2016-10-03 11:42:05 +00:00
|
|
|
vic20.country = .european
|
2016-08-14 18:23:08 +00:00
|
|
|
case 2: // Japanese
|
2016-10-03 11:42:05 +00:00
|
|
|
vic20.country = .japanese
|
2016-08-14 18:23:08 +00:00
|
|
|
case 3: // Swedish
|
2016-10-03 11:42:05 +00:00
|
|
|
vic20.country = .swedish
|
2016-08-14 18:23:08 +00:00
|
|
|
case 4: // US
|
2016-10-03 11:42:05 +00:00
|
|
|
vic20.country = .american
|
2016-08-14 18:23:08 +00:00
|
|
|
default: break
|
|
|
|
}
|
2016-08-14 17:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: memory model selector
|
|
|
|
@IBOutlet var memorySizeButton: NSPopUpButton?
|
|
|
|
var memorySizeUserDefaultsKey: String {
|
|
|
|
get { return prefixedUserDefaultsKey("memorySize") }
|
|
|
|
}
|
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
@IBAction func setMemorySize(_ sender: NSPopUpButton!) {
|
2016-08-14 18:00:08 +00:00
|
|
|
var selectedSize: Int?
|
|
|
|
switch sender.indexOfSelectedItem {
|
|
|
|
case 0: selectedSize = 5
|
|
|
|
case 1: selectedSize = 8
|
|
|
|
case 2: selectedSize = 32
|
|
|
|
default: break
|
|
|
|
}
|
|
|
|
if let selectedSize = selectedSize {
|
2016-09-16 02:12:12 +00:00
|
|
|
UserDefaults.standard.set(selectedSize, forKey: self.memorySizeUserDefaultsKey)
|
2016-08-14 18:23:08 +00:00
|
|
|
setMemorySize(sender.indexOfSelectedItem)
|
|
|
|
}
|
|
|
|
}
|
2016-09-16 02:12:12 +00:00
|
|
|
fileprivate func setMemorySize(_ sizeIndex: Int) {
|
2016-08-14 18:23:08 +00:00
|
|
|
switch sizeIndex {
|
2016-09-16 02:12:12 +00:00
|
|
|
case 2: vic20.memorySize = .size32Kb
|
|
|
|
case 1: vic20.memorySize = .size8Kb
|
|
|
|
default: vic20.memorySize = .size5Kb
|
2016-08-14 18:00:08 +00:00
|
|
|
}
|
2016-08-14 17:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: option restoration
|
2016-08-06 21:39:27 +00:00
|
|
|
override func establishStoredOptions() {
|
|
|
|
super.establishStoredOptions()
|
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
let standardUserDefaults = UserDefaults.standard
|
|
|
|
standardUserDefaults.register(defaults: [
|
2016-08-14 18:00:08 +00:00
|
|
|
self.memorySizeUserDefaultsKey: 5,
|
2016-08-14 20:20:24 +00:00
|
|
|
self.countryUserDefaultsKey: 1
|
2016-08-06 21:39:27 +00:00
|
|
|
])
|
|
|
|
|
2017-05-14 20:59:24 +00:00
|
|
|
// let memorySize = standardUserDefaults.integer(forKey: self.memorySizeUserDefaultsKey)
|
|
|
|
// var indexToSelect: Int?
|
|
|
|
// switch memorySize {
|
|
|
|
// case 32: indexToSelect = 2
|
|
|
|
// case 8: indexToSelect = 1
|
|
|
|
// default: indexToSelect = 0
|
|
|
|
// }
|
|
|
|
// if let indexToSelect = indexToSelect {
|
|
|
|
// self.memorySizeButton?.selectItem(at: indexToSelect)
|
|
|
|
// setMemorySize(indexToSelect)
|
|
|
|
// }
|
2016-08-14 18:00:08 +00:00
|
|
|
|
2016-09-08 11:38:34 +00:00
|
|
|
// TODO: this should be part of the configuration
|
2016-09-16 02:12:12 +00:00
|
|
|
let country = standardUserDefaults.integer(forKey: self.countryUserDefaultsKey)
|
2016-08-14 18:00:08 +00:00
|
|
|
setCountry(country)
|
2016-09-16 02:12:12 +00:00
|
|
|
self.countryButton?.selectItem(at: country)
|
2016-10-03 11:42:05 +00:00
|
|
|
}
|
2016-06-05 01:43:50 +00:00
|
|
|
}
|