Mercurial > hg > forks > pwpunix
annotate pwplib/pwplib-unix.c @ 53:f0c596c5905b
Make Final Isi hack more easily configurable.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 26 May 2010 00:42:25 +0300 |
parents | 411c1c8d810e |
children | 85671798fdb3 |
rev | line source |
---|---|
0 | 1 #define __PWPLIB_C |
2 | |
53
f0c596c5905b
Make Final Isi hack more easily configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
3 #undef FISI_HACK /* NOTICE! Enabling this is a hack for Final ISI only */ |
f0c596c5905b
Make Final Isi hack more easily configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
4 |
0 | 5 #include "config.h" |
6 | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 | |
15
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
10 #ifdef DRIVE_SDL |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
11 #include <SDL.h> |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
12 #endif |
0 | 13 #include <signal.h> |
14 #include <time.h> | |
15 #include <sys/time.h> | |
16 | |
17 #include "pwplib.h" | |
18 #include "tty.h" | |
19 | |
20 | |
21 /******************** random stuff *************************/ | |
22 | |
15
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
23 static int sdl_init = 0; |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
24 |
0 | 25 extern void pwplib_dummy(); |
26 #define pwp_dummy pwplib_dummy | |
27 | |
17
c60e531d19cd
Some misc. cleanups and minor warning removals.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
28 void pwpwrite(const char *fmt, ...) |
0 | 29 { |
19 | 30 if (!pwplib.setup[SETUP_SHUTUP]) { |
31 va_list ap; | |
32 va_start(ap, fmt); | |
33 vfprintf(stderr, fmt, ap); | |
34 va_end(ap); | |
17
c60e531d19cd
Some misc. cleanups and minor warning removals.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
35 |
19 | 36 usleep(1000 * pwplib.set.infodelay); |
37 } | |
0 | 38 } |
39 | |
40 /********************* timer ******************************/ | |
41 | |
42 #define TIMERHZ 72 | |
43 int pwp_unix_tod() | |
44 { | |
15
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
45 #ifdef DRIVE_SDL |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
46 if (sdl_init) { |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
47 int quit = 0; |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
48 SDL_Event event; |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
49 if (SDL_PollEvent(&event) >= 0) { |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
50 switch (event.type) { |
19 | 51 case SDL_KEYDOWN: |
52 if (event.key.keysym.sym == SDLK_ESCAPE) | |
53 quit = 1; | |
54 break; | |
53
f0c596c5905b
Make Final Isi hack more easily configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
55 #ifdef FISI_HACK |
19 | 56 case SDL_QUIT: |
57 quit = 1; | |
58 break; | |
52
411c1c8d810e
Use #if 0 instead of commenting out.
Matti Hamalainen <ccr@tnsp.org>
parents:
51
diff
changeset
|
59 #endif |
15
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
60 } |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
61 } |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
62 if (quit) { |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
63 SDL_Quit(); |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
64 pwplib_shutdown(); |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
65 exit(1); |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
66 } |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
67 return (SDL_GetTicks() * TIMERHZ) / 1000; |
19 | 68 } |
69 else | |
15
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
70 #endif |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
71 { |
0 | 72 struct timeval tod; |
19 | 73 gettimeofday(&tod, NULL); |
74 return (tod.tv_sec * TIMERHZ) + (tod.tv_usec * TIMERHZ / 1000000); | |
15
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
75 } |
0 | 76 } |
77 | |
78 /********************* destructors, signals etc **********/ | |
79 | |
80 void pwp_fatalsignal(int n) | |
81 { | |
19 | 82 pwpwrite("* pwplib shutting down\n"); |
15
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
83 |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
84 #ifdef DRIVE_SDL |
19 | 85 if (sdl_init) { |
86 sdl_init = 0; | |
87 SDL_Quit(); | |
88 } | |
15
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
89 #endif |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
90 |
19 | 91 pwplib_shutdown(); |
0 | 92 |
19 | 93 pwpwrite("* died to signal %d\n", n); |
94 | |
95 exit(1); | |
0 | 96 } |
97 | |
98 /******************** initialization *********************/ | |
99 | |
100 int pwplib_initcore() | |
101 { | |
19 | 102 int sdl_flags = 0; |
103 pwplib_init_common(); | |
0 | 104 |
19 | 105 /*** setup signals, etc ***/ |
0 | 106 |
15
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
107 #ifdef DRIVE_SDL |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
108 #ifdef DRIVE_VIDEO |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
109 sdl_flags |= SDL_INIT_VIDEO; |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
110 #endif |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
111 #ifdef DRIVE_AUDIO |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
112 sdl_flags |= SDL_INIT_AUDIO; |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
113 #endif |
53
f0c596c5905b
Make Final Isi hack more easily configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
114 #ifdef FISI_HACK |
f0c596c5905b
Make Final Isi hack more easily configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
115 sdl_flags |= SDL_INIT_NOPARACHUTE; |
f0c596c5905b
Make Final Isi hack more easily configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
116 #endif |
f0c596c5905b
Make Final Isi hack more easily configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
117 |
19 | 118 /* With SDL, we let it handle the signals */ |
119 if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_EVENTTHREAD | sdl_flags) != 0) { | |
28 | 120 pwpwrite("* SDL could not be initialized (%s).\n", SDL_GetError()); |
15
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
121 sdl_init = 0; |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
122 } else |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
123 sdl_init = 1; |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
124 #endif |
fa87f8897f21
Implement hacky and crummy SDL event handling in timer value fetching function; moved SDL general initialization into pwplib-unix.c.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
125 |
19 | 126 if (!sdl_init) { |
127 signal(SIGTERM, pwp_fatalsignal); | |
128 signal(SIGINT, pwp_fatalsignal); | |
129 signal(SIGQUIT, pwp_fatalsignal); | |
130 signal(SIGKILL, pwp_fatalsignal); | |
131 signal(SIGSEGV, pwp_fatalsignal); | |
132 } | |
0 | 133 |
134 /*** video ***/ | |
135 | |
136 # ifdef DRIVE_VIDEO | |
137 | |
138 # ifdef DRIVE_SDL | |
19 | 139 if (sdl_init && pwp_SDL_init()) |
140 { | |
141 } | |
142 else | |
0 | 143 # endif |
144 # ifdef DRIVE_PVP | |
19 | 145 if (pwplib.setup[SETUP_PVP]) |
146 pvp_init(); | |
147 else | |
0 | 148 # endif |
19 | 149 if (!pwplib.setup[SETUP_NOVIDEO]) |
150 { | |
151 tty_init(); | |
152 } | |
0 | 153 # endif |
154 | |
155 /*** audio ***/ | |
156 # ifdef DRIVE_AUDIO | |
19 | 157 if (!pwplib.setup[SETUP_NOSOUND]) |
158 { | |
159 int snd = 0; | |
0 | 160 #ifdef DRIVE_SDL |
19 | 161 if (!snd) |
162 { | |
163 if (sdl_init && pwp_sdlaudio_init()) | |
164 snd++; | |
165 } | |
0 | 166 #endif |
167 | |
168 #ifdef DRIVE_OSS | |
19 | 169 if (!snd) |
170 { | |
171 if (oss_init()) | |
172 snd++; | |
173 } | |
0 | 174 #endif |
175 | |
176 #ifdef DRIVE_HPUX | |
19 | 177 if (!snd) |
178 { | |
179 if (hpuxsnd_init()) | |
180 snd++; | |
181 } | |
0 | 182 #endif |
183 | |
19 | 184 if (!snd) |
185 pwpwrite("* couldn't init sound. going silent.\n"); | |
0 | 186 |
19 | 187 } |
188 else | |
189 pwpwrite("* no sound, as requested\n"); | |
0 | 190 # endif |
191 | |
192 /*** fallbacks - remove? ***/ | |
193 | |
19 | 194 if (pwplib.dump_rast == pwplib_dummy && pwplib.dump_attr != pwplib_dummy) |
195 pwplib.dump_rast = pwplib_dump_rast_plain; | |
0 | 196 |
197 /*** timer ***/ | |
198 | |
19 | 199 if (pwplib.setup[SETUP_BPS] | pwplib.setup[SETUP_FPS]) |
200 { | |
201 pwpwrite("non-realtime output (bps=%d fps=%d)\n", pwplib.setup[SETUP_BPS], pwplib.setup[SETUP_FPS]); | |
202 pwplib.timerfunc = pwp_timer_nrt; | |
203 pwplib.timer_counter = 0; | |
204 } | |
0 | 205 else |
19 | 206 pwplib.timerfunc = pwp_unix_tod; |
0 | 207 |
208 /*** hmmm ***/ | |
209 | |
29
d83239a98d1e
Take SDL into account when halving height of rendering buffer, and remove the corresponding "hack" from sdl.c. Also misc. cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
210 if (!sdl_init && pwplib.setup[SETUP_HALVE]) |
19 | 211 pwplib.videobuf.height <<= 1; |
0 | 212 |
19 | 213 /* only allow if smaller than original? */ |
0 | 214 |
19 | 215 if (pwplib.setup[SETUP_USERHEIGHT]) |
216 pwplib.videobuf.height = pwplib.setup[SETUP_USERHEIGHT]; | |
217 if (pwplib.setup[SETUP_USERWIDTH]) | |
218 pwplib.videobuf.width = pwplib.setup[SETUP_USERWIDTH]; | |
0 | 219 |
220 /*** done ***/ | |
19 | 221 |
0 | 222 # ifdef DRIVE_VIDEO |
19 | 223 if (!pwplib.setup[SETUP_NOVIDEO]) |
224 { | |
225 pwpwrite("* pwplib now controls a %d x %d framebuffer\n", pwplib.videobuf.width, pwplib.videobuf.height); | |
226 } | |
0 | 227 # endif |
228 | |
19 | 229 return 1; |
0 | 230 } |
231 | |
232 /************************************/ | |
233 | |
19 | 234 const char *pwplogo = |
235 "\033[2J\033[H\n" | |
236 " \033[36;46mMMmmmmmmMM\033[0m\n" | |
237 " \033[36;46mMM\033[0m\n" | |
238 " \033[31;41mxxxxxxxxxxxx\033[0m\n" | |
239 " \033[31;41mxxxxxxxxxxxxxxxxxxx\033[0m\n" | |
240 " \033[31;41mxxxxxxxxx\033[0m\n" | |
241 " \033[33;43mZZZZZ\033[34;44m....\033[0m %%%%%%%%% %%% %%% %%%%%%%%%\n" | |
242 " \033[37;47m@@@@\033[34;44m......\033[0m %%%%%%%%%. %%%....... %%%. %%%%%%%%%....\n" | |
243 " \033[37;47m@@@@\033[34;44m....\033[37mo\033[34m.\033[0m .....%%% %%% %%% %%% %%% %%% %%%\n" | |
244 " \033[37;47m@@@@@@@\033[34;44m....\033[0m %%% %%% %%% %%% %%% %%% %%%\n" | |
245 " \033[37;47m@@@@@@@@@@@\033[0m %%%% %%% %%% %%% %%% %%%% %%%\n" | |
246 " \033[37;47m@@@@@@@@@@@@@\033[0m %%%% %%% %%% %%% %%% %%%% %%%\n" | |
247 " \033[37;47m@@@@@@@@@@@@@@@\033[0m %%%%%%%%% %%% %%% %%% %%%%%%%%%\n" | |
248 " \033[37;47m@@@@\033[0m %%%%%%%%% %%% %%% %%% %%%%%%%%%\n" | |
249 " \033[37;47m@@@@@@\033[0m %%% %%%%% %%% %%% %%%\n" | |
250 " \033[37;47m@@@@@@@@@@\033[0m \033[31;41mxx\033[0m %%% %%%%% %%% %%% %%%\n" | |
251 " \033[37;47m@@@@@@@@@@@@@@\033[0m %%% %%%%% %%%% %%% %%%\n" | |
252 " \033[37;47m@@@@@@@@@@@\033[0m %%% %%%%% %%%% %%% %%%\n" | |
253 " \033[37;47m@@@@@@@@@\033[0m .....%%%....... %%%%%%%%%%%%%%. %%%..........\n" | |
254 " \033[37;47m@@@@@\033[0m %%% %%%%%%%%%%%%%% %%%\n" | |
255 " \033[37;47m@@@@\033[0m\n\n"; | |
0 | 256 |
257 | |
258 void pwplib_startup() | |
259 { | |
19 | 260 if (!pwplib.setup[SETUP_SHUTUP]) |
261 { | |
262 pwpwrite("starting up.... 2sec delay for ^C"); | |
263 sleep(2); | |
264 } | |
0 | 265 |
19 | 266 /* send initstuff? */ |
0 | 267 } |
268 | |
269 void pwplib_end() | |
270 { | |
19 | 271 if (pwplib.setup[SETUP_SHUTUP]) |
272 return; | |
0 | 273 |
19 | 274 pwplib_shutdown(); |
275 sleep(2); | |
0 | 276 |
19 | 277 fputs(pwplogo, stderr); |
278 pwpwrite("shutting down multimedia subsystems\n" "operation finished - support pwp\n\n\n"); | |
0 | 279 } |
280 | |
281 /***************************************************************/ | |
282 | |
19 | 283 int pwplib_init(int argc, char **argv) |
0 | 284 { |
19 | 285 pwplib.argc = argc; |
286 pwplib.argv = argv; | |
0 | 287 |
19 | 288 pwplib_getopts(); |
0 | 289 |
19 | 290 if (pwplib.setup[SETUP_WANTHELP]) |
291 { | |
50
e2b6a35bcb0c
Remove usage of malloc.h; Other misc cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
292 pwplib_printhelp(); |
19 | 293 exit(0); |
294 } | |
0 | 295 |
19 | 296 if (!pwplib.setup[SETUP_SHUTUP]) |
297 { | |
298 fputs(pwplogo, stderr); | |
299 pwpwrite("pwplib " PWPLIB_VERSION " initializing..\n\nrun with --help for some options\n\n"); | |
300 } | |
301 | |
302 pwpwrite("* using locale '%s'\n", pwplib.set.lang); | |
0 | 303 |
19 | 304 if (!pwplib_initcore()) |
305 { | |
306 pwpwrite("initialization failed!\n"); | |
307 return 0; | |
308 } | |
0 | 309 |
19 | 310 if (pwplib.setup[SETUP_WANTHELP]) |
311 return 0; | |
0 | 312 |
19 | 313 return 1; |
0 | 314 } |