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.

Coding > issue with text bg

#20791 - Darmstadium - Mon May 17, 2004 11:34 pm

I'm encountering something that's weird. Ok, I have this 256x256 text bg. Ok, it shows up great, but when I try to move it by changing REG_BG0HOFS, it makes a huge jump and won't move anymore. Here is my code:
Code:

#include "gba.h"
#include "dispcnt.h"
#include "keypad.h"
#include "bg.h"
#include "dma.h"

#include "tiles.raw.c"
#include "tiles.pal.c"

#define BG_PALETTE(p)         ((u16*)(0x5000000+p))

int main()
{
   const int screenblock = 8;
   const int charblock = 0;
   REG_DISPCNT = MODE_0 | BG0_ENABLE | OBJ_MAP_1D;
   REG_BG0CNT = TEXTBG_SIZE_256x256 | (screenblock << SCREEN_SHIFT) | (charblock << CHAR_SHIFT) | BG_COLOR_16;
   REG_BG0HOFS = 8;
   REG_BG0VOFS = 8;
   
   int loop;
   for (loop = 0; loop < 32*32; loop++)
      ScreenBaseBlock(screenblock)[loop] = test[loop];
   
   
   REG_DM3DAD = (u32)CharBaseBlock(charblock);
   REG_DM3SAD = (u32)tiles_Bitmap;
   REG_DM3CNT = 384 | DMA_ENABLE | DMA_TIMEING_IMMEDIATE | DMA_32;
   
   for (int loop = 0; loop < 16; loop++)
      BG_PALETTE(0)[loop] = tiles_Palette[loop];
   
   while (1)
   {
      if (KEYDOWN(KEY_LEFT))
         REG_BG0HOFS -= 1;
      if (KEYDOWN(KEY_RIGHT))
         REG_BG0HOFS += 1;
   }
}


Thanks for your help

#20792 - gadget - Mon May 17, 2004 11:42 pm

I believe at least one of your problems is the code.
if (KEYDOWN(KEY_LEFT))
REG_BG0HOFS -= 1;
if (KEYDOWN(KEY_RIGHT))
REG_BG0HOFS += 1;

The scrolling registers are not able to be read from, only written to so doing a plus/minus 1 won't work. Keep track of the amount of scrolling performed in a variable and increment the value there. Each frame then copy the value in the variable into the background register.

--Wendy

#20793 - poslundc - Mon May 17, 2004 11:44 pm

Also, your code is going much too fast. In a single second you are checking the buttons and updating the background position about a million times or so.

Try waiting for VBlank in your while loop. At least that will slow it down to only 60 times per second.

Dan.

#20795 - Darmstadium - Tue May 18, 2004 12:18 am

i had no idea u couldn't do that. Thanks a lot for your help guys!

#20798 - dagamer34 - Tue May 18, 2004 1:39 am

Take a look at the CowBite spec. The easily tell you which registers you can read and/or write to.
_________________
Little kids and Playstation 2's don't mix. :(