All files / src/web run-controls.js

100% Statements 17/17
100% Branches 0/0
100% Functions 6/6
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40                        5x 5x 5x 5x 5x   5x 9x 9x 9x 9x   5x 5x         2x         2x 2x      
/**
 * The play and pause buttons on the top bar, kept in step with the loop's
 * running state. pause() and resume() are also the desktop app's menu actions.
 */
export class RunControls {
    /**
     * @param {object} options
     * @param {object} options.loop - the emulation loop
     * @param {object} options.dbgr - the debugger, hidden on resume
     * @param {object} options.keyboard - the machine keyboard, told the running state
     */
    constructor({ loop, dbgr, keyboard }) {
        this.loop = loop;
        this.dbgr = dbgr;
        this.keyboard = keyboard;
        this.playButton = document.getElementById("debug-play");
        this.pauseButton = document.getElementById("debug-pause");
 
        loop.addEventListener("running", () => {
            const running = loop.isRunning();
            keyboard.setRunning(running);
            this.playButton.disabled = running;
            this.pauseButton.disabled = !running;
        });
        this.pauseButton.addEventListener("click", () => this.pause());
        this.playButton.addEventListener("click", () => this.resume());
    }
 
    /** Stop the loop into the debugger. */
    pause() {
        this.loop.stop(true);
    }
 
    /** Hide the debugger; the keyboard's resume event restarts the loop. */
    resume() {
        this.dbgr.hide();
        this.keyboard.resumeEmulation();
    }
}