2018-08-23 07:03:28 +02:00
|
|
|
const BUTTONS = document.querySelector('#buttons')
|
|
|
|
|
|
|
|
let cursorCaptured = false;
|
2018-08-23 04:51:31 +02:00
|
|
|
|
|
|
|
const OPTIONS = {
|
|
|
|
win95: {
|
|
|
|
hda: {
|
|
|
|
url: './images/windows95.img',
|
|
|
|
async: true,
|
|
|
|
size: 242049024,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-23 07:03:28 +02:00
|
|
|
async function main(id) {
|
2018-08-23 04:51:31 +02:00
|
|
|
const opts = Object.assign({
|
|
|
|
memory_size: 64 * 1024 * 1024,
|
|
|
|
screen_container: document.getElementById('emulator'),
|
|
|
|
bios: {
|
|
|
|
url: './bios/seabios.bin',
|
|
|
|
},
|
|
|
|
vga_bios: {
|
|
|
|
url: './bios/vgabios.bin',
|
2018-08-23 07:03:28 +02:00
|
|
|
}
|
2018-08-23 04:51:31 +02:00
|
|
|
}, OPTIONS[id])
|
|
|
|
|
2018-08-23 07:03:28 +02:00
|
|
|
// New v86 instance
|
2018-08-23 04:51:31 +02:00
|
|
|
window.emulator = new V86Starter(opts)
|
2018-08-23 07:03:28 +02:00
|
|
|
|
|
|
|
// Restore state. We can't do this right away.
|
|
|
|
setTimeout(async () => {
|
|
|
|
await windows95.restoreState()
|
|
|
|
|
|
|
|
cursorCaptured = true
|
|
|
|
window.emulator.lock_mouse()
|
|
|
|
window.emulator.run()
|
|
|
|
}, 500)
|
2018-08-23 04:51:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setupButtons() {
|
2018-08-23 07:14:50 +02:00
|
|
|
document.querySelectorAll('.btn-start').forEach((btn) => {
|
2018-08-23 04:51:31 +02:00
|
|
|
btn.addEventListener('click', () => {
|
2018-08-23 07:03:28 +02:00
|
|
|
BUTTONS.remove()
|
2018-08-23 04:51:31 +02:00
|
|
|
document.body.className = '';
|
|
|
|
main(btn.id)
|
|
|
|
})
|
|
|
|
})
|
2018-08-23 07:03:28 +02:00
|
|
|
|
|
|
|
document.querySelector('#reset').addEventListener('click', () => {
|
2018-08-23 07:14:50 +02:00
|
|
|
if (window.emulator.stop) {
|
2018-08-23 07:03:28 +02:00
|
|
|
window.emulator.stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
windows95.resetState()
|
2018-08-23 07:14:50 +02:00
|
|
|
|
|
|
|
if (window.emulator.run) {
|
2018-08-23 07:03:28 +02:00
|
|
|
window.emulator.run()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupEscListener() {
|
|
|
|
document.onkeydown = function(evt) {
|
|
|
|
evt = evt || window.event;
|
|
|
|
if (evt.keyCode == 27) {
|
|
|
|
if (cursorCaptured) {
|
|
|
|
cursorCaptured = false
|
|
|
|
document.exitPointerLock()
|
|
|
|
} else {
|
|
|
|
cursorCaptured = true
|
|
|
|
window.emulator.lock_mouse()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupCloseListener() {
|
|
|
|
let isQuitting = false
|
|
|
|
|
|
|
|
const handleClose = async () => {
|
|
|
|
await windows95.saveState()
|
|
|
|
isQuitting = true
|
|
|
|
windows95.quit()
|
|
|
|
}
|
|
|
|
|
|
|
|
window.onbeforeunload = (event) => {
|
|
|
|
if (isQuitting) return
|
|
|
|
|
|
|
|
handleClose()
|
|
|
|
event.preventDefault()
|
|
|
|
event.returnValue = false
|
|
|
|
}
|
2018-08-23 04:51:31 +02:00
|
|
|
}
|
|
|
|
|
2018-08-23 07:03:28 +02:00
|
|
|
setupEscListener()
|
|
|
|
setupCloseListener()
|
2018-08-23 04:51:31 +02:00
|
|
|
setupButtons()
|