Elusive bug finally crushed!


Finally I have been able to fix this rare "direction stuck" bug. I thought I fixed it in V1.3, but the bug was much more elusive than I initially thought. Hold on, and let me take you through this journey :).

Every object in Spelunky64, when not carried, is plotted as a character onto the background. The lowest 4 bits of each character index matches its color, which enables fast colorram updates. However, for the shop items I ran out of suitable character/color index combinations. So in order to fix this I explicitly added a short routine to update the color of the shop items at the end of the generic screen_color_update routine. During the plotting of the character itself I already check whether the object is on screen, so that the "shop_item_color_update" routine doesn't need to check this again. However, when building the transition or title screen (i.e. when you died or went through the exit) I also run the generic screen_color_update routine, which then also triggers the "shop_item_color_update" routine. Since the title or transition screen is always plotted at the top of the levelmap, the position of the shop items relative to the screen can get messed up! Specifically when these shop objects are on screen when you are at the bottom of a level. And typically you are at the bottom of a level when you go through the exit.

And now comes the really tricky part. On the C64 there is a specific memory location allocated for the character colors: from $d800 to $dbe7. Following this colorram are IO registers of the CIA chip which, among other things, controls reading of the joystick ports. Now depending on what specific shop object is located on a specific screen position, its color can be written to memory beyond the actual colorram, specifically to the CIA IO registers! If by chance a specific value is written to $dc02, the data direction register for joystick port 2 can be adapted, effectively disabling the ability to readout specific joystick directions!

In the end I fixed this by simply not updating the shop item colors when building the title or transition screen. It took my quite some time to link this bug to the shop items color routine, but finally it was crushed. The game should be a lot more stable now!

Files

spelunky64_v1_4.zip 84 kB
40 days ago

Get Spelunky64

Buy Now$2.99 USD or more

Leave a comment

Log in with itch.io to leave a comment.