2015-07-16 19:53:53 -04:00
|
|
|
//
|
2015-07-16 20:40:46 -04:00
|
|
|
// Atari2600Document.swift
|
2015-07-16 19:53:53 -04:00
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 16/07/2015.
|
|
|
|
// Copyright © 2015 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
2016-01-04 23:40:43 -05:00
|
|
|
class Atari2600Document: MachineDocument {
|
|
|
|
|
2016-05-31 22:32:38 -04:00
|
|
|
private var atari2600 = CSAtari2600()
|
2016-06-23 21:09:34 -04:00
|
|
|
override var machine: CSMachine! {
|
|
|
|
get {
|
|
|
|
return atari2600
|
|
|
|
}
|
2016-05-31 22:32:38 -04:00
|
|
|
}
|
2016-06-27 21:38:14 -04:00
|
|
|
override var name: String! {
|
|
|
|
get {
|
|
|
|
return "atari2600"
|
|
|
|
}
|
|
|
|
}
|
2016-05-31 22:32:38 -04:00
|
|
|
|
2016-01-04 23:40:43 -05:00
|
|
|
// MARK: NSDocument overrides
|
2015-07-16 19:53:53 -04: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-04 23:12:47 -05:00
|
|
|
atari2600.setROM(data)
|
2015-07-16 19:53:53 -04:00
|
|
|
}
|
|
|
|
|
2016-06-20 21:31:07 -04:00
|
|
|
override func windowControllerDidLoadNib(aController: NSWindowController) {
|
|
|
|
super.windowControllerDidLoadNib(aController)
|
|
|
|
|
|
|
|
// push whatever settings the switches have in the NIB into the emulation
|
|
|
|
pushSwitchValues()
|
|
|
|
|
|
|
|
// show the options window but ensure the OpenGL view is key
|
|
|
|
showOptions(self)
|
|
|
|
self.openGLView.window?.makeKeyWindow()
|
|
|
|
}
|
|
|
|
|
2015-08-18 20:33:24 -04:00
|
|
|
// MARK: CSOpenGLViewResponderDelegate
|
2016-01-04 23:40:43 -05:00
|
|
|
private func inputForKey(event: NSEvent) -> Atari2600DigitalInput? {
|
2015-08-18 20:33:24 -04: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-04 23:40:43 -05:00
|
|
|
override func keyDown(event: NSEvent) {
|
|
|
|
super.keyDown(event)
|
|
|
|
|
2015-08-18 20:33:24 -04:00
|
|
|
if let input = inputForKey(event) {
|
2016-01-04 23:12:47 -05:00
|
|
|
atari2600.setState(true, forDigitalInput: input)
|
2015-08-18 20:33:24 -04:00
|
|
|
}
|
2015-08-18 20:58:05 -04:00
|
|
|
|
|
|
|
if event.keyCode == 36 {
|
2016-01-04 23:12:47 -05:00
|
|
|
atari2600.setResetLineEnabled(true)
|
2015-08-18 20:58:05 -04:00
|
|
|
}
|
2015-08-18 20:33:24 -04:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:40:43 -05:00
|
|
|
override func keyUp(event: NSEvent) {
|
|
|
|
super.keyUp(event)
|
|
|
|
|
2015-08-18 20:33:24 -04:00
|
|
|
if let input = inputForKey(event) {
|
2016-01-04 23:12:47 -05:00
|
|
|
atari2600.setState(false, forDigitalInput: input)
|
2015-08-18 20:33:24 -04:00
|
|
|
}
|
2015-08-18 20:58:05 -04:00
|
|
|
|
|
|
|
if event.keyCode == 36 {
|
2016-01-04 23:12:47 -05:00
|
|
|
atari2600.setResetLineEnabled(false)
|
2015-08-18 20:58:05 -04:00
|
|
|
}
|
2015-08-18 20:33:24 -04:00
|
|
|
}
|
2016-06-19 19:36:34 -04:00
|
|
|
|
|
|
|
// MARK: Options
|
|
|
|
@IBOutlet var resetButton: NSButton!
|
|
|
|
@IBOutlet var selectButton: NSButton!
|
|
|
|
@IBOutlet var colourButton: NSButton!
|
|
|
|
@IBOutlet var leftPlayerDifficultyButton: NSButton!
|
|
|
|
@IBOutlet var rightPlayerDifficultyButton: NSButton!
|
|
|
|
|
|
|
|
@IBAction func optionDidChange(sender: AnyObject!) {
|
2016-06-20 21:31:07 -04:00
|
|
|
pushSwitchValues()
|
|
|
|
}
|
|
|
|
|
|
|
|
private func pushSwitchValues() {
|
2016-06-19 19:36:34 -04:00
|
|
|
atari2600.colourButton = colourButton.state == NSOnState
|
|
|
|
atari2600.leftPlayerDifficultyButton = leftPlayerDifficultyButton.state == NSOnState
|
|
|
|
atari2600.rightPlayerDifficultyButton = rightPlayerDifficultyButton.state == NSOnState
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func optionWasPressed(sender: NSButton!) {
|
|
|
|
if sender == resetButton {
|
|
|
|
atari2600.pressResetButton()
|
|
|
|
} else {
|
|
|
|
atari2600.pressSelectButton()
|
|
|
|
}
|
|
|
|
}
|
2015-07-16 19:53:53 -04:00
|
|
|
}
|