Move examples from docs/samples/ to examples/
This commit is contained in:
parent
c070e90b99
commit
b3c3d4d4a0
14
Readme.md
14
Readme.md
|
@ -13,11 +13,11 @@ Demos
|
|||
API examples
|
||||
-
|
||||
|
||||
- [Basic](docs/samples/basic.html)
|
||||
- [Programatically using the serial terminal](docs/samples/serial.html)
|
||||
- [A LUA interpreter](docs/samples/lua.html)
|
||||
- [Two instances in one window](docs/samples/two_instances.html)
|
||||
- [Saving and restoring emulator state](docs/samples/save_restore.html)
|
||||
- [Basic](examples/basic.html)
|
||||
- [Programatically using the serial terminal](examples/serial.html)
|
||||
- [A LUA interpreter](examples/lua.html)
|
||||
- [Two instances in one window](examples/two_instances.html)
|
||||
- [Saving and restoring emulator state](examples/save_restore.html)
|
||||
|
||||
Using v86 for your own purposes is as easy as:
|
||||
|
||||
|
@ -79,7 +79,7 @@ How to build, run and embed?
|
|||
locally, make sure to serve it from a local webserver. You can use `make run`
|
||||
to serve the files using Python's SimpleHTTPServer.
|
||||
- If you want only want to embed v86 on website you can use libv86.js. For
|
||||
usage, check out the [API](docs/api.md) and [examples](docs/samples/).
|
||||
usage, check out the [API](docs/api.md) and [examples](examples/).
|
||||
- A couple of disk images are provided for testing. You can check them out
|
||||
using `wget -P images/ http://copy.sh/v86/images/{linux.iso,linux3.iso,kolibri.img,windows101.img,os8.dsk,freedos722.img,openbsd.img}`.
|
||||
|
||||
|
@ -88,7 +88,7 @@ How to build, run and embed?
|
|||
|
||||
```bash
|
||||
# grab the main repo
|
||||
git clone https://github.com/copy/v86.git
|
||||
git clone https://github.com/copy/v86.git
|
||||
|
||||
cd v86
|
||||
|
||||
|
|
|
@ -52,10 +52,10 @@ Options can have the following properties (all optional, default in parenthesis)
|
|||
- `serial_container HTMLTextAreaElement` (No serial terminal) - A textarea
|
||||
that will receive and send data to the emulated serial terminal.
|
||||
Alternatively the serial terminal can also be accessed programatically,
|
||||
see [serial.html](samples/serial.html).
|
||||
see [serial.html](../examples/serial.html).
|
||||
|
||||
- `screen_container HTMLElement` (No screen) - An HTMLElement. This should
|
||||
have a certain structure, see [basic.html](samples/basic.html).
|
||||
have a certain structure, see [basic.html](../examples/basic.html).
|
||||
|
||||
***
|
||||
|
||||
|
@ -267,6 +267,6 @@ initialized.
|
|||
1. **`string`** file
|
||||
2. **`function(Object, Uint8Array)`** callback
|
||||
|
||||
<!-- src/browser/starter.js-->
|
||||
<!-- ../src/browser/starter.js-->
|
||||
|
||||
<!-- vim: set tabstop=2 shiftwidth=2 softtabstop=2: -->
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
var markdox = require("markdox");
|
||||
|
||||
var options = {
|
||||
output: __dirname + "/api.md",
|
||||
output: __dirname + "/api.md",
|
||||
template: __dirname + "/template.md.ejs"
|
||||
};
|
||||
|
||||
|
@ -12,5 +12,5 @@ var files = [
|
|||
];
|
||||
|
||||
markdox.process(files, options, function() {
|
||||
console.log("Ok.");
|
||||
console.log("Ok. %s written.", options.output);
|
||||
});
|
||||
|
|
82
examples/arch.html
Normal file
82
examples/arch.html
Normal file
|
@ -0,0 +1,82 @@
|
|||
<!doctype html>
|
||||
<title>Archlinux</title>
|
||||
|
||||
<script src="../../build/libv86.js"></script>
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
window.onload = function()
|
||||
{
|
||||
var emulator = new V86Starter({
|
||||
memory_size: 128 * 1024 * 1024,
|
||||
vga_memory_size: 8 * 1024 * 1024,
|
||||
screen_container: document.getElementById("screen_container"),
|
||||
bios: {
|
||||
url: "../../bios/seabios.bin",
|
||||
},
|
||||
vga_bios: {
|
||||
url: "../../bios/vgabios.bin",
|
||||
},
|
||||
hda: {
|
||||
url: "http://localhost/v86-images/arch3.img",
|
||||
async: true,
|
||||
size: 8 * 1024 * 1024 * 1024,
|
||||
},
|
||||
filesystem: {
|
||||
baseurl: "http://localhost/v86-images/arch/",
|
||||
basefs: "http://localhost/v86-images/fs.json",
|
||||
},
|
||||
autostart: true,
|
||||
});
|
||||
|
||||
document.getElementById("save_file").onclick = function()
|
||||
{
|
||||
emulator.save_state(function(error, new_state)
|
||||
{
|
||||
if(error)
|
||||
{
|
||||
throw error;
|
||||
}
|
||||
|
||||
var a = document.createElement("a");
|
||||
a.download = "v86state.bin";
|
||||
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_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>
|
90
examples/lang.html
Normal file
90
examples/lang.html
Normal file
|
@ -0,0 +1,90 @@
|
|||
<!doctype html>
|
||||
<title>Basic Emulator</title><!-- not BASIC! -->
|
||||
|
||||
<script src="../../build/libv86.js"></script>
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
window.onload = function()
|
||||
{
|
||||
var start = Date.now();
|
||||
|
||||
setInterval(function()
|
||||
{
|
||||
document.getElementById("time").textContent = Math.round((Date.now() - start) / 1000);
|
||||
}, 999);
|
||||
|
||||
var emulator = new V86Starter({
|
||||
memory_size: 128 * 1024 * 1024,
|
||||
vga_memory_size: 8 * 1024 * 1024,
|
||||
screen_container: document.getElementById("screen_container"),
|
||||
bios: {
|
||||
url: "../../bios/seabios.bin",
|
||||
},
|
||||
vga_bios: {
|
||||
url: "../../bios/vgabios.bin",
|
||||
},
|
||||
hda: {
|
||||
url: "http://localhost/v86-images/arch3.img",
|
||||
size: 8 * 1024 * 1024 * 1024,
|
||||
async: true,
|
||||
},
|
||||
initial_state: {
|
||||
url: "http://localhost/v86-images/v86state.bin",
|
||||
},
|
||||
filesystem: {
|
||||
baseurl: "http://localhost/v86-images/arch/",
|
||||
basefs: "http://localhost/v86-images/fs.json",
|
||||
},
|
||||
autostart: true,
|
||||
});
|
||||
|
||||
document.getElementById("status").textContent += ".";
|
||||
|
||||
emulator.add_listener("emulator-ready", function()
|
||||
{
|
||||
document.getElementById("status").textContent += ".";
|
||||
|
||||
var code = "console.log(3 * 7);\n";
|
||||
var buffer = new Uint8Array(code.length);
|
||||
|
||||
buffer.set(code.split("").map(function(chr) { return chr.charCodeAt(0); }));
|
||||
|
||||
emulator.create_file("/root/code.js", buffer, function(error)
|
||||
{
|
||||
if(error) throw error;
|
||||
|
||||
emulator.serial0_send("node /root/code.js > /root/out.txt 2> /root/out.txt\n");
|
||||
});
|
||||
});
|
||||
|
||||
var serial_out = "";
|
||||
emulator.add_listener("serial0-output-char", function(chr)
|
||||
{
|
||||
serial_out += chr;
|
||||
//document.getElementById("output").textContent += chr;
|
||||
|
||||
if(serial_out.endsWith("root@nyu"))
|
||||
{
|
||||
emulator.read_file("/root/out.txt", function(error, data)
|
||||
{
|
||||
if(error) throw error;
|
||||
|
||||
document.getElementById("output").textContent += String.fromCharCode.apply(this, data);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<pre><span id=time></span> <span id=status></span></pre>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<hr>
|
||||
|
||||
<pre id=output></pre>
|
104
examples/lang2.html
Normal file
104
examples/lang2.html
Normal file
|
@ -0,0 +1,104 @@
|
|||
<!doctype html>
|
||||
<title>Interpreter 2</title>
|
||||
|
||||
<script src="../../build/libv86.js"></script>
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
window.onload = function()
|
||||
{
|
||||
var start = Date.now();
|
||||
|
||||
document.getElementById("status").textContent = "Loading ...";
|
||||
|
||||
setInterval(function()
|
||||
{
|
||||
document.getElementById("time").textContent = Math.round((Date.now() - start) / 1000);
|
||||
}, 999);
|
||||
|
||||
if(location.host === "localhost")
|
||||
{
|
||||
var urlbase = "http://localhost/v86-images/";
|
||||
}
|
||||
else
|
||||
{
|
||||
var urlbase = "http://104.131.53.7:8086/";
|
||||
}
|
||||
|
||||
var emulator = new V86Starter({
|
||||
memory_size: 128 * 1024 * 1024,
|
||||
vga_memory_size: 8 * 1024 * 1024,
|
||||
screen_container: document.getElementById("screen_container"),
|
||||
bios: {
|
||||
url: "../../bios/seabios.bin",
|
||||
},
|
||||
vga_bios: {
|
||||
url: "../../bios/vgabios.bin",
|
||||
},
|
||||
hda: {
|
||||
url: urlbase + "arch3.img",
|
||||
size: 8 * 1024 * 1024 * 1024,
|
||||
async: true,
|
||||
},
|
||||
initial_state: {
|
||||
url: urlbase + "v86state-node.bin",
|
||||
},
|
||||
filesystem: {
|
||||
baseurl: urlbase + "arch/",
|
||||
basefs: urlbase + "fs.json",
|
||||
},
|
||||
autostart: true,
|
||||
});
|
||||
|
||||
window.emulator = emulator;
|
||||
|
||||
emulator.add_listener("emulator-ready", function()
|
||||
{
|
||||
document.getElementById("status").textContent = "Running code ...";
|
||||
var code = "var fs = require('fs');\n" +
|
||||
"module.exports = function() {\n" +
|
||||
" fs.writeFileSync('/root/out.txt', 'The result is: ' + 2 * 3 * 4 * 5 * 6 * 7 * 8);\n" +
|
||||
"}\n";
|
||||
var buffer = new Uint8Array(code.length);
|
||||
|
||||
buffer.set(code.split("").map(function(chr) { return chr.charCodeAt(0); }));
|
||||
|
||||
emulator.create_file("/root/code.js", buffer, function(error)
|
||||
{
|
||||
if(error) throw error;
|
||||
|
||||
emulator.serial0_send('require("/root/code.js")()\n\n');
|
||||
});
|
||||
});
|
||||
|
||||
var interval = setInterval(function()
|
||||
{
|
||||
emulator.read_file("/root/out.txt", function(error, data)
|
||||
{
|
||||
if(error || !data)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById("status").textContent = "Done!";
|
||||
document.getElementById("output").textContent = String.fromCharCode.apply(this, data);
|
||||
clearInterval(interval);
|
||||
});
|
||||
}, 500);
|
||||
}
|
||||
</script>
|
||||
|
||||
<pre><span id=time>0</span>s -- <span id=status></span></pre>
|
||||
<hr>
|
||||
|
||||
<pre id=output>
|
||||
|
||||
</pre>
|
||||
<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>
|
||||
|
|
@ -14,6 +14,10 @@ console.log("Use F2 to save the state and F3 to restore.");
|
|||
var bios = readfile(__dirname + "/../../bios/seabios.bin");
|
||||
var linux = readfile(__dirname + "/../../images/linux.iso");
|
||||
|
||||
process.stdin.setRawMode(true);
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding("utf8");
|
||||
|
||||
var emulator = new V86Starter({
|
||||
bios: { buffer: bios },
|
||||
cdrom: { buffer: linux },
|
||||
|
@ -22,15 +26,20 @@ var emulator = new V86Starter({
|
|||
|
||||
emulator.add_listener("serial0-output-char", function(chr)
|
||||
{
|
||||
if(!booted)
|
||||
{
|
||||
var now = Date.now();
|
||||
console.log("Took %dms to boot", now - boot_start);
|
||||
booted = true;
|
||||
}
|
||||
|
||||
process.stdout.write(chr);
|
||||
});
|
||||
|
||||
console.log("Now booting, please stand by ...");
|
||||
|
||||
process.stdin.setRawMode(true);
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding("utf8");
|
||||
|
||||
var boot_start = Date.now();
|
||||
var booted = false;
|
||||
var state;
|
||||
|
||||
process.stdin.on("data", function(c)
|
28
examples/worker.html
Normal file
28
examples/worker.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
<!doctype html>
|
||||
<title>Worker</title>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
window.onload = function()
|
||||
{
|
||||
var worker = new Worker("worker.js");
|
||||
var terminal = document.getElementById("terminal");
|
||||
|
||||
worker.onmessage = function(e)
|
||||
{
|
||||
terminal.textContent += e.data;
|
||||
}
|
||||
}
|
||||
|
||||
var start = Date.now();
|
||||
setInterval(function()
|
||||
{
|
||||
document.getElementById("time").textContent = (Date.now() - start) / 1000 | 0;
|
||||
});
|
||||
</script>
|
||||
|
||||
<span id=time></span>s
|
||||
<hr>
|
||||
<textarea readonly rows=25 cols=80 id=terminal></textarea>
|
||||
|
25
examples/worker.js
Normal file
25
examples/worker.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
importScripts("../../build/libv86.js");
|
||||
|
||||
var worker = this;
|
||||
|
||||
var emulator = new V86Starter({
|
||||
memory_size: 32 * 1024 * 1024,
|
||||
vga_memory_size: 2 * 1024 * 1024,
|
||||
bios: {
|
||||
url: "../../bios/seabios.bin",
|
||||
},
|
||||
vga_bios: {
|
||||
url: "../../bios/vgabios.bin",
|
||||
},
|
||||
cdrom: {
|
||||
url: "../../images/linux.iso",
|
||||
},
|
||||
autostart: true,
|
||||
});
|
||||
|
||||
|
||||
emulator.add_listener("serial0-output-char", function(chr)
|
||||
{
|
||||
worker.postMessage(chr);
|
||||
});
|
||||
|
|
@ -36,10 +36,10 @@
|
|||
* - `serial_container HTMLTextAreaElement` (No serial terminal) - A textarea
|
||||
* that will receive and send data to the emulated serial terminal.
|
||||
* Alternatively the serial terminal can also be accessed programatically,
|
||||
* see [serial.html](samples/serial.html).
|
||||
* see [serial.html](../examples/serial.html).
|
||||
*
|
||||
* - `screen_container HTMLElement` (No screen) - An HTMLElement. This should
|
||||
* have a certain structure, see [basic.html](samples/basic.html).
|
||||
* have a certain structure, see [basic.html](../examples/basic.html).
|
||||
*
|
||||
* ***
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue