deobfuscated other devices a little bit
This commit is contained in:
parent
1bb2a03991
commit
a91f68e0e9
48
CMOS.js
48
CMOS.js
|
@ -3,43 +3,43 @@ Fabrix - An annotated version of the original JSLinux which is Copyright (c) 201
|
||||||
|
|
||||||
Clock Emulator
|
Clock Emulator
|
||||||
*/
|
*/
|
||||||
function Lg(a) { return ((a / 10) << 4) | (a % 10);}
|
function formatter(a) { return ((a / 10) << 4) | (a % 10);}
|
||||||
function CMOS(Ng) {
|
function CMOS(PC) {
|
||||||
var Og, d;
|
var time_array, d;
|
||||||
Og = new Uint8Array(128);
|
time_array = new Uint8Array(128);
|
||||||
this.cmos_data = Og;
|
this.cmos_data = time_array;
|
||||||
this.cmos_index = 0;
|
this.cmos_index = 0;
|
||||||
d = new Date();
|
d = new Date();
|
||||||
Og[0] = Lg(d.getUTCSeconds());
|
time_array[0] = formatter(d.getUTCSeconds());
|
||||||
Og[2] = Lg(d.getUTCMinutes());
|
time_array[2] = formatter(d.getUTCMinutes());
|
||||||
Og[4] = Lg(d.getUTCHours());
|
time_array[4] = formatter(d.getUTCHours());
|
||||||
Og[6] = Lg(d.getUTCDay());
|
time_array[6] = formatter(d.getUTCDay());
|
||||||
Og[7] = Lg(d.getUTCDate());
|
time_array[7] = formatter(d.getUTCDate());
|
||||||
Og[8] = Lg(d.getUTCMonth() + 1);
|
time_array[8] = formatter(d.getUTCMonth() + 1);
|
||||||
Og[9] = Lg(d.getUTCFullYear() % 100);
|
time_array[9] = formatter(d.getUTCFullYear() % 100);
|
||||||
Og[10] = 0x26;
|
time_array[10] = 0x26;
|
||||||
Og[11] = 0x02;
|
time_array[11] = 0x02;
|
||||||
Og[12] = 0x00;
|
time_array[12] = 0x00;
|
||||||
Og[13] = 0x80;
|
time_array[13] = 0x80;
|
||||||
Og[0x14] = 0x02;
|
time_array[0x14] = 0x02;
|
||||||
Ng.register_ioport_write(0x70, 2, 1, this.ioport_write.bind(this));
|
PC.register_ioport_write(0x70, 2, 1, this.ioport_write.bind(this));
|
||||||
Ng.register_ioport_read(0x70, 2, 1, this.ioport_read.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) {
|
if (mem8_loc == 0x70) {
|
||||||
this.cmos_index = Ig & 0x7f;
|
this.cmos_index = data & 0x7f;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
CMOS.prototype.ioport_read = function(mem8_loc) {
|
CMOS.prototype.ioport_read = function(mem8_loc) {
|
||||||
var Pg;
|
var data;
|
||||||
if (mem8_loc == 0x70) {
|
if (mem8_loc == 0x70) {
|
||||||
return 0xff;
|
return 0xff;
|
||||||
} else {
|
} else {
|
||||||
Pg = this.cmos_data[this.cmos_index];
|
data = this.cmos_data[this.cmos_index];
|
||||||
if (this.cmos_index == 10)
|
if (this.cmos_index == 10)
|
||||||
this.cmos_data[10] ^= 0x80;
|
this.cmos_data[10] ^= 0x80;
|
||||||
else if (this.cmos_index == 12)
|
else if (this.cmos_index == 12)
|
||||||
this.cmos_data[12] = 0x00;
|
this.cmos_data[12] = 0x00;
|
||||||
return Pg;
|
return data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
10
KBD.js
10
KBD.js
|
@ -3,10 +3,10 @@ Fabrix - An annotated version of the original JSLinux which is Copyright (c) 201
|
||||||
|
|
||||||
Keyboard Device Emulator
|
Keyboard Device Emulator
|
||||||
*/
|
*/
|
||||||
function KBD(Ng, ph) {
|
function KBD(PC, reset_callback) {
|
||||||
Ng.register_ioport_read(0x64, 1, 1, this.read_status.bind(this));
|
PC.register_ioport_read(0x64, 1, 1, this.read_status.bind(this));
|
||||||
Ng.register_ioport_write(0x64, 1, 1, this.write_command.bind(this));
|
PC.register_ioport_write(0x64, 1, 1, this.write_command.bind(this));
|
||||||
this.reset_request = ph;
|
this.reset_request = reset_callback;
|
||||||
}
|
}
|
||||||
KBD.prototype.read_status = function(mem8_loc) {
|
KBD.prototype.read_status = function(mem8_loc) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -20,3 +20,5 @@ KBD.prototype.write_command = function(mem8_loc, x) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
134
PCEmulator.js
134
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.start = function() { setTimeout(this.timer_func.bind(this), 10); };
|
||||||
|
|
||||||
PCEmulator.prototype.timer_func = function() {
|
PCEmulator.prototype.timer_func = function() {
|
||||||
var La, vh, wh, xh, yh, Ng, cpu;
|
var exit_status, Ncycles, do_reset, err_on_exit, PC, cpu;
|
||||||
Ng = this;
|
PC = this;
|
||||||
cpu = Ng.cpu;
|
cpu = PC.cpu;
|
||||||
wh = cpu.cycle_count + 100000;
|
Ncycles = cpu.cycle_count + 100000;
|
||||||
xh = false;
|
|
||||||
yh = false;
|
do_reset = false;
|
||||||
zh: while (cpu.cycle_count < wh) {
|
err_on_exit = false;
|
||||||
Ng.pit.update_irq();
|
|
||||||
La = cpu.exec(wh - cpu.cycle_count);
|
exec_loop: while (cpu.cycle_count < Ncycles) {
|
||||||
if (La == 256) {
|
PC.pit.update_irq();
|
||||||
if (Ng.reset_request) {
|
exit_status = cpu.exec(Ncycles - cpu.cycle_count);
|
||||||
xh = true;
|
if (exit_status == 256) {
|
||||||
|
if (PC.reset_request) {
|
||||||
|
do_reset = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (La == 257) {
|
} else if (exit_status == 257) {
|
||||||
yh = true;
|
err_on_exit = true;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
xh = true;
|
do_reset = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!xh) {
|
if (!do_reset) {
|
||||||
if (yh) {
|
if (err_on_exit) {
|
||||||
setTimeout(this.timer_func.bind(this), 10);
|
setTimeout(this.timer_func.bind(this), 10);
|
||||||
} else {
|
} else {
|
||||||
setTimeout(this.timer_func.bind(this), 0);
|
setTimeout(this.timer_func.bind(this), 0);
|
||||||
|
@ -70,121 +72,133 @@ PCEmulator.prototype.timer_func = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
PCEmulator.prototype.init_ioports = function() {
|
PCEmulator.prototype.init_ioports = function() {
|
||||||
var i, Ah, Bh;
|
var i, readw, writew;
|
||||||
this.ioport_readb_table = new Array();
|
this.ioport_readb_table = new Array();
|
||||||
this.ioport_writeb_table = new Array();
|
this.ioport_writeb_table = new Array();
|
||||||
this.ioport_readw_table = new Array();
|
this.ioport_readw_table = new Array();
|
||||||
this.ioport_writew_table = new Array();
|
this.ioport_writew_table = new Array();
|
||||||
this.ioport_readl_table = new Array();
|
this.ioport_readl_table = new Array();
|
||||||
this.ioport_writel_table = new Array();
|
this.ioport_writel_table = new Array();
|
||||||
Ah = this.default_ioport_readw.bind(this);
|
readw = this.default_ioport_readw.bind(this);
|
||||||
Bh = this.default_ioport_writew.bind(this);
|
writew = this.default_ioport_writew.bind(this);
|
||||||
for (i = 0; i < 1024; i++) {
|
for (i = 0; i < 1024; i++) {
|
||||||
this.ioport_readb_table[i] = this.default_ioport_readb;
|
this.ioport_readb_table[i] = this.default_ioport_readb;
|
||||||
this.ioport_writeb_table[i] = this.default_ioport_writeb;
|
this.ioport_writeb_table[i] = this.default_ioport_writeb;
|
||||||
this.ioport_readw_table[i] = Ah;
|
this.ioport_readw_table[i] = readw;
|
||||||
this.ioport_writew_table[i] = Bh;
|
this.ioport_writew_table[i] = writew;
|
||||||
this.ioport_readl_table[i] = this.default_ioport_readl;
|
this.ioport_readl_table[i] = this.default_ioport_readl;
|
||||||
this.ioport_writel_table[i] = this.default_ioport_writel;
|
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;
|
var x;
|
||||||
x = 0xff;
|
x = 0xff;
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
|
||||||
PCEmulator.prototype.default_ioport_readw = function(Zf) {
|
PCEmulator.prototype.default_ioport_readw = function(port_num) {
|
||||||
var x;
|
var x;
|
||||||
x = this.ioport_readb_table[Zf](Zf);
|
x = this.ioport_readb_table[port_num](port_num);
|
||||||
Zf = (Zf + 1) & (1024 - 1);
|
port_num = (port_num + 1) & (1024 - 1);
|
||||||
x |= this.ioport_readb_table[Zf](Zf) << 8;
|
x |= this.ioport_readb_table[port_num](port_num) << 8;
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
|
||||||
PCEmulator.prototype.default_ioport_readl = function(Zf) {
|
PCEmulator.prototype.default_ioport_readl = function(port_num) {
|
||||||
var x;
|
var x;
|
||||||
x = -1;
|
x = -1;
|
||||||
return x;
|
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) {
|
PCEmulator.prototype.default_ioport_writew = function(port_num, x) {
|
||||||
this.ioport_writeb_table[Zf](Zf, x & 0xff);
|
this.ioport_writeb_table[port_num](port_num, x & 0xff);
|
||||||
Zf = (Zf + 1) & (1024 - 1);
|
port_num = (port_num + 1) & (1024 - 1);
|
||||||
this.ioport_writeb_table[Zf](Zf, (x >> 8) & 0xff);
|
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;
|
var x;
|
||||||
x = this.ioport_readb_table[Zf & (1024 - 1)](Zf);
|
x = this.ioport_readb_table[port_num & (1024 - 1)](port_num);
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
|
||||||
PCEmulator.prototype.ld16_port = function(Zf) {
|
PCEmulator.prototype.ld16_port = function(port_num) {
|
||||||
var x;
|
var x;
|
||||||
x = this.ioport_readw_table[Zf & (1024 - 1)](Zf);
|
x = this.ioport_readw_table[port_num & (1024 - 1)](port_num);
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
|
||||||
PCEmulator.prototype.ld32_port = function(Zf) {
|
PCEmulator.prototype.ld32_port = function(port_num) {
|
||||||
var x;
|
var x;
|
||||||
x = this.ioport_readl_table[Zf & (1024 - 1)](Zf);
|
x = this.ioport_readl_table[port_num & (1024 - 1)](port_num);
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
|
||||||
PCEmulator.prototype.st8_port = function(Zf, x) { this.ioport_writeb_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(Zf, x) { this.ioport_writew_table[Zf & (1024 - 1)](Zf, 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(Zf, x) { this.ioport_writel_table[Zf & (1024 - 1)](Zf, 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;
|
var i;
|
||||||
switch (cc) {
|
switch (iotype) {
|
||||||
case 1:
|
case 1:
|
||||||
for (i = start; i < start + tg; i++) {
|
for (i = start; i < start + len; i++) {
|
||||||
this.ioport_readb_table[i] = Ch;
|
this.ioport_readb_table[i] = io_callback;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
for (i = start; i < start + tg; i += 2) {
|
for (i = start; i < start + len; i += 2) {
|
||||||
this.ioport_readw_table[i] = Ch;
|
this.ioport_readw_table[i] = io_callback;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
for (i = start; i < start + tg; i += 4) {
|
for (i = start; i < start + len; i += 4) {
|
||||||
this.ioport_readl_table[i] = Ch;
|
this.ioport_readl_table[i] = io_callback;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PCEmulator.prototype.register_ioport_write = function(start, tg, cc, Ch) {
|
PCEmulator.prototype.register_ioport_write = function(start, len, iotype, io_callback) {
|
||||||
var i;
|
var i;
|
||||||
switch (cc) {
|
switch (iotype) {
|
||||||
case 1:
|
case 1:
|
||||||
for (i = start; i < start + tg; i++) {
|
for (i = start; i < start + len; i++) {
|
||||||
this.ioport_writeb_table[i] = Ch;
|
this.ioport_writeb_table[i] = io_callback;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
for (i = start; i < start + tg; i += 2) {
|
for (i = start; i < start + len; i += 2) {
|
||||||
this.ioport_writew_table[i] = Ch;
|
this.ioport_writew_table[i] = io_callback;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
for (i = start; i < start + tg; i += 4) {
|
for (i = start; i < start + len; i += 4) {
|
||||||
this.ioport_writel_table[i] = Ch;
|
this.ioport_writel_table[i] = io_callback;
|
||||||
}
|
}
|
||||||
break;
|
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; };
|
PCEmulator.prototype.reset = function() { this.request_request = 1; };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
14
PIC.js
14
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
|
8259 PIC (Programmable Interrupt Controller) Emulation Code
|
||||||
*/
|
*/
|
||||||
function PIC(Ng, Zf) {
|
function PIC(PC, port_num) {
|
||||||
Ng.register_ioport_write(Zf, 2, 1, this.ioport_write.bind(this));
|
PC.register_ioport_write(port_num, 2, 1, this.ioport_write.bind(this));
|
||||||
Ng.register_ioport_read(Zf, 2, 1, this.ioport_read.bind(this));
|
PC.register_ioport_read(port_num, 2, 1, this.ioport_read.bind(this));
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
PIC.prototype.reset = function() {
|
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 = new Array();
|
||||||
this.pics[0] = new PIC(Ng, Wg);
|
this.pics[0] = new PIC(PC, Wg);
|
||||||
this.pics[1] = new PIC(Ng, Ug);
|
this.pics[1] = new PIC(PC, Ug);
|
||||||
this.pics[0].elcr_mask = 0xf8;
|
this.pics[0].elcr_mask = 0xf8;
|
||||||
this.pics[1].elcr_mask = 0xde;
|
this.pics[1].elcr_mask = 0xde;
|
||||||
this.irq_requested = 0;
|
this.irq_requested = 0;
|
||||||
|
@ -226,3 +226,5 @@ PIC_Controller.prototype.get_hard_intno = function() {
|
||||||
this.update_irq();
|
this.update_irq();
|
||||||
return intno;
|
return intno;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
11
PIT.js
11
PIT.js
|
@ -3,7 +3,7 @@ Fabrix - An annotated version of the original JSLinux which is Copyright (c) 201
|
||||||
|
|
||||||
PIT Emulator
|
PIT Emulator
|
||||||
*/
|
*/
|
||||||
function PIT(Ng, ah, bh) {
|
function PIT(PC, ah, bh) {
|
||||||
var s, i;
|
var s, i;
|
||||||
this.pit_channels = new Array();
|
this.pit_channels = new Array();
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
|
@ -15,10 +15,10 @@ function PIT(Ng, ah, bh) {
|
||||||
}
|
}
|
||||||
this.speaker_data_on = 0;
|
this.speaker_data_on = 0;
|
||||||
this.set_irq = ah;
|
this.set_irq = ah;
|
||||||
Ng.register_ioport_write(0x40, 4, 1, this.ioport_write.bind(this));
|
PC.register_ioport_write(0x40, 4, 1, this.ioport_write.bind(this));
|
||||||
Ng.register_ioport_read(0x40, 3, 1, this.ioport_read.bind(this));
|
PC.register_ioport_read(0x40, 3, 1, this.ioport_read.bind(this));
|
||||||
Ng.register_ioport_read(0x61, 1, 1, this.speaker_ioport_read.bind(this));
|
PC.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(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(1);
|
||||||
this.set_irq(0);
|
this.set_irq(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue