miker00lz wrote:
ulfalizer wrote:
Are you setting the period counter to zero when $C001 is written? Do you reload it with the most recent value written to $C000 when it's clocked by the scanline counter while being zero?
I'd mark up lines where IRQs are being asserted and look at that along with a textual trace of MMC3 IRQs.
AH! I was doing this on write to $C000/$C001:
Code:
if (addr & 1) map4->irqcounter = 0;
else map4->irqlatch = value;
Changing it to this:
Code:
if (addr & 1) map4->irqcounter = map4->irqlatch;
else map4->irqlatch = value;
The old version before the change is what I have.
irqcounter is only ever reloaded from
irqlatch as the result of a clock from the scanline counter - never as a result of writing one of the MMC3 registers.
To be more specific,
irqlatch is copied to
irqcounter when you get a clock from the scanline counter and
irqcounter equals zero.
The fact that your change "almost" fixes things suggests something might be wrong with your scanline counting or reloading logic. Normally the value of
irqcounter would go
0, irqlatch, irqlatch - 1, ..., where the initial 0 is from the $C001 write and the decrements are from scanline clocks. In your version it'll go
irqlatch, irqlatch - 1, irqlatch - 2, ... instead, which probably is why it's off by one. I would check that the
0-to-irqlatch transition on the first scanline clock is working as expected first.