-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
438 lines (410 loc) · 18 KB
/
index.html
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
<head>
<link type="text/css" rel="stylesheet" href="./node_modules/material-design-icons/iconfont/material-icons.css" />
<link type="text/css" rel="stylesheet" href="./node_modules/materialize-css/dist/css/materialize.min.css" media="screen,projection"/>
<style>
#GameBoy, #SLBtn {
width: 80%;
margin-left: 10%;
margin-right: 10%;
margin-top: 60px;
}
#gfx {
position: relative;
height: 0;
width: 100%;
padding-top: 90%;
}
#mainCanvas {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
body {
font-family: "Arial","Microsoft YaHei","黑体","宋体",sans-serif;
display: flex;
min-height: 100vh;
flex-direction: column;
}
main {
flex: 1 0 auto;
}
.rom-title {
font-size: 20px !important;
margin-left: 10px;
}
</style>
<script src="./js/embed.js"></script>
<script src="gbo/other/windowStack.js"></script>
<script src="gbo/other/terminal.js"></script>
<script src="gbo/other/gui.js"></script>
<script src="gbo/other/base64.js"></script>
<script src="gbo/other/json2.js"></script>
<script src="gbo/other/swfobject.js"></script>
<script src="gbo/other/resampler.js"></script>
<script src="gbo/other/XAudioServer.js"></script>
<script src="gbo/other/resize.js"></script>
<script src="gbo/GameBoyCore.js"></script>
<script src="gbo/GameBoyIO.js"></script>
<script src="./node_modules/moment/min/moment.min.js"></script>
<script>
var DEBUG_MESSAGES = false
var DEBUG_WINDOWING = false
window.onload = () => {
windowingInitialize()
//gbc_load_url("./roms/demo.gbc")
}
</script>
<title>xGBCX</title>
</head>
<body>
<header>
<nav class="cyan z-depth-3">
<div class="nav-wrapper">
<span class="brand-logo rom-title left" title="任天堂天下第一!">xGBCX</span>
<ul id="nav-btns" class="right">
<li><a href="#" id="openBtn" title="载入 ROM 文件"><i class="material-icons">input</i></a></li>
<li><a href="#" id="settingsBtn" title="设置"><i class="material-icons">settings</i></a></li>
</ul>
</div>
</nav>
</header>
<main>
<div class="container">
<div id="GameBoy" class="window">
<div id="gfx">
<canvas id="mainCanvas" class="z-depth-5"/>
<span id="title">GameBoy</span>
<span id="port_title">Online</span>
</div>
</div>
<div id="SLBtn" class="row">
<a class="waves-effect waves-light btn sl-btn left col s3 cyan disabled" id="saveBtn"><i class="material-icons left">save</i>存档</a>
<a class="waves-effect waves-light btn sl-btn right col s3 cyan disabled" id="loadBtn"><i class="material-icons left">cloud_download</i>读档</a>
</div>
<div style="display: none;">
<div id="terminal" class="window">
<div id="terminal_output"/>
<div class="button_rack">
<button id="terminal_clear_button" class="left">Clear Messages</button>
<button id="terminal_close_button" class="right">Close Terminal</button>
</div>
</div>
<div id="about" class="window">
<div id="about_message">
<h1>GameBoy Online</h1>
<p>This is a GameBoy Color emulator written purely in JavaScript by Grant Galitz.</p><p>The graphics blitting is done through HTML5 canvas, with the putImageData and drawImage functions.</p><p>Save states are implemented through the window.localStorage object, and are serialized/deserialized through JSON. SRAM saving is also implemented through the window.localStorage object, and are serialized/deserialized through JSON. In order for save states to work properly on most browsers, you need set the maximum size limit for DOM storage higher, to meet the needs of the emulator's save data size.</p><p>For more information about this emulator and its source code, visit the GIT repository at: <a href="https://github.com/taisel/GameBoy-Online" target="_blank">https://github.com/taisel/GameBoy-Online</a>.
</p>
</div>
<div class="button_rack">
<button id="about_close_button" class="center">Close Popup</button>
</div>
</div>
<div class="window" id="settings">
<div id="toggle_settings">
<div class="setting">
<span>Enable Sound:</span>
<input type="checkbox" checked="checked" id="enable_sound"/>
</div>
<div class="setting">
<span>GB mode has priority over GBC mode:</span>
<input type="checkbox" id="disable_colors"/>
</div>
<div class="setting">
<span>Use the BIOS ROM:</span>
<input type="checkbox" checked="checked" id="enable_gbc_bios"/>
</div>
<div class="setting">
<span>Override ROM only cartridge typing to MBC1:</span>
<input type="checkbox" checked="checked" id="rom_only_override"/>
</div>
<div class="setting">
<span>Always allow reading and writing to the MBC banks:</span>
<input type="checkbox" checked="checked" id="mbc_enable_override"/>
</div>
<div class="setting">
<span>Colorize Classic GameBoy Palettes:</span>
<input type="checkbox" checked="checked" id="enable_colorization"/>
</div>
<div class="setting">
<span>Minimal view on fullscreen:</span>
<input type="checkbox" checked="checked" id="do_minimal"/>
</div>
<div class="setting">
<span>Resize canvas directly in JavaScript:</span>
<input type="checkbox" id="software_resizing"/>
</div>
<div class="setting">
<span>Disallow typed arrays to be used:</span>
<input type="checkbox" id="typed_arrays_disallow"/>
</div>
<div class="setting">
<span>Use the DMG boot ROM instead of CGB:</span>
<input type="checkbox" id="gb_boot_rom_utilized"/>
</div>
<div class="setting">
<span>Smooth upon resizing canvas:</span>
<input type="checkbox" checked="checked" id="resize_smoothing"/>
</div>
<div class="setting">
<span>Enable Channel 1 Audio:</span>
<input type="checkbox" checked="checked" id="channel1"/>
</div>
<div class="setting">
<span>Enable Channel 2 Audio:</span>
<input type="checkbox" checked="checked" id="channel2"/>
</div>
<div class="setting">
<span>Enable Channel 3 Audio:</span>
<input type="checkbox" checked="checked" id="channel3"/>
</div>
<div class="setting">
<span>Enable Channel 4 Audio:</span>
<input type="checkbox" checked="checked" id="channel4"/>
</div>
</div>
<div class="button_rack">
<button id="settings_close_button" class="center">Close Settings</button>
</div>
</div>
<div id="instructions" class="window">
<div id="keycodes">
<h1>Keyboard Controls:</h1>
<ul>
<li>X/J are A.</li>
<li>Z/Y/Q are B.</li>
<li>Shift is Select.</li>
<li>Enter is Start.</li>
<li>The d-pad is the control pad.</li>
<li>The escape key (esc) allows you to get in and out of fullscreen mode.</li>
</ul>
</div>
<div class="button_rack">
<button id="instructions_close_button" class="center">Close Instructions</button>
</div>
</div>
<div id="input_select" class="window">
<form>
<input type="file" id="local_file_open"/>
</form>
<div class="button_rack">
<button id="input_select_close_button" class="center">Close File Input</button>
</div>
</div>
<div id="save_importer" class="window">
<form>
<input type="file" id="save_open"/>
</form>
<div class="button_rack">
<button id="save_importer_close_button" class="center">Close Save Importer</button>
</div>
</div>
<div class="window" id="local_storage_listing">
<div id="storageListingMasterContainer" class="storageList">
<div id="storageListingMasterContainerSub"/>
</div>
<div id="download_all_storage">
<a href="about:blank" id="download_local_storage_dba">Export all saved data.</a>
</div>
<div class="button_rack">
<button id="local_storage_list_refresh_button" class="left">Refresh List</button>
<button id="local_storage_list_close_button" class="right">Close Storage List</button>
</div>
</div>
<div class="window" id="local_storage_popup">
<div id="storagePopupMasterParent" class="storageList">
<div id="storagePopupMasterContainer"/>
</div>
<div class="button_rack">
<button id="local_storage_popup_close_button" class="center">Close Storage Popup</button>
</div>
</div>
<div class="window" id="freeze_listing">
<div id="freezeListingMasterContainer" class="storageList">
<div id="freezeListingMasterContainerSub"/>
</div>
<div class="button_rack">
<button id="freeze_list_refresh_button" class="left">Refresh List</button>
<button id="freeze_list_close_button" class="right">Close Freeze State List</button>
</div>
</div>
<ul class="menu" id="GameBoy_file_popup">
<li>Open As<ul class="menu">
<li id="data_uri_clicker">Base 64 Encoding</li>
<li id="internal_file_clicker">Local File</li>
</ul></li>
<li id="save_SRAM_state_clicker">Save Game Memory</li>
<li id="save_state_clicker">Save Freeze State</li>
<li id="set_volume">Set Volume</li>
<li id="set_speed">Set Speed</li>
<li id="restart_cpu_clicker">Restart</li>
<li id="run_cpu_clicker">Resume</li>
<li id="kill_cpu_clicker">Pause</li>
</ul>
<ul class="menu" id="GameBoy_view_popup">
<li id="view_terminal">Terminal</li>
<li id="view_instructions">Instructions</li>
<li id="view_importer">Save Importer</li>
<li id="local_storage_list_menu">Save Manager</li>
<li id="freeze_list_menu">Freeze State Manager</li>
<li id="view_fullscreen">Fullscreen Mode</li>
</ul>
<div id="fullscreenContainer">
<canvas id="fullscreen" class="maximum"/>
</div>
</div>
</div>
</main>
<footer class="page-footer transparent">
<div class="footer-copyright transparent">
<div class="container center"><a href="#" class="grey-text" style="text-decoration: underline;" id="about" onclick="openAbout()">关于</a></div>
</div>
</footer>
<script>
const { ipcRenderer } = require('electron')
var gRom
var gSettings
var gpID
var scanner
var captureInProgress = false
ipcRenderer.on("loadSettings", (event, settings) => {
gSettings = settings
})
document.getElementById("openBtn").onclick = () => {
ipcRenderer.send("openROM")
}
ipcRenderer.on("romSelected", (event, rom) => {
gRom = rom
document.getElementsByClassName("rom-title")[0].innerHTML = gRom.title
Array.from(document.getElementsByClassName("sl-btn")).forEach(e => {
e.classList.remove("disabled")
})
gbc_load_url(gRom.url)
})
window.addEventListener("keydown", e => {
Object.keys(gSettings.keymap.game).forEach(k => {
if (e.key === gSettings.keymap.game[k]) {
GameBoyKeyDown(k)
}
})
}, true)
window.addEventListener("keyup", e => {
if (Object.values(gSettings.keymap.system).includes(e.key)) {
if (e.key === gSettings.keymap.system["save"]) {
onSaveState()
}
else if (e.key === gSettings.keymap.system["load"]) {
ipcRenderer.send("listSaves", gRom)
}
else if (e.key === gSettings.keymap.system["capture"]) {
let image = document.getElementById("mainCanvas").toDataURL("image/jpeg", 0.8)
ipcRenderer.send("saveCapture", image)
}
}
Object.keys(gSettings.keymap.game).forEach(k => {
if (e.key === gSettings.keymap.game[k]) {
GameBoyKeyUp(k)
}
})
}, true)
function onSaveState () {
let data = gameboy.saveState()
let image = document.getElementById("mainCanvas").toDataURL("image/jpeg", 0.8)
let state = {
data: data,
image: image,
md5: gRom.md5,
time: moment().format("YYYY-MM-DD HH_mm_ss")
}
ipcRenderer.send("saveState", state)
}
document.getElementById("saveBtn").onclick = onSaveState
ipcRenderer.on("stateSaved", () => {
M.toast({html: "已保存"})
})
document.getElementById("loadBtn").onclick = () => {
ipcRenderer.send("listSaves", gRom)
}
ipcRenderer.on("loadState", (event, dataURL) => {
gbc_load_state(dataURL)
})
function openAbout () {
ipcRenderer.send("openAbout")
}
document.getElementById("settingsBtn").onclick = () => {
ipcRenderer.send("openSettings")
}
ipcRenderer.on("settingsChanged", (event, settings) => {
gSettings = settings
})
document.ondragover = document.ondrop = (event) => {
event.preventDefault()
}
document.body.ondrop = (event) => {
event.preventDefault()
ipcRenderer.send("romDropped", event.dataTransfer.files[0].path)
}
window.addEventListener("gamepadconnected", e => {
if (e.gamepad.id.includes("Vendor: 057e Product: 2009")) {
M.toast({html: "Pro 手柄已连接"})
gpID = e.gamepad.index
}
scanner = setInterval(proControllerScan, 33)
})
window.addEventListener("gamepaddisconnected", e => {
if (e.gamepad.id.includes("Vendor: 057e Product: 2009")) {
M.toast({html: "Pro 手柄已断开"})
gpID = null
}
clearInterval(scanner)
})
function proControllerScan() {
let gamepad = navigator.getGamepads()[gpID]
let keymap = {
game: {
"a": 1,
"b": 0,
"select": 6,
"start": 7
},
system: {
"save": 8,
"load": 9,
"capture": 13
}
}
for (var k in keymap.game) {
var btn = gamepad.buttons[keymap.game[k]]
if (btn.pressed) {
GameBoyKeyDown(k)
} else {
GameBoyKeyUp(k)
}
}
let deg = (gamepad.axes[9] + 1) * 157.5
axesDegree2Buttons(deg)
if (gamepad.buttons[keymap.system["save"]].pressed) {
onSaveState()
}
if (gamepad.buttons[keymap.system["load"]].pressed) {
ipcRenderer.send("listSaves", gRom)
}
if (gamepad.buttons[keymap.system["capture"]].pressed) {
if (!captureInProgress) {
captureInProgress = true
let image = document.getElementById("mainCanvas").toDataURL("image/jpeg", 0.8)
ipcRenderer.send("saveCapture", image)
}
}
}
ipcRenderer.on("captureSavedOrCancelled", event => {
captureInProgress = false
})
</script>
<script type="text/javascript" src="./node_modules/materialize-css/dist/js/materialize.min.js"></script>
</body>
</html>