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.

Beginners > REG_BGxHOFS and REG_BGxVOFS

#17012 - ender7771 - Sat Feb 28, 2004 8:53 pm

Can somebody please paste the memory locatation these two registers should be at? My mode0 program will only scroll right and left, but not up and down. I think I have the wrong values for them. Thank you.

#17013 - poslundc - Sat Feb 28, 2004 9:48 pm

http://www.cs.rit.edu/~tjh8300/CowBite/CowBiteSpec.htm#Background%20Registers

Dan.

#17024 - ender7771 - Sun Feb 29, 2004 5:15 am

Thanks for the link, it has lots of useful information.

But, alas, I must ask for additional help. My mode0 scrolling program doesn't work completely. As mentioned, when fired up my image will only scroll left and right, but not up and down. I have copied word for word the source file from the demo (the Gba book in pdf that never went into print). The compiled example from the book supports both directions of scrolling, but because i don't have a paypal account I cannot aquire the direct source code. I have posted the code that I think is relevant to the problem, so could somebody please help me out? Thanks. I know the emulator is not the problem, as it can scroll up and down in the book's example, but not in mine. If you think other code is at fault, post and I will add to this.

Code:

#define REG_BG0HOFS *(volatile unsigned int*)0x4000010
#define REG_BG0VOFS *(volatile unsigned int*)0x4000012

#define BUTTON_RIGHT 16
#define BUTTON_LEFT 32
#define BUTTON_UP 64
#define BUTTON_DOWN 128
#define BUTTONS (*(volatile unsigned int*)0x04000130)

        if(!(BUTTONS & BUTTON_UP)){
            y--;
        }//end if

        if(!(BUTTONS & BUTTON_DOWN)){
            y++;
        }//end if

        if(!(BUTTONS & BUTTON_LEFT)){
            x--;
        }//end if

        if(!(BUTTONS & BUTTON_RIGHT)){
            x++;
        }//end if
       
        REG_BG0VOFS = y;
        REG_BG0HOFS = x;

#17026 - poslundc - Sun Feb 29, 2004 5:53 am

REG_BG0HOFS and REG_BG0VOFS should both be declared as volatile unsigned short int pointers, not just volatile unsigned int pointers.

This type of error in the code is very agreeable with the symptoms you've described, so I imagine it is the cause of your problem.

(If I'm right and this is the cause of the error, see if you can figure out why it caused the error and what your code was, in fact, doing. This is a very good example and a good exercise for anyone starting out in GBA programming, as it deals with important programming issues that are neglected by many tutorials.)

For the record, BUTTONS should also be a short, but like REG_BG0HOFS will still work in spite of the error.

Dan.

#17078 - dagamer34 - Sun Feb 29, 2004 6:57 pm

Learn to use the new IO viewer in VBA. It tells you the current state of the I/O registers and allows you to change them if you want.

Amazing piece of software, huh?
_________________
Little kids and Playstation 2's don't mix. :(

#17092 - ender7771 - Sun Feb 29, 2004 11:18 pm

Thanks a lot for your help. The changes fixed my problem.