aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl
diff options
context:
space:
mode:
Diffstat (limited to 'src/libui_sdl')
-rw-r--r--src/libui_sdl/CMakeLists.txt31
-rw-r--r--src/libui_sdl/DlgAudioSettings.cpp2
-rw-r--r--src/libui_sdl/DlgAudioSettings.h2
-rw-r--r--src/libui_sdl/DlgEmuSettings.cpp2
-rw-r--r--src/libui_sdl/DlgEmuSettings.h2
-rw-r--r--src/libui_sdl/DlgInputConfig.cpp8
-rw-r--r--src/libui_sdl/DlgInputConfig.h2
-rw-r--r--src/libui_sdl/DlgVideoSettings.cpp2
-rw-r--r--src/libui_sdl/DlgVideoSettings.h2
-rw-r--r--src/libui_sdl/DlgWifiSettings.cpp2
-rw-r--r--src/libui_sdl/DlgWifiSettings.h2
-rw-r--r--src/libui_sdl/LAN_PCap.cpp26
-rw-r--r--src/libui_sdl/LAN_PCap.h2
-rw-r--r--src/libui_sdl/LAN_Socket.cpp2
-rw-r--r--src/libui_sdl/LAN_Socket.h2
-rw-r--r--src/libui_sdl/MelonCap.cpp6
-rw-r--r--src/libui_sdl/MelonCap.h2
-rw-r--r--src/libui_sdl/OSD.cpp2
-rw-r--r--src/libui_sdl/OSD.h2
-rw-r--r--src/libui_sdl/Platform.cpp73
-rw-r--r--src/libui_sdl/PlatformConfig.cpp34
-rw-r--r--src/libui_sdl/PlatformConfig.h4
-rw-r--r--src/libui_sdl/font.h2
-rw-r--r--src/libui_sdl/main.cpp250
-rw-r--r--src/libui_sdl/main_shaders.h2
25 files changed, 337 insertions, 129 deletions
diff --git a/src/libui_sdl/CMakeLists.txt b/src/libui_sdl/CMakeLists.txt
index 64206bf..a3a7f8a 100644
--- a/src/libui_sdl/CMakeLists.txt
+++ b/src/libui_sdl/CMakeLists.txt
@@ -22,23 +22,24 @@ option(BUILD_SHARED_LIBS "Whether to build libui as a shared library or a static
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(libui)
-find_package(SDL2 REQUIRED)
-include_directories(${SDL2_INCLUDE_DIR})
-#string(STRIP ${SDL2_LIBRARIES} SDL2_LIBRARIES)
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(SDL2 REQUIRED sdl2)
add_executable(melonDS ${SOURCES_LIBUI})
-target_link_libraries(melonDS
- core ${SDL2_LIBRARIES} libui)
+target_include_directories(melonDS PRIVATE ${SDL2_INCLUDE_DIRS})
+target_link_libraries(melonDS core libui ${SDL2_LIBRARIES})
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)
- target_include_directories(melonDS
- PRIVATE ${GTK3_INCLUDE_DIRS} ${SDL2_INCLUDE_DIRS}
- )
- target_link_libraries(melonDS ${GTK3_LIBRARIES} ${SDL2_LIBRARIES})
+ target_include_directories(melonDS PRIVATE ${GTK3_INCLUDE_DIRS})
+ target_link_libraries(melonDS ${GTK3_LIBRARIES})
ADD_DEFINITIONS(${GTK3_CFLAGS_OTHER})
@@ -58,7 +59,15 @@ if (UNIX)
elseif (WIN32)
target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc")
target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
- target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi)
+ target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32)
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/DlgAudioSettings.cpp b/src/libui_sdl/DlgAudioSettings.cpp
index d649321..43836ae 100644
--- a/src/libui_sdl/DlgAudioSettings.cpp
+++ b/src/libui_sdl/DlgAudioSettings.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/DlgAudioSettings.h b/src/libui_sdl/DlgAudioSettings.h
index f058c25..7a5afcc 100644
--- a/src/libui_sdl/DlgAudioSettings.h
+++ b/src/libui_sdl/DlgAudioSettings.h
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/DlgEmuSettings.cpp b/src/libui_sdl/DlgEmuSettings.cpp
index 768560d..c50f216 100644
--- a/src/libui_sdl/DlgEmuSettings.cpp
+++ b/src/libui_sdl/DlgEmuSettings.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/DlgEmuSettings.h b/src/libui_sdl/DlgEmuSettings.h
index baff7ce..d937448 100644
--- a/src/libui_sdl/DlgEmuSettings.h
+++ b/src/libui_sdl/DlgEmuSettings.h
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/DlgInputConfig.cpp b/src/libui_sdl/DlgInputConfig.cpp
index a80e2ec..f4245b4 100644
--- a/src/libui_sdl/DlgInputConfig.cpp
+++ b/src/libui_sdl/DlgInputConfig.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
@@ -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/DlgInputConfig.h b/src/libui_sdl/DlgInputConfig.h
index 94c7325..89ac034 100644
--- a/src/libui_sdl/DlgInputConfig.h
+++ b/src/libui_sdl/DlgInputConfig.h
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/DlgVideoSettings.cpp b/src/libui_sdl/DlgVideoSettings.cpp
index ff88ba8..1062be1 100644
--- a/src/libui_sdl/DlgVideoSettings.cpp
+++ b/src/libui_sdl/DlgVideoSettings.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/DlgVideoSettings.h b/src/libui_sdl/DlgVideoSettings.h
index 25a938f..17072e0 100644
--- a/src/libui_sdl/DlgVideoSettings.h
+++ b/src/libui_sdl/DlgVideoSettings.h
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/DlgWifiSettings.cpp b/src/libui_sdl/DlgWifiSettings.cpp
index 09080a0..d1ce8bd 100644
--- a/src/libui_sdl/DlgWifiSettings.cpp
+++ b/src/libui_sdl/DlgWifiSettings.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/DlgWifiSettings.h b/src/libui_sdl/DlgWifiSettings.h
index 466ce10..a12cbfd 100644
--- a/src/libui_sdl/DlgWifiSettings.h
+++ b/src/libui_sdl/DlgWifiSettings.h
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/LAN_PCap.cpp b/src/libui_sdl/LAN_PCap.cpp
index c228f5e..ce278bc 100644
--- a/src/libui_sdl/LAN_PCap.cpp
+++ b/src/libui_sdl/LAN_PCap.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
@@ -133,7 +133,7 @@ bool Init(bool open_adapter)
return false;
}
}
-
+
PCapAdapter = NULL;
PacketLen = 0;
RXNum = 0;
@@ -172,7 +172,7 @@ bool Init(bool open_adapter)
#else
strncpy(adata->DeviceName, dev->name, 127);
adata->DeviceName[127] = '\0';
-
+
strncpy(adata->FriendlyName, adata->DeviceName, 127);
adata->FriendlyName[127] = '\0';
#endif // __WIN32__
@@ -250,7 +250,7 @@ bool Init(bool open_adapter)
printf("getifaddrs() shat itself :(\n");
return false;
}
-
+
for (int i = 0; i < NumAdapters; i++)
{
adata = &Adapters[i];
@@ -262,8 +262,14 @@ bool Init(bool open_adapter)
curaddr = curaddr->ifa_next;
continue;
}
- if (!curaddr->ifa_addr) continue;
-
+
+ if (!curaddr->ifa_addr)
+ {
+ printf("Device (%s) does not have an address :/\n", curaddr->ifa_name);
+ curaddr = curaddr->ifa_next;
+ continue;
+ }
+
u16 af = curaddr->ifa_addr->sa_family;
if (af == AF_INET)
{
@@ -273,23 +279,23 @@ bool Init(bool open_adapter)
else if (af == AF_PACKET)
{
struct sockaddr_ll* sa = (sockaddr_ll*)curaddr->ifa_addr;
- if (sa->sll_halen != 6)
+ if (sa->sll_halen != 6)
printf("weird MAC length %d for %s\n", sa->sll_halen, curaddr->ifa_name);
else
memcpy(adata->MAC, sa->sll_addr, 6);
}
-
+
curaddr = curaddr->ifa_next;
}
}
-
+
freeifaddrs(addrs);
#endif // __WIN32__
if (!open_adapter) return true;
if (PCapAdapter) pcap_close(PCapAdapter);
-
+
// open pcap device
PCapAdapterData = &Adapters[0];
for (int i = 0; i < NumAdapters; i++)
diff --git a/src/libui_sdl/LAN_PCap.h b/src/libui_sdl/LAN_PCap.h
index 6ca43e8..250b8e9 100644
--- a/src/libui_sdl/LAN_PCap.h
+++ b/src/libui_sdl/LAN_PCap.h
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/LAN_Socket.cpp b/src/libui_sdl/LAN_Socket.cpp
index a9f2cd7..c6fbd4b 100644
--- a/src/libui_sdl/LAN_Socket.cpp
+++ b/src/libui_sdl/LAN_Socket.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/LAN_Socket.h b/src/libui_sdl/LAN_Socket.h
index a0abe45..8453a5f 100644
--- a/src/libui_sdl/LAN_Socket.h
+++ b/src/libui_sdl/LAN_Socket.h
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/MelonCap.cpp b/src/libui_sdl/MelonCap.cpp
index fde440a..2658b66 100644
--- a/src/libui_sdl/MelonCap.cpp
+++ b/src/libui_sdl/MelonCap.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
@@ -336,8 +336,8 @@ void Update()
colA &= mask;
colB &= mask;
- if (colA == colB) WinBitmapData[(y*768) + x + 512] = 0xFF00FF00;
- else WinBitmapData[(y*768) + x + 512] = 0xFFFF0000;
+ if (colA == colB) WinBitmapData[(y*768) + x + 512] = 0xFF000000;//0xFF00FF00;
+ else WinBitmapData[(y*768) + x + 512] = 0xFFFFFFFF;//0xFFFF0000;
}
}
diff --git a/src/libui_sdl/MelonCap.h b/src/libui_sdl/MelonCap.h
index 1185dea..33a391b 100644
--- a/src/libui_sdl/MelonCap.h
+++ b/src/libui_sdl/MelonCap.h
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/OSD.cpp b/src/libui_sdl/OSD.cpp
index bd44e99..a01e39b 100644
--- a/src/libui_sdl/OSD.cpp
+++ b/src/libui_sdl/OSD.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/OSD.h b/src/libui_sdl/OSD.h
index afe403f..12294ea 100644
--- a/src/libui_sdl/OSD.h
+++ b/src/libui_sdl/OSD.h
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp
index 94b3791..54fa568 100644
--- a/src/libui_sdl/Platform.cpp
+++ b/src/libui_sdl/Platform.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
@@ -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..f78b195 100644
--- a/src/libui_sdl/PlatformConfig.cpp
+++ b/src/libui_sdl/PlatformConfig.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
@@ -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..9e02862 100644
--- a/src/libui_sdl/PlatformConfig.h
+++ b/src/libui_sdl/PlatformConfig.h
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
@@ -29,6 +29,8 @@ enum
HK_Reset,
HK_FastForward,
HK_FastForwardToggle,
+ HK_SolarSensorDecrease,
+ HK_SolarSensorIncrease,
HK_MAX
};
diff --git a/src/libui_sdl/font.h b/src/libui_sdl/font.h
index 8647b7a..f2e4f87 100644
--- a/src/libui_sdl/font.h
+++ b/src/libui_sdl/font.h
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp
index 13fb52a..53396e7 100644
--- a/src/libui_sdl/main.cpp
+++ b/src/libui_sdl/main.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.
@@ -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);
@@ -954,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;
@@ -1661,12 +1684,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();
@@ -1681,6 +1710,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]);
@@ -1701,41 +1734,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;
}
}
@@ -1748,22 +1793,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;
@@ -1807,6 +1852,8 @@ void LoadState(int slot)
return;
}
+ u32 oldGBACartCRC = GBACart::CartCRC;
+
// backup
Savestate* backup = new Savestate("timewarp.mln", true);
NDS::DoSavestate(backup);
@@ -1831,21 +1878,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[0], filename, 1019);
+ int len = strlen(SRAMPath[0]);
+ strcpy(&SRAMPath[0][len], ".sav");
+ SRAMPath[0][len+4] = '\0';
+
+ NDS::RelocateSave(SRAMPath[0], false);
+ }
- strncpy(SRAMPath, filename, 1019);
- int len = strlen(SRAMPath);
- strcpy(&SRAMPath[len], ".sav");
- SRAMPath[len+4] = '\0';
+ bool loadedPartialGBAROM = false;
- NDS::RelocateSave(SRAMPath, 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;
@@ -1896,14 +1958,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);
}
}
@@ -1930,10 +1992,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");
@@ -1977,7 +2039,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);
}
}
@@ -2008,7 +2074,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;
@@ -2019,8 +2085,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);
}
@@ -2045,8 +2120,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();
@@ -2602,6 +2683,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]);
@@ -2628,6 +2710,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");
@@ -2663,15 +2752,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();
@@ -2717,7 +2814,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;
@@ -2726,18 +2834,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);
}
}
@@ -2865,14 +2967,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();
diff --git a/src/libui_sdl/main_shaders.h b/src/libui_sdl/main_shaders.h
index 6504520..22d4dd9 100644
--- a/src/libui_sdl/main_shaders.h
+++ b/src/libui_sdl/main_shaders.h
@@ -1,5 +1,5 @@
/*
- Copyright 2016-2019 Arisotura
+ Copyright 2016-2020 Arisotura
This file is part of melonDS.