From 1f8e523ac22b09f4a016dd84af3fcb7a2dd8dcce Mon Sep 17 00:00:00 2001 From: dborth Date: Wed, 20 Aug 2008 07:58:55 +0000 Subject: [PATCH] Preferences now loaded/saved to XML --- source/ngc/dvd.cpp | 67 +++++----- source/ngc/filesel.cpp | 8 +- source/ngc/preferences.cpp | 247 ++++++++++++++++++++++++++++++++++--- source/ngc/s9xconfig.cpp | 28 ++--- source/ngc/snes9xGX.cpp | 16 +-- source/ngc/snes9xGX.h | 20 +-- 6 files changed, 294 insertions(+), 92 deletions(-) diff --git a/source/ngc/dvd.cpp b/source/ngc/dvd.cpp index 58310b5..7e53593 100644 --- a/source/ngc/dvd.cpp +++ b/source/ngc/dvd.cpp @@ -38,34 +38,6 @@ unsigned char DVDreadbuffer[2048] ATTRIBUTE_ALIGN (32); unsigned char dvdbuffer[2048]; -/** - * dvd_driveid - * - * Gets and returns the dvd driveid -**/ -#ifdef HW_DOL -int dvd_driveid() -{ - static unsigned char *inquiry=(unsigned char *)0x80000004; - - dvd[0] = 0x2e; - dvd[1] = 0; - dvd[2] = 0x12000000; - dvd[3] = 0; - dvd[4] = 0x20; - dvd[5] = 0x80000000; - dvd[6] = 0x20; - dvd[7] = 3; - - while( dvd[7] & 1 ) - ; - DCFlushRange((void *)0x80000000, 32); - - return (int)inquiry[2]; -} -#endif - - /** * dvd_read * @@ -86,9 +58,9 @@ dvd_read (void *dst, unsigned int len, u64 offset) if(offset < 0x57057C00 || (isWii == true && offset < 0x118244F00LL)) // don't read past the end of the DVD { offset >>= 2; - + #ifdef HW_DOL - + dvd[0] = 0x2E; dvd[1] = 0; dvd[2] = 0xA8000000; @@ -99,12 +71,12 @@ dvd_read (void *dst, unsigned int len, u64 offset) dvd[7] = 3; /*** Enable reading with DMA ***/ while (dvd[7] & 1); memcpy (dst, buffer, len); - + if (dvd[0] & 0x4) /* Ensure it has completed */ return 0; - + return 1; - + #elif WII_DVD int ret = 1; ret = DI_ReadDVD(dst, (u32)len, (u32)offset); @@ -114,9 +86,8 @@ dvd_read (void *dst, unsigned int len, u64 offset) return 0; #endif } - else // Let's not read past end of DVD - return 0; + return 0; } /** Minimal ISO Directory Definition **/ @@ -542,5 +513,31 @@ void dvd_motor_off( ) dvd[0] = 0x14; dvd[1] = 0; } + +/** + * dvd_driveid + * + * Gets and returns the dvd driveid +**/ + +int dvd_driveid() +{ + static unsigned char *inquiry=(unsigned char *)0x80000004; + + dvd[0] = 0x2e; + dvd[1] = 0; + dvd[2] = 0x12000000; + dvd[3] = 0; + dvd[4] = 0x20; + dvd[5] = 0x80000000; + dvd[6] = 0x20; + dvd[7] = 3; + + while( dvd[7] & 1 ) + ; + DCFlushRange((void *)0x80000000, 32); + + return (int)inquiry[2]; +} #endif diff --git a/source/ngc/filesel.cpp b/source/ngc/filesel.cpp index 3462648..647d996 100644 --- a/source/ngc/filesel.cpp +++ b/source/ngc/filesel.cpp @@ -230,11 +230,11 @@ int FileSelector (int method) signed char gc_sx = 0; signed char wm_ay = 0; signed char wm_sx = 0; - + int haverom = 0; int redraw = 1; int selectit = 0; - + int scroll_delay = 0; bool move_selection = 0; #define SCROLL_INITIAL_DELAY 15 @@ -250,7 +250,7 @@ int FileSelector (int method) gc_ay = PAD_StickY (0); gc_sx = PAD_SubStickX (0); - + p = PAD_ButtonsDown (0); ph = PAD_ButtonsHeld (0); #ifdef HW_RVL @@ -465,7 +465,7 @@ OpenDVD (int method) DI_GetCoverRegister(&val); if(val & 0x1) // True if no disc inside, use (val & 0x2) for true if disc inside. { - WaitPrompt("No disc inserted!"); + WaitPrompt((char *)"No disc inserted!"); return 0; } DI_Mount(); diff --git a/source/ngc/preferences.cpp b/source/ngc/preferences.cpp index 3ef3074..90c8eb3 100644 --- a/source/ngc/preferences.cpp +++ b/source/ngc/preferences.cpp @@ -12,6 +12,7 @@ #include #include #include +#include "mxml.h" #include "snes9x.h" #include "memmap.h" @@ -34,8 +35,9 @@ extern unsigned int wmpadmap[]; extern unsigned int ccpadmap[]; extern unsigned int ncpadmap[]; -#define PREFS_FILE_NAME "snes9xGx.prf" +#define PREFS_FILE_NAME "SNES9xGX.xml" #define PREFSVERSTRING "Snes9x GX 005 Prefs" +#define VERSIONSTRING "005" char prefscomment[2][32] = { {PREFSVERSTRING}, {"Preferences"} }; @@ -44,32 +46,144 @@ char prefscomment[2][32] = { {PREFSVERSTRING}, {"Preferences"} }; * * This sets up the save buffer for saving. ****************************************************************************/ -int -preparePrefsData () +mxml_node_t *xml; +mxml_node_t *data; +mxml_node_t *section; +mxml_node_t *item; +mxml_node_t *elem; + +char temp[200]; + +const char * toStr(int i) { + sprintf(temp, "%d", i); + return temp; +} + +void createXMLSection(const char * name, const char * description) +{ + section = mxmlNewElement(data, "section"); + mxmlElementSetAttr(section, "name", name); + mxmlElementSetAttr(section, "description", description); +} + +void createXMLSetting(const char * name, const char * description, const char * value) +{ + item = mxmlNewElement(section, "setting"); + mxmlElementSetAttr(item, "name", name); + mxmlElementSetAttr(item, "value", value); + mxmlElementSetAttr(item, "description", description); +} + +void createXMLController(unsigned int controller[], const char * name, const char * description) +{ + item = mxmlNewElement(section, "controller"); + mxmlElementSetAttr(item, "name", name); + mxmlElementSetAttr(item, "description", description); + + // create buttons + for(int i=0; i < 12; i++) + { + elem = mxmlNewElement(item, "button"); + mxmlElementSetAttr(elem, "number", toStr(i)); + mxmlElementSetAttr(elem, "assignment", toStr(controller[i])); + } +} + +int +preparePrefsData (int method) +{ + int offset = 0; + memset (savebuffer, 0, SAVEBUFFERSIZE); + + // add save icon and comments for Memory Card saves + if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) + { + offset = sizeof (saveicon); + + // Copy in save icon + memcpy (savebuffer, saveicon, offset); + + // And the comments + memcpy (savebuffer + offset, prefscomment, 64); + offset += 64; + } + + xml = mxmlNewXML("1.0"); + + data = mxmlNewElement(xml, "file"); + mxmlElementSetAttr(data, "version",VERSIONSTRING); + + createXMLSection("File", "File Settings"); + + createXMLSetting("AutoLoad", "Auto Load", toStr(GCSettings.AutoLoad)); + createXMLSetting("AutoSave", "Auto Save", toStr(GCSettings.AutoSave)); + createXMLSetting("LoadMethod", "Load Method", toStr(GCSettings.LoadMethod)); + createXMLSetting("SaveMethod", "Save Method", toStr(GCSettings.SaveMethod)); + createXMLSetting("LoadFolder", "Load Folder", GCSettings.LoadFolder); + createXMLSetting("SaveFolder", "Save Folder", GCSettings.SaveFolder); + createXMLSetting("CheatFolder", "Cheats Folder", GCSettings.CheatFolder); + createXMLSetting("VerifySaves", "Verify Memory Card Saves", toStr(GCSettings.VerifySaves)); + + createXMLSection("Network", "Network Settings"); + + createXMLSetting("smbip", "Share Computer IP", GCSettings.smbip); + createXMLSetting("smbshare", "Share Name", GCSettings.smbshare); + createXMLSetting("smbuser", "Share Username", GCSettings.smbuser); + createXMLSetting("smbpwd", "Share Password", GCSettings.smbpwd); + + createXMLSection("Emulation", "Emulation Settings"); + + createXMLSetting("ReverseStereo", "Reverse Stereo", toStr(Settings.ReverseStereo)); + createXMLSetting("InterpolatedSound", "Interpolated Sound", toStr(Settings.InterpolatedSound)); + createXMLSetting("Transparency", "Transparency", toStr(Settings.Transparency)); + createXMLSetting("DisplayFrameRate", "Display Frame Rate", toStr(Settings.DisplayFrameRate)); + createXMLSetting("NGCZoom", "C-Stick Zoom", toStr(GCSettings.NGCZoom)); + createXMLSetting("render", "Video Filtering", toStr(GCSettings.render)); + + createXMLSection("Controller", "Controller Settings"); + + createXMLSetting("MultiTap", "MultiTap", toStr(Settings.MultiPlayer5Master)); + createXMLSetting("Superscope", "Superscope", toStr(GCSettings.Superscope)); + createXMLSetting("Mice", "Mice", toStr(GCSettings.Mouse)); + createXMLSetting("Justifiers", "Justifiers", toStr(GCSettings.Justifier)); + + createXMLController(gcpadmap, "gcpadmap", "GameCube Pad"); + createXMLController(wmpadmap, "wmpadmap", "Wiimote"); + createXMLController(ccpadmap, "ccpadmap", "Classic Controller"); + createXMLController(ncpadmap, "ncpadmap", "Nunchuk"); + + memset (savebuffer + offset, 0, SAVEBUFFERSIZE); + int datasize = mxmlSaveString(xml, (char *)savebuffer, SAVEBUFFERSIZE, MXML_NO_CALLBACK); + + mxmlDelete(xml); + + return datasize; + + /* int offset = sizeof (saveicon); int size; memset (savebuffer, 0, SAVEBUFFERSIZE); - /*** Copy in save icon ***/ + // Copy in save icon memcpy (savebuffer, saveicon, offset); - /*** And the prefscomments ***/ + // And the prefscomments memcpy (savebuffer + offset, prefscomment, 64); offset += 64; - /*** Save all settings ***/ + // Save all settings size = sizeof (Settings); memcpy (savebuffer + offset, &Settings, size); offset += size; - /*** Save GC specific settings ***/ + // Save GC specific settings size = sizeof (GCSettings); memcpy (savebuffer + offset, &GCSettings, size); offset += size; - /*** Save buttonmaps ***/ + // Save buttonmaps size = sizeof (unsigned int) *12; // this size applies to all padmaps memcpy (savebuffer + offset, &gcpadmap, size); offset += size; @@ -81,15 +195,116 @@ preparePrefsData () offset += size; return offset; + */ } /**************************************************************************** * Decode Preferences Data ****************************************************************************/ -bool -decodePrefsData () +void loadXMLSetting(char * var, const char * name) { + item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND); + if(item) + sprintf(var, "%s", mxmlElementGetAttr(item, "value")); +} +void loadXMLSetting(int * var, const char * name) +{ + item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND); + if(item) + *var = atoi(mxmlElementGetAttr(item, "value")); +} +void loadXMLSetting(bool8 * var, const char * name) +{ + item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND); + if(item) + *var = atoi(mxmlElementGetAttr(item, "value")); +} + +void loadXMLController(unsigned int controller[], const char * name) +{ + item = mxmlFindElement(xml, xml, "controller", "name", name, MXML_DESCEND); + + if(item) + { + WaitPrompt((char *)name); + // populate buttons + for(int i=0; i < 12; i++) + { + elem = mxmlFindElement(item, xml, "button", "number", toStr(i), MXML_DESCEND); + if(elem) + controller[i] = atoi(mxmlElementGetAttr(elem, "assignment")); + } + } +} + +bool +decodePrefsData (int method) +{ + int offset = 0; + + // skip save icon and comments for Memory Card saves + if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) + { + offset = sizeof (saveicon); + offset += 64; // sizeof prefscomment + } + + xml = mxmlLoadString(NULL, (char *)savebuffer+offset, MXML_TEXT_CALLBACK); + + // check settings version + // we don't do anything with the version #, but we'll store it anyway + char * version; + item = mxmlFindElement(xml, xml, "file", "version", NULL, MXML_DESCEND); + if(item) // a version entry exists + version = (char *)mxmlElementGetAttr(item, "version"); + else // version # not found, must be invalid + return false; + + // File Settings + + loadXMLSetting(&GCSettings.AutoLoad, "AutoLoad"); + loadXMLSetting(&GCSettings.AutoSave, "AutoSave"); + loadXMLSetting(&GCSettings.LoadMethod, "LoadMethod"); + loadXMLSetting(&GCSettings.SaveMethod, "SaveMethod"); + loadXMLSetting(GCSettings.LoadFolder, "LoadFolder"); + loadXMLSetting(GCSettings.SaveFolder, "SaveFolder"); + loadXMLSetting(GCSettings.CheatFolder, "CheatFolder"); + loadXMLSetting(&GCSettings.VerifySaves, "VerifySaves"); + + // Network Settings + + loadXMLSetting(GCSettings.smbip, "smbip"); + loadXMLSetting(GCSettings.smbshare, "smbshare"); + loadXMLSetting(GCSettings.smbuser, "smbuser"); + loadXMLSetting(GCSettings.smbpwd, "smbpwd"); + + // Emulation Settings + + loadXMLSetting(&Settings.ReverseStereo, "ReverseStereo"); + loadXMLSetting(&Settings.InterpolatedSound, "InterpolatedSound"); + loadXMLSetting(&Settings.Transparency, "Transparency"); + loadXMLSetting(&Settings.DisplayFrameRate, "DisplayFrameRate"); + loadXMLSetting(&GCSettings.NGCZoom, "NGCZoom"); + loadXMLSetting(&GCSettings.render, "render"); + + // Controller Settings + + loadXMLSetting(&Settings.MultiPlayer5Master, "MultiTap"); + loadXMLSetting(&GCSettings.Superscope, "Superscope"); + loadXMLSetting(&GCSettings.Mouse, "Mice"); + loadXMLSetting(&GCSettings.Justifier, "Justifiers"); + + loadXMLController(gcpadmap, "gcpadmap"); + loadXMLController(wmpadmap, "wmpadmap"); + loadXMLController(ccpadmap, "ccpadmap"); + loadXMLController(ncpadmap, "ncpadmap"); + + mxmlDelete(xml); + + return true; + + /* int offset; char prefscomment[32]; int size; @@ -118,6 +333,7 @@ decodePrefsData () } else return false; + */ } /**************************************************************************** @@ -129,12 +345,11 @@ SavePrefs (int method, bool silent) if(method == METHOD_AUTO) method = autoSaveMethod(); - bool retval = false; char filepath[1024]; int datasize; int offset = 0; - datasize = preparePrefsData (); + datasize = preparePrefsData (method); if (!silent) ShowAction ((char*) "Saving preferences..."); @@ -163,11 +378,11 @@ SavePrefs (int method, bool silent) if (offset > 0) { - retval = decodePrefsData (); - if ( !silent ) + if (!silent) WaitPrompt ((char *)"Preferences saved"); + return true; } - return retval; + return false; } /**************************************************************************** @@ -210,7 +425,7 @@ LoadPrefs (int method, bool silent) if (offset > 0) { - retval = decodePrefsData (); + retval = decodePrefsData (method); if ( !silent ) WaitPrompt((char *)"Preferences loaded"); } diff --git a/source/ngc/s9xconfig.cpp b/source/ngc/s9xconfig.cpp index 9765651..d9f2639 100644 --- a/source/ngc/s9xconfig.cpp +++ b/source/ngc/s9xconfig.cpp @@ -177,26 +177,16 @@ DefaultSettings () GCSettings.AutoSave = 1; // default SMB settings + strncpy (GCSettings.smbip, "192.168.0.1", 15); // IP Address of share server + strncpy (GCSettings.smbuser, "Wiiuser", 19); // Your share user + strncpy (GCSettings.smbpwd, "password", 19); // Your share user password + strncpy (GCSettings.smbshare, "SNES", 19); // Share name on server - #define GC_IP "192.168.0.32" // IP to assign the GameCube - #define GW_IP "192.168.0.150" // Your gateway IP - #define MASK "255.255.255.0" // Your subnet mask - #define SMB_USER "Wiiuser" // Your share user - #define SMB_PWD "password" // Your share user password - #define SMB_GCID "Wii" // Machine Name of GameCube - #define SMB_SVID "Server" // Machine Name of Server(Share) - #define SMB_SHARE "SNES" // Share name on server - #define SMB_IP "192.168.0.1" // IP Address of share server - - strncpy (GCSettings.gcip, GC_IP, 15); - strncpy (GCSettings.gwip, GW_IP, 15); - strncpy (GCSettings.mask, MASK, 15); - strncpy (GCSettings.smbip, SMB_IP, 15); - strncpy (GCSettings.smbuser, SMB_USER, 19); - strncpy (GCSettings.smbpwd, SMB_PWD, 19); - strncpy (GCSettings.smbgcid, SMB_GCID, 19); - strncpy (GCSettings.smbsvid, SMB_SVID, 19); - strncpy (GCSettings.smbshare, SMB_SHARE, 19); + GCSettings.gcip[0] = 0; + GCSettings.gwip[0] = 0; + GCSettings.mask[0] = 0; + GCSettings.smbsvid[0] = 0; + GCSettings.smbgcid[0] = 0; GCSettings.NGCZoom = 0; GCSettings.VerifySaves = 0; diff --git a/source/ngc/snes9xGX.cpp b/source/ngc/snes9xGX.cpp index b32d608..04c5ab2 100644 --- a/source/ngc/snes9xGX.cpp +++ b/source/ngc/snes9xGX.cpp @@ -259,7 +259,7 @@ emulate () { S9xMainLoop (); NGCReportButtons (); - + if (ConfigRequested) { VIDEO_WaitVSync (); @@ -283,21 +283,21 @@ emulate () } mainmenu (3); // go to game menu - + /*** Update any emulation settings changed in the menu ***/ ReInitGCVideo(); // update video after reading settings FrameTimer = 0; setFrameTimerMethod(); // set frametimer method every time a ROM is loaded - + Settings.SuperScopeMaster = (GCSettings.Superscope > 0 ? true : false); Settings.MouseMaster = (GCSettings.Mouse > 0 ? true : false); Settings.JustifierMaster = (GCSettings.Justifier > 0 ? true : false); SetControllers(); S9xReportControllers(); // FIX - + ConfigRequested = 0; }//if ConfigRequested - + }//while } @@ -327,10 +327,10 @@ main () #ifdef WII_DVD DI_Init(); // first #endif - + unsigned int save_flags; int selectedMenu = -1; - + #ifdef HW_RVL WPAD_Init(); // read wiimote accelerometer and IR data @@ -428,7 +428,7 @@ main () CPU.Flags = save_flags; /*** Load SRAM ***/ - Memory.LoadSRAM ("DVD"); + //Memory.LoadSRAM ("DVD"); } /*** Emulate ***/ diff --git a/source/ngc/snes9xGX.h b/source/ngc/snes9xGX.h index 4abcb97..b838f0f 100644 --- a/source/ngc/snes9xGX.h +++ b/source/ngc/snes9xGX.h @@ -177,10 +177,10 @@ enum { }; struct SGCSettings{ - uint8 AutoLoad; - uint8 AutoSave; - uint8 LoadMethod; // For ROMS: Auto, SD, DVD, USB, Network (SMB) - uint8 SaveMethod; // For SRAM, Freeze, Prefs: Auto, SD, Memory Card Slot A, Memory Card Slot B, USB, SMB + int AutoLoad; + int AutoSave; + int LoadMethod; // For ROMS: Auto, SD, DVD, USB, Network (SMB) + int SaveMethod; // For SRAM, Freeze, Prefs: Auto, SD, Memory Card Slot A, Memory Card Slot B, USB, SMB char LoadFolder[200]; // Path to game files char SaveFolder[200]; // Path to save files char CheatFolder[200]; // Path to cheat files @@ -193,12 +193,12 @@ struct SGCSettings{ char smbgcid[20]; char smbsvid[20]; char smbshare[20]; - bool8 NGCZoom; - uint8 VerifySaves; - u16 render; // 0 - original, 1 - no AA - u16 Superscope; - u16 Mouse; - u16 Justifier; + int NGCZoom; // 0 - off, 1 - on + int VerifySaves; + int render; // 0 - original, 1 - no AA + int Superscope; + int Mouse; + int Justifier; }; START_EXTERN_C