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 > Problem getting my game to diplay correctly [Renamed]

#149361 - HubbubJub - Sat Jan 19, 2008 1:45 am

Hi, I've just been playing around with a small game for a few days, and I've been having trouble getting it to display correctly. I've been using the swiWaitForVBlank() function that I've seen in a few tutorials, but it doesn't seem to be doing the right thing for me...

Code:
swiWaitForVBlank();

// Clear console.
consoleClear();
      
// Clear background.
for(i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++)
   VRAM_A[i] = BG_COLOR;


This code is at the end of my main game loop. There are a few printf functions that write at the beginning of the loop, but I never see them (I'm assuming because the console is cleared too often/quickly). Also, the top third of my main screen is always black, which I'm assuming is the fault of the background clear not being synchronized with the drawing. I've been reading a bunch of tutorial but I can't seem to figure out how to get everything to display correctly. Thanks in advance!

#149366 - gmiller - Sat Jan 19, 2008 5:25 am

Just remember that the wait for VBlank starts your code running at the beginning of VBlank but if the time that the code takes to do it business is longer than the VBlank period you will be writing to VRAM while the hardware is drawing ....

You can do the clear of the screen or set it to a single color with a single DMA. The loop may take too long.

#149371 - HubbubJub - Sat Jan 19, 2008 9:13 am

Is there a faster way to clear the screen than the loop? And how, if so? And how does the DMA work? Thanks.

#149383 - HubbubJub - Sat Jan 19, 2008 12:43 pm

Actually, I fixed it! (In case anyone was wondering, I used memset(VRAM_A, 0, SCREEN_WIDTH*SCREEN_HEIGHT << 1). Not sure why I had to multiply it by two though -- if anyone could shed some light on that that would be awesome.)

#149385 - tepples - Sat Jan 19, 2008 1:21 pm

But does the screen really need to be cleared every frame? Can you describe what you are drawing, in such a way that explains why the screen needs to be cleared every frame?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#149391 - dovoto - Sat Jan 19, 2008 2:31 pm

HubbubJub wrote:
Actually, I fixed it! (In case anyone was wondering, I used memset(VRAM_A, 0, SCREEN_WIDTH*SCREEN_HEIGHT << 1). Not sure why I had to multiply it by two though -- if anyone could shed some light on that that would be awesome.)


Each pixel in fram buffer is 16 bits (2 bytes) while memset takes a byte count as its size specifier.

That out of the way, dont spend a lot of time trying to get your frame buffer stuff working well or efficiently. The frame buffer is not reall there for general purpose graphics.

The DS has a fairly impressive aray of interesting 2D hardware that handles the majority of rending for you (static and moving backgrounds, objects which float above / below / between the backgrounds) and errasing vram is never needed when the 2D hardware is employed.
_________________
www.drunkencoders.com