forked from taisel/IodineGBA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlauncher.js
108 lines (106 loc) · 3.29 KB
/
launcher.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"use script";
var directory = "/gamebois/roms/";
var gamename = new URLSearchParams(window.location.search).get('game');
var type = new URLSearchParams(window.location.search).get('type');
var game = String(directory) + String(gamename) + "." + String(type);
var Iodine = null;
var Blitter = null;
var Mixer = null;
var MixerInput = null;
var timerID = null;
window.onload = function () {
if (!games[location.hash.substr(1)]) {
alert("Invalid game request!");
return;
}
//Initialize Iodine:
Iodine = new GameBoyAdvanceEmulator();
//Initialize the graphics:
registerBlitterHandler();
//Initialize the audio:
registerAudioHandler();
//Register the save handler callbacks:
registerSaveHandlers();
//Hook the GUI controls.
registerGUIEvents();
//Enable Sound:
Iodine.enableAudio();
//Download the BIOS:
downloadBIOS();
}
function downloadBIOS() {
downloadFile("/IodineGBA/IodineGBA/gba_bios.bin", registerBIOS);
}
function registerBIOS() {
processDownload(this, attachBIOS);
downloadROM(game);
}
function downloadROM(gamename) {
Iodine.pause();
showTempString("Downloading \"" + games[gamename] + ".\"");
downloadFile("Binaries/" + gamename + ".gba", registerROM);
}
function registerROM() {
clearTempString();
processDownload(this, attachROM);
if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i)) {
Iodine.disableAudio();
}
Iodine.play();
}
function registerBlitterHandler() {
Blitter = new GlueCodeGfx();
Blitter.attachCanvas(document.getElementById("emulator_target"));
Blitter.setSmoothScaling(false);
Iodine.attachGraphicsFrameHandler(function (buffer) {Blitter.copyBuffer(buffer);});
}
function registerAudioHandler() {
Mixer = new GlueCodeMixer();
MixerInput = new GlueCodeMixerInput(Mixer);
Iodine.attachAudioHandler(MixerInput);
}
function registerGUIEvents() {
addEvent("keydown", document, keyDown);
addEvent("keyup", document, keyUpPreprocess);
addEvent("unload", window, ExportSave);
Iodine.attachSpeedHandler(function (speed) {
document.title = games[location.hash.substr(1)] + " - " + speed;
});
}
function lowerVolume() {
Iodine.incrementVolume(-0.04);
}
function raiseVolume() {
Iodine.incrementVolume(0.04);
}
function writeRedTemporaryText(textString) {
if (timerID) {
clearTimeout(timerID);
}
showTempString(textString);
timerID = setTimeout(clearTempString, 5000);
}
function showTempString(textString) {
document.getElementById("tempMessage").style.display = "block";
document.getElementById("tempMessage").textContent = textString;
}
function clearTempString() {
document.getElementById("tempMessage").style.display = "none";
}
//Some wrappers and extensions for non-DOM3 browsers:
function addEvent(sEvent, oElement, fListener) {
try {
oElement.addEventListener(sEvent, fListener, false);
}
catch (error) {
oElement.attachEvent("on" + sEvent, fListener); //Pity for IE.
}
}
function removeEvent(sEvent, oElement, fListener) {
try {
oElement.removeEventListener(sEvent, fListener, false);
}
catch (error) {
oElement.detachEvent("on" + sEvent, fListener); //Pity for IE.
}
}