1 #include "osd_linux_sdl_machine.h"
2
3 int netplay_mode;
4
5 char initial_path[PATH_MAX] = "";
6 // prefered path for for searching
7
8 UChar* osd_gfx_buffer = NULL;
9
10 UChar gamepad = 0;
11 // gamepad detected ?
12
13 UChar* XBuf;
14 // The screen buffer where we draw before blitting it on screen
15
16 int gamepad_driver = 0;
17 // what kind of jypad must we have to handle
18
19 char dump_snd = 0;
20 // Do we write sound to file
21
22 char synchro;
23 // � fond, � fond, � fond? (french joke ;)
24
25 int vwidth, vheight;
26 // size of visible part of the screen (I got troubles with allegro screen->* values!)
27
28 int *fd[4];
29 // handle for joypad devices
30
31 SDL_TimerID timerId;
32 // handle for the timer callback
33
34 UInt32 interrupt_60hz(UInt32, void*);
35 // declaration of the actual callback to call 60 times a second
36
osd_init_machine(void)37 int osd_init_machine(void)
38 {
39
40 int result;
41
42 Log ("\n--[ INITIALISE MACHINE ]--------------------------\n");
43
44 if (SDL_Init(SDL_INIT_TIMER)) {
45 Log("Could not initialise SDL : %s\n",SDL_GetError());
46 return 0;
47 }
48
49 atexit(SDL_Quit);
50
51 printf (MESSAGE[language][init_allegro]);
52
53 printf (MESSAGE[language][translated_by]);
54
55 if (!(XBuf = (UChar*)malloc(XBUF_WIDTH * XBUF_HEIGHT)))
56 {
57 printf (MESSAGE[language][failed_init]);
58 return (0);
59 }
60
61 printf (MESSAGE[language][clear_buffer]);
62 bzero (XBuf, XBUF_WIDTH * XBUF_HEIGHT);
63
64 Log ("Initiating sound\n");
65 printf (MESSAGE[language][init_sound]);
66 InitSound();
67
68 /*
69 * Moved to play_game so changes made in the gui will take effect on the next game start
70
71 if (osd_snd_init_sound ())
72 {
73 Log("Sound ok\n");
74 printf(MESSAGE[language][audio_inited], 0, "SDL sound card", host.sound.freq);
75 SDL_PauseAudio(0);
76 }
77 else
78 {
79 Log("Sound not initialized\n");
80 printf(MESSAGE[language][audio_init_failed]);
81 }
82
83 */
84
85 #ifndef SDL
86 /* Opening joypad number 0 */
87 (int)fd[0] = open ("/dev/js0", O_NONBLOCK);
88 #endif
89
90 osd_gfx_buffer = XBuf + 32 + 64 * XBUF_WIDTH; // We skip the left border of 32 pixels and the 64 first top lines
91
92 timerId = SDL_AddTimer(1000 / 60, interrupt_60hz, NULL);
93 if (timerId)
94 Log("Timer initialised\n");
95 else
96 Log("Timer non initialised\n");
97
98 Log ("End of initialisation of the machine\n");
99
100 return 1;
101 }
102
103
104 /*****************************************************************************
105
106 Function: osd_shut_machine
107
108 Description: Deinitialize all stuff that have been inited in osd_int_machine
109 Parameters: none
110 Return: nothing
111
112 *****************************************************************************/
113 void
osd_shut_machine(void)114 osd_shut_machine (void)
115 {
116
117 free(XBuf);
118
119 if (sound_driver == 1)
120 osd_snd_set_volume (0);
121
122 if (timerId != NULL)
123 SDL_RemoveTimer(timerId);
124
125 #ifndef SDL
126 /* closing joypad device */
127 close ((int)fd[0]);
128 #endif
129
130 if (dump_snd)
131 fclose(out_snd);
132
133 TrashSound();
134
135 SDL_Quit();
136
137 wipe_directory(tmp_basepath);
138
139 }
140
141 /*****************************************************************************
142
143 Function: osd_keypressed
144
145 Description: Tells if a key is available for future call of osd_readkey
146 Parameters: none
147 Return: 0 is no key is available
148 else any non zero value
149
150 *****************************************************************************/
osd_keypressed(void)151 SChar osd_keypressed(void)
152 {
153
154 #warning implement keypressed with sdl
155
156 }
157
158 /*****************************************************************************
159
160 Function: osd_readkey
161
162 Description: Return the first available key stroke, waiting if needed
163 Parameters: none
164 Return: the key value (currently, lower byte is ascii and higher is scancode)
165
166 *****************************************************************************/
osd_readkey(void)167 UInt16 osd_readkey(void)
168 {
169 SDL_Event event;
170 while ( SDL_PollEvent( &event ))
171 {
172 switch (event.type)
173 {
174 case SDL_KEYDOWN:
175 return event.key.keysym.unicode;
176 case SDL_QUIT:
177 return 0;
178 }
179 }
180 }
181
182 /*****************************************************************************
183
184 Function: osd_fix_filename_slashes
185
186 Description: Changes slashes in a filename to correspond to an os need
187 Parameters: char* s
188 Return: nothing but the char* is updated
189
190 *****************************************************************************/
osd_fix_filename_slashes(char * s)191 void osd_fix_filename_slashes(char* s)
192 {
193 while (*s)
194 {
195 if (*s == '\\')
196 *s = '/';
197 s++;
198 }
199 }
200
201 /*****************************************************************************
202
203 Function: osd_init_paths
204
205 Description: set global variables for paths and filenames
206 Parameters: int argc, char* argv[] same as the command line parameters
207 Return: nothing
208
209 *****************************************************************************/
210 void
osd_init_paths(int argc,char * argv[])211 osd_init_paths(int argc, char* argv[])
212 {
213 char* home_path;
214
215 home_path = getenv("HOME");
216
217 // short_exe_name is not really the short part of the exe, but a real multi user aware
218 // path (when HOME environment variable is available)
219 if (home_path)
220 {
221 sprintf(short_exe_name,"%s/.hugo/",home_path);
222
223 // Create directory if not existing
224 mkdir(short_exe_name,0777);
225 }
226 else
227 {
228 strcpy(short_exe_name,"./");
229 }
230
231 sprintf(log_filename,"%s%s",short_exe_name,"hugo.log");
232
233 // Set a temporary path per user (should it be by process ?)
234 sprintf(tmp_basepath, "%shugo.tmp", short_exe_name);
235 mkdir(tmp_basepath, 0777);
236
237 // Set the saved game directory
238 sprintf (sav_basepath, "%ssav/", short_exe_name);
239 mkdir(sav_basepath, 0777);
240
241 // Set the video output directory
242 sprintf (video_path, "%svideo/", short_exe_name);
243 mkdir(video_path, 0777);
244
245 }
246