2016-01-05 04:40:43 +00:00
|
|
|
//
|
|
|
|
// ElectronDocument.swift
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 03/01/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2016-01-14 03:38:59 +00:00
|
|
|
import AudioToolbox
|
2016-01-05 04:40:43 +00:00
|
|
|
|
|
|
|
class ElectronDocument: MachineDocument {
|
|
|
|
|
2016-03-20 02:46:17 +00:00
|
|
|
private lazy var electron = CSElectron()
|
2016-06-01 02:32:38 +00:00
|
|
|
override func machine() -> CSMachine! {
|
|
|
|
return electron
|
|
|
|
}
|
2016-01-05 04:40:43 +00:00
|
|
|
|
2016-06-01 23:04:07 +00:00
|
|
|
override func aspectRatio() -> NSSize {
|
|
|
|
return NSSize(width: 11.0, height: 10.0)
|
|
|
|
}
|
|
|
|
|
2016-06-05 12:33:01 +00:00
|
|
|
private func rom(name: String) -> NSData? {
|
2016-06-05 12:53:05 +00:00
|
|
|
return dataForResource(name, ofType: "rom", inDirectory: "ROMImages/Electron")
|
2016-06-05 12:33:01 +00:00
|
|
|
}
|
|
|
|
|
2016-01-10 01:34:22 +00:00
|
|
|
override func windowControllerDidLoadNib(aController: NSWindowController) {
|
|
|
|
super.windowControllerDidLoadNib(aController)
|
2016-06-01 02:36:53 +00:00
|
|
|
|
2016-06-16 22:19:23 +00:00
|
|
|
self.bestEffortUpdater.clockRate = 2000000
|
2016-06-01 02:36:53 +00:00
|
|
|
|
2016-06-05 12:53:05 +00:00
|
|
|
if let os = rom("os"), basic = rom("basic") {
|
2016-06-05 12:33:01 +00:00
|
|
|
self.electron.setOSROM(os)
|
|
|
|
self.electron.setBASICROM(basic)
|
2016-06-01 02:32:38 +00:00
|
|
|
}
|
2016-06-01 02:36:53 +00:00
|
|
|
|
2016-04-18 12:21:00 +00:00
|
|
|
establishStoredOptions()
|
2016-01-10 01:34:22 +00:00
|
|
|
}
|
2016-01-05 04:40:43 +00:00
|
|
|
|
|
|
|
override var windowNibName: String? {
|
|
|
|
return "ElectronDocument"
|
|
|
|
}
|
|
|
|
|
2016-01-18 21:46:41 +00:00
|
|
|
override func readFromURL(url: NSURL, ofType typeName: String) throws {
|
|
|
|
print(url)
|
|
|
|
print(typeName)
|
2016-01-20 03:05:34 +00:00
|
|
|
|
|
|
|
if let pathExtension = url.pathExtension {
|
|
|
|
switch pathExtension.lowercaseString {
|
|
|
|
case "uef":
|
|
|
|
electron.openUEFAtURL(url)
|
|
|
|
return
|
|
|
|
default: break;
|
|
|
|
}
|
2016-01-18 21:46:41 +00:00
|
|
|
}
|
2016-01-20 03:05:34 +00:00
|
|
|
|
|
|
|
let fileWrapper = try NSFileWrapper(URL: url, options: NSFileWrapperReadingOptions(rawValue: 0))
|
|
|
|
try self.readFromFileWrapper(fileWrapper, ofType: typeName)
|
2016-01-18 21:46:41 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 04:40:43 +00:00
|
|
|
override func readFromData(data: NSData, ofType typeName: String) throws {
|
2016-06-05 12:33:01 +00:00
|
|
|
if let plus1ROM = rom("plus1") {
|
|
|
|
electron.setROM(plus1ROM, slot: 12)
|
2016-03-12 16:51:20 +00:00
|
|
|
}
|
2016-01-13 03:34:26 +00:00
|
|
|
electron.setROM(data, slot: 15)
|
2016-01-05 04:40:43 +00:00
|
|
|
}
|
|
|
|
|
2016-04-18 12:21:00 +00:00
|
|
|
// MARK: IBActions
|
|
|
|
@IBOutlet var displayTypeButton: NSPopUpButton!
|
|
|
|
@IBAction func setDisplayType(sender: NSPopUpButton!) {
|
2016-04-18 23:01:15 +00:00
|
|
|
electron.useTelevisionOutput = (sender.indexOfSelectedItem == 1)
|
2016-04-18 12:21:00 +00:00
|
|
|
NSUserDefaults.standardUserDefaults().setInteger(sender.indexOfSelectedItem, forKey: self.displayTypeUserDefaultsKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBOutlet var fastLoadingButton: NSButton!
|
|
|
|
@IBAction func setFastLoading(sender: NSButton!) {
|
|
|
|
electron.useFastLoadingHack = sender.state == NSOnState
|
|
|
|
NSUserDefaults.standardUserDefaults().setBool(electron.useFastLoadingHack, forKey: self.fastLoadingUserDefaultsKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
private let displayTypeUserDefaultsKey = "electron.displayType"
|
|
|
|
private let fastLoadingUserDefaultsKey = "electron.fastLoading"
|
|
|
|
private func establishStoredOptions() {
|
|
|
|
let standardUserDefaults = NSUserDefaults.standardUserDefaults()
|
|
|
|
standardUserDefaults.registerDefaults([
|
|
|
|
displayTypeUserDefaultsKey: 0,
|
|
|
|
fastLoadingUserDefaultsKey: true
|
|
|
|
])
|
|
|
|
|
|
|
|
let useFastLoadingHack = standardUserDefaults.boolForKey(self.fastLoadingUserDefaultsKey)
|
|
|
|
electron.useFastLoadingHack = useFastLoadingHack
|
|
|
|
self.fastLoadingButton.state = useFastLoadingHack ? NSOnState : NSOffState
|
|
|
|
|
|
|
|
let displayType = standardUserDefaults.integerForKey(self.displayTypeUserDefaultsKey)
|
|
|
|
electron.useTelevisionOutput = (displayType == 1)
|
|
|
|
self.displayTypeButton.selectItemAtIndex(displayType)
|
|
|
|
}
|
2016-01-05 04:40:43 +00:00
|
|
|
}
|