fix VCS hanging up when loading rom when paused; also fixed same bug in AnimationTimer

This commit is contained in:
Steven Hugg 2018-08-25 18:01:51 -04:00
parent 3c9560f273
commit c157f4b071
4 changed files with 24 additions and 27 deletions

View File

@ -278,17 +278,14 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
<link rel="stylesheet" href="codemirror/addon/dialog/dialog.css">
<script src="javatari.js/release/javatari/javatari.js"></script>
<!--
<script src="javatari.js/src/main/Javatari.js"></script>
<script src="javatari.js/temp/javatari.part.concat.js"></script>
-->
<script src="src/cpu/z80fast.js"></script>
<script src="jsnes/jsnes.min.js"></script>
<!--<script src="src/cpu/6809.js"></script>-->
<!--
<script src="jsnes/lib/dynamicaudio-min.js" type="text/javascript" charset="utf-8"></script>
-->
<!--
<script src="local/williams/defender.js"></script>
<script src="local/williams/robotron.js"></script>
<script src="local/atarivec/gravitar/gravitar.js"></script>
-->
<!--<script src="jsnes/lib/dynamicaudio-min.js" type="text/javascript" charset="utf-8"></script>-->
<script src="FileSaver.js/FileSaver.min.js"></script>
<script src="localForage/dist/localforage.nopromises.js"></script>

@ -1 +1 @@
Subproject commit 8f5767e4ca9a759d759e9a09677d649d58f6aff7
Subproject commit 7e246e74bd56c76acf8b7e05334f0221e1783977

View File

@ -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() {

View File

@ -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());
}
}