2016-10-02 20:31:50 +00:00
|
|
|
//
|
2021-07-13 23:04:24 +00:00
|
|
|
// MachineController.swift
|
2016-10-02 20:31:50 +00:00
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 02/10/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-10-02 20:31:50 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
2021-07-13 23:04:24 +00:00
|
|
|
class MachineController: NSObject {
|
2016-10-02 20:31:50 +00:00
|
|
|
var machine: CSMachine!
|
2016-10-03 01:56:50 +00:00
|
|
|
|
|
|
|
// MARK: IBActions
|
|
|
|
final func prefixedUserDefaultsKey(_ key: String) -> String {
|
|
|
|
return "\(self.machine.userDefaultsPrefix).\(key)"
|
|
|
|
}
|
2018-01-15 23:36:22 +00:00
|
|
|
|
2019-09-20 02:32:12 +00:00
|
|
|
// MARK: Fast Loading
|
2016-10-03 01:56:50 +00:00
|
|
|
var fastLoadingUserDefaultsKey: String {
|
2018-01-15 23:36:22 +00:00
|
|
|
return prefixedUserDefaultsKey("fastLoading")
|
2016-10-03 01:56:50 +00:00
|
|
|
}
|
|
|
|
@IBOutlet var fastLoadingButton: NSButton?
|
|
|
|
@IBAction func setFastLoading(_ sender: NSButton!) {
|
2019-09-25 00:13:09 +00:00
|
|
|
let useFastLoadingHack = sender.state == .on
|
|
|
|
machine.useFastLoadingHack = useFastLoadingHack
|
|
|
|
UserDefaults.standard.set(useFastLoadingHack, forKey: fastLoadingUserDefaultsKey)
|
2016-10-03 01:56:50 +00:00
|
|
|
}
|
|
|
|
|
2019-09-20 02:32:12 +00:00
|
|
|
// MARK: Quick Boot
|
|
|
|
var bootQuicklyUserDefaultsKey: String {
|
|
|
|
return prefixedUserDefaultsKey("bootQuickly")
|
|
|
|
}
|
|
|
|
@IBOutlet var fastBootingButton: NSButton?
|
|
|
|
@IBAction func setFastBooting(_ sender: NSButton!) {
|
2019-09-20 02:37:23 +00:00
|
|
|
let useQuickBootingHack = sender.state == .on
|
|
|
|
machine.useQuickBootingHack = useQuickBootingHack
|
|
|
|
UserDefaults.standard.set(useQuickBootingHack, forKey: bootQuicklyUserDefaultsKey)
|
2019-09-20 02:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Display-Type Selection
|
2018-04-01 17:29:04 +00:00
|
|
|
fileprivate func signalForTag(tag: Int) -> CSMachineVideoSignal {
|
|
|
|
switch tag {
|
|
|
|
case 1: return .composite
|
|
|
|
case 2: return .sVideo
|
2019-02-13 00:52:32 +00:00
|
|
|
case 3: return .monochromeComposite
|
2018-04-01 17:29:04 +00:00
|
|
|
default: break
|
|
|
|
}
|
|
|
|
return .RGB
|
|
|
|
}
|
|
|
|
|
2018-01-15 23:36:22 +00:00
|
|
|
var displayTypeUserDefaultsKey: String {
|
|
|
|
return prefixedUserDefaultsKey("displayType")
|
|
|
|
}
|
|
|
|
@IBOutlet var displayTypeButton: NSPopUpButton?
|
|
|
|
@IBAction func setDisplayType(_ sender: NSPopUpButton!) {
|
2018-04-01 17:29:04 +00:00
|
|
|
if let selectedItem = sender.selectedItem {
|
|
|
|
machine.videoSignal = signalForTag(tag: selectedItem.tag)
|
|
|
|
UserDefaults.standard.set(selectedItem.tag, forKey: self.displayTypeUserDefaultsKey)
|
|
|
|
}
|
2018-01-15 23:36:22 +00:00
|
|
|
}
|
|
|
|
|
2019-09-20 02:32:12 +00:00
|
|
|
// MARK: Restoring user defaults
|
2016-10-03 01:56:50 +00:00
|
|
|
func establishStoredOptions() {
|
|
|
|
let standardUserDefaults = UserDefaults.standard
|
|
|
|
standardUserDefaults.register(defaults: [
|
2018-01-15 23:36:22 +00:00
|
|
|
fastLoadingUserDefaultsKey: true,
|
2019-09-20 02:37:23 +00:00
|
|
|
bootQuicklyUserDefaultsKey: true,
|
2018-01-15 23:36:22 +00:00
|
|
|
displayTypeUserDefaultsKey: 0
|
2016-10-03 01:56:50 +00:00
|
|
|
])
|
|
|
|
|
2019-09-25 00:13:09 +00:00
|
|
|
if let fastLoadingButton = self.fastLoadingButton {
|
2016-10-03 01:56:50 +00:00
|
|
|
let useFastLoadingHack = standardUserDefaults.bool(forKey: self.fastLoadingUserDefaultsKey)
|
2019-09-25 00:13:09 +00:00
|
|
|
machine.useFastLoadingHack = useFastLoadingHack
|
|
|
|
fastLoadingButton.state = useFastLoadingHack ? .on : .off
|
2016-10-03 01:56:50 +00:00
|
|
|
}
|
2018-01-15 23:36:22 +00:00
|
|
|
|
2019-09-20 02:37:23 +00:00
|
|
|
if let fastBootingButton = self.fastBootingButton {
|
|
|
|
let bootQuickly = standardUserDefaults.bool(forKey: self.bootQuicklyUserDefaultsKey)
|
|
|
|
machine.useQuickBootingHack = bootQuickly
|
|
|
|
fastBootingButton.state = bootQuickly ? .on : .off
|
|
|
|
}
|
2019-09-20 02:32:12 +00:00
|
|
|
|
2018-04-01 17:29:04 +00:00
|
|
|
if let displayTypeButton = self.displayTypeButton {
|
|
|
|
// Enable or disable options as per machine support.
|
|
|
|
var titlesToRemove: [String] = []
|
|
|
|
for item in displayTypeButton.itemArray {
|
|
|
|
if !machine.supportsVideoSignal(signalForTag(tag: item.tag)) {
|
|
|
|
titlesToRemove.append(item.title)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for title in titlesToRemove {
|
|
|
|
displayTypeButton.removeItem(withTitle: title)
|
|
|
|
}
|
|
|
|
|
|
|
|
let displayType = standardUserDefaults.integer(forKey: self.displayTypeUserDefaultsKey)
|
|
|
|
displayTypeButton.selectItem(withTag: displayType)
|
|
|
|
setDisplayType(displayTypeButton)
|
|
|
|
}
|
2016-10-03 01:56:50 +00:00
|
|
|
}
|
2016-10-02 20:31:50 +00:00
|
|
|
}
|