mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-26 15:32:04 +00:00
Started trying to clean up and consolidate on the Swift side of things but time is up for the day.
This commit is contained in:
parent
8dc66167be
commit
c773c3a66c
@ -10,6 +10,11 @@ import Cocoa
|
||||
|
||||
class Atari2600Document: MachineDocument {
|
||||
|
||||
private var atari2600 = CSAtari2600()
|
||||
override func machine() -> CSMachine? {
|
||||
return atari2600
|
||||
}
|
||||
|
||||
// MARK: NSDocument overrides
|
||||
override init() {
|
||||
super.init()
|
||||
@ -31,7 +36,6 @@ class Atari2600Document: MachineDocument {
|
||||
return "Atari2600Document"
|
||||
}
|
||||
|
||||
private var atari2600 = CSAtari2600()
|
||||
override func dataOfType(typeName: String) throws -> NSData {
|
||||
// Insert code here to write your document to data of the specified type. If outError != nil, ensure that you create and set an appropriate error when returning nil.
|
||||
// You can also choose to override fileWrapperOfType:error:, writeToURL:ofType:error:, or writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
|
||||
@ -42,21 +46,6 @@ class Atari2600Document: MachineDocument {
|
||||
atari2600.setROM(data)
|
||||
}
|
||||
|
||||
override func close() {
|
||||
super.close()
|
||||
openGLView.invalidate()
|
||||
}
|
||||
|
||||
// MARK: MachineDocument overrides
|
||||
|
||||
override func runForNumberOfCycles(numberOfCycles: Int32) {
|
||||
atari2600.runForNumberOfCycles(numberOfCycles)
|
||||
}
|
||||
|
||||
override func openGLView(view: CSOpenGLView, drawViewOnlyIfDirty onlyIfDirty: Bool) {
|
||||
atari2600.drawViewForPixelSize(view.backingSize, onlyIfDirty: onlyIfDirty)
|
||||
}
|
||||
|
||||
// MARK: CSOpenGLViewResponderDelegate
|
||||
|
||||
private func inputForKey(event: NSEvent) -> Atari2600DigitalInput? {
|
||||
|
@ -12,21 +12,24 @@ import AudioToolbox
|
||||
class ElectronDocument: MachineDocument {
|
||||
|
||||
private lazy var electron = CSElectron()
|
||||
override func machine() -> CSMachine! {
|
||||
return electron
|
||||
}
|
||||
|
||||
override func windowControllerDidLoadNib(aController: NSWindowController) {
|
||||
super.windowControllerDidLoadNib(aController)
|
||||
self.intendedCyclesPerSecond = 2000000
|
||||
aController.window?.contentAspectRatio = NSSize(width: 11.0, height: 10.0)
|
||||
if let osPath = NSBundle.mainBundle().pathForResource("os", ofType: "rom") {
|
||||
self.electron.setOSROM(NSData(contentsOfFile: osPath)!)
|
||||
}
|
||||
if let basicPath = NSBundle.mainBundle().pathForResource("basic", ofType: "rom") {
|
||||
self.electron.setBASICROM(NSData(contentsOfFile: basicPath)!)
|
||||
}
|
||||
openGLView.performWithGLContext({
|
||||
if let osPath = NSBundle.mainBundle().pathForResource("os", ofType: "rom") {
|
||||
self.electron.setOSROM(NSData(contentsOfFile: osPath)!)
|
||||
}
|
||||
if let basicPath = NSBundle.mainBundle().pathForResource("basic", ofType: "rom") {
|
||||
self.electron.setBASICROM(NSData(contentsOfFile: basicPath)!)
|
||||
}
|
||||
self.electron.setView(self.openGLView, aspectRatio: 11.0 / 10.0)
|
||||
self.electron.audioQueue = self.audioQueue
|
||||
})
|
||||
self.electron.audioQueue = self.audioQueue
|
||||
establishStoredOptions()
|
||||
}
|
||||
|
||||
@ -58,19 +61,6 @@ class ElectronDocument: MachineDocument {
|
||||
electron.setROM(data, slot: 15)
|
||||
}
|
||||
|
||||
lazy var actionLock = NSLock()
|
||||
lazy var drawLock = NSLock()
|
||||
override func close() {
|
||||
actionLock.lock()
|
||||
drawLock.lock()
|
||||
openGLView.invalidate()
|
||||
openGLView.openGLContext!.makeCurrentContext()
|
||||
actionLock.unlock()
|
||||
drawLock.unlock()
|
||||
|
||||
super.close()
|
||||
}
|
||||
|
||||
// MARK: IBActions
|
||||
@IBOutlet var displayTypeButton: NSPopUpButton!
|
||||
@IBAction func setDisplayType(sender: NSPopUpButton!) {
|
||||
@ -102,21 +92,6 @@ class ElectronDocument: MachineDocument {
|
||||
self.displayTypeButton.selectItemAtIndex(displayType)
|
||||
}
|
||||
|
||||
// MARK: CSOpenGLViewDelegate
|
||||
override func runForNumberOfCycles(numberOfCycles: Int32) {
|
||||
if actionLock.tryLock() {
|
||||
electron.runForNumberOfCycles(numberOfCycles)
|
||||
actionLock.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
override func openGLView(view: CSOpenGLView, drawViewOnlyIfDirty onlyIfDirty: Bool) {
|
||||
if drawLock.tryLock() {
|
||||
electron.drawViewForPixelSize(view.backingSize, onlyIfDirty: onlyIfDirty)
|
||||
drawLock.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: NSWindowDelegate
|
||||
func windowDidResignKey(notification: NSNotification) {
|
||||
electron.clearAllKeys()
|
||||
|
@ -11,6 +11,12 @@ import AudioToolbox
|
||||
|
||||
class MachineDocument: NSDocument, CSOpenGLViewDelegate, CSOpenGLViewResponderDelegate, NSWindowDelegate {
|
||||
|
||||
lazy var actionLock = NSLock()
|
||||
lazy var drawLock = NSLock()
|
||||
func machine() -> CSMachine! {
|
||||
return nil
|
||||
}
|
||||
|
||||
@IBOutlet weak var openGLView: CSOpenGLView! {
|
||||
didSet {
|
||||
openGLView.delegate = self
|
||||
@ -32,6 +38,17 @@ class MachineDocument: NSDocument, CSOpenGLViewDelegate, CSOpenGLViewResponderDe
|
||||
aController.window?.contentAspectRatio = NSSize(width: 4.0, height: 3.0)
|
||||
}
|
||||
|
||||
override func close() {
|
||||
actionLock.lock()
|
||||
drawLock.lock()
|
||||
openGLView.invalidate()
|
||||
openGLView.openGLContext!.makeCurrentContext()
|
||||
actionLock.unlock()
|
||||
drawLock.unlock()
|
||||
|
||||
super.close()
|
||||
}
|
||||
|
||||
var intendedCyclesPerSecond: Int64 = 0
|
||||
private var cycleCountError: Int64 = 0
|
||||
private var lastTime: CVTimeStamp?
|
||||
@ -62,8 +79,20 @@ class MachineDocument: NSDocument, CSOpenGLViewDelegate, CSOpenGLViewResponderDe
|
||||
lastTime = time
|
||||
}
|
||||
|
||||
func openGLView(view: CSOpenGLView, drawViewOnlyIfDirty onlyIfDirty: Bool) {}
|
||||
func runForNumberOfCycles(numberOfCycles: Int32) {}
|
||||
// MARK: CSOpenGLViewDelegate
|
||||
func runForNumberOfCycles(numberOfCycles: Int32) {
|
||||
if actionLock.tryLock() {
|
||||
self.machine().runForNumberOfCycles(numberOfCycles)
|
||||
actionLock.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func openGLView(view: CSOpenGLView, drawViewOnlyIfDirty onlyIfDirty: Bool) {
|
||||
if drawLock.tryLock() {
|
||||
self.machine().drawViewForPixelSize(view.backingSize, onlyIfDirty: onlyIfDirty)
|
||||
drawLock.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: CSOpenGLViewResponderDelegate
|
||||
func keyDown(event: NSEvent) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user