-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
408 lines (317 loc) · 11.6 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
<!DOCTYPE html>
<html>
<head>
<title>Pollen Boy</title>
<meta charset='UTF-8'>
<link rel='stylesheet' href='css/index.css'>
<link rel='shortcut icon' href='img/favicon.png' type='image/png'>
</head>
<body>
<!-- Title -->
<div class='titlewrap'>
<p class='title'>Pollen Boy</p>
<p class='description'>A Gameboy Emulator made in JavaScript</p>
</div>
<div class='gbgap'></div>
<div class='outerwrap'>
<div class='mama'>
<!----- GameBoy div ----->
<div class='spread'>
<div class='gbwrap'>
<div class='gbtop'>
<div class='screenwrap'>
<div class='screencontainer'>
<canvas id='nanacanvas' class='screen' width='160' height='144'></canvas>
<span id='nanastat' class='status_text'></span>
</div>
<div class='center_flex_div'>
<img src='img/gb_logo.png' class='gb_logo' draggable='false'>
</div>
</div>
</div>
<div class='gbgap'></div>
<div class='gbbottom'>
<!-- File input -->
<input id='nanafin' type='file' accept='.gb, .gbc, .bin, .rom' class='hide'>
<label for='nanafin' class='filebutton' style='width:200px;'>Choose ROM</label>
<br>
<label id='nanapause' class='roundbutton'></label>
<label id='nanareset' class='roundbutton'></label>
<!--Step Button
<label id='nanapause' class='filebutton'>Step</label> -->
</div>
</div>
</div>
<!----- Settings div ----->
<div class='spread'>
<div class='setwrap'>
<p class='title' style='font-size: 24px'>Settings</p>
<p class='subtit'>Save files</p>
<div>
<label id='nanaexportsave' class='smallbutton'>Export</label>
<input id='nanaimportsave' type='file' accept='.sav' class='hide'>
<label for='nanaimportsave' class='smallbutton'>Import</label>
</div>
<br>
<details class='title' style='font-size: 16px'>
<summary style='user-select: none' onclick='this.blur()'>More settings:</summary>
<p class='subtit'>Color palletes</p>
<div>
<form>
<label for='palletelist' class='smalltxt'>Pick a pallete !</label>
<select name='palletelist' id='nanapallete'>
</select>
</form>
<br>
<label id='nanacustompallete' class='smallbutton'>Custom</label>
</div>
<p class='subtit'>Sound stuff</p>
<div>
<span class='smalltxt'>Volume: </span><br>
<input id='nanavolume' class='range' type='range' max='0.5' min='0' step='0.025'>
<br>
<span class='smalltxt'>Pitch Shift: </span><br>
<input id='nanapitchshift' class='range' type='range' max='800' min='-800' step='50'>
</div>
</details>
</div>
</div>
</div>
<!----- Scripts ----->
<script src='src/cpu.js'></script>
<script src='src/ops.js'></script>
<script src='src/mem.js'></script>
<script src='src/ppu.js'></script>
<script src='src/apu.js'></script>
<script src='src/joypad.js'></script>
<script src='src/main.js'></script>
<!---- Front-script ----->
<script src='filesaver.js'></script>
<script>
//window.onload = function () {
const nanaCanvas = document.getElementById ('nanacanvas');
const nanaStat = document.getElementById ('nanastat');
const nanaFin = document.getElementById ('nanafin');
const nanaPause = document.getElementById ('nanapause');
const nanaReset = document.getElementById ('nanareset');
const nanaExportSave = document.getElementById ('nanaexportsave');
const nanaImportSave = document.getElementById ('nanaimportsave');
const nanaPallete = document.getElementById ('nanapallete');
const nanaCustomPallete = document.getElementById ('nanacustompallete');
const nanaVolume = document.getElementById ('nanavolume');
const nanaPitchShift = document.getElementById ('nanapitchshift');
function SetButtonImg (button, img) {
button.style.backgroundImage = 'url(' + img.src + ')';
}
// Gameboy
const gb = new Gameboy ();
gb.AttachCanvas (nanaCanvas);
function Start () {
gb.Start ();
SetButtonImg (nanaPause, images.pause);
}
// Palletes
const palletes = {
// I made these but mfs dont like em ... (rightfully so)
'mono': ['ffffff', 'bbbbbb', '666666', '000000'],
'grey': ['A5A5A5', '7F7F7F', '4C4C4C', '333333'],
'leafy': ['47E09B', '1CCE31', '559984', '20705E'],
'crimson': ['E04545', 'B71745', '771100', '3D0E24'],
'wocky slush': ['75BC64', '639E64', '42603F', '21382A'],
'pastel': ['FFA8DC', 'FF60AA', 'CC53AB', 'A0468E'],
// Other ppl's palletes !
'juice': ['dec69c', 'a55aff', '942994', '003973'], // w.atwiki.jp/yychr
'choco': ['ffe4c2', 'dca456', 'a9604c', '422936'], // lospec.com/palette-list/gb-chocolate
'kirby': ['f7bef7', 'e78686', '7733e7', '2c2c96'], // lospec.com/palette-list/kirby-sgb
'sheep': ['f9fbf3', 'e4c179', 'bc7967', '292039'], // lospec.com/palette-list/sheepsheep
'yoshi': ['e2f3e4', '94e344', '46878f', '332c50'], // lospec.com/palette-list/kirokaze-gameboy
'mist': ['c4f0c2', '5ab9a8', '1e606e', '2d1b00'], // lospec.com/palette-list/mist-gb
'starbug': ['8be5ff', '608fcf', '7550e8', '622e4c'], // lospec.com/palette-list/wish-gb
'moonlight': ['5fc75d', '36868f', '203671', '0f052d'], // lospec.com/palette-list/moonlight-gb
'manga': ['ffffff', '4aedff', 'ff8acd', 'b03e80'], // lospec.com/palette-list/mangavania
'cream': ['fff6d3', 'f9a875', 'eb6b6f', '7c3f58'], // lospec.com/palette-list/ice-cream-gb
// My sister made these :3
'mono piink': ['FFFFFF', 'FFD1E6', 'CD9BBB', '603651'],
'strawberry kisses': ['FFF1C9', 'FFC4E9', 'FF6B90', 'A3427B'],
'cotton candy': ['FFC4E9', 'B2E5FF', 'A35984', '2779A5'],
'eeeye candyyy': ['FFD191', '9ACC99', 'FF7270', '2779A5'],
'candy cane': ['FFFFFF', '40DB1A', 'FF4C4C', 'D81717']
};
// Default pallete
const defaultPallete = 'kirby';
// Fill in the pallete list in DOM
{
var keys = Object.keys (palletes);
for (var i = 0; i < keys.length; i++) {
var name = keys [i];
var option = document.createElement ('option');
// Option properties
option.value = name;
option.innerHTML = name;
nanaPallete.appendChild (option);
// Default selection
if (name !== defaultPallete)
continue;
nanaPallete.childNodes [i + 1].selected = true;
}
nanaPallete.onchange = function () {
gb.SetPallete (palletes [nanaPallete.value]);
this.blur (); // It aint annoying now uwu
};
};
// Custom pallete
nanacustompallete.onclick = function () {
gb.SetPallete([
prompt('Input color 0 (white) example: \'ff0069\':'),
prompt('Input color 1 (lite grey):'),
prompt('Input color 2 (dark grey):'),
prompt('Input color 3 (black):')
]);
};
// Default settings
gb.SetFPS (60); // 120 is performant but 60 is smoother
gb.bootromEnabled = false;
gb.SetPallete (palletes [defaultPallete]);
const defaultVolume = 0.05;
gb.SetVolume (defaultVolume);
gb.EnableSound ();
gb.DisableAlphaBlend ();
gb.SetAlphaBlend (0.7);
gb.keyboardEnabled = true;
// Images
const images = {};
images.play = new Image ();
images.play.src = 'img/button_play.png';
images.pause = new Image ();
images.pause.src = 'img/button_pause.png';
images.reset = new Image ();
images.reset.src = 'img/button_reset.png';
// Status text
var statTimeout = null;
const statFadeMs = 1300;
const longStatFadeMs = 1800;
function SetStatMsg (msg, fade=statFadeMs) {
nanaStat.innerHTML = msg;
clearTimeout (statTimeout);
statTimeout = setTimeout (ClearStatMsg, fade);
}
function ClearStatMsg () {
nanaStat.innerHTML = '';
}
// Sound sliders
nanaVolume.value = defaultVolume;
nanaVolume.oninput = function () {
this.blur();
if (this.value == 0)
gb.DisableSound();
else if (!gb.soundenabled)
gb.EnableSound();
gb.SetVolume(parseFloat(this.value));
};
nanaPitchShift.oninput = function () {
this.blur();
gb.SetPitchShift(parseFloat(this.value));
};
// Pause / play button
SetButtonImg (nanaPause, images.pause); // Default
nanaPause.onclick = function () {
if (!gb.cpu.hasRom)
return;
try {
var paused = gb.TogglePause ();
if (paused) {
SetButtonImg (this, images.play);
SetStatMsg ('paused !');
}
else {
SetButtonImg (this, images.pause);
SetStatMsg ('');
}
}
catch (e) {
SetStatMsg (e, longStatFadeMs);
}
};
// Reset button
SetButtonImg (nanaReset, images.reset);
nanaReset.onclick = function () {
if (!confirm ('are you sure you wanna reset ?'))
return;
if (gb.cpu.crashed) {
SetButtonImg (nanaPause, images.play);
}
gb.Reset ();
SetStatMsg ('reset !');
// This helps with crashes
};
// Save importing
function ReadSaveFile (file) {
var fr = new FileReader ();
fr.onload = function () {
var data = new Uint8Array (fr.result);
try {
gb.InsertSram (data); // This may throw an error
Start ();
SetStatMsg ('save loaded :)');
}
catch (e) {
SetStatMsg (e, longStatFadeMs);
}
};
fr.readAsArrayBuffer (file);
};
nanaImportSave.onchange = function (e) {
var file = e.target.files [0];
if (!file)
return;
ReadSaveFile (file);
};
// Save exporting
nanaExportSave.onclick = function () {
try {
var data = gb.GetSramArray ();
// Save to user drive
var blob = new Blob ([new Uint8Array (data)], {type: 'application/octet-stream'});
saveAs (blob, lastreadFilename + '.sav');
}
catch (e) {
SetStatMsg (e, longStatFadeMs);
}
};
// Rom file input
var lastreadFilename = 'rom';
function ReadRomFile (file) {
var fr = new FileReader ();
fr.onload = function () {
var rom = new Uint8Array (fr.result);
//try {
gb.InsertRom (rom); // This may throw an error
Start ();
//}
//catch (e) {
// SetStatMsg (e, longStatFadeMs);
//}
};
fr.readAsArrayBuffer (file);
}
nanaFin.onchange = function (e) {
var file = e.target.files [0];
if (!file)
return;
lastreadFilename = file.name.split ('.') [0]; // Remove file extension
ReadRomFile (file);
};
//};
</script>
</div>
<!-- Footer -->
<div class='gbgap'></div>
<div class='footwrap'>
<p class='foottitle'>nectarboy | 2020 - 2021</p> <!-- • a spare bullet point for u -->
<!-- Credits -->
<a href='https://github.com/nectarboy/gameboy' class='hidehref'><p class='footsrc'>Source</p></a>
<!-- Font: https://www.fontspace.com/super-legend-boy-font-f34010 -->
</div>
<br>
</body>
</html>