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 > Some newbie questions

#5389 - bobbin - Sat Apr 26, 2003 3:47 pm

Well, i've been following the great tutorial by GBAJunkie and everything is pretty understandable. But on my first test I get some strange results. Here is what I do (all includes are there):

Code:

01 int x,y;
02
03 setMode( MODE_3 | BG2_ENABLE );
04
05 for(y=0;y<160;y++)
06  for(x=0;x<120;x++)
07   VideoBuffer[y*120+x] = pic[y*120+x];


The image gets displayed, but only half of it. If I change line 5 to

Code:

for(y=0;y<320;y++)


all of the picture gets displayed. I used the tool gbAmp to convert my 240x160 JPG to a linear image, stored in the array pic. I just don't get it, the GBA only has 160 lines to display, so I wonder what is going wrong.

Then I got two other questions:

1. Is there any tool that reliably converts my pictures to image data + palette data headers? pcx2gba crashes on my pc and i'd really like to go for a tool with gui.

2. I don't understand, why I only have to copy 120 indices of my array into the video buffer each line. I know the GBA copies 2 pixels at once, but in fact i'm only "handing" one pixel at once to it. Does the GBA just fetch the next one on himself depending on the adress given? If that would be case wouldn't I have to write

Code:

 for(x=0;x<240;x+=2)



Well, these ARE beginners questions but I hope you can me help to clear it up a bit. Thanks!

#5391 - Daikath - Sat Apr 26, 2003 3:51 pm

There is a beginners forum so these kind of questiond dont clud up the coders forum :).

http://forum.gbadev.org/viewforum.php?f=14

Can't help you further though.
_________________
?There are no stupid questions but there are a LOT of inquisitive idiots.?

#5392 - bobbin - Sat Apr 26, 2003 4:33 pm

Oh no, how newbie can one get? Please move to beginners forum mod, thanks.

#5393 - Daikath - Sat Apr 26, 2003 4:51 pm

I admit this one is in the grey area though :).
_________________
?There are no stupid questions but there are a LOT of inquisitive idiots.?

#5397 - pollier - Sat Apr 26, 2003 8:40 pm

Quote:
for(x=0;x<120;x++)
VideoBuffer[y*120+x] = pic[y*120+x];


Shouldn't the 120's be 240's? If VideoBuffer and pic are declared as 16-bit arrays then you don't need to half your loop size, since you need to load in 16-bit values anyways.

Also, since your data is a contiguous 1D array, you don't really need to have x and y counters. You could make it this instead, maybe at the expense of some understandability:
Code:
int ctr;
setMode( MODE_3 | BG2_ENABLE );

for(ctr=0;ctr<(160*240);ctr++)
  VideoBuffer[ctr] = pic[ctr];

_________________
(Works for me!)

#5404 - bobbin - Sat Apr 26, 2003 10:34 pm

pollier wrote:
Shouldn't the 120's be 240's? If VideoBuffer and pic are declared as 16-bit arrays then you don't need to half your loop size, since you need to load in 16-bit values anyways.


Thanks, that really helped and that is much closer to what I thought. But gbajunkies also isn't wrong. I still don't get why I need to half stuff when dealing with 8bit data?

#5406 - Daikath - Sat Apr 26, 2003 10:50 pm

Because the GBA hardware can only load 16-bit data. So you load up 8-bit data in 16-bit chunks.
_________________
?There are no stupid questions but there are a LOT of inquisitive idiots.?

#5412 - bobbin - Sun Apr 27, 2003 12:41 am

Seems i'm slowly getting it.

If I load up 16bit data I can simply transfer it, because it as wide as the GBA needs it. If I load up 8bit data, I combine two data blocks to one, so two pixels are being displayed again. Seems I just should have looked at the array specified in gbajunkies tutorial, which is a u16 for a 256 color picture, that made it much clearer to me.

The basics are always the hardest, but thanks again. Don't worry, I'll soon bother you with questions again ;)

#5424 - Link - Sun Apr 27, 2003 11:29 am

why using gfx2gba i get always "const u8 arrayData[]" instead of u16 ?
How can i get u16? What are the Dos comand i must give to gfx2gba.bat?

#5426 - bobbin - Sun Apr 27, 2003 11:54 am

Link wrote:
why using gfx2gba i get always "const u8 arrayData[]" instead of u16 ?
How can i get u16? What are the Dos comand i must give to gfx2gba.bat?


I'm using the tool gbAmp, which is very good when converting non-paletted images.

#5427 - Link - Sun Apr 27, 2003 12:35 pm

i'm success to get u16 dataArray and u16 palette using pcx2gba, but using GIMP graphic program to save my drawing (a simple withe image) cin .pcx file, and including the .h file in the project i get a Green screen.
Why? What i wrong?


Futhermore the tutorials in pernproject are wronged infact it are used void C_Entry(void) instead of int main()

the second one is the
/****************************************\
/ screenmode.h \
/ by Dovoto \
\****************************************/

#ifndef SCREENMODE_H .....

"\* */" is not a correct comment form!!

I think in that tutorial and in the others there are others errors, so there i wrong!

#5428 - Link - Sun Apr 27, 2003 3:05 pm

i think my wrongs depend by GIMP or others Graphics program i use... infact when i strat GIMP i choose to make 240x160 px image, but what resolution? What i must choose of resolution?

#5429 - Link - Sun Apr 27, 2003 3:50 pm

ok i've success

#5437 - Daikath - Sun Apr 27, 2003 6:31 pm

U16 and U8 are different types of integers, u8 cant hold as much information as u16 but u8 takes up less memory.
_________________
?There are no stupid questions but there are a LOT of inquisitive idiots.?