move bus handling around a bit, preparing for web workers
This commit is contained in:
parent
3a68ddfe3b
commit
139cb41488
|
@ -460,6 +460,7 @@
|
|||
emulator.restore_state(buffer);
|
||||
}
|
||||
|
||||
//emulator.send("cpu-run");
|
||||
emulator.run();
|
||||
|
||||
if(query_args["c"])
|
||||
|
@ -489,29 +490,6 @@
|
|||
|
||||
$("restore_state").onchange = function()
|
||||
{
|
||||
var file = $("restore_state").files[0];
|
||||
|
||||
if(!file)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var emulator = new v86();
|
||||
var fr = new FileReader();
|
||||
|
||||
fr.onload = function(e)
|
||||
{
|
||||
start_emulation({
|
||||
settings: settings,
|
||||
done: function(emulator)
|
||||
{
|
||||
emulator.restore_state(e.target.result);
|
||||
emulator.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fr.readAsArrayBuffer(file);
|
||||
};
|
||||
|
||||
$("start_test").onclick = function()
|
||||
|
@ -585,7 +563,13 @@
|
|||
var settings = result.settings;
|
||||
dbg_assert(settings.bios && settings.vga_bios);
|
||||
|
||||
var emulator = new v86();
|
||||
//var worker = new Worker("src/browser/worker.js");
|
||||
//var adapter_bus = WorkerBus.init(worker);
|
||||
var bus = Bus.create();
|
||||
var adapter_bus = bus[0];
|
||||
var device_bus = bus[1];
|
||||
|
||||
var emulator = new v86(device_bus);
|
||||
|
||||
if(DEBUG)
|
||||
{
|
||||
|
@ -634,9 +618,38 @@
|
|||
}
|
||||
|
||||
init_ui(settings, emulator);
|
||||
emulator.init(settings);
|
||||
|
||||
if(settings.mouse_adapter)
|
||||
{
|
||||
settings.mouse_adapter.register(adapter_bus);
|
||||
}
|
||||
if(settings.keyboard_adapter)
|
||||
{
|
||||
settings.keyboard_adapter.register(adapter_bus);
|
||||
}
|
||||
if(settings.serial_adapter)
|
||||
{
|
||||
settings.serial_adapter.register(adapter_bus);
|
||||
}
|
||||
if(settings.screen_adapter)
|
||||
{
|
||||
settings.screen_adapter.register(adapter_bus);
|
||||
}
|
||||
if(settings.network_adapter)
|
||||
{
|
||||
settings.network_adapter.register(adapter_bus);
|
||||
}
|
||||
|
||||
result.done(emulator);
|
||||
emulator.init(settings);
|
||||
|
||||
//settings.fs9p = undefined;
|
||||
//settings.fda = undefined;
|
||||
//adapter_bus.send("cpu-init", settings);
|
||||
|
||||
//setTimeout(function()
|
||||
//{
|
||||
result.done(emulator);
|
||||
//}, 100);
|
||||
});
|
||||
|
||||
function init_ui(settings, emulator)
|
||||
|
|
|
@ -17,7 +17,7 @@ function SerialAdapter(element)
|
|||
|
||||
bus.register("serial0-output", function(chr)
|
||||
{
|
||||
this.put_chr(chr);
|
||||
this.show_char(chr);
|
||||
}, this);
|
||||
|
||||
element.addEventListener("keypress", keypress_handler, false);
|
||||
|
@ -32,7 +32,7 @@ function SerialAdapter(element)
|
|||
element.removeEventListener("paste", paste_handler, false);
|
||||
};
|
||||
|
||||
this.put_chr = function(chr)
|
||||
this.show_char = function(chr)
|
||||
{
|
||||
if(chr === "\x08")
|
||||
{
|
||||
|
@ -52,7 +52,18 @@ function SerialAdapter(element)
|
|||
element.scrollTop = 1e9;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} chr_code
|
||||
*/
|
||||
this.send_char = function(chr_code)
|
||||
{
|
||||
if(serial.bus)
|
||||
{
|
||||
serial.bus.send("serial0-input", chr_code);
|
||||
}
|
||||
};
|
||||
|
||||
function may_handle(e)
|
||||
{
|
||||
|
@ -79,22 +90,18 @@ function SerialAdapter(element)
|
|||
|
||||
var chr = e.keyCode;
|
||||
|
||||
serial.bus.send("serial0-input", chr);
|
||||
serial.send_char(chr);
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
function keydown_handler(e)
|
||||
{
|
||||
if(!serial.bus)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var chr = e.keyCode;
|
||||
|
||||
if(chr === 8)
|
||||
{
|
||||
// supress backspace
|
||||
serial.bus.send("serial0-input", 127);
|
||||
serial.send_char(127);
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
@ -102,16 +109,11 @@ function SerialAdapter(element)
|
|||
function paste_handler(e)
|
||||
{
|
||||
//console.log(e.clipboardData.getData('text/plain'));
|
||||
if(!serial.bus)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var data = e.clipboardData.getData('text/plain');
|
||||
|
||||
for(var i = 0; i < data.length; i++)
|
||||
{
|
||||
serial.bus.send("serial0-input", data.charCodeAt(i));
|
||||
serial.send_char(data.charCodeAt(i));
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
|
|
|
@ -416,7 +416,7 @@ CPU.prototype.reset = function()
|
|||
this.reg16[reg_sp] = 0x100;
|
||||
};
|
||||
|
||||
CPU.prototype.init = function(settings)
|
||||
CPU.prototype.init = function(settings, device_bus)
|
||||
{
|
||||
this.memory_size = settings.memory_size || 1024 * 1024 * 64;
|
||||
this.memory = new Memory(this.memory_size);
|
||||
|
@ -465,10 +465,6 @@ CPU.prototype.init = function(settings)
|
|||
// TODO: Make this more configurable
|
||||
if(settings.load_devices)
|
||||
{
|
||||
var bus = Bus.create();
|
||||
var device_bus = bus[0];
|
||||
var adapter_bus = bus[1];
|
||||
|
||||
this.devices.pic = new PIC(this);
|
||||
|
||||
this.devices.pci = new PCI(this);
|
||||
|
@ -480,28 +476,15 @@ CPU.prototype.init = function(settings)
|
|||
this.devices.hpet = new HPET(this);
|
||||
}
|
||||
|
||||
if(settings.screen_adapter)
|
||||
{
|
||||
settings.screen_adapter.register(adapter_bus);
|
||||
}
|
||||
this.devices.vga = new VGAScreen(this, device_bus,
|
||||
settings.vga_memory_size || 8 * 1024 * 1024);
|
||||
|
||||
this.fpu = new FPU(this);
|
||||
|
||||
if(settings.mouse_adapter)
|
||||
{
|
||||
settings.mouse_adapter.register(adapter_bus);
|
||||
}
|
||||
if(settings.keyboard_adapter)
|
||||
{
|
||||
settings.keyboard_adapter.register(adapter_bus);
|
||||
}
|
||||
this.devices.ps2 = new PS2(this, device_bus);
|
||||
|
||||
if(settings.serial_adapter)
|
||||
{
|
||||
settings.serial_adapter.register(adapter_bus);
|
||||
this.devices.uart = new UART(this, 0x3F8, device_bus);
|
||||
}
|
||||
else
|
||||
|
@ -537,7 +520,6 @@ CPU.prototype.init = function(settings)
|
|||
|
||||
if(settings.network_adapter)
|
||||
{
|
||||
settings.network_adapter.register(adapter_bus);
|
||||
this.devices.net = new Ne2k(this, device_bus);
|
||||
}
|
||||
|
||||
|
|
10
src/main.js
10
src/main.js
|
@ -15,9 +15,8 @@ if(IN_BROWSER + IN_NODE + IN_WORKER !== 1)
|
|||
throw "Invalid environment";
|
||||
}
|
||||
|
||||
|
||||
/** @constructor */
|
||||
function v86()
|
||||
function v86(bus)
|
||||
{
|
||||
/** @type {boolean} */
|
||||
this.first_init = true;
|
||||
|
@ -31,6 +30,11 @@ function v86()
|
|||
/** @type {CPU} */
|
||||
this.cpu = new CPU();
|
||||
|
||||
this.bus = bus;
|
||||
bus.register("cpu-init", this.init, this);
|
||||
bus.register("cpu-run", this.run, this);
|
||||
bus.register("cpu-stop", this.stop, this);
|
||||
|
||||
this.next_tick = function() {};
|
||||
}
|
||||
|
||||
|
@ -78,7 +82,7 @@ v86.prototype.init = function(settings)
|
|||
this.lazy_init();
|
||||
}
|
||||
|
||||
this.cpu.init(settings);
|
||||
this.cpu.init(settings, this.bus);
|
||||
};
|
||||
|
||||
// initialization that only needs to be once
|
||||
|
|
Loading…
Reference in a new issue