From c157f4b071e6e097e8536a62e47d8e09bd428fd0 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sat, 25 Aug 2018 18:01:51 -0400 Subject: [PATCH] fix VCS hanging up when loading rom when paused; also fixed same bug in AnimationTimer --- index.html | 13 +++++-------- javatari.js | 2 +- src/emu.ts | 10 ++++++++-- src/platform/vcs.ts | 26 ++++++++++---------------- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/index.html b/index.html index 2f72de42..8576ee5e 100644 --- a/index.html +++ b/index.html @@ -278,17 +278,14 @@ if (window.location.host.endsWith('8bitworkshop.com')) { + - - + diff --git a/javatari.js b/javatari.js index 8f5767e4..7e246e74 160000 --- a/javatari.js +++ b/javatari.js @@ -1 +1 @@ -Subproject commit 8f5767e4ca9a759d759e9a09677d649d58f6aff7 +Subproject commit 7e246e74bd56c76acf8b7e05334f0221e1783977 diff --git a/src/emu.ts b/src/emu.ts index 80dd68e4..3e2d6b6c 100644 --- a/src/emu.ts +++ b/src/emu.ts @@ -176,7 +176,8 @@ export class RAM { export var AnimationTimer = function(frequencyHz:number, callback:() => void) { var intervalMsec = 1000.0 / frequencyHz; - var running; + var running : boolean = false; + var pulsing : boolean = false; var lastts = 0; var useReqAnimFrame = false; //window.requestAnimationFrame ? (frequencyHz>40) : false; var nframes, startts; // for FPS calc @@ -197,6 +198,8 @@ export var AnimationTimer = function(frequencyHz:number, callback:() => void) { } if (running) { scheduleFrame(lastts - ts); + } else { + pulsing = false; } if (!useReqAnimFrame || lastts - ts > intervalMsec/2) { if (running) { @@ -221,7 +224,10 @@ export var AnimationTimer = function(frequencyHz:number, callback:() => void) { running = true; lastts = 0; nframes = 0; - scheduleFrame(0); + if (!pulsing) { + scheduleFrame(0); + pulsing = true; + } } } this.stop = function() { diff --git a/src/platform/vcs.ts b/src/platform/vcs.ts index 6e40cb57..9ff08b9c 100644 --- a/src/platform/vcs.ts +++ b/src/platform/vcs.ts @@ -50,7 +50,6 @@ Javatari.AUDIO_BUFFER_SIZE = 256; class VCSPlatform { recorder : EmuRecorder; - paused : boolean = true; getPresets() { return VCS_PRESETS; } @@ -64,11 +63,12 @@ class VCSPlatform { self.updateRecorder(); this.oldClockPulse(); } - this.paused = false; } loadROM(title, data) { + var wasrunning = this.isRunning(); Javatari.loadROM(title, data); + if (!wasrunning) this.pause(); } getOpcodeMetadata(opcode, offset) { @@ -86,23 +86,16 @@ class VCSPlatform { // TODO: Clock changes this on event, so it may not be current isRunning() { + //console.log(Javatari.room.console.isRunning(), Javatari.room.console.isPowerOn); return Javatari.room && Javatari.room.console.isRunning(); } pause() { - //console.log('pause', this.paused, this.isRunning()); - if (!this.paused) { - this.paused = true; - Javatari.room.console.pause(); - Javatari.room.speaker.mute(); - } + Javatari.room.console.pause(); + Javatari.room.speaker.mute(); } resume() { - //console.log('resume', this.paused, this.isRunning()); - if (this.paused) { - this.paused = false; - Javatari.room.console.go(); - Javatari.room.speaker.play(); - } + Javatari.room.console.go(); + Javatari.room.speaker.play(); } advance() { Javatari.room.console.clockPulse(); @@ -118,7 +111,8 @@ class VCSPlatform { setupDebug(callback) { Javatari.room.console.onBreakpointHit = (state) => { - this.paused = true; + Javatari.room.console.pause(); + Javatari.room.speaker.mute(); callback(state); } Javatari.room.speaker.mute(); @@ -233,7 +227,7 @@ class VCSPlatform { } updateRecorder() { // are we recording and do we need to save a frame? - if (this.recorder && !this.paused && this.isRunning() && this.recorder.frameRequested()) { + if (this.recorder && this.isRunning() && this.recorder.frameRequested()) { this.recorder.recordFrame(this.saveState()); } }