no sound + turbo mode in guy
[drnoksnes] / platform / hgw.cpp
1 #include <stdio.h>
2 #include <hgw/hgw.h>
3
4 #include "platform.h"
5 #include "hgw.h"
6 #include "snes9x.h"
7
8 #define DIE(format, ...) do { \
9                 fprintf(stderr, "Died at %s:%d: ", __FILE__, __LINE__ ); \
10                 fprintf(stderr, format "\n", ## __VA_ARGS__); \
11                 abort(); \
12         } while (0);
13
14
15
16 bool hgwLaunched;
17 static HgwContext *hgw;
18
19 void HgwInit()
20 {
21         // hildon-games-wrapper sets this env variable for itself.
22         char* service = getenv("HGW_EXEC_SERVICE");
23         
24         if (!service) {
25                 // Not launched from hildon-games-wrapper
26                 hgwLaunched = false;
27                 return;
28         }
29         
30         hgw = hgw_context_init();
31         
32         if (!hgw) {
33                 fprintf(stderr, "Error opening hgw context\n");
34                 hgwLaunched = false;
35         }
36         
37         hgwLaunched = true;
38         printf("Loading in HGW mode\n");
39 }
40
41 void HgwDeinit()
42 {
43         if (!hgwLaunched) return;
44
45         hgw_context_destroy(hgw,
46                 (Config.snapshotSave ? HGW_BYE_PAUSED : HGW_BYE_INACTIVE));
47
48         hgw = 0;
49 }
50
51 void HgwConfig()
52 {
53         if (!hgwLaunched) return;
54         
55         Config.fullscreen = true;
56         
57         char romFile[PATH_MAX + 1];
58         if (hgw_conf_request_string(hgw, kGConfRomFile, romFile) == HGW_ERR_NONE) {
59                 S9xSetRomFile(romFile);
60         } else {
61                 hgw_context_destroy(hgw, HGW_BYE_INACTIVE);
62                 DIE("No Rom in Gconf!");
63         }
64
65         char no_audio = FALSE;
66         if (hgw_conf_request_bool(hgw, kGConfDisableAudio, &no_audio) == HGW_ERR_NONE) {
67                 Config.enableAudio = no_audio ? true : false;
68         }
69
70         char turbo = FALSE;
71         if (hgw_conf_request_bool(hgw, kGConfTurboMode, &turbo) == HGW_ERR_NONE) {
72                 Settings.TurboMode = turbo ? TRUE : FALSE;
73         }
74
75         HgwStartCommand cmd = hgw_context_get_start_command(hgw);
76         switch (cmd) {
77                 default:
78                 case HGW_COMM_NONE:     // called from libosso
79                 case HGW_COMM_CONT:
80                         Config.snapshotLoad = true;
81                         Config.snapshotSave = true;
82                         break;
83                 case HGW_COMM_RESTART:
84                         Config.snapshotLoad = false;
85                         Config.snapshotSave = true;
86                         break;
87                 case HGW_COMM_QUIT:
88                         // hum, what?
89                         Config.snapshotLoad = false;
90                         Config.snapshotSave = false;
91                         Config.quitting = true;
92                         break;
93         }
94 }
95
96 void HgwPollEvents()
97 {
98         if (!hgwLaunched) return;
99         
100         HgwMessage msg;
101         HgwMessageFlags flags = HGW_MSG_FLAG_NONE;
102         
103         if ( hgw_msg_check_incoming(hgw, &msg, flags) == HGW_ERR_COMMUNICATION ) {
104                 // Message Incoming, process msg
105                 
106                 switch (msg.type) {
107                         case HGW_MSG_TYPE_CBREQ:
108                                 switch (msg.e_val) {
109                                         case HGW_CB_QUIT:
110                                         case HGW_CB_EXIT:
111                                                 Config.quitting = true;
112                                                 break;
113                                 }
114                                 break;
115                         case HGW_MSG_TYPE_DEVSTATE:
116                                 switch (msg.e_val) {
117                                         case HGW_DEVICE_STATE_SHUTDOWN:
118                                                 Config.quitting = true; // try to quit gracefully
119                                                 break;
120                                 }
121                                 break;
122                         default:
123                                 // do nothing
124                                 break;
125                 }
126                 
127                 hgw_msg_free_data(&msg);
128         }
129 }
130
131