Jump to content
SpiceWare

using Stella's debugger to analyze VSYNC

Recommended Posts

Yesterday @ckrtech contacted me for insight on an issue he's having with Battlezone and his new RetroTINK 5X-Pro video upscaler. The picture is unstable, as you can see in the video he tweeted this afternoon:

 

 

I suspected it was generating an invalid VSYNC signal. From Stella Programmer's Guide, available at MiniDig, we know that VSYNC should last 3 scanlines:

 

1139648706_ScreenShot2021-05-04at6_52_16PM.thumb.png.cb9a2ae0fd7f6240c052b62eab8e20be.png


So I used Stella to check it out. Sure enough, it was just over 2 scanlines long, and had a couple other issues as well.  After sending him the results I got to thinking that others may find it useful to see how to check this.

 

 

We'll start off this investigation with Combat because it correctly generates VSYNC.

 

Launch Stella and load Combat.

1484164227_ScreenShot2021-05-04at7_54_54PM.thumb.png.81908d53e835756367b252a1ef460514.png


Press the ` key (by 1 and tab) to enter Stella's Integrated Debugger. In the prompt type the command: trapwrite VSYNC

after hitting return you should see: added trap 00

 

912541691_ScreenShot2021-05-04at6_36_51PM.thumb.png.31465c625d5b29af10ea46f1cd7ab88c.png

 

press the ` key again to resume running the ROM. The trap should immediately return you to the debugger:

550280430_ScreenShot2021-05-04at6_37_56PM.thumb.png.6b91804032dedb0220ed7321bce72d6c.png


Make note of:

  • Frame Cycles: 19760
  • Scan Cycle: 3

 

VSYNC should be changed just after the WSYNC, so it should always occur on Scan Cycle 3.

 

Press the ` key again.

 

459803659_ScreenShot2021-05-04at6_41_33PM.thumb.png.cedb0135879e73421acf92eba148477a.png

 

Frame Cycles is now 0 because the new frame just started. 

 

This is useless to determine the number of cycles that elapsed for the VSYNC, so we need to halt the program before the 2nd store to VSYNC occurs. To do that, locate the current instruction in the Disassembly tab, it will be outlined in a red box, then click to the left of the store to VSYNC just above it. A red dot will appear to show the breakpoint is set:

 

998761671_ScreenShot2021-05-04at6_41_48PM.thumb.png.ad014a1fe65a8161b73ae6a8dd446887.png

 

Hit ` again, should see the same Frame Cycles (19760) you saw before.

Hit ` again:

 

230470510_ScreenShot2021-05-04at6_47_39PM.thumb.png.f837fde7faadb228aaa87414f21458f8.png

 

Frame Cycles: 19985
Scan Cycle: 0

 

The store to VSYNC hasn't yet occurred, so we need to know how long the instruction is going to take.  We can see that it's 3 cycles by looking at the value after the ; in the Disassembly.  Adjusting for that we know the cycles after sta VSYNC occurs will be:

 

Frame Cycles: 19988
Scan Cycle: 3


19988 - 19760 = 228.

 

There are 76 cycles per scanline and 3 * 76 = 228 so VSYNC was on for exactly 3 scanlines, which is what we expect it to be.

 


Now we'll do the same after loading Battlezone:

 

708603101_ScreenShot2021-05-04at8_03_52PM.thumb.png.5912e763379048e7ae5ee41804ce2784.png

 

As before:

  • Press the ` key to enter the debugger
  • type the command trapwrite VSYNC
  • press ` again

 

678330186_ScreenShot2021-05-04at7_15_13PM.thumb.png.5fd883b4196d03db6ccd13dfb7cc7716.png

 

Frame Cycles: 19743
Scan Cycle: 64

Scan cycle of 64 is not good, it should be 3.  We can see in the disassembly it was not done after a sta WSYNC.


press the ` again, we'll end up with Frame Cycles of 0. Like before, set a breakpoint on the sta VSYNC instruction

 

57331410_ScreenShot2021-05-04at8_06_52PM.thumb.png.4da805496b89d0552b86433a0c8dd561.png

 

press ` again.

 

130489299_ScreenShot2021-05-04at7_20_22PM.thumb.png.75c4c9f0afeaaf21f184a9bc4436b913.png

Surprise!

 

Frame Cycles: 19741 - was expecting 19743 like before
Scan Cycle: 62 - was expecting 64 like before

 

Inconsistency is not good.

 

press ` again.

 

120601714_ScreenShot2021-05-04at7_21_48PM.thumb.png.9cc0b1df2818233a9c3c4f034b7d25d7.png

Frame Cycles: 19909
Scan Cycle: 2

the sta VSYNC cycle time is 3, so adjust to:


Frame Cycles: 19911
Scan Cycle: 5

 

19911 - 19743 = 168
19911 - 19741 = 170

168 / 76 = 2.21 scanlines
170 / 76 = 2.24 scanlines


If you hit ` a number of additional times you'll see the Frame cycles for the initial VSYNC varies from 19739 - 19745, so actual VSYNC duration varies from to 166 to 172 cycles. 

 

615877739_ScreenShot2021-05-04at7_25_39PM.thumb.png.ef28a312fe572d2023297309ac727cb8.png

 

1861947020_ScreenShot2021-05-04at7_25_20PM.thumb.png.e6b4223f8e48e3d788bdb53852b1d921.png

 

 

So Battlezone does a few things wrong when setting VSYNC:


1) VSYNC is on for less than 3 scanlines 
2) VSYNC is toggled at the wrong cycle for the scanline, it should occur on cycle 3
3) VSYNC duration varies slightly over time


I don't know which of these is causing problems with the RetroLINK 5X-Pro

  • Like 3

Share this post


Link to post
Share on other sites
Posted (edited)

Thanks. We lately had a similar problem when switching the ports for a QuadTari. 

 

Rule of thumb: When wanting to wait for N scanlines, you have to do N+1 WSYNCs (the extra one directly before or anywhere after starting the delay) to be 100% safe. 

Edited by Thomas Jentzsch
  • Like 1

Share this post


Link to post
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...