Skip to content

Commit

Permalink
Save screenshots. Fix #78
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 18, 2024
1 parent 67f1221 commit 2ffcff0
Show file tree
Hide file tree
Showing 8 changed files with 1,928 additions and 13 deletions.
3 changes: 3 additions & 0 deletions platforms/desktop-shared/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ void config_init(void)
config_setShortcut(gui_ShortcutFFWD, KMOD_CTRL, SDL_SCANCODE_F);
config_setShortcut(gui_ShortcutSaveState, KMOD_CTRL, SDL_SCANCODE_S);
config_setShortcut(gui_ShortcutLoadState, KMOD_CTRL, SDL_SCANCODE_L);
config_setShortcut(gui_ShortcutScreenshot, KMOD_CTRL, SDL_SCANCODE_X);
config_setShortcut(gui_ShortcutDebugStep, KMOD_CTRL, SDL_SCANCODE_F10);
config_setShortcut(gui_ShortcutDebugContinue, KMOD_CTRL, SDL_SCANCODE_F5);
config_setShortcut(gui_ShortcutDebugNextFrame, KMOD_CTRL, SDL_SCANCODE_F6);
Expand Down Expand Up @@ -197,6 +198,7 @@ void config_read(void)
config_emulator.last_open_path = read_string("Emulator", "LastOpenPath");
config_emulator.window_width = read_int("Emulator", "WindowWidth", 640);
config_emulator.window_height = read_int("Emulator", "WindowHeight", 503);
config_emulator.status_messages = read_bool("Emulator", "StatusMessages", false);

if (config_emulator.savefiles_path.empty())
{
Expand Down Expand Up @@ -301,6 +303,7 @@ void config_write(void)
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);
write_bool("Emulator", "StatusMessages", config_emulator.status_messages);

for (int i = 0; i < config_max_recent_roms; i++)
{
Expand Down
1 change: 1 addition & 0 deletions platforms/desktop-shared/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct config_Emulator
std::string last_open_path;
int window_width = 640;
int window_height = 503;
bool status_messages = false;
};

struct config_Video
Expand Down
21 changes: 21 additions & 0 deletions platforms/desktop-shared/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
#define EMU_IMPORT
#include "emu.h"

#define STB_IMAGE_WRITE_IMPLEMENTATION
#ifdef _WIN32
#define STBIW_WINDOWS_UTF8
#endif
#include "stb/stb_image_write.h"

static GearsystemCore* gearsystem;
static Sound_Queue* sound_queue;
static s16* audio_buffer;
Expand Down Expand Up @@ -398,6 +404,21 @@ void emu_disable_ym2413(bool disable)
gearsystem->GetAudio()->DisableYM2413(disable);
}

void emu_save_screenshot(const char* file_path)
{
if (!gearsystem->GetCartridge()->IsReady())
return;

GS_RuntimeInfo runtime;
emu_get_runtime(runtime);

Log("Saving screenshot to %s", file_path);

stbi_write_png(file_path, runtime.screen_width, runtime.screen_height, 3, emu_frame_buffer, runtime.screen_width * 3);

Log("Screenshot saved!");
}

static void save_ram(void)
{
#ifdef DEBUG_GEARSYSTEM
Expand Down
1 change: 1 addition & 0 deletions platforms/desktop-shared/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ EXTERN void emu_set_media_slot(int slot);
EXTERN void emu_set_3d_glasses_config(int config);
EXTERN void emu_set_overscan(int overscan);
EXTERN void emu_disable_ym2413(bool disable);
EXTERN void emu_save_screenshot(const char* file_path);

#undef EMU_IMPORT
#undef EXTERN
Expand Down
Loading

0 comments on commit 2ffcff0

Please sign in to comment.