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 > Newbie tutorial problems, macro's no longer found in libgba

#87566 - Spaceface - Wed Jun 14, 2006 4:06 pm

Hey there.. Probably something very simple that I just can't seem to figure. I'm following the Pern tutorials. But they seem to be for DevKitAdvance or at least an older version of libgba, while I'm running the more recent DevKitPro from the updater. The libgba included with it doesn't seem compatible with about EVERY tutorial I found on the net.
For instance this code, the most simplest one:


Code:
#include <gba.h> //everything you need for gba devving

#define VideoBuffer ((volatile u16*)0x6000000)
 
///////////////// C code entry (main())/////////////////////
int main()
{
    unsigned char x,y; 
 
    SetMode(MODE_3 | BG2_ENABLE);   
 
    for(x = 0; x < SCREEN_WIDTH; x++)   
        for(y = 0; y < SCREEN_HEIGHT; y++) 
            VideoBuffer [x+ y * SCREEN_WIDTH] = RGB16(31,0,0); 
 
    while(1){} 
 }//end main
It comes with a list of certain errors:
Code:
c:/devkitPro/projects/Smurfs/source/template.c:12: error: 'SCREEN_WIDTH' undeclared (first use in this function)
c:/devkitPro/projects/Smurfs/source/template.c:12: error: (Each undeclared identifier is reported only once
c:/devkitPro/projects/Smurfs/source/template.c:12: error: for each function it appears in.)
c:/devkitPro/projects/Smurfs/source/template.c:13: error: 'SCREEN_HEIGHT' undeclared (first use in this function)
c:/devkitPro/projects/Smurfs/source/template.c:14: warning: implicit declaration of function 'RGB16'

They all point to undeclared macro's which do not mean anything in the current version of libgba.

However after viewing some older .h files via google I can fill in the macro's with values:
Code:
#include <gba.h> //everything you need for gba devving

#define VideoBuffer ((volatile u16*)0x6000000)

///////////////// C code entry (main())/////////////////////
int main()
{
    unsigned char x,y; 
 
    SetMode(MODE_3 | BG2_ENABLE);   
 
    for(x = 0; x < 240; x++)   
        for(y = 0; y < 160; y++) 
            VideoBuffer [x+ y * 240] = 0x111110000000000; 
 
    while(1){} 
 }//end main
But for one reason or another I keep getting a grey screen visualboy...

Anyone here who can help me out?

#87578 - Cearn - Wed Jun 14, 2006 5:05 pm

Spaceface wrote:
Hey there.. Probably something very simple that I just can't seem to figure. I'm following the Pern tutorials. But they seem to be for DevKitAdvance or at least an older version of libgba, while I'm running the more recent DevKitPro from the updater. The libgba included with it doesn't seem compatible with about EVERY tutorial I found on the net.

Every tutorial that uses DevitAdvance predates devkitARM/Pro, and libgba by extension. That they'd use different #defines is to be expected. But more to the point, the names of the #defines don't really matter, the thing that counts is the values they stand for, whether the #define for enabling background 2 is called BG2_ENABLE (pern), BG2_ON (libgba), DCNT_BG2_ON (tonc) really isn't the issue, that they all stand for 0x0400 is. Look in the header files of the tutorials and either copy those defines or look the values up in libgba and use the proper replacement.

Spaceface wrote:
However after viewing some older .h files via google I can fill in the macro's with values:
Code:
#include <gba.h> //everything you need for gba devving

#define VideoBuffer ((volatile u16*)0x6000000)

///////////////// C code entry (main())/////////////////////
int main()
{
    unsigned char x,y; 
 
    SetMode(MODE_3 | BG2_ENABLE);   
 
    for(x = 0; x < 240; x++)   
        for(y = 0; y < 160; y++) 
            VideoBuffer [x+ y * 240] = 0x111110000000000; 
 
    while(1){} 
 }//end main
But for one reason or another I keep getting a grey screen visualboy...

You shouldn't get a grey screen, you should have a black screen. 0x111110000000000 is a hex constant, not binary. Because it's too large for a 32bit word, and will be truncated to the last 8 nybbles, i.e. 0x00000000.

Also, don't use non-words as variables, and switch order of the loops (x in the inner loop). This saves you a factor 2 in speed*.

* depending on devkit, compile flags, etc, etc. With devkitPro 19, -mthumb -O2 I get a factor 2

#87588 - Spaceface - Wed Jun 14, 2006 6:03 pm

OK, apparently now it's called MODE3_FB in the latest libgba.
Code:
//---------------------------------------------------------------------------------
// Framebuffers for mode 3 and 5
//---------------------------------------------------------------------------------
typedef u16 MODE3_LINE[240];
typedef u16 MODE5_LINE[160];

#define MODE3_FB ((MODE3_LINE *)0x06000000)
#define MODE5_FB ((MODE5_LINE *)0x06000000)
#define MODE5_BB ((MODE5_LINE *)0x0600A000)

However, I still don't get why I got the grey screen in my previous code.

When I use this code:
Code:
#include <gba.h>

#define VideoBuffer ((u16*)0x6000000)

int main()
{
    unsigned char x,y;
 
    SetMode(MODE_3 | BG2_ENABLE);   
 
    for(y = 0; y < 160; y++){
      for(x = 0; x < 240; x++){
            VideoBuffer[x+ y * 240] = 0x1F;
      }
   }
    while(1){}
 }


I get this:
http://img61.imageshack.us/img61/4493/gba27fm.png

With this in on my VideoBuffer address:
http://img61.imageshack.us/img61/8620/gba16og.png

Doesn't seem to make sense to me. Even if I change the for-loops with VideoBuffer[0] = 0x1F; it doesn't show in the Memory Viewer. Anyone has any idea what on earth I'm doing wrong here?

small update:

I now used the includes provided by the Pern tutorials, which allowed me to run the exact original C file. Even now it compiles, but doesn't show anything in the Memory Viewer nor does it show anything onscreen. This keeps getting weirder and weirder...

Even if I view it in BoyCottAdvance I get a black screen, which pretty much indicates that nothing is written to the memory. But whenever I run the compiled version that Pern provides it DOES work and DOES write to the right address.

For some reason I begin to think this has to do something outside of my code and something with either the make file or the compilers. But that can't be it, right? Anyone has any idea?

#87594 - kusma - Wed Jun 14, 2006 6:42 pm

add "-specs=gba.specs" to your linkerflags and try again...

#87595 - Spaceface - Wed Jun 14, 2006 6:49 pm

Tried it, but no result =(
My makefile now has this
Code:
CFLAGS   :=   -g -Wall -O3\
      -mcpu=arm7tdmi -mtune=arm7tdmi\
       -fomit-frame-pointer\
      -ffast-math \
      -specs=gba.specs \
      $(ARCH)


Still no difference whatsoever...

#87606 - tepples - Wed Jun 14, 2006 7:27 pm

-specs=gba.specs goes in the LDFLAGS not the CFLAGS. Think of it as like a library.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#87612 - Spaceface - Wed Jun 14, 2006 7:44 pm

tepples wrote:
-specs=gba.specs goes in the LDFLAGS not the CFLAGS. Think of it as like a library.
Ah OK.. that brings me a bit closer..
However, I get this as an error:
> "make"
template.c
arm-eabi-gcc -MMD -MP -MF /c/devkitPro/projects/Smurfs/build/template.d -g -Wall -O3 -mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer -ffast-math -mthumb -mthumb-interwork -I/c/devkitPro/projects/Smurfs/include -I/c/devkitPro/libgba/include -I/c/devkitPro/projects/Smurfs/build -c /c/devkitPro/projects/Smurfs/source/template.c -o template.o
linking cartridge
c:\devkitpro\devkitarm\arm-eabi\bin\ld.real.exe: warning: cannot find entry symbol cs=c:/devkitPro/devkitARM/arm-eabi/lib/gba.specs; defaulting to 08000234
built ... Smurfs.gba
ROM fixed!
--------------------

These are my LDFLAGS
LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $@).map,-specs=$(DEVKITARM)/arm-eabi/lib/gba.specs

However, if I change it to
LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $@).map,-specs=gba.specs


I get just the same error... Sorry for all these questions, but I don't have the slightest clue what's going on =(

#87617 - Spaceface - Wed Jun 14, 2006 8:04 pm

Small update: it seems to be beyond the whole pern thing, when I try to compile the template file from DevKitPro I also get a blank screen. Anyone knows what that's about?

Final update: apparently there was something wrong with the linkscripts in my version of DevKitPro. DevKitPro.org provides a solution on http://www.devkitpro.org/gba_linkscripts.zip

Wow that was a day thrown away searching for silly stuff ;)