mirror of
https://github.com/dborth/snes9xgx.git
synced 2024-12-25 18:51:50 +01:00
SMB updates, menu tweaks
This commit is contained in:
parent
6b785b0b68
commit
30dc47b29d
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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] = {
|
||||
|
||||
int
|
||||
GameMenu ()
|
||||
{
|
||||
int gamemenuCount = 9;
|
||||
char gamemenu[][50] = {
|
||||
"Return to Game",
|
||||
"Reset Game",
|
||||
"ROM Information",
|
||||
"Cheats",
|
||||
"Load SRAM", "Save SRAM",
|
||||
"Load Freeze", "Save Freeze",
|
||||
"Load Game Snapshot", "Save Game Snapshot",
|
||||
"Back to Main Menu"
|
||||
};
|
||||
};
|
||||
|
||||
int
|
||||
GameMenu ()
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user