fix typo; add save/load settings; auto-loads from WiiSD (or SDGecko slot A in GC mode) at start... for now

This commit is contained in:
dsbomb 2008-05-11 13:54:17 +00:00
parent ee9e70a4c6
commit b3365acc4b
9 changed files with 548 additions and 163 deletions

View File

@ -55,17 +55,13 @@ extern unsigned char *nesromptr;
extern int IsXenoGCImage( char *buffer );
void GetSDInfo ();
extern int ChosenSlot;
/*extern void ClearScreen();
int LoadDVDFile( unsigned char *buffer );
extern int unzipDVDFile( unsigned char *outbuffer, unsigned int discoffset, unsigned int length);
extern int CentreTextPosition( char *text );*/
extern u8 ChosenSlot;
/** true if we the emulator is running on a wii **/
extern bool isWii;
int UseSDCARD = 0;
int UseWiiSDCARD = 0;
extern int WiiSD_Available;
u8 UseSDCARD = 0;
u8 UseWiiSDCARD = 0;
sd_file * filehandle = NULL;
char rootSDdir[SDCARD_MAX_PATH_LEN];
char rootWiiSDdir[SDCARD_MAX_PATH_LEN];
@ -635,7 +631,7 @@ void ShowFiles( int offset, int selection ) {
* Let user select another ROM to load
****************************************************************************/
bool inSz = false;
extern int PADCAL;
extern u8 PADCAL;
void FileSelector() {
short p;
@ -900,6 +896,12 @@ int OpenWiiSD () {
haveSDdir = 0;
char msg[128];
/*if (WiiSD_Available == 0) {
sprintf(msg, "Insert SD card: %d\n", WiiSD_Available);
WaitPrompt(msg);
//return 0;
}*/
memset(&vfs, 0, sizeof(VFATFS));
if (haveWiiSDdir == 0) {
/* don't mess with DVD entries */
@ -926,7 +928,8 @@ int OpenWiiSD () {
FileSelector ();
/* memorize last entries list, actual root directory and selection for next access */
haveWiiSDdir = 1;
/* TODO: Bugged, do not activate cached dir listing
haveWiiSDdir = 1;*/
} else {
/* no entries found */
sprintf (msg, "Error reading %s", rootWiiSDdir);

View File

@ -18,14 +18,14 @@
#include <sdcard.h>
#ifdef HW_RVL
#include "wiisd/tff.h"
#include "wiisd/vfat.h"
extern VFATFS vfs;
extern FSDIRENTRY vfsfile;
extern int UseWiiSDCARD;
extern u8 UseWiiSDCARD;
#endif
extern sd_file *filehandle;
extern int UseSDCARD;
extern u8 UseSDCARD;
extern void ShowAction( char *msg );
extern void WaitPrompt( char *msg );

View File

@ -16,46 +16,35 @@
#define JOY_UP 0x10
#define JOY_DOWN 0x20
static int currpal = 0;
static int timing = 0;
static int FSDisable = 1;
static int slimit = 1;
extern int scrollerx;
u8 currpal = 0;
u8 timing = 0;
u8 FSDisable = 1;
u8 slimit = 1;
extern void FCEUI_DisableSpriteLimitation( int a );
extern void FCEUD_SetPalette(unsigned char index, unsigned char r, unsigned char g, unsigned char b);
extern void FCEU_ResetPalette(void);
extern void WaitPrompt( char *text );
//extern void MCManage( int mode );
extern void ManageState(int mode, int slot, int device);
extern void ManageSettings(int mode, int slot, int device, int quiet);
extern void StartGX();
extern signed int CARDSLOT;
extern int PADCAL;
extern int PADTUR;
extern void scroller(int y, unsigned char text[][512], int nlines);
extern void FCEUI_DisableFourScore(int a);
extern int line;
extern char backdrop[640 * 480 * 2];
extern int UseSDCARD;
extern unsigned char DecodeJoy( unsigned short pp );
extern unsigned char GetAnalog(int Joy);
extern signed int CARDSLOT;
extern u8 PADCAL;
extern u8 PADTUR;
extern int line;
extern char backdrop[640 * 480 * 2];
extern u8 UseSDCARD;
extern int scrollerx;
#ifdef HW_RVL
void (*PSOReload)() = (void(*)())0x90000020;
void (*Reload)() = (void(*)())0x90000020;
#else
void (*PSOReload)() = (void(*)())0x80001800;
void (*Reload)() = (void(*)())0x80001800;
#endif
void Reboot() {
@ -72,7 +61,7 @@ void Reboot() {
#define SCROLLY 395
/* color palettes */
struct {
struct st_palettes {
char *name, *desc;
unsigned int data[64];
} palettes[] = {
@ -301,7 +290,7 @@ extern unsigned int *xfb[2];
extern GXRModeObj *vmode;
extern int font_size[256];
extern int font_height;
extern int screenscaler;
extern u8 screenscaler;
/****************************************************************************
* SetScreen
@ -391,9 +380,7 @@ char PADMap( int padvalue, int padnum ) {
*
* This screen simply let's the user swap A/B/X/Y around.
****************************************************************************/
char mpads[6] = { 0, 1, 2, 3, 4, 5 };
int PADCON = 0;
u8 mpads[6] = { 0, 1, 4, 5, 2, 3 };
void ConfigPAD() {
int PadMenuCount = 10;
char PadMenu[10][MENU_STRING_LENGTH] = {
@ -510,8 +497,16 @@ char SdSlots[3][10] = {
enum SLOTS {
SLOT_A, SLOT_B, SLOT_WIISD
};
int ChosenSlot = 0;
int ChosenDevice = 1;
enum DEVICES {
MEMCARD, SDCARD
};
#ifdef HW_RVL
u8 ChosenSlot = SLOT_WIISD;
#else
u8 ChosenSlot = SLOT_A;
#endif
u8 ChosenDevice = SDCARD;
int StateManager() {
int SaveMenuCount = 5;
@ -542,9 +537,9 @@ int StateManager() {
while ( quit == 0 ) {
if ( redraw ) {
sprintf(SaveMenu[SAVE_SLOT], "%s: %s", ChosenDevice ? "SDCard" : "MemCard",
sprintf(SaveMenu[SAVE_SLOT], "%s: %s", (ChosenDevice == SDCARD) ? "SDCard" : "MemCard",
SdSlots[ChosenSlot]);
sprintf(SaveMenu[SAVE_DEVICE], MENU_SAVE_DEVICE ": %s", ChosenDevice ? "SDCard" : "MemCard");
sprintf(SaveMenu[SAVE_DEVICE], MENU_SAVE_DEVICE ": %s", (ChosenDevice == SDCARD) ? "SDCard" : "MemCard");
DrawMenu(MENU_SAVE_TITLE, SaveMenu, SaveMenuCount, ChosenMenu);
redraw = 0;
}
@ -629,15 +624,17 @@ int StateManager() {
* Video Enhancement Screen
****************************************************************************/
int VideoEnhancements() {
int VideoMenuCount = 5;
char VideoMenu[5][MENU_STRING_LENGTH] = {
int VideoMenuCount = 7;
char VideoMenu[7][MENU_STRING_LENGTH] = {
{ MENU_VIDEO_SCALER }, { MENU_VIDEO_PALETTE },
{ MENU_VIDEO_SPRITE }, { MENU_VIDEO_TIMING },
{ MENU_VIDEO_SAVE }, { MENU_VIDEO_LOAD },
{ MENU_EXIT }
};
enum VIDEO_MENU {
VIDEO_SCALER, VIDEO_PALETTE,
VIDEO_SPRITE, VIDEO_TIMING,
VIDEO_SAVE, VIDEO_LOAD,
VIDEO_EXIT
};
unsigned char VideoMenuText[][512] = {
@ -704,7 +701,6 @@ int VideoEnhancements() {
FCEUD_SetPalette( i+64, r, g, b);
FCEUD_SetPalette( i+128, r, g, b);
FCEUD_SetPalette( i+192, r, g, b);
}
}
break;
@ -719,6 +715,14 @@ int VideoEnhancements() {
FCEUI_SetVidSystem( timing );
break;
case VIDEO_SAVE:
ManageSettings(0, ChosenSlot, ChosenDevice, 0);
break;
case VIDEO_LOAD:
ManageSettings(1, ChosenSlot, ChosenDevice, 0);
break;
case VIDEO_EXIT:
quit = 1;
break;
@ -828,7 +832,6 @@ int MediaSelect() {
#ifdef HW_RVL
strcpy(MediaMenu[MEDIA_DVD], MediaMenu[MEDIA_EXIT]);
MediaMenuCount = 3;
ChosenSlot = SLOT_WIISD; // default to WiiSD
#else
SdSlotCount = 2;
#endif
@ -876,6 +879,7 @@ int MediaSelect() {
#else
UseSDCARD = 0; //DVD
OpenDVD();
ChosenDevice = 1; // Memcard
return 1;
#endif
break;
@ -1075,7 +1079,7 @@ int MainMenu() {
break;
case MAIN_RELOAD:
PSOReload();
Reload();
break;
case MAIN_REBOOT:
@ -1101,7 +1105,6 @@ int MainMenu() {
scroller(SCROLLY, MainMenuText, 7);
VIDEO_WaitVSync();
}
/*** Remove any still held buttons ***/

View File

@ -80,6 +80,8 @@
#define MENU_VIDEO_PALETTE "Palette"
#define MENU_VIDEO_SPRITE "8 Sprite Maximum"
#define MENU_VIDEO_TIMING "Timing"
#define MENU_VIDEO_SAVE "Save Settings"
#define MENU_VIDEO_LOAD "Load Settings"
#define MENU_VIDEO_DEFAULT "Normaal"
#define MENU_VIDEO_TEXT1 "Wow, deze kleuren en vormen zijn zeker mooi, Brengt terug de herideringen."
#define MENU_VIDEO_TEXT2 "Wees zeker niet met deze instellingen kloten, Je wilt niet deze ervaringen verkloten! :D"

View File

@ -80,6 +80,8 @@
#define MENU_VIDEO_PALETTE "Palette"
#define MENU_VIDEO_SPRITE "8 Sprite Limit"
#define MENU_VIDEO_TIMING "Timing"
#define MENU_VIDEO_SAVE "Save Settings"
#define MENU_VIDEO_LOAD "Load Settings"
#define MENU_VIDEO_DEFAULT "Default"
#define MENU_VIDEO_TEXT1 "Wow, these colors and shapes sure are beautiful, brings back the memories."
#define MENU_VIDEO_TEXT2 "Be sure not to mess these settings up, You don't want to ruin the experience! :D"

View File

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <sys/time.h>
#include <gctypes.h>
#include <ogc/system.h>
#include "../../types.h"
#include "common.h"
@ -25,8 +26,7 @@ static volatile int userpause=0;
static int soundvolume=100;
static int soundquality=0;
static int soundo;
int screenscaler = 2;
u8 screenscaler = 2;
uint8 *xbsave=NULL;
int eoptions=EO_BGRUN | EO_FORCEISCALE;
@ -44,19 +44,31 @@ extern void PlaySound( void *Buf, int samples );
long long basetime;
void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count);
extern void ManageSettings(int mode, int slot, int device, int quiet);
extern u8 ChosenSlot;
extern u8 ChosenDevice;
extern void *PSOReload();
extern void *Reload();
extern void Reboot();
static void reset_cb() {
PSOReload();
Reload();
}
/*static int power_hit = 0;
static void power_cb() {
//Reboot();
//SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
power_hit = 1;
}*/
extern int WaitPromptChoice (char *msg, char *bmsg, char *amsg);
bool isWii = false;
static unsigned char *inquiry=(unsigned char *)0x80000004;
int main(int argc, char *argv[]) {
initDisplay();
SYS_SetResetCallback (reset_cb);
SYS_SetResetCallback(reset_cb);
//SYS_SetPowerCallback(power_cb);
InitialiseSound();
SDCARD_Init ();
@ -88,6 +100,8 @@ int main(int argc, char *argv[]) {
cleanSFMDATA();
GCMemROM();
// Load settings
ManageSettings(1, ChosenSlot, ChosenDevice, 1);
MainMenu();
while (1) {
@ -98,6 +112,9 @@ int main(int argc, char *argv[]) {
FCEUI_Emulate(&gfx, &sound, &ssize, 0);
xbsave = gfx;
FCEUD_Update(gfx, sound, ssize);
/*if (power_hit)
//SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
Reboot();*/
}
return 0;

View File

@ -8,12 +8,17 @@
#include <gccore.h>
#include <string.h>
#include <sdcard.h>
#include <malloc.h>
#include "../../types.h"
#include "../../state.h"
#include "saveicon.h"
#include "intl.h"
#ifdef HW_RVL
#include "wiisd/tff.h"
#include "wiisd/integer.h"
FATFS frontfs;
FILINFO finfo;
#endif
#define FCEUDIR "fceu"
#define SAVEDIR "saves"
@ -24,6 +29,9 @@ extern void FCEUSND_SaveState(void);
extern void WaitPrompt( char *text );
extern void FlipByteOrder(uint8 *src, uint32 count);
extern void ShowAction( char *text );
extern void FCEUD_SetPalette(unsigned char index, unsigned char r, unsigned char g, unsigned char b);
extern void FCEU_ResetPalette(void);
extern void FCEUI_DisableSpriteLimitation( int a );
/*** External save structures ***/
extern SFORMAT SFCPU[];
@ -43,12 +51,23 @@ int sboffset; /*** Used as a basic fileptr ***/
int mcversion = 0x981211;
static u8 SysArea[CARD_WORKAREA] ATTRIBUTE_ALIGN(32);
#ifdef HW_RVL
FATFS frontfs;
FILINFO finfo;
#endif
extern int ChosenSlot;
extern int ChosenDevice;
extern u8 ChosenSlot;
extern u8 ChosenDevice;
extern u8 screenscaler;
extern u8 currpal;
extern u8 slimit;
extern u8 timing;
extern u8 mpads[6];
extern u8 FSDisable;
extern u8 PADCAL;
extern u8 PADTUR;
extern u8 UseSDCARD;
extern u8 UseWiiSDCARD;
extern struct st_palettes {
char *name, *desc;
unsigned int data[64];
} *palettes;
/****************************************************************************
* Memory based file functions
****************************************************************************/
@ -248,7 +267,7 @@ int GCFCEUSS_Save()
static unsigned char header[16] = "FCS\xff";
char chunk[] = "CHKE";
int zero = 0;
char Comment[2][32] = { { "FCEU GC Version 1.0.9" }, { "A GAME" } };
char Comment[2][100] = { { MENU_CREDITS_TITLE }, { "A GAME" } };
memopen(); /*** Reset Memory File ***/
@ -347,8 +366,7 @@ int MountTheCard()
*
* This is based on the code from libogc
****************************************************************************/
void MCManage(int mode, int slot) {
void MC_ManageState(int mode, int slot) {
char mcFilename[80];
int CardError;
card_dir CardDir;
@ -370,115 +388,108 @@ void MCManage(int mode, int slot) {
/*** Try for memory card in slot A ***/
CardError = MountTheCard();
if ( CardError >= 0 )
{
if ( CardError >= 0 ) {
/*** Get card sector size ***/
CardError = CARD_GetSectorSize(CARDSLOT, &SectorSize);
switch ( mode ) {
case 0 : { /*** Save Game ***/
/*** Look for this file ***/
CardError = CARD_FindFirst(CARDSLOT, &CardDir, true);
/*** Look for this file ***/
CardError = CARD_FindFirst(CARDSLOT, &CardDir, true);
found = 0;
found = 0;
card_stat CardStatus;
while ( CardError != CARD_ERROR_NOFILE ) {
CardError = CARD_FindNext(&CardDir);
if ( strcmp(CardDir.filename, mcFilename) == 0 )
found = 1;
}
card_stat CardStatus;
while ( CardError != CARD_ERROR_NOFILE )
{
CardError = CARD_FindNext(&CardDir);
if ( strcmp(CardDir.filename, mcFilename) == 0 )
found = 1;
}
/*** Determine number of sectors required ***/
savedBytes = actualSize = GCFCEUSS_Save();
sprintf(debug, "Saving in MC ...");
ShowAction(debug);
/*** Determine number of sectors required ***/
savedBytes = actualSize = GCFCEUSS_Save();
sprintf(debug, "Saving in MC ...");
ShowAction(debug);
FileSize = ( actualSize / SectorSize ) * SectorSize;
if ( actualSize % SectorSize )
FileSize += SectorSize;
FileSize = ( actualSize / SectorSize ) * SectorSize;
if ( actualSize % SectorSize )
FileSize += SectorSize;
/*** Now write the file out ***/
if ( !found )
CardError = CARD_Create(CARDSLOT, mcFilename, FileSize, &CardFile);
else
CardError = CARD_Open(CARDSLOT, mcFilename, &CardFile);
/*** Now write the file out ***/
if ( !found )
CardError = CARD_Create(CARDSLOT, mcFilename, FileSize, &CardFile);
else
CardError = CARD_Open(CARDSLOT, mcFilename, &CardFile);
CARD_GetStatus( CARDSLOT, CardFile.filenum, &CardStatus);
CardStatus.icon_addr = 0;
CardStatus.icon_fmt = 2;
CardStatus.icon_speed = 1;
CardStatus.comment_addr = sizeof(saveicon);
CARD_SetStatus( CARDSLOT, CardFile.filenum, &CardStatus);
/*** Haha! libogc only write one block at a time! ***/
if ( CardError == 0 )
{
int sbo = 0;
while ( actualSize > 0 )
{
CardError = CARD_Write(&CardFile, &statebuffer[sbo], SectorSize, sbo );
actualSize -= SectorSize;
sbo += SectorSize;
}
CardError = CARD_Close(&CardFile);
sprintf(debug, "Saved %d bytes successfully!", savedBytes);
ShowAction(debug);
}
else WaitPrompt("Save Failed!");
CARD_Unmount(CARDSLOT);
CARD_GetStatus( CARDSLOT, CardFile.filenum, &CardStatus);
CardStatus.icon_addr = 0;
CardStatus.icon_fmt = 2;
CardStatus.icon_speed = 1;
CardStatus.comment_addr = sizeof(saveicon);
CARD_SetStatus( CARDSLOT, CardFile.filenum, &CardStatus);
/*** Haha! libogc only write one block at a time! ***/
if ( CardError == 0 ) {
int sbo = 0;
while ( actualSize > 0 ) {
CardError = CARD_Write(&CardFile, &statebuffer[sbo], SectorSize, sbo );
actualSize -= SectorSize;
sbo += SectorSize;
}
break; /*** End save ***/
CardError = CARD_Close(&CardFile);
sprintf(debug, "Saved %d bytes successfully!", savedBytes);
ShowAction(debug);
}
else {
WaitPrompt("Save Failed");
}
CARD_Unmount(CARDSLOT);
}
break; /*** End save ***/
case 1: { /*** Load state ***/
/*** Look for this file ***/
CardError = CARD_FindFirst(CARDSLOT, &CardDir, true);
memopen(); /*** Clear the buffer ***/
found = 0;
/*** Look for this file ***/
CardError = CARD_FindFirst(CARDSLOT, &CardDir, true);
memopen(); /*** Clear the buffer ***/
found = 0;
while ( CardError != CARD_ERROR_NOFILE ) {
CardError = CARD_FindNext(&CardDir);
if ( strcmp(CardDir.filename, mcFilename) == 0 )
found = 1;
}
while ( CardError != CARD_ERROR_NOFILE ) {
CardError = CARD_FindNext(&CardDir);
if ( strcmp(CardDir.filename, mcFilename) == 0 )
found = 1;
}
if ( found == 0 ) {
WaitPrompt("No Save Game Found");
CARD_Unmount(CARDSLOT);
return;
}
if ( found == 0 ) {
WaitPrompt("No Save Game Found");
CARD_Unmount(CARDSLOT);
return;
}
/*** Load the file into memory ***/
CardError = CARD_Open(CARDSLOT, mcFilename, &CardFile);
CardError = CARD_Read(&CardFile, &statebuffer, SectorSize, 0);
/*** Load the file into memory ***/
CardError = CARD_Open(CARDSLOT, mcFilename, &CardFile);
CardError = CARD_Read(&CardFile, &statebuffer, SectorSize, 0);
/*** Get actual size of the file ***/
memcpy(&actualSize, &statebuffer[FILESIZEOFFSET], 4);
savedBytes = actualSize;
/*** Get actual size of the file ***/
memcpy(&actualSize, &statebuffer[FILESIZEOFFSET], 4);
savedBytes = actualSize;
int sbo = SectorSize;
actualSize -= SectorSize;
while( actualSize > 0 ) {
CARD_Read(&CardFile, &statebuffer[sbo], SectorSize, sbo);
actualSize -= SectorSize;
sbo += SectorSize;
}
CARD_Close(&CardFile);
int sbo = SectorSize;
actualSize -= SectorSize;
while( actualSize > 0 ) {
CARD_Read(&CardFile, &statebuffer[sbo], SectorSize, sbo);
actualSize -= SectorSize;
sbo += SectorSize;
}
CARD_Close(&CardFile);
/*** Finally, do load ***/
GCFCEUSS_Load();
/*** Finally, do load ***/
GCFCEUSS_Load();
CARD_Unmount(CARDSLOT);
sprintf(debug, "Loaded %d bytes successfully!", savedBytes);
ShowAction(debug);
}
break; /*** End load ***/
CARD_Unmount(CARDSLOT);
sprintf(debug, "Loaded %d bytes successfully!", savedBytes);
ShowAction(debug);
}
break; /*** End load ***/
default: break;
}
@ -487,7 +498,7 @@ void MCManage(int mode, int slot) {
}
}
void SD_Manage(int mode, int slot) {
void SD_ManageState(int mode, int slot) {
char path[1024];
char msg[128];
int offset = 0;
@ -650,9 +661,356 @@ void SD_Manage(int mode, int slot) {
void ManageState(int mode, int slot, int device) {
if (device == 0) {
MCManage(mode, slot);
MC_ManageState(mode, slot);
}
else {
SD_Manage(mode, slot);
SD_ManageState(mode, slot);
}
}
/* u8 screenscaler
* u8 currpal
* u8 slimit
* u8 timing
* u8 mpads[6]
* int FSDisable (int is u32, 4 bytes)
* u8 PADCAL
* u8 PADTUR
* u8 ChosenSlot
* u8 ChosenDevice
* u8 UseSDCARD
* u8 UseWiiSDCARD
*/
int SaveSettings(u8 *buffer) {
int filesize = 0;
buffer[filesize++] = screenscaler;
buffer[filesize++] = currpal;
buffer[filesize++] = slimit;
buffer[filesize++] = timing;
buffer[filesize++] = mpads[0];
buffer[filesize++] = mpads[1];
buffer[filesize++] = mpads[2];
buffer[filesize++] = mpads[3];
buffer[filesize++] = mpads[4];
buffer[filesize++] = mpads[5];
buffer[filesize++] = FSDisable;
buffer[filesize++] = PADCAL;
buffer[filesize++] = PADTUR;
buffer[filesize++] = ChosenSlot;
buffer[filesize++] = ChosenDevice;
buffer[filesize++] = UseSDCARD;
buffer[filesize++] = UseWiiSDCARD;
return filesize+1;
}
int LoadSettings(u8 *buffer) {
int filesize = 0;
screenscaler = buffer[filesize++];
currpal = buffer[filesize++];
if (currpal == 0)
FCEU_ResetPalette();
else {
u8 r, g, b, i;
/*** Now setup this palette ***/
for ( i = 0; i < 64; i++ ) {
r = palettes[currpal-1].data[i] >> 16;
g = ( palettes[currpal-1].data[i] & 0xff00 ) >> 8;
b = ( palettes[currpal-1].data[i] & 0xff );
FCEUD_SetPalette( i, r, g, b);
FCEUD_SetPalette( i+64, r, g, b);
FCEUD_SetPalette( i+128, r, g, b);
FCEUD_SetPalette( i+192, r, g, b);
}
}
slimit = buffer[filesize++];
FCEUI_DisableSpriteLimitation(slimit);
timing = buffer[filesize++];
FCEUI_SetVidSystem(timing);
mpads[0] = buffer[filesize++];
mpads[1] = buffer[filesize++];
mpads[2] = buffer[filesize++];
mpads[3] = buffer[filesize++];
mpads[4] = buffer[filesize++];
mpads[5] = buffer[filesize++];
FSDisable = buffer[filesize++];
FCEUI_DisableFourScore(FSDisable);
PADCAL = buffer[filesize++];
PADTUR = buffer[filesize++];
ChosenSlot = buffer[filesize++];
ChosenDevice = buffer[filesize++];
UseSDCARD = buffer[filesize++];
UseWiiSDCARD = buffer[filesize++];
return filesize+1;
}
/****************************************************************************
* Save Settings to MemCard
****************************************************************************/
void MC_ManageSettings(int mode, int slot, int quiet) {
char mcFilename[80];
int CardError;
card_dir CardDir;
card_file CardFile;
int SectorSize;
int found = 0;
int FileSize;
int actualSize;
int savedBytes=0;
char msg[128];
/*** Build the file name ***/
strcpy(mcFilename, "FCEU-Settings.fcs");
/*** Mount the Card ***/
CARD_Init("FCEU", "00");
/*** Try for memory card in slot A ***/
CardError = MountTheCard();
if ( CardError >= 0 ) {
/*** Get card sector size ***/
CardError = CARD_GetSectorSize(slot, &SectorSize);
switch ( mode ) {
case 0 : { /*** Save Game ***/
/*** Look for this file ***/
CardError = CARD_FindFirst(slot, &CardDir, true);
found = 0;
card_stat CardStatus;
while ( CardError != CARD_ERROR_NOFILE ) {
CardError = CARD_FindNext(&CardDir);
if ( strcmp(CardDir.filename, mcFilename) == 0 )
found = 1;
}
/*** Determine number of bytes required ***/
u8 buffer[SectorSize];
memset(buffer, 0, SectorSize);
actualSize = SaveSettings(buffer);
savedBytes = actualSize;
sprintf(msg, "Saving Settings to MC ...");
ShowAction(msg);
FileSize = ( actualSize / SectorSize ) * SectorSize;
if ( (actualSize % SectorSize) || (FileSize == 0) )
FileSize += SectorSize;
/*** Now write the file out ***/
if ( !found )
CardError = CARD_Create(CARDSLOT, mcFilename, FileSize, &CardFile);
else
CardError = CARD_Open(CARDSLOT, mcFilename, &CardFile);
CARD_GetStatus( CARDSLOT, CardFile.filenum, &CardStatus);
CardStatus.icon_addr = 0;
CardStatus.icon_fmt = 2;
CardStatus.icon_speed = 1;
CardStatus.comment_addr = sizeof(saveicon);
CARD_SetStatus( CARDSLOT, CardFile.filenum, &CardStatus);
/*** Haha! libogc only write one block at a time! ***/
if ( CardError == 0 ) {
int sbo = 0;
while ( actualSize > 0 ) {
CardError = CARD_Write(&CardFile, &buffer[sbo], SectorSize, sbo );
actualSize -= SectorSize;
sbo += SectorSize;
}
CardError = CARD_Close(&CardFile);
strcpy(msg, "Saved settings successfully");
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
}
else {
strcpy(msg, "Save Settings Failed!");
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
}
CARD_Unmount(CARDSLOT);
}
break; /*** End save ***/
case 1: { /*** Load state ***/
/*** Look for this file ***/
CardError = CARD_FindFirst(CARDSLOT, &CardDir, true);
found = 0;
while ( CardError != CARD_ERROR_NOFILE ) {
CardError = CARD_FindNext(&CardDir);
if ( strcmp(CardDir.filename, mcFilename) == 0 )
found = 1;
}
if ( found == 0 ) {
strcpy(msg, "No Settings Found");
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
CARD_Unmount(CARDSLOT);
return;
}
u8 buffer[SectorSize];
/*** Load the file into memory ***/
CardError = CARD_Open(CARDSLOT, mcFilename, &CardFile);
CardError = CARD_Read(&CardFile, &buffer, SectorSize, 0);
CARD_Close(&CardFile);
/*** Finally, do load ***/
savedBytes = LoadSettings(buffer);
sprintf(msg, "Loaded settings successfully!");
ShowAction(msg);
CARD_Unmount(CARDSLOT);
}
break; /*** End load ***/
default: break;
}
} else {
strcpy(msg, "Cannot mount Memory Card!");
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
}
}
void SD_ManageSettings(int mode, int slot, int quiet) {
char path[1024];
char msg[128];
int filesize = 0;
int len = 0;
u8 buffer[128];
if (slot < 2) {
sd_file *handle;
sprintf (path, "dev%d:\\%s\\%s\\Settings.fcs", ChosenSlot, FCEUDIR, SAVEDIR);
if (mode == 0) ShowAction ("Saving Settings to SD...");
else ShowAction ("Loading Settings from SD...");
handle = SDCARD_OpenFile(path, (mode == 0) ? "wb" : "rb");
if (handle == NULL) {
sprintf(msg, "Couldn't open %s", path);
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
return;
}
if (mode == 0) { // Save
filesize = SaveSettings(buffer);
len = SDCARD_WriteFile(handle, buffer, filesize);
SDCARD_CloseFile(handle);
if (len != filesize) {
sprintf (msg, "Error writing %s", path);
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
return;
}
sprintf(msg, "Saved settings successfully");
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
} else { // Load
len = SDCARD_ReadFile(handle, buffer, 128);
SDCARD_CloseFile (handle);
/*** Finally, do load ***/
filesize = LoadSettings(buffer);
sprintf (msg, "Loaded settings successfully");
ShowAction(msg);
return;
}
} else { // WiiSD
#ifdef HW_RVL
if (mode == 0) ShowAction ("Saving Settings to WiiSD...");
else ShowAction ("Loading Settings from WiiSD...");
sprintf(path, "/%s/%s/Settings.fcs", FCEUDIR, SAVEDIR);
FIL fp;
int res;
/* Mount WiiSD with TinyFatFS*/
if(f_mount(0, &frontfs) != FR_OK) {
strcpy(msg, "f_mount failed");
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
return 0;
}
if (mode == 0)
res = f_open(&fp, path, FA_CREATE_ALWAYS | FA_WRITE);
else {
if ((res=f_stat(path, &finfo)) != FR_OK) {
if (res == FR_NO_FILE) {
sprintf(msg, "Unable to find %s.", path);
}
else {
sprintf(msg, "f_stat failed, error %d", res);
}
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
return;
}
res = f_open(&fp, path, FA_READ);
}
if (res != FR_OK) {
sprintf(msg, "Failed to open %s, error %d.", path, res);
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
return;
}
if (mode == 0) { // Save
u32 written = 0;
filesize = SaveSettings(buffer);
if ((res = f_write(&fp, buffer, filesize, &written)) != FR_OK) {
sprintf(msg, "f_write failed, error %d", res);
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
f_close(&fp);
return;
}
sprintf(msg, "Wrote %d bytes.", filesize);
ShowAction(msg);
f_close(&fp);
return;
} else { // Load
u32 bytes_read = 0;
filesize = 0;
if (f_read(&fp, &buffer, 128, &bytes_read) != FR_OK) {
strcpy(msg, "f_read failed");
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
f_close(&fp);
return;
}
/*** Finally, do load ***/
filesize = LoadSettings(buffer);
sprintf(msg, "Read %d bytes.", bytes_read);
ShowAction(msg);
f_close(&fp);
return;
}
#endif
}
}
void ManageSettings(int mode, int slot, int device, int quiet) {
if (device == 0) {
MC_ManageSettings(mode, slot, quiet);
}
else {
SD_ManageSettings(mode, slot, quiet);
}
}

View File

@ -41,7 +41,7 @@ unsigned int nespadmap[] = { JOY_A, JOY_B, JOY_START, JOY_SELECT, JOY_A, JOY_B,
/****************************************************************************
* Convert GC Joystick Readings to JOY
****************************************************************************/
int PADTUR = 2;
u8 PADTUR = 2;
unsigned char DecodeJoy( unsigned short pp )
{
@ -86,7 +86,7 @@ unsigned char DecodeJoy( unsigned short pp )
*
* Additional check for Analog X/Y
****************************************************************************/
int PADCAL = 40;
u8 PADCAL = 40;
unsigned char GetAnalog(int Joy)
{

View File

@ -9,8 +9,8 @@
#include "gcdvd.h"
#include "sz.h"
extern int UseSDCARD;
extern int UseWiiSDCARD;
extern u8 UseSDCARD;
extern u8 UseWiiSDCARD;
extern sd_file *filehandle;
// 7zip error list