diff --git a/CMOS.js b/CMOS.js index 327f4ec..b4d4ba2 100644 --- a/CMOS.js +++ b/CMOS.js @@ -3,43 +3,43 @@ Fabrix - An annotated version of the original JSLinux which is Copyright (c) 201 Clock Emulator */ -function Lg(a) { return ((a / 10) << 4) | (a % 10);} -function CMOS(Ng) { - var Og, d; - Og = new Uint8Array(128); - this.cmos_data = Og; +function formatter(a) { return ((a / 10) << 4) | (a % 10);} +function CMOS(PC) { + var time_array, d; + time_array = new Uint8Array(128); + this.cmos_data = time_array; this.cmos_index = 0; d = new Date(); - Og[0] = Lg(d.getUTCSeconds()); - Og[2] = Lg(d.getUTCMinutes()); - Og[4] = Lg(d.getUTCHours()); - Og[6] = Lg(d.getUTCDay()); - Og[7] = Lg(d.getUTCDate()); - Og[8] = Lg(d.getUTCMonth() + 1); - Og[9] = Lg(d.getUTCFullYear() % 100); - Og[10] = 0x26; - Og[11] = 0x02; - Og[12] = 0x00; - Og[13] = 0x80; - Og[0x14] = 0x02; - Ng.register_ioport_write(0x70, 2, 1, this.ioport_write.bind(this)); - Ng.register_ioport_read(0x70, 2, 1, this.ioport_read.bind(this)); + time_array[0] = formatter(d.getUTCSeconds()); + time_array[2] = formatter(d.getUTCMinutes()); + time_array[4] = formatter(d.getUTCHours()); + time_array[6] = formatter(d.getUTCDay()); + time_array[7] = formatter(d.getUTCDate()); + time_array[8] = formatter(d.getUTCMonth() + 1); + time_array[9] = formatter(d.getUTCFullYear() % 100); + time_array[10] = 0x26; + time_array[11] = 0x02; + time_array[12] = 0x00; + time_array[13] = 0x80; + time_array[0x14] = 0x02; + PC.register_ioport_write(0x70, 2, 1, this.ioport_write.bind(this)); + PC.register_ioport_read(0x70, 2, 1, this.ioport_read.bind(this)); } -CMOS.prototype.ioport_write = function(mem8_loc, Ig) { +CMOS.prototype.ioport_write = function(mem8_loc, data) { if (mem8_loc == 0x70) { - this.cmos_index = Ig & 0x7f; + this.cmos_index = data & 0x7f; } }; CMOS.prototype.ioport_read = function(mem8_loc) { - var Pg; + var data; if (mem8_loc == 0x70) { return 0xff; } else { - Pg = this.cmos_data[this.cmos_index]; + data = this.cmos_data[this.cmos_index]; if (this.cmos_index == 10) this.cmos_data[10] ^= 0x80; else if (this.cmos_index == 12) this.cmos_data[12] = 0x00; - return Pg; + return data; } }; diff --git a/KBD.js b/KBD.js index 5024d62..ab263c1 100644 --- a/KBD.js +++ b/KBD.js @@ -3,10 +3,10 @@ Fabrix - An annotated version of the original JSLinux which is Copyright (c) 201 Keyboard Device Emulator */ -function KBD(Ng, ph) { - Ng.register_ioport_read(0x64, 1, 1, this.read_status.bind(this)); - Ng.register_ioport_write(0x64, 1, 1, this.write_command.bind(this)); - this.reset_request = ph; +function KBD(PC, reset_callback) { + PC.register_ioport_read(0x64, 1, 1, this.read_status.bind(this)); + PC.register_ioport_write(0x64, 1, 1, this.write_command.bind(this)); + this.reset_request = reset_callback; } KBD.prototype.read_status = function(mem8_loc) { return 0; @@ -20,3 +20,5 @@ KBD.prototype.write_command = function(mem8_loc, x) { break; } }; + + diff --git a/PCEmulator.js b/PCEmulator.js index 1e2a046..7885546 100644 --- a/PCEmulator.js +++ b/PCEmulator.js @@ -38,30 +38,32 @@ PCEmulator.prototype.load_binary = function(Gg, ha) { return this.cpu.load_binar PCEmulator.prototype.start = function() { setTimeout(this.timer_func.bind(this), 10); }; PCEmulator.prototype.timer_func = function() { - var La, vh, wh, xh, yh, Ng, cpu; - Ng = this; - cpu = Ng.cpu; - wh = cpu.cycle_count + 100000; - xh = false; - yh = false; - zh: while (cpu.cycle_count < wh) { - Ng.pit.update_irq(); - La = cpu.exec(wh - cpu.cycle_count); - if (La == 256) { - if (Ng.reset_request) { - xh = true; + var exit_status, Ncycles, do_reset, err_on_exit, PC, cpu; + PC = this; + cpu = PC.cpu; + Ncycles = cpu.cycle_count + 100000; + + do_reset = false; + err_on_exit = false; + + exec_loop: while (cpu.cycle_count < Ncycles) { + PC.pit.update_irq(); + exit_status = cpu.exec(Ncycles - cpu.cycle_count); + if (exit_status == 256) { + if (PC.reset_request) { + do_reset = true; break; } - } else if (La == 257) { - yh = true; + } else if (exit_status == 257) { + err_on_exit = true; break; } else { - xh = true; + do_reset = true; break; } } - if (!xh) { - if (yh) { + if (!do_reset) { + if (err_on_exit) { setTimeout(this.timer_func.bind(this), 10); } else { setTimeout(this.timer_func.bind(this), 0); @@ -70,121 +72,133 @@ PCEmulator.prototype.timer_func = function() { }; PCEmulator.prototype.init_ioports = function() { - var i, Ah, Bh; + var i, readw, writew; this.ioport_readb_table = new Array(); this.ioport_writeb_table = new Array(); this.ioport_readw_table = new Array(); this.ioport_writew_table = new Array(); this.ioport_readl_table = new Array(); this.ioport_writel_table = new Array(); - Ah = this.default_ioport_readw.bind(this); - Bh = this.default_ioport_writew.bind(this); + readw = this.default_ioport_readw.bind(this); + writew = this.default_ioport_writew.bind(this); for (i = 0; i < 1024; i++) { this.ioport_readb_table[i] = this.default_ioport_readb; this.ioport_writeb_table[i] = this.default_ioport_writeb; - this.ioport_readw_table[i] = Ah; - this.ioport_writew_table[i] = Bh; + this.ioport_readw_table[i] = readw; + this.ioport_writew_table[i] = writew; this.ioport_readl_table[i] = this.default_ioport_readl; this.ioport_writel_table[i] = this.default_ioport_writel; } }; -PCEmulator.prototype.default_ioport_readb = function(Zf) { +PCEmulator.prototype.default_ioport_readb = function(port_num) { var x; x = 0xff; return x; }; -PCEmulator.prototype.default_ioport_readw = function(Zf) { +PCEmulator.prototype.default_ioport_readw = function(port_num) { var x; - x = this.ioport_readb_table[Zf](Zf); - Zf = (Zf + 1) & (1024 - 1); - x |= this.ioport_readb_table[Zf](Zf) << 8; + x = this.ioport_readb_table[port_num](port_num); + port_num = (port_num + 1) & (1024 - 1); + x |= this.ioport_readb_table[port_num](port_num) << 8; return x; }; -PCEmulator.prototype.default_ioport_readl = function(Zf) { +PCEmulator.prototype.default_ioport_readl = function(port_num) { var x; x = -1; return x; }; -PCEmulator.prototype.default_ioport_writeb = function(Zf, x) {}; +PCEmulator.prototype.default_ioport_writeb = function(port_num, x) {}; -PCEmulator.prototype.default_ioport_writew = function(Zf, x) { - this.ioport_writeb_table[Zf](Zf, x & 0xff); - Zf = (Zf + 1) & (1024 - 1); - this.ioport_writeb_table[Zf](Zf, (x >> 8) & 0xff); +PCEmulator.prototype.default_ioport_writew = function(port_num, x) { + this.ioport_writeb_table[port_num](port_num, x & 0xff); + port_num = (port_num + 1) & (1024 - 1); + this.ioport_writeb_table[port_num](port_num, (x >> 8) & 0xff); }; -PCEmulator.prototype.default_ioport_writel = function(Zf, x) {}; +PCEmulator.prototype.default_ioport_writel = function(port_num, x) {}; -PCEmulator.prototype.ld8_port = function(Zf) { +PCEmulator.prototype.ld8_port = function(port_num) { var x; - x = this.ioport_readb_table[Zf & (1024 - 1)](Zf); + x = this.ioport_readb_table[port_num & (1024 - 1)](port_num); return x; }; -PCEmulator.prototype.ld16_port = function(Zf) { +PCEmulator.prototype.ld16_port = function(port_num) { var x; - x = this.ioport_readw_table[Zf & (1024 - 1)](Zf); + x = this.ioport_readw_table[port_num & (1024 - 1)](port_num); return x; }; -PCEmulator.prototype.ld32_port = function(Zf) { +PCEmulator.prototype.ld32_port = function(port_num) { var x; - x = this.ioport_readl_table[Zf & (1024 - 1)](Zf); + x = this.ioport_readl_table[port_num & (1024 - 1)](port_num); return x; }; -PCEmulator.prototype.st8_port = function(Zf, x) { this.ioport_writeb_table[Zf & (1024 - 1)](Zf, x); }; -PCEmulator.prototype.st16_port = function(Zf, x) { this.ioport_writew_table[Zf & (1024 - 1)](Zf, x); }; -PCEmulator.prototype.st32_port = function(Zf, x) { this.ioport_writel_table[Zf & (1024 - 1)](Zf, x); }; +PCEmulator.prototype.st8_port = function(port_num, x) { this.ioport_writeb_table[port_num & (1024 - 1)](port_num, x); }; +PCEmulator.prototype.st16_port = function(port_num, x) { this.ioport_writew_table[port_num & (1024 - 1)](port_num, x); }; +PCEmulator.prototype.st32_port = function(port_num, x) { this.ioport_writel_table[port_num & (1024 - 1)](port_num, x); }; -PCEmulator.prototype.register_ioport_read = function(start, tg, cc, Ch) { +PCEmulator.prototype.register_ioport_read = function(start, len, iotype, io_callback) { var i; - switch (cc) { + switch (iotype) { case 1: - for (i = start; i < start + tg; i++) { - this.ioport_readb_table[i] = Ch; + for (i = start; i < start + len; i++) { + this.ioport_readb_table[i] = io_callback; } break; case 2: - for (i = start; i < start + tg; i += 2) { - this.ioport_readw_table[i] = Ch; + for (i = start; i < start + len; i += 2) { + this.ioport_readw_table[i] = io_callback; } break; case 4: - for (i = start; i < start + tg; i += 4) { - this.ioport_readl_table[i] = Ch; + for (i = start; i < start + len; i += 4) { + this.ioport_readl_table[i] = io_callback; } break; } }; -PCEmulator.prototype.register_ioport_write = function(start, tg, cc, Ch) { +PCEmulator.prototype.register_ioport_write = function(start, len, iotype, io_callback) { var i; - switch (cc) { + switch (iotype) { case 1: - for (i = start; i < start + tg; i++) { - this.ioport_writeb_table[i] = Ch; + for (i = start; i < start + len; i++) { + this.ioport_writeb_table[i] = io_callback; } break; case 2: - for (i = start; i < start + tg; i += 2) { - this.ioport_writew_table[i] = Ch; + for (i = start; i < start + len; i += 2) { + this.ioport_writew_table[i] = io_callback; } break; case 4: - for (i = start; i < start + tg; i += 4) { - this.ioport_writel_table[i] = Ch; + for (i = start; i < start + len; i += 4) { + this.ioport_writel_table[i] = io_callback; } break; } }; -PCEmulator.prototype.ioport80_write = function(mem8_loc, Ig) {}; +PCEmulator.prototype.ioport80_write = function(mem8_loc, data) {}; PCEmulator.prototype.reset = function() { this.request_request = 1; }; + + + + + + + + + + + + diff --git a/PIC.js b/PIC.js index 3ac0c62..00e14fe 100644 --- a/PIC.js +++ b/PIC.js @@ -3,9 +3,9 @@ Fabrix - An annotated version of the original JSLinux which is Copyright (c) 201 8259 PIC (Programmable Interrupt Controller) Emulation Code */ -function PIC(Ng, Zf) { - Ng.register_ioport_write(Zf, 2, 1, this.ioport_write.bind(this)); - Ng.register_ioport_read(Zf, 2, 1, this.ioport_read.bind(this)); +function PIC(PC, port_num) { + PC.register_ioport_write(port_num, 2, 1, this.ioport_write.bind(this)); + PC.register_ioport_read(port_num, 2, 1, this.ioport_read.bind(this)); this.reset(); } PIC.prototype.reset = function() { @@ -173,10 +173,10 @@ PIC.prototype.ioport_read = function(Ug) { }; -function PIC_Controller(Ng, Wg, Ug, Xg) { +function PIC_Controller(PC, Wg, Ug, Xg) { this.pics = new Array(); - this.pics[0] = new PIC(Ng, Wg); - this.pics[1] = new PIC(Ng, Ug); + this.pics[0] = new PIC(PC, Wg); + this.pics[1] = new PIC(PC, Ug); this.pics[0].elcr_mask = 0xf8; this.pics[1].elcr_mask = 0xde; this.irq_requested = 0; @@ -226,3 +226,5 @@ PIC_Controller.prototype.get_hard_intno = function() { this.update_irq(); return intno; }; + + diff --git a/PIT.js b/PIT.js index c6c9fbd..d0d86a2 100644 --- a/PIT.js +++ b/PIT.js @@ -3,7 +3,7 @@ Fabrix - An annotated version of the original JSLinux which is Copyright (c) 201 PIT Emulator */ -function PIT(Ng, ah, bh) { +function PIT(PC, ah, bh) { var s, i; this.pit_channels = new Array(); for (i = 0; i < 3; i++) { @@ -15,10 +15,10 @@ function PIT(Ng, ah, bh) { } this.speaker_data_on = 0; this.set_irq = ah; - Ng.register_ioport_write(0x40, 4, 1, this.ioport_write.bind(this)); - Ng.register_ioport_read(0x40, 3, 1, this.ioport_read.bind(this)); - Ng.register_ioport_read(0x61, 1, 1, this.speaker_ioport_read.bind(this)); - Ng.register_ioport_write(0x61, 1, 1, this.speaker_ioport_write.bind(this)); + PC.register_ioport_write(0x40, 4, 1, this.ioport_write.bind(this)); + PC.register_ioport_read(0x40, 3, 1, this.ioport_read.bind(this)); + PC.register_ioport_read(0x61, 1, 1, this.speaker_ioport_read.bind(this)); + PC.register_ioport_write(0x61, 1, 1, this.speaker_ioport_write.bind(this)); } @@ -214,3 +214,4 @@ PIT.prototype.update_irq = function() { this.set_irq(1); this.set_irq(0); }; +