From 8e653129530ed8f8d8d73b597fa78b75d66ad17e Mon Sep 17 00:00:00 2001 From: Ethan O'Brien <77750390+ethanaobrien@users.noreply.github.com> Date: Sat, 1 Jul 2023 11:46:52 -0500 Subject: [PATCH] disk support --- src/GameManager.js | 14 ++++- src/emulator.js | 152 ++++++++++++++++++++++++++++----------------- 2 files changed, 108 insertions(+), 58 deletions(-) diff --git a/src/GameManager.js b/src/GameManager.js index 8a52832..0d59ca8 100644 --- a/src/GameManager.js +++ b/src/GameManager.js @@ -14,7 +14,10 @@ class EJS_GameManager { setVariable: this.Module.cwrap('set_variable', 'null', ['string', 'string']), setCheat: this.Module.cwrap('set_cheat', 'null', ['number', 'number', 'string']), resetCheat: this.Module.cwrap('reset_cheat', 'null', []), - toggleShader: this.Module.cwrap('shader_enable', 'null', ['number']) + toggleShader: this.Module.cwrap('shader_enable', 'null', ['number']), + getDiskCount: this.Module.cwrap('get_disk_count', 'number', []), + getCurrentDisk: this.Module.cwrap('get_current_disk', 'number', []), + setCurrentDisk: this.Module.cwrap('set_current_disk', 'null', ['number']) } this.mkdir("/home"); this.mkdir("/home/web_user"); @@ -122,6 +125,15 @@ class EJS_GameManager { toggleShader(active) { this.functions.toggleShader(active); } + getDiskCount() { + return this.functions.getDiskCount(); + } + getCurrentDisk() { + return this.functions.getCurrentDisk(); + } + setCurrentDisk(disk) { + this.functions.setCurrentDisk(disk); + } } window.EJS_GameManager = EJS_GameManager; diff --git a/src/emulator.js b/src/emulator.js index 4746c9b..11ec39b 100644 --- a/src/emulator.js +++ b/src/emulator.js @@ -15,6 +15,63 @@ class EmulatorJS { nestopia: 1, snes9x: 1 } + getCore(generic) { + const core = this.config.system; + if (generic) { + const options = { + 'fceumm': 'nes', + 'snes9x': 'snes', + 'a5200': 'atari5200', + 'gambatte': 'gb', + 'mgba': 'gba', + 'beetle_vb': 'vb', + 'mupen64plus_next': 'n64', + 'desmume2015': 'nds', + 'mame2003': 'mame2003', + 'fbalpha2012_cps1': 'arcade', + 'fbalpha2012_cps2': 'arcade', + 'mednafen_psx': 'psx', + 'mednafen_psx_hw': 'psx', + 'melonds': 'nds', + 'nestopia': 'nes', + 'opera': '3do' + } + return options[core] || core; + } + const options = { + 'nes': 'fceumm', + 'snes': 'snes9x', + 'atari5200': 'a5200', + 'gb': 'gambatte', + 'gba': 'mgba', + 'vb': 'beetle_vb', + 'n64': 'mupen64plus_next', + 'nds': 'desmume2015', + 'mame2003': 'mame2003', + 'arcade': 'fbalpha2012_cps1', // I need to find a more compatible arcade core + 'psx': 'mednafen_psx_hw', + '3do': 'opera' + } + return options[core] || core; + } + extensions = { + 'fceumm': ['fds', 'nes', 'unif', 'unf'], + 'snes9x': ['smc', 'sfc', 'swc', 'fig', 'bs', 'st'], + 'a5200': ['a52', 'bin'], + 'gambatte': ['gb', 'gbc', 'dmg'], + 'mgba': ['gb', 'gbc', 'gba'], + 'beetle_vb': ['vb', 'vboy', 'bin'], + 'mupen64plus_next': ['n64', 'v64', 'z64', 'bin', 'u1', 'ndd', 'gb'], + 'fbalpha2012_cps1': ['zip'], + 'fbalpha2012_cps2': ['zip'], + 'mame2003': ['zip'], + 'desmume2015': ['nds', 'bin'], + 'melonds': ['nds'], + 'mednafen_psx': ['cue', 'toc', 'm3u', 'ccd', 'exe', 'pbp', 'chd'], + 'mednafen_psx_hw': ['cue', 'toc', 'm3u', 'ccd', 'exe', 'pbp', 'chd'], + 'nestopia': ['fds', 'nes', 'unif', 'unf'], + 'opera': ['iso', 'bin', 'chd', 'cue'] + } createElement(type) { return document.createElement(type); } @@ -339,45 +396,6 @@ class EmulatorJS { script.src = URL.createObjectURL(new Blob([js], {type: "application/javascript"})); document.body.appendChild(script); } - getCore(generic) { - const core = this.config.system; - if (generic) { - const options = { - 'fceumm': 'nes', - 'snes9x': 'snes', - 'a5200': 'atari5200', - 'gambatte': 'gb', - 'mgba': 'gba', - 'beetle_vb': 'vb', - 'mupen64plus_next': 'n64', - 'desmume2015': 'nds', - 'mame2003': 'mame2003', - 'fbalpha2012_cps1': 'arcade', - 'fbalpha2012_cps2': 'arcade', - 'mednafen_psx': 'psx', - 'mednafen_psx_hw': 'psx', - 'melonds': 'nds', - 'nestopia': 'nes', - 'opera': '3do' - } - return options[core] || core; - } - const options = { - 'nes': 'fceumm', - 'snes': 'snes9x', - 'atari5200': 'a5200', - 'gb': 'gambatte', - 'gba': 'mgba', - 'vb': 'beetle_vb', - 'n64': 'mupen64plus_next', - 'nds': 'desmume2015', - 'mame2003': 'mame2003', - 'arcade': 'fbalpha2012_cps1', // I need to find a more compatible arcade core - 'psx': 'mednafen_psx_hw', - '3do': 'opera' - } - return options[core] || core; - } getBaseFileName() { //Only once game and core is loaded if (!this.started) return null; @@ -435,6 +453,12 @@ class EmulatorJS { this.textElem.innerText = this.localization("Download Game Data"); const gotGameData = (data) => { + if (['arcade', 'mame2003'].includes(this.getCore(true))) { + this.fileName = this.config.gameUrl.split('/').pop().split("#")[0].split("?")[0]; + FS.writeFile(this.fileName, data[k]); + this.downloadBios(); + return; + } this.checkCompression(new Uint8Array(data), this.localization("Decompress Game Data")).then((data) => { for (const k in data) { if (k === "!!notCompressedData") { @@ -446,7 +470,11 @@ class EmulatorJS { FS.mkdir(k); continue; } - this.fileName = k; + if (!this.fileName || (this.extensions[this.getCore()].includes(k.split(".").pop()) && + //always prefer m3u files for psx cores + !(this.getCore(true) === "psx" && this.fileName.split(".").pop() === "m3u"))) { + this.fileName = k; + } console.log(k); FS.writeFile(k, data[k]); } @@ -1677,8 +1705,10 @@ class EmulatorJS { this.Module.FS.writeFile("/shader/shader.glslp", window.EJS_SHADERS[value]); this.gameManager.toggleShader(1); return; + } else if (option === "disk") { + this.gameManager.setCurrentDisk(value); + return; } - //console.log(option, value); this.gameManager.setVariable(option, value); } setupSettingsMenu() { @@ -1789,26 +1819,18 @@ class EmulatorJS { nested.appendChild(menu); } - - this.gameManager.getCoreOptions().split('\n').forEach((line, index) => { - let option = line.split('; '); - let name = option[0]; - let options = option[1].split('|'), - optionName = name.split("|")[0].replace(/_/g, ' ').replace(/.+\-(.+)/, '$1'); - options.slice(1, -1); - if (options.length === 1) return; - let availableOptions = {}; - for (let i=0; i 1) ? name.split("|")[1] : options[0].replace('(Default) ', '')); - }) //addToMenu("Test", 'test', {a:1, b:2, c:3}, 2); //addToMenu("Test2", 'test_2', [4, 5, 6]); //addToMenu("Testertthgfd", 'booger', [7, 8, 9]); + if (this.gameManager.getDiskCount() > 1) { + const diskLabels = {}; + for (let i=0; i { + let option = line.split('; '); + let name = option[0]; + let options = option[1].split('|'), + optionName = name.split("|")[0].replace(/_/g, ' ').replace(/.+\-(.+)/, '$1'); + options.slice(1, -1); + if (options.length === 1) return; + let availableOptions = {}; + for (let i=0; i 1) ? name.split("|")[1] : options[0].replace('(Default) ', '')); + }) + this.settingsMenu.appendChild(nested); this.settingParent.appendChild(this.settingsMenu);