2013-07-20 14:09:10 +00:00
|
|
|
var BIOS = function() {
|
|
|
|
}
|
|
|
|
BIOS.logo = "\033[32m" +
|
|
|
|
" .__ .__ \n" +
|
|
|
|
"__ _ _|__| _____| |__ \n" +
|
|
|
|
"\\ \\/ \\/ / |/ ___/ | \\ \n" +
|
|
|
|
" \\ /| |\\___ \\| Y \\\n" +
|
|
|
|
" \\/\\_/ |__/____ >___| /\n" +
|
|
|
|
" \\/ \\/ \033[31mBIOS\033[0m\n";
|
|
|
|
BIOS.hdds;
|
|
|
|
BIOS.lastKey;
|
|
|
|
BIOS.tickid;
|
|
|
|
BIOS.state;
|
|
|
|
BIOS.bootDevice;
|
|
|
|
BIOS.init = function() {
|
|
|
|
console.log("BIOS: init");
|
|
|
|
BIOS.lastKey = 0;
|
|
|
|
console.log("BIOS: register key interrupt");
|
|
|
|
Emulator.interrupts['key'] = BIOS.key;
|
|
|
|
}
|
|
|
|
BIOS.main = function() {
|
|
|
|
console.log("BIOS: main");
|
|
|
|
console.log("BIOS: register 100ms-timer");
|
2013-07-21 08:55:31 +00:00
|
|
|
BIOS.tickid = Emulator.registerTimer(100, BIOS.tick);
|
2013-07-20 14:09:10 +00:00
|
|
|
console.log("BIOS: get hdds");
|
2013-07-21 08:55:31 +00:00
|
|
|
BIOS.hdds = Emulator.Devices.getHarddisks();
|
|
|
|
var text = BIOS.logo + "\n" +
|
2013-07-20 14:09:10 +00:00
|
|
|
"Keyboard: found at name=" + Emulator.input.name + "\n" +
|
|
|
|
"Monitor: found at id=" + Emulator.Output.screen.parentElement.id + "\n\n" +
|
|
|
|
"Harddisks: \n";
|
2013-07-21 08:55:31 +00:00
|
|
|
for (var i = 0; i < BIOS.hdds.length; i++) {
|
|
|
|
text += " " + i + ": "+ BIOS.hdds[i].name + "\n";
|
2013-07-20 14:09:10 +00:00
|
|
|
}
|
|
|
|
Emulator.output(text);
|
2013-07-21 08:55:31 +00:00
|
|
|
if (BIOS.hdds.length == 0) {
|
2013-07-20 14:09:10 +00:00
|
|
|
Emulator.output("No harddisks found. Please insert a bootable device and restart the computer..\n\n");
|
|
|
|
Emulator.output("\033[31msystem halt\033[0m");
|
|
|
|
console.log("BIOS: remove all event handlers");
|
|
|
|
Emulator.interrupts = new Array();
|
2013-07-21 08:56:44 +00:00
|
|
|
Emulator.unregisterTimer(BIOS.tickid);
|
2013-07-20 14:09:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-07-21 10:12:46 +00:00
|
|
|
if (BIOS.hdds.length > 1) {
|
2013-07-20 14:09:10 +00:00
|
|
|
Emulator.output("\nPlease select booting device by pressing the device nr. ");
|
2013-07-21 08:56:44 +00:00
|
|
|
BIOS.state = 0;
|
2013-07-20 14:09:10 +00:00
|
|
|
} else {
|
2013-07-21 08:56:44 +00:00
|
|
|
BIOS.state = 1;
|
2013-07-20 14:09:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
BIOS.key = function(keycode) {
|
|
|
|
BIOS.lastKey = keycode;
|
|
|
|
}
|
|
|
|
BIOS.tick = function() {
|
|
|
|
switch(BIOS.state) {
|
|
|
|
case 0:
|
|
|
|
if (isNumber(KeyCodes.normalKey(BIOS.lastKey))) {
|
|
|
|
if (BIOS.hdds[BIOS.bootDevice = parseInt(KeyCodes.normalKey(BIOS.lastKey))])
|
|
|
|
BIOS.state = 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
BIOS.bootDevice = 0;
|
|
|
|
BIOS.state = 2;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
Emulator.output("\n\nSearching for MBR on " + BIOS.hdds[BIOS.bootDevice].name + "...\n");
|
|
|
|
if (!(mbr = BIOS.hdds[BIOS.bootDevice].mbr)) {
|
|
|
|
console.log(mbr);
|
|
|
|
Emulator.output("No MBR found. Please insert a bootable device and restart the computer...\n\n");
|
|
|
|
Emulator.output("\033[31msystem halt\033[0m");
|
|
|
|
console.log("BIOS: remove all event handlers");
|
|
|
|
Emulator.interrupts = new Array();
|
|
|
|
Emulator.unregisterTimer(BIOS.tickid);
|
|
|
|
}
|
|
|
|
Emulator.Request.include(BIOS.hdds[BIOS.bootDevice].name + "/" + mbr + "/init.js", BIOS.load);
|
|
|
|
BIOS.state = 3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIOS.load = function() {
|
|
|
|
console.log("BIOS: stop BIOS");
|
|
|
|
console.log("BIOS: remove all event handlers");
|
|
|
|
Emulator.interrupts = new Array();
|
|
|
|
Emulator.unregisterTimer(BIOS.tickid);
|
|
|
|
console.log("BIOS: start MBR");
|
|
|
|
try {
|
|
|
|
MBR.main(BIOS.hdds[BIOS.bootDevice]);
|
|
|
|
} catch (exception) {
|
|
|
|
console.dir(exception);
|
|
|
|
Emulator.output("MBR is not bootable. Please insert a bootable device and restart the computer...\n\n");
|
|
|
|
Emulator.output("\033[31msystem halt\033[0m");
|
|
|
|
}
|
|
|
|
}
|