- Improve string parsing; bugs introduced with earlier commits should be gone now

- Add some very preliminary bits for importing a custom font fileExists
- Add "displayDebugF" function for easier debugging
- Add some comments on dsiwarehax mode to instructions file
This commit is contained in:
msiewert76 2011-10-14 20:11:54 +00:00
parent 34e7016312
commit d084a58cf7
9 changed files with 138 additions and 58 deletions

View File

@ -27,6 +27,7 @@
#include "auxspi.h"
#include "hardware.h"
#include "globals.h"
#include "display.h"
#include <algorithm>
@ -89,7 +90,6 @@ uint8 type2_size(auxspi_extra extra)
}
// ========================================================
uint8 auxspi_save_type(auxspi_extra extra)
{
uint32 jedec = auxspi_save_jedec_id(extra); // 9f
@ -130,6 +130,7 @@ uint32 auxspi_save_jedec_id(auxspi_extra extra)
uint32 id = 0;
if (extra)
auxspi_disable_extra(extra);
auxspi_open(0);
auxspi_write(0x9f);
id |= auxspi_read() << 16;
@ -323,7 +324,7 @@ void auxspi_disable_big_protection()
auxspi_extra auxspi_has_extra()
{
sysSetBusOwners(true, true);
// Trying to read the save size in IR mode will fail on non-IR devices.
// If we have success, it is an IR device.
u8 size2 = auxspi_save_size_log_2(AUXSPI_INFRARED);

View File

@ -85,6 +85,7 @@ void displayPrintUpper(bool fc)
iprintf("Status :\n");
} else {
// old DS phat/lite
iprintf("--- SLOT 2 ---------------------");
iprintf("Game ID :\n");
iprintf("Game name:\n");
iprintf("Game save:\n");
@ -176,6 +177,8 @@ void displayPrintUpper(bool fc)
} else {
uint8 type = auxspi_save_type(slot_1_type);
uint8 size = auxspi_save_size_log_2(slot_1_type);
// some debug output may need this so iprintf prints to the correct region
consoleSetWindow(&upperScreen, 10, 5, 22, 1);
switch (type) {
case 1:
sprintf(&name[0], "Eeprom (%i Bytes)", size);
@ -553,3 +556,17 @@ void displayWarning2F(int id, ...)
break;
}
}
void displayDebugF(const char *format, ...)
{
va_list argp;
va_start(argp, format);
memset(txt, 0, 256);
consoleSelect(&upperScreen);
consoleSetWindow(&upperScreen, 0, 12, 32, 4);
consoleClear();
vprintf(format, argp);
va_end(argp);
}

View File

@ -51,6 +51,8 @@ void displayStateF(int id, ...);
void displayProgressBar(int cur, int max0);
void displayDebugF(const char *format, ...);
#endif

View File

@ -34,6 +34,10 @@
#define VERSION_MICRO 0
#define VERSION_EXTRA "RC2"
// this enables a custom font. it does not work yet, stuff is missing, so please uncomment
// this line only for testing and development purposes!
//#define ENABLE_CUSTOM_FONT
extern u8 *data;
extern u32 size_buf;

View File

@ -777,7 +777,7 @@ void hwBackupFTP(bool dlp)
displayPrintUpper();
uint8 size = auxspi_save_size_log_2(slot_1_type);
uint8 type = auxspi_save_type(slot_1_type);
// Second: connect to FTP server
if (!ftp_active)
hwLoginFTP();

View File

@ -228,8 +228,7 @@ void mode_gba()
void mode_wifi()
{
// use 3in1 to buffer data
displayStateF(STR_EMPTY);
//displayStateF(STR_EMPTY);
displayPrintUpper(true);
displayPrintLower();
@ -472,7 +471,7 @@ int main(int argc, char* argv[])
mode = 4;
// load strings
// "txt" is used as a temp buffer for the language file name
// "txt" is used as a temp buffer for the language file name, returned by hwDetect
stringsLoadFile(txt);
// prepare the global data buffer

View File

@ -32,24 +32,46 @@
#include <nds.h>
#include "fileselect.h"
#include "globals.h"
#include "display.h"
// fallback string resources
#include "strings_fallback.inc"
using namespace std;
// a global string array
char **message_strings;
#define ADD_STRING(id,text) sprintf(txt, "%i", id);\
if (ini) {\
if (ini_locateKey(ini, txt) == 0) {\
ini_readString(ini, txt, 256);\
} \
} else {\
strcpy(txt,text);\
}\
message_strings[id] = new char[strlen(txt)+1];\
memcpy(message_strings[id], txt, strlen(txt)+1);
// ---------------------------------------------------
// local functions
//
void AddString(uint32 id, ini_fd_t ini)
{
// first, try to read string from ini file
sprintf(txt, "%i", id);
bool found = false;
if (ini) {
if (ini_locateKey(ini, txt) == 0) {
if (ini_readString(ini, txt, 256) > 0) {
found = true;
}
}
}
if (!found) {
// if no ini file was found, use the fallback striung provided here
message_strings[id] = const_cast<char*>(strings_fallback[id]);
} else {
// did load string, so prepare a buffer for it and move text
message_strings[id] = new char[strlen(txt)+1];
memcpy(message_strings[id], txt, strlen(txt)+1);
}
}
// ---------------------------------------------------
// global functions
//
bool stringsLoadFile(const char *fname)
{
#ifdef DEBUG
@ -71,56 +93,91 @@ bool stringsLoadFile(const char *fname)
message_strings = new char*[STR_LAST];
if (ini)
ini_locateHeading(ini, "");
#if 0
//#ifdef ENABLE_CUSTOM_FONT
// EXPERIMENTAL: load and init a custom font
if (ini_locateKey(ini, "font") == 0) {
ini_readString(ini, txt, 256);
if (strlen(txt)) {
if (fileExists(txt)) {
// load and init custon font; code borrowed from custom_font demo
u32 fs = fileSize(txt);
static u32 min_fs = 32*256;
if (fs >= min_fs) {
// TODO: maybe this should be a fixed size?
void *font0 = malloc(fileSize(txt));
FILE *file = fopen(txt, "rb");
fread(font0, 1, fs, file);
fclose(file);
ADD_STRING(STR_EMPTY, "");
ADD_STRING(STR_STR, "%s");
// borrowed from libnds source
ConsoleFont font;
font.gfx = (u16*)font0 + (fs - 16*256); // 16 bit-pointer, so only "16*"
font.pal = 0; // single color!
font.numColors = 0;
font.numChars = 256; // this is fixed; it should be enough for everybody
font.bpp = 4; // 4 bits per pixel
font.asciiOffset = 0; // we cover 256 letters (well, we try)
font.convertSingleColor = true; // for now, we only want one color!
consoleSetFont(&upperScreen, &font);
consoleSetFont(&lowerScreen, &font);
free(font0);
}
}
}
}
#endif
AddString(STR_EMPTY, ini);
AddString(STR_STR, ini);
//
ADD_STRING(STR_MM_WIPE,"\n WIPES OUT ALL SAVE DATA\n ON YOUR GAME !");
ADD_STRING(STR_TITLE_MSG,"DS savegame manager\nVersion %i.%i.%i%s\nBy Pokedoc");
ADD_STRING(STR_BOOT_NO_INI,"Unable to open ini file!\nPlease make sure that it is\n1. in this apps folder, or"
"\n2. in the root folder\nIf 1. does not work, use 2.");
ADD_STRING(STR_BOOT_MODE_UNSUPPORTED,"This mode is DISABLED.\nPlease restart the system.");
ADD_STRING(STR_BOOT_DLDI_ERROR,"DLDI initialisation error!");
AddString(STR_MM_WIPE, ini);
AddString(STR_TITLE_MSG, ini);
AddString(STR_BOOT_NO_INI, ini);
AddString(STR_BOOT_MODE_UNSUPPORTED, ini);
AddString(STR_BOOT_DLDI_ERROR, ini);
//
ADD_STRING(STR_HW_SWAP_CARD,"Please take out Slot 1 flash card and insert a game.\nPress A when done.");
ADD_STRING(STR_HW_CARD_UNREADABLE,"I can't read the game inserted in slot 1.\nPlease eject and retry.");
ADD_STRING(STR_HW_WRONG_GAME,"This game has a save chip that is bigger than the save you are going to write. Please insert a different game.\nPress A when done.");
ADD_STRING(STR_HW_PLEASE_REBOOT,"Done! Please power off\n(and restart if you want to do more).");
AddString(STR_HW_SWAP_CARD, ini);
AddString(STR_HW_CARD_UNREADABLE, ini);
AddString(STR_HW_WRONG_GAME, ini);
AddString(STR_HW_PLEASE_REBOOT, ini);
//
ADD_STRING(STR_HW_SELECT_FILE,"Please select a .sav file.");
ADD_STRING(STR_HW_SELECT_FILE_OW,"Please select a file to overwrite, or press L+R in a folder to create a new file.");
ADD_STRING(STR_HW_SEEK_UNUSED_FNAME,"Please wait... searching for an unused filename.\nTrying: %s");
ADD_STRING(STR_ERR_NO_FNAME,"ERROR: Unable to get an unused nfilename! This means that you have more than 65536 saves!\n(wow!)");
AddString(STR_HW_SELECT_FILE, ini);
AddString(STR_HW_SELECT_FILE_OW, ini);
AddString(STR_HW_SEEK_UNUSED_FNAME, ini);
AddString(STR_ERR_NO_FNAME, ini);
//
ADD_STRING(STR_HW_FORMAT_GAME,"Preparing to write to your game.\nPlease wait...");
ADD_STRING(STR_HW_WRITE_GAME,"Writing save to your game.\nPlease wait...");
ADD_STRING(STR_HW_READ_GAME,"Reading save from your game.\nPlease wait...");
ADD_STRING(STR_HW_WRITE_FILE, "Writing file:\n%s");
ADD_STRING(STR_HW_READ_FILE, "Reading file:\n%s");
AddString(STR_HW_FORMAT_GAME, ini);
AddString(STR_HW_WRITE_GAME, ini);
AddString(STR_HW_READ_GAME, ini);
AddString(STR_HW_WRITE_FILE, ini);
AddString(STR_HW_READ_FILE, ini);
//
ADD_STRING(STR_HW_3IN1_FORMAT_NOR,"Preparing to write to the 3in1.\nPlease wait...");
ADD_STRING(STR_HW_3IN1_PREPARE_REBOOT,"Preparing reboot...");
ADD_STRING(STR_HW_3IN1_PLEASE_REBOOT,"Save has been written to the 3in1. Please power off and restart this tool to finish the dump.");
ADD_STRING(STR_HW_3IN1_CLEAR_FLAG,"Preparing to dump your save...\nPlease wait...");
ADD_STRING(STR_HW_3IN1_DONE_DUMP,"Done. Your game save has been dumped using your 3in1. Filename:\n%s\nPress (B) to continue.");
ADD_STRING(STR_HW_3IN1_ERR_IDMODE,"ERROR!\nID mode still active!");
ADD_STRING(STR_HW_3IN1_ERR_NOR,"ERROR!\nWriting to NOR failed!");
AddString(STR_HW_3IN1_FORMAT_NOR, ini);
AddString(STR_HW_3IN1_PREPARE_REBOOT, ini);
AddString(STR_HW_3IN1_PLEASE_REBOOT, ini);
AddString(STR_HW_3IN1_CLEAR_FLAG, ini);
AddString(STR_HW_3IN1_DONE_DUMP, ini);
AddString(STR_HW_3IN1_ERR_IDMODE, ini);
AddString(STR_HW_3IN1_ERR_NOR, ini);
//
ADD_STRING(STR_HW_FTP_SEEK_AP,"Connecting to an access point...\nplease wait...");
ADD_STRING(STR_HW_FTP_ERR_AP,"ERROR!\nCould not find a compatible Access Point. Please configure your WiFi Connection from a WiFi-enabled game!");
ADD_STRING(STR_HW_FTP_SEEK_FTP,"Connecting to an FTP server...\nplease wait...");
ADD_STRING(STR_HW_FTP_ERR_FTP,"ERROR!\nCould not find an FTP server. Please refer to the documentation.");
ADD_STRING(STR_HW_FTP_LOGIN,"Logging in...");
ADD_STRING(STR_HW_FTP_ERR_LOGIN,"ERROR!\nCould not log in to the FTP server. Please verify your username and password are correct in your ini file.");
ADD_STRING(STR_HW_FTP_DIR,"Reading FTP directory...");
ADD_STRING(STR_HW_FTP_SLOW,"FTP is slow, please wait...");
ADD_STRING(STR_HW_FTP_READ_ONLY,"WARNING:\nCould not write to your FTP server! Maybe you forgot to enable write access?");
AddString(STR_HW_FTP_SEEK_AP, ini);
AddString(STR_HW_FTP_ERR_AP, ini);
AddString(STR_HW_FTP_SEEK_FTP, ini);
AddString(STR_HW_FTP_ERR_FTP, ini);
AddString(STR_HW_FTP_LOGIN, ini);
AddString(STR_HW_FTP_ERR_LOGIN, ini);
AddString(STR_HW_FTP_DIR, ini);
AddString(STR_HW_FTP_SLOW, ini);
AddString(STR_HW_FTP_READ_ONLY, ini);
//
ADD_STRING(STR_HW_WARN_DELETE,"This will WIPE OUT your entire save! ARE YOU SURE?\n\nPress R+up+Y to confim!");
ADD_STRING(STR_HW_DID_DELETE,"Done. Your game save has been PERMANENTLY deleted.\n\nPlease restart your DS.");
AddString(STR_HW_WARN_DELETE, ini);
AddString(STR_HW_DID_DELETE, ini);
//
ADD_STRING(STR_FS_READ,"Please select a .sav file\n (A) Select\n (B) One directory up\n");
ADD_STRING(STR_FS_WRITE,"Please select a .sav file\n (A) Select\n (B) One directory up\n (L+R) cancel (new file)");
AddString(STR_FS_READ, ini);
AddString(STR_FS_WRITE, ini);
//
// delete temp file (which is a remnant of inilib)

Binary file not shown.

View File

@ -1 +1 @@
<Project name="Savegame Manager"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="arm9" path="arm9\"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="build" path="build\"><File path=".map"></File><File path="auxspi.d"></File><File path="auxspi.o"></File><File path="display.d"></File><File path="display.o"></File><File path="dsCard.d"></File><File path="dsCard.o"></File><File path="dsi.d"></File><File path="dsi.o"></File><File path="fileselect.d"></File><File path="fileselect.o"></File><File path="ftplib.d"></File><File path="ftplib.o"></File><File path="gba.d"></File><File path="gba.o"></File><File path="globals.d"></File><File path="globals.o"></File><File path="hardware.d"></File><File path="hardware.o"></File><File path="ini.d"></File><File path="ini.o"></File><File path="main.d"></File><File path="main.o"></File><File path="strings.d"></File><File path="strings.o"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="debug" path="debug\"></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="source" path="source\"><File path="auxspi.cpp"></File><File path="auxspi.h"></File><File path="auxspi_core.inc"></File><File path="display.cpp"></File><File path="display.h"></File><File path="dsCard.cpp"></File><File path="dsCard.h"></File><File path="dsi.cpp"></File><File path="dsi.h"></File><File path="fileselect.cpp"></File><File path="fileselect.h"></File><File path="ftplib.c"></File><File path="ftplib.h"></File><File path="gba.cpp"></File><File path="gba.h"></File><File path="globals.cpp"></File><File path="globals.h"></File><File path="hardware.cpp"></File><File path="hardware.h"></File><File path="headings.i"></File><File path="ini.cpp"></File><File path="ini.h"></File><File path="iniconfig.h"></File><File path="iniheadings.h"></File><File path="inikeys.h"></File><File path="inilist.h"></File><File path="keys.i"></File><File path="libini.h"></File><File path="list.i"></File><File path="main.cpp"></File><File path="strings.cpp"></File><File path="strings.h"></File><File path="types.i"></File></MagicFolder><File path="Makefile"></File><File path="Makefile.debug"></File><File path="savegame_manager.elf"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="arm7" path="arm7\"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="build" path="build\"><File path=".map"></File><File path="arm7.d"></File><File path="arm7.o"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="debug" path="debug\"></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="source" path="source\"><File path="arm7.c"></File></MagicFolder><File path="Makefile"></File><File path="Makefile.debug"></File><File path="savegame_manager.elf"></File></MagicFolder><File path="Makefile"></File></Project>
<Project name="Savegame Manager"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="arm9" path="arm9\"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="build" path="build\"><File path=".map"></File><File path="auxspi.d"></File><File path="auxspi.o"></File><File path="display.d"></File><File path="display.o"></File><File path="dsCard.d"></File><File path="dsCard.o"></File><File path="dsi.d"></File><File path="dsi.o"></File><File path="fileselect.d"></File><File path="fileselect.o"></File><File path="ftplib.d"></File><File path="ftplib.o"></File><File path="gba.d"></File><File path="gba.o"></File><File path="globals.d"></File><File path="globals.o"></File><File path="hardware.d"></File><File path="hardware.o"></File><File path="ini.d"></File><File path="ini.o"></File><File path="main.d"></File><File path="main.o"></File><File path="strings.d"></File><File path="strings.o"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="debug" path="debug\"></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="source" path="source\"><File path="auxspi.cpp"></File><File path="auxspi.h"></File><File path="auxspi_core.inc"></File><File path="display.cpp"></File><File path="display.h"></File><File path="dsCard.cpp"></File><File path="dsCard.h"></File><File path="dsi.cpp"></File><File path="dsi.h"></File><File path="fileselect.cpp"></File><File path="fileselect.h"></File><File path="ftplib.c"></File><File path="ftplib.h"></File><File path="gba.cpp"></File><File path="gba.h"></File><File path="globals.cpp"></File><File path="globals.h"></File><File path="hardware.cpp"></File><File path="hardware.h"></File><File path="headings.i"></File><File path="ini.cpp"></File><File path="ini.h"></File><File path="iniconfig.h"></File><File path="iniheadings.h"></File><File path="inikeys.h"></File><File path="inilist.h"></File><File path="keys.i"></File><File path="libini.h"></File><File path="list.i"></File><File path="main.cpp"></File><File path="strings.cpp"></File><File path="strings.h"></File><File path="strings_fallback.inc"></File><File path="types.i"></File></MagicFolder><File path="Makefile"></File><File path="Makefile.debug"></File><File path="savegame_manager.elf"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="arm7" path="arm7\"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="build" path="build\"><File path=".map"></File><File path="arm7.d"></File><File path="arm7.o"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="debug" path="debug\"></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="source" path="source\"><File path="arm7.c"></File></MagicFolder><File path="Makefile"></File><File path="Makefile.debug"></File><File path="savegame_manager.elf"></File></MagicFolder><File path="Makefile"></File></Project>