2015-07-16 23:53:53 +00:00
|
|
|
//
|
2015-07-17 00:40:46 +00:00
|
|
|
// Atari2600Document.swift
|
2015-07-16 23:53:53 +00:00
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 16/07/2015.
|
|
|
|
// Copyright © 2015 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
2016-01-05 04:40:43 +00:00
|
|
|
class Atari2600Document: MachineDocument {
|
|
|
|
|
2016-06-01 02:32:38 +00:00
|
|
|
private var atari2600 = CSAtari2600()
|
|
|
|
override func machine() -> CSMachine? {
|
|
|
|
return atari2600
|
|
|
|
}
|
|
|
|
|
2016-01-05 04:40:43 +00:00
|
|
|
// MARK: NSDocument overrides
|
2015-07-16 23:53:53 +00:00
|
|
|
override class func autosavesInPlace() -> Bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
override var windowNibName: String? {
|
|
|
|
return "Atari2600Document"
|
|
|
|
}
|
|
|
|
|
|
|
|
override func readFromData(data: NSData, ofType typeName: String) throws {
|
2016-01-05 04:12:47 +00:00
|
|
|
atari2600.setROM(data)
|
2015-07-16 23:53:53 +00:00
|
|
|
}
|
|
|
|
|
2015-08-19 00:33:24 +00:00
|
|
|
// MARK: CSOpenGLViewResponderDelegate
|
|
|
|
|
2016-01-05 04:40:43 +00:00
|
|
|
private func inputForKey(event: NSEvent) -> Atari2600DigitalInput? {
|
2015-08-19 00:33:24 +00:00
|
|
|
switch event.keyCode {
|
|
|
|
case 123: return Atari2600DigitalInputJoy1Left
|
|
|
|
case 126: return Atari2600DigitalInputJoy1Up
|
|
|
|
case 124: return Atari2600DigitalInputJoy1Right
|
|
|
|
case 125: return Atari2600DigitalInputJoy1Down
|
|
|
|
case 0: return Atari2600DigitalInputJoy1Fire
|
|
|
|
default: print("\(event.keyCode)"); return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 04:40:43 +00:00
|
|
|
override func keyDown(event: NSEvent) {
|
|
|
|
super.keyDown(event)
|
|
|
|
|
2015-08-19 00:33:24 +00:00
|
|
|
if let input = inputForKey(event) {
|
2016-01-05 04:12:47 +00:00
|
|
|
atari2600.setState(true, forDigitalInput: input)
|
2015-08-19 00:33:24 +00:00
|
|
|
}
|
2015-08-19 00:58:05 +00:00
|
|
|
|
|
|
|
if event.keyCode == 36 {
|
2016-01-05 04:12:47 +00:00
|
|
|
atari2600.setResetLineEnabled(true)
|
2015-08-19 00:58:05 +00:00
|
|
|
}
|
2015-08-19 00:33:24 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 04:40:43 +00:00
|
|
|
override func keyUp(event: NSEvent) {
|
|
|
|
super.keyUp(event)
|
|
|
|
|
2015-08-19 00:33:24 +00:00
|
|
|
if let input = inputForKey(event) {
|
2016-01-05 04:12:47 +00:00
|
|
|
atari2600.setState(false, forDigitalInput: input)
|
2015-08-19 00:33:24 +00:00
|
|
|
}
|
2015-08-19 00:58:05 +00:00
|
|
|
|
|
|
|
if event.keyCode == 36 {
|
2016-01-05 04:12:47 +00:00
|
|
|
atari2600.setResetLineEnabled(false)
|
2015-08-19 00:58:05 +00:00
|
|
|
}
|
2015-08-19 00:33:24 +00:00
|
|
|
}
|
2015-07-16 23:53:53 +00:00
|
|
|
}
|