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 parseGConfKeyMappings();
22 // hildon-games-wrapper sets this env variable for itself.
23 char* service = getenv("HGW_EXEC_SERVICE");
26 // Not launched from hildon-games-wrapper
31 hgw = hgw_context_init();
34 fprintf(stderr, "Error opening hgw context\n");
39 printf("Loading in HGW mode\n");
44 if (!hgwLaunched) return;
46 hgw_context_destroy(hgw,
47 (Config.snapshotSave ? HGW_BYE_PAUSED : HGW_BYE_INACTIVE));
54 if (!hgwLaunched) return;
56 Config.fullscreen = true;
58 char romFile[PATH_MAX + 1];
59 if (hgw_conf_request_string(hgw, kGConfRomFile, romFile) == HGW_ERR_NONE) {
60 S9xSetRomFile(romFile);
62 hgw_context_destroy(hgw, HGW_BYE_INACTIVE);
63 DIE("No Rom in Gconf!");
66 char no_audio = FALSE;
67 if (hgw_conf_request_bool(hgw, kGConfDisableAudio, &no_audio) == HGW_ERR_NONE) {
68 Config.enableAudio = no_audio ? false : true;
72 if (hgw_conf_request_bool(hgw, kGConfTurboMode, &turbo) == HGW_ERR_NONE) {
73 Settings.TurboMode = turbo ? TRUE : FALSE;
77 if (hgw_conf_request_int(hgw, kGConfFrameskip, &frameskip) == HGW_ERR_NONE) {
78 Settings.SkipFrames = (frameskip > 0 ? frameskip : AUTO_FRAMERATE);
81 char transparency = FALSE;
82 if (hgw_conf_request_bool(hgw, kGConfTransparency, &transparency) == HGW_ERR_NONE) {
83 Settings.Transparency = transparency ? TRUE : FALSE;
87 if (hgw_conf_request_int(hgw, kGConfFrameskip, &speedhacks) == HGW_ERR_NONE) {
88 if (speedhacks <= 0) {
89 Settings.HacksEnabled = FALSE;
90 Settings.HacksFilter = FALSE;
91 } else if (speedhacks == 1) {
92 Settings.HacksEnabled = TRUE;
93 Settings.HacksFilter = TRUE;
95 Settings.HacksEnabled = TRUE;
96 Settings.HacksFilter = FALSE;
101 if (hgw_conf_request_int(hgw, kGConfMapping, &mappings) == HGW_ERR_NONE) {
104 parseGConfKeyMappings();
109 HgwStartCommand cmd = hgw_context_get_start_command(hgw);
112 case HGW_COMM_NONE: // called from libosso
114 Config.snapshotLoad = true;
115 Config.snapshotSave = true;
117 case HGW_COMM_RESTART:
118 Config.snapshotLoad = false;
119 Config.snapshotSave = true;
123 Config.snapshotLoad = false;
124 Config.snapshotSave = false;
125 Config.quitting = true;
132 if (!hgwLaunched) return;
135 HgwMessageFlags flags = HGW_MSG_FLAG_NONE;
137 if ( hgw_msg_check_incoming(hgw, &msg, flags) == HGW_ERR_COMMUNICATION ) {
138 // Message Incoming, process msg
141 case HGW_MSG_TYPE_CBREQ:
145 Config.quitting = true;
149 case HGW_MSG_TYPE_DEVSTATE:
151 case HGW_DEVICE_STATE_SHUTDOWN:
152 Config.quitting = true; // try to quit gracefully
161 hgw_msg_free_data(&msg);
165 // For now, please keep this in sync with ../gui/controls.c
166 typedef struct ButtonEntry {
171 #define BUTTON_INITIALIZER(button, name) \
172 { kGConfKeysPath "/" name, SNES_##button##_MASK, false }
173 #define ACTION_INITIALIZER(action, name) \
174 { kGConfKeysPath "/" name, kAction##action, true }
175 #define BUTTON_LAST \
177 static const ButtonEntry buttons[] = {
178 BUTTON_INITIALIZER(A, "a"),
179 BUTTON_INITIALIZER(B, "b"),
180 BUTTON_INITIALIZER(X, "x"),
181 BUTTON_INITIALIZER(Y, "y"),
182 BUTTON_INITIALIZER(TL, "l"),
183 BUTTON_INITIALIZER(TR, "r"),
184 BUTTON_INITIALIZER(START, "start"),
185 BUTTON_INITIALIZER(SELECT, "select"),
186 BUTTON_INITIALIZER(UP, "up"),
187 BUTTON_INITIALIZER(DOWN, "down"),
188 BUTTON_INITIALIZER(LEFT, "left"),
189 BUTTON_INITIALIZER(RIGHT, "right"),
190 ACTION_INITIALIZER(Quit, "quit"),
191 ACTION_INITIALIZER(ToggleFullscreen, "fullscreen"),
195 static void parseGConfKeyMappings()
197 // Discard any other mapping
198 ZeroMemory(Config.joypad1Mapping, sizeof(Config.joypad1Mapping));
199 ZeroMemory(Config.action, sizeof(Config.action));
201 // If the user does not map fullscreen or quit
202 bool quit_mapped = false;
204 printf("Hgw: Using gconf key mappings\n");
207 for (i = 0; buttons[i].gconf_key; i++) {
208 if (hgw_conf_request_int(hgw, buttons[i].gconf_key, &scancode) == HGW_ERR_NONE) {
209 if (scancode <= 0 || scancode > 255) continue;
211 if (buttons[i].is_action) {
212 Config.action[scancode] |= buttons[i].mask;
213 if (buttons[i].mask & (kActionQuit | kActionToggleFullscreen)) {
217 Config.joypad1Mapping[scancode] |= buttons[i].mask;
224 // Newbie user won't know how to quit game.
225 if (!Config.joypad1Mapping[72] && !Config.action[72]) {
226 // Fullscreen key is not mapped, map
227 Config.action[72] = kActionQuit;
230 if (!quit_mapped && !Config.joypad1Mapping[9] && !Config.action[9]) {
231 // Escape key is not mapped, map
232 // But only if we couldn't map quit to fullscreen. Some people
233 // actually want Quit not to be mapped.
234 Config.action[9] = kActionQuit;
238 // Force mapping of fullscreen to Quit if can't map anywhere else.
239 Config.joypad1Mapping[72] = 0;
240 Config.action[72] = kActionQuit;