File size: 2,898 Bytes
89610f7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | function GameBoyAdvanceSIO() {
this.SIO_NORMAL_8 = 0;
this.SIO_NORMAL_32 = 1;
this.SIO_MULTI = 2;
this.SIO_UART = 3;
this.SIO_GPIO = 8;
this.SIO_JOYBUS = 12;
this.BAUD = [ 9600, 38400, 57600, 115200 ];
}
GameBoyAdvanceSIO.prototype.clear = function() {
this.mode = this.SIO_GPIO;
this.sd = false;
this.irq = false;
this.multiplayer = {
baud: 0,
si: 0,
id: 0,
error: 0,
busy: 0,
states: [ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF ]
};
this.linkLayer = null;
};
GameBoyAdvanceSIO.prototype.setMode = function(mode) {
if (mode & 0x8) {
mode &= 0xC;
} else {
mode &= 0x3;
}
this.mode = mode;
this.core.INFO('Setting SIO mode to ' + hex(mode, 1));
};
GameBoyAdvanceSIO.prototype.writeRCNT = function(value) {
if (this.mode != this.SIO_GPIO) {
return;
}
this.core.STUB('General purpose serial not supported');
};
GameBoyAdvanceSIO.prototype.writeSIOCNT = function(value) {
switch (this.mode) {
case this.SIO_NORMAL_8:
this.core.STUB('8-bit transfer unsupported');
break;
case this.SIO_NORMAL_32:
this.core.STUB('32-bit transfer unsupported');
break;
case this.SIO_MULTI:
this.multiplayer.baud = value & 0x0003;
if (this.linkLayer) {
this.linkLayer.setBaud(this.BAUD[this.multiplayer.baud]);
}
if (!this.multiplayer.si) {
this.multiplayer.busy = value & 0x0080;
if (this.linkLayer && this.multiplayer.busy) {
this.linkLayer.startMultiplayerTransfer();
}
}
this.irq = value & 0x4000;
break;
case this.SIO_UART:
this.core.STUB('UART unsupported');
break;
case this.SIO_GPIO:
// This register isn't used in general-purpose mode
break;
case this.SIO_JOYBUS:
this.core.STUB('JOY BUS unsupported');
break;
}
};
GameBoyAdvanceSIO.prototype.readSIOCNT = function() {
var value = (this.mode << 12) & 0xFFFF;
switch (this.mode) {
case this.SIO_NORMAL_8:
this.core.STUB('8-bit transfer unsupported');
break;
case this.SIO_NORMAL_32:
this.core.STUB('32-bit transfer unsupported');
break;
case this.SIO_MULTI:
value |= this.multiplayer.baud;
value |= this.multiplayer.si;
value |= (!!this.sd) << 3;
value |= this.multiplayer.id << 4;
value |= this.multiplayer.error;
value |= this.multiplayer.busy;
value |= (!!this.multiplayer.irq) << 14;
break;
case this.SIO_UART:
this.core.STUB('UART unsupported');
break;
case this.SIO_GPIO:
// This register isn't used in general-purpose mode
break;
case this.SIO_JOYBUS:
this.core.STUB('JOY BUS unsupported');
break;
}
return value;
};
GameBoyAdvanceSIO.prototype.read = function(slot) {
switch (this.mode) {
case this.SIO_NORMAL_32:
this.core.STUB('32-bit transfer unsupported');
break;
case this.SIO_MULTI:
return this.multiplayer.states[slot];
case this.SIO_UART:
this.core.STUB('UART unsupported');
break;
default:
this.core.WARN('Reading from transfer register in unsupported mode');
break;
}
return 0;
};
|