Jump to content
IGNORED

Should the RIOT timer decrement immediately after initialization?


Smidge

Recommended Posts

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?)

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...