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 > Graphic problems [starting]

#44403 - Shade - Wed Jun 01, 2005 11:55 am

Hi, sorry for posting, but I've read through the FAQ and had no luck so far.

I'm using devkitpro (as per instructions). My make.bat:

Code:
PATH=C:\devkitpro\msys\bin;C:\devkitpro\devkitARM\bin;%PATH%;

arm-elf-gcc -mthumb -mthumb-interwork -c hello.c
arm-elf-gcc -specs=gba_mb.specs -mthumb -mthumb-interwork hello.o -o hello.elf
arm-elf-objcopy -O binary hello.elf hello.gba
gbafix hello.gba


And this is my source file:

Code:

/* hello.c - Gameboy Advance Tutorial - Loirak Development */
#define RGB16(r,g,b)  ((r)+(g<<5)+(b<<10))

int main()
{
   char x,y; 
   unsigned short* Screen = (unsigned short*)0x6000000;
   *(unsigned long*)0x4000000 = 0x403; // mode3, bg2 on

    while(1){   //loop forever
   // clear screen, and draw a magenta back ground
   for(x = 0; x<240;x++)   //loop through all x
   {
      for(y = 0; y<160; y++)  //loop through all y
      {
         Screen[x+y*240] = RGB16(30,0,31); 
      }
   }
   Screen[0] = 0x7c00; // draw a single blue pixel
    }
}


Now, it was supposed to clear the screen with magenta and draw a single blue pixel on the corner, repeatedly. However, the "Screen[0]" attribution seems to affect the whole screen -- the effect is, the whole screen blinks magenta/blue/magenta/blue...

Note that I could only test it in Visual Boy Advance so far.

What is this? Some weird alignment issue? What am I missing?

Thanks in advance

#44407 - strager - Wed Jun 01, 2005 2:48 pm

Screen should be a macro, and X and Y should be int's.

Place your while(1) loop at the bottom of the two for loops (outside), and make sure it doesn't have an code in it. Make the Screen[0] = ... before the while loop.

Example:
Code:

#define Screen ((u16 *)(0x06000000))
#define pixel(x,y) (Screen[(x) + ((y) * 240)])

int x, y;

for(y = 0; y < 160; y++)
{
    for(x = 0; x < 240; x++)
    {
        pixel(x, y) = RGB16(31, 0, 31);
    };
};

pixel(0, 0) = RGB16(0, 0, 31);

while(1)
    /* DO NOTHING */;


If you haven't noticed, I've switched the X and Y for loops. Not only will this make it faster, it will appear more natural. The old loop, X then Y, draws pixels going down. When it reached the bottom, it is returned to the top and shifted right. The drawing starts over until the entire screen is filled. The loop above, Y then X, draws pixels going right and returns at the end, going down one...

Hope this helps.

#44459 - Shade - Thu Jun 02, 2005 12:54 am

Thanks for the assist, but I still have the same problem (even using the exact code you posted). The screen blinks magenta and then goes all blue, even setting just the (0,0) pixel (Screen[0]).

I'm thinking it's something emulator-related... I'm using a pretty default VisualBoy Advance, is there a setting I should be concerned about? Without GBAFIX I get the garbled "Nintendo" logo, with it I get this result.

I tried loading an example that someone else sent to the board and got a solid red screen.

Thanks again for the help. And BTW, I agree with your switch of x/y -- it's probably faster, anyway -- but that came from sample code.

Cheers

#44506 - Shade - Thu Jun 02, 2005 11:58 am

Ok -- I've re-downloaded everything from scratch and followed this excellent tutorial people recommended at another thread...

...and it works.

I'm still curious to find out how come it didn't work the first time -- I'll see if I can find the problematic element and post my results later on.

Actually, I just noticed the working demo uses MODE_4 (palette) instead of direct bitmap drawing... Gotta check mode 3.

Thanks for the support!

#44518 - strager - Thu Jun 02, 2005 2:01 pm

Ah, that's your problem. If only you had set it to mode 4...

#44538 - Shade - Thu Jun 02, 2005 6:18 pm

But why didn't the solution work with mode 3? Isn't it supposed to?

Thanks

#44541 - strager - Thu Jun 02, 2005 6:37 pm

Wait - I got mode 3 and 4 mixed up.

Mode 3 has a single buffer and uses 16-bit color (xBBBBBGGGGGRRRRR).
Mode 4 has a double buffer and a pallet.

Mode 0-5: Text, Rotating Text, Rotating, Single Bitmap, Palletted Bitmap, Double Bitmap
T, RT, R, SB, PB, DB...

Sorry if I caused any confusion

#44579 - Shade - Fri Jun 03, 2005 1:21 am

strager wrote:
Mode 3 has a single buffer and uses 16-bit color (xBBBBBGGGGGRRRRR).
Mode 4 has a double buffer and a pallet.

Exactly... The other tutorial uses Mode 4, and it worked. The first example uses mode 3 (no pallete) and it didn't work, still dunno why. I'll try some more stuff tonight and during the weekend, but frankly, I feel better disposed towards simply going for mode 3. It's enough for my toy projects anyway.

Cheers