From 30dc47b29d6ac8cdccb882073edfddee86804d11 Mon Sep 17 00:00:00 2001 From: dborth Date: Wed, 13 Aug 2008 05:47:04 +0000 Subject: [PATCH] SMB updates, menu tweaks --- source/ngc/fileop.cpp | 5 ++-- source/ngc/freeze.cpp | 53 +++++++++++++++++++++-------------------- source/ngc/menu.cpp | 48 +++++++++++++++++++++++++++---------- source/ngc/smbop.cpp | 38 ++++++++++++++++------------- source/ngc/smbop.h | 1 + source/ngc/snes9xGX.cpp | 13 ++++------ source/ngc/unzip.cpp | 11 ++------- 7 files changed, 93 insertions(+), 76 deletions(-) diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index 1b11e18..bdf0b9c 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -235,6 +235,8 @@ LoadBufferFromFAT (char *filepath, bool silent) int boffset = 0; int read = 0; + ClearSaveBuffer (); + handle = fopen (filepath, "rb"); if (handle <= 0) @@ -248,8 +250,6 @@ LoadBufferFromFAT (char *filepath, bool silent) return 0; } - memset (savebuffer, 0, 0x22000); - /*** This is really nice, just load the file and decode it ***/ while ((read = fread (savebuffer + boffset, 1, 1024, handle)) > 0) { @@ -285,5 +285,6 @@ SaveBufferToFAT (char *filepath, int datasize, bool silent) fclose (handle); } + ClearSaveBuffer (); return datasize; } diff --git a/source/ngc/freeze.cpp b/source/ngc/freeze.cpp index 0d3e1dd..70c6e0f 100644 --- a/source/ngc/freeze.cpp +++ b/source/ngc/freeze.cpp @@ -139,6 +139,8 @@ NGCFreezeGame (int method, bool8 silent) S9xPrepareSoundForSnapshotSave (FALSE); NGCFreezeMemBuffer (); // copy freeze mem into membuffer + + ClearSaveBuffer (); memcpy (savebuffer, membuffer, bufoffset); S9xPrepareSoundForSnapshotSave (TRUE); @@ -164,17 +166,17 @@ NGCFreezeGame (int method, bool8 silent) ClearSaveBuffer (); /*** Copy in save icon ***/ - int offset = sizeof (saveicon); - memcpy (savebuffer, saveicon, offset); + int woffset = sizeof (saveicon); + memcpy (savebuffer, saveicon, woffset); /*** And the freezecomment ***/ sprintf (freezecomment[1], "%s", Memory.ROMFilename); - memcpy (savebuffer + offset, freezecomment, 64); - offset += 64; + memcpy (savebuffer + woffset, freezecomment, 64); + woffset += 64; /*** Zip and copy in the freeze ***/ uLongf DestBuffSize = (uLongf) SAVEBUFFERSIZE; - int err= compress2((Bytef*)(savebuffer+offset+8), (uLongf*)&DestBuffSize, (const Bytef*)membuffer, (uLongf)bufoffset, Z_BEST_COMPRESSION); + int err= compress2((Bytef*)(savebuffer+woffset+8), (uLongf*)&DestBuffSize, (const Bytef*)membuffer, (uLongf)bufoffset, Z_BEST_COMPRESSION); if(err!=Z_OK) { @@ -184,27 +186,19 @@ NGCFreezeGame (int method, bool8 silent) } int zippedsize = (int)DestBuffSize; - memcpy (savebuffer + offset, &zippedsize, 4); - offset += 4; + memcpy (savebuffer + woffset, &zippedsize, 4); + woffset += 4; int decompressedsize = (int)bufoffset; - memcpy (savebuffer + offset, &decompressedsize, 4); - offset += 4; + memcpy (savebuffer + woffset, &decompressedsize, 4); + woffset += 4; - offset += zippedsize; - - int ret; + woffset += zippedsize; if(method == METHOD_MC_SLOTA) - ret = SaveBufferToMC ( savebuffer, CARD_SLOTA, filename, offset, SILENT ); + offset = SaveBufferToMC ( savebuffer, CARD_SLOTA, filename, woffset, SILENT ); else - ret = SaveBufferToMC ( savebuffer, CARD_SLOTB, filename, offset, SILENT ); - - if ( ret && !silent ) - { - sprintf (filename, "Written %d bytes", ret); - WaitPrompt (filename); - } + offset = SaveBufferToMC ( savebuffer, CARD_SLOTB, filename, woffset, SILENT ); } if(offset > 0) // save successful! @@ -289,12 +283,14 @@ NGCUnfreezeGame (int method, bool8 silent) int ret = 0; if(method == METHOD_MC_SLOTA) - LoadBufferFromMC ( savebuffer, CARD_SLOTA, filename, silent ); + ret = LoadBufferFromMC ( savebuffer, CARD_SLOTA, filename, silent ); else - LoadBufferFromMC ( savebuffer, CARD_SLOTB, filename, silent ); + ret = LoadBufferFromMC ( savebuffer, CARD_SLOTB, filename, silent ); - if ( ret ) + if (ret) { + char zipbuffer[MEMBUFFER]; + // skip the saveicon and comment offset = (sizeof(saveicon) + 64); uLongf zipsize = 0; @@ -309,7 +305,7 @@ NGCUnfreezeGame (int method, bool8 silent) memset(membuffer, 0, MEMBUFFER); uLongf DestBuffSize = MEMBUFFER; - int err= uncompress((Bytef*)membuffer, (uLongf*)&DestBuffSize, (const Bytef*)(savebuffer + offset), zipsize); + int err= uncompress((Bytef*)zipbuffer, (uLongf*)&DestBuffSize, (const Bytef*)(savebuffer + offset), zipsize); if ( err!=Z_OK ) { @@ -317,18 +313,23 @@ NGCUnfreezeGame (int method, bool8 silent) WaitPrompt (msg); return 0; } - - if ( DestBuffSize != decompressedsize ) + else if ( DestBuffSize != decompressedsize ) { WaitPrompt((char*) "Unzipped size doesn't match expected size!"); return 0; } + else + { + offset = MEMBUFFER; + memcpy (savebuffer, zipbuffer, MEMBUFFER); + } } } if(offset > 0) { memcpy (membuffer, savebuffer, offset); + ClearSaveBuffer (); if (S9xUnfreezeGame ("AGAME") == SUCCESS) return 1; diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index d12ea08..ac36f1b 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -188,11 +188,11 @@ PreferencesMenu () if (GCSettings.AutoLoad == 0) sprintf (prefmenu[4],"Auto Load OFF"); else if (GCSettings.AutoLoad == 1) sprintf (prefmenu[4],"Auto Load SRAM"); - else if (GCSettings.AutoLoad == 2) sprintf (prefmenu[4],"Auto Load FREEZE"); + else if (GCSettings.AutoLoad == 2) sprintf (prefmenu[4],"Auto Load SNAPSHOT"); if (GCSettings.AutoSave == 0) sprintf (prefmenu[5],"Auto Save OFF"); else if (GCSettings.AutoSave == 1) sprintf (prefmenu[5],"Auto Save SRAM"); - else if (GCSettings.AutoSave == 2) sprintf (prefmenu[5],"Auto Save FREEZE"); + else if (GCSettings.AutoSave == 2) sprintf (prefmenu[5],"Auto Save SNAPSHOT"); else if (GCSettings.AutoSave == 3) sprintf (prefmenu[5],"Auto Save BOTH"); sprintf (prefmenu[6], "Verify MC Saves %s", @@ -332,20 +332,21 @@ void CheatMenu() /**************************************************************************** * Game Options Menu ****************************************************************************/ -static int gamemenuCount = 9; -static char gamemenu[][50] = { - "Return to Game", - "Reset Game", - "ROM Information", - "Cheats", - "Load SRAM", "Save SRAM", - "Load Freeze", "Save Freeze", - "Back to Main Menu" -}; int GameMenu () { + int gamemenuCount = 9; + char gamemenu[][50] = { + "Return to Game", + "Reset Game", + "ROM Information", + "Cheats", + "Load SRAM", "Save SRAM", + "Load Game Snapshot", "Save Game Snapshot", + "Back to Main Menu" + }; + int ret, retval = 0; int quit = 0; int oldmenu = menu; @@ -353,7 +354,28 @@ GameMenu () while (quit == 0) { - ret = RunMenu (gamemenu, gamemenuCount, (char*)"Game Options"); + // disable SRAM/SNAPSHOT saving/loading if AUTO is on + + if (GCSettings.AutoLoad == 1) // Auto Load SRAM + gamemenu[4][0] = '\0'; + else if (GCSettings.AutoLoad == 2) // Auto Load SNAPSHOT + gamemenu[6][0] = '\0'; + + if (GCSettings.AutoSave == 1) // Auto Save SRAM + gamemenu[5][0] = '\0'; + else if (GCSettings.AutoSave == 2) // Auto Save SNAPSHOT + gamemenu[7][0] = '\0'; + else if (GCSettings.AutoSave == 3) // Auto Save BOTH + { + gamemenu[5][0] = '\0'; + gamemenu[7][0] = '\0'; + } + + // hide cheats menu if cheats file not present + if(Cheat.num_cheats == 0) + gamemenu[3][0] = '\0'; + + ret = RunMenu (gamemenu, gamemenuCount, (char*)"Game Menu"); switch (ret) { diff --git a/source/ngc/smbop.cpp b/source/ngc/smbop.cpp index 5cd500e..8d3b5f3 100644 --- a/source/ngc/smbop.cpp +++ b/source/ngc/smbop.cpp @@ -226,14 +226,17 @@ LoadSMBFile (char *filename, int length) return -1; } - boffset = LoadBufferFromSMB(SMBPath(filepath), NOTSILENT); + boffset = LoadBufferFromSMB((char *)rbuffer, SMBPath(filepath), NOTSILENT); if(boffset > 0) { - if(IsZipFile ((char *)savebuffer)) - return UnZipBuffer(rbuffer, savebuffer); - else - memcpy (rbuffer, savebuffer, boffset); + if(IsZipFile ((char *)rbuffer)) + { + //return UnZipBuffer(rbuffer, 0, 2, NULL); + // UNZIP currently crashes - FIX ME + WaitPrompt((char*) "Zipped files are currently not supported!"); + return -1; + } } return boffset; } @@ -270,10 +273,7 @@ SaveBufferToSMB (char *filepath, int datasize, bool8 silent) boffset += wrote; dsize -= wrote; } - SMB_CloseFile (smbfile); - - return boffset; } else { @@ -282,7 +282,8 @@ SaveBufferToSMB (char *filepath, int datasize, bool8 silent) WaitPrompt (msg); } - return 0; + ClearSaveBuffer (); + return boffset; } /**************************************************************************** @@ -290,13 +291,20 @@ SaveBufferToSMB (char *filepath, int datasize, bool8 silent) ****************************************************************************/ int LoadBufferFromSMB (char *filepath, bool8 silent) +{ + ClearSaveBuffer (); + return LoadBufferFromSMB((char *)savebuffer, filepath, silent); +} + +int +LoadBufferFromSMB (char * sbuffer, char *filepath, bool8 silent) { if(!ConnectShare (NOTSILENT)) return 0; SMBFILE smbfile; int ret; - int offset = 0; + int boffset = 0; smbfile = SMB_OpenFile (SMBPath(filepath), SMB_OPEN_READING, SMB_OF_OPEN, smbconn); @@ -312,14 +320,10 @@ LoadBufferFromSMB (char *filepath, bool8 silent) return 0; } - memset (savebuffer, 0, 0x22000); - - while ((ret = - SMB_ReadFile ((char *) savebuffer + offset, 1024, offset, - smbfile)) > 0) - offset += ret; + while ((ret = SMB_ReadFile (sbuffer + boffset, 1024, boffset, smbfile)) > 0) + boffset += ret; SMB_CloseFile (smbfile); - return offset; + return boffset; } diff --git a/source/ngc/smbop.h b/source/ngc/smbop.h index c759d00..1989252 100644 --- a/source/ngc/smbop.h +++ b/source/ngc/smbop.h @@ -22,6 +22,7 @@ int UpdateSMBdirname(); int ParseSMBdirectory (); int LoadSMBFile (char *filename, int length); int LoadBufferFromSMB (char *filepath, bool8 silent); +int LoadBufferFromSMB (char * sbuffer, char *filepath, bool8 silent); int SaveBufferToSMB (char *filepath, int datasize, bool8 silent); #endif diff --git a/source/ngc/snes9xGX.cpp b/source/ngc/snes9xGX.cpp index 2ad143e..a3b5c8d 100644 --- a/source/ngc/snes9xGX.cpp +++ b/source/ngc/snes9xGX.cpp @@ -595,14 +595,6 @@ NGCReportButtons () } mainmenu (3); // go to game menu - FrameTimer = 0; - ConfigRequested = 0; - - setFrameTimerMethod(); // set frametimer method every time a ROM is loaded - - S9xReportControllers(); // FIX - - } else { @@ -803,7 +795,10 @@ emulate () AudioStart (); S9xInitSync(); - setFrameTimerMethod(); // also called in NGCReportButtons() + FrameTimer = 0; + ConfigRequested = 0; + setFrameTimerMethod(); // set frametimer method every time a ROM is loaded + S9xReportControllers(); // FIX while (1) { diff --git a/source/ngc/unzip.cpp b/source/ngc/unzip.cpp index 5832b29..72c9a68 100644 --- a/source/ngc/unzip.cpp +++ b/source/ngc/unzip.cpp @@ -73,13 +73,6 @@ IsZipFile (char *buffer) * * It should be noted that there is a limit of 5MB total size for any ROM ******************************************************************************/ -unsigned char * uzipbuffer; - -int UnZipBuffer(unsigned char *outbuffer, unsigned char *inbuffer) -{ - uzipbuffer = inbuffer; - return UnZipBuffer(outbuffer, 0, 2, NULL); -} int UnZipBuffer (unsigned char *outbuffer, u64 inoffset, short where, FILE* filehandle) @@ -108,7 +101,7 @@ UnZipBuffer (unsigned char *outbuffer, u64 inoffset, short where, FILE* filehand break; case 2: // From buffer - memcpy(readbuffer, uzipbuffer, 2048); + memcpy(readbuffer, outbuffer, 2048); break; } @@ -186,7 +179,7 @@ UnZipBuffer (unsigned char *outbuffer, u64 inoffset, short where, FILE* filehand case 2: // From buffer inoffset += 2048; - memcpy(readbuffer, uzipbuffer+inoffset, 2048); + memcpy(readbuffer, outbuffer+inoffset, 2048); break; } }