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