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
|
|
|
|
|
|
|
|
class ElectronDocument: MachineDocument {
|
|
|
|
|
|
|
|
private var electron = CSElectron()
|
|
|
|
override init() {
|
|
|
|
super.init()
|
|
|
|
self.intendedCyclesPerSecond = 2000000
|
2016-01-07 04:14:36 +00:00
|
|
|
|
|
|
|
if let osPath = NSBundle.mainBundle().pathForResource("os", ofType: "rom") {
|
|
|
|
electron.setOSROM(NSData(contentsOfFile: osPath)!)
|
|
|
|
}
|
|
|
|
if let basicPath = NSBundle.mainBundle().pathForResource("basic", ofType: "rom") {
|
|
|
|
electron.setBASICROM(NSData(contentsOfFile: basicPath)!)
|
|
|
|
}
|
2016-01-05 04:40:43 +00:00
|
|
|
}
|
|
|
|
|
2016-01-10 01:34:22 +00:00
|
|
|
override func windowControllerDidLoadNib(aController: NSWindowController) {
|
|
|
|
super.windowControllerDidLoadNib(aController)
|
|
|
|
electron.view = openGLView
|
|
|
|
// openGLView.frameBounds = CGRectMake(0.1, 0.1, 0.8, 0.8)
|
|
|
|
}
|
2016-01-05 04:40:43 +00:00
|
|
|
|
|
|
|
override var windowNibName: String? {
|
|
|
|
return "ElectronDocument"
|
|
|
|
}
|
|
|
|
|
|
|
|
override func readFromData(data: NSData, ofType typeName: String) throws {
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: CSOpenGLViewDelegate
|
|
|
|
override func runForNumberOfCycles(numberOfCycles: Int32) {
|
|
|
|
electron.runForNumberOfCycles(numberOfCycles)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: CSOpenGLViewResponderDelegate
|
2016-01-12 00:48:31 +00:00
|
|
|
override func keyDown(event: NSEvent) {
|
|
|
|
electron.setKey(event.keyCode, isPressed: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func keyUp(event: NSEvent) {
|
|
|
|
electron.setKey(event.keyCode, isPressed: false)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func flagsChanged(newModifiers: NSEvent) {
|
|
|
|
electron.setKey(kVK_Shift, isPressed: newModifiers.modifierFlags.contains(.ShiftKeyMask))
|
|
|
|
electron.setKey(kVK_Control, isPressed: newModifiers.modifierFlags.contains(.ControlKeyMask))
|
|
|
|
electron.setKey(kVK_Command, isPressed: newModifiers.modifierFlags.contains(.CommandKeyMask))
|
|
|
|
}
|
2016-01-05 04:40:43 +00:00
|
|
|
|
|
|
|
}
|