1 /*
2 * +-------------------------------------------------------+
3 * | |
4 * | videogen |
5 * | |
6 * | a simple XFree86 Modeline calculator |
7 * | (c) 1997-2003, Szabolcs Rumi |
8 * | |
9 * | http://www.dynaweb.hu/opensource/videogen |
10 * | |
11 * | the videogen package is distributed under the |
12 * | GNU General Public License Version 2 (GPLv2) |
13 * | |
14 * +-------------------------------------------------------+
15 */
16
17
18
19
20
21 #include <stdio.h>
22 #include <string.h>
23
24 #include "config.h"
25 #include "videogen.h"
26
27
28
29
30
31 /*
32 * parameter checking functions return values:
33 *
34 * commit success retval = 0
35 * precedence error retval = -1
36 * overflow error retval > 0
37 * underflow error retval < 0
38 */
39
40
41
42
43
44 int
commit_verbose(int precedence,unsigned int * verbose,unsigned int x)45 commit_verbose (int precedence, unsigned int *verbose, unsigned int x)
46 {
47 static int current_precedence = CFG_PREC_DEFAULT;
48
49
50
51 if (precedence < current_precedence)
52 return (-1);
53
54 *verbose = x;
55 current_precedence = precedence;
56 return (0);
57 }
58
59
60
61
62
63 int
commit_fbset(int precedence,unsigned int * fbset,unsigned int x)64 commit_fbset (int precedence, unsigned int *fbset, unsigned int x)
65 {
66 static int current_precedence = CFG_PREC_DEFAULT;
67
68
69
70 if (precedence < current_precedence)
71 return (-1);
72
73 *fbset = x;
74 current_precedence = precedence;
75 return (0);
76 }
77
78
79
80
81
82 int
commit_nvidia(int precedence,unsigned int * nvidia,unsigned int x)83 commit_nvidia (int precedence, unsigned int *nvidia, unsigned int x)
84 {
85 static int current_precedence = CFG_PREC_DEFAULT;
86
87
88
89 if (precedence < current_precedence)
90 return (-1);
91
92 *nvidia = x;
93 current_precedence = precedence;
94 return (0);
95 }
96
97
98
99
100
101 int
commit_mode(int precedence,resolution_t (* modes)[],unsigned int * num_modes,unsigned int x,unsigned int y)102 commit_mode (int precedence, resolution_t (*modes)[], unsigned int *num_modes, unsigned int x, unsigned int y)
103 {
104 static int current_precedence = CFG_PREC_DEFAULT;
105
106
107
108 if (x < CFG_WIDTH_MIN)
109 return (-2);
110
111 if (x > CFG_WIDTH_MAX)
112 return (2);
113
114 if (y < CFG_HEIGHT_MIN)
115 return (-3);
116
117 if (y > CFG_HEIGHT_MAX)
118 return (3);
119
120 if ((double)y / x < CFG_ASPECT_RATIO_MIN)
121 return (-4);
122
123 if ((double)y / x > CFG_ASPECT_RATIO_MAX)
124 return (4);
125
126 if ((unsigned int)(x / 8) * 8 != x)
127 return (6);
128
129 if (precedence < current_precedence)
130 return (-1);
131
132 if (precedence > current_precedence)
133 *num_modes = 0;
134
135 if (*num_modes > 255)
136 return (5);
137
138 (*modes)[*num_modes].hres = x;
139 (*modes)[*num_modes].vres = y;
140 (*num_modes)++;
141 current_precedence = precedence;
142 return (0);
143 }
144
145
146
147
148
149 int
commit_max_dotclk(int precedence,double * max_dotclk,double x)150 commit_max_dotclk (int precedence, double *max_dotclk, double x)
151 {
152 static int current_precedence = CFG_PREC_DEFAULT;
153
154
155
156 if (x < CFG_MAX_DOTCLK_MIN)
157 return (-2);
158
159 if (x > CFG_MAX_DOTCLK_MAX)
160 return (2);
161
162 if (precedence < current_precedence)
163 return (-1);
164
165 *max_dotclk = x;
166 current_precedence = precedence;
167 return (0);
168 }
169
170
171
172
173
174 int
commit_max_hfreq(int precedence,double * max_hfreq,double x)175 commit_max_hfreq (int precedence, double *max_hfreq, double x)
176 {
177 static int current_precedence = CFG_PREC_DEFAULT;
178
179
180
181 if (x < CFG_MAX_HFREQ_MIN)
182 return (-2);
183
184 if (x > CFG_MAX_HFREQ_MAX)
185 return (2);
186
187 if (precedence < current_precedence)
188 return (-1);
189
190 *max_hfreq = x;
191 current_precedence = precedence;
192 return (0);
193 }
194
195
196
197
198
199 int
commit_max_vfreq(int precedence,double * max_vfreq,double x)200 commit_max_vfreq (int precedence, double *max_vfreq, double x)
201 {
202 static int current_precedence = CFG_PREC_DEFAULT;
203
204
205
206 if (x < CFG_MAX_VFREQ_MIN)
207 return (-2);
208
209 if (x > CFG_MAX_VFREQ_MAX)
210 return (2);
211
212 if (precedence < current_precedence)
213 return (-1);
214
215 *max_vfreq = x;
216 current_precedence = precedence;
217 return (0);
218 }
219
220
221
222
223
224 int
commit_desired_vfreq(int precedence,double * desired_vfreq,double x)225 commit_desired_vfreq (int precedence, double *desired_vfreq, double x)
226 {
227 static int current_precedence = CFG_PREC_DEFAULT;
228
229
230
231 if (x < CFG_TARGET_VFREQ_MIN)
232 return (-2);
233
234 if (x > CFG_TARGET_VFREQ_MAX)
235 return (2);
236
237 if (precedence < current_precedence)
238 return (-1);
239
240 *desired_vfreq = x;
241 current_precedence = precedence;
242 return (0);
243 }
244
245
246
247
248
249 int
commit_hvisible(int precedence,double * hvisible,double x)250 commit_hvisible (int precedence, double *hvisible, double x)
251 {
252 static int current_precedence = CFG_PREC_DEFAULT;
253
254
255
256 if (x < CFG_HORIZ_VISIBLE_MIN)
257 return (-2);
258
259 if (x > CFG_HORIZ_VISIBLE_MAX)
260 return (2);
261
262 if (precedence < current_precedence)
263 return (-1);
264
265 *hvisible = x;
266 current_precedence = precedence;
267 return (0);
268 }
269
270
271
272
273
274 int
commit_vvisible(int precedence,double * vvisible,double x)275 commit_vvisible (int precedence, double *vvisible, double x)
276 {
277 static int current_precedence = CFG_PREC_DEFAULT;
278
279
280
281 if (x < CFG_VERT_VISIBLE_MIN)
282 return (-2);
283
284 if (x > CFG_VERT_VISIBLE_MAX)
285 return (2);
286
287 if (precedence < current_precedence)
288 return (-1);
289
290 *vvisible = x;
291 current_precedence = precedence;
292 return (0);
293 }
294
295
296
297
298
299 int
commit_hfporch(int precedence,double * hfporch,double x)300 commit_hfporch (int precedence, double *hfporch, double x)
301 {
302 static int current_precedence = CFG_PREC_DEFAULT;
303
304
305
306 if (x < CFG_HORIZ_FRONT_PORCH_MIN)
307 return (-2);
308
309 if (x > CFG_HORIZ_FRONT_PORCH_MAX)
310 return (2);
311
312 if ((unsigned int)(x / 8) * 8 != x)
313 return (3);
314
315 if (precedence < current_precedence)
316 return (-1);
317
318 *hfporch = x;
319 current_precedence = precedence;
320 return (0);
321 }
322
323
324
325
326
327 int
commit_hbporch(int precedence,double * hbporch,double x)328 commit_hbporch (int precedence, double *hbporch, double x)
329 {
330 static int current_precedence = CFG_PREC_DEFAULT;
331
332
333
334 if (x < CFG_HORIZ_BACK_PORCH_MIN)
335 return (-2);
336
337 if (x > CFG_HORIZ_BACK_PORCH_MAX)
338 return (2);
339
340 if ((unsigned int)(x / 8) * 8 != x)
341 return (3);
342
343 if (precedence < current_precedence)
344 return (-1);
345
346 *hbporch = x;
347 current_precedence = precedence;
348 return (0);
349 }
350
351
352
353
354
355 int
commit_hsync(int precedence,double * hsync,double x)356 commit_hsync (int precedence, double *hsync, double x)
357 {
358 static int current_precedence = CFG_PREC_DEFAULT;
359
360
361
362 if (x < CFG_HORIZ_SYNC_PULSE_MIN)
363 return (-2);
364
365 if (x > CFG_HORIZ_SYNC_PULSE_MAX)
366 return (2);
367
368 if (precedence < current_precedence)
369 return (-1);
370
371 *hsync = x;
372 current_precedence = precedence;
373 return (0);
374 }
375
376
377
378
379
380 int
commit_vfporch(int precedence,double * vfporch,double x)381 commit_vfporch (int precedence, double *vfporch, double x)
382 {
383 static int current_precedence = CFG_PREC_DEFAULT;
384
385
386
387 if (x < CFG_VERT_FRONT_PORCH_MIN)
388 return (-2);
389
390 if (x > CFG_VERT_FRONT_PORCH_MAX)
391 return (2);
392
393 if (precedence < current_precedence)
394 return (-1);
395
396 *vfporch = x;
397 current_precedence = precedence;
398 return (0);
399 }
400
401
402
403
404
405 int
commit_vbporch(int precedence,double * vbporch,double x)406 commit_vbporch (int precedence, double *vbporch, double x)
407 {
408 static int current_precedence = CFG_PREC_DEFAULT;
409
410
411
412 if (x < CFG_VERT_BACK_PORCH_MIN)
413 return (-2);
414
415 if (x > CFG_VERT_BACK_PORCH_MAX)
416 return (2);
417
418 if (precedence < current_precedence)
419 return (-1);
420
421 *vbporch = x;
422 current_precedence = precedence;
423 return (0);
424 }
425
426
427
428
429 int
commit_vsync(int precedence,double * vsync,double x)430 commit_vsync (int precedence, double *vsync, double x)
431 {
432 static int current_precedence = CFG_PREC_DEFAULT;
433
434
435
436 if (x < CFG_VERT_SYNC_PULSE_MIN)
437 return (-2);
438
439 if (x > CFG_VERT_SYNC_PULSE_MAX)
440 return (2);
441
442 if (precedence < current_precedence)
443 return (-1);
444
445 *vsync = x;
446 current_precedence = precedence;
447 return (0);
448 }
449
450
451
452
453
454 /* EOF */
455