[Scummvm-cvs-logs] SF.net SVN: scummvm: [23341] scummvm/branches/branch-0-9-0/backends/gp32
wonst719 at users.sourceforge.net
wonst719 at users.sourceforge.net
Thu Jun 29 10:23:02 CEST 2006
Revision: 23341
Author: wonst719
Date: 2006-06-29 01:22:45 -0700 (Thu, 29 Jun 2006)
ViewCVS: http://svn.sourceforge.net/scummvm/?rev=23341&view=rev
Log Message:
-----------
Backport backend changes.
Modified Paths:
--------------
scummvm/branches/branch-0-9-0/backends/gp32/Makefile
scummvm/branches/branch-0-9-0/backends/gp32/debug-gdbstub-usb.cpp
scummvm/branches/branch-0-9-0/backends/gp32/gp32_main.cpp
scummvm/branches/branch-0-9-0/backends/gp32/gp32_osys.h
scummvm/branches/branch-0-9-0/backends/gp32/gp32std.cpp
scummvm/branches/branch-0-9-0/backends/gp32/gp32std.h
scummvm/branches/branch-0-9-0/backends/gp32/gp32std_sound.cpp
scummvm/branches/branch-0-9-0/backends/gp32/portdefs.h
Added Paths:
-----------
scummvm/branches/branch-0-9-0/backends/gp32/gp32std_file.cpp
scummvm/branches/branch-0-9-0/backends/gp32/gp32std_file.h
scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.cpp
scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.h
Modified: scummvm/branches/branch-0-9-0/backends/gp32/Makefile
===================================================================
--- scummvm/branches/branch-0-9-0/backends/gp32/Makefile 2006-06-29 05:34:56 UTC (rev 23340)
+++ scummvm/branches/branch-0-9-0/backends/gp32/Makefile 2006-06-29 08:22:45 UTC (rev 23341)
@@ -123,8 +123,10 @@
# Custom GP32 std library
OBJS += backends/gp32/gp32std.o \
+ backends/gp32/gp32std_file.o \
backends/gp32/gp32std_grap.o \
backends/gp32/gp32std_input.o \
+ backends/gp32/gp32std_memory.o \
backends/gp32/gp32std_sound.o \
#backends/gp32/dmaaudio_asm.o \
#backends/gp32/dmaaudio.o \
Modified: scummvm/branches/branch-0-9-0/backends/gp32/debug-gdbstub-usb.cpp
===================================================================
--- scummvm/branches/branch-0-9-0/backends/gp32/debug-gdbstub-usb.cpp 2006-06-29 05:34:56 UTC (rev 23340)
+++ scummvm/branches/branch-0-9-0/backends/gp32/debug-gdbstub-usb.cpp 2006-06-29 08:22:45 UTC (rev 23341)
@@ -943,25 +943,18 @@
switch(CSPR & 0x1f) {
case 0x10: // USER
return 0;
- break;
case 0x11: // FIQ
return 1;
- break;
case 0x12: // IRQ
return 2;
- break;
case 0x13: // Supervisor
return 3;
- break;
case 0x17: // Abort
return 4;
- break;
case 0x1B: // Undefined/Breakpoint
return 5;
- break;
case 0x1F: // System
return 6;
- break;
default:
return -1;
}
@@ -1299,75 +1292,59 @@
// This is true if Z is set in CSPR
if ((CSPR & (1 << 30)) != 0) return true;
else return false;
-
- break;
case 1: // NE
// This should be true if Z is not set.
if ((CSPR & (1 << 30)) == 0) return true;
else return false;
- break;
case 2: // CS/HS
// this one should be true if C is set.
if ((CSPR & (1 << 29)) != 0) return true;
else return false;
- break;
case 3: // CC/LO
// this one should be true if C is clear.
if ((CSPR & (1 << 29)) == 0) return true;
else return false;
- break;
case 4: // MI
// this one should be true if N is set
if ((CSPR & (1 << 31)) != 0) return true;
else return false;
- break;
case 5: // PL
// this one should be true if N is clear.
if ((CSPR & (1 << 31)) == 0) return true;
else return false;
- break;
case 6: // VS
// this one should be true if V is set
if ((CSPR & (1 << 28)) != 0) return true;
else return false;
- break;
case 7: // VC
// this one should be true if V is clear.
if ((CSPR & (1 << 28)) == 0) return true;
else return false;
- break;
case 8: // HI
// This is true if C and Z is clear
if (((CSPR & (1 << 30)) == 0) && ((CSPR & (1 << 29)) == 0)) return true;
else return false;
- break;
case 9: // LS
// C clear OR Z set
if (((CSPR & (1 << 29)) == 0) || ((CSPR & (1 << 30)) != 0)) return true;
else return false;
- break;
case 10: // GE
// N set AND V set || N clear and V clear
if ((CSPR & (1 << 31)) == (CSPR & (1 << 28))) return true;
else return false;
- break;
case 11: // LT
// N != V
if ((CSPR & (1 << 31)) != (CSPR & (1 << 28))) return true;
else return false;
- break;
case 12: // GT
// Z == 0, N == V
if (((CSPR & (1 << 30)) == 0) && ((CSPR & (1 << 31)) == (CSPR & (1 << 28)))) return true;
else return false;
- break;
case 13: // LE
if (((CSPR & (1 << 30)) == 1) && ((CSPR & (1 << 31)) != (CSPR & (1 << 28)))) return true;
else return false;
- break;
case 14: // AL
return true;
- break;
default:
break;
}
@@ -1662,20 +1639,14 @@
switch (shift) {
case 0: // LSL
return LSL(uiRegisterValue, amount);
- break;
case 1: // LSR
return LSR(uiRegisterValue, amount);
- break;
case 2: // ASR
return ASR(uiRegisterValue, amount);
- break;
case 3: // ROR
return ROR(uiRegisterValue, amount);
- break;
-
default:
break;
-
}
return 0;
}
Modified: scummvm/branches/branch-0-9-0/backends/gp32/gp32_main.cpp
===================================================================
--- scummvm/branches/branch-0-9-0/backends/gp32/gp32_main.cpp 2006-06-29 05:34:56 UTC (rev 23340)
+++ scummvm/branches/branch-0-9-0/backends/gp32/gp32_main.cpp 2006-06-29 08:22:45 UTC (rev 23341)
@@ -55,6 +55,9 @@
}
void GpMain(void *arg) {
+ extern void memChunkInit();
+ memChunkInit();
+
init();
readConfigVars();
@@ -78,6 +81,10 @@
// Invoke the actual ScummVM main entry point:
//int res = scummvm_main(argc, argv);
int res = scummvm_main(1, NULL);
+
+ extern void memChunkDeinit();
+ memChunkDeinit();
+
g_system->quit(); // TODO: Consider removing / replacing this!
//return res;
Modified: scummvm/branches/branch-0-9-0/backends/gp32/gp32_osys.h
===================================================================
--- scummvm/branches/branch-0-9-0/backends/gp32/gp32_osys.h 2006-06-29 05:34:56 UTC (rev 23340)
+++ scummvm/branches/branch-0-9-0/backends/gp32/gp32_osys.h 2006-06-29 08:22:45 UTC (rev 23341)
@@ -85,62 +85,62 @@
public:
OSystem_GP32();
- virtual ~OSystem_GP32();
+ ~OSystem_GP32();
- virtual bool hasFeature(Feature f);
- virtual void setFeatureState(Feature f, bool enable);
- virtual bool getFeatureState(Feature f);
- virtual const GraphicsMode *getSupportedGraphicsModes() const;
- virtual int getDefaultGraphicsMode() const;
- virtual bool setGraphicsMode(int mode);
+ bool hasFeature(Feature f);
+ void setFeatureState(Feature f, bool enable);
+ bool getFeatureState(Feature f);
+ const GraphicsMode *getSupportedGraphicsModes() const;
+ int getDefaultGraphicsMode() const;
+ bool setGraphicsMode(int mode);
bool setGraphicsMode(const char *name);
- virtual int getGraphicsMode() const;
- virtual void initSize(uint width, uint height);
- virtual int16 getHeight();
- virtual int16 getWidth();
- virtual void setPalette(const byte *colors, uint start, uint num);
- virtual void grabPalette(byte *colors, uint start, uint num);
+ int getGraphicsMode() const;
+ void initSize(uint width, uint height);
+ int16 getHeight();
+ int16 getWidth();
+ void setPalette(const byte *colors, uint start, uint num);
+ void grabPalette(byte *colors, uint start, uint num);
- virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h);
- virtual void updateScreen();
- virtual void setShakePos(int shakeOffset);
+ void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h);
+ void updateScreen();
+ void setShakePos(int shakeOffset);
- virtual void showOverlay();
- virtual void hideOverlay();
- virtual void clearOverlay();
- virtual void grabOverlay(OverlayColor *buf, int pitch);
- virtual void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h);
- virtual int16 getOverlayHeight();
- virtual int16 getOverlayWidth();
+ void showOverlay();
+ void hideOverlay();
+ void clearOverlay();
+ void grabOverlay(OverlayColor *buf, int pitch);
+ void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h);
+ int16 getOverlayHeight();
+ int16 getOverlayWidth();
- virtual OverlayColor RGBToColor(uint8 r, uint8 g, uint8 b);
- virtual void colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b);
+ OverlayColor RGBToColor(uint8 r, uint8 g, uint8 b);
+ void colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b);
- virtual bool showMouse(bool visible);
+ bool showMouse(bool visible);
- virtual void warpMouse(int x, int y);
- virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int cursorTargetScale = 1);
+ void warpMouse(int x, int y);
+ void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int cursorTargetScale = 1);
- virtual bool pollEvent(Event &event);
- virtual uint32 getMillis();
- virtual void delayMillis(uint msecs);
+ bool pollEvent(Event &event);
+ uint32 getMillis();
+ void delayMillis(uint msecs);
- virtual void setTimerCallback(TimerProc callback, int interval);
+ void setTimerCallback(TimerProc callback, int interval);
- virtual MutexRef createMutex(void);
- virtual void lockMutex(MutexRef mutex);
- virtual void unlockMutex(MutexRef mutex);
- virtual void deleteMutex(MutexRef mutex);
+ MutexRef createMutex(void);
+ void lockMutex(MutexRef mutex);
+ void unlockMutex(MutexRef mutex);
+ void deleteMutex(MutexRef mutex);
- virtual bool setSoundCallback(SoundProc proc, void *param);
- virtual void clearSoundCallback();
- virtual int getOutputSampleRate() const;
+ bool setSoundCallback(SoundProc proc, void *param);
+ void clearSoundCallback();
+ int getOutputSampleRate() const;
- virtual void quit();
+ void quit();
- virtual void setWindowCaption(const char *caption);
+ void setWindowCaption(const char *caption);
- virtual void displayMessageOnOSD(const char *msg);
+ void displayMessageOnOSD(const char *msg);
void fillMouseEvent(Event &event, int x, int y);
void handleKbdMouse();
Modified: scummvm/branches/branch-0-9-0/backends/gp32/gp32std.cpp
===================================================================
--- scummvm/branches/branch-0-9-0/backends/gp32/gp32std.cpp 2006-06-29 05:34:56 UTC (rev 23340)
+++ scummvm/branches/branch-0-9-0/backends/gp32/gp32std.cpp 2006-06-29 08:22:45 UTC (rev 23341)
@@ -33,13 +33,8 @@
#include "backends/gp32/gp32std.h"
#include "backends/gp32/gp32std_grap.h"
+#include "backends/gp32/gp32std_memory.h"
-FILE *gp_stderr = NULL;
-FILE *gp_stdout = NULL;
-FILE *gp_stdin = NULL;
-
-//#define USE_CACHE
-
#define DEBUG_MAX 5
char debline[DEBUG_MAX][256];
static int debnext = 0;
@@ -71,300 +66,6 @@
// gp_delay(100);
}
-//////////////////
-//File functions
-
-GPFILE *gp_fopen(const char *fileName, const char *openMode) {
- //FIXME: allocation, mode, malloc -> new
- uint32 mode;
- GPFILE *file;
- ERR_CODE err;
- char tempPath[256];
-
- if (!strchr(fileName, '.')) {
- sprintf(tempPath, "%s.", fileName);
- fileName = tempPath;
- }
-
- file = (GPFILE *)malloc(sizeof(GPFILE));
-
-// NP("%s(\"%s\", \"%s\")", __FUNCTION__, fileName, openMode);
-
- // FIXME add binary/text support
- if (tolower(openMode[0]) == 'r') {
- mode = OPEN_R;
- GpFileGetSize(fileName, &file->size);
- err = GpFileOpen(fileName, mode, &file->handle);
- } else if (tolower(openMode[0]) == 'w') {
- //printf("open if as W");
- file->size = 0; // FIXME? new file has no size?
- file->cachePos = 0;
- mode = OPEN_W;
- err = GpFileCreate(fileName, ALWAYS_CREATE, &file->handle);
- } else if (tolower(openMode[0]) == 'a') {
- warning("We do not support 'a' file open mode.");
- free(file);
- return NULL;
- } else {
- error("wrong file mode");
- }
-
- if (!file) {
- error("%s: cannot create FILE structure", __FUNCTION__);
- }
- if (err) {
-// BP("%s: IO error %d", __FUNCTION__, err);
- free(file);
- return NULL;
- }
-
- return file;
-}
-
-int gp_fclose(GPFILE *stream) {
- if (!stream) {
- //warning("closing null file");
- return 1;
- }
-
-/* if (*(uint32 *)((char *)stream - sizeof(uint32)) == 0x4321) {
- debug(0, "Double closing", __FUNCTION__);
- return 1;
- }
-*/
-
-#ifdef USE_CACHE
- if (stream->cachePos) {
- GpFileWrite(stream->handle, (char *)stream->cacheData, stream->cachePos); // flush cache
- stream->cachePos = 0;
- }
-#endif
-
- ERR_CODE err = GpFileClose(stream->handle);
- free(stream);
-
- return err;
-}
-
-int gp_fseek(GPFILE *stream, long offset, int whence) {
- ulong dummy;
-
- switch (whence) {
- case SEEK_SET:
- whence = FROM_BEGIN;
- break;
- case SEEK_CUR:
- whence = FROM_CURRENT;
- break;
- case SEEK_END:
- whence = FROM_END;
- break;
- }
- return GpFileSeek(stream->handle, whence, offset, (long *)&dummy);
-}
-
-//TODO: read cache
-size_t gp_fread(void *ptr, size_t size, size_t n, GPFILE *stream) {
- ulong readcount = 0;
- ERR_CODE err = GpFileRead(stream->handle, ptr, size * n, &readcount); //fixme? size*n
- return readcount / size; //FIXME?
-}
-
-size_t gp_fwrite(const void *ptr, size_t size, size_t n, GPFILE *stream) {
- int len = size * n;
-
- if (!stream) {
- //warning("writing to null file");
- return 0;
- }
-
-#ifdef USE_CACHE
- if (stream->cachePos + len < FCACHE_SIZE) {
- memcpy(stream->cacheData + stream->cachePos, ptr, len);
- stream->cachePos += len;
- } else {
- if (stream->cachePos) {
- GpFileWrite(stream->handle, stream->cacheData, stream->cachePos); // flush cache
- stream->cachePos = 0;
- }
-
-#endif
- ERR_CODE err = GpFileWrite(stream->handle, ptr, len);
- if (!err)
- return n;
- else
- return -err;
-#ifdef USE_CACHE
- }
-#endif
- return 0;
-}
-
-//FIXME? use standard func
-long gp_ftell(GPFILE *stream) {
- ulong pos = 0;
- ERR_CODE err = GpFileSeek(stream->handle, FROM_CURRENT, 0, (long*)&pos);
- return pos;
-}
-
-void gp_clearerr(GPFILE *stream)
-{
-}
-
-//FIXME!
-int gp_feof(GPFILE *stream) {
- return gp_ftell(stream) >= stream->size;
-}
-
-char gp_fgetc(GPFILE *stream) {
- char c[1];
-
- gp_fread(&c[0], 1, 1, stream);
- return c[0];
-}
-
-char *gp_fgets(char *s, int n, GPFILE *stream) {
- int i = 0;
-
- while (!gp_feof(stream) && i < n) {
- gp_fread(&s[i], 1, 1, stream);
- if (s[i] == '\n') {
- s[i + 1] = 0;
- return s;
- }
- i++;
- }
- if (gp_feof(stream))
- return NULL;
- else
- return s;
-}
-
-int gp_fprintf(GPFILE *stream, const char *fmt, ...) {
- char s[256];
- va_list marker;
-
- va_start(marker, fmt);
- vsnprintf(s, 256, fmt, marker);
- va_end(marker);
-
- return gp_fwrite(s, 1, strlen(s), stream);
-}
-
-int gp_fflush(GPFILE *stream) {
- return 0;
-}
-
-int gp_ferror(GPFILE *stream) {
- return 0;
-}
-
-/////////////////////
-//Memory management
-#undef memcpy
-#undef memset
-void *gp_memcpy(void *dst, const void *src, size_t count) {
- return memcpy(dst, src, count);
-}
-
-void *gp_memset(void *dst, int val, size_t count) {
- return memset(dst, val, count);
-}
-
-void *gp_malloc(size_t size) {
- uint32 np;
- uint32 *up;
-
- np = (uint32) gm_malloc(size + sizeof(uint32));
-
- if (np) {
- up = (uint32 *) np;
- *up = 0x1234;
- return (void *)(np + sizeof(uint32));
- }
-
- return NULL;
-}
-
-void *gp_calloc(size_t nitems, size_t size) {
- void *p = gp_malloc(nitems * size); //gpcalloc doesnt clear?
-
- gp_memset(p, 0, nitems * size);
-
-// if (*(uint8 *)p != 0)
-// warning("%s: calloc doesn't clear", __FUNCTION__); //fixme: was error
-
- return p;
-}
-
-void gp_free(void *block) {
- uint32 np;
- uint32 *up;
-
- if (!block) {
- return;
- }
-
- np = ((uint32) block) - sizeof(uint32);
- up = (uint32 *) np;
- if (*up == 0x4321) {
- warning("%s: double deallocation", __FUNCTION__);
- return;
- }
-
- if (*up != 0x1234) {
- warning("%s: corrupt block", __FUNCTION__);
- return;
- }
- *up = 0x4321;
-
- gm_free(up);
-}
-
-//////////////////////////////////////////////////
-// GP32 stuff
-//////////////////////////////////////////////////
-static char usedMemStr[16];
-int gUsedMem = 1024 * 1024;
-
-//#define CLEAN_MEMORY_WITH_0xE7
-#define CHECK_USED_MEMORY
-#define CHECK_NEW_TIME
-
-void *operator new(size_t size) {
-#if defined(CHECK_NEW_TIME)
- static int ftick;
- ftick = GpTickCountGet();
-#endif
-// printf("BP:operator new(%d)", size);
- void *ptr = gp_malloc(size);
-
-#if defined(CLEAN_MEMORY_WITH_0xE7)
- if(ptr != NULL) {
- gp_memset(ptr, 0xE7, size);
- }
-#endif
-#if defined(CHECK_USED_MEMORY)
- // Check free memory.
- gUsedMem = ((int)(ptr) + size) - 0xc000000;
-
- sprintf(usedMemStr, "%8d", gUsedMem);
- gp_fillRect(frameBuffer1, 0, 0, 64, 12, 0);
- gp_textOut(frameBuffer1, 0, 0, usedMemStr, 0xfffff);
-#endif
-#if defined(CHECK_NEW_TIME)
- sprintf(usedMemStr, "%2d", GpTickCountGet() - ftick);
- gp_fillRect(frameBuffer1, 72, 0, 24, 12, 0);
- gp_textOut(frameBuffer1, 72, 0, usedMemStr, 0xfffff);
-#endif
- return ptr;
-}
-
-void operator delete(void *ptr) {
-// printf("operator delete(%x)", ptr);
- gp_free(ptr);
-}
-
////////////////////
//String functions
char *gp_strcpy(char *dst, const char *src) {
Modified: scummvm/branches/branch-0-9-0/backends/gp32/gp32std.h
===================================================================
--- scummvm/branches/branch-0-9-0/backends/gp32/gp32std.h 2006-06-29 05:34:56 UTC (rev 23340)
+++ scummvm/branches/branch-0-9-0/backends/gp32/gp32std.h 2006-06-29 08:22:45 UTC (rev 23341)
@@ -39,33 +39,6 @@
#define LCD_WIDTH 320
#define LCD_HEIGHT 240
-#define FCACHE_SIZE 8 * 1024
-
-typedef struct {
- F_HANDLE handle;
- unsigned long size;
- unsigned long cachePos; //cache position
- unsigned char cacheData[FCACHE_SIZE];
-} GPFILE;
-
-extern GPFILE *gp_stderr;
-extern GPFILE *gp_stdout;
-extern GPFILE *gp_stdin;
-
-extern GPFILE * gp_fopen(const char *filename, const char *mode);
-extern int gp_fclose(GPFILE *stream);
-extern int gp_fseek(GPFILE *stream, long offset, int whence);
-extern size_t gp_fread(void *ptr, size_t size, size_t n, GPFILE *stream);
-extern size_t gp_fwrite(const void *ptr, size_t size, size_t n, GPFILE *stream);
-extern long gp_ftell(GPFILE *stream);
-extern void gp_clearerr(GPFILE *stream);
-extern int gp_feof(GPFILE *stream);
-extern char gp_fgetc(GPFILE *stream);
-extern char * gp_fgets(char *s, int n, GPFILE *stream);
-extern int gp_fflush(GPFILE *stream);
-extern int gp_ferror(GPFILE *stream);
-extern int gp_fprintf(GPFILE *stream, const char *fmt, ...);
-
extern char * gp_strcpy(char *dst, const char *src);
extern char * gp_strncpy(char *dst, const char *src, size_t count);
extern char * gp_strcat(char *dst, const char *src);
@@ -74,12 +47,6 @@
extern int gp_strncasecmp(const char *dst, const char *src, size_t count);
extern void gp_sprintf(char *str, const char *fmt, ...);
-extern void * gp_memcpy(void *dst, const void *src, size_t count);
-extern void * gp_memset(void *dst, int val, size_t count);
-extern void * gp_malloc(size_t size);
-extern void * gp_calloc(size_t nitems, size_t size);
-extern void gp_free(void *block);
-
extern void gp_setCpuSpeed(int freq);
extern int gp_printf(const char *fmt, ...);
extern void gp_delay(unsigned long msecs);
Added: scummvm/branches/branch-0-9-0/backends/gp32/gp32std_file.cpp
===================================================================
--- scummvm/branches/branch-0-9-0/backends/gp32/gp32std_file.cpp (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/gp32/gp32std_file.cpp 2006-06-29 08:22:45 UTC (rev 23341)
@@ -0,0 +1,256 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002 Ph0x - GP32 Backend
+ * Copyright (C) 2003/2004 DJWillis - GP32 Backend
+ * Copyright (C) 2005 Won Star - GP32 Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+
+#include "stdafx.h"
+#include "common/scummsys.h"
+//#include "graphics/scaler.h"
+#include "common/system.h"
+#include "backends/intern.h"
+
+#include "gp32std.h"
+#include "gp32std_file.h"
+
+FILE *gp_stderr = NULL;
+FILE *gp_stdout = NULL;
+FILE *gp_stdin = NULL;
+
+// Cache Idea / Code borrowed from the ps2 port
+//#define USE_CACHE
+
+//////////////////
+//File functions
+
+GPFILE *gp_fopen(const char *fileName, const char *openMode) {
+ //FIXME: allocation, mode
+ uint32 mode;
+ GPFILE *file;
+ ERR_CODE err;
+ char tempPath[256];
+
+ if (!strchr(fileName, '.')) {
+ sprintf(tempPath, "%s.", fileName);
+ fileName = tempPath;
+ }
+
+ file = new GPFILE;
+
+// NP("%s(\"%s\", \"%s\")", __FUNCTION__, fileName, openMode);
+
+ // FIXME add binary/text support
+ if (tolower(openMode[0]) == 'r') {
+ mode = OPEN_R;
+ GpFileGetSize(fileName, &file->fileSize);
+ err = GpFileOpen(fileName, mode, &file->handle);
+ } else if (tolower(openMode[0]) == 'w') {
+ file->fileSize = 0;
+ mode = OPEN_W;
+ err = GpFileCreate(fileName, ALWAYS_CREATE, &file->handle);
+ } else if (tolower(openMode[0]) == 'a') {
+ warning("We do not support 'a' file open mode.");
+ delete file;
+ return NULL;
+ } else {
+ error("wrong file mode");
+ }
+
+ if (!file) {
+ error("%s: cannot create FILE structure", __FUNCTION__);
+ }
+
+ if (err) {
+ printf("gp_gopen(): IO error %d", err);
+ delete file;
+ return NULL;
+ }
+
+ file->mode = mode;
+ file->cachePos = 0;
+ file->bytesInCache = 0;
+
+ return file;
+}
+
+int gp_fclose(GPFILE *stream) {
+ if (!stream) {
+ //warning("closing null file");
+ return 1;
+ }
+
+/* if (*(uint32 *)((char *)stream - sizeof(uint32)) == 0x4321) {
+ debug(0, "Double closing", __FUNCTION__);
+ return 1;
+ }
+*/
+
+#ifdef USE_CACHE
+ if (stream->cachePos && stream->mode == OPEN_W) {
+ GpFileWrite(stream->handle, (char *)stream->cacheData, stream->cachePos); // flush cache
+ stream->cachePos = 0;
+ }
+#endif
+
+ ERR_CODE err = GpFileClose(stream->handle);
+ delete stream;
+
+ return err;
+}
+
+int gp_fseek(GPFILE *stream, long offset, int whence) {
+ switch (whence) {
+ case SEEK_SET:
+ whence = FROM_BEGIN;
+ break;
+ case SEEK_CUR:
+ whence = FROM_CURRENT;
+ break;
+ case SEEK_END:
+ whence = FROM_END;
+ break;
+ }
+ return GpFileSeek(stream->handle, whence, offset, (long *)&stream->filePos); //FIXME?
+}
+
+size_t gp_fread(void *ptr, size_t size, size_t n, GPFILE *stream) {
+ ulong readcount = 0;
+ int len = size * n;
+
+#ifdef USE_CACHE
+ uint8 *dest = (uint8 *)ptr;
+
+ while (len && (stream->filePos != stream->fileSize)) {
+ if (stream->cachePos <= filePos && filePos < stream->cachePos + stream->bytesInCache) {
+ uint32 startPos = (stream->cacheBufOffs + (stream->filePos - stream->cachePos)) % FCACHE_SIZE;
+ uint32 copyLen = stream->bytesInCache - (stream->filePos - stream->cachePos);
+ if (copyLen > len)
+ copyLen = len;
+ if (startPos + copyLen > FCACHE_SIZE)
+ copyLen = FCACHE_SIZE - startPos;
+
+ memcpy(dest, cacheData + startPos, copyLen);
+
+ filePos += copyLen;
+ dest += copyLen;
+ len -= copyLen;
+ } else {
+#endif
+ ERR_CODE err = GpFileRead(stream->handle, ptr, len, &readcount);
+
+#ifdef USE_CACHE
+ stream->filePos += len;
+ }
+ }
+#endif
+
+ return readcount / size; //FIXME?
+}
+
+size_t gp_fwrite(const void *ptr, size_t size, size_t n, GPFILE *stream) {
+ int len = size * n;
+
+ if (!stream) {
+ //warning("writing to null file");
+ return 0;
+ }
+
+#ifdef USE_CACHE
+ if (stream->cachePos + len < FCACHE_SIZE) {
+ memcpy(stream->cacheData + stream->cachePos, ptr, len);
+ stream->cachePos += len;
+ } else {
+ if (stream->cachePos) {
+ GpFileWrite(stream->handle, stream->cacheData, stream->cachePos); // flush cache
+ stream->cachePos = 0;
+ }
+
+#endif
+ ERR_CODE err = GpFileWrite(stream->handle, ptr, len);
+ if (!err)
+ return n;
+ else
+ return -err;
+#ifdef USE_CACHE
+ }
+#endif
+ return 0;
+}
+
+//FIXME? use standard func
+long gp_ftell(GPFILE *stream) {
+ ulong pos = 0;
+ ERR_CODE err = GpFileSeek(stream->handle, FROM_CURRENT, 0, (long*)&pos);
+ return pos;
+}
+
+void gp_clearerr(GPFILE *stream)
+{
+}
+
+int gp_feof(GPFILE *stream) {
+ return gp_ftell(stream) >= stream->fileSize;
+}
+
+char gp_fgetc(GPFILE *stream) {
+ char c[1];
+
+ gp_fread(&c[0], 1, 1, stream);
+ return c[0];
+}
+
+char *gp_fgets(char *s, int n, GPFILE *stream) {
+ int i = 0;
+
+ while (!gp_feof(stream) && i < n) {
+ gp_fread(&s[i], 1, 1, stream);
+ if (s[i] == '\n') {
+ s[i + 1] = 0;
+ return s;
+ }
+ i++;
+ }
+ if (gp_feof(stream))
+ return NULL;
+ else
+ return s;
+}
+
+int gp_fprintf(GPFILE *stream, const char *fmt, ...) {
+ char s[256];
+ va_list marker;
+
+ va_start(marker, fmt);
+ vsnprintf(s, 256, fmt, marker);
+ va_end(marker);
+
+ return gp_fwrite(s, 1, strlen(s), stream);
+}
+
+int gp_fflush(GPFILE *stream) {
+ return 0;
+}
+
+int gp_ferror(GPFILE *stream) {
+ return 0;
+}
Property changes on: scummvm/branches/branch-0-9-0/backends/gp32/gp32std_file.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:eol-style
+ native
Added: scummvm/branches/branch-0-9-0/backends/gp32/gp32std_file.h
===================================================================
--- scummvm/branches/branch-0-9-0/backends/gp32/gp32std_file.h (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/gp32/gp32std_file.h 2006-06-29 08:22:45 UTC (rev 23341)
@@ -0,0 +1,60 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002 Ph0x - GP32 Backend
+ * Copyright (C) 2003/2004 DJWillis - GP32 Backend
+ * Copyright (C) 2005 Won Star - GP32 Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef __GP32STD_FILE_H
+#define __GP32STD_FILE_H
+
+#define FCACHE_SIZE 8 * 1024
+
+typedef struct {
+ F_HANDLE handle;
+ unsigned long mode;
+ unsigned long fileSize;
+ unsigned long filePos;
+ unsigned long cachePos;
+ unsigned long cacheBufOffs;
+ unsigned long bytesInCache;
+ unsigned char cacheData[FCACHE_SIZE];
+} GPFILE;
+
+extern GPFILE *gp_stderr;
+extern GPFILE *gp_stdout;
+extern GPFILE *gp_stdin;
+
+extern GPFILE * gp_fopen(const char *filename, const char *mode);
+extern int gp_fclose(GPFILE *stream);
+extern int gp_fseek(GPFILE *stream, long offset, int whence);
+extern size_t gp_fread(void *ptr, size_t size, size_t n, GPFILE *stream);
+extern size_t gp_fwrite(const void *ptr, size_t size, size_t n, GPFILE *stream);
+extern long gp_ftell(GPFILE *stream);
+extern void gp_clearerr(GPFILE *stream);
+extern int gp_feof(GPFILE *stream);
+extern char gp_fgetc(GPFILE *stream);
+extern char * gp_fgets(char *s, int n, GPFILE *stream);
+extern int gp_fflush(GPFILE *stream);
+extern int gp_ferror(GPFILE *stream);
+extern int gp_fprintf(GPFILE *stream, const char *fmt, ...);
+
+#endif
Property changes on: scummvm/branches/branch-0-9-0/backends/gp32/gp32std_file.h
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:eol-style
+ native
Added: scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.cpp
===================================================================
--- scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.cpp (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.cpp 2006-06-29 08:22:45 UTC (rev 23341)
@@ -0,0 +1,310 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002 Ph0x - GP32 Backend
+ * Copyright (C) 2003/2004 DJWillis - GP32 Backend
+ * Copyright (C) 2005/2006 Won Star - GP32 Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "stdafx.h"
+#include "common/scummsys.h"
+//#include "graphics/scaler.h"
+#include "common/system.h"
+#include "backends/intern.h"
+
+#include "base/engine.h"
+
+#include "backends/gp32/gp32std.h"
+#include "backends/gp32/gp32std_grap.h"
+#include "backends/gp32/gp32std_memory.h"
+
+/////////////////////
+//Memory management
+
+#define USER_MEMORY_SIZE (256 * 1024)
+#define USER_BLOCK_SIZE 24
+#define NUM_BLOCK (USER_MEMORY_SIZE / USER_BLOCK_SIZE)
+// use fixed block size for small allocations
+// consumes about 128k for block array
+// consumes 256k for user memory
+
+class MemBlock {
+protected:
+ static byte *userMem;
+// static size_t allocSize;
+// static MemBlock *head;
+ static int numBlock;
+ static int prevBlock;
+
+ // Linked list is slow for this task. :)
+ static MemBlock block[NUM_BLOCK];
+
+ byte *block;
+ size_t size;
+
+// MemBlock *next;
+
+ int used;
+
+public:
+ static void init();
+ static void deinit();
+
+ static void *addBlock(size_t size);
+ static void deleteBlock(void *block);
+};
+
+byte *MemBlock::userMem = NULL;
+//MemBlock *MemBlock::head = NULL;
+//size_t MemBlock::allocSize = 0;
+int MemBlock::numBlock = 0;
+int MemBlock::prevBlock = 0;
+MemBlock MemBlock::block[NUM_BLOCK];
+
+void MemBlock::init()
+{
+ userMem = (byte *)gm_malloc(USER_MEMORY_SIZE + USER_BLOCK_SIZE);
+ if (!userMem) {
+ //error
+ }
+}
+
+void MemBlock::deinit()
+{
+ if (!userMem) {
+ //error
+ }
+ gm_free(userMem);
+ userMem = NULL;
+}
+
+void *MemBlock::addBlock(size_t size)
+{
+ int i;
+ MemBlock *blk = &block[prevBlock];
+
+ // some optimizaion with loop
+ for (i = prevBlock; i < NUM_BLOCK; i++) {
+ if (!blk->used) {
+ break;
+ }
+ blk++;
+ }
+ if(i == NUM_BLOCK) {
+ blk = &block[0];
+ for (i = 0; i < prevBlock; i++) {
+ if (!blk->used) {
+ break;
+ }
+ blk++;
+ }
+ if(i == prevBlock)
+ return NULL;
+ }
+
+ byte *ptr = userMem + (i * USER_BLOCK_SIZE);
+
+ blk->size = size;
+ blk->block = ptr;
+ blk->used = 1;
+
+ prevBlock = i;
+
+ return (void *) ptr;
+}
+
+void MemBlock::deleteBlock(void *block)
+{
+ uint32 np = (uint32) block - (uint32) userMem;
+
+ if ((np / USER_BLOCK_SIZE) * USER_BLOCK_SIZE != np) {
+ gm_free(block);
+// warning("wrong block! (%d / %d)", (np / USER_BLOCK_SIZE) * USER_BLOCK_SIZE, np);
+ }
+ int i = np / USER_BLOCK_SIZE;
+ if (i > NUM_BLOCK) {
+ gm_free(block);
+ return;
+ }
+ block[i].used = 0;
+
+/*
+ int i = 0;
+ for (i = 0; i < NUM_BLOCK; i++) {
+ if (block[i].block == block)
+ break;
+ }
+ if (i == NUM_BLOCK) {
+ gm_free(block); //fixme?
+ //warning("wrong block! %x", (uint32)block - (uint32)userMem);
+ } else {
+ GPDEBUG("deleteing block %d", i);
+ block[i].used = 0;
+ }*/
+}
+
+// HACK not to include struct MemBlock
+void memBlockInit()
+{
+ MemBlock::init();
+}
+
+void memBlockDeinit()
+{
+ MemBlock::deinit();
+}
+
+#undef memcpy
+#undef memset
+void *gp_memcpy(void *dst, const void *src, size_t count) {
+ return memcpy(dst, src, count);
+}
+
+void *gp_memset(void *dst, int val, size_t count) {
+ return memset(dst, val, count);
+}
+
+#define MALLOC_MASK 0xAB800000
+
+void *gp_malloc(size_t size) {
+ uint32 np;
+ uint32 *up;
+
+ // size + 8 bytes : stores block size
+ int allocSize = size + sizeof(uint32) + sizeof(uint32);
+ if (allocSize <= USER_BLOCK_SIZE) {
+ np = (uint32) MemBlock::addBlock(allocSize);
+ if (!np) {
+// GPDEBUG("falling back to gm_malloc");
+ np = (uint32) gm_malloc(allocSize);
+ }
+ } else {
+ np = (uint32) gm_malloc(allocSize);
+ }
+
+ if (np) {
+ up = (uint32 *)np;
+ *up = size | MALLOC_MASK; // mem size: up to 8mb
+ up = (uint32 *)(np + size + sizeof(uint32));
+ *up = 0x1234; // catches oob acess
+ return (void *)(np + sizeof(uint32));
+ }
+
+ return NULL;
+}
+
+void gp_free(void *block) {
+ uint32 np;
+ uint32 *up;
+
+ if (!block) {
+ return;
+ }
+
+ np = ((uint32) block) - sizeof(uint32);
+ up = (uint32 *) np;
+ if (*up == 0x43210900) {
+ warning("%s: double deallocation", __FUNCTION__);
+ return;
+ }
+
+ if (*up & MALLOC_MASK != MALLOC_MASK) {
+ warning("%s: corrupt block", __FUNCTION__);
+ return;
+ }
+
+ int blockSize = (*up & 0x7fffff);
+ up = (uint32 *)(np + blockSize + sizeof(uint32));
+ if (*up != 0x1234) {
+ warning("gp_free: corrupt block - OOB access", __FUNCTION__);
+ return;
+ }
+
+ *up = 0x43210900;
+ np = ((uint32) block) - sizeof(uint32);
+ up = (uint32 *) np;
+
+ if (blockSize + 8 <= USER_BLOCK_SIZE) {
+ MemBlock::deleteBlock(up);
+ } else {
+ gm_free(up);
+ }
+}
+
+void *gp_calloc(size_t nitems, size_t size) {
+ void *p = gp_malloc(nitems * size); //gpcalloc doesnt clear?
+
+ gp_memset(p, 0, nitems * size);
+
+// if (*(uint8 *)p != 0)
+// warning("%s: calloc doesn't clear", __FUNCTION__); //fixme: was error
+
+ return p;
+}
+
+//////////////////////////////////////////////////
+// GP32 stuff
+//////////////////////////////////////////////////
+static char usedMemStr[16];
+int gUsedMem = 1024 * 1024;
+
+//#define CLEAN_MEMORY_WITH_0xE7
+#define CHECK_USED_MEMORY
+//#define CHECK_NEW_TIME
+//#define CHECK_NEW_SIZE
+
+void *operator new(size_t size) {
+#if defined(CHECK_NEW_TIME)
+ static int ftick;
+ ftick = GpTickCountGet();
+#endif
+// printf("BP:operator new(%d)", size);
+ void *ptr = gp_malloc(size);
+
+#if defined(CLEAN_MEMORY_WITH_0xE7)
+ if(ptr != NULL) {
+ gp_memset(ptr, 0xE7, size);
+ }
+#endif
+#if defined(CHECK_USED_MEMORY)
+ // Check free memory.
+ gUsedMem = ((int)(ptr) + size) - 0xc000000;
+
+ sprintf(usedMemStr, "%8d", gUsedMem);
+ gp_fillRect(frameBuffer1, 0, 0, 64, 12, 0);
+ gp_textOut(frameBuffer1, 0, 0, usedMemStr, 0xfffff);
+#endif
+#if defined(CHECK_NEW_TIME)
+ sprintf(usedMemStr, "%2d", GpTickCountGet() - ftick);
+ gp_fillRect(frameBuffer1, 72, 0, 24, 12, 0);
+ gp_textOut(frameBuffer1, 72, 0, usedMemStr, 0xfffff);
+#endif
+#if defined(CHECK_NEW_SIZE)
+ sprintf(usedMemStr, "%8d", size);
+ gp_fillRect(frameBuffer1, 108, 0, 64, 12, 0);
+ gp_textOut(frameBuffer1, 108, 0, usedMemStr, 0xfffff);
+#endif
+ return ptr;
+}
+
+void operator delete(void *ptr) {
+// printf("operator delete(%x)", ptr);
+ gp_free(ptr);
+}
Property changes on: scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:eol-style
+ native
Added: scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.h
===================================================================
--- scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.h (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.h 2006-06-29 08:22:45 UTC (rev 23341)
@@ -0,0 +1,35 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002 Ph0x - GP32 Backend
+ * Copyright (C) 2003/2004 DJWillis - GP32 Backend
+ * Copyright (C) 2005 Won Star - GP32 Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef __GP32STD_MEMORY_H
+#define __GP32STD_MEMORY_H
+
+extern void * gp_memcpy(void *dst, const void *src, size_t count);
+extern void * gp_memset(void *dst, int val, size_t count);
+extern void * gp_malloc(size_t size);
+extern void * gp_calloc(size_t nitems, size_t size);
+extern void gp_free(void *block);
+
+#endif
Property changes on: scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.h
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:eol-style
+ native
Modified: scummvm/branches/branch-0-9-0/backends/gp32/gp32std_sound.cpp
===================================================================
--- scummvm/branches/branch-0-9-0/backends/gp32/gp32std_sound.cpp 2006-06-29 05:34:56 UTC (rev 23340)
+++ scummvm/branches/branch-0-9-0/backends/gp32/gp32std_sound.cpp 2006-06-29 08:22:45 UTC (rev 23341)
@@ -43,6 +43,14 @@
// polls the current playing position within the buffer.
static void soundTimer() {
+ static int locked = false;
+
+ if (locked) {
+ return;
+ }
+
+ locked = true;
+
unsigned int sampleshiftVal = soundBuf.samples << shiftVal;
unsigned int t = (((unsigned int)(*soundPos) - (unsigned int)buffer) >> shiftVal) >= soundBuf.samples ? 1 : 0;
if (t != frame) {
@@ -90,6 +98,8 @@
} while ((uint32)d < max);
}
}
+
+ locked = false;
}
int gp_soundBufStart(GPSOUNDBUF *sb) {
Modified: scummvm/branches/branch-0-9-0/backends/gp32/portdefs.h
===================================================================
--- scummvm/branches/branch-0-9-0/backends/gp32/portdefs.h 2006-06-29 05:34:56 UTC (rev 23340)
+++ scummvm/branches/branch-0-9-0/backends/gp32/portdefs.h 2006-06-29 08:22:45 UTC (rev 23341)
@@ -35,6 +35,8 @@
#include <cctype>
#include "gp32std.h"
+#include "gp32std_file.h"
+#include "gp32std_memory.h"
#undef byte
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list