-
Notifications
You must be signed in to change notification settings - Fork 55
/
standalone.html
52 lines (52 loc) · 2 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<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)
try { localStorage.getItem('octoFlagRegisters') }
catch(e) {
console.warn("Persistent flag register storage is unavailable! Flag registers will not be saved across sessions.")
emulator.importFlags = _ => emulator.flags
emulator.exportFlags = f => emulator.flags = f
}
emulator.buzzTrigger = (ticks,rest)=> playPattern(ticks, emulator.pattern, rest)
const kd = e=>{
if (!audio) audioSetup(emulator)
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)
const frameTime=1000/60
let last=Date.now(), origin=last+frameTime/2
intervalHandle=setInterval(_=>{
last+=(Date.now()-last)
if (emulator.halted) return
for(var k=0; origin<last-frameTime&&k<2; origin+=frameTime,k++){
for(var z=0;(z<emulator.tickrate) && (!emulator.waiting); z++){
if (emulator.vBlankQuirks &&((emulator.m[emulator.pc] & 0xF0)==0xD0)) z=emulator.tickrate
emulator.tick()
}
if (emulator.dt > 0) emulator.dt--
if (emulator.st > 0) emulator.st--
XOAudio && XOAudio.refresh(frameTime/1000)
}
renderDisplay(emulator)
document.body.style.backgroundColor = emulator.st?emulator.buzzColor:emulator.quietColor
}, frameTime)
injectAdaptiveControls(emulator.touchInputMode,document.getElementById('target'),ku,kd)
</script>