1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-09 01:29:44 +00:00

Introduced enough logic that the Atari 2600 is being run, at least. No output yet though because (i) it has no-one to send output to; and (ii) there's nobody that knows how to display output. Hmmm.

This commit is contained in:
Thomas Harte 2015-07-16 22:14:40 -04:00
parent 4496493e85
commit 195c8a87d8
5 changed files with 25 additions and 4 deletions

View File

@ -8,15 +8,17 @@
import Cocoa
class Atari2600Document: NSDocument {
class Atari2600Document: NSDocument, CSOpenGLViewDelegate {
override init() {
super.init()
// Add your subclass-specific initialization here.
}
@IBOutlet weak var openGLView: CSOpenGLView?
override func windowControllerDidLoadNib(aController: NSWindowController) {
super.windowControllerDidLoadNib(aController)
openGLView!.delegate = self
// Add any code here that needs to be executed once the windowController has loaded the document's window.
}
@ -45,5 +47,14 @@ class Atari2600Document: NSDocument {
atari2600?.setROM(data)
}
private var lastCycleCount: Int64?
func openGLView(view: CSOpenGLView!, didUpdateToTime time: CVTimeStamp) {
let cycleCount = (1194720 * time.videoTime) / Int64(time.videoTimeScale)
if let lastCycleCount = lastCycleCount {
let elapsedTime = cycleCount - lastCycleCount
atari2600!.runForNumberOfCycles(Int32(elapsedTime))
}
lastCycleCount = cycleCount
}
}

View File

@ -4,8 +4,9 @@
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8152.3"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="Document" customModule="Clock_Signal" customModuleProvider="target">
<customObject id="-2" userLabel="File's Owner" customClass="Atari2600Document" customModule="Clock_Signal" customModuleProvider="target">
<connections>
<outlet property="openGLView" destination="DEG-fq-cjd" id="Gxs-2u-n7B"/>
<outlet property="window" destination="xOd-HO-29H" id="JIz-fz-R2o"/>
</connections>
</customObject>

View File

@ -3,3 +3,4 @@
//
#import "Atari2600.h"
#import "OpenGLView.h"

View File

@ -9,6 +9,14 @@
#import <Foundation/Foundation.h>
@import AppKit;
@class CSOpenGLView;
@protocol CSOpenGLViewDelegate
- (void)openGLView:(CSOpenGLView *)view didUpdateToTime:(CVTimeStamp)time;
@end
@interface CSOpenGLView : NSOpenGLView
@property (nonatomic, weak) id <CSOpenGLViewDelegate> delegate;
@end

View File

@ -34,10 +34,10 @@
CVDisplayLinkStart(displayLink);
}
// This is the renderer output callback function
static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext)
{
[(__bridge CSOpenGLView *)displayLinkContext setNeedsDisplay:YES];
CSOpenGLView *view = (__bridge CSOpenGLView *)displayLinkContext;
[view.delegate openGLView:view didUpdateToTime:*now];
return kCVReturnSuccess;
}