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 > Mode 0 Graphics Tools

#34314 - arock99 - Mon Jan 17, 2005 6:28 pm

Hello,
Although I'm not new to programming in general (I have been doing various things for over 10 years now) pretty much everything i'm doing now is being learned as I go for GBA Development.
I have written code to scroll though a Mode 0 Map and using someone else's already generated .h header file everything looks and works ok. When I try and use a .h header file I generate by using either pcx2gba or pcx2sprite I get garbled graphics. What tool should I be using? I use pcx2gba and pcx2sprite by dragging and dropping the pcx file on to them.
I'm using photoshop and am using an indexed pcx file as per the tutorials.

Here is my main function:
int main() {
int xBg = 0, yBg = 0;//start x,y position of screen in map
unsigned short* bg0map =(unsigned short*)ScreenBaseBlock(31);//Create a pointer to background 0 tilemap buffer
REG_BG0CNT = BG_COLOR256 | TEXTBG_SIZE_256x256 | (31 << SCREEN_SHIFT) | WRAPAROUND;//set up background 0
SetMode(0 | BG0_ENABLE);//set video mode 0 with background 0
DMAFastCopy((void*)bgPalette, (void*)BGPaletteMem,256, DMA_16NOW);//copy the palette into the background palette memory
DMAFastCopy((void*)bgData, (void*)CharBaseBlock(0),sizeof(bgData)/4, DMA_32NOW);//copy the tile images into the tile memory
DMAFastCopy((void*)lvlMap, (void*)bg0map, 512, DMA_32NOW);//copy the tile map into background 0

while (1) {
while(REG_VCOUNT < 160); //wait for the start of VBLANK

//D-pad moves background
if(!(BUTTONS & BUTTON_LEFT)) xBg--;
if(!(BUTTONS & BUTTON_RIGHT)) xBg++;
if(!(BUTTONS & BUTTON_UP)) yBg--;
if(!(BUTTONS & BUTTON_DOWN)) yBg++;

REG_BG0HOFS = xBg; //x position of start of background
REG_BG0VOFS = yBg; //y position of start of background

while(REG_VCOUNT > 160); //wait for end of VBLANK
}

return 0;
}

#34317 - Celeryface - Mon Jan 17, 2005 8:55 pm

arock99 wrote:
.

DMAFastCopy((void*)bgData, (void*)CharBaseBlock(0),sizeof(bgData)/4, DMA_32NOW);//copy the tile images into the tile memory



In this line here, you're using sizeof(bgData). Won't this return the size of the type, rather than the size of the array? Or are you using another function of your own that returns the size of the array? :)

#34319 - arock99 - Mon Jan 17, 2005 9:31 pm

Celeryface wrote:
arock99 wrote:
.

DMAFastCopy((void*)bgData, (void*)CharBaseBlock(0),sizeof(bgData)/4, DMA_32NOW);//copy the tile images into the tile memory



In this line here, you're using sizeof(bgData). Won't this return the size of the type, rather than the size of the array? Or are you using another function of your own that returns the size of the array? :)


I did not create a function of my own no...I have already tried putting in the size of my array and that didn't do it. I have also tried dividing by everything from 1 to 8 ;) I'm going to have to double check some documents I have a feeling there are a few things i might have missed

#34321 - Celeryface - Mon Jan 17, 2005 9:33 pm

arock99 wrote:
Celeryface wrote:
arock99 wrote:
.

DMAFastCopy((void*)bgData, (void*)CharBaseBlock(0),sizeof(bgData)/4, DMA_32NOW);//copy the tile images into the tile memory



In this line here, you're using sizeof(bgData). Won't this return the size of the type, rather than the size of the array? Or are you using another function of your own that returns the size of the array? :)


I did not create a function of my own no...I have already tried putting in the size of my array and that didn't do it. I have also tried dividing by everything from 1 to 8 ;) I'm going to have to double check some documents I have a feeling there are a few things i might have missed


Yeah, normally when you're using 256-colour mode for backgrounds, you'd divide the size of your tile array by 4 when copying the tiles into memory. Have you tried using gfx2gba to make your background header files?

#34324 - sajiimori - Mon Jan 17, 2005 9:39 pm

There are lots of threads about this sort of thing. In fact, I think there was one just a few days ago. You might check around here.