mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-01 11:49:58 +00:00
Ensured there's no overflow while changing base.
This commit is contained in:
parent
412e02fdd8
commit
12746b35e3
@ -50,7 +50,14 @@ class Atari2600Document: NSDocument, CSOpenGLViewDelegate {
|
|||||||
private var lastCycleCount: Int64?
|
private var lastCycleCount: Int64?
|
||||||
func openGLView(view: CSOpenGLView!, didUpdateToTime time: CVTimeStamp) {
|
func openGLView(view: CSOpenGLView!, didUpdateToTime time: CVTimeStamp) {
|
||||||
|
|
||||||
let cycleCount = (1194720 * time.videoTime) / Int64(time.videoTimeScale)
|
// this slightly elaborate dance is to avoid overflow
|
||||||
|
let intendedCyclesPerSecond: Int64 = 1194720
|
||||||
|
let videoTimeScale64 = Int64(time.videoTimeScale)
|
||||||
|
|
||||||
|
let cycleCountLow = ((time.videoTime % videoTimeScale64) * intendedCyclesPerSecond) / videoTimeScale64
|
||||||
|
let cycleCountHigh = (time.videoTime / videoTimeScale64) * intendedCyclesPerSecond
|
||||||
|
|
||||||
|
let cycleCount = cycleCountLow + cycleCountHigh
|
||||||
if let lastCycleCount = lastCycleCount {
|
if let lastCycleCount = lastCycleCount {
|
||||||
let elapsedTime = cycleCount - lastCycleCount
|
let elapsedTime = cycleCount - lastCycleCount
|
||||||
atari2600!.runForNumberOfCycles(Int32(elapsedTime))
|
atari2600!.runForNumberOfCycles(Int32(elapsedTime))
|
||||||
|
Loading…
Reference in New Issue
Block a user