It's not a hack. DMC DMA takes a different length depending on where they land during the OAM DMA.
Though I thought the last few cycles were 1,2,3 ... not 2,1,3. Lemme find that page.
EDIT: Here's the post:
viewtopic.php?p=62690#p62690blargg wrote:
DMC DMA adds 4 cycles normally, 3 if it lands on a CPU write, 2 if it lands on the $4014 write or during OAM DMA, 1 if on the next-to-next-to-last DMA cycle, 3 if on the last DMA cycle.
So:
last cycle = 3 cycles
next-to last cycle = 2 cycles
next-to-next-to-last cycle = 1 cycle
so the last 3 DMC runs in Zepper's code should be 1,2,3 -- not 2,1,3
Though the wiki makes no mention of this and just says it's 2 cycles throughout the entirety of OAM DMA. Which is correct?
EDIT 2: I'm still not convinced reading from PC is correct for the dummy cycles. I guess it could be, but $4014 still makes more sense to me.
blargg's post suggests that the OAM DMA process starts
on the 4014 write cycle (since that's in the '2 cycle' zone), and if that's true it would mean 4014 would still be on the address bus, and the DMA unit would have no reason to put the PC back on the bus.
So either:
1)
- CPU puts PC on address bus before DMA starts (possibly as part of pipelining for the next instruction)
- DMA cuts in, reads dummy value(s) from PC (since that's what on the bus)
- DMA does it's thing
- DMA restores PC on address bus so that normal CPU execution is uninterrupted
- normal CPU execution resumes with the next opcode read
or
2)
- DMA cuts in while 4014 is still on the bus, before PC is put back on the bus
- dummy values read from whatever is on the bus (which would be 4014)
- DMA does it's thing
- DMA does not need to restore the PC because the PC was never put on the bus in the first place
- normal CPu execution resumes... and NOW the PC is placed on the bus for the next opcode read
or
3)
- something else
I just find scenario 2 much more likely than scenario 1.... but that's a total guess and I have zero evidence to back it up.