diff options
Diffstat (limited to 'src/libui_sdl')
-rw-r--r-- | src/libui_sdl/CMakeLists.txt | 13 | ||||
-rw-r--r-- | src/libui_sdl/DlgInputConfig.cpp | 6 | ||||
-rw-r--r-- | src/libui_sdl/Platform.cpp | 71 | ||||
-rw-r--r-- | src/libui_sdl/PlatformConfig.cpp | 32 | ||||
-rw-r--r-- | src/libui_sdl/PlatformConfig.h | 2 | ||||
-rw-r--r-- | src/libui_sdl/main.cpp | 267 |
6 files changed, 306 insertions, 85 deletions
diff --git a/src/libui_sdl/CMakeLists.txt b/src/libui_sdl/CMakeLists.txt index 64206bf..8c8467b 100644 --- a/src/libui_sdl/CMakeLists.txt +++ b/src/libui_sdl/CMakeLists.txt @@ -31,6 +31,11 @@ target_link_libraries(melonDS core ${SDL2_LIBRARIES} libui) if (UNIX) + option(UNIX_PORTABLE "Make a portable build that looks for its configuration in the current directory" OFF) + if (UNIX_PORTABLE) + add_definitions(-DUNIX_PORTABLE) + endif() + find_package(PkgConfig REQUIRED) pkg_check_modules(GTK3 REQUIRED gtk+-3.0) pkg_check_modules(SDL2 REQUIRED sdl2) @@ -61,4 +66,12 @@ elseif (WIN32) target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi) endif () +install(FILES ../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) +install(FILES ../../icon/melon_16x16.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/16x16/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../icon/melon_32x32.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/32x32/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../icon/melon_48x48.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/48x48/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../icon/melon_64x64.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/64x64/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../icon/melon_128x128.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/128x128/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../icon/melon_256x256.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/256x256/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../romlist.bin DESTINATION ${CMAKE_INSTALL_PREFIX}/share/melonDS) install(TARGETS melonDS RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) diff --git a/src/libui_sdl/DlgInputConfig.cpp b/src/libui_sdl/DlgInputConfig.cpp index a80e2ec..21394b1 100644 --- a/src/libui_sdl/DlgInputConfig.cpp +++ b/src/libui_sdl/DlgInputConfig.cpp @@ -71,7 +71,9 @@ char hotkeylabels[HK_MAX][32] = "Pause/resume:", "Reset:", "Fast forward:", - "Fast forward (toggle):" + "Fast forward (toggle):", + "Decrease sunlight (Boktai):", + "Increase sunlight (Boktai):" }; int openedmask; @@ -514,7 +516,7 @@ void Open(int type) memcpy(dlg->keymap, Config::HKKeyMapping, sizeof(int)*HK_MAX); memcpy(dlg->joymap, Config::HKJoyMapping, sizeof(int)*HK_MAX); - dlg->win = uiNewWindow("Hotkey config - melonDS", 600, 100, 0, 0, 0); + dlg->win = uiNewWindow("Hotkey config - melonDS", 700, 100, 0, 0, 0); } uiControl(dlg->win)->UserData = dlg; diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp index 94b3791..cc1b734 100644 --- a/src/libui_sdl/Platform.cpp +++ b/src/libui_sdl/Platform.cpp @@ -135,6 +135,66 @@ FILE* OpenFile(const char* path, const char* mode, bool mustexist) return ret; } +#if !defined(UNIX_PORTABLE) && !defined(__WIN32__) + +FILE* OpenLocalFile(const char* path, const char* mode) +{ + std::string fullpath; + if (path[0] == '/') + { + // If it's an absolute path, just open that. + fullpath = std::string(path); + } + else + { + // Check user configuration directory + std::string confpath = std::string(g_get_user_config_dir()) + "/melonDS/"; + g_mkdir_with_parents(confpath.c_str(), 0755); + fullpath = confpath + path; + } + + return OpenFile(fullpath.c_str(), mode, mode[0] != 'w'); +} + +FILE* OpenDataFile(const char* path) +{ + const char* melondir = "melonDS"; + const char* const* sys_dirs = g_get_system_data_dirs(); + const char* user_dir = g_get_user_data_dir(); + + // First check the user's data directory + char* fullpath = g_build_path("/", user_dir, melondir, path, NULL); + if (access(fullpath, R_OK) == 0) + { + FILE* f = fopen(fullpath, "r"); + g_free(fullpath); + return f; + } + free(fullpath); + + // Then check the system data directories + for (size_t i = 0; sys_dirs[i] != NULL; i++) + { + const char* dir = sys_dirs[i]; + char* fullpath = g_build_path("/", dir, melondir, path, NULL); + + if (access(fullpath, R_OK) == 0) + { + FILE* f = fopen(fullpath, "r"); + g_free(fullpath); + return f; + } + free(fullpath); + } + + FILE* f = fopen(path, "rb"); + if (f) return f; + + return NULL; +} + +#else + FILE* OpenLocalFile(const char* path, const char* mode) { bool relpath = false; @@ -178,7 +238,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) emudirpath[pathlen] = '\0'; } - // Locations are application directory, and AppData/melonDS on Windows or XDG_CONFIG_HOME/melonds on Linux + // Locations are application directory, and AppData/melonDS on Windows or XDG_CONFIG_HOME/melonDS on Linux FILE* f; @@ -240,7 +300,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) { // Now check XDG_CONFIG_HOME // TODO: check for memory leak there - std::string fullpath = std::string(g_get_user_config_dir()) + "/melonds/" + path; + std::string fullpath = std::string(g_get_user_config_dir()) + "/melonDS/" + path; f = OpenFile(fullpath.c_str(), mode, true); if (f) { delete[] emudirpath; return f; } } @@ -257,6 +317,13 @@ FILE* OpenLocalFile(const char* path, const char* mode) return NULL; } +FILE* OpenDataFile(const char* path) +{ + return OpenLocalFile(path, "rb"); +} + +#endif + void* Thread_Create(void (*func)()) { diff --git a/src/libui_sdl/PlatformConfig.cpp b/src/libui_sdl/PlatformConfig.cpp index c8ec19f..a2eaab9 100644 --- a/src/libui_sdl/PlatformConfig.cpp +++ b/src/libui_sdl/PlatformConfig.cpp @@ -93,25 +93,29 @@ ConfigEntry PlatformConfigFile[] = {"Joy_X", 0, &JoyMapping[10], -1, NULL, 0}, {"Joy_Y", 0, &JoyMapping[11], -1, NULL, 0}, - {"HKKey_Lid", 0, &HKKeyMapping[HK_Lid], 0x0D, NULL, 0}, - {"HKKey_Mic", 0, &HKKeyMapping[HK_Mic], 0x35, NULL, 0}, - {"HKKey_Pause", 0, &HKKeyMapping[HK_Pause], -1, NULL, 0}, - {"HKKey_Reset", 0, &HKKeyMapping[HK_Reset], -1, NULL, 0}, - {"HKKey_FastForward", 0, &HKKeyMapping[HK_FastForward], 0x0F, NULL, 0}, - {"HKKey_FastForwardToggle", 0, &HKKeyMapping[HK_FastForwardToggle], -1, NULL, 0}, - - {"HKJoy_Lid", 0, &HKJoyMapping[HK_Lid], -1, NULL, 0}, - {"HKJoy_Mic", 0, &HKJoyMapping[HK_Mic], -1, NULL, 0}, - {"HKJoy_Pause", 0, &HKJoyMapping[HK_Pause], -1, NULL, 0}, - {"HKJoy_Reset", 0, &HKJoyMapping[HK_Reset], -1, NULL, 0}, - {"HKJoy_FastForward", 0, &HKJoyMapping[HK_FastForward], -1, NULL, 0}, - {"HKJoy_FastForwardToggle", 0, &HKJoyMapping[HK_FastForwardToggle], -1, NULL, 0}, + {"HKKey_Lid", 0, &HKKeyMapping[HK_Lid], 0x0D, NULL, 0}, + {"HKKey_Mic", 0, &HKKeyMapping[HK_Mic], 0x35, NULL, 0}, + {"HKKey_Pause", 0, &HKKeyMapping[HK_Pause], -1, NULL, 0}, + {"HKKey_Reset", 0, &HKKeyMapping[HK_Reset], -1, NULL, 0}, + {"HKKey_FastForward", 0, &HKKeyMapping[HK_FastForward], 0x0F, NULL, 0}, + {"HKKey_FastForwardToggle", 0, &HKKeyMapping[HK_FastForwardToggle], -1, NULL, 0}, + {"HKKey_SolarSensorDecrease", 0, &HKKeyMapping[HK_SolarSensorDecrease], 0x4B, NULL, 0}, + {"HKKey_SolarSensorIncrease", 0, &HKKeyMapping[HK_SolarSensorIncrease], 0x4D, NULL, 0}, + + {"HKJoy_Lid", 0, &HKJoyMapping[HK_Lid], -1, NULL, 0}, + {"HKJoy_Mic", 0, &HKJoyMapping[HK_Mic], -1, NULL, 0}, + {"HKJoy_Pause", 0, &HKJoyMapping[HK_Pause], -1, NULL, 0}, + {"HKJoy_Reset", 0, &HKJoyMapping[HK_Reset], -1, NULL, 0}, + {"HKJoy_FastForward", 0, &HKJoyMapping[HK_FastForward], -1, NULL, 0}, + {"HKJoy_FastForwardToggle", 0, &HKJoyMapping[HK_FastForwardToggle], -1, NULL, 0}, + {"HKJoy_SolarSensorDecrease", 0, &HKJoyMapping[HK_SolarSensorDecrease], -1, NULL, 0}, + {"HKJoy_SolarSensorIncrease", 0, &HKJoyMapping[HK_SolarSensorIncrease], -1, NULL, 0}, {"JoystickID", 0, &JoystickID, 0, NULL, 0}, {"WindowWidth", 0, &WindowWidth, 256, NULL, 0}, {"WindowHeight", 0, &WindowHeight, 384, NULL, 0}, - {"WindowMax", 0, &WindowMaximized, 0, NULL, 0}, + {"WindowMax", 0, &WindowMaximized, 0, NULL, 0}, {"ScreenRotation", 0, &ScreenRotation, 0, NULL, 0}, {"ScreenGap", 0, &ScreenGap, 0, NULL, 0}, diff --git a/src/libui_sdl/PlatformConfig.h b/src/libui_sdl/PlatformConfig.h index 842e72a..682b9bc 100644 --- a/src/libui_sdl/PlatformConfig.h +++ b/src/libui_sdl/PlatformConfig.h @@ -29,6 +29,8 @@ enum HK_Reset, HK_FastForward, HK_FastForwardToggle, + HK_SolarSensorDecrease, + HK_SolarSensorIncrease, HK_MAX }; diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index d6aa460..130c8f9 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -21,6 +21,10 @@ #include <stdio.h> #include <string.h> +#ifndef __WIN32__ +#include <glib.h> +#endif + #include <SDL2/SDL.h> #include "libui/ui.h" @@ -38,6 +42,7 @@ #include "DlgWifiSettings.h" #include "../NDS.h" +#include "../GBACart.h" #include "../GPU.h" #include "../SPU.h" #include "../Wifi.h" @@ -105,9 +110,9 @@ int EmuRunning; volatile int EmuStatus; bool RunningSomething; -char ROMPath[1024]; -char SRAMPath[1024]; -char PrevSRAMPath[1024]; // for savestate 'undo load' +char ROMPath[2][1024]; +char SRAMPath[2][1024]; +char PrevSRAMPath[2][1024]; // for savestate 'undo load' bool SavestateLoaded; @@ -184,7 +189,7 @@ void SetupScreenRects(int width, int height); void TogglePause(void* blarg); void Reset(void* blarg); -void SetupSRAMPath(); +void SetupSRAMPath(int slot); void SaveState(int slot); void LoadState(int slot); @@ -886,7 +891,10 @@ bool JoyButtonHeld(int btnid, int njoybuttons, Uint8* joybuttons, Uint32 hat) void UpdateWindowTitle(void* data) { if (EmuStatus == 0) return; - uiWindowSetTitle(MainWindow, (const char*)data); + void** dataarray = (void**)data; + SDL_LockMutex((SDL_mutex*)dataarray[1]); + uiWindowSetTitle(MainWindow, (const char*)dataarray[0]); + SDL_UnlockMutex((SDL_mutex*)dataarray[1]); } void UpdateFPSLimit(void* data) @@ -932,7 +940,10 @@ int EmuThreadFunc(void* burp) u64 perffreq = SDL_GetPerformanceFrequency(); float samplesleft = 0; u32 nsamples = 0; + char melontitle[100]; + SDL_mutex* titlemutex = SDL_CreateMutex(); + void* titledata[2] = {melontitle, titlemutex}; while (EmuRunning != 0) { @@ -948,6 +959,24 @@ int EmuThreadFunc(void* burp) if (HotkeyPressed(HK_Pause)) uiQueueMain(TogglePause, NULL); if (HotkeyPressed(HK_Reset)) uiQueueMain(Reset, NULL); + if (GBACart::CartInserted && GBACart::HasSolarSensor) + { + if (HotkeyPressed(HK_SolarSensorDecrease)) + { + if (GBACart_SolarSensor::LightLevel > 0) GBACart_SolarSensor::LightLevel--; + char msg[64]; + sprintf(msg, "Solar sensor level set to %d", GBACart_SolarSensor::LightLevel); + OSD::AddMessage(0, msg); + } + if (HotkeyPressed(HK_SolarSensorIncrease)) + { + if (GBACart_SolarSensor::LightLevel < 10) GBACart_SolarSensor::LightLevel++; + char msg[64]; + sprintf(msg, "Solar sensor level set to %d", GBACart_SolarSensor::LightLevel); + OSD::AddMessage(0, msg); + } + } + if (EmuRunning == 1) { EmuStatus = 1; @@ -1056,6 +1085,11 @@ int EmuThreadFunc(void* burp) starttick = lasttick; } } + else + { + if (delay < 1) SDL_Delay(1); + lasttick = SDL_GetTicks(); + } } nframes++; @@ -1074,8 +1108,10 @@ int EmuThreadFunc(void* burp) if (framerate < 1) fpstarget = 999; else fpstarget = 1000.0f/framerate; + SDL_LockMutex(titlemutex); sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, fpstarget); - uiQueueMain(UpdateWindowTitle, melontitle); + SDL_UnlockMutex(titlemutex); + uiQueueMain(UpdateWindowTitle, titledata); } } else @@ -1109,6 +1145,8 @@ int EmuThreadFunc(void* burp) EmuStatus = 0; + SDL_DestroyMutex(titlemutex); + if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); NDS::DeInit(); @@ -1648,12 +1686,18 @@ void Reset(void* blarg) SavestateLoaded = false; uiMenuItemDisable(MenuItem_UndoStateLoad); - if (ROMPath[0] == '\0') + if (ROMPath[0][0] == '\0') NDS::LoadBIOS(); else { - SetupSRAMPath(); - NDS::LoadROM(ROMPath, SRAMPath, Config::DirectBoot); + SetupSRAMPath(0); + NDS::LoadROM(ROMPath[0], SRAMPath[0], Config::DirectBoot); + } + + if (ROMPath[1][0] != '\0') + { + SetupSRAMPath(1); + NDS::LoadGBAROM(ROMPath[1], SRAMPath[1]); } Run(); @@ -1668,6 +1712,10 @@ void Stop(bool internal) while (EmuStatus != 2); RunningSomething = false; + // eject any inserted GBA cartridge + GBACart::Eject(); + ROMPath[1][0] = '\0'; + uiWindowSetTitle(MainWindow, "melonDS " MELONDS_VERSION); for (int i = 0; i < 9; i++) uiMenuItemDisable(MenuItem_SaveStateSlot[i]); @@ -1688,41 +1736,53 @@ void Stop(bool internal) OSD::AddMessage(0xFFC040, "Shutdown"); } -void SetupSRAMPath() +void SetupSRAMPath(int slot) { - strncpy(SRAMPath, ROMPath, 1023); - SRAMPath[1023] = '\0'; - strncpy(SRAMPath + strlen(ROMPath) - 3, "sav", 3); + strncpy(SRAMPath[slot], ROMPath[slot], 1023); + SRAMPath[slot][1023] = '\0'; + strncpy(SRAMPath[slot] + strlen(ROMPath[slot]) - 3, "sav", 3); } -void TryLoadROM(char* file, int prevstatus) +void TryLoadROM(char* file, int slot, int prevstatus) { char oldpath[1024]; char oldsram[1024]; - strncpy(oldpath, ROMPath, 1024); - strncpy(oldsram, SRAMPath, 1024); + strncpy(oldpath, ROMPath[slot], 1024); + strncpy(oldsram, SRAMPath[slot], 1024); - strncpy(ROMPath, file, 1023); - ROMPath[1023] = '\0'; + strncpy(ROMPath[slot], file, 1023); + ROMPath[slot][1023] = '\0'; - SetupSRAMPath(); + SetupSRAMPath(0); + SetupSRAMPath(1); - if (NDS::LoadROM(ROMPath, SRAMPath, Config::DirectBoot)) + if (slot == 0 && NDS::LoadROM(ROMPath[slot], SRAMPath[slot], Config::DirectBoot)) { SavestateLoaded = false; uiMenuItemDisable(MenuItem_UndoStateLoad); - strncpy(PrevSRAMPath, SRAMPath, 1024); // safety + // Reload the inserted GBA cartridge (if any) + if (ROMPath[1][0] != '\0') NDS::LoadGBAROM(ROMPath[1], SRAMPath[1]); + + strncpy(PrevSRAMPath[slot], SRAMPath[slot], 1024); // safety Run(); } + else if (slot == 1 && NDS::LoadGBAROM(ROMPath[slot], SRAMPath[slot])) + { + SavestateLoaded = false; + uiMenuItemDisable(MenuItem_UndoStateLoad); + + strncpy(PrevSRAMPath[slot], SRAMPath[slot], 1024); // safety + if (RunningSomething) Run(); // do not start just from a GBA cart + } else { uiMsgBoxError(MainWindow, "Failed to load the ROM", "Make sure the file can be accessed and isn't opened in another application."); - strncpy(ROMPath, oldpath, 1024); - strncpy(SRAMPath, oldsram, 1024); + strncpy(ROMPath[slot], oldpath, 1024); + strncpy(SRAMPath[slot], oldsram, 1024); EmuRunning = prevstatus; } } @@ -1735,22 +1795,22 @@ void GetSavestateName(int slot, char* filename, int len) { int pos; - if (ROMPath[0] == '\0') // running firmware, no ROM + if (ROMPath[0][0] == '\0') // running firmware, no ROM { strcpy(filename, "firmware"); pos = 8; } else { - int l = strlen(ROMPath); + int l = strlen(ROMPath[0]); pos = l; - while (ROMPath[pos] != '.' && pos > 0) pos--; + while (ROMPath[0][pos] != '.' && pos > 0) pos--; if (pos == 0) pos = l; // avoid buffer overflow. shoddy if (pos > len-5) pos = len-5; - strncpy(&filename[0], ROMPath, pos); + strncpy(&filename[0], ROMPath[0], pos); } strcpy(&filename[pos], ".ml"); filename[pos+3] = '0'+slot; @@ -1794,6 +1854,8 @@ void LoadState(int slot) return; } + u32 oldGBACartCRC = GBACart::CartCRC; + // backup Savestate* backup = new Savestate("timewarp.mln", true); NDS::DoSavestate(backup); @@ -1818,21 +1880,36 @@ void LoadState(int slot) if (!failed) { - if (Config::SavestateRelocSRAM && ROMPath[0]!='\0') + if (Config::SavestateRelocSRAM && ROMPath[0][0]!='\0') { - strncpy(PrevSRAMPath, SRAMPath, 1024); + strncpy(PrevSRAMPath[0], SRAMPath[0], 1024); - strncpy(SRAMPath, filename, 1019); - int len = strlen(SRAMPath); - strcpy(&SRAMPath[len], ".sav"); - SRAMPath[len+4] = '\0'; + strncpy(SRAMPath[0], filename, 1019); + int len = strlen(SRAMPath[0]); + strcpy(&SRAMPath[0][len], ".sav"); + SRAMPath[0][len+4] = '\0'; - NDS::RelocateSave(SRAMPath, false); + NDS::RelocateSave(SRAMPath[0], false); + } + + bool loadedPartialGBAROM = false; + + // in case we have a GBA cart inserted, and the GBA ROM changes + // due to having loaded a save state, we do not want to reload + // the previous cartridge on reset, or commit writes to any + // loaded save file. therefore, their paths are "nulled". + if (GBACart::CartInserted && GBACart::CartCRC != oldGBACartCRC) + { + ROMPath[1][0] = '\0'; + SRAMPath[1][0] = '\0'; + loadedPartialGBAROM = true; } char msg[64]; - if (slot > 0) sprintf(msg, "State loaded from slot %d", slot); - else sprintf(msg, "State loaded from file"); + if (slot > 0) sprintf(msg, "State loaded from slot %d%s", + slot, loadedPartialGBAROM ? " (GBA ROM header only)" : ""); + else sprintf(msg, "State loaded from file%s", + loadedPartialGBAROM ? " (GBA ROM header only)" : ""); OSD::AddMessage(0, msg); SavestateLoaded = true; @@ -1883,14 +1960,14 @@ void SaveState(int slot) if (slot > 0) uiMenuItemEnable(MenuItem_LoadStateSlot[slot-1]); - if (Config::SavestateRelocSRAM && ROMPath[0]!='\0') + if (Config::SavestateRelocSRAM && ROMPath[0][0]!='\0') { - strncpy(SRAMPath, filename, 1019); - int len = strlen(SRAMPath); - strcpy(&SRAMPath[len], ".sav"); - SRAMPath[len+4] = '\0'; + strncpy(SRAMPath[0], filename, 1019); + int len = strlen(SRAMPath[0]); + strcpy(&SRAMPath[0][len], ".sav"); + SRAMPath[0][len+4] = '\0'; - NDS::RelocateSave(SRAMPath, true); + NDS::RelocateSave(SRAMPath[0], true); } } @@ -1917,10 +1994,10 @@ void UndoStateLoad() NDS::DoSavestate(backup); delete backup; - if (ROMPath[0]!='\0') + if (ROMPath[0][0]!='\0') { - strncpy(SRAMPath, PrevSRAMPath, 1024); - NDS::RelocateSave(SRAMPath, false); + strncpy(SRAMPath[0], PrevSRAMPath[0], 1024); + NDS::RelocateSave(SRAMPath[0], false); } OSD::AddMessage(0, "State load undone"); @@ -1964,7 +2041,11 @@ void OnDropFile(uiWindow* window, char* file, void* blarg) while (EmuStatus != 2); } - TryLoadROM(file, prevstatus); + TryLoadROM(file, 0, prevstatus); + } + else if (!strcasecmp(ext, "gba")) + { + TryLoadROM(file, 1, prevstatus); } } @@ -1995,7 +2076,7 @@ void OnOpenFile(uiMenuItem* item, uiWindow* window, void* blarg) EmuRunning = 2; while (EmuStatus != 2); - char* file = uiOpenFile(window, "DS ROM (*.nds)|*.nds;*.srl|Any file|*.*", Config::LastROMFolder); + char* file = uiOpenFile(window, "DS ROM (*.nds)|*.nds;*.srl|GBA ROM (*.gba)|*.gba|Any file|*.*", Config::LastROMFolder); if (!file) { EmuRunning = prevstatus; @@ -2006,8 +2087,17 @@ void OnOpenFile(uiMenuItem* item, uiWindow* window, void* blarg) while (file[pos] != '/' && file[pos] != '\\' && pos > 0) pos--; strncpy(Config::LastROMFolder, file, pos); Config::LastROMFolder[pos] = '\0'; + char* ext = &file[strlen(file)-3]; + + if (!strcasecmp(ext, "gba")) + { + TryLoadROM(file, 1, prevstatus); + } + else + { + TryLoadROM(file, 0, prevstatus); + } - TryLoadROM(file, prevstatus); uiFreeText(file); } @@ -2032,8 +2122,14 @@ void OnRun(uiMenuItem* item, uiWindow* window, void* blarg) { if (!RunningSomething) { - ROMPath[0] = '\0'; + ROMPath[0][0] = '\0'; NDS::LoadBIOS(); + + if (ROMPath[1][0] != '\0') + { + SetupSRAMPath(1); + NDS::LoadGBAROM(ROMPath[1], SRAMPath[1]); + } } Run(); @@ -2589,6 +2685,7 @@ int main(int argc, char** argv) printf("melonDS " MELONDS_VERSION "\n"); printf(MELONDS_URL "\n"); +#if defined(__WIN32__) || defined(UNIX_PORTABLE) if (argc > 0 && strlen(argv[0]) > 0) { int len = strlen(argv[0]); @@ -2615,6 +2712,13 @@ int main(int argc, char** argv) EmuDirectory = new char[2]; strcpy(EmuDirectory, "."); } +#else + const char* confdir = g_get_user_config_dir(); + const char* confname = "/melonds"; + EmuDirectory = new char[strlen(confdir) + strlen(confname) + 1]; + strcat(EmuDirectory, confdir); + strcat(EmuDirectory, confname); +#endif // http://stackoverflow.com/questions/14543333/joystick-wont-work-using-sdl SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); @@ -2650,15 +2754,23 @@ int main(int argc, char** argv) !Platform::LocalFileExists("bios9.bin") || !Platform::LocalFileExists("firmware.bin")) { - uiMsgBoxError( - NULL, - "BIOS/Firmware not found", +#if defined(__WIN32__) || defined(UNIX_PORTABLE) + const char* locationName = "the directory you run melonDS from"; +#else + char* locationName = EmuDirectory; +#endif + char msgboxtext[512]; + sprintf(msgboxtext, "One or more of the following required files don't exist or couldn't be accessed:\n\n" "bios7.bin -- ARM7 BIOS\n" "bios9.bin -- ARM9 BIOS\n" "firmware.bin -- firmware image\n\n" - "Dump the files from your DS and place them in the directory you run melonDS from.\n" - "Make sure that the files can be accessed."); + "Dump the files from your DS and place them in %s.\n" + "Make sure that the files can be accessed.", + locationName + ); + + uiMsgBoxError(NULL, "BIOS/Firmware not found", msgboxtext); uiUninit(); SDL_Quit(); @@ -2704,7 +2816,18 @@ int main(int argc, char** argv) } } { - FILE* f = Platform::OpenLocalFile("romlist.bin", "rb"); + const char* romlist_missing = "Save memory type detection will not work correctly.\n\n" + "You should use the latest version of romlist.bin (provided in melonDS release packages)."; +#if !defined(UNIX_PORTABLE) && !defined(__WIN32__) + std::string missingstr = std::string(romlist_missing) + + "\n\nThe ROM list should be placed in " + g_get_user_data_dir() + "/melonds/, otherwise " + "melonDS will search for it in the current working directory."; + const char* romlist_missing_text = missingstr.c_str(); +#else + const char* romlist_missing_text = romlist_missing; +#endif + + FILE* f = Platform::OpenDataFile("romlist.bin"); if (f) { u32 data; @@ -2713,18 +2836,12 @@ int main(int argc, char** argv) if ((data >> 24) == 0) // old CRC-based list { - uiMsgBoxError(NULL, - "Your version of romlist.bin is outdated.", - "Save memory type detection will not work correctly.\n\n" - "You should use the latest version of romlist.bin (provided in melonDS release packages)."); + uiMsgBoxError(NULL, "Your version of romlist.bin is outdated.", romlist_missing_text); } } else { - uiMsgBoxError(NULL, - "romlist.bin not found.", - "Save memory type detection will not work correctly.\n\n" - "You should use the latest version of romlist.bin (provided in melonDS release packages)."); + uiMsgBoxError(NULL, "romlist.bin not found.", romlist_missing_text); } } @@ -2852,14 +2969,30 @@ int main(int argc, char** argv) if (!strcasecmp(ext, "nds") || !strcasecmp(ext, "srl")) { - strncpy(ROMPath, file, 1023); - ROMPath[1023] = '\0'; + strncpy(ROMPath[0], file, 1023); + ROMPath[0][1023] = '\0'; - SetupSRAMPath(); + SetupSRAMPath(0); - if (NDS::LoadROM(ROMPath, SRAMPath, Config::DirectBoot)) + if (NDS::LoadROM(ROMPath[0], SRAMPath[0], Config::DirectBoot)) Run(); } + + if (argc > 2) + { + file = argv[2]; + ext = &file[strlen(file)-3]; + + if (!strcasecmp(ext, "gba")) + { + strncpy(ROMPath[1], file, 1023); + ROMPath[1][1023] = '\0'; + + SetupSRAMPath(1); + + NDS::LoadGBAROM(ROMPath[1], SRAMPath[1]); + } + } } uiMain(); |