qeed wrote:
does that mean if the CPU will still execute an IRQ if there is one set by DMC when the sample reading is done? (assuming that frame interrupt flag already set too, when $4015 reading takes place). Also I didn't quite understand what "At any time, if the interrupt flag is set, the CPU's IRQ line is continuously asserted until the interrupt flag is cleared. " meant. Could you please elaborate.
IRQs are "level triggered" which means that as long as hardware is asserting an IRQ, an IRQ will be "pending" and the CPU will IRQ as soon as it is able to. "Acknowledging" an IRQ is like telling the hardware to stop asserting the IRQ.
An easy way to abstract and visualize this is to imagine every IRQ-generating source has a "pending" flag. When an IRQ is tripped, all that happens is the Pending flag is set. When the IRQ is acknowledged, the Pending flag is cleared. And if at any time,
any Pending flag anywhere on the system is set, this indicates that the CPU should IRQ.
To clarify further:
Code:
void AcknowledgeFrameIRQ()
{
// called when APU Frame IRQ is acknowledged
frameirq_pending = false;
}
void TriggerFrameIRQ()
{
// called when an APU Frame IRQ has been triggered
frameirq_pending = true;
}
bool ShouldIRQ()
{
// called between instructions to see if the CPU should do an IRQ
if(frameirq_pending) return true;
if(dmcirq_pending) return true;
if(mapperirq_pending) return true;
if(anyotherirq_pending) return true;
return false;
}
This isn't practical code, of course. I'm just trying to illustrate the concept.
Note that the IRQ itself does not aknowledge any IRQs! Therefore if a game RTIs from an IRQ without acknowledging the IRQ, another IRQ will happen immediately because the same one is still pending.
Quote:
As for the DMC output unit, which register is the one that is playing, the 8 bit right shift register since it says the sample is 8 bit too, if that is the case, what does the delta counter do?
Basically... the contents of $4011
is the output of the DMC. Writes to $4011 immediately change the output of the channel.
The delta modulation reads bytes from ROM, and modifies $4011 (increasing or decreasing it by 2), which in turn changes the output, which is how samples are played.
Quote:
Finally, the $4011, when does the counter sometimes fail to be loaded by $4011, should i ignore the sometimes failing case in my emulator.
I wouldn't worry about this. I'd imagine there's edge cases when you try to write to $4011 when the delta modulation thing is accessing it -- but I don't think they've been completely worked out yet.
So don't worry about this.