diff --git a/arm9/source/auxspi.cpp b/arm9/source/auxspi.cpp index 02d98bf..9a89897 100644 --- a/arm9/source/auxspi.cpp +++ b/arm9/source/auxspi.cpp @@ -27,6 +27,7 @@ #include "auxspi.h" #include "hardware.h" #include "globals.h" +#include "display.h" #include @@ -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); diff --git a/arm9/source/display.cpp b/arm9/source/display.cpp index e5713a8..cf26f82 100644 --- a/arm9/source/display.cpp +++ b/arm9/source/display.cpp @@ -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); +} diff --git a/arm9/source/display.h b/arm9/source/display.h index 48b1b33..0fab927 100644 --- a/arm9/source/display.h +++ b/arm9/source/display.h @@ -51,6 +51,8 @@ void displayStateF(int id, ...); void displayProgressBar(int cur, int max0); +void displayDebugF(const char *format, ...); + #endif diff --git a/arm9/source/globals.h b/arm9/source/globals.h index 1deadc7..233e264 100644 --- a/arm9/source/globals.h +++ b/arm9/source/globals.h @@ -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; diff --git a/arm9/source/hardware.cpp b/arm9/source/hardware.cpp index 21769d0..fa6e109 100644 --- a/arm9/source/hardware.cpp +++ b/arm9/source/hardware.cpp @@ -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(); diff --git a/arm9/source/main.cpp b/arm9/source/main.cpp index 43d9f16..b43b440 100644 --- a/arm9/source/main.cpp +++ b/arm9/source/main.cpp @@ -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 diff --git a/arm9/source/strings.cpp b/arm9/source/strings.cpp index 0cdd668..5cba2bf 100644 --- a/arm9/source/strings.cpp +++ b/arm9/source/strings.cpp @@ -32,24 +32,46 @@ #include #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(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) diff --git a/savegame_manager.odt b/savegame_manager.odt index 33c9934..c5a8a7c 100644 Binary files a/savegame_manager.odt and b/savegame_manager.odt differ diff --git a/savegame_manager.pnproj b/savegame_manager.pnproj index bf9ead6..48c0dcb 100644 --- a/savegame_manager.pnproj +++ b/savegame_manager.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file