2011-12-21 13:34:38 +08:00
|
|
|
/*
|
2013-03-29 10:43:44 +08:00
|
|
|
JSLinux-deobfuscated - An annotated version of the original JSLinux.
|
|
|
|
|
|
|
|
Original is Copyright (c) 2011-2012 Fabrice Bellard
|
|
|
|
Redistribution or commercial use is prohibited without the author's permission.
|
2011-12-21 13:34:38 +08:00
|
|
|
|
2013-09-16 11:17:04 +08:00
|
|
|
CMOS Ram Memory, actually just the RTC Clock Emulator
|
|
|
|
|
|
|
|
Useful references:
|
|
|
|
------------------
|
|
|
|
http://www.bioscentral.com/misc/cmosmap.htm
|
|
|
|
http://wiki.osdev.org/CMOS
|
2011-12-21 13:34:38 +08:00
|
|
|
*/
|
2013-09-16 11:17:04 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
In this implementation, bytes are stored in the RTC in BCD format
|
|
|
|
binary -> bcd: bcd = ((bin / 10) << 4) | (bin % 10)
|
|
|
|
bcd -> binary: bin = ((bcd / 16) * 10) + (bcd & 0xf)
|
|
|
|
*/
|
|
|
|
function bin_to_bcd(a) { return ((a / 10) << 4) | (a % 10);}
|
|
|
|
|
2011-12-24 11:28:34 +08:00
|
|
|
function CMOS(PC) {
|
|
|
|
var time_array, d;
|
|
|
|
time_array = new Uint8Array(128);
|
|
|
|
this.cmos_data = time_array;
|
2011-12-21 13:34:38 +08:00
|
|
|
this.cmos_index = 0;
|
|
|
|
d = new Date();
|
2013-09-16 11:17:04 +08:00
|
|
|
time_array[0] = bin_to_bcd(d.getUTCSeconds());
|
|
|
|
time_array[2] = bin_to_bcd(d.getUTCMinutes());
|
|
|
|
time_array[4] = bin_to_bcd(d.getUTCHours());
|
|
|
|
time_array[6] = bin_to_bcd(d.getUTCDay());
|
|
|
|
time_array[7] = bin_to_bcd(d.getUTCDate());
|
|
|
|
time_array[8] = bin_to_bcd(d.getUTCMonth() + 1);
|
|
|
|
time_array[9] = bin_to_bcd(d.getUTCFullYear() % 100);
|
2011-12-24 11:28:34 +08:00
|
|
|
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));
|
2011-12-21 13:34:38 +08:00
|
|
|
}
|
2011-12-24 11:28:34 +08:00
|
|
|
CMOS.prototype.ioport_write = function(mem8_loc, data) {
|
2011-12-21 13:34:38 +08:00
|
|
|
if (mem8_loc == 0x70) {
|
2013-09-16 11:17:04 +08:00
|
|
|
// the high order bit is used to indicate NMI masking
|
2013-03-21 22:45:13 +08:00
|
|
|
// low order bits are used to address CMOS
|
|
|
|
// the index written here is used on an ioread 0x71
|
2013-03-29 10:43:44 +08:00
|
|
|
this.cmos_index = data & 0x7f;
|
2011-12-21 13:34:38 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
CMOS.prototype.ioport_read = function(mem8_loc) {
|
2011-12-24 11:28:34 +08:00
|
|
|
var data;
|
2011-12-21 13:34:38 +08:00
|
|
|
if (mem8_loc == 0x70) {
|
|
|
|
return 0xff;
|
|
|
|
} else {
|
2013-09-16 11:17:04 +08:00
|
|
|
// else here => 0x71, i.e., CMOS read
|
2011-12-24 11:28:34 +08:00
|
|
|
data = this.cmos_data[this.cmos_index];
|
2011-12-21 13:34:38 +08:00
|
|
|
if (this.cmos_index == 10)
|
2013-03-21 22:45:13 +08:00
|
|
|
// flip the UIP (update in progress) bit on a read
|
2011-12-21 13:34:38 +08:00
|
|
|
this.cmos_data[10] ^= 0x80;
|
|
|
|
else if (this.cmos_index == 12)
|
2013-03-21 22:45:13 +08:00
|
|
|
// Always return interrupt status == 0
|
2011-12-21 13:34:38 +08:00
|
|
|
this.cmos_data[12] = 0x00;
|
2011-12-24 11:28:34 +08:00
|
|
|
return data;
|
2011-12-21 13:34:38 +08:00
|
|
|
}
|
|
|
|
};
|