2015-01-12 06:16:01 +01:00
|
|
|
<!doctype html>
|
|
|
|
<title>Save and restore</title>
|
|
|
|
|
2015-09-12 00:35:44 +02:00
|
|
|
<script src="../build/libv86.js"></script>
|
2015-01-12 06:16:01 +01:00
|
|
|
<script>
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
window.onload = function()
|
|
|
|
{
|
|
|
|
var emulator = new V86Starter({
|
2021-01-01 02:14:30 +01:00
|
|
|
wasm_path: "../build/v86.wasm",
|
2015-01-12 06:16:01 +01:00
|
|
|
memory_size: 32 * 1024 * 1024,
|
|
|
|
vga_memory_size: 2 * 1024 * 1024,
|
|
|
|
screen_container: document.getElementById("screen_container"),
|
|
|
|
bios: {
|
2015-09-12 00:35:44 +02:00
|
|
|
url: "../bios/seabios.bin",
|
2015-01-12 06:16:01 +01:00
|
|
|
},
|
|
|
|
vga_bios: {
|
2015-09-12 00:35:44 +02:00
|
|
|
url: "../bios/vgabios.bin",
|
2015-01-12 06:16:01 +01:00
|
|
|
},
|
|
|
|
cdrom: {
|
2015-09-12 00:35:44 +02:00
|
|
|
url: "../images/linux.iso",
|
2015-01-12 06:16:01 +01:00
|
|
|
},
|
|
|
|
autostart: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
var state;
|
|
|
|
|
|
|
|
document.getElementById("save_restore").onclick = function()
|
|
|
|
{
|
|
|
|
var button = this;
|
|
|
|
|
|
|
|
if(state)
|
|
|
|
{
|
|
|
|
button.value = "Save state";
|
|
|
|
|
|
|
|
emulator.restore_state(state);
|
|
|
|
state = undefined;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
emulator.save_state(function(error, new_state)
|
|
|
|
{
|
|
|
|
if(error)
|
|
|
|
{
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
2015-01-19 21:58:58 +01:00
|
|
|
console.log("Saved state of " + new_state.byteLength + " bytes");
|
2015-01-12 06:16:01 +01:00
|
|
|
button.value = "Restore state";
|
|
|
|
state = new_state;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
button.blur();
|
|
|
|
};
|
|
|
|
|
|
|
|
document.getElementById("save_file").onclick = function()
|
|
|
|
{
|
|
|
|
emulator.save_state(function(error, new_state)
|
|
|
|
{
|
|
|
|
if(error)
|
|
|
|
{
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
var a = document.createElement("a");
|
2015-01-19 21:58:58 +01:00
|
|
|
a.download = "v86state.bin";
|
2015-01-12 06:16:01 +01:00
|
|
|
a.href = window.URL.createObjectURL(new Blob([new_state]));
|
|
|
|
a.dataset.downloadurl = "application/octet-stream:" + a.download + ":" + a.href;
|
|
|
|
a.click();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.blur();
|
|
|
|
};
|
|
|
|
|
|
|
|
document.getElementById("restore_file").onchange = function()
|
|
|
|
{
|
|
|
|
if(this.files.length)
|
|
|
|
{
|
|
|
|
var filereader = new FileReader();
|
|
|
|
emulator.stop();
|
|
|
|
|
|
|
|
filereader.onload = function(e)
|
|
|
|
{
|
|
|
|
emulator.restore_state(e.target.result);
|
|
|
|
emulator.run();
|
|
|
|
};
|
|
|
|
|
|
|
|
filereader.readAsArrayBuffer(this.files[0]);
|
|
|
|
|
|
|
|
this.value = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
this.blur();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<input id="save_restore" type="button" value="Save state">
|
|
|
|
<input id="save_file" type="button" value="Save state to file">
|
|
|
|
Restore from file: <input id="restore_file" type="file">
|
|
|
|
<hr>
|
|
|
|
|
|
|
|
<!-- A minimal structure for the ScreenAdapter defined in browser/screen.js -->
|
|
|
|
<div id="screen_container">
|
|
|
|
<div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
|
|
|
|
<canvas style="display: none"></canvas>
|
|
|
|
</div>
|