4 * Handles hotkeys for pause/continue, save states, quit, etc
6 * Copyright (c) 2009 wahrhaft
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
24 #include "dreamcast.h"
28 #include "drivers/input_lirc.h"
31 static void hotkey_resume_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
32 static void hotkey_stop_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
33 static void hotkey_reset_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
34 static void hotkey_exit_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
35 static void hotkey_state_select_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
36 static void hotkey_state_save_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
37 static void hotkey_state_load_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
39 static char *set_current_state_filename(int filenum);
41 static char *current_save_state;
43 struct lxdream_config_entry hotkeys_config[] = {
44 {"resume", N_("Resume emulation"), CONFIG_TYPE_KEY},
45 {"stop", N_("Stop emulation"), CONFIG_TYPE_KEY},
46 {"reset", N_("Reset emulator"), CONFIG_TYPE_KEY},
47 {"exit", N_("Exit emulator"), CONFIG_TYPE_KEY},
48 {"save", N_("Save current quick save"), CONFIG_TYPE_KEY},
49 {"load", N_("Load current quick save"), CONFIG_TYPE_KEY},
50 {"state1", N_("Select quick save state 1"), CONFIG_TYPE_KEY},
51 {"state2", N_("Select quick save state 2"), CONFIG_TYPE_KEY},
52 {"state3", N_("Select quick save state 3"), CONFIG_TYPE_KEY},
53 {"state4", N_("Select quick save state 4"), CONFIG_TYPE_KEY},
54 {"state5", N_("Select quick save state 5"), CONFIG_TYPE_KEY},
55 {"state6", N_("Select quick save state 6"), CONFIG_TYPE_KEY},
56 {"state7", N_("Select quick save state 7"), CONFIG_TYPE_KEY},
57 {"state8", N_("Select quick save state 8"), CONFIG_TYPE_KEY},
58 {"state9", N_("Select quick save state 9"), CONFIG_TYPE_KEY},
59 {NULL, CONFIG_TYPE_NONE}
68 char *home = getenv("HOME");
69 char *save_path = g_strdup_printf("%s/.lxdream", home);
70 mkdir(save_path, S_IRWXU);
73 set_current_state_filename(1);
75 hotkeys_register_keys();
78 void hotkeys_register_keys()
80 input_register_key(hotkeys_config[0].value, &hotkey_resume_callback, NULL, 0);
81 input_register_key(hotkeys_config[1].value, &hotkey_stop_callback, NULL, 0);
82 input_register_key(hotkeys_config[2].value, &hotkey_reset_callback, NULL, 0);
83 input_register_key(hotkeys_config[3].value, &hotkey_exit_callback, NULL, 0);
84 input_register_key(hotkeys_config[4].value, &hotkey_state_save_callback, NULL, 0);
85 input_register_key(hotkeys_config[5].value, &hotkey_state_load_callback, NULL, 0);
86 for (int i = 0; i < 9; i++)
88 input_register_key(hotkeys_config[6 + i].value, &hotkey_state_select_callback, NULL, i);
92 void hotkeys_unregister_keys()
94 input_unregister_key(hotkeys_config[0].value, &hotkey_resume_callback, NULL, 0);
95 input_unregister_key(hotkeys_config[1].value, &hotkey_stop_callback, NULL, 0);
96 input_unregister_key(hotkeys_config[2].value, &hotkey_reset_callback, NULL, 0);
97 input_unregister_key(hotkeys_config[3].value, &hotkey_exit_callback, NULL, 0);
98 input_unregister_key(hotkeys_config[4].value, &hotkey_state_save_callback, NULL, 0);
99 input_unregister_key(hotkeys_config[5].value, &hotkey_state_load_callback, NULL, 0);
100 for (int i = 0; i < 9; i++)
102 input_unregister_key(hotkeys_config[6 + i].value, &hotkey_state_select_callback, NULL, i);
106 lxdream_config_entry_t hotkeys_get_config()
108 return hotkeys_config;
112 static void hotkey_resume_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
114 if (isKeyDown && !dreamcast_is_running() ) {
115 gui_do_later(dreamcast_run);
119 static void hotkey_stop_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
121 if (isKeyDown && dreamcast_is_running() ) {
122 gui_do_later(dreamcast_stop);
126 static void hotkey_reset_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
133 static void hotkey_exit_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
136 dreamcast_shutdown();
141 static void hotkey_state_select_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
144 INFO("state select callback called (%d)", value);
145 assert(value > 0 && value <= 9);
146 set_current_state_filename(value);
150 static void hotkey_state_save_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
153 if (current_save_state != NULL)
154 dreamcast_save_state(current_save_state);
158 static void hotkey_state_load_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
161 if (current_save_state != NULL)
162 dreamcast_load_state(current_save_state);
166 static char *set_current_state_filename(int filenum)
168 char *home = getenv("HOME");
169 if (current_save_state != NULL)
170 g_free(current_save_state);
171 current_save_state = g_strdup_printf("%s/.lxdream/quicksave%d.dst", home, filenum);
.