Mercurial > hg > forks > pwpunix
annotate pwplib/setup.c @ 35:b9d679965320
Code cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 24 May 2010 01:22:33 +0300 |
parents | f0869ef0f2d9 |
children | e2b6a35bcb0c |
rev | line source |
---|---|
0 | 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 | |
17
c60e531d19cd
Some misc. cleanups and minor warning removals.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
76 void pwplib_regdestr(void(*func)()) |
0 | 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 | |
35 | 125 static int getopts(optab *argin) |
0 | 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 | |
35 | 222 static optab main_init[]= |
0 | 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 | |
21
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
262 #if (defined(DRIVE_SDL)) |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
263 "fs", OPT_ONE,(void*)0,(void*)&pwplib.setup[SETUP_FULLSCREEN], |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
264 "xres", OPT_INT,(void*)640,(void*)&pwplib.setup[SETUP_XRES], |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
265 "yres", OPT_INT,(void*)480,(void*)&pwplib.setup[SETUP_YRES], |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
266 #endif |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
267 |
0 | 268 NULL,0,NULL,NULL |
269 }; | |
270 | |
271 void printhelp() | |
272 { | |
273 printf( | |
274 "usage: %s [options] where options include:\n\n" | |
275 | |
276 " help this text\n" | |
277 | |
278 "\n" | |
279 | |
280 " shutup be quiet - only output the essentials\n" | |
281 " term s set terminal type to s (e.g. xterm-color, vt100, ansi)\n" | |
282 " lang s set locale/language to s (e.g. en, fi)\n" | |
283 " pvp output in pwp video phormat (stdout)\n" | |
284 | |
285 "\n" | |
286 | |
287 " nosound no sound\n" | |
288 " novideo no video output\n" | |
289 | |
290 "\n" | |
291 | |
292 " height x set buffer height (default = fullwindow)\n" | |
293 " width x set buffer width (default = fullwindow)\n" | |
294 | |
295 "\n" | |
296 | |
297 " volume v set soft volume to v (numeric, default 32)\n" | |
298 " colors x color configuration: 0=16x16, 1=8fg 2=8bg, 3=8x8\n" | |
299 " 8=monochrome, 9=vtattributes\n" | |
300 " trans n charset: 1=ibm, 2=ascii, 3=ascii-pure\n" | |
301 " raster n raster rendering mode: 0==fg+bg 1=fgonly 2=mono\n" | |
302 " ascii pure ascii: no colors, no attributes\n" | |
303 " nohalve always use one character cell to represent a pixel\n" | |
304 | |
305 "\n" | |
306 | |
307 " fbytes n bytes/frame threshold (optimize frame if exceeded)\n" | |
308 " fdelay n delay after each frame (milliseconds)\n" | |
309 | |
310 "\n" | |
311 | |
312 " bps n non-rt: fix to n bits per second, no delay\n" | |
313 " fps n non-rt: fix to n frames per second, no delay\n" | |
21
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
314 |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
315 "\n" |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
316 |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
317 #if (defined(DRIVE_SDL)) |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
318 " fs full screen mode (SDL)\n" |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
319 " xres x graphical x resolution (640)\n" |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
320 " yres x graphical y resolution (480)\n" |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
321 |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
322 "\n" |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
323 #endif |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
324 , |
f0869ef0f2d9
Add commandline settings for fullscreen and changing horiz/vert resolution of SDL output. Also hide the mouse cursor.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
325 pwplib.argv[0]); |
0 | 326 } |
327 | |
328 void pwplib_getopts() | |
329 { | |
330 getopts(main_init); | |
331 | |
332 if(pwplib.set.lang==NULL) | |
333 pwplib.set.lang=pwp_get_locale(); | |
334 } | |
335 |