-
Notifications
You must be signed in to change notification settings - Fork 31
/
famiclone.js
85 lines (75 loc) · 2.73 KB
/
famiclone.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
vars[key] = value;
});
return vars;
}
function runMAME(cart, device) {
var wantsWASM = 'WebAssembly' in window;
var wasmjs_filename = "https://dnbwg.cdn.bcebos.com/emularity-common/emulators/jsmess/mamenes_wasm.js";
var wasm_filename = "https://dnbwg.cdn.bcebos.com/emularity-common/emulators/jsmess/mamenes_wasm.wasm"
var js_filename = "https://dnbwg.cdn.bcebos.com/emularity-common/emulators/jsmess/mamenes.js"
var emulator = new Emulator(document.querySelector("#canvas"),
postRun,
new JSMESSLoader(JSMESSLoader.driver(device),
JSMESSLoader.nativeResolution(640, 480),
JSMESSLoader.emulatorJS(wantsWASM ? wasmjs_filename : js_filename),
JSMESSLoader.emulatorWASM(wantsWASM && wasm_filename),
JSMESSLoader.mountZip("rom",
JSMESSLoader.fetchFile("Game File",
cart)),
JSMESSLoader.extraArgs(["-cart", "/emulator/rom/game.nes"])));
emulator.setScale(3).start({ waitAfterDownloading: true });
}
function postRun() {
console.log("Emulator started");
var bodyWidth = $("body").width();
if (bodyWidth < 600) {
$("#mobile-tools").show();
resizeCanvas();
}
}
function resizeCanvas() {
var bodyWidth = $("body").width();
var canvasWidth = $("#emularity-canvas").width();
var canvasHeight = $("#emularity-canvas").height();
if (bodyWidth < canvasWidth) {
//Resize canvas for mobile device
var newHeight = Math.round(canvasHeight * bodyWidth / canvasWidth);
$("#emularity-canvas").width(bodyWidth);
$("#emularity-canvas").height(newHeight);
}
}
//IE 11 string includes ployfill
if (!String.prototype.includes) {
Object.defineProperty(String.prototype, 'includes', {
value: function (search, start) {
if (typeof start !== 'number') {
start = 0
}
if (start + search.length > this.length) {
return false
} else {
return this.indexOf(search, start) !== -1
}
}
})
}
$(document).ready(function () {
var device = getUrlVars()["device"];
if (!device) {
device = "nespal"
}
var gameBaseUrl = "https://dnbwg3.cdn.bcebos.com/roms-nes-zip/"
if (device == "sb486") {
gameBaseUrl = "https://dnbwg3.cdn.bcebos.com/roms-edu-zip/"
}
var game = getUrlVars()["game"];
var cart = gameBaseUrl + game + ".zip"
if (screen.width < 600) {
sessionStorage.setItem('fallback_page', 'console_list.html');
} else {
runMAME(cart, device);
}
});