2015-11-14 00:52:51 +00:00
|
|
|
auto ICD2::lcdScanline() -> void {
|
2014-01-28 10:04:58 +00:00
|
|
|
if(GameBoy::ppu.status.ly > 143) return; //Vblank
|
2012-04-26 10:51:13 +00:00
|
|
|
if((GameBoy::ppu.status.ly & 7) == 0) {
|
2016-06-17 13:03:54 +00:00
|
|
|
writeBank = (writeBank + 1) & 3;
|
|
|
|
writeAddress = 0;
|
2011-05-08 13:46:37 +00:00
|
|
|
}
|
2014-01-28 10:04:58 +00:00
|
|
|
}
|
2011-05-08 13:46:37 +00:00
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto ICD2::lcdOutput(uint2 color) -> void {
|
2016-06-17 13:03:54 +00:00
|
|
|
uint y = writeAddress / 160;
|
|
|
|
uint x = writeAddress % 160;
|
|
|
|
uint addr = writeBank * 512 + y * 2 + x / 8 * 16;
|
2014-01-28 10:04:58 +00:00
|
|
|
output[addr + 0] = (output[addr + 0] << 1) | (bool)(color & 1);
|
|
|
|
output[addr + 1] = (output[addr + 1] << 1) | (bool)(color & 2);
|
2016-06-17 13:03:54 +00:00
|
|
|
writeAddress = (writeAddress + 1) % 1280;
|
2011-05-08 13:46:37 +00:00
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto ICD2::joypWrite(bool p15, bool p14) -> void {
|
2011-01-08 09:58:41 +00:00
|
|
|
//joypad handling
|
|
|
|
if(p15 == 1 && p14 == 1) {
|
2016-06-17 13:03:54 +00:00
|
|
|
if(joyp15Lock == 0 && joyp14Lock == 0) {
|
|
|
|
joyp15Lock = 1;
|
|
|
|
joyp14Lock = 1;
|
|
|
|
joypID = (joypID + 1) & 3;
|
2011-01-08 09:58:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-17 13:03:54 +00:00
|
|
|
if(p15 == 0 && p14 == 1) joyp15Lock = 0;
|
|
|
|
if(p15 == 1 && p14 == 0) joyp14Lock = 0;
|
2011-01-08 09:58:41 +00:00
|
|
|
|
|
|
|
//packet handling
|
|
|
|
if(p15 == 0 && p14 == 0) { //pulse
|
2016-06-17 13:03:54 +00:00
|
|
|
pulseLock = false;
|
|
|
|
packetOffset = 0;
|
|
|
|
bitOffset = 0;
|
|
|
|
strobeLock = true;
|
|
|
|
packetLock = false;
|
2011-01-08 09:58:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-17 13:03:54 +00:00
|
|
|
if(pulseLock) return;
|
2011-01-08 09:58:41 +00:00
|
|
|
|
|
|
|
if(p15 == 1 && p14 == 1) {
|
2016-06-17 13:03:54 +00:00
|
|
|
strobeLock = false;
|
2011-01-08 09:58:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-17 13:03:54 +00:00
|
|
|
if(strobeLock) {
|
2011-01-08 09:58:41 +00:00
|
|
|
if(p15 == 1 || p14 == 1) { //malformed packet
|
2016-06-17 13:03:54 +00:00
|
|
|
packetLock = false;
|
|
|
|
pulseLock = true;
|
|
|
|
bitOffset = 0;
|
|
|
|
packetOffset = 0;
|
2011-01-08 09:58:41 +00:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//p15:1, p14:0 = 0
|
|
|
|
//p15:0, p14:1 = 1
|
|
|
|
bool bit = (p15 == 0);
|
2016-06-17 13:03:54 +00:00
|
|
|
strobeLock = true;
|
2011-01-08 09:58:41 +00:00
|
|
|
|
2016-06-17 13:03:54 +00:00
|
|
|
if(packetLock) {
|
2011-01-08 09:58:41 +00:00
|
|
|
if(p15 == 1 && p14 == 0) {
|
2016-06-17 13:03:54 +00:00
|
|
|
if((joypPacket[0] >> 3) == 0x11) {
|
|
|
|
mltReq = joypPacket[1] & 3;
|
|
|
|
if(mltReq == 2) mltReq = 3;
|
|
|
|
joypID = 0;
|
2011-01-08 09:58:41 +00:00
|
|
|
}
|
|
|
|
|
2016-06-17 13:03:54 +00:00
|
|
|
if(packetSize < 64) packet[packetSize++] = joypPacket;
|
|
|
|
packetLock = false;
|
|
|
|
pulseLock = true;
|
2011-01-08 09:58:41 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-17 13:03:54 +00:00
|
|
|
bitData = (bit << 7) | (bitData >> 1);
|
|
|
|
if(++bitOffset < 8) return;
|
2011-01-08 09:58:41 +00:00
|
|
|
|
2016-06-17 13:03:54 +00:00
|
|
|
bitOffset = 0;
|
|
|
|
joypPacket[packetOffset] = bitData;
|
|
|
|
if(++packetOffset < 16) return;
|
|
|
|
packetLock = true;
|
2011-01-08 09:58:41 +00:00
|
|
|
}
|