-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchip8.html
37 lines (31 loc) · 943 Bytes
/
chip8.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
<!DOCTYPE html>
<script src="wasm_exec.js"></script>
<script>
const go = new Go()
// "exports"
function resetChip8() {}
function pause() {}
function resume() {}
function loadWasm() {
return WebAssembly.instantiateStreaming(fetch("chip8.wasm"), go.importObject).then(result => {
go.run(result.instance);
});
}
function loadRom(id) {
pause();
let oReq = new XMLHttpRequest()
oReq.open("GET", "/roms/games/Space%20Invaders%20%5BDavid%20Winter%5D.ch8", true)
oReq.responseType = "arraybuffer"
oReq.onload = function (oEvent) {
const arrayBuffer = oReq.response
if (arrayBuffer) {
const byteArray = new Uint8Array(arrayBuffer)
resetChip8(byteArray)
}
resume();
}
oReq.send(null)
}
loadWasm()
.then(() => { loadRom(1) })
</script>