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