From d8a3101bb0b1bd5e3f37ea203ed5a8f4200d9065 Mon Sep 17 00:00:00 2001 From: dborth Date: Wed, 1 Oct 2008 05:25:38 +0000 Subject: [PATCH] complete redesign/rewrite of ROM loading (UNIF, NSF, partial FDS support), 7z detection --- readme.txt | 12 ++- source/fceultra/fceu.c | 8 +- source/fceultra/fds.c | 66 ++++++++-------- source/fceultra/file.c | 6 -- source/fceultra/file.h | 6 ++ source/fceultra/ines.c | 159 +-------------------------------------- source/fceultra/unif.c | 26 +++---- source/fceultra/video.c | 4 +- source/ngc/dvd.c | 23 +++--- source/ngc/fceugc.c | 25 +++--- source/ngc/fceuload.c | 102 ++++++++++++++++++++++--- source/ngc/fceuload.h | 2 +- source/ngc/fceuram.c | 26 ++++--- source/ngc/fceustate.c | 13 ++-- source/ngc/fileop.c | 35 +++++---- source/ngc/fileop.h | 3 +- source/ngc/filesel.c | 6 +- source/ngc/filesel.h | 10 +++ source/ngc/gcaudio.c | 2 +- source/ngc/gcunzip.c | 67 +++++++++++++---- source/ngc/memcardop.c | 2 +- source/ngc/menu.c | 28 ++++--- source/ngc/preferences.c | 2 +- source/ngc/smbop.c | 19 +++-- 24 files changed, 320 insertions(+), 332 deletions(-) diff --git a/readme.txt b/readme.txt index 1af56ef..16b79bd 100644 --- a/readme.txt +++ b/readme.txt @@ -29,14 +29,20 @@ SNES9x GX and Genesis Plus GX projects. |0Oื๘oท UPDATE HISTORY ทo๘ืO0| `จ•จจจจจ จจจจจจจจจจจจจจจจ จจจจจจจจจจจจจจจ จจจจจจจจจจจจจจจจจจจจ จจจจจจจจจจจจจ' -[What's New 2.0.2] +[What's New 2.0.3] +* VS game support (submitted by pakitovic) +* Complete rewrite of loading code - UNIF / NSF support, FDS games + load but don't run +* 480p and DVD now available for GameCube + +[What's New 2.0.2 - September 19, 2008] * Fixed network freeze-up problem * Zapper now mapped to A and B * Fixed auto-save feature * Performance slowdowns on Gamecube should be fixed * Will now attempt to load old save states with CRC filename -[What's New 2.0.1] +[What's New 2.0.1 - September 6, 2008] * Zapper support! Turn this on in the Controller Settings - most games require you to have the Zapper on Port 2. Thanks go to aksommerville whose previous work on the Zapper helped, and michniewski's cursor code @@ -46,7 +52,7 @@ SNES9x GX and Genesis Plus GX projects. * Start/Select reversed mapping fixed for Wii controllers * Small bug fixes / improvements / tweaks -[What's New 2.0.0] +[What's New 2.0.0 - September 1, 2008] * Complete rewrite based on code from SNES9x GX and Genesis Plus GX * Wiimote, Nunchuk, and Classic controller support diff --git a/source/fceultra/fceu.c b/source/fceultra/fceu.c index 4f2c856..6fe6db9 100644 --- a/source/fceultra/fceu.c +++ b/source/fceultra/fceu.c @@ -424,7 +424,7 @@ FCEUS FSettings; void FCEU_printf(char *format, ...) { - char temp[2048]; + /*char temp[2048]; va_list ap; @@ -432,12 +432,12 @@ void FCEU_printf(char *format, ...) vsprintf(temp,format,ap); FCEUD_Message(temp); - va_end(ap); + va_end(ap);*/ } void FCEU_PrintError(char *format, ...) { - char temp[2048]; +/* char temp[2048]; va_list ap; @@ -445,7 +445,7 @@ void FCEU_PrintError(char *format, ...) vsprintf(temp,format,ap); FCEUD_PrintError(temp); - va_end(ap); + va_end(ap);*/ } void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall) diff --git a/source/fceultra/fds.c b/source/fceultra/fds.c index 5a98d6b..d1023c1 100644 --- a/source/fceultra/fds.c +++ b/source/fceultra/fds.c @@ -67,7 +67,7 @@ static int32 IRQLatch,IRQCount; static uint8 IRQa; static void FDSClose(void); -static uint8 FDSBIOS[8192]; +uint8 FDSBIOS[8192]; /* Original disk data backup, to help in creating save states. */ static uint8 *diskdatao[8]={0,0,0,0,0,0,0,0}; @@ -93,7 +93,7 @@ void FDSGI(int h) } static void FDSStateRestore(int version) -{ +{ int x; setmirror(((FDSRegs[5]&8)>>3)^1); @@ -132,7 +132,7 @@ static void FDSInit(void) SetReadHandler(0x4032,0x4032,FDSRead4032); SetReadHandler(0x4033,0x4033,FDSRead4033); - SetWriteHandler(0x4020,0x4025,FDSWrite); + SetWriteHandler(0x4020,0x4025,FDSWrite); SetWriteHandler(0x6000,0xdfff,FDSRAMWrite); SetReadHandler(0x6000,0xdfff,FDSRAMRead); @@ -148,10 +148,10 @@ void FCEU_FDSInsert(int oride) { if(InDisk==255) { - FCEU_DispMessage("Disk %d Side %s Inserted",SelectDisk>>1,(SelectDisk&1)?"B":"A"); + FCEU_DispMessage("Disk %d Side %s Inserted",SelectDisk>>1,(SelectDisk&1)?"B":"A"); InDisk=SelectDisk; } - else + else { FCEU_DispMessage("Disk %d Side %s Ejected",SelectDisk>>1,(SelectDisk&1)?"B":"A"); InDisk=255; @@ -187,14 +187,14 @@ static void FP_FASTAPASS(1) FDSFix(int a) IRQCount=IRQLatch=0; } else - IRQCount=IRQLatch; + IRQCount=IRQLatch; //IRQCount=IRQLatch; //0xFFFF; X6502_IRQBegin(FCEU_IQEXT); //printf("IRQ: %d\n",timestamp); // printf("IRQ: %d\n",scanline); } } - if(DiskSeekIRQ>0) + if(DiskSeekIRQ>0) { DiskSeekIRQ-=a; if(DiskSeekIRQ<=0) @@ -239,14 +239,14 @@ static DECLFR(FDSRead4031) return z; } static DECLFR(FDSRead4032) -{ +{ uint8 ret; ret=X.DB&~7; if(InDisk==255) ret|=5; - if(InDisk==255 || !(FDSRegs[5]&1) || (FDSRegs[5]&2)) + if(InDisk==255 || !(FDSRegs[5]&1) || (FDSRegs[5]&2)) ret|=2; return ret; } @@ -345,7 +345,7 @@ static DECLFW(FDSSWrite) A-=0x4080; switch(A) { - case 0x0: + case 0x0: case 0x4: if(V&0x80) amplitude[(A&0xF)>>2]=V&0x3F; //)>0x20?0x20:(V&0x3F); break; @@ -361,7 +361,7 @@ static DECLFW(FDSSWrite) break; } //if(A>=0x7 && A!=0x8 && A<=0xF) - //if(A==0xA || A==0x9) + //if(A==0xA || A==0x9) //printf("$%04x:$%02x\n",A,V); SPSG[A]=V; } @@ -428,7 +428,7 @@ static INLINE void ClockRise(void) b19shiftreg60=(SPSG[0x2]|((SPSG[0x3]&0xF)<<8)); b17latch76=(SPSG[0x6]|((SPSG[0x07]&0xF)<<8))+b17latch76; - if(!(SPSG[0x7]&0x80)) + if(!(SPSG[0x7]&0x80)) { int t=fdso.mwave[(b17latch76>>13)&0x1F]&7; int t2=amplitude[1]; @@ -448,13 +448,13 @@ static INLINE void ClockRise(void) b8shiftreg88=0x80 + adj; } else - { + { b8shiftreg88=0x80; } } else { - b19shiftreg60<<=1; + b19shiftreg60<<=1; b8shiftreg88>>=1; } // b24adder66=(b24latch68+b19shiftreg60)&0x3FFFFFF; @@ -484,7 +484,7 @@ static INLINE int32 FDSDoSound(void) if(fdso.envcount<=0) { fdso.envcount+=SPSG[0xA]*3; - DoEnv(); + DoEnv(); } } if(fdso.count>=32768) goto dogk; @@ -523,7 +523,7 @@ static void RenderSound(void) static void RenderSoundHQ(void) { int32 x; - + if(!(SPSG[0x9]&0x80)) for(x=FBC;xtype=GIT_FDS; GameInterface=FDSGI; @@ -817,7 +815,7 @@ int FDSLoad(const char *name, FCEUFILE *fp) for(x=0;x>4); - MapperNo|=(head.ROM_type2&0xF0); - Mirroring = (head.ROM_type&1); - - if(head.ROM_type&8) Mirroring=2; - - if(!(ROM=(uint8 *)FCEU_malloc(ROM_size<<14))) - return 0; - - if (VROM_size) - if(!(VROM=(uint8 *)FCEU_malloc(VROM_size<<13))) - { - free(ROM); - return 0; - } - - memset(ROM,0xFF,ROM_size<<14); - if(VROM_size) memset(VROM,0xFF,VROM_size<<13); - if(head.ROM_type&4) /* Trainer */ - { - trainerpoo=(uint8 *)FCEU_gmalloc(512); - memcpy(trainerpoo, &nesrom[memoffs], 512); - memoffs+=512; - //FCEU_fread(trainerpoo,512,1,fp); - } - - ResetCartMapping(); - ResetExState(0,0); - - SetupCartPRGMapping(0,ROM,ROM_size*0x4000,0); - SetupCartPRGMapping(1,WRAM,8192,1); - - //FCEU_fread(ROM,0x4000,head.ROM_size,fp); - memcpy(ROM, &nesrom[memoffs], head.ROM_size * 0x4000); - memoffs += ( head.ROM_size * 0x4000 ); - - if(VROM_size){ - //FCEU_fread(VROM,0x2000,head.VROM_size,fp); - memcpy(VROM, &nesrom[memoffs], 0x2000 * head.VROM_size); - memoffs += ( head.VROM_size * 0x2000 ); - } - - md5_starts(&md5); - md5_update(&md5,ROM,ROM_size<<14); - - iNESGameCRC32=CalcCRC32(0,ROM,ROM_size<<14); - - if(VROM_size) - { - iNESGameCRC32=CalcCRC32(iNESGameCRC32,VROM,VROM_size<<13); - md5_update(&md5,VROM,VROM_size<<13); - } - - md5_finish(&md5,iNESCart.MD5); - memcpy(FCEUGameInfo->MD5,iNESCart.MD5,sizeof(iNESCart.MD5)); - - iNESCart.CRC32=iNESGameCRC32; - - SetInput(); - CheckHInfo(); - - { - int x; - uint64 partialmd5=0; - - for(x=0;x<8;x++) - { - partialmd5 |= (uint64)iNESCart.MD5[7-x] << (x*8); - } - - FCEU_VSUniCheck(partialmd5, &MapperNo, &Mirroring); - } - - /* Must remain here because above functions might change value of - VROM_size and free(VROM). - */ - if(VROM_size) - SetupCartCHRMapping(0,VROM,VROM_size*0x2000,0); - - if(Mirroring==2) - SetupCartMirroring(4,1,ExtraNTARAM); - else if(Mirroring>=0x10) - SetupCartMirroring(2+(Mirroring&1),1,0); - else - SetupCartMirroring(Mirroring&1,(Mirroring&4)>>2,0); - - iNESCart.battery=(head.ROM_type&2)?1:0; - iNESCart.mirror=Mirroring; - - if(NewiNES_Init(MapperNo)) - { - - } - else - { - iNESCart.Power=iNESPower; - if(head.ROM_type&2) - { - iNESCart.SaveGame[0]=WRAM; - iNESCart.SaveGameLen[0]=8192; - } - } - - GameInterface=iNESGI; - return 1; -} - diff --git a/source/fceultra/unif.c b/source/fceultra/unif.c index a6bfd6a..49d9c66 100644 --- a/source/fceultra/unif.c +++ b/source/fceultra/unif.c @@ -57,7 +57,7 @@ typedef struct { int (*init)(FCEUFILE *fp); } BFMAPPING; -static CartInfo UNIFCart; +CartInfo UNIFCart; static int vramo; static int mirrortodo; @@ -130,7 +130,7 @@ static int DoMirroring(FCEUFILE *fp) { uint8 t; t=FCEU_fgetc(fp); - mirrortodo=t; + mirrortodo=t; { static char *stuffo[6]={"Horizontal","Vertical","$2000","$2400","\"Four-screen\"","Controlled by Mapper Hardware"}; @@ -268,7 +268,7 @@ static int LoadPRG(FCEUFILE *fp) else FCEU_printf("\n"); - SetupCartPRGMapping(z,malloced[z],t,0); + SetupCartPRGMapping(z,malloced[z],t,0); return(1); } @@ -371,14 +371,14 @@ static BMAPPING bmap[] = { { "CPROM", CPROM_Init,0}, { "CNROM", CNROM_Init,0}, - + //{ "GNROM", GNROM_Init,0}, //{ "NROM", NROM256_Init,0 }, //{ "RROM", NROM128_Init,0 }, //{ "RROM-128", NROM128_Init,0 }, //{ "NROM-128", NROM128_Init,0 }, //{ "NROM-256", NROM256_Init,0 }, - + { "MHROM", MHROM_Init,0}, { "UNROM", UNROM_Init,0}, { "MARIO1-MALEE2", MALEE_Init,0}, @@ -410,13 +410,13 @@ int LoadUNIFChunks(FCEUFILE *fp) for(;;) { t=FCEU_fread(&uchead,1,4,fp); - if(t<4) + if(t<4) { if(t>0) - return 0; + return 0; return 1; } - if(!(FCEU_read32le(&uchead.info,fp))) + if(!(FCEU_read32le(&uchead.info,fp))) return 0; t=0; x=0; @@ -428,7 +428,7 @@ int LoadUNIFChunks(FCEUFILE *fp) if(!bfunc[x].init(fp)) return 0; t=1; - break; + break; } x++; } @@ -497,7 +497,7 @@ int UNIFLoad(const char *name, FCEUFILE *fp) FCEU_fseek(fp,0,SEEK_SET); FCEU_fread(&unhead,1,4,fp); if(memcmp(&unhead,"UNIF",4)) - return 0; + return 0; ResetCartMapping(); @@ -512,7 +512,7 @@ int UNIFLoad(const char *name, FCEUFILE *fp) { int x; struct md5_context md5; - + md5_starts(&md5); for(x=0;x<32;x++) @@ -531,10 +531,10 @@ int UNIFLoad(const char *name, FCEUFILE *fp) if(!InitializeBoard()) goto aborto; - FCEU_LoadGameSave(&UNIFCart); + //FCEU_LoadGameSave(&UNIFCart); GameInterface=UNIFGI; return 1; - + aborto: FreeUNIF(); diff --git a/source/fceultra/video.c b/source/fceultra/video.c index 96981f6..e091393 100644 --- a/source/fceultra/video.c +++ b/source/fceultra/video.c @@ -144,13 +144,13 @@ void FCEU_PutImage(void) void FCEU_DispMessage(char *format, ...) { - va_list ap; +/* va_list ap; va_start(ap,format); vsprintf(errmsg,format,ap); va_end(ap); - howlong=180; + howlong=180;*/ } void FCEU_ResetMessages(void) diff --git a/source/ngc/dvd.c b/source/ngc/dvd.c index 765e8a2..bcde09f 100644 --- a/source/ngc/dvd.c +++ b/source/ngc/dvd.c @@ -22,11 +22,6 @@ #include "menudraw.h" #include "gcunzip.h" -extern bool isWii; -extern int offset; -extern int selection; -extern FILEENTRIES filelist[MAXFILES]; -extern int maxfiles; u64 dvddir = 0; u64 dvdrootdir = 0; int dvddirlength = 0; @@ -451,7 +446,19 @@ LoadDVDFile (unsigned char *buffer) ShowAction ((char*) "Loading..."); dvd_read (readbuffer, 2048, discoffset); - if (!IsZipFile (readbuffer)) + int r = IsZipFile (readbuffer); + + if(r == 2) // 7z + { + WaitPrompt ((char *)"7z files are not supported!"); + return 0; + } + + if (r) + { + return UnZipDVDFile (buffer, discoffset); // unzip from dvd + } + else { for (i = 0; i < blocks; i++) { @@ -469,10 +476,6 @@ LoadDVDFile (unsigned char *buffer) memcpy (buffer + offset, readbuffer, i); } } - else - { - return UnZipDVDFile (buffer, discoffset); // unzip from dvd - } return dvddirlength; } diff --git a/source/ngc/fceugc.c b/source/ngc/fceugc.c index 22b3fd0..bf9fade 100644 --- a/source/ngc/fceugc.c +++ b/source/ngc/fceugc.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -33,6 +34,7 @@ #include #endif +extern unsigned char nesrom[]; extern bool romLoaded; bool isWii; @@ -40,6 +42,7 @@ uint8 *xbsave=NULL; extern int cleanSFMDATA(); extern void ResetNES(void); +extern uint8 FDSBIOS[8192]; void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); @@ -83,9 +86,9 @@ int main(int argc, char *argv[]) FCEUI_SetVidSystem(0); // 0 - NTSC, 1 - PAL FCEUI_SetGameGenie(0); // 0 - OFF, 1 - ON + memset(FDSBIOS, 0, sizeof(FDSBIOS)); // clear FDS BIOS memory cleanSFMDATA(); // clear state data - GCMemROM(); // load color test ROM - romLoaded = false; // we start off with only the color test rom + nesromptr = &nesrom[0]; // address of embedded color test ROM // Set Defaults DefaultSettings(); @@ -118,15 +121,13 @@ int main(int argc, char *argv[]) /**************************************************************************** * FCEU Support Functions to be written ****************************************************************************/ -/*** File Control ***/ - - +// File Control FILE *FCEUD_UTF8fopen(const char *n, const char *m) { return(fopen(n,m)); } -/*** General Logging ***/ +// General Logging void FCEUD_PrintError(char *s) { } @@ -135,15 +136,15 @@ void FCEUD_Message(char *text) { } -/*** VIDEO ***/ -void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count) +// main interface to FCE Ultra +void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int32 Count) { - PlaySound(Buffer, Count); - RenderFrame( (char *)XBuf, GCSettings.screenscaler ); - GetJoy(); + PlaySound(Buffer, Count); // play sound + RenderFrame( (char *)XBuf, GCSettings.screenscaler); // output video frame + GetJoy(); // check controller input } -/*** Netplay ***/ +// Netplay int FCEUD_SendData(void *data, uint32 len) { return 1; diff --git a/source/ngc/fceuload.c b/source/ngc/fceuload.c index cfc1e03..55b1e91 100644 --- a/source/ngc/fceuload.c +++ b/source/ngc/fceuload.c @@ -22,25 +22,58 @@ #include "palette.h" #include "fceu.h" #include "sound.h" +#include "file.h" #include "common.h" #include "pad.h" #include "menudraw.h" +#include "fceuconfig.h" +#include "fileop.h" +#include "filesel.h" +#include "smbop.h" unsigned char *nesromptr; bool romLoaded = false; extern FCEUGI *FCEUGameInfo; -extern int iNESMemLoad( char *rom ); - -extern unsigned char nesrom[]; #define SAMPLERATE 48000 -int GCMemROM() -{ - nesromptr = &nesrom[0]; +FCEUFILE *fceufp = NULL; +MEMWRAP *fceumem = NULL; +unsigned char * fceuFileData = NULL; +void MakeFCEUFile(char * membuffer, int length) +{ + if(fceufp != NULL) + { + free(fceuFileData); + free(fceumem); + free(fceufp); + fceuFileData = NULL; + fceumem = NULL; + fceufp = NULL; + } + + fceufp =(FCEUFILE *)malloc(sizeof(FCEUFILE)); + fceufp->type=3; + fceumem = (MEMWRAP *)malloc(sizeof(MEMWRAP)); + fceumem->location=0; + fceumem->size=length; + fceuFileData = (unsigned char *)malloc(length); + memcpy(fceuFileData, membuffer, length); + fceumem->data=fceuFileData; + fceufp->fp = fceumem; +} + +extern int FDSLoad(const char *name, FCEUFILE *fp); +extern int iNESLoad(const char *name, FCEUFILE *fp); +extern int UNIFLoad(const char *name, FCEUFILE *fp); +extern int NSFLoad(FCEUFILE *fp); +extern uint8 FDSBIOS[8192]; + +int GCMemROM(method) +{ ResetGameLoaded(); /*** Allocate and clear GameInfo ***/ @@ -66,7 +99,58 @@ int GCMemROM() InitialisePads(); - if ( iNESMemLoad( (char *)nesromptr ) ) + MakeFCEUFile((char *)nesromptr, filelist[selection].length); + + nesGameType = 0; + + if(iNESLoad(NULL, fceufp)) + nesGameType = 1; + else if(UNIFLoad(NULL,fceufp)) + nesGameType = 2; + else if(NSFLoad(fceufp)) + nesGameType = 3; + else + { + // read FDS BIOS into FDSBIOS - should be 8192 bytes + if(FDSBIOS[1] == 0) + { + int biosSize = 0; + char * tmpbuffer = (char *)malloc(64 * 1024); + + char filepath[1024]; + sprintf(filepath, "%s/disksys.rom", GCSettings.LoadFolder); + + switch (method) + { + case METHOD_SD: + case METHOD_USB: + biosSize = LoadBufferFromFAT(tmpbuffer, filepath, NOTSILENT); + break; + case METHOD_SMB: + biosSize = LoadBufferFromSMB(tmpbuffer, filepath, NOTSILENT); + break; + } + + if(biosSize == 8192) + { + memcpy(FDSBIOS, tmpbuffer, 8192); + } + else + { + if(biosSize > 0) + WaitPrompt("FDS BIOS file is invalid!"); + } + free(tmpbuffer); + } + else + { + // load game + if(FDSLoad(NULL,fceufp)) + nesGameType = 4; + } + } + + if (nesGameType > 0) { FCEU_ResetVidSys(); PowerNES(); @@ -74,6 +158,7 @@ int GCMemROM() FCEU_ResetMessages(); // Save state, status messages, etc. SetSoundVariables(); romLoaded = true; + return 1; } else { @@ -81,7 +166,4 @@ int GCMemROM() romLoaded = false; return 0; } - - return 1; } - diff --git a/source/ngc/fceuload.h b/source/ngc/fceuload.h index 138a10d..c5013f3 100644 --- a/source/ngc/fceuload.h +++ b/source/ngc/fceuload.h @@ -9,4 +9,4 @@ * NES Memory Load Game ****************************************************************************/ -int GCMemROM(); +int GCMemROM(int method); diff --git a/source/ngc/fceuram.c b/source/ngc/fceuram.c index d53e4ae..a05b74c 100644 --- a/source/ngc/fceuram.c +++ b/source/ngc/fceuram.c @@ -41,9 +41,7 @@ extern u32 iNESGameCRC32; extern CartInfo iNESCart; - -extern unsigned char savebuffer[SAVEBUFFERSIZE]; -extern char romFilename[]; +extern CartInfo UNIFCart; int NGCFCEU_GameSave(CartInfo *LocalHWInfo, int operation) { @@ -80,10 +78,14 @@ bool SaveRAM (int method, bool silent) bool retval = false; char filepath[1024]; - int datasize; + int datasize = 0; int offset = 0; - datasize = NGCFCEU_GameSave(&iNESCart, 0); // save game save to savebuffer + // save game save to savebuffer + if(nesGameType == 1) + datasize = NGCFCEU_GameSave(&iNESCart, 0); + else if(nesGameType == 2) + datasize = NGCFCEU_GameSave(&UNIFCart, 0); if ( datasize ) { @@ -137,9 +139,11 @@ bool LoadRAM (int method, bool silent) if(method == METHOD_SD || method == METHOD_USB) { - ChangeFATInterface(method, NOTSILENT); - sprintf (filepath, "%s/%s/%s.sav", ROOTFATDIR, GCSettings.SaveFolder, romFilename); - offset = LoadBufferFromFAT (filepath, silent); + if(ChangeFATInterface(method, NOTSILENT)) + { + sprintf (filepath, "%s/%s/%s.sav", ROOTFATDIR, GCSettings.SaveFolder, romFilename); + offset = LoadSaveBufferFromFAT (filepath, silent); + } } else if(method == METHOD_SMB) { @@ -158,7 +162,11 @@ bool LoadRAM (int method, bool silent) if (offset > 0) { - NGCFCEU_GameSave(&iNESCart, 1); // load game save from savebuffer + if(nesGameType == 1) + NGCFCEU_GameSave(&iNESCart, 1); + else if(nesGameType == 2) + NGCFCEU_GameSave(&UNIFCart, 1); + ResetNES(); return 1; } diff --git a/source/ngc/fceustate.c b/source/ngc/fceustate.c index 08e74e9..f692ef2 100644 --- a/source/ngc/fceustate.c +++ b/source/ngc/fceustate.c @@ -52,9 +52,6 @@ extern u32 iNESGameCRC32; int sboffset; /*** Used as a basic fileptr ***/ int mcversion = 0x981211; -extern unsigned char savebuffer[SAVEBUFFERSIZE]; -extern char romFilename[]; - /**************************************************************************** * Memory based file functions ****************************************************************************/ @@ -62,7 +59,7 @@ extern char romFilename[]; /*** Open a file ***/ void memopen() { sboffset = 0; - memset(savebuffer, 0, sizeof(savebuffer)); + memset(savebuffer, 0, SAVEBUFFERSIZE); } /*** Close a file ***/ @@ -72,7 +69,7 @@ void memclose() { /*** Write to the file ***/ void memfwrite( void *buffer, int len ) { - if ( (sboffset + len ) > sizeof(savebuffer)) + if ( (sboffset + len ) > SAVEBUFFERSIZE) WaitPrompt("Buffer Exceeded"); if ( len > 0 ) { @@ -84,7 +81,7 @@ void memfwrite( void *buffer, int len ) { /*** Read from a file ***/ void memfread( void *buffer, int len ) { - if ( ( sboffset + len ) > sizeof(savebuffer)) + if ( ( sboffset + len ) > SAVEBUFFERSIZE) WaitPrompt("Buffer exceeded"); if ( len > 0 ) { @@ -334,13 +331,13 @@ bool LoadState (int method, bool silent) { ChangeFATInterface(method, NOTSILENT); sprintf (filepath, "%s/%s/%s.fcs", ROOTFATDIR, GCSettings.SaveFolder, romFilename); - offset = LoadBufferFromFAT (filepath, silent); + offset = LoadSaveBufferFromFAT (filepath, silent); if(offset == 0) // file not found { // look for CRC save sprintf (filepath, "%08x.fcs", iNESGameCRC32); - offset = LoadBufferFromFAT (filepath, silent); + offset = LoadSaveBufferFromFAT (filepath, silent); } } else if(method == METHOD_SMB) diff --git a/source/ngc/fileop.c b/source/ngc/fileop.c index 9ad5772..0f13333 100644 --- a/source/ngc/fileop.c +++ b/source/ngc/fileop.c @@ -25,13 +25,6 @@ FILE * filehandle; -extern unsigned char savebuffer[]; -extern char output[16384]; -extern int offset; -extern int selection; -extern char currentdir[MAXPATHLEN]; -extern FILEENTRIES filelist[MAXFILES]; - /**************************************************************************** * fat_is_mounted * to check whether FAT media are detected. @@ -190,9 +183,17 @@ LoadFATFile (char *filename, int length) { fread (zipbuffer, 1, 2048, handle); - if (IsZipFile (zipbuffer)) + int r = IsZipFile (zipbuffer); + + if(r == 2) // 7z { - size = UnZipFATFile (nesromptr, handle); // unzip from FAT + WaitPrompt ((char *)"7z files are not supported!"); + return 0; + } + + if (r) + { + size = UnZipFATFile (nesromptr, handle); // unzip from FAT } else { @@ -218,16 +219,22 @@ LoadFATFile (char *filename, int length) /**************************************************************************** * Load savebuffer from FAT file - ****************************************************************************/ + ***************************************************************************/ + +// no buffer is specified - so use savebuffer int -LoadBufferFromFAT (char *filepath, bool silent) +LoadSaveBufferFromFAT (char *filepath, bool silent) +{ + return LoadBufferFromFAT((char *)savebuffer, filepath, silent); +} + +int +LoadBufferFromFAT (char * sbuffer, char *filepath, bool silent) { FILE *handle; int boffset = 0; int read = 0; - ClearSaveBuffer (); - handle = fopen (filepath, "rb"); if (handle <= 0) @@ -275,7 +282,5 @@ SaveBufferToFAT (char *filepath, int datasize, bool silent) fwrite (savebuffer, 1, datasize, handle); fclose (handle); } - - ClearSaveBuffer (); return datasize; } diff --git a/source/ngc/fileop.h b/source/ngc/fileop.h index 2c6c184..5e9052e 100644 --- a/source/ngc/fileop.h +++ b/source/ngc/fileop.h @@ -26,7 +26,8 @@ bool ChangeFATInterface(int method, bool silent); int ParseFATdirectory(int method); int LoadFATFile (char *filename, int length); int SaveBufferToFAT (char *filepath, int datasize, bool silent); -int LoadBufferFromFAT (char *filepath, bool silent); +int LoadSaveBufferFromFAT (char *filepath, bool silent); +int LoadBufferFromFAT (char * buffer, char *filepath, bool silent); extern char currFATdir[MAXPATHLEN]; diff --git a/source/ngc/filesel.c b/source/ngc/filesel.c index 8f2aba3..55f765c 100644 --- a/source/ngc/filesel.c +++ b/source/ngc/filesel.c @@ -34,6 +34,7 @@ int offset; int selection; char currentdir[MAXPATHLEN]; char romFilename[200]; +int nesGameType; int maxfiles; extern int screenheight; @@ -46,7 +47,7 @@ int hasloaded = 0; // Global file entry table FILEENTRIES filelist[MAXFILES]; -unsigned char savebuffer[SAVEBUFFERSIZE] ATTRIBUTE_ALIGN (32); +unsigned char savebuffer[SAVEBUFFERSIZE]; /**************************************************************************** * Clear the savebuffer @@ -323,13 +324,14 @@ int FileSelector (int method) break; } - if (GCMemROM() >= 0) + if (GCMemROM(method) > 0) { return 1; } else { WaitPrompt((char*) "Error loading ROM!"); + return 0; } } redraw = 1; diff --git a/source/ngc/filesel.h b/source/ngc/filesel.h index c5925da..8b99e4e 100644 --- a/source/ngc/filesel.h +++ b/source/ngc/filesel.h @@ -12,6 +12,8 @@ #ifndef _NGCFILESEL_ #define _NGCFILESEL_ +#include + #define SAVEBUFFERSIZE (64 * 1024) #define MAXJOLIET 255 #define MAXDISPLAY 54 @@ -27,6 +29,14 @@ typedef struct #define MAXFILES 2000 // Restrict to 2000 files per dir extern FILEENTRIES filelist[MAXFILES]; +extern bool isWii; +extern int offset; +extern int selection; +extern char currentdir[MAXPATHLEN]; +extern int maxfiles; +extern unsigned char savebuffer[]; +extern char romFilename[]; +extern int nesGameType; void ClearSaveBuffer (); int OpenROM (int method); diff --git a/source/ngc/gcaudio.c b/source/ngc/gcaudio.c index 2b2feb0..a2bd0f1 100644 --- a/source/ngc/gcaudio.c +++ b/source/ngc/gcaudio.c @@ -44,7 +44,7 @@ void InitialiseSound() AUDIO_Init(NULL); /*** Start audio subsystem ***/ AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ); AUDIO_RegisterDMACallback( AudioSwitchBuffers ); - + memset(audiobuffer, 0, (64 * 1024)); buffSize[0] = buffSize[1] = 0; } diff --git a/source/ngc/gcunzip.c b/source/ngc/gcunzip.c index 1b629ce..b5144da 100644 --- a/source/ngc/gcunzip.c +++ b/source/ngc/gcunzip.c @@ -21,7 +21,6 @@ /* * PKWare Zip Header - adopted into zip standard */ -#define PKZIPID 0x504b0304 #define MAXROM 0x500000 #define ZIPCHUNK 2048 @@ -56,19 +55,27 @@ FLIP16 (u16 b) /**************************************************************************** * IsZipFile * - * Returns TRUE when PKZIPID is first four characters of buffer + * Returns 1 when Zip signature is found + * Returns 2 when 7z signature is found ****************************************************************************/ int IsZipFile (char *buffer) { unsigned int *check; - check = (unsigned int *) buffer; - if (check[0] == PKZIPID) + if (check[0] == 0x504b0304) // ZIP file return 1; - return 0; + // 7z signature + static Byte Signature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; + + int i; + for(i = 0; i < 6; i++) + if(buffer[i] != Signature[i]) + return 0; + + return 2; // 7z archive found } /***************************************************************************** @@ -228,7 +235,46 @@ UnZipSMBFile (unsigned char *outbuffer, SMBFILE infile) /* * 7-zip functions are below. Have to be written to work with above. + * +else if (selection == 0 && inSz == true) { + rootdir = filelist[1].offset; + rootdirlength = filelist[1].length; + offset = 0; + maxfiles = parsedir(); + inSz = false; + SzClose(); +} +else if (inSz == false && SzDvdIsArchive(filelist[selection].offset) == SZ_OK) { + // parse the 7zip file + ShowAction("Found 7z"); + SzParse(); + if(SzRes == SZ_OK) { + inSz = true; + offset = selection = 0; + } else { + SzDisplayError(SzRes); + } +} +else if (inSz == true) { + // extract the selected ROM from the 7zip file to the buffer + if(SzExtractROM(filelist[selection].offset, nesromptr) == true) { + haverom = 1; + inSz = false; + // go one directory up + rootdir = filelist[1].offset; + rootdirlength = filelist[1].length; + offset = selection = 0; + maxfiles = parsedir(); + } +} +*/ + + + + +/* + * 7-zip functions are below. Have to be written to work with above. #include "7zCrc.h" @@ -269,17 +315,6 @@ size_t SzOutSizeProcessed; CFileItem *SzF; char sz_buffer[2048]; -// needed because there are no header files -.- -//#include -#define MAXFILES 1000 -#define MAXJOLIET 256 - -extern FILEENTRIES filelist[MAXFILES]; - -extern int selection; -extern int maxfiles; -extern int offset; - // the GC's dvd drive only supports offsets and length which are a multiply of 32 bytes // additionally the max length of a read is 2048 bytes // this function removes these limitations diff --git a/source/ngc/memcardop.c b/source/ngc/memcardop.c index 5301e56..4f623cc 100644 --- a/source/ngc/memcardop.c +++ b/source/ngc/memcardop.c @@ -22,10 +22,10 @@ #include "menu.h" #include "memcardop.h" #include "fileop.h" +#include "filesel.h" #define VERIFBUFFERSIZE 65536 static u8 SysArea[CARD_WORKAREA] ATTRIBUTE_ALIGN (32); -extern unsigned char savebuffer[]; unsigned char verifbuffer[VERIFBUFFERSIZE] ATTRIBUTE_ALIGN (32); card_dir CardDir; card_file CardFile; diff --git a/source/ngc/menu.c b/source/ngc/menu.c index 20ee2bd..f3a2a87 100644 --- a/source/ngc/menu.c +++ b/source/ngc/menu.c @@ -76,9 +76,6 @@ LoadManager () if ( loadROM == 1 ) // if ROM was loaded { - if(!GCMemROM()) // ROM was not valid - return 0; - // load the RAM if (GCSettings.AutoLoad == 1) LoadRAM(GCSettings.SaveMethod, SILENT); @@ -87,7 +84,6 @@ LoadManager () ResetNES(); } - return loadROM; } @@ -527,16 +523,17 @@ GetButtonMap(u16 ctrlr_type, char* btn_name) return pressed; } // end getButtonMap() -int cfg_btns_count = 9; +int cfg_btns_count = 10; char cfg_btns_menu[][50] = { - "B - ", - "A - ", - "SELECT - ", - "START - ", - "UP - ", - "DOWN - ", - "LEFT - ", - "RIGHT - ", + "B - ", + "A - ", + "SELECT - ", + "START - ", + "UP - ", + "DOWN - ", + "LEFT - ", + "RIGHT - ", + "VS INSERT COIN - " "Return to previous" }; @@ -583,7 +580,7 @@ ConfigureButtons (u16 ctrlr_type) while (quit == 0) { /*** Update Menu with Current ButtonMap ***/ - for (i=0; i<8; i++) // nes pad has 8 buttons to config (go thru them) + for (i=0; i