2015-11-14 00:52:51 +00:00
|
|
|
auto ICD2::read(uint addr) -> uint8 {
|
2011-01-08 09:58:41 +00:00
|
|
|
addr &= 0xffff;
|
|
|
|
|
|
|
|
//LY counter
|
|
|
|
if(addr == 0x6000) {
|
2015-11-14 00:52:51 +00:00
|
|
|
uint y = min(143u, GameBoy::ppu.status.ly);
|
2014-01-28 10:04:58 +00:00
|
|
|
return (y & ~7) | write_bank;
|
2011-01-08 09:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//command ready port
|
|
|
|
if(addr == 0x6002) {
|
|
|
|
bool data = packetsize > 0;
|
|
|
|
if(data) {
|
2015-11-14 00:52:51 +00:00
|
|
|
for(auto n : range(16)) r7000[n] = packet[0][n];
|
2011-01-08 09:58:41 +00:00
|
|
|
packetsize--;
|
2015-11-14 00:52:51 +00:00
|
|
|
for(auto n : range(packetsize)) packet[n] = packet[n + 1];
|
2011-01-08 09:58:41 +00:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
//ICD2 revision
|
|
|
|
if(addr == 0x600f) {
|
|
|
|
return 0x21;
|
|
|
|
}
|
|
|
|
|
|
|
|
//command port
|
|
|
|
if((addr & 0xfff0) == 0x7000) {
|
|
|
|
return r7000[addr & 15];
|
|
|
|
}
|
|
|
|
|
|
|
|
//VRAM port
|
|
|
|
if(addr == 0x7800) {
|
2014-01-28 10:04:58 +00:00
|
|
|
uint8 data = output[read_bank * 512 + read_addr];
|
|
|
|
read_addr = (read_addr + 1) & 511;
|
2011-01-08 09:58:41 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0x00;
|
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto ICD2::write(uint addr, uint8 data) -> void {
|
2011-01-08 09:58:41 +00:00
|
|
|
addr &= 0xffff;
|
|
|
|
|
2011-05-08 13:46:37 +00:00
|
|
|
//VRAM port
|
|
|
|
if(addr == 0x6001) {
|
2014-01-28 10:04:58 +00:00
|
|
|
read_bank = data & 3;
|
|
|
|
read_addr = 0;
|
2011-05-08 13:46:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-08 09:58:41 +00:00
|
|
|
//control port
|
|
|
|
//d7: 0 = halt, 1 = reset
|
|
|
|
//d5,d4: 0 = 1-player, 1 = 2-player, 2 = 4-player, 3 = ???
|
|
|
|
//d1,d0: 0 = frequency divider (clock rate adjust)
|
|
|
|
if(addr == 0x6003) {
|
|
|
|
if((r6003 & 0x80) == 0x00 && (data & 0x80) == 0x80) {
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
switch(data & 3) {
|
2013-05-05 09:21:30 +00:00
|
|
|
case 0: frequency = cpu.frequency / 4; break; //fast (glitchy, even on real hardware)
|
|
|
|
case 1: frequency = cpu.frequency / 5; break; //normal
|
|
|
|
case 2: frequency = cpu.frequency / 7; break; //slow
|
|
|
|
case 3: frequency = cpu.frequency / 9; break; //very slow
|
2011-01-08 09:58:41 +00:00
|
|
|
}
|
|
|
|
r6003 = data;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0x6004) { r6004 = data; return; } //joypad 1
|
|
|
|
if(addr == 0x6005) { r6005 = data; return; } //joypad 2
|
|
|
|
if(addr == 0x6006) { r6006 = data; return; } //joypad 3
|
|
|
|
if(addr == 0x6007) { r6007 = data; return; } //joypad 4
|
|
|
|
}
|