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)
+++ /dev/null
-#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;
-
#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
* 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>
#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
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;
};
#endif
-//static char ROMFilename [_MAX_PATH];
-//static char SnapshotFilename [_MAX_PATH];
+static STREAM ss_st;
static void Freeze ();
static int Unfreeze ();
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);
bool8 S9xUnfreezeGame (const char *filename)
{
- if(statef_open(filename, "rb"))
+ if(ss_st = OPEN_STREAM(filename, "rb"))
{
int result;
if ((result = Unfreeze()) != SUCCESS)
// 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 ()
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));
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);
{
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,
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)
{
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);
if (rem)
{
char *junk = (char*)malloc(rem);
- statef_read(junk, rem);
+ READ_STREAM(ss_st, rem, junk);
free(junk);
}
-
- return (SUCCESS);
+
+ return SUCCESS;
}
#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