RAM save support, sound changes, code cleanup

This commit is contained in:
dborth 2008-09-06 03:30:42 +00:00
parent 7f7b2c2300
commit 6420f2178c
36 changed files with 299 additions and 95 deletions

View File

@ -17,6 +17,7 @@ SNES9x GX and Genesis Plus GX projects.
* Wiimote, Nunchuk, Classic, and Gamecube controller support
* 1-2 Player Support
* RAM and State saving
* Custom controller configurations
* SD, USB, DVD, SMB, GC Memory Card, and Zip support
* NES Compatibility Based on v0.98.12
@ -27,6 +28,16 @@ SNES9x GX and Genesis Plus GX projects.
|0O×øo· UPDATE HISTORY ·oø×O0|
`¨•¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨'
[What's New 2.0.1]
* 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
* RAM game save support! Now you can save your games just like the NES did.
By default game saves are saved/loaded automatically. This can be changed
in the Preferences menu
* Start/Select reversed mapping fixed for Wii controllers
* Small bug fixes / improvements / tweaks
[What's New 2.0.0]
* Complete rewrite based on code from SNES9x GX and Genesis Plus GX

View File

@ -46,7 +46,7 @@ static uint8 *trainerpoo=0;
static uint8 *ROM=NULL;
static uint8 *VROM=NULL;
static CartInfo iNESCart;
CartInfo iNESCart;
uint8 iNESMirroring;
uint16 iNESCHRBankList[8];

View File

@ -1,7 +0,0 @@
.rodata
.globl nesrom
nesromsize: .long 1048592
.balign 32
nesrom:
.incbin "../source/fceultra/rom/ROM.NES"

View File

@ -34,8 +34,8 @@ DefaultSettings ()
sprintf (GCSettings.LoadFolder,"fceugx/roms"); // Path to game files
sprintf (GCSettings.SaveFolder,"fceugx/saves"); // Path to save files
sprintf (GCSettings.CheatFolder,"fceugx/cheats"); // Path to cheat files
GCSettings.AutoLoad = 0;
GCSettings.AutoSave = 0;
GCSettings.AutoLoad = 1; // Auto Load RAM
GCSettings.AutoSave = 1; // Auto Save RAM
// default SMB settings
strncpy (GCSettings.smbip, "192.168.0.1", 15); // IP Address of share server

View File

@ -15,8 +15,8 @@
void DefaultSettings ();
#define VERSIONNUM "2.0.0"
#define VERSIONSTR "FCEUGX 2.0.0"
#define VERSIONNUM "2.0.1"
#define VERSIONSTR "FCE Ultra GX 2.0.1"
#define NOTSILENT 0
#define SILENT 1

View File

@ -36,32 +36,10 @@
extern bool romLoaded;
bool isWii;
/* Some timing-related variables. */
static int fullscreen=0;
static int genie=0;
static volatile int nofocus=0;
static volatile int userpause=0;
#define SO_FORCE8BIT 1
#define SO_SECONDARY 2
#define SO_GFOCUS 4
#define SO_D16VOL 8
#define GOO_DISABLESS 1 /* Disable screen saver when game is loaded. */
#define GOO_CONFIRMEXIT 2 /* Confirmation before exiting. */
#define GOO_POWERRESET 4 /* Confirm on power/reset. */
static int soundvolume=100;
static int soundquality=0;
static int soundo;
uint8 *xbsave=NULL;
int eoptions=EO_BGRUN | EO_FORCEISCALE;
extern int cleanSFMDATA();
extern void ResetNES(void);
long long basetime;
void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count);
@ -103,12 +81,10 @@ int main(int argc, char *argv[])
}
FCEUI_SetVidSystem(0); // 0 - NTSC, 1 - PAL
genie&=1;
FCEUI_SetGameGenie(genie);
fullscreen&=1;
soundo&=1;
FCEUI_SetSoundVolume(soundvolume);
FCEUI_SetSoundQuality(soundquality);
FCEUI_SetGameGenie(0); // 0 - OFF, 1 - ON
FCEUI_SetSoundVolume(100); // 0-100
FCEUI_SetSoundQuality(1); // 0 - low, 1 - high
cleanSFMDATA();
GCMemROM();
@ -188,4 +164,10 @@ void FCEUD_NetworkClose(void)
void FCEUD_NetplayText(uint8 *text)
{
}
/*
void FCEUI_SaveExtraDataUnderBase(int a);
If "a" is nonzero, save extra non-volatile game data(battery-backed
RAM) under FCE Ultra's base directory. Otherwise, the behavior is
to save it under the same directory the game is located in(this is
the default behavior).
*/

View File

@ -60,7 +60,7 @@ int GCMemROM()
/*** Set internal sound information ***/
FCEUI_Sound(SAMPLERATE);
FCEUI_SetSoundQuality(0);
FCEUI_SetSoundQuality(1);
FCEUI_SetSoundVolume(100);
FCEUI_SetLowPass(0);

171
source/ngc/fceuram.c Normal file
View File

@ -0,0 +1,171 @@
/****************************************************************************
* FCE Ultra 0.98.12
* Nintendo Wii/Gamecube Port
*
* Tantric September 2008
*
* fceustate.c
*
* Memory Based Load/Save RAM Manager
*
* These are the battery-backed RAM (save data) routines, brought together
* as GCxxxxx
* The original file I/O is replaced with Memory Read/Writes to the
* savebuffer below
****************************************************************************/
#include <gccore.h>
#include <string.h>
#include <malloc.h>
#include <fat.h>
#include <string.h>
#include "types.h"
#include "fceu.h"
#include "ppu.h"
#include "cart.h"
#include "memory.h"
#include "x6502.h"
#include "general.h"
#include "fceuconfig.h"
#include "intl.h"
#include "menudraw.h"
#include "filesel.h"
#include "memcardop.h"
#include "fileop.h"
#include "smbop.h"
extern u32 iNESGameCRC32;
extern CartInfo iNESCart;
extern unsigned char savebuffer[SAVEBUFFERSIZE];
extern char romFilename[];
int NGCFCEU_GameSave(CartInfo *LocalHWInfo, int operation)
{
int size = 0;
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0])
{
int x;
for(x=0;x<4;x++)
{
if(LocalHWInfo->SaveGame[x])
{
if(operation == 0) // save to file
{
memcpy(savebuffer, LocalHWInfo->SaveGame[x], LocalHWInfo->SaveGameLen[x]);
}
else // load from file
{
memcpy(LocalHWInfo->SaveGame[x], savebuffer, LocalHWInfo->SaveGameLen[x]);
}
size += LocalHWInfo->SaveGameLen[x];
}
}
}
return size;
}
bool SaveRAM (int method, bool silent)
{
ShowAction ((char*) "Saving...");
if(method == METHOD_AUTO)
method = autoSaveMethod();
bool retval = false;
char filepath[1024];
int datasize;
int offset = 0;
datasize = NGCFCEU_GameSave(&iNESCart, 0); // save game save to savebuffer
if ( datasize )
{
if(method == METHOD_SD || method == METHOD_USB)
{
if(ChangeFATInterface(method, NOTSILENT))
{
sprintf (filepath, "%s/%s/%s.sav", ROOTFATDIR, GCSettings.SaveFolder, romFilename);
offset = SaveBufferToFAT (filepath, datasize, silent);
}
}
else if(method == METHOD_SMB)
{
sprintf (filepath, "%s/%s.sav", GCSettings.SaveFolder, romFilename);
offset = SaveBufferToSMB (filepath, datasize, silent);
}
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
{
sprintf (filepath, "%08x.sav", iNESGameCRC32);
if(method == METHOD_MC_SLOTA)
offset = SaveBufferToMC (savebuffer, CARD_SLOTA, filepath, datasize, silent);
else
offset = SaveBufferToMC (savebuffer, CARD_SLOTB, filepath, datasize, silent);
}
if (offset > 0)
{
if ( !silent )
WaitPrompt((char *)"Save successful");
retval = true;
}
}
else
{
if ( !silent )
WaitPrompt((char *)"No data to save!");
}
return retval;
}
bool LoadRAM (int method, bool silent)
{
ShowAction ((char*) "Loading...");
if(method == METHOD_AUTO)
method = autoSaveMethod(); // we use 'Save' because we need R/W
char filepath[1024];
int offset = 0;
if(method == METHOD_SD || method == METHOD_USB)
{
ChangeFATInterface(method, NOTSILENT);
sprintf (filepath, "%s/%s/%s.sav", ROOTFATDIR, GCSettings.SaveFolder, romFilename);
offset = LoadBufferFromFAT (filepath, silent);
}
else if(method == METHOD_SMB)
{
sprintf (filepath, "%s/%s.sav", GCSettings.SaveFolder, romFilename);
offset = LoadSaveBufferFromSMB (filepath, silent);
}
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
{
sprintf (filepath, "%08x.sav", iNESGameCRC32);
if(method == METHOD_MC_SLOTA)
offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, filepath, silent);
else
offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, filepath, silent);
}
if (offset > 0)
{
NGCFCEU_GameSave(&iNESCart, 1); // load game save from savebuffer
ResetNES();
return 1;
}
// if we reached here, nothing was done!
if(!silent)
WaitPrompt ((char*) "Save file not found");
return 0;
}

13
source/ngc/fceuram.h Normal file
View File

@ -0,0 +1,13 @@
/****************************************************************************
* FCE Ultra 0.98.12
* Nintendo Wii/Gamecube Port
*
* Tantric September 2008
*
* fceuram.h
*
* Memory Based Load/Save RAM Manager
****************************************************************************/
bool SaveRAM (int method, bool silent);
bool LoadRAM (int method, bool silent);

View File

@ -325,7 +325,7 @@ bool LoadState (int method, bool silent)
ShowAction ((char*) "Loading...");
if(method == METHOD_AUTO)
method = autoSaveMethod(); // we use 'Save' because SRAM needs R/W
method = autoSaveMethod(); // we use 'Save' because we need R/W
char filepath[1024];
int offset = 0;

View File

@ -34,6 +34,7 @@
#include "fceustate.h"
#include "gcvideo.h"
#include "preferences.h"
#include "fceuram.h"
extern int GCMemROM();
extern void ResetNES(void);
@ -78,9 +79,13 @@ LoadManager ()
if(!GCMemROM()) // ROM was not valid
return 0;
// load the state
// load the RAM
if (GCSettings.AutoLoad == 1)
LoadRAM(GCSettings.SaveMethod, SILENT);
else
LoadState(GCSettings.SaveMethod, SILENT);
ResetNES();
}
return loadROM;
@ -276,10 +281,13 @@ PreferencesMenu ()
prefmenu[3][0] = '\0';
if (GCSettings.AutoLoad == 0) sprintf (prefmenu[4],"Auto Load OFF");
else if (GCSettings.AutoLoad == 1) sprintf (prefmenu[4],"Auto Load ON");
else if (GCSettings.AutoLoad == 1) sprintf (prefmenu[4],"Auto Load RAM");
else if (GCSettings.AutoLoad == 2) sprintf (prefmenu[4],"Auto Load STATE");
if (GCSettings.AutoSave == 0) sprintf (prefmenu[5],"Auto Save OFF");
else if (GCSettings.AutoSave == 1) sprintf (prefmenu[5],"Auto Save ON");
else if (GCSettings.AutoSave == 1) sprintf (prefmenu[5],"Auto Save RAM");
else if (GCSettings.AutoSave == 2) sprintf (prefmenu[5],"Auto Save STATE");
else if (GCSettings.AutoSave == 3) sprintf (prefmenu[5],"Auto Save BOTH");
sprintf (prefmenu[6], "Verify MC Saves %s",
GCSettings.VerifySaves == true ? " ON" : "OFF");
@ -304,13 +312,13 @@ PreferencesMenu ()
case 4:
GCSettings.AutoLoad ++;
if (GCSettings.AutoLoad > 1)
if (GCSettings.AutoLoad > 2)
GCSettings.AutoLoad = 0;
break;
case 5:
GCSettings.AutoSave ++;
if (GCSettings.AutoSave > 1)
if (GCSettings.AutoSave > 3)
GCSettings.AutoSave = 0;
break;
@ -339,11 +347,12 @@ PreferencesMenu ()
int
GameMenu ()
{
int gamemenuCount = 6;
int gamemenuCount = 8;
char gamemenu[][50] = {
"Return to Game",
"Reset Game",
"ROM Information",
"Load RAM", "Save RAM",
"Load State", "Save State",
"Back to Main Menu"
};
@ -355,12 +364,21 @@ GameMenu ()
while (quit == 0)
{
// disable state saving/loading if AUTO is on
if (GCSettings.AutoLoad == 1) // Auto Load State
// disable RAM/STATE saving/loading if AUTO is on
if (GCSettings.AutoLoad == 1) // Auto Load RAM
gamemenu[3][0] = '\0';
if (GCSettings.AutoSave == 1) // Auto Save State
else if (GCSettings.AutoLoad == 2) // Auto Load STATE
gamemenu[5][0] = '\0';
if (GCSettings.AutoSave == 1) // Auto Save RAM
gamemenu[4][0] = '\0';
else if (GCSettings.AutoSave == 2) // Auto Save STATE
gamemenu[6][0] = '\0';
else if (GCSettings.AutoSave == 3) // Auto Save BOTH
{
gamemenu[4][0] = '\0';
gamemenu[6][0] = '\0';
}
ret = RunMenu (gamemenu, gamemenuCount, (char*)"Game Menu", 20, -1);
@ -380,16 +398,24 @@ GameMenu ()
WaitButtonA ();
break;
case 3: // Load State
case 3: // Load RAM
quit = retval = LoadRAM(GCSettings.SaveMethod, NOTSILENT);
break;
case 4: // Save RAM
SaveRAM(GCSettings.SaveMethod, NOTSILENT);
break;
case 5: // Load State
quit = retval = LoadState(GCSettings.SaveMethod, NOTSILENT);
break;
case 4: // Save State
case 6: // Save State
SaveState(GCSettings.SaveMethod, NOTSILENT);
break;
case -1: // Button B
case 5: // Return to previous menu
case 7: // Return to previous menu
retval = 0;
quit = 1;
break;

View File

@ -20,6 +20,7 @@
#include <zlib.h>
#include FT_FREETYPE_H
#include "fceuconfig.h"
#include "gcvideo.h"
#include "menudraw.h"
#include "filesel.h"
@ -421,7 +422,7 @@ DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsiz
}
setfontsize (12);
DrawText (510, screenheight - 40, (char *)"FCEUGX 2.0.0");
DrawText (510, screenheight - 40, VERSIONSTR);
// Draw menu items

7
source/ngc/nesrom.s Normal file
View File

@ -0,0 +1,7 @@
.rodata
.globl nesrom
nesromsize: .long 1048592
.balign 32
nesrom:
.incbin "../source/ngc/rom/ROM.NES"