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