Smidge Posted November 19, 2021 Share Posted November 19, 2021 I've been writing a 2600 emulator from scratch and using Stella's debugger mode to help track down some timing issues, and I noticed something odd with how Stella handles the RIOT timer after it is initialized. In the game Dolphin, TIM64T is initialized to $30, and after the next instruction (LDY SWCHA, 4 cycles), the timer immediately decrements to $2f instead of holding the value $30 for 64 cycles. After that the timer is decremented every 64 cycles as expected. This I identified as the reason my emulator started drawing the first non-garbage frame of Dolphin one scan line later than Stella. I tend to trust that Stella is doing everything correctly, but is this actually the right behavior? To add more background, here is the relevant segment of code from Dolphin: f647 LDA #$30 ;2 cycles f649 STA WSYNC ;3 cycles f64b STA TIM64T ;4 cycles f64e LDY SWCHA ;4 cycles Immediately after STA TIM64T (scan cycle = 4), Stella sets TIM64T and INTIM to $30 and resets TIMINT and Total Clks to 0. INTIM Clks is unchanged from its previous value of 1. Immediately after LDY SWCHA (scan cycle = 8), Stella decrements INTIM to $2f. TIMINT remains at 0. Total Clks is now 4, and INTIM Clks in $3d. I checked another game (Adventure) and observed the same behavior. So who's right, me or Stella? (Okay obviously Stella's right, but why?) Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted November 20, 2021 Share Posted November 20, 2021 AFAIK the timer is described that way in the tech documents. Quote Link to comment Share on other sites More sharing options...
Smidge Posted November 20, 2021 Author Share Posted November 20, 2021 Interesting, that means the example given in the Stella guide that setting TIM64T to 100 would cause the timer to take 6,400 cycles to reach 0 is inaccurate (it would need to be set to 101). I wrote a quick program to test this behavior on real hardware (source attached). It sets TIM64T to 1 and then immediately checks INTIM. If it's 0, the background is set to blue. Otherwise, it's set to red. I confirmed that in Stella and on real hardware the result is a blue screen. As expected my emulator incorrectly displays red, but it won't for long. timer-init-test.asm Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.