2011-11-04 11:57:54 +00:00
|
|
|
struct VRC1 : Chip {
|
2015-12-05 05:44:49 +00:00
|
|
|
VRC1(Board& board) : Chip(board) {
|
|
|
|
}
|
2011-11-04 11:57:54 +00:00
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
auto addrPRG(uint addr) const -> uint {
|
2015-12-05 05:44:49 +00:00
|
|
|
uint bank = 0x0f;
|
2016-06-27 13:07:57 +00:00
|
|
|
if((addr & 0xe000) == 0x8000) bank = prgBank[0];
|
|
|
|
if((addr & 0xe000) == 0xa000) bank = prgBank[1];
|
|
|
|
if((addr & 0xe000) == 0xc000) bank = prgBank[2];
|
2015-12-05 05:44:49 +00:00
|
|
|
return (bank * 0x2000) + (addr & 0x1fff);
|
|
|
|
}
|
2011-11-04 11:57:54 +00:00
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
auto addrCHR(uint addr) const -> uint {
|
|
|
|
uint bank = chrBankLo[(bool)(addr & 0x1000)];
|
|
|
|
bank |= chrBankHi[(bool)(addr & 0x1000)] << 4;
|
2015-12-05 05:44:49 +00:00
|
|
|
return (bank * 0x1000) + (addr & 0x0fff);
|
|
|
|
}
|
2011-11-04 11:57:54 +00:00
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
auto addrCIRAM(uint addr) const -> uint {
|
2015-12-05 05:44:49 +00:00
|
|
|
switch(mirror) {
|
|
|
|
case 0: return ((addr & 0x0400) >> 0) | (addr & 0x03ff); //vertical mirroring
|
|
|
|
case 1: return ((addr & 0x0800) >> 1) | (addr & 0x03ff); //horizontal mirroring
|
|
|
|
}
|
|
|
|
throw;
|
2011-11-04 11:57:54 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
auto writeIO(uint addr, uint8 data) -> void {
|
2015-12-05 05:44:49 +00:00
|
|
|
switch(addr & 0xf000) {
|
|
|
|
case 0x8000:
|
2016-06-27 13:07:57 +00:00
|
|
|
prgBank[0] = data & 0x0f;
|
2015-12-05 05:44:49 +00:00
|
|
|
break;
|
2011-11-04 11:57:54 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
case 0x9000:
|
2016-06-27 13:07:57 +00:00
|
|
|
chrBankHi[1] = data & 0x04;
|
|
|
|
chrBankHi[0] = data & 0x02;
|
2015-12-05 05:44:49 +00:00
|
|
|
mirror = data & 0x01;
|
|
|
|
break;
|
2011-11-04 11:57:54 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
case 0xa000:
|
2016-06-27 13:07:57 +00:00
|
|
|
prgBank[1] = data & 0x0f;
|
2015-12-05 05:44:49 +00:00
|
|
|
break;
|
2011-11-04 11:57:54 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
case 0xc000:
|
2016-06-27 13:07:57 +00:00
|
|
|
prgBank[2] = data & 0x0f;
|
2015-12-05 05:44:49 +00:00
|
|
|
break;
|
2011-11-04 11:57:54 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
case 0xe000:
|
2016-06-27 13:07:57 +00:00
|
|
|
chrBankLo[0] = data & 0x0f;
|
2015-12-05 05:44:49 +00:00
|
|
|
break;
|
2011-11-04 11:57:54 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
case 0xf000:
|
2016-06-27 13:07:57 +00:00
|
|
|
chrBankLo[1] = data & 0x0f;
|
2015-12-05 05:44:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-11-04 11:57:54 +00:00
|
|
|
}
|
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
auto power() -> void {
|
|
|
|
}
|
2011-11-04 11:57:54 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
auto reset() -> void {
|
2016-06-27 13:07:57 +00:00
|
|
|
for(auto& n : prgBank) n = 0;
|
|
|
|
for(auto& n : chrBankLo) n = 0;
|
|
|
|
for(auto& n : chrBankHi) n = 0;
|
2015-12-05 05:44:49 +00:00
|
|
|
mirror = 0;
|
|
|
|
}
|
2011-11-04 11:57:54 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
auto serialize(serializer& s) -> void {
|
2016-06-27 13:07:57 +00:00
|
|
|
for(auto& n : prgBank) s.integer(n);
|
|
|
|
for(auto& n : chrBankLo) s.integer(n);
|
|
|
|
for(auto& n : chrBankHi) s.integer(n);
|
2015-12-05 05:44:49 +00:00
|
|
|
s.integer(mirror);
|
|
|
|
}
|
2011-11-04 11:57:54 +00:00
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
uint4 prgBank[3];
|
|
|
|
uint4 chrBankLo[2];
|
|
|
|
bool chrBankHi[2];
|
2015-12-05 05:44:49 +00:00
|
|
|
bool mirror;
|
2011-11-04 11:57:54 +00:00
|
|
|
};
|