cleanup - remove useless files

This commit is contained in:
dborth 2008-10-03 07:02:25 +00:00
parent cb83ca6688
commit 5f31d56b30
8 changed files with 119 additions and 279 deletions

View File

@ -1,115 +0,0 @@
/****************************************************************************
* Visual Boy Advance GX
*
* Tantric September 2008
*
* sdfileio.c
*
* Generic File I/O for VisualBoyAdvance
* Currently only supports SD/USB
****************************************************************************/
#include <gccore.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fat.h>
#include <sys/dir.h>
#define MAXDIRENTRIES 1000
char direntries[MAXDIRENTRIES][255];
/**
* SDInit
*/
void SDInit( void )
{
fatInitDefault();
}
/**
* SD Card f_open
*/
FILE* gen_fopen( const char *filename, const char *mode )
{
return fopen( filename, mode );
}
/**
* SD Card f_write
*/
int gen_fwrite( const void *buffer, int len, int block, FILE* f )
{
return fwrite(buffer, len, block, f);
}
/**
* SD Card f_read
*/
int gen_fread( void *buffer, int len, int block, FILE* f )
{
return fread(buffer, len, block, f);
}
/**
* SD Card fclose
*/
void gen_fclose( FILE* f )
{
fclose(f);
}
/**
* SD Card fseek
*
* NB: Only supports SEEK_SET
*/
int gen_fseek(FILE* f, int where, int whence)
{
fseek(f, where, whence);
return 1;
}
/**
* Simple fgetc
*/
int gen_fgetc( FILE* f )
{
return fgetc(f);
}
static struct stat _fstat;
char filename[1024];
int fcount = 0;
/**
* Get directory listing
*/
int gen_getdir( char *thisdir )
{
memset(&direntries[0],0,MAXDIRENTRIES*255);
DIR_ITER* dp = diropen( thisdir );
if ( dp )
{
while ( dirnext(dp, filename, &_fstat) == 0 )
{
// Skip any sub directories
if ( !(_fstat.st_mode & S_IFDIR) )
{
memcpy(&direntries[fcount],&filename,strlen(filename));
fcount++;
}
}
dirclose(dp);
}
else
return 0;
return fcount;
}

View File

@ -1,38 +0,0 @@
/****************************************************************************
* Visual Boy Advance GX
*
* Tantric September 2008
*
* sdfileio.h
*
* Generic File I/O for VisualBoyAdvance
* Currently only supports SD/USB
****************************************************************************/
#ifndef __SDFILEIO__
#define __SDFILEIO__
#define MAXDIRENTRIES 1000
#include <fat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/dir.h>
extern "C"
{
/* Required Functions */
FILE* gen_fopen( const char *filename, const char *mode );
int gen_fwrite( const void *buffer, int len, int block, FILE* f );
int gen_fread( void *buffer, int len, int block, FILE* f );
void gen_fclose( FILE* f );
int gen_fseek(FILE* f, int where, int whence);
int gen_fgetc( FILE* f );
int SDInit( void );
int gen_getdir( char *thisdir );
extern char direntries[MAXDIRENTRIES][255];
}
#endif

View File

@ -9,7 +9,6 @@
***************************************************************************/ ***************************************************************************/
#ifdef HW_RVL #ifdef HW_RVL
#include "sdfileio.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -191,7 +190,6 @@ u8 VMRead8( u32 address )
} }
#else #else
#include "sdfileio.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -356,7 +354,7 @@ static void VMClose( void )
free(gbabase); free(gbabase);
if ( romfile != NULL ) if ( romfile != NULL )
gen_fclose(romfile); fclose(romfile);
rombase = gbabase = NULL; rombase = gbabase = NULL;
romfile = NULL; romfile = NULL;
@ -419,7 +417,7 @@ int VMCPULoadROM(int method)
// printf("ROM Size %d\n", romfile->fsize); // printf("ROM Size %d\n", romfile->fsize);
/* Always use VM, regardless of ROM size */ /* Always use VM, regardless of ROM size */
res = gen_fread(rom, 1, (1 << VMSHIFTBITS), romfile); res = fread(rom, 1, (1 << VMSHIFTBITS), romfile);
if ( res != (1 << VMSHIFTBITS ) ) if ( res != (1 << VMSHIFTBITS ) )
{ {
sprintf(msg, "Error reading file! %i \n",res); sprintf(msg, "Error reading file! %i \n",res);
@ -456,7 +454,7 @@ static void VMNewPage( int pageid )
mftb(&start); mftb(&start);
res = gen_fseek( romfile, pageid << VMSHIFTBITS, SEEK_SET ); res = fseek( romfile, pageid << VMSHIFTBITS, SEEK_SET );
if ( ! res ) if ( ! res )
{ {
sprintf(msg, "Seek error! - Offset %08x %d\n", pageid << VMSHIFTBITS, res); sprintf(msg, "Seek error! - Offset %08x %d\n", pageid << VMSHIFTBITS, res);
@ -467,7 +465,7 @@ static void VMNewPage( int pageid )
VMAllocate( pageid ); VMAllocate( pageid );
res = gen_fread( vmpage[pageid].pageptr, 1, 1 << VMSHIFTBITS, romfile ); res = fread( vmpage[pageid].pageptr, 1, 1 << VMSHIFTBITS, romfile );
if ( res != ( 1 << VMSHIFTBITS ) ) if ( res != ( 1 << VMSHIFTBITS ) )
{ {
sprintf(msg, "Error reading! %d bytes only\n", res); sprintf(msg, "Error reading! %d bytes only\n", res);

View File

@ -16,7 +16,6 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sdfileio.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -76,7 +75,7 @@ bool utilWritePNGFile(const char *fileName, int w, int h, u8 *pix)
NULL, NULL,
NULL); NULL);
if(!png_ptr) { if(!png_ptr) {
gen_fclose(fp); fclose(fp);
return false; return false;
} }
@ -84,13 +83,13 @@ bool utilWritePNGFile(const char *fileName, int w, int h, u8 *pix)
if(!info_ptr) { if(!info_ptr) {
png_destroy_write_struct(&png_ptr,NULL); png_destroy_write_struct(&png_ptr,NULL);
gen_fclose(fp); fclose(fp);
return false; return false;
} }
if(setjmp(png_ptr->jmpbuf)) { if(setjmp(png_ptr->jmpbuf)) {
png_destroy_write_struct(&png_ptr,NULL); png_destroy_write_struct(&png_ptr,NULL);
gen_fclose(fp); fclose(fp);
return false; return false;
} }
@ -183,7 +182,7 @@ bool utilWritePNGFile(const char *fileName, int w, int h, u8 *pix)
png_destroy_write_struct(&png_ptr, &info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr);
gen_fclose(fp); fclose(fp);
return true; return true;
#else #else
@ -209,7 +208,7 @@ bool utilWriteBMPFile(const char *fileName, int w, int h, u8 *pix)
{ {
u8 writeBuffer[512 * 3]; u8 writeBuffer[512 * 3];
FILE *fp = gen_fopen(fileName,"wb"); FILE *fp = fopen(fileName,"wb");
if(!fp) { if(!fp) {
systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), fileName); systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), fileName);
@ -249,7 +248,7 @@ bool utilWriteBMPFile(const char *fileName, int w, int h, u8 *pix)
utilPutDword(bmpheader.bitsperpixel, 24); utilPutDword(bmpheader.bitsperpixel, 24);
utilPutDword(bmpheader.datasize, 3*w*h); utilPutDword(bmpheader.datasize, 3*w*h);
gen_fwrite(&bmpheader, 1, sizeof(bmpheader), fp); fwrite(&bmpheader, 1, sizeof(bmpheader), fp);
u8 *b = writeBuffer; u8 *b = writeBuffer;
@ -271,7 +270,7 @@ bool utilWriteBMPFile(const char *fileName, int w, int h, u8 *pix)
p++; // skip black pixel for filters p++; // skip black pixel for filters
p++; // skip black pixel for filters p++; // skip black pixel for filters
p -= 2*(w+2); p -= 2*(w+2);
gen_fwrite(writeBuffer, 1, 3*w, fp); fwrite(writeBuffer, 1, 3*w, fp);
b = writeBuffer; b = writeBuffer;
} }
@ -297,7 +296,7 @@ bool utilWriteBMPFile(const char *fileName, int w, int h, u8 *pix)
} }
} }
pixU8 -= 2*3*w; pixU8 -= 2*3*w;
gen_fwrite(writeBuffer, 1, 3*w, fp); fwrite(writeBuffer, 1, 3*w, fp);
b = writeBuffer; b = writeBuffer;
} }
@ -317,7 +316,7 @@ bool utilWriteBMPFile(const char *fileName, int w, int h, u8 *pix)
pixU32++; pixU32++;
pixU32 -= 2*(w+1); pixU32 -= 2*(w+1);
gen_fwrite(writeBuffer, 1, 3*w, fp); fwrite(writeBuffer, 1, 3*w, fp);
b = writeBuffer; b = writeBuffer;
} }
@ -325,7 +324,7 @@ bool utilWriteBMPFile(const char *fileName, int w, int h, u8 *pix)
break; break;
} }
gen_fclose(fp); fclose(fp);
return true; return true;
} }
@ -333,11 +332,11 @@ bool utilWriteBMPFile(const char *fileName, int w, int h, u8 *pix)
static int utilReadInt2(FILE *f) static int utilReadInt2(FILE *f)
{ {
int res = 0; int res = 0;
int c = gen_fgetc(f); int c = fgetc(f);
if(c == EOF) if(c == EOF)
return -1; return -1;
res = c; res = c;
c = gen_fgetc(f); c = fgetc(f);
if(c == EOF) if(c == EOF)
return -1; return -1;
return c + (res<<8); return c + (res<<8);
@ -346,15 +345,15 @@ static int utilReadInt2(FILE *f)
static int utilReadInt3(FILE *f) static int utilReadInt3(FILE *f)
{ {
int res = 0; int res = 0;
int c = gen_fgetc(f); int c = fgetc(f);
if(c == EOF) if(c == EOF)
return -1; return -1;
res = c; res = c;
c = gen_fgetc(f); c = fgetc(f);
if(c == EOF) if(c == EOF)
return -1; return -1;
res = c + (res<<8); res = c + (res<<8);
c = gen_fgetc(f); c = fgetc(f);
if(c == EOF) if(c == EOF)
return -1; return -1;
return c + (res<<8); return c + (res<<8);
@ -363,16 +362,16 @@ static int utilReadInt3(FILE *f)
void utilApplyIPS(const char *ips, u8 **r, int *s) void utilApplyIPS(const char *ips, u8 **r, int *s)
{ {
// from the IPS spec at http://zerosoft.zophar.net/ips.htm // from the IPS spec at http://zerosoft.zophar.net/ips.htm
FILE *f = gen_fopen(ips, "rb"); FILE *f = fopen(ips, "rb");
if(!f) if(!f)
return; return;
u8 *rom = *r; u8 *rom = *r;
int size = *s; int size = *s;
if(gen_fgetc(f) == 'P' && if(fgetc(f) == 'P' &&
gen_fgetc(f) == 'A' && fgetc(f) == 'A' &&
gen_fgetc(f) == 'T' && fgetc(f) == 'T' &&
gen_fgetc(f) == 'C' && fgetc(f) == 'C' &&
gen_fgetc(f) == 'H') { fgetc(f) == 'H') {
int b; int b;
int offset; int offset;
int len; int len;
@ -388,7 +387,7 @@ void utilApplyIPS(const char *ips, u8 **r, int *s)
// len == 0, RLE block // len == 0, RLE block
len = utilReadInt2(f); len = utilReadInt2(f);
// byte to fill // byte to fill
int c = gen_fgetc(f); int c = fgetc(f);
if(c == -1) if(c == -1)
break; break;
b = (u8)c; b = (u8)c;
@ -403,7 +402,7 @@ void utilApplyIPS(const char *ips, u8 **r, int *s)
} }
if(b == -1) { if(b == -1) {
// normal block, just read the data // normal block, just read the data
if(gen_fread(&rom[offset], 1, len, f) != (int)len) if(fread(&rom[offset], 1, len, f) != (uint)len)
break; break;
} else { } else {
// fill the region with the given byte // fill the region with the given byte
@ -414,7 +413,7 @@ void utilApplyIPS(const char *ips, u8 **r, int *s)
} }
} }
// close the file // close the file
gen_fclose(f); fclose(f);
} }
//TODO: Modify ZSNES code for this //TODO: Modify ZSNES code for this
@ -738,7 +737,7 @@ static u8 *utilLoadGzipFile(const char *file,
u8 *data, u8 *data,
int &size) int &size)
{ {
FILE* f = gen_fopen(file, "rb"); FILE* f = fopen(file, "rb");
if(f == NULL) if(f == NULL)
{ {
@ -748,9 +747,9 @@ static u8 *utilLoadGzipFile(const char *file,
return NULL; return NULL;
} }
gen_fseek(f, -4, SEEK_END); fseek(f, -4, SEEK_END);
int fileSize = gen_fgetc(f) | (gen_fgetc(f) << 8) | (gen_fgetc(f) << 16) | (gen_fgetc(f) << 24); int fileSize = fgetc(f) | (fgetc(f) << 8) | (fgetc(f) << 16) | (fgetc(f) << 24);
gen_fclose(f); fclose(f);
if(size == 0) if(size == 0)
@ -774,7 +773,7 @@ static u8 *utilLoadGzipFile(const char *file,
{ {
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"), systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
"data"); "data");
gen_fclose(f); fclose(f);
return NULL; return NULL;
} }
size = fileSize; size = fileSize;
@ -813,7 +812,7 @@ u8 *utilLoad(const char *file,
u8 *image = data; u8 *image = data;
FILE* f = gen_fopen(file, "rb"); FILE* f = fopen(file, "rb");
if(!f) if(!f)
{ {
@ -821,10 +820,10 @@ u8 *utilLoad(const char *file,
return NULL; return NULL;
} }
gen_fseek(f,0,SEEK_END); fseek(f,0,SEEK_END);
int fileSize = ftell(f); int fileSize = ftell(f);
gen_fseek(f,0,SEEK_SET); fseek(f,0,SEEK_SET);
if(size == 0) if(size == 0)
size = fileSize; size = fileSize;
@ -839,14 +838,14 @@ u8 *utilLoad(const char *file,
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"), systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
"data"); "data");
gen_fclose(f); fclose(f);
return NULL; return NULL;
} }
size = fileSize; size = fileSize;
} }
int read = fileSize <= size ? fileSize : size; int read = fileSize <= size ? fileSize : size;
int r = gen_fread(image, 1, read, f); int r = fread(image, 1, read, f);
gen_fclose(f); fclose(f);
if(r != (int)read) if(r != (int)read)
{ {

View File

@ -16,7 +16,6 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sdfileio.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>

View File

@ -16,7 +16,6 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sdfileio.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -1777,7 +1776,7 @@ void gbReset()
void gbWriteSaveMBC1(const char * name) void gbWriteSaveMBC1(const char * name)
{ {
FILE* gzFile = gen_fopen(name,"wb"); FILE* gzFile = fopen(name,"wb");
if(gzFile == NULL) if(gzFile == NULL)
{ {
@ -1785,17 +1784,17 @@ void gbWriteSaveMBC1(const char * name)
return; return;
} }
gen_fwrite(gbRam, fwrite(gbRam,
1, 1,
gbRamSize, gbRamSize,
gzFile); gzFile);
gen_fclose(gzFile); fclose(gzFile);
} }
void gbWriteSaveMBC2(const char * name) void gbWriteSaveMBC2(const char * name)
{ {
FILE* file = gen_fopen(name, "wb"); FILE* file = fopen(name, "wb");
if(file == NULL) if(file == NULL)
{ {
@ -1803,17 +1802,17 @@ void gbWriteSaveMBC2(const char * name)
return; return;
} }
gen_fwrite(&gbMemory[0xa000], fwrite(&gbMemory[0xa000],
1, 1,
256, 256,
file); file);
gen_fclose(file); fclose(file);
} }
void gbWriteSaveMBC3(const char * name, bool extendedSave) void gbWriteSaveMBC3(const char * name, bool extendedSave)
{ {
FILE* gzFile = gen_fopen(name,"wb"); FILE* gzFile = fopen(name,"wb");
if(gzFile == NULL) if(gzFile == NULL)
{ {
@ -1821,23 +1820,23 @@ void gbWriteSaveMBC3(const char * name, bool extendedSave)
return; return;
} }
gen_fwrite(gbRam, fwrite(gbRam,
1, 1,
gbRamSize, gbRamSize,
gzFile); gzFile);
if(extendedSave) if(extendedSave)
gen_fwrite(&gbDataMBC3.mapperSeconds, fwrite(&gbDataMBC3.mapperSeconds,
1, 1,
10*sizeof(int) + sizeof(time_t), 10*sizeof(int) + sizeof(time_t),
gzFile); gzFile);
gen_fclose(gzFile); fclose(gzFile);
} }
void gbWriteSaveMBC5(const char * name) void gbWriteSaveMBC5(const char * name)
{ {
FILE* gzFile = gen_fopen(name,"wb"); FILE* gzFile = fopen(name,"wb");
if(gzFile == NULL) if(gzFile == NULL)
{ {
@ -1845,17 +1844,17 @@ void gbWriteSaveMBC5(const char * name)
return; return;
} }
gen_fwrite(gbRam, fwrite(gbRam,
1, 1,
gbRamSize, gbRamSize,
gzFile); gzFile);
gen_fclose(gzFile); fclose(gzFile);
} }
void gbWriteSaveMBC7(const char * name) void gbWriteSaveMBC7(const char * name)
{ {
FILE* file = gen_fopen(name, "wb"); FILE* file = fopen(name, "wb");
if(file == NULL) if(file == NULL)
{ {
@ -1863,12 +1862,12 @@ void gbWriteSaveMBC7(const char * name)
return; return;
} }
gen_fwrite(&gbMemory[0xa000], fwrite(&gbMemory[0xa000],
1, 1,
256, 256,
file); file);
gen_fclose(file); fclose(file);
} }
bool gbReadSaveMBC1(const char * name) bool gbReadSaveMBC1(const char * name)
@ -1897,14 +1896,14 @@ bool gbReadSaveMBC1(const char * name)
bool gbReadSaveMBC2(const char * name) bool gbReadSaveMBC2(const char * name)
{ {
FILE* file = gen_fopen(name, "rb"); FILE* file = fopen(name, "rb");
if(file == NULL) if(file == NULL)
{ {
return false; return false;
} }
int read = gen_fread(&gbMemory[0xa000], int read = fread(&gbMemory[0xa000],
1, 1,
256, 256,
file); file);
@ -1913,11 +1912,11 @@ bool gbReadSaveMBC2(const char * name)
{ {
systemMessage(MSG_FAILED_TO_READ_SGM, systemMessage(MSG_FAILED_TO_READ_SGM,
N_("Failed to read complete save game %s (%d)"), name, read); N_("Failed to read complete save game %s (%d)"), name, read);
gen_fclose(file); fclose(file);
return false; return false;
} }
gen_fclose(file); fclose(file);
return true; return true;
} }
@ -1987,14 +1986,14 @@ bool gbReadSaveMBC5(const char * name)
bool gbReadSaveMBC7(const char * name) bool gbReadSaveMBC7(const char * name)
{ {
FILE* file = gen_fopen(name, "rb"); FILE* file = fopen(name, "rb");
if(file == NULL) if(file == NULL)
{ {
return false; return false;
} }
int read = gen_fread(&gbMemory[0xa000], int read = fread(&gbMemory[0xa000],
1, 1,
256, 256,
file); file);
@ -2003,11 +2002,11 @@ bool gbReadSaveMBC7(const char * name)
{ {
systemMessage(MSG_FAILED_TO_READ_SGM, systemMessage(MSG_FAILED_TO_READ_SGM,
N_("Failed to read complete save game %s (%d)"), name, read); N_("Failed to read complete save game %s (%d)"), name, read);
gen_fclose(file); fclose(file);
return false; return false;
} }
gen_fclose(file); fclose(file);
return true; return true;
} }
@ -2115,7 +2114,7 @@ bool gbReadBatteryFile(const char *file)
bool gbReadGSASnapshot(const char *fileName) bool gbReadGSASnapshot(const char *fileName)
{ {
FILE* file = gen_fopen(fileName, "rb"); FILE* file = fopen(fileName, "rb");
if(!file) if(!file)
{ {
@ -2124,10 +2123,10 @@ bool gbReadGSASnapshot(const char *fileName)
} }
// long size = ftell(file); // long size = ftell(file);
gen_fseek(file, 0x4, SEEK_SET); fseek(file, 0x4, SEEK_SET);
char buffer[16]; char buffer[16];
char buffer2[16]; char buffer2[16];
gen_fread(buffer, 1, 15, file); fread(buffer, 1, 15, file);
buffer[15] = 0; buffer[15] = 0;
memcpy(buffer2, &gbRom[0x134], 15); memcpy(buffer2, &gbRom[0x134], 15);
buffer2[15] = 0; buffer2[15] = 0;
@ -2137,10 +2136,10 @@ bool gbReadGSASnapshot(const char *fileName)
N_("Cannot import snapshot for %s. Current game is %s"), N_("Cannot import snapshot for %s. Current game is %s"),
buffer, buffer,
buffer2); buffer2);
gen_fclose(file); fclose(file);
return false; return false;
} }
gen_fseek(file, 0x13, SEEK_SET); fseek(file, 0x13, SEEK_SET);
int read = 0; int read = 0;
int toRead = 0; int toRead = 0;
switch(gbRom[0x147]) switch(gbRom[0x147])
@ -2152,22 +2151,22 @@ bool gbReadGSASnapshot(const char *fileName)
case 0x1b: case 0x1b:
case 0x1e: case 0x1e:
case 0xff: case 0xff:
read = gen_fread(gbRam, 1, gbRamSize, file); read = fread(gbRam, 1, gbRamSize, file);
toRead = gbRamSize; toRead = gbRamSize;
break; break;
case 0x06: case 0x06:
case 0x22: case 0x22:
read = gen_fread(&gbMemory[0xa000],1,256,file); read = fread(&gbMemory[0xa000],1,256,file);
toRead = 256; toRead = 256;
break; break;
default: default:
systemMessage(MSG_UNSUPPORTED_SNAPSHOT_FILE, systemMessage(MSG_UNSUPPORTED_SNAPSHOT_FILE,
N_("Unsupported snapshot file %s"), N_("Unsupported snapshot file %s"),
fileName); fileName);
gen_fclose(file); fclose(file);
return false; return false;
} }
gen_fclose(file); fclose(file);
gbReset(); gbReset();
return true; return true;
} }

View File

@ -16,7 +16,6 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sdfileio.h"
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -103,16 +102,16 @@ void gbCheatsSaveCheatList(const char *file)
{ {
if(gbCheatNumber == 0) if(gbCheatNumber == 0)
return; return;
FILE* f = gen_fopen(file, "wb"); FILE* f = fopen(file, "wb");
if(f == NULL) if(f == NULL)
return; return;
int version = 1; int version = 1;
gen_fwrite(&version, 1, sizeof(version), f); fwrite(&version, 1, sizeof(version), f);
int type = 1; int type = 1;
gen_fwrite(&type, 1, sizeof(type), f); fwrite(&type, 1, sizeof(type), f);
gen_fwrite(&gbCheatNumber, 1, sizeof(gbCheatNumber), f); fwrite(&gbCheatNumber, 1, sizeof(gbCheatNumber), f);
gen_fwrite(gbCheatList, 1, sizeof(gbCheatList), f); fwrite(gbCheatList, 1, sizeof(gbCheatList), f);
gen_fclose(f); fclose(f);
} }
bool gbCheatsLoadCheatList(const char *file) bool gbCheatsLoadCheatList(const char *file)
@ -123,16 +122,16 @@ bool gbCheatsLoadCheatList(const char *file)
int count = 0; int count = 0;
FILE* f = gen_fopen(file, "rb"); FILE* f = fopen(file, "rb");
if(f == NULL) if(f == NULL)
return false; return false;
int version = 0; int version = 0;
if(gen_fread(&version, 1, sizeof(version), f) != sizeof(version)) if(fread(&version, 1, sizeof(version), f) != sizeof(version))
{ {
gen_fclose(f); fclose(f);
return false; return false;
} }
@ -140,14 +139,14 @@ bool gbCheatsLoadCheatList(const char *file)
{ {
systemMessage(MSG_UNSUPPORTED_CHEAT_LIST_VERSION, systemMessage(MSG_UNSUPPORTED_CHEAT_LIST_VERSION,
N_("Unsupported cheat list version %d"), version); N_("Unsupported cheat list version %d"), version);
gen_fclose(f); fclose(f);
return false; return false;
} }
int type = 0; int type = 0;
if(gen_fread(&type, 1, sizeof(type), f) != sizeof(type)) if(fread(&type, 1, sizeof(type), f) != sizeof(type))
{ {
gen_fclose(f); fclose(f);
return false; return false;
} }
@ -155,19 +154,19 @@ bool gbCheatsLoadCheatList(const char *file)
{ {
systemMessage(MSG_UNSUPPORTED_CHEAT_LIST_TYPE, systemMessage(MSG_UNSUPPORTED_CHEAT_LIST_TYPE,
N_("Unsupported cheat list type %d"), type); N_("Unsupported cheat list type %d"), type);
gen_fclose(f); fclose(f);
return false; return false;
} }
if(gen_fread(&count, 1, sizeof(count), f) != sizeof(count)) if(fread(&count, 1, sizeof(count), f) != sizeof(count))
{ {
gen_fclose(f); fclose(f);
return false; return false;
} }
if(gen_fread(gbCheatList, 1, sizeof(gbCheatList), f) != sizeof(gbCheatList)) if(fread(gbCheatList, 1, sizeof(gbCheatList), f) != sizeof(gbCheatList))
{ {
gen_fclose(f); fclose(f);
return false; return false;
} }
@ -423,7 +422,7 @@ void gbCheatDisable(int i)
bool gbCheatReadGSCodeFile(const char *fileName) bool gbCheatReadGSCodeFile(const char *fileName)
{ {
FILE* file = gen_fopen(fileName, "rb"); FILE* file = fopen(fileName, "rb");
if(!file) if(!file)
{ {
@ -431,9 +430,9 @@ bool gbCheatReadGSCodeFile(const char *fileName)
return false; return false;
} }
gen_fseek(file, 0x18, SEEK_SET); fseek(file, 0x18, SEEK_SET);
int count = 0; int count = 0;
gen_fread(&count, 1, 2, file); fread(&count, 1, 2, file);
int dummy = 0; int dummy = 0;
gbCheatRemoveAll(); gbCheatRemoveAll();
char desc[13]; char desc[13];
@ -441,10 +440,10 @@ bool gbCheatReadGSCodeFile(const char *fileName)
int i; int i;
for(i = 0; i < count; i++) for(i = 0; i < count; i++)
{ {
gen_fread(&dummy, 1, 2, file); fread(&dummy, 1, 2, file);
gen_fread(desc, 1, 12, file); fread(desc, 1, 12, file);
desc[12] = 0; desc[12] = 0;
gen_fread(code, 1, 8, file); fread(code, 1, 8, file);
code[8] = 0; code[8] = 0;
gbAddGsCheat(code, desc); gbAddGsCheat(code, desc);
} }
@ -452,7 +451,7 @@ bool gbCheatReadGSCodeFile(const char *fileName)
for(i = 0; i < gbCheatNumber; i++) for(i = 0; i < gbCheatNumber; i++)
gbCheatDisable(i); gbCheatDisable(i);
gen_fclose(file); fclose(file);
return true; return true;
} }

View File

@ -22,7 +22,6 @@
Read unzip.h for more info Read unzip.h for more info
*/ */
#include "sdfileio.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -157,7 +156,7 @@ unz_s;
local int unzlocal_getByte(FILE* fin,int *pi) local int unzlocal_getByte(FILE* fin,int *pi)
{ {
unsigned char c; unsigned char c;
int err = gen_fread(&c, 1, 1, fin); int err = fread(&c, 1, 1, fin);
if (err==1) if (err==1)
{ {
*pi = (int)c; *pi = (int)c;
@ -183,7 +182,7 @@ local int unzlocal_getByte(FILE* fin,int *pi)
local int unzlocal_getShort (FILE* fin,uLong *pX) local int unzlocal_getShort (FILE* fin,uLong *pX)
{ {
uLong x ; uLong x ;
int i; int i = 0;
int err; int err;
err = unzlocal_getByte(fin,&i); err = unzlocal_getByte(fin,&i);
@ -203,7 +202,7 @@ local int unzlocal_getShort (FILE* fin,uLong *pX)
local int unzlocal_getLong (FILE* fin,uLong *pX) local int unzlocal_getLong (FILE* fin,uLong *pX)
{ {
uLong x ; uLong x ;
int i; int i = 0;
int err; int err;
err = unzlocal_getByte(fin,&i); err = unzlocal_getByte(fin,&i);
@ -300,7 +299,7 @@ local uLong unzlocal_SearchCentralDir(FILE* fin)
uLong uPosFound=0; uLong uPosFound=0;
if (gen_fseek(fin,0,SEEK_END) != 0) if (fseek(fin,0,SEEK_END) != 0)
return 0; return 0;
@ -325,10 +324,10 @@ local uLong unzlocal_SearchCentralDir(FILE* fin)
uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
(BUFREADCOMMENT+4) : (uSizeFile-uReadPos); (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
if (gen_fseek(fin,uReadPos,SEEK_SET)!=0) if (fseek(fin,uReadPos,SEEK_SET)!=0)
break; break;
if (gen_fread(buf,(uInt)uReadSize,1,fin)!=1) if (fread(buf,(uInt)uReadSize,1,fin)!=1)
break; break;
for (i=(int)uReadSize-3; (i--)>0;) for (i=(int)uReadSize-3; (i--)>0;)
@ -375,7 +374,7 @@ extern unzFile ZEXPORT unzOpen (const char *path)
if (unz_copyright[0]!=' ') if (unz_copyright[0]!=' ')
return NULL; return NULL;
fin=gen_fopen(path,"rb"); fin=fopen(path,"rb");
if (fin==NULL) if (fin==NULL)
return NULL; return NULL;
@ -383,7 +382,7 @@ extern unzFile ZEXPORT unzOpen (const char *path)
if (central_pos==0) if (central_pos==0)
err=UNZ_ERRNO; err=UNZ_ERRNO;
if (gen_fseek(fin,central_pos,SEEK_SET)!=0) if (fseek(fin,central_pos,SEEK_SET)!=0)
err=UNZ_ERRNO; err=UNZ_ERRNO;
/* the signature, already checked */ /* the signature, already checked */
@ -430,7 +429,7 @@ extern unzFile ZEXPORT unzOpen (const char *path)
if (err!=UNZ_OK) if (err!=UNZ_OK)
{ {
gen_fclose(fin); fclose(fin);
return NULL; return NULL;
} }
@ -463,7 +462,7 @@ extern int ZEXPORT unzClose (unzFile file)
if (s->pfile_in_zip_read!=NULL) if (s->pfile_in_zip_read!=NULL)
unzCloseCurrentFile(file); unzCloseCurrentFile(file);
gen_fclose(s->file); fclose(s->file);
TRYFREE(s); TRYFREE(s);
return UNZ_OK; return UNZ_OK;
} }
@ -535,7 +534,7 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
if (file==NULL) if (file==NULL)
return UNZ_PARAMERROR; return UNZ_PARAMERROR;
s=(unz_s*)file; s=(unz_s*)file;
if (gen_fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0) if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0)
err=UNZ_ERRNO; err=UNZ_ERRNO;
@ -606,7 +605,7 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
uSizeRead = fileNameBufferSize; uSizeRead = fileNameBufferSize;
if ((file_info.size_filename>0) && (fileNameBufferSize>0)) if ((file_info.size_filename>0) && (fileNameBufferSize>0))
if (gen_fread(szFileName,(uInt)uSizeRead,1,s->file)!=1) if (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1)
err=UNZ_ERRNO; err=UNZ_ERRNO;
lSeek -= uSizeRead; lSeek -= uSizeRead;
} }
@ -621,12 +620,12 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
uSizeRead = extraFieldBufferSize; uSizeRead = extraFieldBufferSize;
if (lSeek!=0) if (lSeek!=0)
if (gen_fseek(s->file,lSeek,SEEK_CUR)==0) if (fseek(s->file,lSeek,SEEK_CUR)==0)
lSeek=0; lSeek=0;
else else
err=UNZ_ERRNO; err=UNZ_ERRNO;
if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
if (gen_fread(extraField,(uInt)uSizeRead,1,s->file)!=1) if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1)
err=UNZ_ERRNO; err=UNZ_ERRNO;
lSeek += file_info.size_file_extra - uSizeRead; lSeek += file_info.size_file_extra - uSizeRead;
} }
@ -646,12 +645,12 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
uSizeRead = commentBufferSize; uSizeRead = commentBufferSize;
if (lSeek!=0) if (lSeek!=0)
if (gen_fseek(s->file,lSeek,SEEK_CUR)==0) if (fseek(s->file,lSeek,SEEK_CUR)==0)
lSeek=0; lSeek=0;
else else
err=UNZ_ERRNO; err=UNZ_ERRNO;
if ((file_info.size_file_comment>0) && (commentBufferSize>0)) if ((file_info.size_file_comment>0) && (commentBufferSize>0))
if (gen_fread(szComment,(uInt)uSizeRead,1,s->file)!=1) if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1)
err=UNZ_ERRNO; err=UNZ_ERRNO;
lSeek+=file_info.size_file_comment - uSizeRead; lSeek+=file_info.size_file_comment - uSizeRead;
} }
@ -813,7 +812,7 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (unz_s *s,
*poffset_local_extrafield = 0; *poffset_local_extrafield = 0;
*psize_local_extrafield = 0; *psize_local_extrafield = 0;
if (gen_fseek(s->file,s->cur_file_info_internal.offset_curfile + if (fseek(s->file,s->cur_file_info_internal.offset_curfile +
s->byte_before_the_zipfile,SEEK_SET)!=0) s->byte_before_the_zipfile,SEEK_SET)!=0)
return UNZ_ERRNO; return UNZ_ERRNO;
@ -1024,11 +1023,11 @@ extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed; uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
if (uReadThis == 0) if (uReadThis == 0)
return UNZ_EOF; return UNZ_EOF;
if (gen_fseek(pfile_in_zip_read_info->file, if (fseek(pfile_in_zip_read_info->file,
pfile_in_zip_read_info->pos_in_zipfile + pfile_in_zip_read_info->pos_in_zipfile +
pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0) pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0)
return UNZ_ERRNO; return UNZ_ERRNO;
if (gen_fread(pfile_in_zip_read_info->read_buffer,uReadThis,1, if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1,
pfile_in_zip_read_info->file)!=1) pfile_in_zip_read_info->file)!=1)
return UNZ_ERRNO; return UNZ_ERRNO;
pfile_in_zip_read_info->pos_in_zipfile += uReadThis; pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
@ -1190,12 +1189,12 @@ extern int ZEXPORT unzGetLocalExtrafield (unzFile file,voidp buf,unsigned len)
if (read_now==0) if (read_now==0)
return 0; return 0;
if (gen_fseek(pfile_in_zip_read_info->file, if (fseek(pfile_in_zip_read_info->file,
pfile_in_zip_read_info->offset_local_extrafield + pfile_in_zip_read_info->offset_local_extrafield +
pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0) pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0)
return UNZ_ERRNO; return UNZ_ERRNO;
if (gen_fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1) if (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1)
return UNZ_ERRNO; return UNZ_ERRNO;
return (int)read_now; return (int)read_now;
@ -1261,13 +1260,13 @@ extern int ZEXPORT unzGetGlobalComment (unzFile file,
if (uReadThis>s->gi.size_comment) if (uReadThis>s->gi.size_comment)
uReadThis = s->gi.size_comment; uReadThis = s->gi.size_comment;
if (gen_fseek(s->file,s->central_pos+22,SEEK_SET)!=0) if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0)
return UNZ_ERRNO; return UNZ_ERRNO;
if (uReadThis>0) if (uReadThis>0)
{ {
*szComment='\0'; *szComment='\0';
if (gen_fread(szComment,(uInt)uReadThis,1,s->file)!=1) if (fread(szComment,(uInt)uReadThis,1,s->file)!=1)
return UNZ_ERRNO; return UNZ_ERRNO;
} }