-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
223 lines (206 loc) · 9.09 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Another GameBoy Emulator written in Rust</title>
<link rel="stylesheet" href="content/style.css" />
</head>
<body>
<div class="page-container">
<div class="sidebar">
<div class="sidebar-box">
<div class="sidebar-box-header" onclick="toggleBoxContent('box-rom-select')">
Select ROM
</div>
<div id="box-rom-select" class="sidebar-box-content">
<div class="rom-select-entry first">
<h1>GB 240p</h1>
<p><a href="https://github.com/pinobatch/240p-test-mini">github.com/pinobatch/240p-test-mini</a></p>
<button onclick="playRomFromUrl('roms/gb240p.gb')">︎⏵</button>
</div>
<div class="rom-select-entry">
<h1>ACID 2 Test</h1>
<p><a href="https://github.com/mattcurrie/cgb-acid2">github.com/mattcurrie/cgb-acid2</a></p>
<button onclick="playRomFromUrl('roms/cgb-acid2.gbc')">︎⏵</button>
</div>
<div class="rom-select-entry">
<h1>Obsolete Hardware Demo</h1>
<p><a href="https://www.pouet.net/prod.php?which=54175">www.pouet.net/prod.php?which=54175</a></p>
<button onclick="playRomFromUrl('roms/oh.gb')">︎⏵</button>
</div>
<div class="rom-select-entry">
<h1>Is that a demo in your pocket?</h1>
<p><a href="https://www.pouet.net/prod.php?which=65997">www.pouet.net/prod.php?which=65997</a></p>
<button onclick="playRomFromUrl('roms/pocket.gb')">︎⏵</button>
</div>
</div>
</div>
<div class="sidebar-box">
<div class="sidebar-box-header" onclick="toggleBoxContent('box-keybindings')">
Keybindings
</div>
<div id="box-keybindings" class="sidebar-box-content">
<table class="grid keybindings">
<tbody>
<tr>
<td>➕</td>
<td>
<span class="key">w</span><br>
<span class="key">a</span>
<span class="key">s</span>
<span class="key">d</span>
</td>
<td>
<span class="key">↑</span><br>
<span class="key">←</span>
<span class="key">↓</span>
<span class="key">→</span>
</td>
</tr>
<tr>
<td>
<span class="key ab">B</span>
<span class="key ab">A</span>
</td>
<td>
<span class="key">q</span>
<span class="key">e</span>
</td>
<td>
<span class="key">y</span>
<span class="key">x</span>
</td>
</tr>
<tr>
<td><span class="key start">Select</span></td>
<td><span class="key">1</span></td>
<td><span class="key">Enter</span></td>
</tr>
<tr>
<td><span class="key start">Start</span></td>
<td><span class="key">2</span></td>
<td><span class="key">Shift</span></td>
</tr>
</tbody>
</table>
</div>
</div>
<script>
function toggleBoxContent(id) {
let element = document.getElementById(id);
if (element) {
if (element.style.maxHeight) {
element.style.maxHeight = null;
}
else {
element.style.maxHeight = '0';
}
}
}
</script>
</div>
<div class="page-content-container">
<div class="gameboy-container">
<div id="gameboy-case" class="gameboy-case">
<div class="gameboy-screen-border">
<div class="gameboy-screen-bg"></div>
<div class="gameboy-screen-container">
<canvas id="gameboy-screen" width="160" height="144">
</canvas>
</div>
<div class="menu-overlay-container">
<div id="menu-overlay-background" class="menu-overlay-background">
</div>
<div class="menu-bar-top-container">
<p id="game-title" class="game-title"></p>
</div>
<div class="menu-bar-bottom-background">
</div>
<div class="menu-bar-bottom-container">
<div class="gameboy-controls-left">
<button id="button-pause">X</button>
</div>
<div class="gameboy-controls-right">
<span>🔊</span>
<input id="volume-control" type="range" style="width: 128px;">
</div>
</div>
</div>
<div id="power-led" class="power-led-off">
</div>
</div>
</div>
</div>
</div>
</div>
<script type="module">
import { EmulatorGlue } from "./content/script.js";
let emu = new EmulatorGlue();
const SYMBOL_PLAY = "︎⏵";
const SYMBOL_PAUSE = "︎⏸";
let gb_case = document.getElementById("gameboy-case");
let canvas = document.getElementById("gameboy-screen");
let bt_pause = document.getElementById("button-pause");
let volume_ctrl = document.getElementById("volume-control");
let power_led = document.getElementById("power-led");
let overlay = document.getElementById("menu-overlay-background");
emu.registerFileDropOn(gb_case);
emu.registerClickToOpenOn(gb_case);
emu.registerCanvas(canvas);
emu.registerKeyEvents();
// handle click to pause/unpause
{
bt_pause.innerHTML = SYMBOL_PLAY;
bt_pause.addEventListener("click", (ev) => {
if (emu.isEmulatorPaused()) {
emu.setEmulatorPaused(false);
bt_pause.innerHTML = SYMBOL_PAUSE;
}
else {
emu.setEmulatorPaused(true);
bt_pause.innerHTML = SYMBOL_PLAY;
}
ev.stopPropagation();
});
}
// handle volume change
{
volume_ctrl.value = emu.getVolume();
volume_ctrl.addEventListener("click", (ev) => {
ev.stopPropagation();
})
volume_ctrl.addEventListener("input", (ev) => {
let v = volume_ctrl.value;
emu.setVolume(v);
ev.stopPropagation();
ev.preventDefault();
});
}
// double-click on the overlay background to enter fullscreen
{
overlay.addEventListener("dblclick", (_ev) => {
emu.setCanvasFullScreen(true);
});
}
// react on rom start / end
{
emu.onRomStarted = (name) => {
let game_title_field = document.getElementById("game-title");
if (game_title_field) {
game_title_field.innerText = name;
}
power_led.className = "power-led-on";
bt_pause.innerHTML = SYMBOL_PAUSE;
}
emu.onRomEnded = () => {
power_led.className = "power-led-off";
bt_pause.innerHTML = SYMBOL_PLAY;
}
}
// global function to allow to load ROMS from a URL.
window.playRomFromUrl = async function(url) {
await emu.tryLoadCartridgeFromUrl(url);
}
</script>
</body>
</html>