Last night I got stuck on a silly problem. I was trying to add an array of item colors before my graphics definitions:
ItemColors ;This is the new array
.byte #$44
.byte #$44
.byte #$44
.byte #$44
.byte #$44
.byte #$44
.byte #$44
.byte #$44
.byte #$44
.byte #$44
.byte #$44
.byte #$44
.byte #$44
.byte #$44
.byte #$44
.byte #$44
.byte #$44
ItemGfx
.byte #%00000000;--
None
.byte #%00000000;--
.byte #%00000000;--
.byte #%00000000;--
.byte #%00000000;--
.byte #%00000000;--
.byte #%00000000;--
.byte #%00000000;--
.byte #%00000000;--
KeyIcon
.byte #%00001100;--
.byte #%00001000;--
.byte #%00001100;--
.byte #%00001000;--
.byte #%00001000;--
.byte #%00011100;--
.byte #%00010100;--
.byte #%00011100;--
...etc
The ItemGfx array was already there, with many more item graphic definitions following it. Everything worked fine. But when I added that ItemColors array, suddenly my items wouldn't appear anymore once the enemies were killed in a room! It wasn't even referencing the ItemColors array anywhere. And I was looking up ItemGfx by the label, so it shouldn't have mattered if it was offset by a few bytes. I even fired up the debugger to verify -- the item graphics were still being properly loaded. I removed the array just to double check, and it started working again. I spent a good hour and a half stepping through on Stella's incredible debugger trying to figure out what was going on.
Turns out, it was a bug in a different section of code. Thanks to a suggestion from yllawwally, I'm storing a position for each room layout that things (items) can spawn in. That gets specified in an array immediately after the itemGfx arrays:
SafeSpawnX
.byte #100
.byte #100
SafeSpawnY
.byte #30
.byte #30
Well, it turns out that my code to read those spawn arrays was buggy, and I never noticed. It wasn't actually reading those arrays, but instead some unintended byte at some random address that happened to be in the middle of the itemGfx array (not really "random", because it was the same byte every time, but random in the sense that the selection was made by the nature of the bug, not on purpose). I just lucked out that it happened to be a reasonable value that wasn't so far off from my hardcoded safe value, so I never noticed. Until I inserted a few more bytes before, meaning I was now hitting a new "random" value, which didn't have the magic coincidence of working.
Sheesh.
Anyway, I'm back on track now. I'm currently sidetracked playing with trying to move some code to bank 2, and reducing the amount of space my code takes up -- I realized I only have about 700 bytes of space left in bank 1, and I have a lot more I'm hoping to put there. At the current rate, I won't have space for the game as designed, unless I manage to move a lot to bank 2 and trim things up a bit. Or switch and use a different bankswitching mechanism. We'll see.
No comments:
Post a Comment