That’s helped fix the npal error but I am still getting other errors such as:
‘tile’ undeclared <first use in this function>
stray ‘\240’ in program
coRp have you been able to get it to work???
This is my code:
/* Rico's GP32 Programming Tutorial, part 2
Example source */
#include <stdlib.h>
#include "gpdef.h"
#include "gpstdlib.h"
#include "gpgraphic.h"
#include "gpmain.h"
#include "gpstdio.h"
#include "gpfont.h"
#include "tileset.h"
#define TILESIZE 32
#define MAPH 100
#define MAPW 200
int py, px, ex, ey, exmax, eymax;
unsigned char map[MAPW][MAPH];
void GpMain(void *arg)
{
Init();
GameEngine();
}
void Init()
{
int i, j;
GpClockSpeedChange(132000000, 0x24001, 2); /* speed = 133 Mhz */
/* Page-flipper - we need to keep track of which video page we're on. We'll start with page 1. */
nflip = 1;
/* Enable and clear LCD screen:
go through each page (this loop is a little pointless) and register it as a 'page' with the GP32. */
for(i = 0; i < 2 ; i++)
{
GpLcdSurfaceGet(&gpDraw, i);
}
/* Here we wipe the first screen clear white - it starts off with random garbage. We don't need to clear screen 0, since it
is a direct copy of screen 1. */
GpRectFill(NULL, &gpDraw[nflip], 0, 0, gpDraw[nflip].buf_w, gpDraw[nflip].buf_h, 0xff);
h_pal = GpPaletteCreate(256, (GP_PALETTEENTRY*)npal);
GpPaletteSelect(h_pal);
GpPaletteRealize();
GpPaletteDelete(h_pal);
h_pal = NULL;
/* The GP32 needs to know to show screen 0 on the LCD, while we show screen 1 */
GpSurfaceSet(&gpDraw[0]);
/* The random values all come from one number, this case 36547. The random numbers will be
the same every time this way, but we'll improve that later */
srand(36547);
py = px = 400;
exmax = MAPW * TILESIZE - 320;
eymax = MAPH * TILESIZE - 240;
for(i = 0; i < MAPW; i++)
{
for(j = 0; j < MAPH; j++)
{
map[j] = (unsigned char)(rand() % 36);
}
}
}
void GameEngine()
{
while(1)
{
HandleInput();
ex = px - 160;
ey = py - 120;
if (ex < 0) ex = 0;
if (ey < 0) ey = 0;
if (ex > exmax) ex = exmax;
if (ey > eymax) ey = eymax;
DrawTiles(ex, ey);
/* Now we tell the LCD to swtich to the next page, and tell our program to draw on the next page
e.g. at the start of the code, LCD is set to 0, drawing (nflip) is set to 1
Now LCD is set to 1, nflip is set to 0 ... clever eh? */
GpRectFill(NULL, &gpDraw[nflip], px - ex - 5, py - ey - 5, 10, 10, 255);
GpRectFill(NULL, &gpDraw[nflip], px - ex - 4, py - ey - 4, 8, 8, 0);
GpSurfaceFlip(&gpDraw[nflip++]);
nflip &= 0x01;
}
}
void DrawTiles (int x, int y)
{
int xtile, ytile, xpos, ypos, i, j;
/* Getting starting tile to draw at */
xtile = x / TILESIZE;
ytile = y / TILESIZE;
/* Get the pixel offset to draw at
By the way, 'xpos = x & 31' is the same as 'xpos = x % 32' but faster */
xpos = x & (TILESIZE - 1);
ypos = y & (TILESIZE - 1);
/* Now draw the tiles */
for(i = 0; i < (320/TILESIZE + 1); i++)
{
for(j = 0; j < (240/TILESIZE + 2); j++)
{
/* Get tile number to draw, draw it */
tile = map[ytile + j][xtile + i];
GpBitBlt(NULL, &gpDraw[nflip], i * TILESIZE - xpos, j * TILESIZE - ypos, TILESIZE, TILESIZE,
(unsigned char*)sprite_tileset, tile * TILESIZE, 0, sprite_tileset_width, sprite_tileset_height);
}
}
}
void HandleInput()
{
ExKey = GpKeyGet();
if (ExKey & GPC_VK_LEFT) px--;
if (ExKey & GPC_VK_RIGHT) px++;
if (ExKey & GPC_VK_UP) py--;
if (ExKey & GPC_VK_DOWN) py++;
}