forked from srojam/gba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIodineGBACoreGlueCode.js
214 lines (214 loc) · 7.86 KB
/
IodineGBACoreGlueCode.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
"use strict";
/*
* This file is part of IodineGBA
*
* Copyright (C) 2012-2013 Grant Galitz
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
* The full license is available at http://www.gnu.org/licenses/gpl.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
var games = {
"advancewars":"Advance Wars",
"advancewars2":"Advance Wars 2",
"aladdin":"Aladdin",
"alienhominid":"Alien Hominid",
"bomberman_max2blue":"Bomberman Max 2 - Blue Advance",
"bomberman_tournament":"Bomberman Tournament",
"bubblebobble":"Bubble Bobble",
"croket1":"Croket! - Yume no Banker Survival!",
"croket2":"Croket! 2 - Yami no Bank to Banqueen",
"croket3":"Croket! 3 - Granu Oukoku no Nazo",
"croket4":"Croket! 4 - Bank no Mori no Mamorigami",
"digimon_racing":"Digimon Racing",
"dbz_supersonic":"Dragon Ball Z - Supersonic Warriors",
"drilldozer":"Drill Dozer",
"earthwormjim":"Earthworm Jim",
"earthwormjim2":"Earthworm Jim 2",
"ff1and2":"Final Fantasy 1 & 2 Advance",
"ff4S":"Final Fantasy IV Advance (Sound Restoration Mod)",
"ff6":"Final Fantasy VI Advance",
"final_fantasy_tactics":"Final Fantasy Tactics Advance",
"fire_emblem":"Fire Emblem",
"frogger1":"Frogger Advance - The Great Quest",
"frogger2":"Frogger's Adventures - Temple of the Frog",
"frogger3":"Frogger's Adventures 2 - The Lost Wand",
"fzero_gp":"F-Zero - GP Legend",
"fzero_max":"F-Zero - Maximum Velocity",
"gamewatch4":"Game & Watch Gallery 4",
"goldensun":"Golden Sun",
"gunstar_super_heroes":"Gunstar Super Heroes",
"hamtaro_heartbreak":"Hamtaro - Ham-Ham Heartbreak",
"kirbymirror":"Kirby & The Amazing Mirror",
"kirbynightmare":"Kirby: Nightmare in Dreamland",
"mariokart":"Mario Kart: Super Circuit",
"marioparty":"Mario Party Advance",
"mariopinball":"Mario Pinball Land",
"megamanbass":"Megaman & Bass",
"megaman_battle1":"Megaman Battle Network 1",
"megaman_battle2":"Megaman Battle Network 2",
"megaman_battle3_blue":"Megaman Battle Network 3 Blue",
"megaman_battle4_blue":"Megaman Battle Network 4 Blue Moon",
"megaman_battle4_red":"Megaman Battle Network 4 Red Sun",
"megaman_battle5":"Megaman Battle Network 5 Team Protoman",
"megaman_battle6":"Megaman Battle Network 6 Cybeast Falzar",
"megaman_zero1":"Megaman Zero",
"megaman_zero2":"Megaman Zero 2",
"megaman_zero3":"Megaman Zero 3",
"megaman_zero4":"Megaman Zero 4",
"metalslug":"Metal Slug Advance",
"metroid_fusion":"Metroid Fusion",
"momotarou_dentetsu":"Momotarou Dentetsu G Gold Deck wo Tsukure!",
"monopoly":"Monopoly",
"monster_force":"Monster Force",
"mortal_kombat":"Mortal Kombat Advance",
"pacman_world":"Pacman World",
"pacman_world2":"Pacman World 2",
"pokemonflorasky":"Pokemon Flora Sky Rom Hack",
"pokemonemerald":"Pokemon Emerald",
"pokemongreen":"Pokemon Leaf Green",
"mysteryred":"Pokemon Mystery Dungeon Red",
"pokemonruby":"Pokemon Ruby",
"pokemonsapphire":"Pokemon Sapphire",
"pokemonred":"Pokemon Fire Red",
"gba_video_pokemon_1":"Pokemon Video Pak 1",
"gba_video_pokemon_2":"Pokemon Video Pak 2",
"gba_video_pokemon_3":"Pokemon Video Pak 3",
"gba_video_pokemon_4":"Pokemon Video Pak 4",
"sonic_advance":"Sonic Advance",
"sonic_advance2":"Sonic Advance 2",
"sonic_advance3":"Sonic Advance 3",
"sonicbattle":"Sonic Battle",
"supermonkeyballjr":"Super Monkey Ball Jr",
"superstar":"Mario & Luigi: Superstar Saga",
"supermarioadvance":"Super Mario Advance",
"supermarioadvance2":"Super Mario Advance 2",
"supermarioadvance3":"Super Mario Advance 3",
"supermarioadvance4":"Super Mario Advance 4",
"simpsons":"The Simpsons: Road Rage",
"sonicpinball":"Sonic Pinball",
"super_street_fighter_2_turbo_revival":"Super Street Fighter II: Turbo Revival",
"super_street_fighter_3_alpha":"Super Street Fighter III: Alpha",
"tales_of_phantasia":"Tales of Phantasia",
"tak2_staff_of_dreams":"Tak 2: The Staff of Dreams",
"tetris_worlds":"Tetris Worlds",
"tmnt":"Teenage Mutant Ninja Turtles",
"sims_bustin_out":"The Sims: Bustin' Out",
"sims2":"The Sims 2",
"spyro_adventure":"Spyro Adventure",
"spyro_ice":"Spyro: Season of Ice",
"spyro_flame":"Spyro 2: Season of Flame",
"turok_evolution":"Turok Evolution",
"warioland4":"Wario Land 4",
"wario_ware":"Wario Ware Inc",
"zelda_past":"The Legend of Zelda: A Link to the Past",
"zelda_minish":"The Legend of Zelda: The Minish Cap"
};
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("Binaries/gba_bios.bin", registerBIOS);
}
function registerBIOS() {
processDownload(this, attachBIOS);
downloadROM(location.hash.substr(1));
}
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.
}
}