Merge pull request #11 from danluu/deobfuscate

Various devices
This commit is contained in:
Anselm Levskaya 2013-03-23 01:06:43 -07:00
commit e7b0f1b321
5 changed files with 28 additions and 3 deletions

View File

@ -27,6 +27,9 @@ function CMOS(PC) {
}
CMOS.prototype.ioport_write = function(mem8_loc, data) {
if (mem8_loc == 0x70) {
// the high order bit is used to indicate NMI masking
// low order bits are used to address CMOS
// the index written here is used on an ioread 0x71
this.cmos_index = data & 0x7f;
}
};
@ -35,10 +38,13 @@ CMOS.prototype.ioport_read = function(mem8_loc) {
if (mem8_loc == 0x70) {
return 0xff;
} else {
// else here => 0x71, i.e., CMOS read
data = this.cmos_data[this.cmos_index];
if (this.cmos_index == 10)
// flip the UIP (update in progress) bit on a read
this.cmos_data[10] ^= 0x80;
else if (this.cmos_index == 12)
// Always return interrupt status == 0
this.cmos_data[12] = 0x00;
return data;
}

2
KBD.js
View File

@ -13,7 +13,7 @@ KBD.prototype.read_status = function(mem8_loc) {
};
KBD.prototype.write_command = function(mem8_loc, x) {
switch (x) {
case 0xfe:
case 0xfe: // Resend command. Other commands are, apparently, ignored.
this.reset_request();
break;
default:

View File

@ -185,7 +185,7 @@ PCEmulator.prototype.register_ioport_write = function(start, len, iotype, io_cal
}
};
PCEmulator.prototype.ioport80_write = function(mem8_loc, data) {};
PCEmulator.prototype.ioport80_write = function(mem8_loc, data) {}; //POST codes! Seem to be ignored?
PCEmulator.prototype.reset = function() { this.request_request = 1; };

10
PIC.js
View File

@ -72,6 +72,16 @@ PIC.prototype.ioport_write = function(mem8_loc, x) {
mem8_loc &= 1;
if (mem8_loc == 0) {
if (x & 0x10) {
/*
ICW1
// 7:5 = address (if MCS-80/85 mode)
// 4 == 1
// 3: 1 == level triggered, 0 == edge triggered
// 2: 1 == call interval 4, 0 == call interval 8
// 1: 1 == single PIC, 0 == cascaded PICs
// 0: 1 == send ICW4
*/
this.reset();
this.init_state = 1;
this.init4 = x & 1;

9
PIT.js
View File

@ -15,6 +15,9 @@ function PIT(PC, ah, bh) {
}
this.speaker_data_on = 0;
this.set_irq = ah;
// Ports:
// 0x40: Channel 0 data port
// 0x61: Control
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));
@ -58,22 +61,28 @@ IRQCH.prototype.pit_get_out = function() {
d = this.get_time() - this.count_load_time;
switch (this.mode) {
default:
// Interrupt on terminal count
case 0:
eh = (d >= this.count) >> 0;
break;
// One shot
case 1:
eh = (d < this.count) >> 0;
break;
// Frequency divider
case 2:
if ((d % this.count) == 0 && d != 0)
eh = 1;
else
eh = 0;
break;
// Square wave
case 3:
eh = ((d % this.count) < (this.count >> 1)) >> 0;
break;
// SW strobe
case 4:
// HW strobe
case 5:
eh = (d == this.count) >> 0;
break;