diff --git a/fonts/jp.ttf b/fonts/jp.ttf new file mode 100644 index 0000000..39ff91b Binary files /dev/null and b/fonts/jp.ttf differ diff --git a/fonts/ko.ttf b/fonts/ko.ttf new file mode 100644 index 0000000..bcfadd8 Binary files /dev/null and b/fonts/ko.ttf differ diff --git a/readme.txt b/readme.txt index 3edd86e..52d6abb 100644 --- a/readme.txt +++ b/readme.txt @@ -38,6 +38,13 @@ https://github.com/dborth/fceugx/releases |0Oื๘oท UPDATE HISTORY ทo๘ืO0| `จ•จจจจจ จจจจจจจจจจจจจจจจ จจจจจจจจจจจจจจจ จจจจจจจจจจจจจจจจจจจจ จจจจจจจจจจจจจ' +[3.4.2] + +* Fixed GameCube controllers not working +* Added ability to load external fonts and activated Japanese/Korean + translations. Simply put the ko.ttf or jp.ttf in the app directory +* Added ability to change preview image source with + button (thanks Zalo!) + [3.4.1 - January 4, 2019] * Improved WiiFlow integration diff --git a/source/fceugx.cpp b/source/fceugx.cpp index 8f56bb0..d0456b4 100644 --- a/source/fceugx.cpp +++ b/source/fceugx.cpp @@ -41,6 +41,9 @@ #include "gui/gui.h" #include "utils/wiidrc.h" #include "utils/FreeTypeGX.h" +#ifdef HW_RVL + #include "mem2.h" +#endif #ifdef USE_VM #include "vmalloc.h" #endif @@ -400,6 +403,8 @@ int main(int argc, char *argv[]) // store path app was loaded from if(argc > 0 && argv[0] != NULL) CreateAppPath(argv[0]); + + InitMem2Manager(); #endif DefaultSettings(); // Set defaults diff --git a/source/fileop.cpp b/source/fileop.cpp index b9c608d..33a0137 100644 --- a/source/fileop.cpp +++ b/source/fileop.cpp @@ -35,9 +35,14 @@ #include "filebrowser.h" #include "gui/gui.h" +#ifdef HW_RVL + #include "mem2.h" +#endif + #define THREAD_SLEEP 100 unsigned char *savebuffer = NULL; +u8 *ext_font_ttf = NULL; static mutex_t bufferLock = LWP_MUTEX_NULL; FILE * file; // file pointer - the only one we should ever use! bool unmountRequired[7] = { false, false, false, false, false, false, false }; @@ -854,6 +859,43 @@ size_t LoadFile(char * filepath, bool silent) return LoadFile((char *)savebuffer, filepath, 0, SAVEBUFFERSIZE, silent); } +#ifdef HW_RVL +size_t LoadFont(char * filepath) +{ + FILE *file = fopen (filepath, "rb"); + + if(!file) { + ErrorPrompt("Font file not found!"); + return 0; + } + + fseeko(file,0,SEEK_END); + size_t loadSize = ftello(file); + + if(loadSize == 0) { + ErrorPrompt("Error loading font!"); + return 0; + } + + if(ext_font_ttf) { + mem2_free(ext_font_ttf); + } + + ext_font_ttf = (u8 *)mem2_malloc(loadSize); + + if(!ext_font_ttf) { + ErrorPrompt("Font file is too large!"); + fclose(file); + return 0; + } + + fseeko(file,0,SEEK_SET); + fread (ext_font_ttf, 1, loadSize, file); + fclose(file); + return loadSize; +} +#endif + /**************************************************************************** * SaveFile * Write buffer to file diff --git a/source/fileop.h b/source/fileop.h index 6f28ed1..56b2599 100644 --- a/source/fileop.h +++ b/source/fileop.h @@ -37,10 +37,12 @@ void FreeSaveBuffer(); size_t LoadFile(char * rbuffer, char *filepath, size_t length, size_t buffersize, bool silent); size_t LoadFile(char * filepath, bool silent); size_t LoadSzFile(char * filepath, unsigned char * rbuffer); +size_t LoadFont(char *filepath); size_t SaveFile(char * buffer, char *filepath, size_t datasize, bool silent); size_t SaveFile(char * filepath, size_t datasize, bool silent); extern unsigned char *savebuffer; +extern u8 *ext_font_ttf; extern FILE * file; extern bool unmountRequired[]; extern bool isMounted[]; diff --git a/source/mem2.cpp b/source/mem2.cpp new file mode 100644 index 0000000..5873f7e --- /dev/null +++ b/source/mem2.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** + * FCE Ultra + * Nintendo Wii/Gamecube Port + * + * Tantric 2010 + * + * mem2.cpp + * + * MEM2 memory allocator + ***************************************************************************/ + +#ifdef HW_RVL + +#include +#include +#include +#include + +static heap_cntrl mem2_heap; + +u32 InitMem2Manager () +{ + int size = (10*1024*1024); + u32 level; + _CPU_ISR_Disable(level); + size &= ~0x1f; // round down, because otherwise we may exceed the area + void *mem2_heap_ptr = (void *)((u32)SYS_GetArena2Hi()-size); + SYS_SetArena2Hi(mem2_heap_ptr); + _CPU_ISR_Restore(level); + size = __lwp_heap_init(&mem2_heap, mem2_heap_ptr, size, 32); + return size; +} + +void* mem2_malloc(u32 size) +{ + return __lwp_heap_allocate(&mem2_heap, size); +} + +bool mem2_free(void *ptr) +{ + return __lwp_heap_free(&mem2_heap, ptr); +} + +#endif diff --git a/source/mem2.h b/source/mem2.h new file mode 100644 index 0000000..4aeda0b --- /dev/null +++ b/source/mem2.h @@ -0,0 +1,23 @@ +/**************************************************************************** + * FCE Ultra + * Nintendo Wii/Gamecube Port + * + * Tantric 2010 + * + * mem2.h + * + * MEM2 memory allocator + ***************************************************************************/ + +#ifdef HW_RVL + +#ifndef _MEM2MANAGER_H_ +#define _MEM2MANAGER_H_ + +u32 InitMem2Manager (); +void* mem2_malloc(u32 size); +bool mem2_free(void *ptr); + +#endif + +#endif diff --git a/source/menu.cpp b/source/menu.cpp index addede1..b512d80 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -41,6 +41,7 @@ #include "cheatmgr.h" #include "gui/gui.h" #include "utils/gettext.h" +#include "utils/FreeTypeGX.h" #define THREAD_SLEEP 100 @@ -48,6 +49,10 @@ static GuiImageData * pointer[4]; #endif +#ifdef HW_RVL + #include "mem2.h" +#endif + #ifdef USE_VM #include "vmalloc.h" #define MEM_ALLOC(A) (u8*)vm_malloc(A) @@ -126,7 +131,7 @@ HaltGui() usleep(THREAD_SLEEP); } -void ResetText() +static void ResetText() { LoadLanguage(); @@ -134,6 +139,58 @@ void ResetText() mainWindow->ResetText(); } +static int currentLanguage = -1; + +void ChangeLanguage() { + if(currentLanguage == GCSettings.language) { + return; + } + + if(GCSettings.language == LANG_JAPANESE || GCSettings.language == LANG_KOREAN) { +#ifdef HW_RVL + char filepath[MAXPATHLEN]; + + switch(GCSettings.language) { + case LANG_KOREAN: + sprintf(filepath, "%s/ko.ttf", appPath); + break; + case LANG_JAPANESE: + sprintf(filepath, "%s/jp.ttf", appPath); + break; + } + + size_t fontSize = LoadFont(filepath); + + if(fontSize > 0) { + HaltGui(); + DeinitFreeType(); + InitFreeType((u8*)ext_font_ttf, fontSize); + } + else { + GCSettings.language = currentLanguage; + } +#else + GCSettings.language = currentLanguage; + ErrorPrompt("Unsupported language!"); +#endif + } +#ifdef HW_RVL + else { + if(ext_font_ttf != NULL) { + HaltGui(); + DeinitFreeType(); + mem2_free(ext_font_ttf); + ext_font_ttf = NULL; + InitFreeType((u8*)font_ttf, font_ttf_size); + } + } +#endif + HaltGui(); + ResetText(); + currentLanguage = GCSettings.language; + ResumeGui(); +} + /**************************************************************************** * WindowPrompt * @@ -3735,6 +3792,7 @@ static int MenuSettingsMenu() int i = 0; bool firstRun = true; OptionList options; + currentLanguage = GCSettings.language; sprintf(options.name[i++], "Exit Action"); sprintf(options.name[i++], "Wiimote Orientation"); @@ -3822,9 +3880,7 @@ static int MenuSettingsMenu() GCSettings.language = LANG_JAPANESE; if(GCSettings.language == LANG_SIMP_CHINESE) - GCSettings.language = LANG_PORTUGUESE; - else if(GCSettings.language == LANG_JAPANESE) - GCSettings.language = LANG_ENGLISH; + GCSettings.language = LANG_KOREAN; break; case 6: @@ -3920,11 +3976,11 @@ static int MenuSettingsMenu() menu = MENU_SETTINGS; } } + ChangeLanguage(); HaltGui(); mainWindow->Remove(&optionBrowser); mainWindow->Remove(&w); mainWindow->Remove(&titleTxt); - ResetText(); return menu; } diff --git a/source/menu.h b/source/menu.h index ca3edde..f96f393 100644 --- a/source/menu.h +++ b/source/menu.h @@ -21,7 +21,7 @@ void InfoPrompt(const char * msg); void ShowAction (const char *msg); void CancelAction(); void ShowProgress (const char *msg, int done, int total); -void ResetText(); +void ChangeLanguage(); enum { diff --git a/source/preferences.cpp b/source/preferences.cpp index 6d3fced..695e5ef 100644 --- a/source/preferences.cpp +++ b/source/preferences.cpp @@ -624,6 +624,6 @@ bool LoadPrefs() } - ResetText(); + ChangeLanguage(); return prefFound; }