remove statef + gz rom support
authorJavier S. Pedro <maemo@javispedro.com>
Sun, 6 Sep 2009 20:41:01 +0000 (22:41 +0200)
committerJavier S. Pedro <maemo@javispedro.com>
Sun, 6 Sep 2009 20:41:01 +0000 (22:41 +0200)
Makefile
platform/statef.c [deleted file]
port.h
snapshot.cpp
snes9x.h

index e2838c3..dd3143a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -22,12 +22,11 @@ OBJS += os9x_asm_cpu.o os9x_65c816.o spc700a.o
 OBJS += m3d_func.o misc.o
 # from open-whatever sdk
 OBJS += unzip.o ioapi.o
-# my own extensions to snes9x
+# my extensions to snes9x (speedhacks support)
 OBJS += hacks.o
 # the glue code that sticks it all together in a monstruous way
-OBJS += platform/path.o platform/statef.o platform/config.o
+OBJS += platform/path.o platform/config.o platform/hgw.o
 OBJS += platform/sdl.o platform/sdlv.o platform/sdla.o platform/sdli.o
-OBJS += platform/hgw.o
 
 # automatic dependencies
 DEPS := $(OBJS:.o=.d)
diff --git a/platform/statef.c b/platform/statef.c
deleted file mode 100644 (file)
index 7994755..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <zlib.h>
-
-#include "port.h"
-
-static gzFile gfd;
-
-static int zlib_open(const char *fname, const char *mode)
-{
-       gfd = gzopen(fname, mode);
-       if (!gfd) return 0;
-
-       return 1;
-}
-
-static int zlib_read(void *p, int l)
-{
-       return gzread(gfd, p, l);
-}
-
-static int zlib_write(void *p, int l)
-{
-       return gzwrite(gfd, p, l);
-}
-
-static void zlib_close()
-{
-       gzclose(gfd);
-}
-
-int  (*statef_open)(const char *fname, const char *mode) = zlib_open;
-int  (*statef_read)(void *p, int l) = zlib_read;
-int  (*statef_write)(void *p, int l) = zlib_write;
-void (*statef_close)() = zlib_close;
-
diff --git a/port.h b/port.h
index c5b1e2c..80101f5 100644 (file)
--- a/port.h
+++ b/port.h
@@ -108,34 +108,60 @@ typedef int16_t                   int16_32;
 #define SUPER_FX               1
 #define CPU_SHUTDOWN   1
 //#define NETPLAY_SUPPORT      1
+#define ZLIB                   1
+#define UNZIP_SUPPORT  1
 
 //Misc Items
 #define VAR_CYCLES
 //#define SPC700_SHUTDOWN
 #define LSB_FIRST
-#define STATIC static
-#define FASTCALL
 #define PIXEL_FORMAT RGB565
 #define CHECK_SOUND()
-#define UNZIP_SUPPORT
 #define ZeroMemory(a,b) memset((a),0,(b))
 #define PACKING __attribute__ ((packed))
 #define ALIGN_BY_ONE  __attribute__ ((aligned (1), packed))
 #define LSB_FIRST
 #undef  FAST_LSB_WORD_ACCESS
 
-#ifndef INLINE
+// Language abstractions
+#define FASTCALL
+#define STATIC static
 #define INLINE inline
-#endif
 
 START_EXTERN_C
 // Path functions
 void PathMake(char *path, const char *drive, const char *dir,
        const char *fname, const char *ext);
 void PathSplit(const char *path, char *drive, char *dir, char *fname, char *ext);
-/** A simplified basename function returning a pointer inside the same string */
+/** A simplified basename function returning a pointer inside the src string */
 const char * PathBasename(const char * path);
 END_EXTERN_C
 
+// Stream functions, used when opening ROMs and snapshots.
+#ifdef ZLIB
+#include <zlib.h>
+#define STREAM gzFile
+#define READ_STREAM(p,l,s) gzread (s,p,l)
+#define WRITE_STREAM(p,l,s) gzwrite (s,p,l)
+#define GETS_STREAM(p,l,s) gzgets(s,p,l)
+#define GETC_STREAM(s) gzgetc(s)
+#define OPEN_STREAM(f,m) gzopen (f,m)
+#define REOPEN_STREAM(f,m) gzdopen (f,m)
+#define FIND_STREAM(f) gztell(f)
+#define REVERT_STREAM(f,o,s)  gzseek(f,o,s)
+#define CLOSE_STREAM(s) gzclose (s)
+#else
+#define STREAM FILE *
+#define READ_STREAM(p,l,s) fread (p,1,l,s)
+#define WRITE_STREAM(p,l,s) fwrite (p,1,l,s)
+#define GETS_STREAM(p,l,s) fgets(p,l,s)
+#define GETC_STREAM(s) fgetc(s)
+#define OPEN_STREAM(f,m) fopen (f,m)
+#define REOPEN_STREAM(f,m) fdopen (f,m)
+#define FIND_STREAM(f) ftell(f)
+#define REVERT_STREAM(f,o,s)    fseek(f,o,s)
+#define CLOSE_STREAM(s) fclose (s)
+#endif
+
 #endif
 
index 14229bd..f2bb795 100644 (file)
  * Nintendo Co., Limited and its subsidiary companies.
  */
 
-#ifndef __GP32__ 
 #include <string.h>
 #include <ctype.h>
 #include <stdlib.h>
-#endif
+
 #if defined(__unix) || defined(__linux) || defined(__sun) || defined(__DJGPP)
 #include <unistd.h>
 #include <sys/types.h>
@@ -51,7 +50,6 @@
 #endif
 
 #include "snapshot.h"
-//#include "snaporig.h"
 #include "memmap.h"
 #include "snes9x.h"
 #include "65c816.h"
 #include "srtc.h"
 #include "sdd1.h"
 
-
-// notaz: file i/o function pointers for states,
-// changing funcs will allow to enable/disable gzipped saves
-extern int  (*statef_open)(const char *fname, const char *mode);
-extern int  (*statef_read)(void *p, int l);
-extern int  (*statef_write)(void *p, int l);
-extern void (*statef_close)();
-
 extern uint8 *SRAM;
 
 #ifdef ZSNES_FX
@@ -81,11 +71,10 @@ START_EXTERN_C
 void S9xSuperFXPreSaveState ();
 void S9xSuperFXPostSaveState ();
 void S9xSuperFXPostLoadState ();
+//bool8 S9xUnfreezeZSNES (const char *filename);
 END_EXTERN_C
 #endif
 
-//bool8 S9xUnfreezeZSNES (const char *filename);
-
 typedef struct {
     int offset;
     int size;
@@ -404,8 +393,7 @@ static FreezeData SnapSA1 [] = {
 };
 #endif
 
-//static char ROMFilename [_MAX_PATH];
-//static char SnapshotFilename [_MAX_PATH];
+static STREAM ss_st;
 
 static void Freeze ();
 static int Unfreeze ();
@@ -419,10 +407,10 @@ static int UnfreezeBlock (const char *name, uint8 *block, int size);
 
 bool8 S9xFreezeGame (const char *filename)
 {
-    if(statef_open(filename, "wb"))
+    if(ss_st = OPEN_STREAM(filename, "wb"))
     {
                Freeze();
-               statef_close();
+               CLOSE_STREAM(ss_st);
                return (TRUE);
     }
     return (FALSE);
@@ -431,7 +419,7 @@ bool8 S9xFreezeGame (const char *filename)
 
 bool8 S9xUnfreezeGame (const char *filename)
 {
-    if(statef_open(filename, "rb"))
+    if(ss_st = OPEN_STREAM(filename, "rb"))
     {
                int result;
                if ((result = Unfreeze()) != SUCCESS)
@@ -452,15 +440,15 @@ bool8 S9xUnfreezeGame (const char *filename)
                        // should never happen
                        break;
                        }
-                       statef_close();
-                       return (FALSE);
+                       CLOSE_STREAM(ss_st);
+                       return FALSE;
                }
-               statef_close();
-               return (TRUE);
+               CLOSE_STREAM(ss_st);
+               return TRUE;
     }
 
     
-    return (FALSE);
+    return FALSE;
 }
 
 static void Freeze ()
@@ -482,10 +470,10 @@ static void Freeze ()
        SoundData.channels [i].previous16 [1] = (int16) SoundData.channels [i].previous [1];
     }
     sprintf (buffer, "%s:%04d\n", SNAPSHOT_MAGIC, SNAPSHOT_VERSION);
-    statef_write(buffer, strlen (buffer));
+    WRITE_STREAM(ss_st, strlen (buffer), buffer);
     sprintf (buffer, "NAM:%06d:%s%c", strlen (Memory.ROMFilename) + 1,
             Memory.ROMFilename, 0);
-    statef_write(buffer, strlen (buffer) + 1);
+    WRITE_STREAM(ss_st, strlen (buffer) + 1, buffer);
     FreezeStruct ("CPU", &CPU, SnapCPU, COUNT (SnapCPU));
     FreezeStruct ("REG", &Registers, SnapRegisters, COUNT (SnapRegisters));
     FreezeStruct ("PPU", &PPU, SnapPPU, COUNT (SnapPPU));
@@ -540,7 +528,7 @@ static int Unfreeze()
 
     int version;
     unsigned int len = strlen (SNAPSHOT_MAGIC) + 1 + 4 + 1;
-    if (statef_read(buffer, len) != (int)len)
+    if (READ_STREAM(ss_st, len, buffer) != (int)len)
     {
                printf("failed to read header\r\n");
                return (WRONG_FORMAT);
@@ -796,8 +784,8 @@ void FreezeBlock (const char *name, uint8 *block, int size)
 {
     char buffer [512];
     sprintf (buffer, "%s:%06d:", name, size);
-    statef_write(buffer, strlen (buffer));
-    statef_write(block, size);
+    WRITE_STREAM(ss_st, strlen (buffer), buffer);
+    WRITE_STREAM(ss_st, size, block);
 }
 
 int UnfreezeStruct (const char *name, void *base, FreezeData *fields,
@@ -901,7 +889,7 @@ int UnfreezeBlock(const char *name, uint8 *block, int size)
     int len = 0;
     int rem = 0;
     printf("UnfreezeBlock: %s\r\n",name);
-    if (statef_read(buffer, 11) != 11 ||
+    if (READ_STREAM(ss_st, 11, buffer) != 11 ||
        strncmp (buffer, name, 3) != 0 || buffer [3] != ':' ||
        (len = atoi (&buffer [4])) == 0)
     {
@@ -914,8 +902,8 @@ int UnfreezeBlock(const char *name, uint8 *block, int size)
                rem = len - size;
                len = size;
     }
-    
-    if (statef_read(block, len) != len)
+
+    if (READ_STREAM(ss_st, len, block) != len)
     {
                printf("UnfreezeBlock err2\n");
                return (WRONG_FORMAT);
@@ -924,11 +912,11 @@ int UnfreezeBlock(const char *name, uint8 *block, int size)
     if (rem)
     {
                char *junk = (char*)malloc(rem);
-               statef_read(junk, rem);
+               READ_STREAM(ss_st, rem, junk);
                free(junk);
     }
-       
-    return (SUCCESS);
+
+    return SUCCESS;
 }
 
 
index 3e4482e..6b9dd04 100644 (file)
--- a/snes9x.h
+++ b/snes9x.h
 
 #define ROM_NAME_LEN 23
 
-#define STREAM FILE *
-#define READ_STREAM(p,l,s) fread (p,1,l,s)
-#define WRITE_STREAM(p,l,s) fwrite (p,1,l,s)
-#define OPEN_STREAM(f,m) fopen (f,m)
-#define CLOSE_STREAM(s) fclose (s)
-#define SEEK_STREAM(p,r,s) fseek(s,p,r)
-#define FROM_CURRENT SEEK_CUR
-
 /* SNES screen width and height */
 #define SNES_WIDTH             256
 #define SNES_HEIGHT            224