forked from JohnEarnest/Octo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
standalone.html
38 lines (37 loc) · 1.43 KB
/
standalone.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
<body><canvas id='target' width=512 height=256></canvas></body>
<style>body{margin:0px;display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;}</style>
<script>
const emulator = new Emulator()
unpackOptions(emulator, data.options)
setRenderTarget(data.options.displayScale || 4, 'target')
emulator.init({rom:data.rom})
emulator.importFlags = _ => getPref('octoFlagRegisters')
emulator.exportFlags = f => setPref('octoFlagRegisters',f)
emulator.buzzTrigger = (ticks,rest)=> playPattern(ticks, emulator.pattern, rest)
const kd = e=>{
if (!audio) audioSetup()
if (!(e.key in emulator.keys)) emulator.keys[e.key]=true
e.preventDefault()
}
const ku = e=>{
if (e.key in emulator.keys) delete emulator.keys[e.key]
if (!emulator.waiting) return
const kindex = keymapInverse[e.key]
if (kindex != undefined) {
emulator.waiting = false
emulator.v[emulator.waitReg] = kindex
}
e.preventDefault()
}
window.addEventListener('keydown',kd,false)
window.addEventListener('keyup',ku,false)
intervalHandle = setInterval(_=>{
if (emulator.halted) return
for(var z = 0; (z<emulator.tickrate) && (!emulator.waiting); z++) emulator.tick()
if (emulator.dt > 0) emulator.dt--
if (emulator.st > 0) emulator.st--
renderDisplay(emulator)
document.body.style.backgroundColor = emulator.st?emulator.buzzColor:emulator.quietColor
}, 1000/60)
injectAdaptiveControls(emulator.touchInputMode,document.getElementById('target'),ku,kd)
</script>