9 #define DIE(format, ...) do { \
10 fprintf(stderr, "Died at %s:%d: ", __FILE__, __LINE__ ); \
11 fprintf(stderr, format "\n", ## __VA_ARGS__); \
17 static HgwContext *hgw;
19 static void createActionMappingsOnly();
20 static void parseGConfKeyMappings();
24 // hildon-games-wrapper sets this env variable for itself.
25 char* service = getenv("HGW_EXEC_SERVICE");
28 // Not launched from hildon-games-wrapper
33 hgw = hgw_context_init();
36 fprintf(stderr, "Error opening hgw context\n");
41 printf("Loading in HGW mode\n");
46 if (!hgwLaunched) return;
48 hgw_context_destroy(hgw,
49 (Config.snapshotSave ? HGW_BYE_PAUSED : HGW_BYE_INACTIVE));
56 if (!hgwLaunched) return;
58 Config.fullscreen = true;
60 char romFile[PATH_MAX + 1];
61 if (hgw_conf_request_string(hgw, kGConfRomFile, romFile) == HGW_ERR_NONE) {
62 S9xSetRomFile(romFile);
64 hgw_context_destroy(hgw, HGW_BYE_INACTIVE);
65 DIE("No Rom in Gconf!");
68 char no_audio = FALSE;
69 if (hgw_conf_request_bool(hgw, kGConfDisableAudio, &no_audio) == HGW_ERR_NONE) {
70 Config.enableAudio = no_audio ? false : true;
74 if (hgw_conf_request_bool(hgw, kGConfTurboMode, &turbo) == HGW_ERR_NONE) {
75 Settings.TurboMode = turbo ? TRUE : FALSE;
79 if (hgw_conf_request_int(hgw, kGConfFrameskip, &frameskip) == HGW_ERR_NONE) {
80 Settings.SkipFrames = (frameskip > 0 ? frameskip : AUTO_FRAMERATE);
83 char transparency = FALSE;
84 if (hgw_conf_request_bool(hgw, kGConfTransparency, &transparency) == HGW_ERR_NONE) {
85 Settings.Transparency = transparency ? TRUE : FALSE;
88 char displayFramerate = FALSE;
89 if (hgw_conf_request_bool(hgw, kGConfDisplayFramerate, &displayFramerate) == HGW_ERR_NONE) {
90 Settings.DisplayFrameRate = displayFramerate ? TRUE : FALSE;
94 if (hgw_conf_request_int(hgw, kGConfFrameskip, &speedhacks) == HGW_ERR_NONE) {
95 if (speedhacks <= 0) {
96 Settings.HacksEnabled = FALSE;
97 Settings.HacksFilter = FALSE;
98 } else if (speedhacks == 1) {
99 Settings.HacksEnabled = TRUE;
100 Settings.HacksFilter = TRUE;
102 Settings.HacksEnabled = TRUE;
103 Settings.HacksFilter = FALSE;
106 if (Settings.HacksEnabled && !Config.hacksFile) {
107 // Provide a default speedhacks file
108 Config.hacksFile = asprintf("%s/snesadvance.dat", dirname(romFile));
109 // romFile[] is garbled from now on.
113 if (hgw_conf_request_int(hgw, kGConfMapping, &mappings) == HGW_ERR_NONE) {
116 // Do nothing, leave mappings as is.
119 parseGConfKeyMappings();
121 case 2: // Touchscreen
122 Config.touchscreenInput = true;
123 createActionMappingsOnly();
125 case 3: // Touchscreen + keys
126 Config.touchscreenInput = true;
127 parseGConfKeyMappings();
130 Settings.Mouse = TRUE;
131 Settings.ControllerOption = SNES_MOUSE_SWAPPED;
132 createActionMappingsOnly();
134 case 5: // Mouse + keys
135 Settings.Mouse = TRUE;
136 Settings.ControllerOption = SNES_MOUSE;
137 parseGConfKeyMappings();
142 HgwStartCommand cmd = hgw_context_get_start_command(hgw);
145 case HGW_COMM_NONE: // called from libosso
147 Config.snapshotLoad = true;
148 Config.snapshotSave = true;
150 case HGW_COMM_RESTART:
151 Config.snapshotLoad = false;
152 Config.snapshotSave = true;
156 Config.snapshotLoad = false;
157 Config.snapshotSave = false;
158 Config.quitting = true;
165 if (!hgwLaunched) return;
168 HgwMessageFlags flags = HGW_MSG_FLAG_NONE;
170 if ( hgw_msg_check_incoming(hgw, &msg, flags) == HGW_ERR_COMMUNICATION ) {
171 // Message Incoming, process msg
174 case HGW_MSG_TYPE_CBREQ:
178 Config.quitting = true;
182 case HGW_MSG_TYPE_DEVSTATE:
184 case HGW_DEVICE_STATE_SHUTDOWN:
185 Config.quitting = true; // try to quit gracefully
194 hgw_msg_free_data(&msg);
198 // For now, please keep this in sync with ../gui/controls.c
199 typedef struct ButtonEntry {
204 #define BUTTON_INITIALIZER(button, name) \
205 { kGConfKeysPath "/" name, SNES_##button##_MASK, false }
206 #define ACTION_INITIALIZER(action, name) \
207 { kGConfKeysPath "/" name, kAction##action, true }
208 #define BUTTON_LAST \
210 static const ButtonEntry buttons[] = {
211 BUTTON_INITIALIZER(A, "a"),
212 BUTTON_INITIALIZER(B, "b"),
213 BUTTON_INITIALIZER(X, "x"),
214 BUTTON_INITIALIZER(Y, "y"),
215 BUTTON_INITIALIZER(TL, "l"),
216 BUTTON_INITIALIZER(TR, "r"),
217 BUTTON_INITIALIZER(START, "start"),
218 BUTTON_INITIALIZER(SELECT, "select"),
219 BUTTON_INITIALIZER(UP, "up"),
220 BUTTON_INITIALIZER(DOWN, "down"),
221 BUTTON_INITIALIZER(LEFT, "left"),
222 BUTTON_INITIALIZER(RIGHT, "right"),
223 ACTION_INITIALIZER(Quit, "quit"),
224 ACTION_INITIALIZER(ToggleFullscreen, "fullscreen"),
228 static void createActionMappingsOnly()
230 // Discard any other mapping
231 ZeroMemory(Config.joypad1Mapping, sizeof(Config.joypad1Mapping));
232 ZeroMemory(Config.action, sizeof(Config.action));
234 // Map quit to fullscreen and escape
235 Config.action[72] = kActionQuit;
236 Config.action[9] = kActionQuit;
239 static void parseGConfKeyMappings()
241 // Discard any other mapping
242 ZeroMemory(Config.joypad1Mapping, sizeof(Config.joypad1Mapping));
243 ZeroMemory(Config.action, sizeof(Config.action));
245 // If the user does not map fullscreen or quit
246 bool quit_mapped = false;
248 printf("Hgw: Using gconf key mappings\n");
251 for (i = 0; buttons[i].gconf_key; i++) {
252 if (hgw_conf_request_int(hgw, buttons[i].gconf_key, &scancode) == HGW_ERR_NONE) {
253 if (scancode <= 0 || scancode > 255) continue;
255 if (buttons[i].is_action) {
256 Config.action[scancode] |= buttons[i].mask;
257 if (buttons[i].mask & (kActionQuit | kActionToggleFullscreen)) {
261 Config.joypad1Mapping[scancode] |= buttons[i].mask;
268 // Newbie user won't know how to quit game.
269 if (!Config.joypad1Mapping[72] && !Config.action[72]) {
270 // Fullscreen key is not mapped, map
271 Config.action[72] = kActionQuit;
274 if (!quit_mapped && !Config.joypad1Mapping[9] && !Config.action[9]) {
275 // Escape key is not mapped, map
276 // But only if we couldn't map quit to fullscreen. Some people
277 // actually want Quit not to be mapped.
278 Config.action[9] = kActionQuit;
282 // Force mapping of fullscreen to Quit if can't map anywhere else.
283 Config.joypad1Mapping[72] = 0;
284 Config.action[72] = kActionQuit;