2017-07-27 06:28:52 +00:00
|
|
|
//
|
2017-08-01 06:02:49 +00:00
|
|
|
// AppleIIViewController.swift
|
2017-07-27 06:28:52 +00:00
|
|
|
// FruitMachine
|
|
|
|
//
|
2017-08-01 06:02:49 +00:00
|
|
|
// Created by Christopher Rohl on 8/1/17.
|
2017-07-27 06:28:52 +00:00
|
|
|
// Copyright © 2017 Christopher Rohl. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
2017-08-01 06:02:49 +00:00
|
|
|
class AppleIIViewController: NSViewController {
|
2017-07-27 06:28:52 +00:00
|
|
|
|
2017-08-01 06:02:49 +00:00
|
|
|
let computer = AppleII.sharedInstance
|
2017-07-27 23:22:13 +00:00
|
|
|
var debuggerWindowController: DebuggerWindowController!
|
2017-07-31 07:03:14 +00:00
|
|
|
var preferencesWindowController: PreferencesWindowController!
|
2017-07-27 23:22:13 +00:00
|
|
|
|
2017-07-29 06:56:06 +00:00
|
|
|
var isPaused = false
|
|
|
|
var frameTimer: Timer?
|
2017-08-01 06:02:49 +00:00
|
|
|
|
|
|
|
override func viewDidLoad() {
|
2017-07-27 06:28:52 +00:00
|
|
|
super.viewDidLoad()
|
2017-08-01 06:02:49 +00:00
|
|
|
// Do view setup here.
|
2017-07-31 07:03:14 +00:00
|
|
|
|
|
|
|
preferencesWindowController = PreferencesWindowController()
|
2017-07-27 06:28:52 +00:00
|
|
|
|
2017-07-27 23:22:13 +00:00
|
|
|
self.view.addSubview(computer.emulatorView)
|
2017-07-27 06:28:52 +00:00
|
|
|
|
2017-08-01 21:40:01 +00:00
|
|
|
self.frameTimer = Timer.scheduledTimer(timeInterval: 1.0/60.0,
|
2017-07-31 03:23:31 +00:00
|
|
|
target: self,
|
|
|
|
selector: #selector(runEmulation),
|
|
|
|
userInfo: nil,
|
|
|
|
repeats: true)
|
2017-07-29 06:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@objc func runEmulation() {
|
2017-07-29 20:11:14 +00:00
|
|
|
computer.runFrame()
|
2017-07-30 02:48:37 +00:00
|
|
|
if(!CPU.sharedInstance.isRunning) {
|
|
|
|
self.frameTimer?.invalidate()
|
|
|
|
}
|
2017-07-29 06:56:06 +00:00
|
|
|
}
|
|
|
|
|
2017-07-31 07:03:14 +00:00
|
|
|
@IBAction func showDebugger(_ sender: Any) {
|
|
|
|
let debuggerStoryboard = NSStoryboard(name: NSStoryboard.Name(rawValue: "Debugger"), bundle: nil)
|
|
|
|
debuggerWindowController = debuggerStoryboard.instantiateInitialController() as! DebuggerWindowController
|
|
|
|
debuggerWindowController.showWindow(self)
|
|
|
|
}
|
2017-07-31 20:33:42 +00:00
|
|
|
|
|
|
|
@IBAction func showPreferences(_ sender: Any) {
|
|
|
|
preferencesWindowController.loadWindow()
|
|
|
|
}
|
2017-08-01 06:02:49 +00:00
|
|
|
|
2017-08-01 21:40:01 +00:00
|
|
|
override func keyDown(with event: NSEvent) {
|
|
|
|
let c = returnChar(theEvent: event)
|
|
|
|
|
|
|
|
guard let ascii32 = c?.asciiValue else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//Poke the ASCII byte into $C000.
|
|
|
|
CPU.sharedInstance.memoryInterface.writeByte(offset: 0xC000, value: UInt8((ascii32 | 0x80) & 0x000000FF))
|
|
|
|
}
|
|
|
|
|
|
|
|
private func returnChar(theEvent: NSEvent) -> Character?{
|
|
|
|
let s: String = theEvent.characters!
|
|
|
|
for char in s{
|
|
|
|
return char
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-07-29 20:11:14 +00:00
|
|
|
}
|