Pause / Resume with VSYNC

This commit is contained in:
tudnai 2022-06-21 21:53:10 -07:00
parent 7fa288d84d
commit 74ae760730
3 changed files with 29 additions and 27 deletions

2
.gitignore vendored
View File

@ -22,3 +22,5 @@ Resources/rom/Downloads/APPLE_IIe_ROM_KRK1.zip
Resources/rom/Downloads/APPLE_IIe_ROM_KRK2.zip Resources/rom/Downloads/APPLE_IIe_ROM_KRK2.zip
Resources/rom/Downloads/apple_iie_rom.zip Resources/rom/Downloads/apple_iie_rom.zip
Resources/rom/Downloads/077-0026-0027 for IIe.zip Resources/rom/Downloads/077-0026-0027 for IIe.zip
**/Contents/**

View File

@ -208,7 +208,7 @@ class ViewController: NSViewController {
var workItem : DispatchWorkItem? = nil; var workItem : DispatchWorkItem? = nil;
@IBAction func PowerOn(_ sender: Any) { @IBAction func PowerOn(_ sender: Any) {
upd.suspend() CVDisplayLinkStop(displayLink!)
cpuState = cpuState_inited; cpuState = cpuState_inited;
spkr_stopAll() spkr_stopAll()
@ -239,7 +239,7 @@ class ViewController: NSViewController {
m6502_ColdReset( Bundle.main.resourcePath! + "/rom/", ViewController.romFileName ) m6502_ColdReset( Bundle.main.resourcePath! + "/rom/", ViewController.romFileName )
cpuState = cpuState_running; cpuState = cpuState_running;
self.upd.resume() CVDisplayLinkStart(self.displayLink!)
} }
//------------------------------------------------------------ //------------------------------------------------------------
@ -267,7 +267,7 @@ class ViewController: NSViewController {
@IBAction func PowerOff(_ sender: Any) { @IBAction func PowerOff(_ sender: Any) {
upd.suspend() CVDisplayLinkStop(displayLink!)
cpuState = cpuState_inited; cpuState = cpuState_inited;
spkr_stopAll() spkr_stopAll()
@ -290,12 +290,12 @@ class ViewController: NSViewController {
switch ( cpuState ) { switch ( cpuState ) {
case cpuState_halted: case cpuState_halted:
upd.resume() CVDisplayLinkStart(displayLink!)
cpuState = cpuState_running cpuState = cpuState_running
break break
case cpuState_running: case cpuState_running:
upd.suspend() CVDisplayLinkStop(displayLink!)
cpuState = cpuState_halted cpuState = cpuState_halted
break break
@ -337,6 +337,8 @@ class ViewController: NSViewController {
let lineEndChars = ViewController.lineEndChars let lineEndChars = ViewController.lineEndChars
var frameCnt = 0 var frameCnt = 0
var flashInverted = false
// let spaceChar : Character = "\u{E17F}" // let spaceChar : Character = "\u{E17F}"
// let blockChar : Character = "\u{E07F}" // let blockChar : Character = "\u{E07F}"
// static let spaceChar : Character = " " // static let spaceChar : Character = " "
@ -465,7 +467,7 @@ class ViewController: NSViewController {
if ( cpuMode == cpuMode_eco ) { if ( cpuMode == cpuMode_eco ) {
cpuState = cpuState_running; cpuState = cpuState_running;
upd.resume() CVDisplayLinkStart(displayLink!)
} }
// print("keyDown") // print("keyDown")
@ -714,11 +716,18 @@ class ViewController: NSViewController {
self.frameCnt += 1 self.frameCnt += 1
if ( self.frameCnt == fps / video_fps_divider / 2 ) { if ( self.frameCnt == fps / video_fps_divider / 2 ) {
ViewController.charConvTbl = ViewController.charConvTblFlashOn if !flashInverted {
ViewController.charConvTbl = ViewController.charConvTblFlashOn
flashInverted = true
}
} }
else if ( self.frameCnt >= fps / video_fps_divider ) { else if ( self.frameCnt >= fps / video_fps_divider ) {
self.frameCnt = 0 self.frameCnt = 0
ViewController.charConvTbl = ViewController.charConvTblFlashOff
if flashInverted {
ViewController.charConvTbl = ViewController.charConvTblFlashOff
flashInverted = false
}
} }
} }
@ -1008,13 +1017,13 @@ class ViewController: NSViewController {
case cpuState_halting: case cpuState_halting:
cpuState = cpuState_halted cpuState = cpuState_halted
// video rendering // last video rendering before halt
Render() Render()
break break
case cpuState_halted: case cpuState_halted:
upd.suspend() CVDisplayLinkStop(displayLink!)
break break
default: default:
@ -1034,17 +1043,6 @@ class ViewController: NSViewController {
// } // }
var upd = RepeatingTimer(timeInterval: 1)
// func newUpdateTimer( timeInterval : Double ) {
// upd.kill()
// upd = RepeatingTimer(timeInterval: timeInterval)
// upd.eventHandler = {
// self.Update()
// }
// upd.resume()
// }
// Kelvin Sherlock's fix to avoid uninstalled font problems // Kelvin Sherlock's fix to avoid uninstalled font problems
override func awakeFromNib() { override func awakeFromNib() {
@ -1144,7 +1142,7 @@ class ViewController: NSViewController {
let unsafeSelf: UnsafeMutableRawPointer = Unmanaged.passUnretained(self).toOpaque() let unsafeSelf: UnsafeMutableRawPointer = Unmanaged.passUnretained(self).toOpaque()
CVDisplayLinkSetOutputCallback(displayLink!, displayLinkOutputCallback, unsafeSelf) CVDisplayLinkSetOutputCallback(displayLink!, displayLinkOutputCallback, unsafeSelf)
CVDisplayLinkStart(displayLink!) // CVDisplayLinkStart(displayLink!)
} }
@ -1399,7 +1397,7 @@ class ViewController: NSViewController {
cpuMode = cpuMode_eco cpuMode = cpuMode_eco
fps = DEFAULT_FPS fps = DEFAULT_FPS
video_fps_divider = DEF_VIDEO_DIV video_fps_divider = ECO_VIDEO_DIV
break break
case "Game": case "Game":

View File

@ -187,11 +187,13 @@ extern double mips;
extern double mhz; extern double mhz;
#define DEFAULT_FPS 60U #define DEFAULT_FPS 60U
#define DEF_VIDEO_DIV 1U #define DEF_VIDEO_DIV 2U
#define DEF_SPKR_DIV 1U #define DEF_SPKR_DIV 2U
#define GAME_FPS 180U // 480U #define ECO_VIDEO_DIV 4U
#define GAME_VIDEO_DIV (GAME_FPS / DEFAULT_FPS)
#define GAME_FPS 60U // 180U // 480U
#define GAME_VIDEO_DIV 1U // (GAME_FPS / DEFAULT_FPS)
extern unsigned int video_fps_divider; extern unsigned int video_fps_divider;
extern unsigned int fps; extern unsigned int fps;