0
|
1 #define __PWPLIB_C
|
|
2
|
|
3 #include "config.h"
|
|
4
|
|
5 #include <stdio.h>
|
|
6 #include <stdlib.h>
|
|
7
|
|
8 #include <signal.h>
|
|
9 #include <time.h>
|
|
10 #include <sys/time.h>
|
|
11
|
|
12 #include "pwplib.h"
|
|
13 #include "tty.h"
|
|
14
|
|
15 #define DESTRUCTORS 8
|
|
16
|
|
17 /******************** random stuff *************************/
|
|
18
|
|
19 extern void pwplib_dummy();
|
|
20 #define pwp_dummy pwplib_dummy
|
|
21
|
|
22 void pwpwrite(char*z)
|
|
23 {
|
|
24 if(!pwplib.setup[SETUP_SHUTUP])
|
|
25 {
|
|
26 fprintf(stderr,"%s",z);
|
|
27 usleep(1000*pwplib.set.infodelay);
|
|
28 }
|
|
29 }
|
|
30
|
|
31 /********************* timer ******************************/
|
|
32
|
|
33 #define TIMERHZ 72
|
|
34 int pwp_unix_tod()
|
|
35 {
|
|
36 struct timeval tod;
|
|
37 gettimeofday(&tod,NULL);
|
|
38 return (tod.tv_sec*TIMERHZ)+(tod.tv_usec*TIMERHZ/1000000);
|
|
39 }
|
|
40
|
|
41 /********************* destructors, signals etc **********/
|
|
42
|
|
43 void pwp_fatalsignal(int n)
|
|
44 {
|
|
45 char buf[40];
|
|
46
|
|
47 pwplib_shutdown();
|
|
48
|
|
49 sprintf(buf,"* died to signal %d\n",n);
|
|
50 pwpwrite(buf);
|
|
51
|
|
52 exit(1);
|
|
53 }
|
|
54
|
|
55 /******************** initialization *********************/
|
|
56
|
|
57 int pwplib_initcore()
|
|
58 {
|
|
59 pwplib_init_common();
|
|
60
|
|
61 /*** set signals ***/
|
|
62
|
|
63 signal(SIGTERM,pwp_fatalsignal);
|
|
64 signal(SIGINT,pwp_fatalsignal);
|
|
65 signal(SIGQUIT,pwp_fatalsignal);
|
|
66 signal(SIGKILL,pwp_fatalsignal);
|
|
67 signal(SIGSEGV,pwp_fatalsignal);
|
|
68
|
|
69 /*** video ***/
|
|
70
|
|
71 # ifdef DRIVE_VIDEO
|
|
72
|
|
73 # ifdef DRIVE_SDL
|
|
74 if(pwp_SDL_init())
|
|
75 {
|
|
76 }
|
|
77 else
|
|
78 # endif
|
|
79 # ifdef DRIVE_PVP
|
|
80 if(pwplib.setup[SETUP_PVP])
|
|
81 pvp_init();
|
|
82 else
|
|
83 # endif
|
|
84 if(!pwplib.setup[SETUP_NOVIDEO])
|
|
85 {
|
|
86 tty_init();
|
|
87 }
|
|
88 # endif
|
|
89
|
|
90 /*** audio ***/
|
|
91 # ifdef DRIVE_AUDIO
|
|
92 if(!pwplib.setup[SETUP_NOSOUND])
|
|
93 {
|
|
94 int snd=0;
|
|
95 #ifdef DRIVE_SDL
|
|
96 if(!snd) { if(pwp_sdlaudio_init())snd++; }
|
|
97 #endif
|
|
98
|
|
99 #ifdef DRIVE_OSS
|
|
100 if(!snd) { if(oss_init())snd++; }
|
|
101 #endif
|
|
102
|
|
103 #ifdef DRIVE_HPUX
|
|
104 if(!snd) { if(hpuxsnd_init())snd++; }
|
|
105 #endif
|
|
106
|
|
107 if(!snd)
|
|
108 pwpwrite("* couldn't init sound. going silent.\n");
|
|
109
|
|
110 }
|
|
111 else
|
|
112 pwpwrite("* no sound, as requested\n");
|
|
113 # endif
|
|
114
|
|
115 /*** fallbacks - remove? ***/
|
|
116
|
|
117 if(pwplib.dump_rast==pwplib_dummy && pwplib.dump_attr!=pwplib_dummy)
|
|
118 pwplib.dump_rast=pwplib_dump_rast_plain;
|
|
119
|
|
120 /*** timer ***/
|
|
121
|
|
122 if(pwplib.setup[SETUP_BPS]|pwplib.setup[SETUP_FPS])
|
|
123 {
|
|
124 char tmp[100];
|
|
125 sprintf(tmp,"non-realtime output (bps=%d fps=%d)\n",
|
|
126 pwplib.setup[SETUP_BPS],pwplib.setup[SETUP_FPS]);
|
|
127 pwpwrite(tmp);
|
|
128
|
|
129 pwplib.timerfunc=pwp_timer_nrt;
|
|
130 pwplib.timer_counter=0;
|
|
131 }
|
|
132 else
|
|
133 pwplib.timerfunc=pwp_unix_tod;
|
|
134
|
|
135 /*** hmmm ***/
|
|
136
|
|
137 if(pwplib.setup[SETUP_HALVE])
|
|
138 pwplib.videobuf.height<<=1;
|
|
139
|
|
140 /* only allow if smaller than original? */
|
|
141
|
|
142 if(pwplib.setup[SETUP_USERHEIGHT])
|
|
143 pwplib.videobuf.height=pwplib.setup[SETUP_USERHEIGHT];
|
|
144 if(pwplib.setup[SETUP_USERWIDTH])
|
|
145 pwplib.videobuf.width=pwplib.setup[SETUP_USERWIDTH];
|
|
146
|
|
147 /*** done ***/
|
|
148
|
|
149 # ifdef DRIVE_VIDEO
|
|
150 if(!pwplib.setup[SETUP_NOVIDEO])
|
|
151 {char tmp[100];
|
|
152 sprintf(tmp,"* pwplib now controls a %d x %d framebuffer\n",
|
|
153 pwplib.videobuf.width,pwplib.videobuf.height);
|
|
154 pwpwrite(tmp);
|
|
155 }
|
|
156 # endif
|
|
157
|
|
158 return 1;
|
|
159 }
|
|
160
|
|
161 /************************************/
|
|
162
|
|
163 const char*pwplogo=
|
|
164 "\033[2J\033[H\n"
|
|
165 " \033[36;46mMMmmmmmmMM\033[0m\n"
|
|
166 " \033[36;46mMM\033[0m\n"
|
|
167 " \033[31;41mxxxxxxxxxxxx\033[0m\n"
|
|
168 " \033[31;41mxxxxxxxxxxxxxxxxxxx\033[0m\n"
|
|
169 " \033[31;41mxxxxxxxxx\033[0m\n"
|
|
170 " \033[33;43mZZZZZ\033[34;44m....\033[0m %%%%%%%%% %%% %%% %%%%%%%%%\n"
|
|
171 " \033[37;47m@@@@\033[34;44m......\033[0m %%%%%%%%%. %%%....... %%%. %%%%%%%%%....\n"
|
|
172 " \033[37;47m@@@@\033[34;44m....\033[37mo\033[34m.\033[0m .....%%% %%% %%% %%% %%% %%% %%%\n"
|
|
173 " \033[37;47m@@@@@@@\033[34;44m....\033[0m %%% %%% %%% %%% %%% %%% %%%\n"
|
|
174 " \033[37;47m@@@@@@@@@@@\033[0m %%%% %%% %%% %%% %%% %%%% %%%\n"
|
|
175 " \033[37;47m@@@@@@@@@@@@@\033[0m %%%% %%% %%% %%% %%% %%%% %%%\n"
|
|
176 " \033[37;47m@@@@@@@@@@@@@@@\033[0m %%%%%%%%% %%% %%% %%% %%%%%%%%%\n"
|
|
177 " \033[37;47m@@@@\033[0m %%%%%%%%% %%% %%% %%% %%%%%%%%%\n"
|
|
178 " \033[37;47m@@@@@@\033[0m %%% %%%%% %%% %%% %%%\n"
|
|
179 " \033[37;47m@@@@@@@@@@\033[0m \033[31;41mxx\033[0m %%% %%%%% %%% %%% %%%\n"
|
|
180 " \033[37;47m@@@@@@@@@@@@@@\033[0m %%% %%%%% %%%% %%% %%%\n"
|
|
181 " \033[37;47m@@@@@@@@@@@\033[0m %%% %%%%% %%%% %%% %%%\n"
|
|
182 " \033[37;47m@@@@@@@@@\033[0m .....%%%....... %%%%%%%%%%%%%%. %%%..........\n"
|
|
183 " \033[37;47m@@@@@\033[0m %%% %%%%%%%%%%%%%% %%%\n"
|
|
184 " \033[37;47m@@@@\033[0m\n\n";
|
|
185
|
|
186
|
|
187 void pwplib_startup()
|
|
188 {
|
|
189 if(!pwplib.setup[SETUP_SHUTUP])
|
|
190 {
|
|
191 pwpwrite("starting up.... 2sec delay for ^C");
|
|
192 sleep(2);
|
|
193 }
|
|
194
|
|
195 /* send initstuff? */
|
|
196 }
|
|
197
|
|
198 void pwplib_end()
|
|
199 {
|
|
200 if(pwplib.setup[SETUP_SHUTUP])return;
|
|
201
|
|
202 pwplib_shutdown();
|
|
203 sleep(2);
|
|
204
|
|
205 fputs(pwplogo,stderr);
|
|
206 pwpwrite("shutting down multimedia subsystems\n"
|
|
207 "operation finished - support pwp\n\n\n");
|
|
208 }
|
|
209
|
|
210 /***************************************************************/
|
|
211
|
|
212 int pwplib_init(int argc,char**argv)
|
|
213 {
|
|
214 int i=0,quit=0;
|
|
215
|
|
216 pwplib.argc=argc;
|
|
217 pwplib.argv=argv;
|
|
218
|
|
219 pwplib_getopts();
|
|
220
|
|
221 if(pwplib.setup[SETUP_WANTHELP])
|
|
222 {
|
|
223 printhelp();
|
|
224 exit(0);
|
|
225 pwplib.setup[SETUP_SHUTUP]++;
|
|
226 }
|
|
227
|
|
228 if(!pwplib.setup[SETUP_SHUTUP])
|
|
229 {
|
|
230 fputs(pwplogo,stderr);
|
|
231 pwpwrite("pwplib " PWPLIB_VERSION " initializing..\n\nrun with --help for some options\n\n");
|
|
232 }
|
|
233
|
|
234 {char buf[40];
|
|
235 sprintf(buf,"* using locale '%s'\n",pwplib.set.lang);
|
|
236 pwpwrite(buf);
|
|
237 }
|
|
238
|
|
239 if(!pwplib_initcore())
|
|
240 {
|
|
241 pwpwrite("initialization failed!\n");
|
|
242 return 0;
|
|
243 }
|
|
244
|
|
245 if(pwplib.setup[SETUP_WANTHELP])
|
|
246 return 0;
|
|
247
|
|
248 return 1;
|
|
249 }
|