2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::dma_transfer_valid(uint8 bbus, uint abus) -> bool {
|
2010-08-11 00:40:59 +00:00
|
|
|
//transfers from WRAM to WRAM are invalid; chip only has one address bus
|
|
|
|
if(bbus == 0x80 && ((abus & 0xfe0000) == 0x7e0000 || (abus & 0x40e000) == 0x0000)) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::dma_addr_valid(uint abus) -> bool {
|
2010-08-11 00:40:59 +00:00
|
|
|
//A-bus access to B-bus or S-CPU registers are invalid
|
|
|
|
if((abus & 0x40ff00) == 0x2100) return false; //$[00-3f|80-bf]:[2100-21ff]
|
|
|
|
if((abus & 0x40fe00) == 0x4000) return false; //$[00-3f|80-bf]:[4000-41ff]
|
|
|
|
if((abus & 0x40ffe0) == 0x4200) return false; //$[00-3f|80-bf]:[4200-421f]
|
|
|
|
if((abus & 0x40ff80) == 0x4300) return false; //$[00-3f|80-bf]:[4300-437f]
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::dma_read(uint abus) -> uint8 {
|
2010-08-11 00:40:59 +00:00
|
|
|
if(dma_addr_valid(abus) == false) return 0x00;
|
|
|
|
return bus.read(abus);
|
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::dma_write(bool valid, uint addr, uint8 data) -> void {
|
2010-08-11 00:40:59 +00:00
|
|
|
if(valid) bus.write(addr, data);
|
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::dma_transfer(bool direction, uint8 bbus, uint abus) -> void {
|
2010-08-11 00:40:59 +00:00
|
|
|
if(direction == 0) {
|
|
|
|
uint8 data = dma_read(abus);
|
|
|
|
add_clocks(8);
|
|
|
|
dma_write(dma_transfer_valid(bbus, abus), 0x2100 | bbus, data);
|
|
|
|
} else {
|
|
|
|
uint8 data = dma_transfer_valid(bbus, abus) ? bus.read(0x2100 | bbus) : 0x00;
|
|
|
|
add_clocks(8);
|
|
|
|
dma_write(dma_addr_valid(abus), abus, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::dma_bbus(uint i, uint index) -> uint8 {
|
2010-08-11 00:40:59 +00:00
|
|
|
switch(channel[i].transfer_mode) { default:
|
|
|
|
case 0: return (channel[i].dest_addr); //0
|
|
|
|
case 1: return (channel[i].dest_addr + (index & 1)); //0,1
|
|
|
|
case 2: return (channel[i].dest_addr); //0,0
|
|
|
|
case 3: return (channel[i].dest_addr + ((index >> 1) & 1)); //0,0,1,1
|
|
|
|
case 4: return (channel[i].dest_addr + (index & 3)); //0,1,2,3
|
|
|
|
case 5: return (channel[i].dest_addr + (index & 1)); //0,1,0,1
|
|
|
|
case 6: return (channel[i].dest_addr); //0,0 [2]
|
|
|
|
case 7: return (channel[i].dest_addr + ((index >> 1) & 1)); //0,0,1,1 [3]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::dma_addr(uint i) -> uint {
|
|
|
|
uint result = (channel[i].source_bank << 16) | (channel[i].source_addr);
|
2010-08-11 00:40:59 +00:00
|
|
|
|
|
|
|
if(channel[i].fixed_transfer == false) {
|
|
|
|
if(channel[i].reverse_transfer == false) {
|
|
|
|
channel[i].source_addr++;
|
|
|
|
} else {
|
|
|
|
channel[i].source_addr--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::hdma_addr(uint i) -> uint {
|
2010-08-11 00:40:59 +00:00
|
|
|
return (channel[i].source_bank << 16) | (channel[i].hdma_addr++);
|
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::hdma_iaddr(uint i) -> uint {
|
2010-08-11 00:40:59 +00:00
|
|
|
return (channel[i].indirect_bank << 16) | (channel[i].indirect_addr++);
|
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::dma_run() -> void {
|
2010-08-11 00:40:59 +00:00
|
|
|
add_clocks(16);
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
for(uint i = 0; i < 8; i++) {
|
2010-08-11 00:40:59 +00:00
|
|
|
if(channel[i].dma_enabled == false) continue;
|
|
|
|
add_clocks(8);
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
uint index = 0;
|
2010-08-11 00:40:59 +00:00
|
|
|
do {
|
|
|
|
dma_transfer(channel[i].direction, dma_bbus(i, index++), dma_addr(i));
|
|
|
|
} while(channel[i].dma_enabled && --channel[i].transfer_size);
|
2010-08-20 13:01:32 +00:00
|
|
|
|
|
|
|
channel[i].dma_enabled = false;
|
2010-08-11 00:40:59 +00:00
|
|
|
}
|
2010-08-12 00:39:41 +00:00
|
|
|
|
|
|
|
status.irq_lock = true;
|
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::hdma_active_after(uint i) -> bool {
|
|
|
|
for(uint n = i + 1; i < 8; i++) {
|
2010-08-12 00:39:41 +00:00
|
|
|
if(channel[i].hdma_enabled && !channel[i].hdma_completed) return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-08-11 00:40:59 +00:00
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::hdma_update(uint i) -> void {
|
2010-08-11 00:40:59 +00:00
|
|
|
if((channel[i].line_counter & 0x7f) == 0) {
|
|
|
|
channel[i].line_counter = dma_read(hdma_addr(i));
|
|
|
|
channel[i].hdma_completed = (channel[i].line_counter == 0);
|
|
|
|
channel[i].hdma_do_transfer = !channel[i].hdma_completed;
|
|
|
|
add_clocks(8);
|
|
|
|
|
|
|
|
if(channel[i].indirect) {
|
2010-08-12 00:39:41 +00:00
|
|
|
channel[i].indirect_addr = dma_read(hdma_addr(i)) << 8;
|
2010-08-11 00:40:59 +00:00
|
|
|
add_clocks(8);
|
2010-08-12 00:39:41 +00:00
|
|
|
|
|
|
|
//emulating this glitch causes a slight slowdown; only enable if needed
|
|
|
|
//if(!channel[i].hdma_completed || hdma_active_after(i)) {
|
|
|
|
channel[i].indirect_addr >>= 8;
|
|
|
|
channel[i].indirect_addr |= dma_read(hdma_addr(i)) << 8;
|
|
|
|
add_clocks(8);
|
|
|
|
//}
|
2010-08-11 00:40:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::hdma_run() -> void {
|
|
|
|
uint channels = 0;
|
|
|
|
for(uint i = 0; i < 8; i++) {
|
2010-08-11 00:40:59 +00:00
|
|
|
if(channel[i].hdma_enabled) channels++;
|
|
|
|
}
|
|
|
|
if(channels == 0) return;
|
|
|
|
|
Updated to v067r23 release.
byuu says:
Added missing $4200 IRQ lock, which fixes Chou Aniki on the fast CPU
core, so slower PCs can get their brotherly love on.
Added range-based controller IOBit latching to the fast CPU core, which
enables Super Scope and Justifier support. Uses the priority queue as
well, so there is zero speed-hit. Given the way range-testing works, the
trigger point may vary by 1-2 pixels when firing at the same spot. Not
really a big deal when it avoids a massive speed penalty.
Fixed PAL and interlace-mode HVIRQs at V=0,H<2 on the fast CPU core.
Added the dot-renderer's sprite list update-on-OAM-write functionality
to the scanline-based PPU renderer. Unfortunately it looks like all the
speed gain was already taken from the global dirty flag I was using
before, but this certainly won't hurt speed any, so whatever.
Added #ifdef to stop CoInitialize(0) on non-Windows ports.
Added #ifdefs to stop gradient fade on Windows port. Not going to fuck
over the Linux port aesthetic because of Qt bug #47,326,927. If there's
a way to tell what Qt theme is being used, I can leave it enabled for
XP/Vista themes.
Moved HDMA trigger from 1104 to 1112, and reduced channel overhead from
24 to 16, to better simulate one-cycle DMA->CPU sync.
Code clarity: I've re-added my varint.hpp classes, and am actively using
them in the accuracy cores. So far, I haven't done anything that would
detriment speed, but it is certainly cool. The APU ports exposed by the
CPU and SMP now take uint2 address arguments, the CPU WRAM address
register is a uint17, and the IRQ H/VTIME values are uint10. This
basically allows the source to clearly convey the data sizes, and
eliminates the need to manually mask values when writing to registers or
reading from memory. I'm going to be doing this everywhere, and it will
have a speed impact eventually, because the automation means we can't
skip masks when we know the data is already masked off.
Source: archive contains the launcher code, so that I can look into why
it's crashing on XP tomorrow.
It doesn't look like Circuit USA's flags are going to work too well with
this new CPU core. Still not sure what the hell Robocop vs The
Terminator is doing, I'll read through the mega SNES thread for clues
tomorrow. Speedy Gonzales is definitely broken, as modifying the MDR was
breaking things with my current core. Probably because the new CPU core
doesn't wait for a cycle edge to trigger.
I was thinking that perhaps we could keep some form of cheat codes list
to work as game-specific hacks for the performance core. Keeps the hacks
out of the emulator, but could allow the remaining bugs to be worked
around for people who have no choice but to use the performance core.
2010-08-16 09:42:20 +00:00
|
|
|
add_clocks(16);
|
2015-12-06 21:11:41 +00:00
|
|
|
for(uint i = 0; i < 8; i++) {
|
2010-08-11 00:40:59 +00:00
|
|
|
if(channel[i].hdma_enabled == false || channel[i].hdma_completed == true) continue;
|
|
|
|
channel[i].dma_enabled = false;
|
|
|
|
|
|
|
|
if(channel[i].hdma_do_transfer) {
|
2015-12-06 21:11:41 +00:00
|
|
|
static const uint transfer_length[] = {1, 2, 2, 4, 4, 4, 2, 4};
|
|
|
|
uint length = transfer_length[channel[i].transfer_mode];
|
|
|
|
for(uint index = 0; index < length; index++) {
|
|
|
|
uint addr = channel[i].indirect == false ? hdma_addr(i) : hdma_iaddr(i);
|
2010-08-11 00:40:59 +00:00
|
|
|
dma_transfer(channel[i].direction, dma_bbus(i, index), addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
for(uint i = 0; i < 8; i++) {
|
2010-08-11 00:40:59 +00:00
|
|
|
if(channel[i].hdma_enabled == false || channel[i].hdma_completed == true) continue;
|
|
|
|
|
|
|
|
channel[i].line_counter--;
|
|
|
|
channel[i].hdma_do_transfer = channel[i].line_counter & 0x80;
|
|
|
|
hdma_update(i);
|
|
|
|
}
|
2010-08-12 00:39:41 +00:00
|
|
|
|
|
|
|
status.irq_lock = true;
|
2010-08-11 00:40:59 +00:00
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::hdma_init() -> void {
|
|
|
|
uint channels = 0;
|
2010-08-11 00:40:59 +00:00
|
|
|
for(unsigned i = 0; i < 8; i++) {
|
|
|
|
channel[i].hdma_completed = false;
|
|
|
|
channel[i].hdma_do_transfer = false;
|
|
|
|
if(channel[i].hdma_enabled) channels++;
|
|
|
|
}
|
|
|
|
if(channels == 0) return;
|
|
|
|
|
|
|
|
add_clocks(16);
|
2015-12-06 21:11:41 +00:00
|
|
|
for(uint i = 0; i < 8; i++) {
|
2010-08-11 00:40:59 +00:00
|
|
|
if(!channel[i].hdma_enabled) continue;
|
|
|
|
channel[i].dma_enabled = false;
|
|
|
|
|
|
|
|
channel[i].hdma_addr = channel[i].source_addr;
|
|
|
|
channel[i].line_counter = 0;
|
|
|
|
hdma_update(i);
|
|
|
|
}
|
2010-08-12 00:39:41 +00:00
|
|
|
|
|
|
|
status.irq_lock = true;
|
2010-08-11 00:40:59 +00:00
|
|
|
}
|
|
|
|
|
2015-12-06 21:11:41 +00:00
|
|
|
auto CPU::dma_reset() -> void {
|
|
|
|
for(uint i = 0; i < 8; i++) {
|
2010-08-11 00:40:59 +00:00
|
|
|
channel[i].dma_enabled = false;
|
|
|
|
channel[i].hdma_enabled = false;
|
|
|
|
|
2010-08-20 13:01:32 +00:00
|
|
|
channel[i].direction = 1;
|
|
|
|
channel[i].indirect = true;
|
|
|
|
channel[i].unused = true;
|
|
|
|
channel[i].reverse_transfer = true;
|
|
|
|
channel[i].fixed_transfer = true;
|
|
|
|
channel[i].transfer_mode = 0x07;
|
2010-08-11 00:40:59 +00:00
|
|
|
|
2010-08-20 13:01:32 +00:00
|
|
|
channel[i].dest_addr = 0xff;
|
|
|
|
channel[i].source_addr = 0xffff;
|
|
|
|
channel[i].source_bank = 0xff;
|
2010-08-11 00:40:59 +00:00
|
|
|
|
2010-08-20 13:01:32 +00:00
|
|
|
channel[i].transfer_size = 0xffff;
|
|
|
|
channel[i].indirect_addr = 0xffff;
|
2010-08-11 00:40:59 +00:00
|
|
|
|
2010-08-20 13:01:32 +00:00
|
|
|
channel[i].indirect_bank = 0xff;
|
|
|
|
channel[i].hdma_addr = 0xff;
|
|
|
|
channel[i].line_counter = 0xff;
|
|
|
|
channel[i].unknown = 0xff;
|
2010-08-11 00:40:59 +00:00
|
|
|
|
|
|
|
channel[i].hdma_completed = false;
|
|
|
|
channel[i].hdma_do_transfer = false;
|
|
|
|
}
|
|
|
|
}
|