now that MESS and MAME are combined, combine all our code for them into just MAMELoader

This commit is contained in:
Daniel Brooks
2016-07-31 18:14:02 -07:00
parent 6af4c5b895
commit a6cf1324b2
2 changed files with 83 additions and 142 deletions
+45 -36
View File
@@ -10,12 +10,17 @@ function which returns a `Promise` of a config.
# Acquiring Emulators #
The Internet Archive is currently maintaining three sets of emulators - one for JSMESS, one for JSMAME and one for EM-DOSBOX. They can be found at:
The Internet Archive is currently maintaining two sets of emulators -
one for MAME and one for EM-DOSBOX. They can be found at:
* [Emularity Engines: Arcade (JSMAME)](https://archive.org/details/emularity_engine_jsmame)
* [Emularity Engines: Computers and Consoles (JSMESS)](https://archive.org/details/emularity_engine_jsmess)
* [Emularity Engines: Arcade (MAME)](https://archive.org/details/emularity_engine_jsmame)
* [Emularity Engines: Computers and Consoles (MAME)](https://archive.org/details/emularity_engine_jsmess)
* [Emularity Engines: MS-DOS (EM-DOSBOX)](https://archive.org/details/emularity_engine_emdosbox)
Note that MESS and MAME used to be separate, if related,
projects. They've recently been combined into a single source code
repository and prjoject structure, and Emularity has changed to match.
# Configuration #
## Examples ##
@@ -27,12 +32,12 @@ copy of the rom (which it loads from examples/1943.zip).
var emulator = new Emulator(document.querySelector("#canvas"),
null,
new JSMAMELoader(JSMAMELoader.driver("1943"),
JSMAMELoader.nativeResolution(224, 256),
JSMAMELoader.emulatorJS("emulators/mess1943.js"),
JSMAMELoader.mountFile("1943.zip",
JSMAMELoader.fetchFile("Game File",
"examples/1943.zip"))))
new MAMELoader(MAMELoader.driver("1943"),
MAMELoader.nativeResolution(224, 256),
MAMELoader.emulatorJS("emulators/mess1943.js"),
MAMELoader.mountFile("1943.zip",
MAMELoader.fetchFile("Game File",
"examples/1943.zip"))))
emulator.setScale(3);
emulator.start({ waitAfterDownloading: true });
@@ -46,16 +51,16 @@ keybindings needed to use the 2600.
var emulator = new Emulator(document.querySelector("#canvas"),
null,
new JSMESSLoader(JSMESSLoader.driver("a2600"),
JSMESSLoader.nativeResolution(352, 223),
JSMESSLoader.emulatorJS("emulators/messa2600.js"),
JSMESSLoader.mountFile("Pitfall_Activision_1982.bin",
JSMESSLoader.fetchFile("Game File",
"examples/Pitfall_Activision_1982.bin")),
JSMESSLoader.mountFile("a2600.cfg",
JSMESSLoader.fetchFile("Config File",
"examples/a2600.cfg")),
JSMESSLoader.peripheral("cart", "Pitfall_Activision_1982.bin")))
new MAMELoader(MAMELoader.driver("a2600"),
MAMELoader.nativeResolution(352, 223),
MAMELoader.emulatorJS("emulators/messa2600.js"),
MAMELoader.mountFile("Pitfall_Activision_1982.bin",
MAMELoader.fetchFile("Game File",
"examples/Pitfall_Activision_1982.bin")),
MAMELoader.mountFile("a2600.cfg",
MAMELoader.fetchFile("Config File",
"examples/a2600.cfg")),
MAMELoader.peripheral("cart", "Pitfall_Activision_1982.bin")))
emulator.setScale(3).start({ waitAfterDownloading: true });
### DOS game ###
@@ -87,38 +92,42 @@ to the era.
Each of these is configured by calling a constructor function and
providing it with arguments formed by calling static methods on that
same constructor.
same constructor. In principle this configuration is just an object
with various properties. Although the static methods are more
indirect, they are intended to allow autocompletion in IDEs to
function, and thus make writing them more convenient.
### Common ###
* `emulatorJS(url)`
* `mountZip(drive, file)`
* `mountFile(filename, file)`
* `fetchFile(url)`
* `fetchOptionalFile(url)`
* `localFile(data)`
* `BaseLoader.emulatorJS(url)`
* `BaseLoader.mountZip(drive, file)`
* `BaseLoader.mountFile(filename, file)`
* `BaseLoader.fetchFile(url)`
* `BaseLoader.fetchOptionalFile(url)`
* `BaseLoader.localFile(data)`
### MAME ###
* `MAMELoader.driver(driverName)`
* `MAMELoader.extraArgs(args)`
* `MAMELoader.peripheral(name, filename)`
### JSMESS ###
* `driver(driverName)`
* `extraArgs(args)`
* `peripheral(name, filename)`
### JSMAME ###
* `driver(driverName)`
* `extraArgs(args)`
JSMESSLoader is merely a synonym for MAMELoader, and is provided so
that we don't break existing users.
### EM-DOSBox ###
* `startExe(filename)`
* `DosBoxLoader.startExe(filename)`
## Internet Archive ##
There's also a helper for loading software from
[the Internet Archive](https://archive.org/v2), `IALoader`. IALoader
looks at the metadata associated with an Internet Archive item and
uses that to build the configuration for the emulator.
uses that to build the configuration for the emulator by calling
MAMELoader or DosBoxLoader as necessary.
## Examples ##
+38 -106
View File
@@ -113,9 +113,6 @@ var Module = null;
}
modulecfg = JSON.parse(data);
var mame = modulecfg &&
'arcade' in modulecfg &&
parseInt(modulecfg['arcade'], 10);
var get_files;
if (module && module.indexOf("dosbox") === 0) {
@@ -124,15 +121,9 @@ var Module = null;
get_files = get_dosbox_files;
}
else if (module) {
if (mame) {
emulator_logo = images.mame;
cfgr = JSMAMELoader;
get_files = get_mame_files;
} else {
emulator_logo = images.mess;
cfgr = JSMESSLoader;
get_files = get_mame_files;
}
emulator_logo = images.mame;
cfgr = MAMELoader;
get_files = get_mame_files;
}
else {
throw new Error("Unknown module type "+ module +"; cannot configure the emulator.");
@@ -223,27 +214,6 @@ var Module = null;
return files;
}
function get_mess_files(cfgr, metadata, modulecfg, filelist) {
var files = [],
bios_files = modulecfg['bios_filenames'];
bios_files.forEach(function (fname, i) {
if (fname) {
var title = "Bios File ("+ (i+1) +" of "+ bios_files.length +")";
files.push(cfgr.mountFile('/'+ fname,
cfgr.fetchFile(title,
get_bios_url(fname))));
}
});
files.push(cfgr.mountFile('/'+ get_game_name(game),
cfgr.fetchFile("Game File",
get_zip_url(game))));
files.push(cfgr.mountFile('/'+ modulecfg['driver'] + '.cfg',
cfgr.fetchOptionalFile("CFG File",
get_other_emulator_config_url(module))));
return files;
}
function get_mame_files(cfgr, metadata, modulecfg, filelist) {
var files = [],
bios_files = modulecfg['bios_filenames'];
@@ -423,54 +393,33 @@ var Module = null;
};
/**
* JSMESSLoader
* MAMELoader
*/
function JSMESSLoader() {
function MAMELoader() {
var config = Array.prototype.reduce.call(arguments, extend);
config.emulator_arguments = build_mess_arguments(config.muted, config.mess_driver,
config.emulator_arguments = build_mame_arguments(config.muted, config.mame_driver,
config.nativeResolution, config.sample_rate,
config.peripheral, config.extra_mess_args);
config.needs_jsmess_webaudio = true;
config.extra_mame_args);
config.needs_jsmame_webaudio = true;
return config;
}
JSMESSLoader.__proto__ = BaseLoader;
MAMELoader.__proto__ = BaseLoader;
JSMESSLoader.driver = function (driver) {
return { mess_driver: driver };
MAMELoader.driver = function (driver) {
return { mame_driver: driver };
};
JSMESSLoader.peripheral = function (peripheral, game) {
MAMELoader.peripheral = function (peripheral, game) {
var p = {}
p[peripheral] = [game];
return { peripheral: p };
};
JSMESSLoader.extraArgs = function (args) {
return { extra_mess_args: args };
MAMELoader.extraArgs = function (args) {
return { extra_mame_args: args };
};
/**
* JSMAMELoader
*/
function JSMAMELoader() {
var config = Array.prototype.reduce.call(arguments, extend);
config.emulator_arguments = build_mame_arguments(config.muted, config.mess_driver,
config.nativeResolution, config.sample_rate,
config.extra_mess_args);
config.needs_jsmess_webaudio = true;
return config;
}
JSMAMELoader.__proto__ = BaseLoader;
JSMAMELoader.driver = function (driver) {
return { mess_driver: driver };
};
JSMAMELoader.extraArgs = function (args) {
return { extra_mess_args: args };
};
var build_mess_arguments = function (muted, driver, native_resolution, sample_rate, peripheral, extra_args) {
var build_mame_arguments = function (muted, driver, native_resolution, sample_rate, peripheral, extra_args) {
var args = [driver,
'-verbose',
'-rompath', 'emulator',
@@ -503,30 +452,6 @@ var Module = null;
return args;
};
var build_mame_arguments = function (muted, driver, native_resolution, sample_rate, extra_args) {
var args = [driver,
'-verbose',
'-rompath', 'emulator',
'-window',
'-nokeepaspect'];
if (native_resolution && "width" in native_resolution && "height" in native_resolution) {
args.push('-resolution', [native_resolution.width, native_resolution.height].join('x'));
}
if (muted) {
args.push('-sound', 'none');
} else if (sample_rate) {
args.push('-samplerate', sample_rate);
}
if (extra_args) {
args = args.concat(extra_args);
}
return args;
};
var build_dosbox_arguments = function (emulator_start, files) {
var args = ['-conf', '/emulator/dosbox.conf'];
@@ -603,7 +528,7 @@ var Module = null;
var css_resolution, scale, aspectRatio;
// right off the bat we set the canvas's inner dimensions to
// whatever it's current css dimensions are; this isn't likely to be
// the same size that dosbox/jsmess will set it to, but it avoids
// the same size that dosbox/jsmame will set it to, but it avoids
// the case where the size was left at the default 300x150
if (!canvas.hasAttribute("width")) {
var style = getComputedStyle(canvas);
@@ -762,7 +687,7 @@ var Module = null;
})
.then(function (game_files) {
if (!game_data || splash.failed_loading) {
return;
return null;
}
if (options.waitAfterDownloading) {
return new Promise(function (resolve, reject) {
@@ -786,7 +711,7 @@ var Module = null;
})
.then(function () {
if (!game_data || splash.failed_loading) {
return;
return null;
}
splash.spinning = true;
window.removeEventListener('keypress', k);
@@ -797,8 +722,8 @@ var Module = null;
blockSomeKeys();
setupFullScreen();
disableRightClickContextMenu(canvas);
if (game_data.needs_jsmess_webaudio)
setup_jsmess_webaudio();
if (game_data.needs_jsmame_webaudio)
setup_jsmame_webaudio();
// Emscripten doesn't use the proper prefixed functions for fullscreen requests,
// so let's map the prefixed versions to the correct function.
@@ -1235,12 +1160,12 @@ var Module = null;
return Array.prototype.slice.call(xml.childNodes);
}
function setup_jsmess_webaudio() {
// jsmess web audio backend v0.3
function setup_jsmame_webaudio() {
// jsmame web audio backend v0.3
// katelyn gadd - kg at luminance dot org ; @antumbral on twitter
//taisel working on it atm
var jsmess_web_audio = (function () {
var jsmame_web_audio = (function () {
var context = null;
var gain_node = null;
@@ -1334,7 +1259,7 @@ var Module = null;
// seemingly incorrect/broken. figures. welcome to Web Audio
// var gain_web_audio = 1.0 - Math.pow(10, 10 / attenuation_in_decibels);
// HACK: Max attenuation in JSMESS appears to be 32.
// HACK: Max attenuation in MAME appears to be 32.
// Hit ' then left/right arrow to test.
// FIXME: This is linear instead of log10 scale.
var gain_web_audio = 1.0 + (+attenuation_in_decibels / +32);
@@ -1439,16 +1364,23 @@ var Module = null;
})();
window.jsmess_set_mastervolume = jsmess_web_audio.set_mastervolume;
window.jsmess_update_audio_stream = jsmess_web_audio.update_audio_stream;
window.jsmess_sample_count = jsmess_web_audio.sample_count;
window.jsmess_web_audio = jsmess_web_audio;
}
// depreciated; just for backwards compatibility
window.jsmess_set_mastervolume = jsmame_web_audio.set_mastervolume;
window.jsmess_update_audio_stream = jsmame_web_audio.update_audio_stream;
window.jsmess_sample_count = jsmame_web_audio.sample_count;
window.jsmess_web_audio = jsmame_web_audio;
window.jsmame_set_mastervolume = jsmame_web_audio.set_mastervolume;
window.jsmame_update_audio_stream = jsmame_web_audio.update_audio_stream;
window.jsmame_sample_count = jsmame_web_audio.sample_count;
window.jsmame_web_audio = jsmame_web_audio;
}
window.IALoader = IALoader;
window.DosBoxLoader = DosBoxLoader;
window.JSMESSLoader = JSMESSLoader;
window.JSMAMELoader = JSMAMELoader;
window.JSMESSLoader = MAMELoader; // depreciated; just for backwards compatibility
window.JSMAMELoader = MAMELoader; // ditto
window.MAMELoader = MAMELoader;
window.Emulator = Emulator;
})(typeof Promise === 'undefined' ? ES6Promise.Promise : Promise);