I have implemented APU emulation for ffnes.
After run some of APU test rom, I found there are lots of timing issue of my APU emulation.
run 4-jitter.nes, it says:
Frame irq is set too soon
4-jitter
Failed #2
As I known, The Frame sequencer's divider generates an output clock rate of just under 240 Hz, may be 21.47727 MHz master clock, divided by 89490. My implemention of apu, I using ppu clock, which is divided by 4 of master clock, to clock the divider, instead of master clock.
so I using 21477272 / 4 / 240 = 22372.158333333333333333333333333 = (int)22372 as the period of Frame sequencer divider.
I checked all related code of apu, could't found any problem, except the period of Frame sequencer divider, which is not divisible but using 22372 approximately instead.
If I use 22372 + 1 instead of 22372, then run the 4-jitter.nes, it says:
Odd jitter not handled
properly
4-jitter
Failed #5
We can see the test result is related to the period, when change the period, test result will be changed. so.
I think the divider period is the root cause. Anyone could help me to explain the details of the timming, and the real root cause of this issue.
And also give me a method how to fix this issue.
Thanks.
After run some of APU test rom, I found there are lots of timing issue of my APU emulation.
run 4-jitter.nes, it says:
Frame irq is set too soon
4-jitter
Failed #2
As I known, The Frame sequencer's divider generates an output clock rate of just under 240 Hz, may be 21.47727 MHz master clock, divided by 89490. My implemention of apu, I using ppu clock, which is divided by 4 of master clock, to clock the divider, instead of master clock.
so I using 21477272 / 4 / 240 = 22372.158333333333333333333333333 = (int)22372 as the period of Frame sequencer divider.
I checked all related code of apu, could't found any problem, except the period of Frame sequencer divider, which is not divisible but using 22372 approximately instead.
If I use 22372 + 1 instead of 22372, then run the 4-jitter.nes, it says:
Odd jitter not handled
properly
4-jitter
Failed #5
We can see the test result is related to the period, when change the period, test result will be changed. so.
I think the divider period is the root cause. Anyone could help me to explain the details of the timming, and the real root cause of this issue.
And also give me a method how to fix this issue.
Thanks.