Skip to content

Commit

Permalink
Add option for setting emulator directories
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 23, 2025
1 parent 70ef5ce commit 5ebfd7d
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 73 deletions.
5 changes: 0 additions & 5 deletions platforms/shared/desktop/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ int application_init(const char* rom_file, const char* symbol_file)
int ret = sdl_init();
emu_init();

strcpy(emu_savefiles_path, config_emulator.savefiles_path.c_str());
strcpy(emu_savestates_path, config_emulator.savestates_path.c_str());
emu_savefiles_dir_option = config_emulator.savefiles_dir_option;
emu_savestates_dir_option = config_emulator.savestates_dir_option;

gui_init();

ImGui_ImplSDL2_InitForOpenGL(application_sdl_window, gl_context);
Expand Down
8 changes: 8 additions & 0 deletions platforms/shared/desktop/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ void config_read(void)
config_emulator.savefiles_path = read_string("Emulator", "SaveFilesPath");
config_emulator.savestates_dir_option = read_int("Emulator", "SaveStatesDirOption", 0);
config_emulator.savestates_path = read_string("Emulator", "SaveStatesPath");
config_emulator.screenshots_dir_option = read_int("Emulator", "ScreenshotDirOption", 0);
config_emulator.screenshots_path = read_string("Emulator", "ScreenshotPath");
config_emulator.last_open_path = read_string("Emulator", "LastOpenPath");
config_emulator.window_width = read_int("Emulator", "WindowWidth", 770);
config_emulator.window_height = read_int("Emulator", "WindowHeight", 600);
Expand All @@ -156,6 +158,10 @@ void config_read(void)
{
config_emulator.savestates_path = config_root_path;
}
if (config_emulator.screenshots_path.empty())
{
config_emulator.screenshots_path = config_root_path;
}

for (int i = 0; i < config_max_recent_roms; i++)
{
Expand Down Expand Up @@ -268,6 +274,8 @@ void config_write(void)
write_string("Emulator", "SaveFilesPath", config_emulator.savefiles_path);
write_int("Emulator", "SaveStatesDirOption", config_emulator.savestates_dir_option);
write_string("Emulator", "SaveStatesPath", config_emulator.savestates_path);
write_int("Emulator", "ScreenshotDirOption", config_emulator.screenshots_dir_option);
write_string("Emulator", "ScreenshotPath", config_emulator.screenshots_path);
write_string("Emulator", "LastOpenPath", config_emulator.last_open_path);
write_int("Emulator", "WindowWidth", config_emulator.window_width);
write_int("Emulator", "WindowHeight", config_emulator.window_height);
Expand Down
2 changes: 2 additions & 0 deletions platforms/shared/desktop/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct config_Emulator
std::string savefiles_path;
int savestates_dir_option = 0;
std::string savestates_path;
int screenshots_dir_option = 0;
std::string screenshots_path;
std::string last_open_path;
int window_width = 770;
int window_height = 600;
Expand Down
120 changes: 83 additions & 37 deletions platforms/shared/desktop/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ static void destroy_debug(void);
static void update_debug(void);
static void update_debug_background(void);
static void update_debug_sprites(void);
static void update_savestates_data(void);

void emu_init(void)
{
Expand All @@ -63,10 +62,6 @@ void emu_init(void)

audio_enabled = true;
emu_audio_sync = true;
emu_savefiles_dir_option = 0;
emu_savestates_dir_option = 0;
emu_savefiles_path[0] = 0;
emu_savestates_path[0] = 0;
emu_debug_disable_breakpoints = false;
emu_debug_irq_breakpoints = false;
emu_debug_command = Debug_Command_None;
Expand Down Expand Up @@ -228,10 +223,25 @@ void emu_save_state_slot(int index)
{
if (!emu_is_empty())
{
if ((emu_savestates_dir_option == 0) && (strcmp(emu_savestates_path, "")))
geargrafx->SaveState(emu_savestates_path, index, true);
else
geargrafx->SaveState(NULL, index, true);
switch ((Directory_Location)config_emulator.savestates_dir_option)
{
default:
case Directory_Location_Default:
{
geargrafx->SaveState(config_root_path, index, true);
break;
}
case Directory_Location_ROM:
{
geargrafx->SaveState(NULL, index, true);
break;
}
case Directory_Location_Custom:
{
geargrafx->SaveState(config_emulator.savestates_path.c_str(), index, true);
break;
}
}

update_savestates_data();
}
Expand All @@ -241,10 +251,25 @@ void emu_load_state_slot(int index)
{
if (!emu_is_empty())
{
if ((emu_savestates_dir_option == 0) && (strcmp(emu_savestates_path, "")))
geargrafx->LoadState(emu_savestates_path, index);
else
geargrafx->LoadState(NULL, index);
switch ((Directory_Location)config_emulator.savestates_dir_option)
{
default:
case Directory_Location_Default:
{
geargrafx->LoadState(config_root_path, index);
break;
}
case Directory_Location_ROM:
{
geargrafx->LoadState(NULL, index);
break;
}
case Directory_Location_Custom:
{
geargrafx->LoadState(config_emulator.savestates_path.c_str(), index);
break;
}
}
}
}

Expand All @@ -260,6 +285,51 @@ void emu_load_state_file(const char* file_path)
geargrafx->LoadState(file_path);
}

void update_savestates_data(void)
{
if (emu_is_empty())
return;

for (int i = 0; i < 5; i++)
{
emu_savestates[i].rom_name[0] = 0;
SafeDeleteArray(emu_savestates_screenshots[i].data);

const char* dir = NULL;

switch ((Directory_Location)config_emulator.savestates_dir_option)
{
default:
case Directory_Location_Default:
{
dir = config_root_path;
break;
}
case Directory_Location_ROM:
{
dir = NULL;
break;
}
case Directory_Location_Custom:
{
dir = config_emulator.savestates_path.c_str();
break;
}
}

if (!geargrafx->GetSaveStateHeader(i + 1, dir, &emu_savestates[i]))
continue;

if (emu_savestates[i].screenshot_size > 0)
{
emu_savestates_screenshots[i].data = new u8[emu_savestates[i].screenshot_size];
emu_savestates_screenshots[i].size = emu_savestates[i].screenshot_size;
geargrafx->GetSaveStateScreenshot(i + 1, dir, &emu_savestates_screenshots[i]);
}
}
}


void emu_get_runtime(GG_Runtime_Info& runtime)
{
geargrafx->GetRuntimeInfo(runtime);
Expand Down Expand Up @@ -585,27 +655,3 @@ static void update_debug_sprites(void)
}
}
}

static void update_savestates_data(void)
{
if (emu_is_empty())
return;

bool using_path = (emu_savestates_dir_option == 0) && (strcmp(emu_savestates_path, ""));

for (int i = 0; i < 5; i++)
{
emu_savestates[i].rom_name[0] = 0;
SafeDeleteArray(emu_savestates_screenshots[i].data);

if (!geargrafx->GetSaveStateHeader(i + 1, using_path ? emu_savestates_path : NULL, &emu_savestates[i]))
continue;

if (emu_savestates[i].screenshot_size > 0)
{
emu_savestates_screenshots[i].data = new u8[emu_savestates[i].screenshot_size];
emu_savestates_screenshots[i].size = emu_savestates[i].screenshot_size;
geargrafx->GetSaveStateScreenshot(i + 1, using_path ? emu_savestates_path : NULL, &emu_savestates_screenshots[i]);
}
}
}
11 changes: 7 additions & 4 deletions platforms/shared/desktop/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ enum Debug_Command
Debug_Command_None
};

enum Directory_Location
{
Directory_Location_Default = 0,
Directory_Location_ROM = 1,
Directory_Location_Custom = 2
};

EXTERN u8* emu_frame_buffer;
EXTERN GG_SaveState_Header emu_savestates[5];
Expand All @@ -52,10 +58,6 @@ EXTERN bool emu_debug_pc_changed;
EXTERN bool emu_audio_sync;
EXTERN bool emu_debug_disable_breakpoints;
EXTERN bool emu_debug_irq_breakpoints;
EXTERN bool emu_savefiles_dir_option;
EXTERN bool emu_savestates_dir_option;
EXTERN char emu_savefiles_path[4096];
EXTERN char emu_savestates_path[4096];

EXTERN void emu_init(void);
EXTERN void emu_destroy(void);
Expand All @@ -79,6 +81,7 @@ EXTERN void emu_save_state_slot(int index);
EXTERN void emu_load_state_slot(int index);
EXTERN void emu_save_state_file(const char* file_path);
EXTERN void emu_load_state_file(const char* file_path);
EXTERN void update_savestates_data(void);
EXTERN void emu_get_runtime(GG_Runtime_Info& runtime);
EXTERN void emu_get_info(char* info, int buffer_size);
EXTERN GeargrafxCore* emu_get_core(void);
Expand Down
24 changes: 21 additions & 3 deletions platforms/shared/desktop/gui_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,28 @@ void gui_action_save_screenshot(const char* path)
if (file_path.find_last_of(".") == string::npos)
file_path += ".png";
}
else if ((emu_savestates_dir_option == 0) && (strcmp(emu_savestates_path, "")))
file_path = file_path.assign(emu_savestates_path)+ "/" + string(emu_get_core()->GetCartridge()->GetFileName()) + " - " + date_time + ".png";
else
file_path = file_path.assign(emu_get_core()->GetCartridge()->GetFilePath()) + " - " + date_time + ".png";
{
switch ((Directory_Location)config_emulator.screenshots_dir_option)
{
default:
case Directory_Location_Default:
{
file_path = file_path.assign(config_root_path)+ "/" + string(emu_get_core()->GetCartridge()->GetFileName()) + " - " + date_time + ".png";
break;
}
case Directory_Location_ROM:
{
file_path = file_path.assign(emu_get_core()->GetCartridge()->GetFilePath()) + " - " + date_time + ".png";
break;
}
case Directory_Location_Custom:
{
file_path = file_path.assign(config_emulator.screenshots_path)+ "/" + string(emu_get_core()->GetCartridge()->GetFileName()) + " - " + date_time + ".png";
break;
}
}
}

emu_save_screenshot(file_path.c_str());

Expand Down
20 changes: 20 additions & 0 deletions platforms/shared/desktop/gui_filedialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@ void gui_file_dialog_choose_savestate_path(void)
}
}

void gui_file_dialog_choose_screenshot_path(void)
{
nfdchar_t *outPath;
nfdpickfolderu8args_t args = { };
args.defaultPath = config_emulator.screenshots_path.c_str();
file_dialog_set_native_window(application_sdl_window, &args.parentWindow);

nfdresult_t result = NFD_PickFolderU8_With(&outPath, &args);
if (result == NFD_OKAY)
{
config_emulator.screenshots_path.assign(outPath);
update_savestates_data();
NFD_FreePath(outPath);
}
else if (result != NFD_CANCEL)
{
Log("Screenshot Path Error: %s", NFD_GetError());
}
}

void gui_file_dialog_load_symbols(void)
{
nfdchar_t *outPath;
Expand Down
1 change: 1 addition & 0 deletions platforms/shared/desktop/gui_filedialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ EXTERN void gui_file_dialog_save_ram(void);
EXTERN void gui_file_dialog_load_state(void);
EXTERN void gui_file_dialog_save_state(void);
EXTERN void gui_file_dialog_choose_savestate_path(void);
EXTERN void gui_file_dialog_choose_screenshot_path(void);
EXTERN void gui_file_dialog_load_symbols(void);
EXTERN void gui_file_dialog_save_screenshot(void);
EXTERN void gui_file_dialog_save_memory_dump(void);
Expand Down
Loading

0 comments on commit 5ebfd7d

Please sign in to comment.