diff options
| author | Joost Peters | 2003-04-10 13:44:50 +0000 | 
|---|---|---|
| committer | Joost Peters | 2003-04-10 13:44:50 +0000 | 
| commit | 81ac7cc8f8b802c2078a41c2ac2ac2fadf5ae5bd (patch) | |
| tree | 2b0f9d801d1d8e0fbba6573defa88398faa076cb /backends | |
| parent | e169b15efac96849d77ad69081cace179318be6f (diff) | |
| download | scummvm-rg350-81ac7cc8f8b802c2078a41c2ac2ac2fadf5ae5bd.tar.gz scummvm-rg350-81ac7cc8f8b802c2078a41c2ac2ac2fadf5ae5bd.tar.bz2 scummvm-rg350-81ac7cc8f8b802c2078a41c2ac2ac2fadf5ae5bd.zip | |
fixed GP32 port
svn-id: r6958
Diffstat (limited to 'backends')
| -rw-r--r-- | backends/gp32/build.rules | 2 | ||||
| -rw-r--r-- | backends/gp32/gp-fs.cpp | 152 | ||||
| -rw-r--r-- | backends/gp32/gp32.cpp | 173 | ||||
| -rw-r--r-- | backends/gp32/gp32.h | 6 | ||||
| -rw-r--r-- | backends/gp32/portdefs.h | 28 | 
5 files changed, 257 insertions, 104 deletions
| diff --git a/backends/gp32/build.rules b/backends/gp32/build.rules index 628c2f67fd..bdcfb25279 100644 --- a/backends/gp32/build.rules +++ b/backends/gp32/build.rules @@ -32,4 +32,4 @@ LDFLAGS = -Wl,-T $(LNKSCRIPT)  LIBS	+= -lgpgraphic -lgpmem -lgpos -lgpstdlib -lgpstdio -lgpsound -lgpfont  INCLUDES += -Ibackends/gp32  MODULES	+= backends/gp32 -OBJS	+= $(CCBASE)/arm-agb-elf/lib/gpstart/gpstart.o backends/gp32/gp32.o
\ No newline at end of file +OBJS	+= $(CCBASE)/arm-agb-elf/lib/gpstart/gpstart.o backends/gp32/gp32.o backends/gp32/gp-fs.o diff --git a/backends/gp32/gp-fs.cpp b/backends/gp32/gp-fs.cpp new file mode 100644 index 0000000000..79173f2e83 --- /dev/null +++ b/backends/gp32/gp-fs.cpp @@ -0,0 +1,152 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2001-2003 The ScummVM project + * + * This program 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; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. + * + * $Header$ + */ + +#if defined (__GP32__) + +#include "../fs/fs.h" +#include "stdio.h" + +extern "C" { +	#include "gpstdio.h" +} + +/* + * Implementation of the ScummVM file system API based on GP32. + */ + +class GP32FilesystemNode : public FilesystemNode { +protected: +	String _displayName; +	bool _isDirectory; +	bool _isValid; +	String _path; +	 +public: +	GP32FilesystemNode(); +	GP32FilesystemNode(const String &path); +	GP32FilesystemNode(const GP32FilesystemNode *node); + +	virtual String displayName() const { return _displayName; } +	virtual bool isValid() const { return _isValid; } +	virtual bool isDirectory() const { return _isDirectory; } +	virtual String path() const { return _path; } + +	virtual FSList *listDir(ListMode mode = kListDirectoriesOnly) const; +	virtual FilesystemNode *parent() const; +	virtual FilesystemNode *clone() const { return new GP32FilesystemNode(this); } +}; + + +FilesystemNode *FilesystemNode::getRoot() { +	return new GP32FilesystemNode(); +} + +GP32FilesystemNode::GP32FilesystemNode() { +	_displayName = "gp:\\"; +	_isValid = true; +	_isDirectory = true; +	_path = "gp:\\"; +} + +/* +GP32FilesystemNode::GP32FilesystemNode(const String &p) { +	// TODO - extract last component from path +	_displayName = p; +	// TODO - check whether it is a directory, and whether the file actually exists +	_isValid = true; +	_isDirectory = true; +	_path = p; +} +*/ + +GP32FilesystemNode::GP32FilesystemNode(const GP32FilesystemNode *node) { +	_displayName = node->_displayName; +	_isValid = node->_isValid; +	_isDirectory = node->_isDirectory; +	_path = node->_path; +} + +FSList *GP32FilesystemNode::listDir(ListMode mode) const { +	assert(_isDirectory); + +	GPDIRENTRY dp; +	ulong read; + +	FSList *myList = new FSList(); +	 +	int start=0; // current file + +	// ... loop over dir entries using readdir +	while (GpDirEnumList(_path.c_str(), start++, 1, &dp, &read)  == SM_OK) {  +		if (strcmp(dp.name,".")==0|| strcmp(dp.name,"..")==0) continue; +		GP32FilesystemNode entry; +		entry._displayName = dp.name; +		entry._path = _path; +		entry._path += dp.name; +		 +		GPFILEATTR attr; +		char s[256]; +		sprintf(s, "%s%s", _path.c_str(), dp.name); +		GpFileAttr(s, &attr); +		entry._isDirectory = attr.attr & (1<<4); + +		// Honor the chosen mode +		if ((mode == kListFilesOnly && entry._isDirectory) || +			(mode == kListDirectoriesOnly && !entry._isDirectory)) +			continue; + +		if (entry._isDirectory) +			entry._path += "\\"; //ph0x +		myList->push_back(entry); +	}	 +	return myList; +} + +const char *lastPathComponent(const ScummVM::String &str) { +	const char *start = str.c_str(); +	const char *cur = start + str.size() - 2; +	 +	while (cur > start && *cur != '\\') { //ph0x +		--cur; +	} +	 +	return cur+1; +} + +FilesystemNode *GP32FilesystemNode::parent() const { +	 +	GP32FilesystemNode *p = new GP32FilesystemNode(); + +	// Root node is its own parent. Still we can't just return this +	// as the GUI code will call delete on the old node. +	if (_path != "gp:\\") {  //ph0x +		const char *start = _path.c_str(); +		const char *end = lastPathComponent(_path); + +		p->_path = String(start, end - start); +		p->_isValid = true; +		p->_isDirectory = true; +		p->_displayName = lastPathComponent(p->_path); +	} +	return p; +} + +#endif // defined(__GP32__) + diff --git a/backends/gp32/gp32.cpp b/backends/gp32/gp32.cpp index 19a1aaec57..133907b425 100644 --- a/backends/gp32/gp32.cpp +++ b/backends/gp32/gp32.cpp @@ -30,9 +30,10 @@ void GpSetPaletteEntry(u8 i, u8 r, u8 g, u8 b);  #define NAMEME_SURFACE 1  #define DEBUG_SURFACE 2 -GPDRAWSURFACE gpDraw[2];	// surfaces +GPDRAWSURFACE gpDraw[3];	// surfaces  int mx=1, my=1;	// wrong if 0?  char currsurface; +FILE *fstderr, *fstdout, *fstdin;  // Set colors of the palette  void OSystem_GP32::set_palette(const byte *colors, uint start, uint num) {  @@ -609,7 +610,7 @@ void OSystem_GP32::draw_mouse() {  			*bak++ = *dst;  			color = *src++;  			if (color != 0xFF)	// 0xFF = transparent, don't draw -				*dst = RGB_TO_16(_currentPalette[color].r, _currentPalette[color].g, _currentPalette[color].b); +				*dst = RGBToColor(_currentPalette[color].r, _currentPalette[color].g, _currentPalette[color].b);  			dst++;  			width--;  		} @@ -824,7 +825,11 @@ void OSystem_GP32::set_mouse_pos(int x, int y) {  		undraw_mouse();  	}  } -	 + +void OSystem_GP32::warp_mouse(int x, int y) { +	set_mouse_pos(x, y);	 +} +  // Set the bitmap that's used when drawing the cursor.  void OSystem_GP32::set_mouse_cursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y) {   	_mouse_cur_state.w = w; @@ -890,8 +895,8 @@ bool OSystem_GP32::poll_event(Event *event) { 	// fixme: make more user-friendly  		if (key & GPC_VK_FL && key & GPC_VK_FR) { // L+R = save state  			printf("Saving game, please wait..."); -			extern void autosave(void * engine);  -			autosave(NULL); //FIXME? +			//extern void autosave(void * engine);  +			//autosave(NULL); //FIXME?  			do key=GpKeyGet(); while (key != GPC_VK_NONE) ;  			return false;  		} else @@ -1078,7 +1083,7 @@ void OSystem_GP32::delete_mutex(void *mutex) { }  // Quit  void gphalt(int);  void OSystem_GP32::quit() {  -	gphalt(); +	exit(0);  }  // Overlay @@ -1220,56 +1225,34 @@ OSystem *OSystem_GP32_create(int gfx_mode, bool full_screen) {  extern "C" int write(int fd, void *p, size_t n);  int write(int fd, void *p, size_t n) { return 0; } //ph0x hack! -// fixme - unnecessary? -class GP32SaveFile : public SaveFile { -private: -	FILE *fh; -public: -	GP32SaveFile(FILE *f) : fh(f) { } - -	~GP32SaveFile(); - -	int fread(void *buf, int size, int cnt); -	int fwrite(void *buf, int size, int cnt); -} - -class GP32SaveFileManager : public SaveFileManager { -	SaveFile *open_savefile(const char *filename, bool saveOrLoad); -} - -int GP32SaveFile::fwrite(void *buf, int size, int cnt) { -	// implement me -	return ::fwrite(buf, size, cnt, fh); -} - -SaveFile GP32SaveFileManager::open_savefile(const char *filename, -					    bool saveOrLoad) { -	// implement me -	FILE *fh = ::fopen(filename, (saveOrLoad? "wb":"rb")); -	//if (saveOrLoad) 	error("Autosaving.."); -	return fh? new GP32SaveFile(fh) : NULL; -} - -void GP32SaveFile::~GP32SaveFile() { -	// implement me -	::fclose(fh); -} -int GP32SaveFile::fread(void *buf, int size, int cnt) { -	// implement me -	return 	::fread(buf, size, cnt, fh); - -} - -SaveFileManager *OSystem_GP32::get_savefile_manager() { -	return new GP32SaveFileManager(); -} -  // Converts 8bit rgb values to a GP32 palette value   void GpSetPaletteEntry(u8 i, u8 r, u8 g, u8 b) {    GP_PALETTEENTRY entry = GP_RGB16(r,g,b);    GpPaletteEntryChange ( i, 1, &entry, 0 );  } +void switchsurf(int surf) { +	GPLCDINFO lcd; +	GpLcdInfoGet(&lcd); + +	if (surf == DEBUG_SURFACE) { +		if (lcd.lcd_global.U8_lcd.bpp == 16) +			GpGraphicModeSet(8, NULL); + +		currsurface = DEBUG_SURFACE; +		GpSurfaceFlip(&gpDraw[currsurface]); +		GpSetPaletteEntry(0, 0, 0, 0); +		GpSetPaletteEntry(1, 255, 0, 0); +		GpSetPaletteEntry(2, 255, 255, 255); +	} else { +		if (surf == GAME_SURFACE) { +			currsurface = GAME_SURFACE; +			GpSurfaceFlip(&gpDraw[currsurface]); +		} +	} +			 +} +  int gpprintf(const char *fmt, ...) { //return 0; //fixme  	static int y;  	char s[1024]; // ? @@ -1443,6 +1426,39 @@ void gphalt(int code=0) {  	while (1);   } +char *gpstrdup(const char *strSource) { + +	char *buffer; +	buffer = (char *)malloc(strlen(strSource) + 1); +	if (buffer) +			strcpy(buffer, strSource); +	return buffer; +} + +time_t gptime(time_t *timer) { + +	time_t t = GpTickCountGet() / 1000; +	if (timer) +		*timer = t; + +	return t; +} + +void gpdeinit() { +	fclose(fstdin); +	fclose(fstdout); +	fclose(fstderr); +} + +void gpexit(int code) { + +	switchsurf(DEBUG_SURFACE); + +	printf("Your GP32 will now restart..."); +	gpdeinit(); +	GpAppExit(); +} +  //#include <string.h>  #include "common/gamedetector.h"  VersionSettings* menu() { @@ -1501,68 +1517,41 @@ VersionSettings* menu() {  }  int gpinit() {	 + +	ERR_CODE err; +	 +	//GpKeyInit(); +	GpFatInit(); +	GpRelativePathSet("gp:\\gpmm"); +  	// Initialize graphics   	GpGraphicModeSet(8, NULL);  	GpLcdSurfaceGet(&gpDraw[DEBUG_SURFACE], DEBUG_SURFACE);  	GpLcdSurfaceGet(&gpDraw[NAMEME_SURFACE], NAMEME_SURFACE);		  	GpLcdSurfaceGet(&gpDraw[GAME_SURFACE], GAME_SURFACE);	 -//	gpDraw[GAME_SURFACE].oy=19; //center screen? -//	GpRectFill(NULL,&gpDraw[GAME_SURFACE], 0, 0, 320, 240, 0); //black border -	GpLcdEnable(); +	GpSetPaletteEntry(0, 0, 0, 0); +	GpSetPaletteEntry(1, 255, 0, 0); +	GpSetPaletteEntry(2, 255, 255, 255); +  	// fixme - use get function  	currsurface=DEBUG_SURFACE;  	GpSurfaceSet(&gpDraw[currsurface]); -//	_gp_sdk_init(); -//	GpKeyInit(); -	GpFatInit(); -	GpRelativePathSet("gp:"); // fixme (get path) +	GpLcdEnable(); -/*	 -	char s[256]; -	GpRelativePathGet(s); -	printf("path=%s", s); -*/	  #ifdef GPDEBUG -	printf(">waiting debugger..."); +	printf(">waiting for debugger...");  	InitDebug();  #endif  	printf(">Running ScummVM");  }	 -void createfakeini() { -/* -char s[] = "\ -[dott]\n\ -gameid=tentacle\n\ -[samnmax]\n\ -gameid=samnmax\n\ -[atlantis]\n\ -gameid=playfate\n\ -"; -FILE *f=fopen("scummvm.ini", "w"); -fwrite(s, 1, sizeof(s)+1, f); -fclose(f); -*/ -	printf("Creating scummvm.ini, please wait..."); -	FILE *f=fopen("scummvm.ini", "w"); -	const VersionSettings *v = version_settings;	 -	char s[256]; -	while (v->filename && v->gamename) { -		sprintf(s, "[%s]\ngameid=%s\n", v->filename, v->filename);  -		fwrite(s, 1, strlen(s), f); -		v++; -	} -	fclose(f); -} -  extern "C" void GpMain (void * arg); // hack  void GpMain (void * arg) {  	gpinit(); -	createfakeini(); //FIXME: use methods :) - +	  	// fixme - use get function  	currsurface=GAME_SURFACE;  	GpSurfaceFlip(&gpDraw[currsurface]); @@ -1572,6 +1561,6 @@ void GpMain (void * arg) {  	extern int main(int argc, char *argv[]);  	main(argc, argv); -		 +	  	error("returned from main ?!");	  } diff --git a/backends/gp32/gp32.h b/backends/gp32/gp32.h index f56de538f7..7445167ba6 100644 --- a/backends/gp32/gp32.h +++ b/backends/gp32/gp32.h @@ -28,6 +28,7 @@  #include "scumm/saveload.h"  #include "common/scaler.h" +#include "portdefs.h"  #include "sdl.h"  class OSystem_GP32 : public OSystem { @@ -52,6 +53,7 @@ public:  	// Either show or hide the mouse cursor  	bool show_mouse(bool visible); +	void warp_mouse(int x, int y);  	// Set the position of the mouse cursor  	void set_mouse_pos(int x, int y); @@ -115,10 +117,6 @@ public:  	void grab_overlay(int16 *buf, int pitch);  	void copy_rect_overlay(const int16 *buf, int pitch, int x, int y, int w, int h); -	// Savefiles -	SaveFileManager *get_savefile_manager(); - -  	static OSystem *create(int gfx_mode, bool full_screen);  private:  	typedef void ScalerProc(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, diff --git a/backends/gp32/portdefs.h b/backends/gp32/portdefs.h index 6f6315ebfb..57d1c66f7f 100644 --- a/backends/gp32/portdefs.h +++ b/backends/gp32/portdefs.h @@ -55,6 +55,8 @@ typedef int s32;  	extern void *gpmalloc(size_t size);  	extern void *gpcalloc(size_t nitems, size_t size);  	extern void gpfree(void *block); +	extern char *gpstrdup(const char *s); +  	#define malloc gpmalloc   	#define calloc gpcalloc //gm_calloc  	#define free gpfree	 @@ -65,16 +67,22 @@ typedef int s32;  	#define strncpy gm_strncpy  	#define strcat gm_strcat  	#define sprintf gm_sprintf*/ +	#define strdup gpstrdup  	#define assert(e) ((e) ? 0 : (printf("!AS: " #e " (%s, %d)\n", __FILE__, __LINE__)))  	#define ASSERT assert  	#define ENDLESSLOOP while (1) +	  	#define FILE F_HANDLE -	#define stderr NULL	// hack... -	#define stdout stderr -	#define stdin stderr +	extern FILE *fstderr; +	extern FILE *fstdout; +	extern FILE *fstdin; + +	#define stderr fstderr +	#define stdout fstdout +	#define stdin fstdin  	extern FILE *gpfopen(const char *filename, const char *mode);  	extern int gpfclose(FILE *stream); @@ -101,10 +109,16 @@ typedef int s32;  	#define fprintf gpfprintf  	#define fflush gpfflush -	extern void gphalt(int code=0); -	#define exit gphalt +	extern void gpexit(int code); +	#define exit gpexit  	//#define error printf -	#define time(x) (0) // fixme! (SIMON) +	extern time_t gptime(time_t *timer); +	#define time gptime +	#define MARK printf("MARK: %s, %s, %d", __FILE__, __FUNCTION__, __LINE__); +	 +	extern void *gpmemset (void *s, int c, size_t n); +	extern void *gpmemcpy (void *dest, const void *src, size_t n); +	//#define memset gpmemset +	//#define memcpy gpmemcpy -	// EOF | 
