Some work on a port for the gp2x. Runs up to the splashscreen, but as there is no mouse i have to make the program usable with a joystick.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@462 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Adrien Destugues 2009-01-05 21:12:46 +00:00
parent c130a327d1
commit 132eabcde5
20 changed files with 297 additions and 274 deletions

View File

@ -139,6 +139,7 @@ else
MKDIR = mkdir -p
RMDIR = rmdir
CP = cp
ifdef WIN32CROSS
#cross compile a Win32 executable
CC = i586-mingw32msvc-gcc
@ -148,13 +149,27 @@ else
LOPT = -mwindows -lmingw32 -lSDLmain -lSDL -lshlwapi `/usr/local/cross-tools/i386-mingw32/bin/sdl-config --libs` -lSDL_image $(TTFLOPT)
OBJDIR = obj/win32
else
BIN = grafx2
CFGBIN = gfxcfg
COPT = -W -Wall -Wdeclaration-after-statement -pedantic -std=c99 -c -g `sdl-config --cflags` $(TTFCOPT)
LOPT = `sdl-config --libs` -lSDL_image $(TTFLOPT)
CC = gcc
OBJDIR = obj/unix
X11LOPT = -lX11
ifdef GP2XCROSS
#cross compile an exec for the gp2x
CC = /opt/open2x/gcc-4.1.1-glibc-2.3.6/arm-open2x-linux/bin/arm-open2x-linux-gcc
BIN = grafx2.gpe
CFGBIN = gfxcfg.gpe
COPT = -W -Wall -Wdeclaration-after-statement -pedantic -std=c99 -static -c -g -O3 `/opt/open2x/gcc-4.1.1-glibc-2.3.6/bin/sdl-config --cflags` $(TTFCOPT) -D__GP2X__
LOPT = -static -lSDL_image `/opt/open2x/gcc-4.1.1-glibc-2.3.6/bin/sdl-config --static-libs` -ljpeg -lpng -lz -lm $(TTFLOPT)
OBJDIR = obj/gp2x
NOTTF = 1
else
# Compiles a regular linux exectutable for the native platform
BIN = grafx2
CFGBIN = gfxcfg
COPT = -W -Wall -Wdeclaration-after-statement -pedantic -std=c99 -c -g `sdl-config --cflags` $(TTFCOPT)
LOPT = `sdl-config --libs` -lSDL_image $(TTFLOPT)
CC = gcc
OBJDIR = obj/unix
X11LOPT = -lX11
endif
endif
endif
endif

View File

@ -24,8 +24,8 @@
GERMANY
karlb@gmx.net
*/
#include <SDL/SDL.h>
#include <SDL/SDL_video.h>
#include <SDL.h>
#include <SDL_video.h>
#include <assert.h>
#include <stdlib.h>

View File

@ -36,7 +36,7 @@
#ifndef _SFONT_H_
#define _SFONT_H_
#include <SDL/SDL.h>
#include <SDL.h>
#ifdef __cplusplus
extern "C" {

View File

@ -25,7 +25,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <SDL/SDL.h>
#include <SDL.h>
#include "const.h"
#include "struct.h"

View File

@ -20,8 +20,9 @@
write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <SDL/SDL.h>
#include <SDL.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "struct.h"
#include "sdlscreen.h"

View File

@ -285,7 +285,6 @@ void bstrtostr( BSTR in, STRPTR out, TEXT max )
// -- Lecture d'une liste de lecteurs / volumes -----------------------------
void Lire_liste_des_lecteurs(void)
{
// Fixes a warning on os4
#ifndef __amigaos4__
int Indice;
#endif

View File

@ -29,9 +29,9 @@
#include <unistd.h>
//SDL
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_events.h>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_events.h>
//#include <SDL_gfxPrimitives.h>
//mine

View File

@ -39,7 +39,7 @@
#ifndef _GLOBAL_H_
#define _GLOBAL_H_
#include <SDL/SDL.h>
#include <SDL.h>
#include "struct.h"
GFX2_GLOBAL struct S_Config

View File

@ -20,7 +20,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdbool.h>
#include <SDL/SDL.h>
#include <SDL.h>
/*** Types definitions and structs ***/

2
init.c
View File

@ -31,7 +31,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <SDL/SDL_byteorder.h>
#include <SDL_byteorder.h>
#if defined(__WIN32__)
#include <windows.h> // GetLogicalDrives(), GetDriveType(), DRIVE_*
#endif

488
io.c
View File

@ -1,245 +1,245 @@
/* Grafx2 - The Ultimate 256-color bitmap paint program
Copyright 2008 Yves Rizoud
Copyright 2007 Adrien Destugues
Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
Grafx2 is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.
Grafx2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grafx2; if not, see <http://www.gnu.org/licenses/> or
write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Fonctions de lecture/ecriture fichier, gèrent les systèmes big-endian et
// little-endian.
#include <SDL/SDL_endian.h>
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
#if defined(__amigaos4__)
#include <proto/dos.h>
#include <dirent.h>
#elif defined(__WATCOMC__)
#include <direct.h>
#elif defined(__WIN32__)
#include <dirent.h>
#include <windows.h>
#else
#include <dirent.h>
#endif
#include "struct.h"
#include "io.h"
word endian_magic16(word x)
{
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
return x;
#else
return SDL_Swap16(x);
#endif
}
dword endian_magic32(dword x)
{
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
return x;
#else
return SDL_Swap32(x);
#endif
}
// Lit un octet
// Renvoie -1 si OK, 0 en cas d'erreur
int read_byte(FILE *Fichier, byte *Dest)
{
return fread(Dest, 1, 1, Fichier) == 1;
}
// Ecrit un octet
// Renvoie -1 si OK, 0 en cas d'erreur
int write_byte(FILE *Fichier, byte Byte)
{
return fwrite(&Byte, 1, 1, Fichier) == 1;
}
// Lit des octets
// Renvoie -1 si OK, 0 en cas d'erreur
int read_bytes(FILE *Fichier, void *Dest, size_t Taille)
{
return fread(Dest, 1, Taille, Fichier) == Taille;
}
// Ecrit des octets
// Renvoie -1 si OK, 0 en cas d'erreur
int write_bytes(FILE *Fichier, void *Src, size_t Taille)
{
return fwrite(Src, 1, Taille, Fichier) == Taille;
}
// Lit un word (little-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int read_word_le(FILE *Fichier, word *Dest)
{
if (fread(Dest, 1, sizeof(word), Fichier) != sizeof(word))
return 0;
#if SDL_BYTEORDER != SDL_LIL_ENDIAN
*Dest = SDL_Swap16(*Dest);
#endif
return -1;
}
// Ecrit un word (little-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int write_word_le(FILE *Fichier, word Mot)
{
#if SDL_BYTEORDER != SDL_LIL_ENDIAN
Mot = SDL_Swap16(Mot);
#endif
return fwrite(&Mot, 1, sizeof(word), Fichier) == sizeof(word);
}
// Lit un word (big-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int read_word_be(FILE *Fichier, word *Dest)
{
if (fread(Dest, 1, sizeof(word), Fichier) != sizeof(word))
return 0;
#if SDL_BYTEORDER != SDL_BIG_ENDIAN
*Dest = SDL_Swap16(*Dest);
#endif
return -1;
}
// Ecrit un word (big-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int write_word_be(FILE *Fichier, word Mot)
{
#if SDL_BYTEORDER != SDL_BIG_ENDIAN
Mot = SDL_Swap16(Mot);
#endif
return fwrite(&Mot, 1, sizeof(word), Fichier) == sizeof(word);
}
// Lit un dword (little-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int read_dword_le(FILE *Fichier, dword *Dest)
{
if (fread(Dest, 1, sizeof(dword), Fichier) != sizeof(dword))
return 0;
#if SDL_BYTEORDER != SDL_LIL_ENDIAN
*Dest = SDL_Swap32(*Dest);
#endif
return -1;
}
// Ecrit un dword (little-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int write_dword_le(FILE *Fichier, dword Mot)
{
#if SDL_BYTEORDER != SDL_LIL_ENDIAN
Mot = SDL_Swap32(Mot);
#endif
return fwrite(&Mot, 1, sizeof(dword), Fichier) == sizeof(dword);
}
// Lit un dword (big-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int read_dword_be(FILE *Fichier, dword *Dest)
{
if (fread(Dest, 1, sizeof(dword), Fichier) != sizeof(dword))
return 0;
#if SDL_BYTEORDER != SDL_BIG_ENDIAN
*Dest = SDL_Swap32(*Dest);
#endif
return -1;
}
// Ecrit un dword (big-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int write_dword_be(FILE *Fichier, dword Mot)
{
#if SDL_BYTEORDER != SDL_BIG_ENDIAN
Mot = SDL_Swap32(Mot);
#endif
return fwrite(&Mot, 1, sizeof(dword), Fichier) == sizeof(dword);
}
// Détermine la position du dernier '/' ou '\\' dans une chaine,
// typiquement pour séparer le nom de fichier d'un chemin.
// Attention, sous Windows, il faut s'attendre aux deux car
// par exemple un programme lancé sous GDB aura comme argv[0]:
// d:\Data\C\GFX2\grafx2/grafx2.exe
char * Position_dernier_slash(const char * Chaine)
{
const char * Position = NULL;
for (; *Chaine != '\0'; Chaine++)
if (*Chaine == SEPARATEUR_CHEMIN[0]
#ifdef __WIN32__
|| *Chaine == '/'
#endif
)
Position = Chaine;
return (char *)Position;
}
// Récupère la partie "nom de fichier seul" d'un chemin
void Extraire_nom_fichier(char *Destination, const char *Source)
{
const char * Position = Position_dernier_slash(Source);
if (Position)
strcpy(Destination,Position+1);
else
strcpy(Destination,Source);
}
// Récupère la partie "répertoire+/" d'un chemin.
void Extraire_chemin(char *Destination, const char *Source)
{
char * Position;
strcpy(Destination,Source);
Position = Position_dernier_slash(Destination);
if (Position)
*(Position+1) = '\0';
else
strcat(Destination, SEPARATEUR_CHEMIN);
}
int Fichier_existe(char * Fichier)
// Détermine si un fichier passé en paramètre existe ou non dans le
// répertoire courant.
{
struct stat buf;
int Resultat;
Resultat=stat(Fichier,&buf);
if (Resultat!=0)
return(errno!=ENOENT);
else
return 1;
}
int Repertoire_existe(char * Repertoire)
// Détermine si un répertoire passé en paramètre existe ou non dans le
// répertoire courant.
{
DIR* Enreg; // Structure de lecture des éléments
if (strcmp(Repertoire,"..")==0)
return 1;
else
{
// On va chercher si le répertoire existe à l'aide d'un Opendir. S'il
// renvoie NULL c'est que le répertoire n'est pas accessible...
Enreg=opendir(Repertoire);
if (Enreg==NULL)
return 0;
else
{
closedir(Enreg);
return 1;
}
}
/* Grafx2 - The Ultimate 256-color bitmap paint program
Copyright 2008 Yves Rizoud
Copyright 2007 Adrien Destugues
Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
Grafx2 is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.
Grafx2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grafx2; if not, see <http://www.gnu.org/licenses/> or
write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Fonctions de lecture/ecriture fichier, gèrent les systèmes big-endian et
// little-endian.
#include <SDL_endian.h>
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
#if defined(__amigaos4__)
#include <proto/dos.h>
#include <dirent.h>
#elif defined(__WATCOMC__)
#include <direct.h>
#elif defined(__WIN32__)
#include <dirent.h>
#include <windows.h>
#else
#include <dirent.h>
#endif
#include "struct.h"
#include "io.h"
word endian_magic16(word x)
{
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
return x;
#else
return SDL_Swap16(x);
#endif
}
dword endian_magic32(dword x)
{
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
return x;
#else
return SDL_Swap32(x);
#endif
}
// Lit un octet
// Renvoie -1 si OK, 0 en cas d'erreur
int read_byte(FILE *Fichier, byte *Dest)
{
return fread(Dest, 1, 1, Fichier) == 1;
}
// Ecrit un octet
// Renvoie -1 si OK, 0 en cas d'erreur
int write_byte(FILE *Fichier, byte Byte)
{
return fwrite(&Byte, 1, 1, Fichier) == 1;
}
// Lit des octets
// Renvoie -1 si OK, 0 en cas d'erreur
int read_bytes(FILE *Fichier, void *Dest, size_t Taille)
{
return fread(Dest, 1, Taille, Fichier) == Taille;
}
// Ecrit des octets
// Renvoie -1 si OK, 0 en cas d'erreur
int write_bytes(FILE *Fichier, void *Src, size_t Taille)
{
return fwrite(Src, 1, Taille, Fichier) == Taille;
}
// Lit un word (little-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int read_word_le(FILE *Fichier, word *Dest)
{
if (fread(Dest, 1, sizeof(word), Fichier) != sizeof(word))
return 0;
#if SDL_BYTEORDER != SDL_LIL_ENDIAN
*Dest = SDL_Swap16(*Dest);
#endif
return -1;
}
// Ecrit un word (little-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int write_word_le(FILE *Fichier, word Mot)
{
#if SDL_BYTEORDER != SDL_LIL_ENDIAN
Mot = SDL_Swap16(Mot);
#endif
return fwrite(&Mot, 1, sizeof(word), Fichier) == sizeof(word);
}
// Lit un word (big-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int read_word_be(FILE *Fichier, word *Dest)
{
if (fread(Dest, 1, sizeof(word), Fichier) != sizeof(word))
return 0;
#if SDL_BYTEORDER != SDL_BIG_ENDIAN
*Dest = SDL_Swap16(*Dest);
#endif
return -1;
}
// Ecrit un word (big-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int write_word_be(FILE *Fichier, word Mot)
{
#if SDL_BYTEORDER != SDL_BIG_ENDIAN
Mot = SDL_Swap16(Mot);
#endif
return fwrite(&Mot, 1, sizeof(word), Fichier) == sizeof(word);
}
// Lit un dword (little-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int read_dword_le(FILE *Fichier, dword *Dest)
{
if (fread(Dest, 1, sizeof(dword), Fichier) != sizeof(dword))
return 0;
#if SDL_BYTEORDER != SDL_LIL_ENDIAN
*Dest = SDL_Swap32(*Dest);
#endif
return -1;
}
// Ecrit un dword (little-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int write_dword_le(FILE *Fichier, dword Mot)
{
#if SDL_BYTEORDER != SDL_LIL_ENDIAN
Mot = SDL_Swap32(Mot);
#endif
return fwrite(&Mot, 1, sizeof(dword), Fichier) == sizeof(dword);
}
// Lit un dword (big-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int read_dword_be(FILE *Fichier, dword *Dest)
{
if (fread(Dest, 1, sizeof(dword), Fichier) != sizeof(dword))
return 0;
#if SDL_BYTEORDER != SDL_BIG_ENDIAN
*Dest = SDL_Swap32(*Dest);
#endif
return -1;
}
// Ecrit un dword (big-endian)
// Renvoie -1 si OK, 0 en cas d'erreur
int write_dword_be(FILE *Fichier, dword Mot)
{
#if SDL_BYTEORDER != SDL_BIG_ENDIAN
Mot = SDL_Swap32(Mot);
#endif
return fwrite(&Mot, 1, sizeof(dword), Fichier) == sizeof(dword);
}
// Détermine la position du dernier '/' ou '\\' dans une chaine,
// typiquement pour séparer le nom de fichier d'un chemin.
// Attention, sous Windows, il faut s'attendre aux deux car
// par exemple un programme lancé sous GDB aura comme argv[0]:
// d:\Data\C\GFX2\grafx2/grafx2.exe
char * Position_dernier_slash(const char * Chaine)
{
const char * Position = NULL;
for (; *Chaine != '\0'; Chaine++)
if (*Chaine == SEPARATEUR_CHEMIN[0]
#ifdef __WIN32__
|| *Chaine == '/'
#endif
)
Position = Chaine;
return (char *)Position;
}
// Récupère la partie "nom de fichier seul" d'un chemin
void Extraire_nom_fichier(char *Destination, const char *Source)
{
const char * Position = Position_dernier_slash(Source);
if (Position)
strcpy(Destination,Position+1);
else
strcpy(Destination,Source);
}
// Récupère la partie "répertoire+/" d'un chemin.
void Extraire_chemin(char *Destination, const char *Source)
{
char * Position;
strcpy(Destination,Source);
Position = Position_dernier_slash(Destination);
if (Position)
*(Position+1) = '\0';
else
strcat(Destination, SEPARATEUR_CHEMIN);
}
int Fichier_existe(char * Fichier)
// Détermine si un fichier passé en paramètre existe ou non dans le
// répertoire courant.
{
struct stat buf;
int Resultat;
Resultat=stat(Fichier,&buf);
if (Resultat!=0)
return(errno!=ENOENT);
else
return 1;
}
int Repertoire_existe(char * Repertoire)
// Détermine si un répertoire passé en paramètre existe ou non dans le
// répertoire courant.
{
DIR* Enreg; // Structure de lecture des éléments
if (strcmp(Repertoire,"..")==0)
return 1;
else
{
// On va chercher si le répertoire existe à l'aide d'un Opendir. S'il
// renvoie NULL c'est que le répertoire n'est pas accessible...
Enreg=opendir(Repertoire);
if (Enreg==NULL)
return 0;
else
{
closedir(Enreg);
return 1;
}
}
}

6
main.c
View File

@ -35,8 +35,8 @@
#include <string.h>
#include <signal.h>
#include <time.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL.h>
#include <SDL_image.h>
#include <unistd.h>
#include "pages.h"
#include "files.h"
@ -58,7 +58,7 @@
#elif defined(__macosx__)
#import <corefoundation/corefoundation.h>
#import <sys/param.h>
#elif defined(__AROS__) || defined(__BEOS__) || defined(__MORPHOS__)
#elif defined(__AROS__) || defined(__BEOS__) || defined(__MORPHOS__) || defined(__GP2X__)
#include "realpath.h"
#endif

View File

@ -36,7 +36,7 @@
#include "brush.h"
#include "windows.h"
#ifdef __WATCOMC__
#if defined(__WATCOMC__) || defined(__GP2X__)
#define M_PI 3.14159265358979323846
#endif

View File

@ -23,7 +23,7 @@
#include <string.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL.h>
#include "global.h"
#include "sdlscreen.h"
#include "divers.h"

View File

@ -23,7 +23,7 @@
#include <string.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL.h>
#include "global.h"
#include "sdlscreen.h"
#include "divers.h"

View File

@ -23,7 +23,7 @@
#include <string.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL.h>
#include "global.h"
#include "sdlscreen.h"
#include "divers.h"

View File

@ -9,6 +9,11 @@
#include <string.h>
#include <unistd.h>
#if defined(__GP2X__)
// This is a random default value ...
#define PATH_MAX 32768
#endif
static char *sep(char *path)
{
char *tmp, c;

View File

@ -22,7 +22,7 @@
*/
#include <string.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL.h>
#include "global.h"
#include "sdlscreen.h"
#include "erreurs.h"

View File

@ -22,7 +22,7 @@
#ifndef SDLSCREEN_H_INCLUDED
#define SDLSCREEN_H_INCLUDED
#include <SDL/SDL.h>
#include <SDL.h>
#include "struct.h"
void Set_Mode_SDL(int *,int *,int);

View File

@ -33,7 +33,7 @@
#ifdef __macosx__
#include <SDL_ttf/SDL_ttf.h>
#else
#include <SDL/SDL_ttf.h>
#include <SDL_ttf.h>
#endif
#ifdef __linux__
@ -46,7 +46,8 @@
#endif
#endif
#endif
#include <SDL/SDL_image.h>
#include <SDL_image.h>
// SFont
#include "SFont.h"
@ -319,6 +320,7 @@ void Initialisation_Texte(void)
#endif
#elif defined(__linux__)
#ifndef NOTTF
#define USE_XLIB
#ifdef USE_XLIB
@ -333,6 +335,7 @@ void Initialisation_Texte(void)
XFreeFontPath(font_path_list);
}
#endif
#endif
#elif defined(__amigaos4__)
#ifndef NOTTF
for_each_file( "FONTS:_TrueType", Ajout_fonte );