Fix play/pause

This commit is contained in:
Will Scullin 2019-12-27 18:14:33 -08:00
parent 2c2a1832da
commit deec11a2a3
No known key found for this signature in database
GPG Key ID: 9092A5C0A673416B
2 changed files with 16 additions and 5 deletions

View File

@ -22,6 +22,7 @@ export function Apple2(options) {
var trace = [];
var runTimer = null;
var runAnimationFrame = null;
var cpu = new CPU6502({ '65C02': options.enhanced });
var gr = new LoresPage(1, options.characterRom, options.e, options.screen[0]);
@ -60,9 +61,15 @@ export function Apple2(options) {
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame;
var _cancelAnimationFrame =
window.cancelAnimationFrame ||
window.mozCancelAnimationFrame ||
window.webkitCancelAnimationFrame ||
window.msCancelAnimationFrame;
function run() {
if (runTimer) {
clearInterval(runTimer);
if (runTimer || runAnimationFrame) {
return; // already running
}
var interval = 30;
@ -109,7 +116,7 @@ export function Apple2(options) {
options.tick();
if (!paused && _requestAnimationFrame) {
_requestAnimationFrame(runFn);
runAnimationFrame = _requestAnimationFrame(runFn);
}
};
if (_requestAnimationFrame) {
@ -123,7 +130,11 @@ export function Apple2(options) {
if (runTimer) {
clearInterval(runTimer);
}
if (runAnimationFrame) {
_cancelAnimationFrame(runAnimationFrame);
}
runTimer = null;
runAnimationFrame = null;
}
function saveState() {

View File

@ -651,11 +651,11 @@ var paused = false;
export function pauseRun() {
var label = document.querySelector('#pause-run i');
if (paused) {
cpu.run();
_apple2.run();
label.classList.remove('fa-play');
label.classList.add('fa-pause');
} else {
cpu.stop();
_apple2.stop();
label.classList.remove('fa-pause');
label.classList.add('fa-play');
}