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 > GBA Pong crash course parse error >.<

#95047 - Rogmatic - Thu Jul 27, 2006 4:06 pm

I just started doing the GBA Pong Crash Course tutorial, which I found from gbadev.org (http://www.webbesen.dk/gba/default.asp), and while compiling, got a strange parse error.

I used Dovotos' pcx2gba (http://www.webbesen.dk/gba/files/pcx2gba.zip) to convert my background image from bg.PCX to bg.h.

I continued with the tutorial, to the point where the first compile is done: it compiled fine, no errors.

Now here's the part that's puzzling me: I haven't edited the bg.h file in any way, and now, after adding some more code and reaching the second compile in the tutorial, I'm getting a parse error in the bg.h file.

Quote:

In file included from pong.c:2:
bg.h:9: parse error before 'const'


Code:

/**********************************************\
*       bg.h                                   *
*          by dovotos pcx->gba program         *
/**********************************************/
#define  bg_WIDTH   240
#define  bg_HEIGHT  160


const u16 bgData[] = {    // <-- Parse error before 'const'
                    0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828,
                    0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828,
                    0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828,
                    0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828,
                    0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828, 0x2828,
...};

const u16 bgPalette[] = {
                    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
                    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
                    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
                    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7FFF,
                    0x0000, 0x1800, 0x3000, 0x4C00, 0x6400, 0x7C00, 0x00C0, 0x18C0, 0x30C0, 0x4CC0,
                    0x64C0, 0x7CC0, 0x0180, 0x1980, 0x3180, 0x4D80, 0x6580, 0x7D80, 0x0260, 0x1A60,
                    0x3260, 0x4E60, 0x6660, 0x7E60, 0x0320, 0x1B20, 0x3320, 0x4F20, 0x6720, 0x7F20,
...};


Thanks in advance, any help is greatly appreciated.

#95056 - tepples - Thu Jul 27, 2006 5:12 pm

First off, rename bg.h to bg.c before compiling it. Second, because you're using u16 without including any GBA headers, you need to put the following above the first 'const u16':
Code:
typedef unsigned short u16;

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#95072 - Rogmatic - Thu Jul 27, 2006 6:35 pm

Actually, I've defined u16 in a gba header file, and bg.h is not the main program source, it's just the file containing the image data. I suppose I should have posted the main program source...anyways, here it is:

Code:

#include "gba.h"
#include "bg.h"
#include "ball.h"

void InitializeSprites(void);
void CopyOAM(void);

OAMEntry sprites[128];

int main() {

   u16 loop;

   SetMode(MODE_4 | BG2_ENABLE | OBJ_ENABLE | OBJ_MAP_1D);

   for (loop = 0; loop < 256; loop++) {
      OBJ_PaletteMem[loop] = ballPalette[loop];
   }

   for (loop = 0; loop < 256; loop++) {
      BG_PaletteMem[loop] = bgPalette[loop];   // Fill the palette memory with all 256 colors
   }


   for (loop = 0; loop < (120*160); loop++) {
      FrontBuffer[loop] = bgData[loop];   // Fill the VRAM with the background image data
   }

   memcpy( (u16 *)0x06014000, &ballData, sizeof(ballData) );

   sprites[0].attribute0 = COLOR_256 | SQUARE | 50;
   sprites[0].attribute1 = SIZE_8 | 30;
   sprites[0].attribute2 = 512;

   while(1)
   {
      WaitForVsync();
      CopyOAM();
   }


   return 0;

}

void InitializeSprites(void)
{
   u16 loop;
   for (loop = 0; loop < 128; loop++) {
      sprites[loop].attribute0 = 160;
      sprites[loop].attribute1 = 240;
   }
}

void CopyOAM(void)
{
   u16 loop;
   u16* temp;
   temp = (u16*)sprites;
   for (loop = 0; loop < 128*4; loop++) {
      OAM_Mem[loop] = temp[loop];
   }
}

#95101 - kusma - Thu Jul 27, 2006 9:19 pm

the parse error is _before_ the first const keyword, and since there is no other c/c++-code (only preprocessor-stuff) prior to that point in that header, my guess is that the source of the error is located in the end of gba.h as it is the file included before bg.h. something like a missing semicolon after a struct/class-declaration is a good candidate to look for.

#95103 - Rogmatic - Thu Jul 27, 2006 9:27 pm

Thanks for your advice guys.

I took a look at the gba.h file just now, didn't see anything that might cause a problem, but here's the code, maybe you'll see something I'm not.

Code:

//
// Including all macros into gba.h
//

#ifndef GBA_H
#define GBA_H

#include "gba_types.h"
#include "gba_regs.h"
#include "gba_video.h"
#include "gba_sprites.h"

#endif

#95127 - kusma - Thu Jul 27, 2006 11:47 pm

what's the contents of gba_sprites.h?

#95131 - Rogmatic - Thu Jul 27, 2006 11:57 pm

gba_sprites.h:

Code:

//
// Sprites
//

#ifndef GBA_SPRITES_H
#define GBA_SPRITES_H

#include "gba_types.h"

// Attribute 0

#define ROTATION_FLAG      0x0100
#define SIZE_DOUBLE      0x0200
#define MODE_NORMAL      0x0000
#define MODE_TRANSPARENT   0x0400
#define MODE_WINDOWED      0x0800
#define MOSAIC         0x1000
#define COLOR_16      0x0000
#define COLOR_256      0x2000
#define SQUARE         0x0000
#define   WIDE         0x4000
#define TALL         0x8000

// Attribute 1

#define ROTDATA(n)      (n << 9)
#define HORIZONTAL_FLIP      0x1000
#define VERTICAL_FLIP      0x2000
#define SIZE_8         0x0000
#define SIZE_16         0x4000
#define SIZE_32         0x8000
#define SIZE_64         0xC000

// Attribute 2

#define PRIORITY(n)      ((n) << 10)
#define PALETTE(n)      ((n) << 12)

// Sprite structure definitions

typedef struct tagOAMEntry
{
   u16 attribute0;
   u16 attribute1;
   u16 attribute2;
   u16 attribute3;
} OAMEntry, *pOAMEntry;

// Sprite rotation information

typedef struct tagRotData
{
   u16 filler1[3];
   u16 pa;
   u16 filler2[3];
   u16 pb;
   u16 filler3[3];
   u16 pc;
   u16 filler4[3];
   u16 pd;
} RotData, *pRotData

#endif

#95137 - Sausage Boy - Fri Jul 28, 2006 12:10 am

I see it! Missing ; !

edit:
hmm yeah, right after *pRotData
_________________
"no offense, but this is the gayest game ever"

#95176 - Rogmatic - Fri Jul 28, 2006 3:43 am

Well damn, I can't believe I missed that.
Thanks alot, everyone. XD