Skip to content

Commit

Permalink
New publicly usable interface called V86Starter, refactor browser/mai…
Browse files Browse the repository at this point in the history
…n.js using it
  • Loading branch information
copy committed Jan 9, 2015
1 parent ac7ca3c commit 1032ef3
Show file tree
Hide file tree
Showing 7 changed files with 774 additions and 497 deletions.
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ build/cpu.js: src/*.macro.js

# Used for nodejs builds and in order to profile code.
# `debug` gives identifiers a readable name, make sure it doesn't have any side effects.
CLOSURE_READABLE=--formatting PRETTY_PRINT --debug
#CLOSURE_READABLE=--formatting PRETTY_PRINT --debug
CLOSURE_READABLE=--formatting PRETTY_PRINT

CLOSURE_SOURCE_MAP=\
--source_map_format V3\
Expand All @@ -39,9 +40,9 @@ CORE_FILES=const.js io.js main.js lib.js fpu.js ide.js pci.js floppy.js memory.j
dma.js pit.js vga.js ps2.js pic.js rtc.js uart.js hpet.js acpi.js\
state.js ne2k.js virtio.js bus.js log.js
LIB_FILES=../lib/9p.js ../lib/filesystem.js ../lib/jor1k.js ../lib/marshall.js ../lib/utf8.js
BROWSER_FILES=browser/main.js browser/screen.js\
BROWSER_FILES=browser/screen.js\
browser/keyboard.js browser/mouse.js browser/serial.js\
browser/network.js browser/lib.js
browser/network.js browser/lib.js browser/starter.js

build/v86_all.js: src/*.js src/browser/*.js build/cpu.js lib/*.js
-ls -lh build/v86_all.js
Expand All @@ -57,21 +58,26 @@ build/v86_all.js: src/*.js src/browser/*.js build/cpu.js lib/*.js
--js $(CORE_FILES)\
--js $(LIB_FILES)\
--js $(BROWSER_FILES)\
--js ../build/cpu.js
--js ../build/cpu.js\
--js browser/main.js

echo "//# sourceMappingURL=v86_all.js.map" >> build/v86_all.js
ls -lh build/v86_all.js


build/libv86.js: src/*.js build/cpu.js lib/*.js
build/libv86.js: src/*.js build/cpu.js lib/*.js src/browser/*.js
cd src &&\
java -jar $(CLOSURE) \
--js_output_file "../build/libv86.js"\
--define=DEBUG=false\
--externs adapter-externs.js\
--define=IN_NODE=false\
--define=IN_BROWSER=true\
--define=IN_WORKER=false\
$(CLOSURE_FLAGS)\
$(CLOSURE_READABLE)\
--output_wrapper ';(function(){%output%})();'\
--js $(CORE_FILES)\
--js $(BROWSER_FILES)\
--js $(LIB_FILES)\
--js ../build/cpu.js

Expand Down
99 changes: 14 additions & 85 deletions docs/samples/basic.html
Original file line number Diff line number Diff line change
@@ -1,96 +1,25 @@
<!doctype html>
<title>Basic Emulator</title><!-- not BASIC! -->


<!-- defines ScreenAdapter -->
<script src="../../src/browser/screen.js"></script>

<!-- defines KeyboardAdapter -->
<script src="../../src/browser/keyboard.js"></script>

<!-- defines v86, SyncBuffer, Bus -->
<script src="../../build/libv86.js"></script>


<script>
// Load a file using XHR as an ArrayBuffer.
// If you want to use this, add some error handling
function load_file(filename, done)
{
var http = new XMLHttpRequest();

http.open("get", filename, true);
http.responseType = "arraybuffer";

http.onload = function(e) {
if(http.readyState === 4 && http.response) {
done(http.response);
}
};
http.send(null);
}

window.onload = function()
{
// For a minimal boot, we need at least 2 images: A bios and a disk image
// (CD, HD or floppy). For non-serial output, a vgabios has to be specified
var images = {};

load_file("../../bios/seabios.bin", function(buffer) {
images.seabios = buffer;
cont(images);
var emulator = new V86Starter({
memory_size: 32 * 1024 * 1024,
vga_memory_size: 2 * 1024 * 1024,
screen_container: document.getElementById("screen_container"),
bios: {
url: "../../bios/seabios.bin",
},
vga_bios: {
url: "../../bios/vgabios.bin",
},
cdrom: {
url: "../../images/linux.iso",
},
autostart: true,
});

load_file("../../bios/vgabios.bin", function(buffer) {
images.vga_bios = buffer;
cont(images);
});

load_file("../../images/linux.iso", function(buffer) {
images.cdrom = buffer;
cont(images);
});
};

function cont(images)
{
if(!images.seabios || !images.vga_bios || !images.cdrom) {
return;
}

var bus = Bus.create();

var container = document.getElementById("screen_container");
var cpu = new v86(bus[0]);

// Adapters implement the communication from or to the emulator. These
// default adapters (defined in browser/*.js) implement what you see
// on copy.sh/v86. You could change them to programatically control the emulator
var keyboard = new KeyboardAdapter(bus[1]);
var screen = new ScreenAdapter(container, bus[1]);

cpu.init({
// load_devices has to be set to true, otherwise no OS can run
load_devices: true,

// The CD image. All disk images have to be wrapped in SyncBuffer or an
// object, that exports the same interface. A few examples are available
// in browser/lib.js
cdrom: new SyncBuffer(images.cdrom),

//hda: images.hd, // a hard disk image
//fda: images.floppy, // a floppy disk image

// The bioses. If you don't need the vgabios, just leave it out.
// Only pass ArrayBuffers here
bios: images.seabios,
vga_bios: images.vga_bios,

vga_memory_size: 2 * 1024 * 1024, // default 8M
memory_size: 32 * 1024 * 1024, // default 64M
});

cpu.run();
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var CORE_FILES = "const.js io.js main.js lib.js ide.js fpu.js pci.js floppy.js " +
"memory.js dma.js pit.js vga.js ps2.js pic.js rtc.js uart.js acpi.js hpet.js " +
"ne2k.js state.js virtio.js bus.js log.js";
var BROWSER_FILES = "main.js screen.js keyboard.js mouse.js serial.js lib.js network.js";
var BROWSER_FILES = "main.js screen.js keyboard.js mouse.js serial.js lib.js network.js starter.js";
var LIB_FILES = "esprima.js walk.js";

// jor1k stuff
Expand Down
Loading

0 comments on commit 1032ef3

Please sign in to comment.