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 > Visual Ham project wont compile

#149239 - yaazz - Thu Jan 17, 2008 2:37 am

Hello I am attempting to learn GBA programming from the book "how to program the Game Boy Advance", and have run into an issue.
When I try to compile my program the compiler spits this out:
{
C:/gcc-arm/bin/arm-thumb-elf-gcc.exe -I C:/gcc-arm/include -I C:/gcc-arm/arm-thumb-elf/include -I C:/include -I C:/system -c -DHAM_HAM -DHAM_MULTIBOOT -DHAM_ENABLE_MBV2LIB -O2 -DHAM_WITH_LIBHAM -mthumb-interwork -mlong-calls -Wall -save-temps -fverbose-asm -nostartfiles main.c -o main.o
In file included from C:/gcc-arm/arm-thumb-elf/include/stdlib.h:14,
from main.c:5:
C:/gcc-arm/lib/gcc-lib/arm-thumb-elf/3.3.2/include/stddef.h:213: error: syntax error before "typedef"
make: *** [main.o] Error 1
}

For some reason, STDLIB, and STDDEF (which must be linked from stdlib) will not compile.....
Does anyone know how to fix this?


here is the source for my program
Code:

#define multiboot int_gba_multiboot
MULTIBOOT

#include <stdlib.h>

//drawing functions
void drawPixel(int,int,unsigned short);
void drawLine3(int,int,int,int,unsigned short);

//defines for the video mode
#define REG_DISPCNT *(unsigned long*)0x4000000
#define MODE_3 0x3
#define BG2_ENABLE 0x400

//changes the video mode
#define setMode(mode) REG_DISPCNT= (mode)

//packs 3 values into 15 bit color
#define RGB(r,g,b) ((r)+(g<<5)+(b<<10))

//create a pointer to the video buffer
unsigned short* videoBuffer = (unsigned short*)0x6000000;


int main(void)
{
   int x1,y1,x2,y2;
   unsigned short color;

   setMode(MODE_3 | BG2_ENABLE);

   while(1)
   {
       x1 = rand()*240;
       y1 = rand()*160;
       x2 = rand()*240;
       y2 = rand()*160;

       color=RGB(rand()%31, rand()%31, rand()%31);

       drawLine3(x1,y1,x2,y2,color);
   }

   return 0;
}

void drawPixel3(int x, int y, unsigned short c)
{
    videoBuffer[y * 240 + x] = c;
}

void drawLine3(int x1,int y1, int x2, int y2, unsigned short c)
{
    int i, deltaX, deltaY, numPixels;
    int d, dinc1, dinc2;
    int x, xinc1, xinc2;
    int y, yinc1, yinc2;

    //calculate deltaX and deltaY
    deltaX = abs(x2 - x1);
    deltaY = abs(y2 - y1);

    //initialize
    if(deltaX > deltaY)
    {
        //If x is an independant variable
        numPixels = deltaX + 1;
        d = (2 * deltaY) - deltaX;
        dinc1 = deltaY << 1;
        dinc2 = (deltaY - deltaX) << 1;
        xinc1 = 1;
        xinc2 = 1;
        yinc1 = 0;
        yinc2 = 1;
    }
    else
    {
        // if y is independant variable
        numPixels = deltaY + 1;
        d = (2* deltaX) - deltaY;
        dinc1 = deltaX << 1;
        dinc2 = (deltaX - deltaY) << 1;
        xinc1 = 0;
        xinc2 = 1;
        yinc1 = 1;
        yinc2 = 2;

    }

    //move the right direction
    if (x1>x2)
    {
        xinc1 = -xinc1;
        xinc2 = -xinc2;
    }

    if (y1 > y2)
    {
        yinc1 = -yinc1;
        yinc2 = -yinc2;
    }

    x = x1;
    y = y1;

    //draw the pixels
    for (i=1;i<numPixels;i++)
    {
        drawPixel(x,y,c);

        if(d<0)
        {
            d = d + dinc1;
            x = x + xinc1;
            y = y + yinc1;
        }
        else
        {
            d = d + dinc2;
            x = x + xinc2;
            y = y + yinc2;
        }
    }
}
/* END OF FILE */
[/code]

#149250 - bpoint - Thu Jan 17, 2008 8:19 am

yaazz wrote:

here is the source for my program
Code:

#define multiboot int_gba_multiboot
MULTIBOOT

#include <stdlib.h>



I've never used Ham, but I'd be willing to bet this is your problem.

The #define for multiboot is fine, but the "MULTIBOOT" is an undefined symbol. There's nothing before that line that tells the compiler what "MULTIBOOT" is, so when it #includes stdlib.h, the first source code line in the header file causes a compiler error (the typedef in your case).

Moving the #include <stdlib.h> line above the "MULTIBOOT" code will fix the error in the stddef.h header, but you'll still need a valid symbol for "MULTIBOOT" -- which is where Ham does something for you but you're not #including.

However, just going on a gut feeling (no guarantees!), I would simply change the line:
Code:
MULTIBOOT

to:
Code:
multiboot;

(note the semicolon) and see what happens.

#149344 - tepples - Fri Jan 18, 2008 8:11 pm

That method of making a multiboot program was correct in DevKit Advance, but it is not correct in devkitARM.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#149501 - elyk1212 - Mon Jan 21, 2008 5:49 am

tepples wrote:
That method of making a multiboot program was correct in DevKit Advance, but it is not correct in devkitARM.


Yep, visual ham doesn't use the new DevkitARM gcc/binutils/etc build version. I also do not think it has been updated in years. But, ham libraries itself have (I think?) just not the visual HAM IDE (and perhaps the gcc tools underneath this Visual HAM install), and not much updates for Linux :(.

yaazz:
FYI, you can use most of the concepts from the book and still use devkitARM. Even though the first few examples list VisualHAM most of the time the author defines all the addresses etc, that you need to complete the tutorials.

You may run into a few define annoyances (as you listed earlier), but you can safely substitute to something workable with a little leg work.

OR,

You can use the Deprecated VisualHAM IDE to compile the examples with out a hitch, and switch to devkitARM when you are ready.

BTW, I rather liked Peter's VisualHAM (if I was ever using windows). It was a working out of the box solution. Too bad it was abandoned (but I guess keeping an IDE project updated can be daunting for one fellow).

#149522 - gmiller - Mon Jan 21, 2008 3:38 pm

You can use Visual Ham with the devkitPro tools with some different makefile's and some minor work on the Ham Libraries. My students use Visual Ham and devkitPro every month. The Ham libraries are not part of that but I do have one example that uses that combo.

If you are interested just PM me and I will work out a way for you to get this setup. I do not think many here would care for this combination.