Thursday, 15 July 2010

BSOD 2 - The Tweakening

I was debugging a little bit of code last night, and dropped a BRK instruction into the code to trigger the BSOD routine so I could see whether the registers contained what I thought they should. At which point STROUT bit me in the behind again.

You might remember that I used this ROM routine to generate the BSOD display, and subsequently wrote CHARPLOT because it wasn't fast enough to draw the games' playfield screen - that exercise has been wholly successful, resulting in a nice chunk of code that's fast and flexible enough to let me draw the playfield instantly, as well as act as the 'engine' for moving things around during gameplay. I didn't bother going back to convert BSOD to use CHARPLOT because it just writes lines of text to the screen when the CPU hits a BRK instruction - at that point, speed is irrelevant because we're in a failure scenario and just displaying the wreckage.

However, my Zero Page usage has gone up recently to more than double the previous high-water-mark - I'm now using almost 30 bytes, and there will definitely be more added before I'm done. The thing about Zero Page is, it's used extensively by the BASIC and KERNAL ROMs - which is not a problem when you're in pure Assembly mode and not using any ROM routines which have ZP dependencies, but can be a headache if you happen to call a routine which, in turn, needs some ZP location you've overwritten with game data. Like, for example, STROUT - which evidently relies on something in those first 30 bytes of ZP that I have appropriated for the game. Consequently, when BSOD gets invoked and starts making calls to STROUT, all manner of nasty things now happen and the CPU gets shunted off into the weeds somewhere - VICE pops up an alert telling me everything has gone pear-shaped, and the BSOD never appears.

I could trace through STROUT and figure-out what it's getting upset over, and then leave whatever byte(s) of Zero Page it needs alone - but actually, I don't really want to, because that would leave me with 'holes' in my ZP map which are only there because STROUT sulks otherwise. And of course STROUT is only being called by BSOD, which in the 'release' version of the code won't even be there (I use a conditional assembly directive to include BSOD in the 'debug' version of the code, and leave it out of the 'release' version). So I'm now back in the innards of the code converting it to use CHARPLOT instead.

Some days it feels like 2 steps forward, 1.97 back...

0 comments:

Post a Comment