diff --git a/src/controllers.js b/src/controllers.js index 16b715e..414b020 100644 --- a/src/controllers.js +++ b/src/controllers.js @@ -44,7 +44,7 @@ const GamepadButtons = makeEnum({ CenterCenter: 16, }); -const GamepadButtonsCount = 17; +const GamepadButtonsCount = 16; // The system/menu button is optional on standard controllers. // Gamepad API axes values. const GamepadAxes = makeEnum({ diff --git a/src/devices/sp.js b/src/devices/sp.js index 1cdfbe9..9316fa9 100644 --- a/src/devices/sp.js +++ b/src/devices/sp.js @@ -111,7 +111,6 @@ export class SPIBISTDevice extends Device { switch (ea) { case sp.SPIBIST_PC_REG: value = this.hardware.rsp.pc; - console.log(`value is ${toString32(value)}`) break; default: diff --git a/src/hle/graphics/hle_graphics.js b/src/hle/graphics/hle_graphics.js index f1efbe0..0364ac8 100644 --- a/src/hle/graphics/hle_graphics.js +++ b/src/hle/graphics/hle_graphics.js @@ -80,8 +80,8 @@ export function dispatchGraphicsTask(hardware, mode, task) { return resume; } -export function initialiseRenderer(canvas) { - debugController.initUI(); +export function initialiseRenderer(canvas, withDebugUI = true) { + if (withDebugUI) debugController.initUI(); initWebGL(canvas); // Initialize the GL context diff --git a/src/n64.js b/src/n64.js index c4b9ad0..d4cc294 100644 --- a/src/n64.js +++ b/src/n64.js @@ -23,10 +23,11 @@ import { dbgGUI } from './debug/dbg_ui.js'; window.n64js = window.n64js || {}; -const kCyclesPerUpdate = 100_000_000; +let kCyclesPerUpdate = 100_000_000; let stats = null; let running = false; +let arcadeSaveId; let animationFrame = null; const framePacer = new FramePacer(); const resetCallbacks = []; @@ -229,7 +230,7 @@ n64js.breakpoints = () => { } function getLocalStorageName(item) { - return item + '-' + rominfo.id; + return item + '-' + (arcadeSaveId || rominfo.id); } n64js.getLocalStorageItem = (name) => { @@ -353,3 +354,25 @@ n64js.togglePerformance = () => { parent.appendChild(stats.dom); } }; + +// Compact player adapter for the arcade. The debugger UI belongs to the upstream app. +n64js.initArcade = (canvas, reportError, saveId) => { + arcadeSaveId = saveId; + // Bound a slow cartridge or firmware startup to one video refresh per browser turn. + kCyclesPerUpdate = 2_000_000; + ui.setRunning = () => {}; + ui.displayError = reportError; + dbg = { active: false, redraw() {}, hide() {} }; + n64js.reset(); + initialiseRenderer(canvas, false); + for (const gamepad of navigator.getGamepads?.() || []) { + if (gamepad) controllers.connectGamepad({ gamepad }); + } +}; +n64js.arcadeKey = (key, pressed) => controllers.handleKey(0, key, pressed); +n64js.arcadePollControllers = poll => { controllers.updateInput = poll; }; +n64js.stopArcade = () => { + setRunning(false); + breakAllExecution(); + return hardware.aiRegDevice.audioContext.close(); +};