I am running gbdk a gameboy game making program and I am getting parse errors on the following code

1.4k Views Asked by At
#include <gb/gb.h>
#include <stdio.h>
#include "racecars.h"

/*

 RACECARS.C

 Tile Source File.

 Info:
  Form                 : All tiles as one unit.
  Format               : Gameboy 4 color.
  Compression          : None.
  Counter              : None.
  Tile size            : 8 x 8
  Tiles                : 0 to 16

  Palette colors       : None.
  SGB Palette          : None.
  CGB Palette          : None.

  Convert to metatiles : No.

 This file was generated by GBTD v2.2

*/

/* Start of tile array. */
unsigned char Racecars[] =
{
  0x7E,0x7E,0x42,0x5E,0xC3,0xD7,0xC3,0xDF,
  0x42,0x52,0x7E,0x7E,0xC3,0xC3,0xC3,0xC3,
  0x1C,0x1C,0x36,0x3E,0x62,0x7A,0x43,0x4B,
  0x41,0x5D,0x7F,0x7F,0x55,0x55,0x77,0x77,
  0x38,0x38,0x44,0xC6,0xAA,0xAA,0xAA,0xAA,
  0xAA,0xAA,0x82,0x82,0x44,0xC6,0x38,0x38,
  0x18,0x18,0x18,0x18,0x24,0x24,0x42,0x42,
  0xFF,0xFF,0x00,0xC6,0x00,0xC6,0x00,0x00,
  0x3C,0x3C,0x24,0xE7,0x24,0xE7,0x24,0x24,
  0x24,0xE7,0x3C,0xFF,0x24,0x24,0x3C,0x3C,
  0x18,0x18,0x24,0xE7,0x42,0xC3,0x42,0x42,
  0x42,0x42,0x24,0x66,0x18,0x7E,0x00,0x00,
  0xF2,0xF2,0x96,0x96,0xF2,0xF2,0x82,0x82,
  0x8F,0x8F,0x00,0x00,0x00,0x00,0x00,0x00,
  0xEE,0xEE,0x82,0x82,0x8E,0x8E,0x8B,0x8B,
  0xEE,0xEE,0x00,0x00,0x00,0x00,0x00,0x00,
  0xEE,0xEE,0x82,0x82,0x8E,0x8E,0x82,0x82,
  0xEE,0xEE,0x00,0x00,0x00,0x00,0x00,0x00,
  0xE2,0xE2,0x86,0x86,0x82,0x82,0x82,0x82,
  0xE7,0xE7,0x00,0x00,0x00,0x00,0x00,0x00,
  0xEA,0xEA,0x8A,0x8A,0x8E,0x8E,0x82,0x82,
  0xE2,0xE2,0x00,0x00,0x00,0x00,0x00,0x00,
  0xE7,0xE7,0x84,0x84,0x87,0x87,0x81,0x81,
  0xE7,0xE7,0x00,0x00,0x00,0x00,0x00,0x00,
  0xF7,0xF7,0x85,0x85,0x85,0x85,0xB5,0xB5,
  0x95,0x95,0xF7,0xF7,0x00,0x00,0x00,0x00,
  0x82,0x82,0x82,0x82,0x92,0x92,0x92,0x92,
  0x92,0x92,0x92,0x92,0xFE,0xFE,0x00,0x00,
  0xFF,0xFF,0x10,0x10,0x10,0x10,0x10,0x10,
  0x10,0x10,0xFF,0xFF,0x00,0x00,0x00,0x00,
  0x82,0x82,0xC2,0xC2,0xA2,0xA2,0x92,0x92,
  0x8A,0x8A,0x86,0x86,0x82,0x82,0x00,0x00,
  0x20,0x20,0x30,0x30,0x38,0x38,0x3C,0x3C,
  0x20,0x20,0x20,0x20,0x20,0x20,0xFF,0xFF
};

/* End of RACECARS.C */

int main(void){             //starts the main function
 int x,y,st,key,z;          //define the integers x and y wich will be used to define the hero position, key will be used later
 int x1,y1,st1;             
 int x2,y2,st2;             
 int x3,y3,st3; 
    x=20;                   //set x as 20
    y=20;                   //set y as 20
    st=0;                   //sprite type(1=closed 0=open)
    z=0;                    //set z=0, z will be used for testing if its time to change sprite or not

    set_sprite_data(0,76,Racecars);     //set our sprite data   

    wait_vbl_done();            //wait for the visual blank to be done
    set_sprite_tile(0,0);           //set our tile 0 as the tile 0 of our tile data-pacman open
    set_sprite_tile(1,1);           //set our tile 1 as the 1st tile of our tile data-pacman closed
    set_sprite_tile(2,2);
    set_sprite_tile(3,3);
    set_sprite_tile(4,4);
    set_sprite_tile(5,5);
    set_sprite_tile(6,6);
    set_sprite_tile(7,7);
    set_sprite_tile(8,8);
    set_sprite_tile(9,9);
    set_sprite_tile(10,10);
    set_sprite_tile(11,11);
    set_sprite_tile(12,12);
    set_sprite_tile(13,13);
    set_sprite_tile(14,14);
    set_sprite_tile(15,15);
    set_sprite_tile(16,16);

    move_sprite(st,x,y);            

    #define MapSizeX 256;   

    #define MapSizeY 256;   


    UBYTE ScrollXCnt;   

    UBYTE ScrollYCnt;   

    BYTE SCXCnt;        

    BYTE SCYCnt;        

    UBYTE tempa, tempb; 

    UWORD Cnt;      





    Cnt = 0;

    wait_vbl_done();

    for(tempa = 0; tempa != 32; tempa++) {

        set_bkg_tiles(0,tempa,32,tempa+1,TileMap[Cnt]);

        Cnt = Cnt + MapSizeX;   

    }
    if(joypad() & J_UP) ScrollUp();

    if(joypad() & J_DOWN) ScrollDown();

    if(joypad() & J_LEFT) ScrollLeft();

    if(joypad() & J_RIGHT) ScrollRight();

    wait_vbl_done();

    scroll_bkg(x,y);  

    ScrollX++;  or  ScrollX--;

    ScrollY++;  or  ScrollY--;

    SCXCnt++;   or  SCXCnt++;

    SCYCnt++;   or  SCYCnt--;

        if(SCXCnt == 8) {

        SCXCnt = 0;     

        Cnt = ScrollX / 8;  



        Cnt = Cnt + 20;     





        for(tempa = 0; tempa != 224; tempa++) {



            set_bkg_tiles(0,tempa,1,tempa+1,TileMap[Cnt]);

            Cnt = Cnt + MapSizeX;

        }       

    }

    if(SCXCnt == -8) {

        SCXCnt = 0;

        SCXCnt = 0;     

        Cnt = ScrollX / 8;  


        Cnt--;          




        for(tempa = 0; tempa != 224; tempa++) {



            set_bkg_tiles(0,tempa,1,tempa+1,TileMap[Cnt]);


            Cnt = Cnt + MapSizeX;

        }       

    }
    .

    .

    .

That is the c code

I ran the prompt and the following errors popped up.

   Parse error before ubyte line 108
   Parse error before scroll x
   Parse error before scroll y
   Parse error before scxCnt
   Parse error before ScyCnt
   Parse error before 32
3

There are 3 best solutions below

0
On

That UBYTE error shouldn't occur with current sdcc 4.1.0 and therefore gbdk-2020 4.0.3

GBDK's last update was 2001 or so...

Though the other errors are coming from your code being invalid.

That's no valid C code:

    ScrollX++;  or  ScrollX--;

    ScrollY++;  or  ScrollY--;

    SCXCnt++;   or  SCXCnt++;

    SCYCnt++;   or  SCYCnt--;

And I don't think this is doing what you want:

    #define MapSizeX 256;   

    #define MapSizeY 256; 

Defines are always unscoped since they are handled by the preprocessor and not the compiler. And you rather want #define MapSizeX 256U

What you wrote will work with your code. Cnt = Cnt + MapSizeX; turning into Cnt = Cnt + 256;; isn't a big deal, but it would likely break later.

1
On

You might be missing an include file which defines UBYTE.

1
On

Your issue is that you are tying to define new variables in the middle of the function. The GBDK compiler does not allow that, for whatever reason. (This is apparently part of the ANSI C / C89 standard)

You can fix this by changing the top of your main() from

int main(void){             //starts the main function
 int x,y,st,key,z;          //define the integers x and y wich will be used to define the hero position, key will be used later
 int x1,y1,st1;             
 int x2,y2,st2;             
 int x3,y3,st3; 

to this:

int main(void){             //starts the main function
    int x,y,st,key,z;          //define the integers x and y wich will be used to define the hero position, key will be used later
    int x1,y1,st1;
    int x2,y2,st2;
    int x3,y3,st3;

    //These variables are used later on.
    UBYTE ScrollXCnt;
    UBYTE ScrollYCnt;
    BYTE SCXCnt;
    BYTE SCYCnt;
    UBYTE tempa, tempb;
    UWORD Cnt;

Alternatively, you could move all of the code starting at those variables to another function, and then those variables will be declared with the function and all will be fine.