Debugging Quikman+

You need an actual VIC.

Moderator: Moderators

Post Reply
rhurst
Omega Star Commander
Posts: 1371
Joined: Thu Jan 31, 2008 2:12 pm
Website: https://robert.hurst-ri.us
Location: Providence, RI
Occupation: Tech & Innovation

Debugging Quikman+

Post by rhurst »

I ran into this obscure bug and wanted to share my experience hunting it down using the wonderful debugging features found in emulators. I did this particular session using the M.E.S.S. debugger, but later discovered I could have used VICE to do the same thing -- so use whatever emulator you're more comfortable with. But for this post, I will demo how I found my bug using M.E.S.S. and the concepts should be very similar if using VICE:
From a console window:

Code: Select all

mess -debug -window vic20 -ram 16k -quik quikman+8k.prg
Image
This starts the emulator up and BREAKS to a separate monitor window immediately. If your workstation is fast (like mine), use the debug window's menu or press F5 to allow the emulator to run, but keep the debug window(s) open (they refresh very quickly, so I believe the default is at every VBLANK). IF you find the emulator is running too slowly with the debug window open, press F12 and you can always interrupt the session using the back quote (`) hot-key (not documented there, but useful).

I like to open a memory window, use the debug window's menu or press Ctrl-M, to watch for changes to address spaces that hold my program's variables, in this case, FLEEINGSCORE was being saved at location $70. All of MESS debugging windows are very flexible and allows for edits as well.
Image<-- you can see the leftover BYTES FREE result on the stack

In the debug window, there is a bottom command-line interface box (with convenient command recall using the uparrow). From there, enter:

Code: Select all

help
You get a nice menu of help topics, so I next picked:

Code: Select all

help watchpoints
... which led me to:

Code: Select all

help wpset
After reading its syntax and examples, I entered:

Code: Select all

wpset $70,1,w
Later, I would realize later it would have been more efficient if I extended that command to use a conditional modifier ,wpdata==0. Press F5 to continue running.
It was interesting (and annoying) that when I typed LIST to see if Quikman+ was loaded into memory, how many times that triggered $70 to go off from the VIC ROM routines. So the use of wpdisable / wpenable becomes obvious if you need to narrow down WHEN you want that event to fire. So I typed wpdisable and will wait until this session is nearer to when this scoring bug occurs.

Since MESS only auto-loads the binary into memory, I typed RUN to start Quikman+. Press F1 twice to start a single player game using the original maze, and start playing until I reached 9,000+ points. That's where the fun begins...

I played and reached a good score of 9190 points on the cherry level, with one power pill remaining. I pressed the back quote (`) key to enter the debug window, so I could wpenable to activate any WRITEs to $70. At this point, I see $70 is holding a value of $10, because I only ate 3 blue ghosts from the last power pill -- good, that's what it should be. I press F5 to continue the game.

Now, my play at this point is getting a little jittery, because I want to get the "bug" to reveal itself, and it only occurs when I reach a score of 10,000+ (rewarded an extra life), and then eating any blue ghost during that power pill phase results in a ZERO bonus score. M.E.S.S. does not have a hotkey to slowdown (only pause, with a single frame advance) the action, so I had to be a little nimble at this point. Of course, I could have started the emulator to run at a slower speed setting, but fortunately, I did not need to resort to that. Five years from now, maybe . . .

Anyways, I eat a blue ghost (+400) that will put me over the 10,000 points. The debugger kicks in because it ASL $70 for the next blue ghost (+800); I press F5, but it immediately comes back to the debug window -- and $70 shows a new value of $05. Woot -- I ran into the bug!

It turns out that when the event goes to update the player's score, it is within that subroutine that it checks to see if the score breaks the 10,000 point barrier. If it does, then it needs to award a bonus life -- and reflect that event on the display with an additional Quikman icon. Since the call to THAT subroutine writes to VIC's display at line #24, it uncovers my bad math.

I maintain an array of "dirty" lines, so that frame-flipping is optimized by only transferring bytes/color into the new frame that changed on the playfield buffer from the previous flip. That DIRTYLINE2 array starts at $59. Well, add 23 ($17) to that and you get $70 -- which is the same address that occupies FLEEINGSCORE.

As I do not write to line #24 (usually) in the main loop, because I only need to update it when you advance to the next level, this bug will not occur, making it very hard to reproduce (if you noticed it at all). So ONLY when you break 10,000 points and ONLY if you have the opportunity to catch another blue monster for THAT power pill will $70 get reset to zero... and any subsequent catches on that power pill are also zero, because ASL $70 of a zero is still a zero. Eating another power pill resets the bonus scoring to $02, so the bug never gets repeated in the same game.

Fini.
Last edited by rhurst on Sat Aug 14, 2010 8:31 am, edited 1 time in total.
Any technology distinguishable from magic is insufficiently advanced.
https://robert.hurst-ri.us/rob/retrocomputing
User avatar
robinsonmason
Vic 20 Enthusiast
Posts: 195
Joined: Sun Mar 14, 2010 9:17 pm

Post by robinsonmason »

Very cool read, thanks!

I was just playing Vicman in the online section and it's a great port, very enjoyable.
Post Reply