source: trunk/src/opengl/glide/cvg/init/parse.c

Last change on this file was 6653, checked in by bird, 24 years ago

Added $Id:$ keyword.

File size: 34.5 KB
Line 
1/*-*-c++-*-*/
2/* $Id: parse.c,v 1.2 2001-09-05 14:30:38 bird Exp $ */
3/*
4** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
5** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
6** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX
7** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE
8** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com).
9** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
10** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A
11** FULL TEXT OF THE NON-WARRANTY PROVISIONS.
12**
13** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
14** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
15** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013,
16** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
17** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
18** THE UNITED STATES.
19**
20** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
21**
22**
23** $Revision: 1.2 $
24** $Date: 2001-09-05 14:30:38 $
25**
26** Parsing code for grabbing information from "voodoo2.ini" initialization file
27**
28*/
29#pragma optimize ("",off)
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33#include <ctype.h>
34
35#if __WIN32__
36#include <windows.h>
37
38/* Path relative to HKEY_LOCAL_MACHINE */
39#define REGSTR_PATH_3DFXSW "Software\\3Dfx Interactive\\Voodoo2"
40#define REGSTR_PATH_GLIDE REGSTR_PATH_3DFXSW"\\Glide"
41#endif /* __WIN32__ */
42
43#include <3dfx.h>
44#include <cvgregs.h>
45#include <cvgdefs.h>
46#define FX_DLL_DEFINITION
47#include <fxdll.h>
48#include <sst1vid.h>
49#include <sst1init.h>
50
51static int sst1InitFgets(char *, FILE *);
52static int sst1InitFgetc(FILE *);
53static int sst1InitParseFieldDac(char *);
54static int sst1InitParseFieldCfg(char *);
55static int sst1InitParseDacRdWrString(char *, sst1InitDacStruct *);
56static int sst1InitParseDacRdWr(char *, sst1InitDacRdWrStruct *);
57static int sst1InitParseSetVideoString(char *, sst1InitDacStruct *);
58static int sst1InitParseSetMemClkString(char *, sst1InitDacStruct *);
59static int sst1InitParseSetVideoModeString(char *, sst1InitDacStruct *);
60static void sst1InitPrintDacRdWr(sst1InitDacRdWrStruct *, char *);
61static void sst1InitToLower(char *string);
62static void sst1InitFixFilename(char *dst, char *src);
63
64static FxBool checkedFileP = FXFALSE;
65
66#ifndef INIT_LINUX
67/*
68** sst1InitVoodooFile():
69** Find and setup "voodoo2.ini" file if possible
70**
71** Returns:
72** FxTRUE if "voodoo2.ini" file is found, opened with no errors, and
73** constains the dac programming data.
74** FXFALSE if cannot find file, error opening file, or has no dac data in it.
75**
76*/
77FX_ENTRY FxBool FX_CALL sst1InitVoodooFile()
78{
79 static FxBool retVal = FXFALSE;
80
81#ifndef DIRECTX
82 int inCfg, inDac;
83 FILE *file = (FILE *) NULL;
84 char buffer[1024], filename[256];
85 int helper = (getenv(("SSTV2_DEBUGDAC"))) ? 1 : 0;
86
87 filename[0] = '\0';
88 if (checkedFileP) goto __errExit;
89
90#if __DOS32__
91 {
92 char fixedFilename[512], *tmpPtr;
93 char path[512];
94 int i;
95
96
97 if(getenv("VOODOO2_FILE")) {
98 /* Override voodoo2.ini name */
99 strcpy(filename, getenv("VOODOO2_FILE"));
100 if(!(file = fopen(filename, "r"))) goto __errExit;
101 } else {
102 /* Override path setting */
103 if(getenv("VOODOO2_PATH"))
104 strcpy(path, getenv("VOODOO2_PATH"));
105 else if(getenv("PATH")) {
106 strcpy(path, ".;");
107 strcat(path, getenv("PATH"));
108 } else
109 strcpy(path, ".;");
110
111 i = 0;
112 while(1) {
113 if(!i) {
114 if((tmpPtr = strtok(path, ";")) == NULL)
115 break;
116 } else {
117 if((tmpPtr = strtok(NULL, ";")) == NULL)
118 break;
119 }
120 strcpy(filename, tmpPtr);
121 sst1InitFixFilename(fixedFilename, filename);
122 if(fixedFilename[strlen(fixedFilename)-1] == '\\')
123 sprintf(filename, "%svoodoo2.var", filename);
124 else
125 sprintf(filename, "%s\\voodoo2.var", filename);
126 i++;
127 if((file = fopen(filename, "r")))
128 break;
129 }
130 }
131 }
132#elif __MWERKS__
133 {
134 FSSpec iniSpec = {
135 0, 0,
136 "\pvoodoo2.var"
137 };
138 Boolean foundP = false;
139
140 /* Check the app's directory */
141 if (!foundP) {
142 ProcessSerialNumber curApp;
143 ProcessInfoRec appInfo;
144 FSSpec appSpec;
145
146 if (GetCurrentProcess(&curApp) != noErr) goto __errAppDir;
147
148 /* We only care about the app's location */
149 appInfo.processInfoLength = sizeof(ProcessInfoRec);
150 appInfo.processName = NULL;
151 appInfo.processAppSpec = &appSpec;
152 if (GetProcessInformation(&curApp, &appInfo) != noErr) goto __errAppDir;
153
154 {
155 CInfoPBRec thePB;
156
157 thePB.hFileInfo.ioCompletion = NULL;
158 thePB.hFileInfo.ioNamePtr = iniSpec.name;
159 thePB.hFileInfo.ioVRefNum = appSpec.vRefNum;
160 thePB.hFileInfo.ioDirID = appSpec.parID;
161
162 thePB.hFileInfo.ioFDirIndex = 0;
163
164 foundP = ((PBGetCatInfoSync(&thePB) == noErr) &&
165 ((thePB.hFileInfo.ioFlAttrib & (0x01 << 4)) == 0));
166 if (foundP) {
167 iniSpec.vRefNum = appSpec.vRefNum;
168 iniSpec.parID = appSpec.parID;
169 }
170 }
171
172 __errAppDir:
173 ;
174 }
175
176 /* Check the mac's version of the 'search path' */
177 if (!foundP) {
178 OSType folderList[] = { kPreferencesFolderType, kExtensionFolderType };
179 int i;
180
181 for(i = 0; i < sizeof(folderList) / sizeof(folderList[0]); i++) {
182 short vRefNum;
183 long dirId;
184
185 if (FindFolder(kOnSystemDisk, folderList[i], false,
186 &vRefNum, &dirId) == noErr) {
187
188 CInfoPBRec thePB;
189
190 thePB.hFileInfo.ioCompletion = NULL;
191 thePB.hFileInfo.ioNamePtr = iniSpec.name;
192 thePB.hFileInfo.ioVRefNum = vRefNum;
193 thePB.hFileInfo.ioDirID = dirId;
194
195 thePB.hFileInfo.ioFDirIndex = 0;
196
197 foundP = ((PBGetCatInfoSync(&thePB) == noErr) &&
198 ((thePB.hFileInfo.ioFlAttrib & (0x01 << 4)) == 0));
199 if (foundP) {
200 iniSpec.vRefNum = vRefNum;
201 iniSpec.parID = dirId;
202
203 break;
204 }
205 }
206 }
207 }
208
209 if (foundP) {
210 short wdRefNum;
211 long wdDirId;
212
213 /* Change working directories, just in case the app did something else */
214 if (HGetVol(NULL, &wdRefNum, &wdDirId) != noErr) goto __errFile;
215 if (HSetVol(NULL, iniSpec.vRefNum, iniSpec.parID) != noErr) goto __errFile;
216
217 /* NB: We leave the name trashed after this */
218 p2cstr(iniSpec.name);
219 file = fopen((const char*)iniSpec.name, "r");
220
221 HSetVol(NULL, wdRefNum, wdDirId);
222
223 __errFile:
224 ;
225 }
226 }
227#endif
228
229 if(file == NULL) goto __errExit;
230
231 inCfg = inDac = 0;
232 while(sst1InitFgets(buffer, file)) {
233 buffer[strlen(buffer)-1] = (char) NULL;
234 if(!strcmp(buffer, "[VOODOO2]")) {
235 inCfg = 1; inDac = 0;
236 continue;
237 } else if (!strcmp(buffer, "[DAC]")) {
238 inCfg = 0; inDac = 1;
239 retVal = FXTRUE;
240 continue;
241 } else if(buffer[0] == '[') {
242 inCfg = 0; inDac = 0;
243 continue;
244 }
245
246 if(inCfg) {
247 if(!sst1InitParseFieldCfg(buffer)) {
248 if(helper) INIT_PRINTF(("sst1InitVoodooFile(): ERROR in [CFG] section of .ini file...\n"));
249 retVal = FXFALSE;
250 break;
251 }
252 } else if(inDac) {
253 if(!sst1InitParseFieldDac(buffer)) {
254 if(helper) INIT_PRINTF(("sst1InitVoodooFile(): ERROR in [DAC] section of .ini file...\n"));
255 retVal = FXFALSE;
256 break;
257 }
258 }
259 }
260 if (file != NULL) fclose(file);
261 INIT_PRINTF(("sst1Init Routines(): Using Initialization file '%s'\n", filename));
262
263__errExit:
264 checkedFileP = FXTRUE;
265#endif /* !DIRECTX */
266
267 return retVal;
268}
269
270#else
271
272/*
273** sst1InitVoodooFile():
274** Find and setup "voodoo2.ini" file if possible
275**
276** Returns:
277** FxTRUE if "voodoo2.ini" file is found, opened with no errors, and
278** constains the dac programming data.
279** FXFALSE if cannot find file, error opening file, or has no dac data in it.
280**
281*/
282FX_ENTRY FxBool FX_CALL sst1InitVoodooFile() {
283 static FxBool retVal = FXFALSE;
284 int inCfg, inDac;
285 FILE *file = 0;
286 char buffer[1024], filename[256];
287 char *tmpPtr;
288 char path[512];
289 int i;
290
291 filename[0] = '\0';
292 if (checkedFileP) goto __errExit;
293
294 if (getenv("VOODOO2_FILE")) {
295 /* Override voodoo2.ini name */
296 strcpy(filename, getenv("VOODOO2_FILE"));
297 if (!(file = fopen(filename, "r")))
298 goto __errExit;
299 } else {
300 /* Override path setting */
301 if (getenv("VOODOO2_PATH")) {
302 strcpy(path, getenv("VOODOO2_PATH"));
303 } else {
304 strcpy(path, "/etc/conf.3dfx");
305 }
306
307 i = 0;
308 while(1) {
309 if (!i) {
310 if ((tmpPtr = strtok(path, ":")) == NULL)
311 break;
312 } else {
313 if ((tmpPtr = strtok(NULL, ":")) == NULL)
314 break;
315 }
316 strcpy(filename, tmpPtr);
317 if (filename[strlen(filename)-1] == '\\')
318 sprintf(filename, "%voodoo2", filename);
319 else
320 sprintf(filename, "%s/voodoo2", filename);
321 i++;
322 if ((file = fopen(filename, "r")))
323 break;
324 }
325 }
326 if (!file) {
327 retVal = FXFALSE;
328 goto __errExit;
329 }
330 while(sst1InitFgets(buffer, file)) {
331 buffer[strlen(buffer)-1] = 0;
332 if (buffer[0]=='#') continue;
333 if (!sst1InitParseFieldCfg(buffer)) {
334 retVal = FXFALSE;
335 break;
336 }
337 }
338 INIT_PRINTF(("sst1Init Routines(): Using Initialization file '%s'\n", filename));
339
340__errExit:
341 if (file) fclose(file);
342 checkedFileP = FXTRUE;
343
344 return retVal;
345}
346#endif
347
348//#if defined(INIT_DOS) || defined(INIT_LINUX)
349
350#if TEST
351/* void main(int argc, char **argv) */
352static void foo(int argc, char **argv)
353{
354 char buffer[2048]; /* buffer for command line inputs */
355 int inCfg, inDac;
356 sst1InitEnvVarStruct *envVarsPtr;
357 sst1InitDacStruct *dacPtr;
358 sst1InitDacSetVideoStruct *setVideo;
359 sst1InitDacSetMemClkStruct *setMemClk;
360 FILE *file = fopen(argv[1], "r");
361
362 inCfg = inDac = 0;
363 while(sst1InitFgets(buffer, file)) {
364 buffer[strlen(buffer)-1] = (char) NULL;
365 if(!strcmp(buffer, "[CFG]")) {
366 inCfg = 1; inDac = 0;
367 continue;
368 } else if (!strcmp(buffer, "[DAC]")) {
369 inCfg = 0; inDac = 1;
370 continue;
371 } else if(buffer[0] == '[') {
372 inCfg = 0; inDac = 0;
373 continue;
374 }
375 if(inCfg) {
376 if(!sst1InitParseFieldCfg(buffer))
377 /* Error processing .ini file */
378 exit(1);
379 } else if(inDac) {
380 if(!sst1InitParseFieldDac(buffer))
381 /* Error processing .ini file */
382 exit(1);
383 }
384 }
385
386 /* Dump CFG Data... */
387 envVarsPtr = envVarsBase;
388 while(envVarsPtr) {
389 printf("ENV VAR:%s VALUE:%s\n", envVarsPtr->envVariable,
390 envVarsPtr->envValue);
391 envVarsPtr = (sst1InitEnvVarStruct *) envVarsPtr->nextVar;
392 }
393
394 /* Dump Dac Data... */
395 dacPtr = dacStructBase;
396 while(dacPtr) {
397 printf("DAC MANU:%s DEVICE:%s\n", dacPtr->dacManufacturer,
398 dacPtr->dacDevice);
399 if(dacPtr->detect) {
400 printf("\tDetect:\n");
401 sst1InitPrintDacRdWr(dacPtr->detect, "\t\t");
402 }
403 if(dacPtr->setVideo) {
404 setVideo = dacPtr->setVideo;
405 while(1) {
406 printf("\tsetVideo (%dx%d @ %d Hz)\n",
407 setVideo->width, setVideo->height, setVideo->refresh);
408 sst1InitPrintDacRdWr(setVideo->setVideoRdWr, "\t\t");
409 if(!setVideo->nextSetVideo)
410 break;
411 else
412 setVideo = setVideo->nextSetVideo;
413 }
414 }
415 if(dacPtr->setMemClk) {
416 setMemClk = dacPtr->setMemClk;
417 while(1) {
418 printf("\tsetMemClk (%d MHz)\n", setMemClk->frequency);
419 sst1InitPrintDacRdWr(setMemClk->setMemClkRdWr, "\t\t");
420 if(!setMemClk->nextSetMemClk)
421 break;
422 else
423 setMemClk = setMemClk->nextSetMemClk;
424 }
425 }
426 dacPtr = dacPtr->nextDac;
427 }
428 fclose(file);
429}
430#endif
431
432static void sst1InitFixFilename(char *dst, char *src)
433{
434 while(*src) {
435 *dst++ = *src;
436 if(*src == '\\')
437 *dst++ = *src;
438 src++;
439 }
440 *dst = (char) NULL;
441}
442
443
444static int sst1InitFgets(char *string, FILE *stream)
445{
446 int validChars = 0;
447 char *ptr = string;
448 int charRead;
449
450 while(0 != ((charRead = sst1InitFgetc(stream)))) {
451 *ptr++ = (char) charRead;
452 validChars++;
453 if(charRead == '\n') {
454 *ptr++ = (char) NULL;
455 break;
456 }
457 }
458 return(validChars);
459}
460
461static int sst1InitFgetc(FILE *stream)
462{
463 static int column = 0;
464 static int validChars = 0;
465 int charRead, charReadL;
466 int inComment;
467
468 inComment = 0;
469 while(1) {
470 charRead = fgetc(stream);
471 if(inComment == 1) {
472 if(charRead <= 0)
473 return(0);
474 else if(charRead == '\n')
475 inComment = 0;
476 column = 0;
477 validChars = 0;
478 continue;
479 } else if(column == 0 && charRead == '#') {
480 /* Comment line */
481 inComment = 1;
482 column = 0;
483 validChars = 0;
484 } else if(charRead <= 0) {
485 return(0);
486 } else {
487 if(charRead == '\n') {
488 if(validChars > 0) {
489 validChars = 0;
490 column = 0;
491 return(charRead);
492 } else
493 continue;
494 } else {
495 if(isspace(charRead))
496 continue;
497 validChars++;
498 column++;
499 charReadL = (islower(charRead)) ? toupper(charRead) : charRead;
500 return(charReadL);
501 }
502 }
503 }
504}
505
506static int sst1InitParseFieldCfg(char *string)
507{
508 char *envName, *envVal;
509 sst1InitEnvVarStruct *envVarsPtr;
510
511 if((envName = strtok(string, "=")) == NULL)
512 return(0);
513 if((envVal = strtok((char *) NULL, "=")) == NULL)
514 /* Valid environment variable, NULL value */
515 return(1);
516
517 /* .ini canonical form is now lower case */
518 sst1InitToLower(envName);
519 sst1InitToLower(envVal);
520
521 if(envVarsBase == (sst1InitEnvVarStruct *) NULL) {
522 if((envVarsPtr = malloc(sizeof(sst1InitEnvVarStruct))) ==
523 (sst1InitEnvVarStruct *) NULL)
524 return(0);
525 envVarsBase = envVarsPtr;
526 } else {
527 envVarsPtr = envVarsBase;
528 while(1) {
529 if(envVarsPtr->nextVar == (sst1InitEnvVarStruct *) NULL)
530 break;
531 else
532 envVarsPtr = envVarsPtr->nextVar;
533 }
534 if((envVarsPtr->nextVar = malloc(sizeof(sst1InitEnvVarStruct))) ==
535 (sst1InitEnvVarStruct *) NULL)
536 return(0);
537 envVarsPtr = envVarsPtr->nextVar;
538 }
539 envVarsPtr->nextVar = (sst1InitEnvVarStruct *) NULL;
540 strcpy(envVarsPtr->envVariable, envName);
541 strcpy(envVarsPtr->envValue, envVal);
542
543 return(1);
544}
545
546static int sst1InitParseFieldDac(char *string)
547{
548 char *dacFieldReference, *dacFieldValue;
549 static sst1InitDacStruct *dacPtr = (sst1InitDacStruct *) NULL;
550
551 if((dacFieldReference = strtok(string, "=")) == NULL)
552 return(0);
553 if(!strcmp(dacFieldReference, "MANUFACTURER")) {
554 /* Add new dac device */
555 if(dacStructBase == (sst1InitDacStruct *) NULL) {
556 if((dacPtr = malloc(sizeof(sst1InitDacStruct))) ==
557 (sst1InitDacStruct *) NULL)
558 return(0);
559 dacStructBase = dacPtr;
560 } else {
561 dacPtr = dacStructBase;
562 while(1) {
563 if(dacPtr->nextDac == (sst1InitDacStruct *) NULL)
564 break;
565 else
566 dacPtr = dacPtr->nextDac;
567 }
568 if((dacPtr->nextDac = malloc(sizeof(sst1InitDacStruct))) ==
569 (sst1InitDacStruct *) NULL)
570 return(0);
571 dacPtr = dacPtr->nextDac;
572 }
573 dacPtr->nextDac = (sst1InitDacStruct *) NULL;
574 dacPtr->dacManufacturer[0] = (char) NULL;
575 dacPtr->dacDevice[0] = (char) NULL;
576 dacPtr->detect = (sst1InitDacRdWrStruct *) NULL;
577 dacPtr->setVideo = (sst1InitDacSetVideoStruct *) NULL;
578 dacPtr->setMemClk = (sst1InitDacSetMemClkStruct *) NULL;
579 dacPtr->setVideoMode = (sst1InitDacSetVideoModeStruct *) NULL;
580 if((dacFieldValue = strtok((char *) NULL, "=")) == NULL)
581 return(0);
582 strcpy(dacPtr->dacManufacturer, dacFieldValue);
583 } else if(!strcmp(dacFieldReference, "DEVICE")) {
584 if((dacFieldValue = strtok((char *) NULL, "=")) == NULL)
585 return(0);
586 strcpy(dacPtr->dacDevice, dacFieldValue);
587 } else if(!strcmp(dacFieldReference, "DETECT")) {
588 if((dacFieldValue = strtok((char *) NULL, "=")) == NULL)
589 return(0);
590 sst1InitToLower(dacFieldValue);
591 if(!sst1InitParseDacRdWrString(dacFieldValue, dacPtr))
592 return(0);
593 } else if(!strcmp(dacFieldReference, "SETVIDEO")) {
594 if((dacFieldValue = strtok((char *) NULL, "=")) == NULL)
595 return(0);
596 sst1InitToLower(dacFieldValue);
597 if(!sst1InitParseSetVideoString(dacFieldValue, dacPtr))
598 return(0);
599 } else if(!strcmp(dacFieldReference, "SETMEMCLK")) {
600 if((dacFieldValue = strtok((char *) NULL, "=")) == NULL)
601 return(0);
602 sst1InitToLower(dacFieldValue);
603 if(!sst1InitParseSetMemClkString(dacFieldValue, dacPtr))
604 return(0);
605 } else if(!strcmp(dacFieldReference, "SETVIDEOMODE")) {
606 if((dacFieldValue = strtok((char *) NULL, "=")) == NULL)
607 return(0);
608 sst1InitToLower(dacFieldValue);
609 if(!sst1InitParseSetVideoModeString(dacFieldValue, dacPtr))
610 return(0);
611 } else
612 return(0);
613
614 return(1);
615}
616
617static int sst1InitParseDacRdWrString(char *string, sst1InitDacStruct *dacBase)
618{
619 int cntr = 0;
620 int i;
621 sst1InitDacRdWrStruct *dacRdWrPtr;
622 char *dacRdWrCmd;
623 char stringCpy[2048];
624
625 while(1) {
626 strcpy(stringCpy, string);
627 if((dacRdWrCmd = strtok(stringCpy, ";")) == NULL)
628 return(0);
629 if(cntr == 0) {
630 if(!(dacBase->detect = malloc(sizeof(sst1InitDacRdWrStruct))))
631 return(0);
632 dacRdWrPtr = dacBase->detect;
633 } else {
634 for(i=0; i<(cntr-1); i++) {
635 if((dacRdWrCmd = strtok(NULL, ";")) == NULL)
636 return(0);
637 }
638 if((dacRdWrCmd = strtok(NULL, ";")) == NULL) {
639 break;
640 }
641 if(!(dacRdWrPtr->nextRdWr = malloc(sizeof(sst1InitDacRdWrStruct))))
642 return(0);
643
644 dacRdWrPtr = dacRdWrPtr->nextRdWr;
645 }
646 dacRdWrPtr->nextRdWr = (sst1InitDacRdWrStruct *) NULL;
647 if(!sst1InitParseDacRdWr(dacRdWrCmd, dacRdWrPtr))
648 return(0);
649 cntr++;
650 }
651 return(1);
652}
653
654static int sst1InitParseDacRdWr(char *string, sst1InitDacRdWrStruct *dacRdWrPtr)
655{
656 char *addr, *data, *mask, *addrDataCmd;
657 char stringCpy[2048];
658
659 strcpy(stringCpy, string);
660
661 if(stringCpy[5] == '(') {
662 stringCpy[5] = (char) NULL;
663 addrDataCmd = &stringCpy[6];
664 } else if(stringCpy[7] == '(') {
665 stringCpy[7] = (char) NULL;
666 addrDataCmd = &stringCpy[8];
667 } else if(stringCpy[8] == '(') {
668 stringCpy[8] = (char) NULL;
669 addrDataCmd = &stringCpy[9];
670 } else if(stringCpy[9] == '(') {
671 stringCpy[9] = (char) NULL;
672 addrDataCmd = &stringCpy[10];
673 } else
674 return(0);
675
676 if(!strcmp(stringCpy, "dacwr")) {
677 if((addr = strtok(addrDataCmd, ",")) == NULL)
678 return(0);
679 if((data = strtok(NULL, ",")) == NULL)
680 return(0);
681 if(data[strlen(data)-1] != ')')
682 return(0);
683 data[strlen(data)-1] = (char) NULL;
684 dacRdWrPtr->type = DACRDWR_TYPE_WR;
685 SSCANF(addr, "%i", &dacRdWrPtr->addr);
686 SSCANF(data, "%i", &dacRdWrPtr->data);
687 } else if(!strcmp(stringCpy, "dacwrpop")) {
688 if((addr = strtok(addrDataCmd, ",")) == NULL)
689 return(0);
690 if((mask = strtok(NULL, ",")) == NULL)
691 return(0);
692 if((data = strtok(NULL, ",")) == NULL)
693 return(0);
694 if(data[strlen(data)-1] != ')')
695 return(0);
696 data[strlen(data)-1] = (char) NULL;
697 dacRdWrPtr->type = DACRDWR_TYPE_WRMOD_POP;
698 SSCANF(addr, "%i", &dacRdWrPtr->addr);
699 SSCANF(mask, "%i", &dacRdWrPtr->mask);
700 SSCANF(data, "%i", &dacRdWrPtr->data);
701 } else if(!strcmp(stringCpy, "dacrdwr")) {
702 if((addr = strtok(addrDataCmd, ",")) == NULL)
703 return(0);
704 if((mask = strtok(NULL, ",")) == NULL)
705 return(0);
706 if((data = strtok(NULL, ",")) == NULL)
707 return(0);
708 if(data[strlen(data)-1] != ')')
709 return(0);
710 data[strlen(data)-1] = (char) NULL;
711 dacRdWrPtr->type = DACRDWR_TYPE_RDMODWR;
712 SSCANF(addr, "%i", &dacRdWrPtr->addr);
713 SSCANF(mask, "%i", &dacRdWrPtr->mask);
714 SSCANF(data, "%i", &dacRdWrPtr->data);
715 } else if(!strcmp(stringCpy, "dacrd")) {
716 if((addr = strtok(addrDataCmd, ",")) == NULL)
717 return(0);
718 if(addr[strlen(addr)-1] == ')') {
719 dacRdWrPtr->type = DACRDWR_TYPE_RDNOCHECK;
720 SSCANF(addr, "%i", &dacRdWrPtr->addr);
721 } else {
722 dacRdWrPtr->type = DACRDWR_TYPE_RDCHECK;
723 if((data = strtok(NULL, ",")) == NULL)
724 return(0);
725 if(data[strlen(data)-1] != ')')
726 return(0);
727 data[strlen(data)-1] = (char) NULL;
728 SSCANF(addr, "%i", &dacRdWrPtr->addr);
729 SSCANF(data, "%i", &dacRdWrPtr->data);
730 }
731 } else if(!strcmp(stringCpy, "dacrdpush")) {
732 if((addr = strtok(addrDataCmd, ",")) == NULL)
733 return(0);
734 if(addr[strlen(addr)-1] == ')') {
735 dacRdWrPtr->type = DACRDWR_TYPE_RDPUSH;
736 SSCANF(addr, "%i", &dacRdWrPtr->addr);
737 } else
738 return(0);
739 } else {
740 return(0);
741 }
742
743 return(1);
744}
745
746#if TEST
747static void sst1InitPrintDacRdWr(sst1InitDacRdWrStruct *dacRdWrBase,
748 char *prefix)
749{
750 sst1InitDacRdWrStruct *dacRdWrPtr = dacRdWrBase;
751
752 while(dacRdWrPtr) {
753 if(dacRdWrPtr->type == DACRDWR_TYPE_WR) {
754 printf("%sDacWR", prefix);
755 printf("(0x%x,0x%x)\n", dacRdWrPtr->addr, dacRdWrPtr->data);
756 } else if(dacRdWrPtr->type == DACRDWR_TYPE_RDMODWR) {
757 printf("%sDacRD-MOD-WR", prefix);
758 printf("(0x%x,0x%x,0x%x)\n", dacRdWrPtr->addr, dacRdWrPtr->mask,
759 dacRdWrPtr->data);
760 } else if(dacRdWrPtr->type == DACRDWR_TYPE_RDNOCHECK) {
761 printf("%sDacRD-NOCHECK", prefix);
762 printf("(0x%x)\n", dacRdWrPtr->addr);
763 } else if(dacRdWrPtr->type == DACRDWR_TYPE_RDCHECK) {
764 printf("%sDacRD-CHECK", prefix);
765 printf("(0x%x,0x%x)\n", dacRdWrPtr->addr, dacRdWrPtr->data);
766 } else
767 printf("%sDAC???", prefix);
768 dacRdWrPtr = dacRdWrPtr->nextRdWr;
769 }
770}
771#endif /* TEST */
772
773static int sst1InitParseSetVideoString(char *string, sst1InitDacStruct *dacBase)
774{
775 int cntr = 0;
776 int i;
777 sst1InitDacRdWrStruct *dacRdWrPtr;
778 sst1InitDacSetVideoStruct *dacSetVideoPtr;
779 char *dacRdWrCmd;
780 char stringCpy[2048];
781
782 while(1) {
783 strcpy(stringCpy, string);
784 if((dacRdWrCmd = strtok(stringCpy, ";")) == NULL)
785 return(0);
786 if(cntr == 0) {
787 if(!dacBase->setVideo) {
788 if(!(dacBase->setVideo =
789 malloc(sizeof(sst1InitDacSetVideoStruct))))
790 return(0);
791 dacSetVideoPtr = dacBase->setVideo;
792 } else {
793 dacSetVideoPtr = dacBase->setVideo;
794 while(1) {
795 if(!dacSetVideoPtr->nextSetVideo)
796 break;
797 dacSetVideoPtr = dacSetVideoPtr->nextSetVideo;
798 }
799 if(!(dacSetVideoPtr->nextSetVideo =
800 malloc(sizeof(sst1InitDacSetVideoStruct))))
801 return(0);
802 dacSetVideoPtr = dacSetVideoPtr->nextSetVideo;
803 }
804 dacSetVideoPtr->nextSetVideo = (sst1InitDacSetVideoStruct *) NULL;
805 /* Width */
806 SSCANF(dacRdWrCmd, "%i", &dacSetVideoPtr->width);
807 /* Height */
808 if((dacRdWrCmd = strtok(NULL, ";")) == NULL)
809 return(0);
810 SSCANF(dacRdWrCmd, "%i", &dacSetVideoPtr->height);
811 /* Refresh */
812 if((dacRdWrCmd = strtok(NULL, ";")) == NULL)
813 return(0);
814 SSCANF(dacRdWrCmd, "%i", &dacSetVideoPtr->refresh);
815 /* video16BPP */
816 if((dacRdWrCmd = strtok(NULL, ";")) == NULL)
817 return(0);
818 SSCANF(dacRdWrCmd, "%i", &dacSetVideoPtr->video16BPP);
819 /* First DacRdWr */
820 if((dacRdWrCmd = strtok(NULL, ";")) == NULL)
821 return(0);
822 if(!(dacSetVideoPtr->setVideoRdWr =
823 malloc(sizeof(sst1InitDacRdWrStruct))))
824 return(0);
825 dacRdWrPtr = dacSetVideoPtr->setVideoRdWr;
826 } else {
827 for(i=0; i<(cntr+3); i++) {
828 if((dacRdWrCmd = strtok(NULL, ";")) == NULL)
829 return(0);
830 }
831 if((dacRdWrCmd = strtok(NULL, ";")) == NULL) {
832 break;
833 }
834 if(!(dacRdWrPtr->nextRdWr = malloc(sizeof(sst1InitDacRdWrStruct))))
835 return(0);
836 dacRdWrPtr = dacRdWrPtr->nextRdWr;
837 }
838 dacRdWrPtr->nextRdWr = (sst1InitDacRdWrStruct *) NULL;
839 if(!sst1InitParseDacRdWr(dacRdWrCmd, dacRdWrPtr))
840 return(0);
841 cntr++;
842 }
843 return(1);
844}
845
846static int sst1InitParseSetMemClkString(char *string,
847 sst1InitDacStruct *dacBase)
848{
849 int cntr = 0;
850 int i;
851 sst1InitDacRdWrStruct *dacRdWrPtr;
852 sst1InitDacSetMemClkStruct *dacSetMemClkPtr;
853 char *dacRdWrCmd;
854 char stringCpy[2048];
855
856 while(1) {
857 strcpy(stringCpy, string);
858 if((dacRdWrCmd = strtok(stringCpy, ";")) == NULL)
859 return(0);
860 if(cntr == 0) {
861 if(!dacBase->setMemClk) {
862 if(!(dacBase->setMemClk =
863 malloc(sizeof(sst1InitDacSetMemClkStruct))))
864 return(0);
865 dacSetMemClkPtr = dacBase->setMemClk;
866 } else {
867 dacSetMemClkPtr = dacBase->setMemClk;
868 while(1) {
869 if(!dacSetMemClkPtr->nextSetMemClk)
870 break;
871 dacSetMemClkPtr = dacSetMemClkPtr->nextSetMemClk;
872 }
873 if(!(dacSetMemClkPtr->nextSetMemClk =
874 malloc(sizeof(sst1InitDacSetMemClkStruct))))
875 return(0);
876 dacSetMemClkPtr = dacSetMemClkPtr->nextSetMemClk;
877 }
878 dacSetMemClkPtr->nextSetMemClk = (sst1InitDacSetMemClkStruct *)
879 NULL;
880 /* Frequency */
881 SSCANF(dacRdWrCmd, "%i", &dacSetMemClkPtr->frequency);
882
883 /* First DacRdWr */
884 if((dacRdWrCmd = strtok(NULL, ";")) == NULL)
885 return(0);
886 if(!(dacSetMemClkPtr->setMemClkRdWr =
887 malloc(sizeof(sst1InitDacRdWrStruct))))
888 return(0);
889 dacRdWrPtr = dacSetMemClkPtr->setMemClkRdWr;
890 } else {
891 for(i=0; i<(cntr); i++) {
892 if((dacRdWrCmd = strtok(NULL, ";")) == NULL)
893 return(0);
894 }
895 if((dacRdWrCmd = strtok(NULL, ";")) == NULL) {
896 break;
897 }
898 if(!(dacRdWrPtr->nextRdWr = malloc(sizeof(sst1InitDacRdWrStruct))))
899 return(0);
900 dacRdWrPtr = dacRdWrPtr->nextRdWr;
901 }
902 dacRdWrPtr->nextRdWr = (sst1InitDacRdWrStruct *) NULL;
903 if(!sst1InitParseDacRdWr(dacRdWrCmd, dacRdWrPtr))
904 return(0);
905 cntr++;
906 }
907 return(1);
908}
909
910static int sst1InitParseSetVideoModeString(char *string,
911 sst1InitDacStruct *dacBase)
912{
913 int cntr = 0;
914 int i;
915 sst1InitDacRdWrStruct *dacRdWrPtr;
916 sst1InitDacSetVideoModeStruct *dacSetVideoModePtr;
917 char *dacRdWrCmd;
918 char stringCpy[2048];
919
920 while(1) {
921 strcpy(stringCpy, string);
922 if((dacRdWrCmd = strtok(stringCpy, ";")) == NULL)
923 return(0);
924 if(cntr == 0) {
925 if(!dacBase->setVideoMode) {
926 if(!(dacBase->setVideoMode =
927 malloc(sizeof(sst1InitDacSetVideoModeStruct))))
928 return(0);
929 dacSetVideoModePtr = dacBase->setVideoMode;
930 } else {
931 dacSetVideoModePtr = dacBase->setVideoMode;
932 while(1) {
933 if(!dacSetVideoModePtr->nextSetVideoMode)
934 break;
935 dacSetVideoModePtr = dacSetVideoModePtr->nextSetVideoMode;
936 }
937 if(!(dacSetVideoModePtr->nextSetVideoMode =
938 malloc(sizeof(sst1InitDacSetVideoModeStruct))))
939 return(0);
940 dacSetVideoModePtr = dacSetVideoModePtr->nextSetVideoMode;
941 }
942 dacSetVideoModePtr->nextSetVideoMode =
943 (sst1InitDacSetVideoModeStruct *) NULL;
944 /* video16BPP */
945 SSCANF(dacRdWrCmd, "%i", &dacSetVideoModePtr->video16BPP);
946
947 /* First DacRdWr */
948 if((dacRdWrCmd = strtok(NULL, ";")) == NULL)
949 return(0);
950 if(!(dacSetVideoModePtr->setVideoModeRdWr =
951 malloc(sizeof(sst1InitDacRdWrStruct))))
952 return(0);
953 dacRdWrPtr = dacSetVideoModePtr->setVideoModeRdWr;
954 } else {
955 for(i=0; i<(cntr); i++) {
956 if((dacRdWrCmd = strtok(NULL, ";")) == NULL)
957 return(0);
958 }
959 if((dacRdWrCmd = strtok(NULL, ";")) == NULL) {
960 break;
961 }
962 if(!(dacRdWrPtr->nextRdWr = malloc(sizeof(sst1InitDacRdWrStruct))))
963 return(0);
964 dacRdWrPtr = dacRdWrPtr->nextRdWr;
965 }
966 dacRdWrPtr->nextRdWr = (sst1InitDacRdWrStruct *) NULL;
967 if(!sst1InitParseDacRdWr(dacRdWrCmd, dacRdWrPtr))
968 return(0);
969 cntr++;
970 }
971 return(1);
972}
973
974static void sst1InitToLower(char *string)
975{
976 char *ptr = string;
977
978 while(*ptr) {
979 *ptr = (isupper(*ptr)) ? tolower(*ptr) : *ptr;
980 ptr++;
981 }
982}
983
984#if __WIN32__
985FxBool GetRegistryKey(HKEY hKey, const char* keyName,
986 char* regValBuf, FxU32 bufSize)
987{
988 DWORD type;
989 DWORD tsize = bufSize;
990 FxBool retVal = FXFALSE;
991
992 // Don't worry about default if query fails, its handled higher up
993 if(!RegQueryValueEx(hKey, keyName, NULL, &type, (CONST LPBYTE)regValBuf, &tsize)) {
994 switch(type) {
995 case REG_DWORD:
996 {
997 DWORD dValue = *(DWORD*)regValBuf;
998 sprintf(regValBuf, "%d", dValue);
999 }
1000 /* Fall through */
1001
1002 case REG_SZ:
1003 retVal = FXTRUE;
1004 break;
1005 }
1006 }
1007
1008 return retVal;
1009}
1010#endif /* __WIN32__ */
1011
1012static const char*
1013myGetenv(const char* envKey)
1014{
1015 FxBool callRealGetenvP = FXTRUE;
1016
1017#if __WIN32__
1018 /* NB: If were being called from cya code in
1019 * DllMain(DLL_PROCESS_DETACH) because the current app has called
1020 * exit() or dropped off of the end of main the per dll environ
1021 * string table has been freed by the c runtime but has not been set
1022 * to NULL. Bad things happen if this memory has been unmapped by
1023 * the system or if the string cannot be found.
1024 */
1025 {
1026 HANDLE curProcessHandle = GetCurrentProcess();
1027 DWORD exitCode = STILL_ACTIVE;
1028
1029 callRealGetenvP = ((curProcessHandle != NULL) &&
1030 GetExitCodeProcess(curProcessHandle, &exitCode) &&
1031 (exitCode == STILL_ACTIVE));
1032 }
1033#endif /* __WIN32__ */
1034
1035 return (callRealGetenvP
1036 ? getenv(envKey)
1037 : NULL);
1038}
1039
1040/*
1041** sst1InitGetenv():
1042** Getenv() for INIT routines.
1043**
1044** If the actual environment variable exists (determined by a call to
1045** the system getenv() routine), then that pointer is returned. Otherwise,
1046** if the variable is defined in the [CFG] section of "voodoo2.ini", then
1047** a pointer to the value defined in "voodoo2.ini" is returned. Otherwise,
1048** NULL is returned
1049**
1050*/
1051FX_ENTRY char* FX_CALL sst1InitGetenv(char *string)
1052{
1053 const char* retVal;
1054
1055 /* Does the real environment variable exist?
1056 * This overrides everything for glide.
1057 */
1058 retVal = myGetenv(string);
1059 if (retVal == NULL) {
1060#if __WIN32__
1061 /* On windows check to see if the control panel thingee
1062 * has added entries for glide or voodoo^2.
1063 */
1064 {
1065 /* List of the various registry paths to check. These
1066 * should be in the order that you want them checked in.
1067 */
1068 static const char* regPathList[] = {
1069 REGSTR_PATH_GLIDE,
1070 REGSTR_PATH_3DFXSW
1071 };
1072 HKEY hKey;
1073 int i;
1074
1075 for(i = 0; (retVal == NULL) && (i < sizeof(regPathList) / sizeof(regPathList[0])); i++) {
1076 if (!RegOpenKey(HKEY_LOCAL_MACHINE, regPathList[i], &hKey)) {
1077#define kRegKeyBufSize 256
1078 static char regKeyBuf[kRegKeyBufSize];
1079
1080 regKeyBuf[0] = '\0';
1081 if (GetRegistryKey(hKey, string, regKeyBuf, kRegKeyBufSize)) retVal = regKeyBuf;
1082 RegCloseKey(hKey);
1083 }
1084 }
1085 }
1086#endif /* __WIN32__ */
1087
1088 /* Does the requested environment variable exist in "voodoo2.ini"? */
1089 /* Dump CFG Data... */
1090 if (!checkedFileP) {
1091 static FxBool inProc = FXFALSE;
1092
1093 if (!inProc) {
1094 inProc = FXTRUE;
1095 sst1InitVoodooFile();
1096 inProc = FXFALSE;
1097 }
1098 }
1099
1100 {
1101 sst1InitEnvVarStruct *envVarsPtr = envVarsBase;
1102 char tempSearchString[kMaxEnvVarLen];
1103
1104 /* Put the search into canonical form */
1105 strcpy(tempSearchString, string);
1106 sst1InitToLower(tempSearchString);
1107
1108 while(envVarsPtr) {
1109 if(!strcmp(tempSearchString, envVarsPtr->envVariable)) {
1110 retVal = envVarsPtr->envValue;
1111 break;
1112 }
1113 envVarsPtr = (sst1InitEnvVarStruct *) envVarsPtr->nextVar;
1114 }
1115 }
1116 }
1117
1118 return (char*)retVal;
1119}
1120//#endif /* INIT_DOS */
1121
1122#pragma optimize ("",on)
Note: See TracBrowser for help on using the repository browser.