-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (58 loc) · 1.44 KB
/
index.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
(() => {
const roms = [
'15PUZZLE',
'BLITZ',
'CONNECT4',
'HIDDEN',
'INVADERS',
'MAZE',
'MISSILE',
'PONG2',
'SYZYGY',
'TETRIS',
'UFO',
'VERS',
'BLINKY',
'BRIX',
'GUESS',
'IBM',
'KALEID',
'MERLIN',
'PONG',
'PUZZLE',
'TANK',
'TICTAC',
'VBRIX',
'WIPEOFF',
]
const romLoader = (name) => {
return fetch(`roms/${name}`)
.then((response) => response.arrayBuffer())
.then((buffer) => new Uint8Array(buffer))
}
const initRoms = (runner) => {
const romSelector = document.getElementById('romSelector')
roms.forEach((rom) => {
const option = document.createElement('option')
option.value = rom
option.innerHTML = rom
romSelector.appendChild(option)
})
romSelector.addEventListener('change', (event) => {
if (event.target.value === '') {
return
}
romSelector.blur()
romLoader(event.target.value)
.then((rom) => runner.load(rom))
.then(() => runner.start())
})
}
const runner = new chip8.Runner({
chip8: chip8.Chip8,
screen: chip8.Screen,
input: chip8.Input,
speaker: chip8.Speaker,
})
initRoms(runner)
})()