2016-06-05 22:10:01 +00:00
|
|
|
auto SuperFX::read(uint24 addr, uint8 data) -> uint8 {
|
|
|
|
if((addr & 0xc00000) == 0x000000) { //$00-3f:0000-7fff,:8000-ffff
|
2016-02-09 11:51:12 +00:00
|
|
|
while(!regs.scmr.ron && !scheduler.synchronizing()) {
|
2012-04-29 06:16:44 +00:00
|
|
|
step(6);
|
2015-12-14 09:41:06 +00:00
|
|
|
synchronizeCPU();
|
2011-01-16 13:17:45 +00:00
|
|
|
}
|
2016-06-05 22:10:01 +00:00
|
|
|
return rom.read((((addr & 0x3f0000) >> 1) | (addr & 0x7fff)) & romMask);
|
2011-01-16 13:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if((addr & 0xe00000) == 0x400000) { //$40-5f:0000-ffff
|
2016-02-09 11:51:12 +00:00
|
|
|
while(!regs.scmr.ron && !scheduler.synchronizing()) {
|
2012-04-29 06:16:44 +00:00
|
|
|
step(6);
|
2015-12-14 09:41:06 +00:00
|
|
|
synchronizeCPU();
|
2011-01-16 13:17:45 +00:00
|
|
|
}
|
2016-06-05 22:10:01 +00:00
|
|
|
return rom.read(addr & romMask);
|
2011-01-16 13:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if((addr & 0xe00000) == 0x600000) { //$60-7f:0000-ffff
|
2016-02-09 11:51:12 +00:00
|
|
|
while(!regs.scmr.ran && !scheduler.synchronizing()) {
|
2012-04-29 06:16:44 +00:00
|
|
|
step(6);
|
2015-12-14 09:41:06 +00:00
|
|
|
synchronizeCPU();
|
2011-01-16 13:17:45 +00:00
|
|
|
}
|
2016-06-05 22:10:01 +00:00
|
|
|
return ram.read(addr & ramMask);
|
2011-01-16 13:17:45 +00:00
|
|
|
}
|
2016-03-26 01:56:15 +00:00
|
|
|
|
|
|
|
return data;
|
2011-01-16 13:17:45 +00:00
|
|
|
}
|
|
|
|
|
2016-06-05 22:10:01 +00:00
|
|
|
auto SuperFX::write(uint24 addr, uint8 data) -> void {
|
2011-01-16 13:17:45 +00:00
|
|
|
if((addr & 0xe00000) == 0x600000) { //$60-7f:0000-ffff
|
2016-02-09 11:51:12 +00:00
|
|
|
while(!regs.scmr.ran && !scheduler.synchronizing()) {
|
2012-04-29 06:16:44 +00:00
|
|
|
step(6);
|
2015-12-14 09:41:06 +00:00
|
|
|
synchronizeCPU();
|
2011-01-16 13:17:45 +00:00
|
|
|
}
|
2016-06-05 22:10:01 +00:00
|
|
|
return ram.write(addr & ramMask, data);
|
2011-01-16 13:17:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-05 22:10:01 +00:00
|
|
|
auto SuperFX::readOpcode(uint16 addr) -> uint8 {
|
2010-08-09 13:28:56 +00:00
|
|
|
uint16 offset = addr - regs.cbr;
|
|
|
|
if(offset < 512) {
|
|
|
|
if(cache.valid[offset >> 4] == false) {
|
2016-06-05 22:10:01 +00:00
|
|
|
uint dp = offset & 0xfff0;
|
|
|
|
uint sp = (regs.pbr << 16) + ((regs.cbr + dp) & 0xfff0);
|
|
|
|
for(uint n : range(16)) {
|
2015-06-28 08:44:56 +00:00
|
|
|
step(regs.clsr ? 5 : 6);
|
2016-06-05 22:10:01 +00:00
|
|
|
cache.buffer[dp++] = read(sp++);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
cache.valid[offset >> 4] = true;
|
|
|
|
} else {
|
2015-06-28 08:44:56 +00:00
|
|
|
step(regs.clsr ? 1 : 2);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
return cache.buffer[offset];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(regs.pbr <= 0x5f) {
|
2016-06-05 22:10:01 +00:00
|
|
|
//$00-5f:0000-ffff ROM
|
|
|
|
syncROMBuffer();
|
2015-06-28 08:44:56 +00:00
|
|
|
step(regs.clsr ? 5 : 6);
|
2016-06-05 22:10:01 +00:00
|
|
|
return read(regs.pbr << 16 | addr);
|
2010-08-09 13:28:56 +00:00
|
|
|
} else {
|
2016-06-05 22:10:01 +00:00
|
|
|
//$60-7f:0000-ffff RAM
|
|
|
|
syncRAMBuffer();
|
2015-06-28 08:44:56 +00:00
|
|
|
step(regs.clsr ? 5 : 6);
|
2016-06-05 22:10:01 +00:00
|
|
|
return read(regs.pbr << 16 | addr);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-27 02:38:47 +00:00
|
|
|
auto SuperFX::peekpipe() -> uint8 {
|
2010-08-09 13:28:56 +00:00
|
|
|
uint8 result = regs.pipeline;
|
2016-06-05 22:10:01 +00:00
|
|
|
regs.pipeline = readOpcode(regs.r[15]);
|
|
|
|
regs.r[15].modified = false;
|
2010-08-09 13:28:56 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-06-27 02:38:47 +00:00
|
|
|
auto SuperFX::pipe() -> uint8 {
|
2010-08-09 13:28:56 +00:00
|
|
|
uint8 result = regs.pipeline;
|
2016-06-05 22:10:01 +00:00
|
|
|
regs.pipeline = readOpcode(++regs.r[15]);
|
|
|
|
regs.r[15].modified = false;
|
2010-08-09 13:28:56 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-06-05 22:10:01 +00:00
|
|
|
auto SuperFX::flushCache() -> void {
|
|
|
|
for(uint n : range(32)) cache.valid[n] = false;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-05 22:10:01 +00:00
|
|
|
auto SuperFX::readCache(uint16 addr) -> uint8 {
|
2010-08-09 13:28:56 +00:00
|
|
|
addr = (addr + regs.cbr) & 511;
|
|
|
|
return cache.buffer[addr];
|
|
|
|
}
|
|
|
|
|
2016-06-05 22:10:01 +00:00
|
|
|
auto SuperFX::writeCache(uint16 addr, uint8 data) -> void {
|
2010-08-09 13:28:56 +00:00
|
|
|
addr = (addr + regs.cbr) & 511;
|
|
|
|
cache.buffer[addr] = data;
|
|
|
|
if((addr & 15) == 15) cache.valid[addr >> 4] = true;
|
|
|
|
}
|