MEGA65 / mega65-core

MEGA65 FPGA core
Other
237 stars 84 forks source link

TI drifts in NTSC mode #733

Open dansanderson opened 9 months ago

dansanderson commented 9 months ago

Test Environment (required) Platform: MEGA65 ROM Release: 920385 Core Commit: cae3b0b

Describe the bug The TI timer variable counts inaccurately in NTSC mode.

To Reproduce

5 T=TI
10 ?TI-T:GOTO 10

Run this along with a stopwatch. In PAL mode, it matches. In NTSC mode, it drifts by about a second per minute.

Additional context This was originally filed as https://github.com/MEGA65/mega65-rom-public/issues/78 to research whether the ROM is setting registers correctly. We fixed an issue where TOD50 was not being set correctly in NTSC mode, but this didn't fix the drift, and would not have adequately explained the drift anyway. I don't know enough about expected behavior of the CIA to know if this is a core issue, but I don't have any active leads on changes that could be made in the ROM, so I'm creating a corresponding core issue for further research.

lydon42 commented 6 months ago

Something seems to be wrong here... if I change NTSC/PAL with freezer, then do clr ti, I always end up with 193 in DD0E. This seems to be wrong. Tested with development head and 920385.

Edit: and I know that TOD50 does work, as I discovered the problem while working on RTC tick detection in freezer...

lydon42 commented 6 months ago

And it's 50Hz vs. 60Hz, which means if you have the wrong TOD50 setting you should be loosing a just over a second every ten seconds (this is what I was seeing in my 14 sec RTC tick test).

lydon42 commented 6 months ago

In freezer TOD50 is manipulated correctly. The freezer switch function also manipulates frozen memory... but when I exit freezer, the restored system again has the old settings... but CIAs are saved to frozen memory, so it should be possible to manipulate them.

What confuses me is that ROM seems to set CIA1 and CIA2 TOD50 differently. Or is CIA1 not used as a timer and because of this the flag has no meaning?

dansanderson commented 6 months ago

I only see references to CIA2 in the ROM code for TI, I don't know why.