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