8 #define DIE(format, ...) do { \
9 fprintf(stderr, "Died at %s:%d: ", __FILE__, __LINE__ ); \
10 fprintf(stderr, format "\n", ## __VA_ARGS__); \
16 static HgwContext *hgw;
18 static void createActionMappingsOnly();
19 static void parseGConfKeyMappings();
23 // hildon-games-wrapper sets this env variable for itself.
24 char* service = getenv("HGW_EXEC_SERVICE");
27 // Not launched from hildon-games-wrapper
32 hgw = hgw_context_init();
35 fprintf(stderr, "Error opening hgw context\n");
40 printf("Loading in HGW mode\n");
45 if (!hgwLaunched) return;
47 hgw_context_destroy(hgw,
48 (Config.snapshotSave ? HGW_BYE_PAUSED : HGW_BYE_INACTIVE));
55 if (!hgwLaunched) return;
57 Config.fullscreen = true;
59 char romFile[PATH_MAX + 1];
60 if (hgw_conf_request_string(hgw, kGConfRomFile, romFile) == HGW_ERR_NONE) {
61 S9xSetRomFile(romFile);
63 hgw_context_destroy(hgw, HGW_BYE_INACTIVE);
64 DIE("No Rom in Gconf!");
67 char no_audio = FALSE;
68 if (hgw_conf_request_bool(hgw, kGConfDisableAudio, &no_audio) == HGW_ERR_NONE) {
69 Config.enableAudio = no_audio ? false : true;
73 if (hgw_conf_request_bool(hgw, kGConfTurboMode, &turbo) == HGW_ERR_NONE) {
74 Settings.TurboMode = turbo ? TRUE : FALSE;
78 if (hgw_conf_request_int(hgw, kGConfFrameskip, &frameskip) == HGW_ERR_NONE) {
79 Settings.SkipFrames = (frameskip > 0 ? frameskip : AUTO_FRAMERATE);
82 char transparency = FALSE;
83 if (hgw_conf_request_bool(hgw, kGConfTransparency, &transparency) == HGW_ERR_NONE) {
84 Settings.Transparency = transparency ? TRUE : FALSE;
87 char displayFramerate = FALSE;
88 if (hgw_conf_request_bool(hgw, kGConfDisplayFramerate, &displayFramerate) == HGW_ERR_NONE) {
89 Settings.DisplayFrameRate = displayFramerate ? TRUE : FALSE;
93 if (hgw_conf_request_int(hgw, kGConfFrameskip, &speedhacks) == HGW_ERR_NONE) {
94 if (speedhacks <= 0) {
95 Settings.HacksEnabled = FALSE;
96 Settings.HacksFilter = FALSE;
97 } else if (speedhacks == 1) {
98 Settings.HacksEnabled = TRUE;
99 Settings.HacksFilter = TRUE;
101 Settings.HacksEnabled = TRUE;
102 Settings.HacksFilter = FALSE;
107 if (hgw_conf_request_int(hgw, kGConfMapping, &mappings) == HGW_ERR_NONE) {
110 // Do nothing, leave mappings as is.
113 parseGConfKeyMappings();
115 case 2: // Touchscreen
116 Config.touchscreenInput = true;
117 createActionMappingsOnly();
119 case 3: // Touchscreen + keys
120 Config.touchscreenInput = true;
121 parseGConfKeyMappings();
124 Settings.Mouse = TRUE;
125 Settings.ControllerOption = SNES_MOUSE_SWAPPED;
127 case 5: // Mouse + keys
128 Settings.Mouse = TRUE;
129 Settings.ControllerOption = SNES_MOUSE;
130 parseGConfKeyMappings();
135 HgwStartCommand cmd = hgw_context_get_start_command(hgw);
138 case HGW_COMM_NONE: // called from libosso
140 Config.snapshotLoad = true;
141 Config.snapshotSave = true;
143 case HGW_COMM_RESTART:
144 Config.snapshotLoad = false;
145 Config.snapshotSave = true;
149 Config.snapshotLoad = false;
150 Config.snapshotSave = false;
151 Config.quitting = true;
158 if (!hgwLaunched) return;
161 HgwMessageFlags flags = HGW_MSG_FLAG_NONE;
163 if ( hgw_msg_check_incoming(hgw, &msg, flags) == HGW_ERR_COMMUNICATION ) {
164 // Message Incoming, process msg
167 case HGW_MSG_TYPE_CBREQ:
171 Config.quitting = true;
175 case HGW_MSG_TYPE_DEVSTATE:
177 case HGW_DEVICE_STATE_SHUTDOWN:
178 Config.quitting = true; // try to quit gracefully
187 hgw_msg_free_data(&msg);
191 // For now, please keep this in sync with ../gui/controls.c
192 typedef struct ButtonEntry {
197 #define BUTTON_INITIALIZER(button, name) \
198 { kGConfKeysPath "/" name, SNES_##button##_MASK, false }
199 #define ACTION_INITIALIZER(action, name) \
200 { kGConfKeysPath "/" name, kAction##action, true }
201 #define BUTTON_LAST \
203 static const ButtonEntry buttons[] = {
204 BUTTON_INITIALIZER(A, "a"),
205 BUTTON_INITIALIZER(B, "b"),
206 BUTTON_INITIALIZER(X, "x"),
207 BUTTON_INITIALIZER(Y, "y"),
208 BUTTON_INITIALIZER(TL, "l"),
209 BUTTON_INITIALIZER(TR, "r"),
210 BUTTON_INITIALIZER(START, "start"),
211 BUTTON_INITIALIZER(SELECT, "select"),
212 BUTTON_INITIALIZER(UP, "up"),
213 BUTTON_INITIALIZER(DOWN, "down"),
214 BUTTON_INITIALIZER(LEFT, "left"),
215 BUTTON_INITIALIZER(RIGHT, "right"),
216 ACTION_INITIALIZER(Quit, "quit"),
217 ACTION_INITIALIZER(ToggleFullscreen, "fullscreen"),
221 static void createActionMappingsOnly()
223 // Discard any other mapping
224 ZeroMemory(Config.joypad1Mapping, sizeof(Config.joypad1Mapping));
225 ZeroMemory(Config.action, sizeof(Config.action));
227 // Map quit to fullscreen and escape
228 Config.action[72] = kActionQuit;
229 Config.action[9] = kActionQuit;
232 static void parseGConfKeyMappings()
234 // Discard any other mapping
235 ZeroMemory(Config.joypad1Mapping, sizeof(Config.joypad1Mapping));
236 ZeroMemory(Config.action, sizeof(Config.action));
238 // If the user does not map fullscreen or quit
239 bool quit_mapped = false;
241 printf("Hgw: Using gconf key mappings\n");
244 for (i = 0; buttons[i].gconf_key; i++) {
245 if (hgw_conf_request_int(hgw, buttons[i].gconf_key, &scancode) == HGW_ERR_NONE) {
246 if (scancode <= 0 || scancode > 255) continue;
248 if (buttons[i].is_action) {
249 Config.action[scancode] |= buttons[i].mask;
250 if (buttons[i].mask & (kActionQuit | kActionToggleFullscreen)) {
254 Config.joypad1Mapping[scancode] |= buttons[i].mask;
261 // Newbie user won't know how to quit game.
262 if (!Config.joypad1Mapping[72] && !Config.action[72]) {
263 // Fullscreen key is not mapped, map
264 Config.action[72] = kActionQuit;
267 if (!quit_mapped && !Config.joypad1Mapping[9] && !Config.action[9]) {
268 // Escape key is not mapped, map
269 // But only if we couldn't map quit to fullscreen. Some people
270 // actually want Quit not to be mapped.
271 Config.action[9] = kActionQuit;
275 // Force mapping of fullscreen to Quit if can't map anywhere else.
276 Config.joypad1Mapping[72] = 0;
277 Config.action[72] = kActionQuit;