Mercurial > hg > forks > pwpunix
comparison pwplib/setup.c @ 0:acb5694e93d9
Initial import.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 18 May 2010 04:25:44 +0300 |
parents | |
children | c60e531d19cd |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:acb5694e93d9 |
---|---|
1 #include "config.h" | |
2 #include "pwplib.h" | |
3 | |
4 #define DESTRUCTORS 8 | |
5 | |
6 /******************** random stuff *************************/ | |
7 | |
8 void pwplib_dummy(){} | |
9 #define pwp_dummy pwplib_dummy | |
10 | |
11 void pwplib_dump_rast_plain() | |
12 { | |
13 TEMPMALL(u8,tmp,pwplib.videobuf.width*pwplib.videobuf.height*2); | |
14 u8 | |
15 *d=tmp, | |
16 *parentbuf=pwplib.videobuf.d, | |
17 *s=parentbuf; | |
18 | |
19 int i=pwplib.videobuf.width*pwplib.videobuf.height; | |
20 | |
21 for(;i;i--) | |
22 { | |
23 #ifdef DRIVE_WIN32 | |
24 d[0]=176; | |
25 #else | |
26 d[0]='%'; | |
27 #endif | |
28 d[1]=*s++; | |
29 d+=2; | |
30 } | |
31 | |
32 pwplib.videobuf.d=tmp; | |
33 pwplib.dump_attr(); | |
34 pwplib.videobuf.d=parentbuf; | |
35 | |
36 TEMPFREE(tmp); | |
37 } | |
38 | |
39 /********************* timer (unix) ************************/ | |
40 | |
41 #define TIMERHZ 72 | |
42 int pwp_timer_nrt() | |
43 { | |
44 static int lastctr=0,framectr=0; | |
45 | |
46 if(pwplib.setup[SETUP_BPS]) | |
47 { | |
48 pwplib.timer_counter++; /* kludge */ | |
49 return (pwplib.timer_counter*TIMERHZ)/(pwplib.setup[SETUP_BPS]>>3); | |
50 } | |
51 else | |
52 { | |
53 if(pwplib.timer_counter!=lastctr) | |
54 { | |
55 framectr++; | |
56 lastctr=pwplib.timer_counter; | |
57 } | |
58 else | |
59 pwplib.timer_counter++; | |
60 return (framectr*TIMERHZ)/pwplib.setup[SETUP_FPS]; | |
61 } | |
62 } | |
63 | |
64 int pwplib_timer() | |
65 { | |
66 static int base=-1;int v; | |
67 v=pwplib.timerfunc(); | |
68 if(base==-1)base=v; | |
69 return v-base; | |
70 } | |
71 | |
72 /********************* destructors, signals etc **********/ | |
73 | |
74 void(*pwp_destr[DESTRUCTORS])(); | |
75 | |
76 void pwp_regdestr(void(*func)()) | |
77 { | |
78 static int curr=0; | |
79 pwp_destr[curr++]=func; | |
80 pwp_destr[curr]=NULL; | |
81 } | |
82 | |
83 void pwplib_shutdown() | |
84 { | |
85 int i=0; | |
86 | |
87 while(pwp_destr[i]!=NULL) | |
88 pwp_destr[i++](); | |
89 } | |
90 | |
91 /******************** initialization *********************/ | |
92 | |
93 int pwplib_init_common() | |
94 { | |
95 /*** base stuff ***/ | |
96 | |
97 pwplib.sound= | |
98 pwplib.loopflush= | |
99 pwplib.player= | |
100 pwplib.dump_attr= | |
101 pwplib.dump_rast= | |
102 pwplib.prep_attr= | |
103 pwplib.prep_rast= | |
104 pwplib_dummy; | |
105 | |
106 pwp_destr[0]=NULL; | |
107 } | |
108 | |
109 /***********************************************/ | |
110 | |
111 void rmarg(int*argc,char**argv,int n) | |
112 { | |
113 while(n<*argc) | |
114 { | |
115 argv[n]=argv[n+1]; | |
116 n++; | |
117 } | |
118 (*argc)--; | |
119 } | |
120 | |
121 /*********************************************************************/ | |
122 | |
123 #define ARGC pwplib.argc | |
124 #define ARGV pwplib.argv | |
125 int getopts(optab*argin) | |
126 { | |
127 int i=0; | |
128 | |
129 {optab*s0=argin; | |
130 while(s0->name!=NULL) | |
131 { | |
132 *(s0->var)=s0->dflt; | |
133 s0++; | |
134 } | |
135 } | |
136 | |
137 for(i=0;i<ARGC;) | |
138 { | |
139 int j=0; | |
140 | |
141 int match=0,wh=-1,lev=0,m=0; | |
142 | |
143 while(argin[j].name!=NULL) | |
144 { | |
145 char*s1=argin[j].name; | |
146 char*s0=ARGV[i]; | |
147 int ngl=0,m=0; | |
148 | |
149 while(*s0) | |
150 { | |
151 if(*s0=='-') | |
152 ngl=0; | |
153 else | |
154 if(*s0=='+') | |
155 ngl=1; | |
156 else | |
157 { | |
158 m++; | |
159 if(*s0=='\0' || *s1=='\0')break; | |
160 else | |
161 if((*s0|32)!=*s1) | |
162 { | |
163 m=0; | |
164 break; | |
165 } | |
166 s1++; | |
167 } | |
168 s0++; | |
169 } | |
170 | |
171 if(m>match) | |
172 { | |
173 match=m; | |
174 lev=ngl; | |
175 wh=j; | |
176 } | |
177 j++; | |
178 } | |
179 | |
180 if(wh>=0) | |
181 { | |
182 rmarg(&ARGC,ARGV,i); | |
183 | |
184 switch((int)argin[wh].type) | |
185 { | |
186 case(OPT_BIN): | |
187 *((int*)(argin[wh].var))=lev; | |
188 break; | |
189 | |
190 case(OPT_NOT): | |
191 *((int*)(argin[wh].var))=1-lev; | |
192 break; | |
193 | |
194 case(OPT_ONE): | |
195 *((int*)(argin[wh].var))=1; | |
196 | |
197 case(OPT_INT): | |
198 if(ARGV[i]!=NULL) | |
199 { | |
200 *((int*)(argin[wh].var))=atoi(ARGV[i]); | |
201 rmarg(&ARGC,ARGV,i); | |
202 } | |
203 break; | |
204 | |
205 case(OPT_STRING): | |
206 if(ARGV[i]!=NULL) | |
207 { | |
208 *((char**)(argin[wh].var))=strdup(ARGV[i]); | |
209 rmarg(&ARGC,&ARGV,1); | |
210 } | |
211 break; | |
212 } | |
213 } | |
214 else i++; | |
215 } | |
216 } | |
217 #undef ARGC | |
218 #undef ARGV | |
219 | |
220 /************************************/ | |
221 | |
222 optab main_init[]= | |
223 { | |
224 /* stuph */ | |
225 "help", OPT_ONE,(void*)0,(void*)&pwplib.setup[SETUP_WANTHELP], | |
226 "shutup", OPT_ONE,(void*)0,(void*)&pwplib.setup[SETUP_SHUTUP], | |
227 "infodelay",OPT_INT,(void*)100,(void*)&pwplib.set.infodelay, | |
228 | |
229 /* general */ | |
230 "nosound",OPT_ONE,(void*)0,(void*)&pwplib.setup[SETUP_NOSOUND], | |
231 "novideo",OPT_ONE,(void*)0,(void*)&pwplib.setup[SETUP_NOVIDEO], | |
232 | |
233 /* video */ | |
234 "term", OPT_STRING,(void*)NULL,(void*)&pwplib.set.term, | |
235 "lang", OPT_STRING,(void*)NULL,(void*)&pwplib.set.lang, | |
236 "tty", OPT_BIN,(void*)0,(void*)&pwplib.setup[SETUP_TTY], /* obsolete? */ | |
237 "pvp", OPT_BIN,(void*)0,(void*)&pwplib.setup[SETUP_PVP], | |
238 | |
239 /* size */ | |
240 "height", OPT_INT,(void*)0,(void*)&pwplib.setup[SETUP_USERHEIGHT], | |
241 "width", OPT_INT,(void*)0,(void*)&pwplib.setup[SETUP_USERWIDTH], | |
242 | |
243 /* conversion */ | |
244 "trans", OPT_INT,(void*)-1,(void*)&pwplib.setup[SETUP_TRANS], | |
245 "colors", OPT_INT,(void*)-1,(void*)&pwplib.setup[SETUP_COLORS], | |
246 "raster", OPT_INT,(void*)-1,(void*)&pwplib.setup[SETUP_RASTER], | |
247 "halve", OPT_BIN,(void*)1,(void*)&pwplib.setup[SETUP_HALVE], | |
248 | |
249 /* tty-etc stuff */ | |
250 "fps", OPT_INT,(void*)0,(void*)&pwplib.setup[SETUP_FPS], | |
251 "bps", OPT_INT,(void*)0,(void*)&pwplib.setup[SETUP_BPS], | |
252 "minfps", OPT_INT,(void*)0,(void*)&pwplib.setup[SETUP_MINFPS], | |
253 "maxfps", OPT_INT,(void*)256,(void*)&pwplib.setup[SETUP_MAXFPS], | |
254 "lossy", OPT_BIN,(void*)0,(void*)&pwplib.setup[SETUP_LOSSY], | |
255 "fdelay", OPT_INT,(void*)0,(void*)&pwplib.set.framedelay, | |
256 "fbytes", OPT_INT,(void*)500,(void*)&pwplib.set.framebytes, | |
257 | |
258 /* audio options */ | |
259 "audev", OPT_STRING,(void*)NULL,(void*)&pwplib.set.audev, | |
260 "volume", OPT_INT,(void*)32,(void*)&pwplib.setup[SETUP_VOLUME], | |
261 | |
262 NULL,0,NULL,NULL | |
263 }; | |
264 | |
265 void printhelp() | |
266 { | |
267 printf( | |
268 "usage: %s [options] where options include:\n\n" | |
269 | |
270 " help this text\n" | |
271 | |
272 "\n" | |
273 | |
274 " shutup be quiet - only output the essentials\n" | |
275 " term s set terminal type to s (e.g. xterm-color, vt100, ansi)\n" | |
276 " lang s set locale/language to s (e.g. en, fi)\n" | |
277 " pvp output in pwp video phormat (stdout)\n" | |
278 | |
279 "\n" | |
280 | |
281 " nosound no sound\n" | |
282 " novideo no video output\n" | |
283 | |
284 "\n" | |
285 | |
286 " height x set buffer height (default = fullwindow)\n" | |
287 " width x set buffer width (default = fullwindow)\n" | |
288 | |
289 "\n" | |
290 | |
291 " volume v set soft volume to v (numeric, default 32)\n" | |
292 " colors x color configuration: 0=16x16, 1=8fg 2=8bg, 3=8x8\n" | |
293 " 8=monochrome, 9=vtattributes\n" | |
294 " trans n charset: 1=ibm, 2=ascii, 3=ascii-pure\n" | |
295 " raster n raster rendering mode: 0==fg+bg 1=fgonly 2=mono\n" | |
296 " ascii pure ascii: no colors, no attributes\n" | |
297 " nohalve always use one character cell to represent a pixel\n" | |
298 | |
299 "\n" | |
300 | |
301 " fbytes n bytes/frame threshold (optimize frame if exceeded)\n" | |
302 " fdelay n delay after each frame (milliseconds)\n" | |
303 | |
304 "\n" | |
305 | |
306 " bps n non-rt: fix to n bits per second, no delay\n" | |
307 " fps n non-rt: fix to n frames per second, no delay\n" | |
308 "\n",pwplib.argv[0]); | |
309 } | |
310 | |
311 void pwplib_getopts() | |
312 { | |
313 getopts(main_init); | |
314 | |
315 if(pwplib.set.lang==NULL) | |
316 pwplib.set.lang=pwp_get_locale(); | |
317 } | |
318 |