BydoEmpire Posted March 20, 2022 Share Posted March 20, 2022 So just thinking out loud... I was banging my head on the keyboard for a couple days on this bug, so even though I got it working (see below) I don't really understand why. When I moved my tilesets and room setup code into different banks for different levels I saw a bug where the top 12 pixels were cutoff: when I moved the hero sprite around, even more pixels in the top rows of tiles were cutoff bank1 - no gfx, just common setup & control code, MovePlayer, the main loop, etc bank2 - tileset and sprites for a forest level bank3 - tileset and sprites for a castle level ... bank16 - the hero sprite, common background routines (poking chars into currentmapdata buffer), "default" tileset (in theory unused), fonts, etc Then I realized maybe it's drawing those rows from bank 1, and sure enough I put a default tileset & fonts at the start of bank 1 (where the tilesets are inc'd for banks 2 & 3) and then I saw those bank1 tiles being drawn for the rows in question: I supposed it makes sense that while you're moving the player around more code is being executed, so more rows from bank 1 are being drawn. I'm not sure why that is. I don't restore screen until after MovePlayer is complete, and the restore/draw calls are all (now) from within whatever bank is being used. Seemed like I need some kind of wait before it actually draws the screen. Here is the main loop, which is in bank 1. Bank1_MainLoop_Control rem ** control and input gosub Bank1_MovePlayer Bank1_MainLoop_Draw rem ** draw level-specific sprites if cur_level=2 then gosub Bank2_DrawScreen bank2 if cur_level=3 then gosub Bank3_DrawScreen bank3 rem ** if we've moved to a new level, set that up and restart if goto_level <> cur_level then goto Bank1_InitNewLevel goto Bank1_MainLoop And the screen drawing bank2 (bank3 has an equivalent): Bank2_DrawScreen rem ** restore background first restorescreen rem ** draw bank-specific sprites gosub Bank2_DrawEnemies bank2 rem ** draw general graphics (Bank16) gosub Bank16_DrawHero gosub Bank16_DrawStatus drawscreen return Sticking a drawwait after drawscreen fixed the bug, but not if I move the restorescreen & drawscreen back into the main loop where I originally had it. It only worked if I called restorescreen / drawscreen from bank 2 or 3. I suppose it makes sense, is that expected? Since I use plot* commands to draw sprites at the end of the frame, it seemed like that would be unnecessary. I don't really understand what it's doing. Happy the bug is fixed, but I don't like not really knowing why. I think the real issue is that I don't quite understand what's being executed across the frame, and what overlaps with the actual drawing. It didn't matter in a 48k game... Sorry for the rambling, I actually fixed (or worked around) the bug as I was iterating on this post. It's helpful to try to explain it. 2 Quote Link to comment Share on other sites More sharing options...
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.