gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Changing VRAM banks between vcount values

#142005 - Rajveer - Wed Oct 03, 2007 12:32 am

What's the best way to do this? I have a function to reload a texture into vram which uses the following code to unlock vram, load a texture, and lock vram within vcount values 192 and 214:

Code:
while((REG_VCOUNT < 192) || (REG_VCOUNT > 200))
   {}
   if((REG_VCOUNT >= 192) && (REG_VCOUNT <= 200))
   {
      unlock banks, load texture, lock banks
   }


However it seems as if it misses 192-200 frequently, turning my textures into coloured blobs :S Would I wait for an interrupt? How would I do this?

P.s. reason I used 192-200 instead of 214 is to give me enough time to actually do the copy before 214 comes around.

#142022 - DiscoStew - Wed Oct 03, 2007 6:31 am

Are you waiting for VBlank to start? Pretty much when you make the swi call to wait for the VBlank, non-interrupt control will be lost until after the screen is refreshed, and at that time, you'll end up at 192 for REG_VCOUNT.

If you've got stuff happening after the start of the VBlank, but before you get to this point in your code, you may end up doing enough processing that will have REG_VCOUNT end up greater than 200, of which according to your code, would just skip the bank/texture code and continue on.

You can use interrupts for this. A simple one would be to set the VBlank interrupt to a function to call each time the hardware gets to the VBlank.

A simple set up for this would be like this with libnds...

Code:
irqInit();
irqSet(IRQ_VBLANK, VblankHandler);
irqEnable(IRQ_VBLANK);


'VBlankHandler'' is a function, and just placing your bank/texture stuff in there should be enough.
_________________
DS - It's all about DiscoStew

#142032 - Rajveer - Wed Oct 03, 2007 3:10 pm

Replacing my code with a swiWaitForVBlank(); always gives me REG_VCOUNT 192 to start off with now. Also there is no flickering on textures now so I'm assuming that it loads everything within the time (actually it starts at 192 and finishes at 209). However, something else is flickering, a large untextured quad I'm using as the background: other places with textures loaded don't flicker at all. And even when only unlocking and locking VRAM without any other code within this time makes the quad flicker. As a test I disabled the quad and used ClearColor to not black, which works perfectly. I also rendered a texture to the quad resulting in no flicker, so any idea why that quad was flickering?