Yay, works :)

This commit is contained in:
Themaister 2011-05-15 17:16:29 +02:00
parent 29addd605e
commit efed98d5b6
8 changed files with 60 additions and 4 deletions

View File

@ -245,6 +245,7 @@ static const struct snes_keybind snes_keybinds_1[] = {
{ SSNES_CHEAT_INDEX_PLUS, SDLK_y, NO_BTN, AXIS_NONE },
{ SSNES_CHEAT_INDEX_MINUS, SDLK_t, NO_BTN, AXIS_NONE },
{ SSNES_CHEAT_TOGGLE, SDLK_u, NO_BTN, AXIS_NONE },
{ SSNES_SCREENSHOT, SDLK_PRINT, NO_BTN, AXIS_NONE },
{ -1 }
};

View File

@ -44,7 +44,8 @@ enum
SSNES_SHADER_PREV,
SSNES_CHEAT_INDEX_PLUS,
SSNES_CHEAT_INDEX_MINUS,
SSNES_CHEAT_TOGGLE
SSNES_CHEAT_TOGGLE,
SSNES_SCREENSHOT
};

View File

@ -44,7 +44,7 @@
#define MAX_PLAYERS 5
#define MAX_BINDS 31 // Needs to be increased every time there are new binds added.
#define MAX_BINDS 32 // Needs to be increased every time there are new binds added.
#define SSNES_NO_JOYPAD 0xFFFF
enum ssnes_shader_type
@ -121,6 +121,8 @@ struct settings
char libsnes[256];
char cheat_database[256];
char screenshot_directory[256];
bool rewind_enable;
unsigned rewind_buffer_size;
unsigned rewind_granularity;
@ -258,7 +260,9 @@ struct global
size_t ptr;
} shader_dir;
char sha256[65];
char sha256[64 + 1];
bool do_screenshot;
#ifdef HAVE_XML
cheat_manager_t *cheat;

View File

@ -87,7 +87,7 @@ bool screenshot_dump(const char *folder, const uint16_t *frame,
time(&cur_time);
char timefmt[64];
strftime(timefmt, sizeof(timefmt), "SSNES-%c", localtime(&cur_time));
strftime(timefmt, sizeof(timefmt), "SSNES-%c.bmp", localtime(&cur_time));
char filename[256];
strlcpy(filename, folder, sizeof(filename));

View File

@ -374,6 +374,7 @@ static void parse_config_file(void)
CONFIG_GET_STRING(audio.dsp_plugin, "audio_dsp_plugin");
CONFIG_GET_STRING(input.driver, "input_driver");
CONFIG_GET_STRING(libsnes, "libsnes_path");
CONFIG_GET_STRING(screenshot_directory, "screenshot_directory");
CONFIG_GET_BOOL(rewind_enable, "rewind_enable");
@ -435,6 +436,7 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = {
DECLARE_BIND(cheat_index_plus, SSNES_CHEAT_INDEX_PLUS)
DECLARE_BIND(cheat_index_minus, SSNES_CHEAT_INDEX_MINUS)
DECLARE_BIND(cheat_toggle, SSNES_CHEAT_TOGGLE)
DECLARE_BIND(screenshot, SSNES_SCREENSHOT)
},
{
DECLARE_BIND(player2_a, SNES_DEVICE_ID_JOYPAD_A)
@ -467,6 +469,7 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = {
DECLARE_BIND(cheat_index_plus, SSNES_CHEAT_INDEX_PLUS)
DECLARE_BIND(cheat_index_minus, SSNES_CHEAT_INDEX_MINUS)
DECLARE_BIND(cheat_toggle, SSNES_CHEAT_TOGGLE)
DECLARE_BIND(screenshot, SSNES_SCREENSHOT)
},
{
DECLARE_BIND(player3_a, SNES_DEVICE_ID_JOYPAD_A)
@ -499,6 +502,7 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = {
DECLARE_BIND(cheat_index_plus, SSNES_CHEAT_INDEX_PLUS)
DECLARE_BIND(cheat_index_minus, SSNES_CHEAT_INDEX_MINUS)
DECLARE_BIND(cheat_toggle, SSNES_CHEAT_TOGGLE)
DECLARE_BIND(screenshot, SSNES_SCREENSHOT)
},
{
DECLARE_BIND(player4_a, SNES_DEVICE_ID_JOYPAD_A)
@ -531,6 +535,7 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = {
DECLARE_BIND(cheat_index_plus, SSNES_CHEAT_INDEX_PLUS)
DECLARE_BIND(cheat_index_minus, SSNES_CHEAT_INDEX_MINUS)
DECLARE_BIND(cheat_toggle, SSNES_CHEAT_TOGGLE)
DECLARE_BIND(screenshot, SSNES_SCREENSHOT)
},
{
DECLARE_BIND(player5_a, SNES_DEVICE_ID_JOYPAD_A)
@ -563,6 +568,7 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = {
DECLARE_BIND(cheat_index_plus, SSNES_CHEAT_INDEX_PLUS)
DECLARE_BIND(cheat_index_minus, SSNES_CHEAT_INDEX_MINUS)
DECLARE_BIND(cheat_toggle, SSNES_CHEAT_TOGGLE)
DECLARE_BIND(screenshot, SSNES_SCREENSHOT)
},
};

37
ssnes.c
View File

@ -32,6 +32,7 @@
#include "movie.h"
#include "netplay.h"
#include "strl.h"
#include "screenshot.h"
#include "cheats.h"
#include <assert.h>
#ifdef HAVE_SRC
@ -78,6 +79,30 @@ static void set_fast_forward_button(bool new_button_state)
old_button_state = new_button_state;
}
static void take_screenshot(const uint16_t *frame, unsigned width, unsigned height)
{
if (!*(g_settings.screenshot_directory))
return;
bool ret = screenshot_dump(g_settings.screenshot_directory, frame,
width, height, (height == 448 || height == 478) ? 1024 : 2048);
const char *msg = NULL;
if (ret)
{
SSNES_LOG("Taking screenshot!\n");
msg = "Taking screenshot!";
}
else
{
SSNES_WARN("Failed to take screenshot ...\n");
msg = "Failed to take screenshot!";
}
msg_queue_clear(g_extern.msg_queue);
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
}
// libsnes: 0.065
// Format received is 16-bit 0RRRRRGGGGGBBBBB
static void video_frame(const uint16_t *data, unsigned width, unsigned height)
@ -99,6 +124,9 @@ static void video_frame(const uint16_t *data, unsigned width, unsigned height)
}
}
if (g_extern.do_screenshot)
take_screenshot(data, width, height);
#ifdef HAVE_FFMPEG
if (g_extern.recording)
{
@ -1311,6 +1339,14 @@ static void check_cheats(void)
}
#endif
static void check_screenshot(void)
{
static bool old_pressed = false;
bool pressed = driver.input->key_pressed(driver.input_data, SSNES_SCREENSHOT);
g_extern.do_screenshot = pressed && !old_pressed;
old_pressed = pressed;
}
static void do_state_checks(void)
{
if (!g_extern.netplay)
@ -1342,6 +1378,7 @@ static void do_state_checks(void)
check_fullscreen();
check_input_rate();
check_screenshot();
}
static void fill_title_buf(void)

View File

@ -278,3 +278,9 @@
# input_cheat_index_plus = y
# input_cheat_index_minus = t
# input_cheat_toggle = u
# Take screenshot
# input_screenshot = print_screen
# Directory to dump screenshots to.
# screenshot_directory =

View File

@ -97,6 +97,7 @@ static struct bind binds[] = {
MISC_BIND("Toggle cheat on/off", cheat_toggle)
MISC_BIND("Cheat index plus", cheat_index_plus)
MISC_BIND("Cheat index minus", cheat_index_minus)
MISC_BIND("Screenshot", screenshot)
};
static void get_binds(config_file_t *conf, int player, int joypad)