From 1e715272b6d7f0aa11347b21048ad301f908850a Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Tue, 7 Mar 2023 09:21:43 -0500 Subject: [PATCH] Add some directories to environment --- src/libretro/environment.hpp | 5 +++++ src/libretro/libretro.cpp | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/libretro/environment.hpp b/src/libretro/environment.hpp index d793e9e..7657d8c 100644 --- a/src/libretro/environment.hpp +++ b/src/libretro/environment.hpp @@ -5,6 +5,8 @@ #ifndef MELONDS_DS_ENVIRONMENT_HPP #define MELONDS_DS_ENVIRONMENT_HPP +#include + namespace retro { /// For use by other parts of the core bool environment(unsigned cmd, void *data); @@ -12,6 +14,9 @@ namespace retro { void log(enum retro_log_level level, const char *fmt, ...); bool supports_bitmasks(); + + const std::string& base_directory(); + const std::string& save_directory(); } #endif //MELONDS_DS_ENVIRONMENT_HPP diff --git a/src/libretro/libretro.cpp b/src/libretro/libretro.cpp index 3c0ec74..530c6b8 100644 --- a/src/libretro/libretro.cpp +++ b/src/libretro/libretro.cpp @@ -1,9 +1,24 @@ #include +#include "environment.hpp" #include "libretro.hpp" -PUBLIC_SYMBOL void retro_init(void) { +namespace retro { + static std::string _base_directory; + static std::string _save_directory; +} + + +PUBLIC_SYMBOL void retro_init(void) { + const char *dir = nullptr; + + srand(time(nullptr)); + if (retro::environment(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir) + retro::_base_directory = dir; + + if (retro::environment(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir) + retro::_save_directory = dir; } PUBLIC_SYMBOL void retro_deinit(void) {