gpu_unai: basic frameskip
[pcsx_rearmed.git] / plugins / dfxvideo / cfg.c
CommitLineData
ef79bbde
P
1/***************************************************************************
2 cfg.c - description
3 -------------------
4 begin : Sun Oct 28 2001
5 copyright : (C) 2001 by Pete Bernert
6 email : BlackDove@addcom.de
7 ***************************************************************************/
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. See also the license.txt file for *
14 * additional informations. *
15 * *
16 ***************************************************************************/
17
18#define _IN_CFG
19
20#include <sys/stat.h>
21#include <unistd.h>
22#include <stdlib.h>
23
24#undef FALSE
25#undef TRUE
26#define MAKELONG(low,high) ((unsigned long)(((unsigned short)(low)) | (((unsigned long)((unsigned short)(high))) << 16)))
27
28#include "externals.h"
29#include "cfg.h"
30#include "gpu.h"
31
32char * pConfigFile = NULL;
33
34// CONFIG FILE helpers....
35// some helper macros:
36
37#define GetValue(name, var) \
38 p = strstr(pB, name); \
39 if (p != NULL) { \
40 p+=strlen(name); \
41 while ((*p == ' ') || (*p == '=')) p++; \
42 if (*p != '\n') var = atoi(p); \
43 }
44
45#define GetFloatValue(name, var) \
46 p = strstr(pB, name); \
47 if (p != NULL) { \
48 p+=strlen(name); \
49 while ((*p == ' ') || (*p == '=')) p++; \
50 if (*p != '\n') var = (float)atof(p); \
51 }
52
53#define SetValue(name, var) \
54 p = strstr(pB, name); \
55 if (p != NULL) { \
56 p+=strlen(name); \
57 while ((*p == ' ') || (*p == '=')) p++; \
58 if (*p != '\n') { \
59 len = sprintf(t1, "%d", var); \
60 strncpy(p, t1, len); \
61 if (p[len] != ' ' && p[len] != '\n' && p[len] != 0) p[len] = ' '; \
62 } \
63 } \
64 else { \
65 size+=sprintf(pB+size, "%s = %d\n", name, var); \
66 }
67
68#define SetFloatValue(name, var) \
69 p = strstr(pB, name); \
70 if (p != NULL) { \
71 p+=strlen(name); \
72 while ((*p == ' ') || (*p == '=')) p++; \
73 if (*p != '\n') { \
74 len = sprintf(t1, "%.1f", (double)var); \
75 strncpy(p, t1, len); \
76 if (p[len] != ' ' && p[len] != '\n' && p[len] != 0) p[len] = ' '; \
77 } \
78 } \
79 else { \
80 size+=sprintf(pB+size, "%s = %.1f\n", name, (double)var); \
81 }
82
e906c010 83static void ReadConfigFile()
ef79bbde
P
84{
85 struct stat buf;
86 FILE *in;char t[256];int len, size;
87 char * pB, * p;
88
89 if(pConfigFile)
90 strcpy(t,pConfigFile);
91 else
92 {
93 strcpy(t,"dfxvideo.cfg");
94 in = fopen(t,"rb");
95 if (!in)
96 {
97 strcpy(t,"cfg/dfxvideo.cfg");
98 in = fopen(t,"rb");
99 if(!in) sprintf(t,"%s/.pcsx/plugins/dfxvideo.cfg",getenv("HOME"));
100 else fclose(in);
101 }
102 else fclose(in);
103 }
104
105 if (stat(t, &buf) == -1) return;
106 size = buf.st_size;
107
108 in = fopen(t,"rb");
109 if (!in) return;
110
111 pB=(char *)malloc(size + 1);
112 memset(pB,0,size + 1);
113
114 len = fread(pB, 1, size, in);
115 fclose(in);
116
117 GetValue("ResX", iResX);
118 if(iResX<20) iResX=20;
119 iResX=(iResX/4)*4;
120
121 GetValue("ResY", iResY);
122 if(iResY<20) iResY=20;
123 iResY=(iResY/4)*4;
124
125 iWinSize=MAKELONG(iResX,iResY);
126
127 GetValue("NoStretch", iUseNoStretchBlt);
128
129 GetValue("Dithering", iUseDither);
130
131 GetValue("FullScreen", iWindowMode);
132 if(iWindowMode!=0) iWindowMode=0;
133 else iWindowMode=1;
134
135 GetValue("ShowFPS", iShowFPS);
136 if(iShowFPS<0) iShowFPS=0;
137 if(iShowFPS>1) iShowFPS=1;
138
139 GetValue("Maintain43", iMaintainAspect);
140 if(iMaintainAspect<0) iMaintainAspect=0;
141 if(iMaintainAspect>1) iMaintainAspect=1;
142
143 GetValue("UseFrameLimit", UseFrameLimit);
144 if(UseFrameLimit<0) UseFrameLimit=0;
145 if(UseFrameLimit>1) UseFrameLimit=1;
146
147 GetValue("UseFrameSkip", UseFrameSkip);
148 if(UseFrameSkip<0) UseFrameSkip=0;
149 if(UseFrameSkip>1) UseFrameSkip=1;
150
151 GetValue("FPSDetection", iFrameLimit);
152 if(iFrameLimit<1) iFrameLimit=1;
153 if(iFrameLimit>2) iFrameLimit=2;
154
155 GetFloatValue("FrameRate", fFrameRate);
156 fFrameRate/=10;
157 if(fFrameRate<10.0f) fFrameRate=10.0f;
158 if(fFrameRate>1000.0f) fFrameRate=1000.0f;
159
160 GetValue("CfgFixes", dwCfgFixes);
161
162 GetValue("UseFixes", iUseFixes);
163 if(iUseFixes<0) iUseFixes=0;
164 if(iUseFixes>1) iUseFixes=1;
165
166 free(pB);
167}
168
169void ExecCfg(char *arg) {
170 char cfg[256];
171 struct stat buf;
172
173 strcpy(cfg, "./cfgDFXVideo");
174 if (stat(cfg, &buf) != -1) {
175 if (fork() == 0) {
176 execl(cfg, "cfgDFXVideo", arg, NULL);
177 exit(0);
178 }
179 return;
180 }
181
182 strcpy(cfg, "./cfg/cfgDFXVideo");
183 if (stat(cfg, &buf) != -1) {
184 if (fork() == 0) {
185 execl(cfg, "cfgDFXVideo", arg, NULL);
186 exit(0);
187 }
188 return;
189 }
190
191 sprintf(cfg, "%s/.pcsx/plugins/cfg/cfgDFXVideo", getenv("HOME"));
192 if (stat(cfg, &buf) != -1) {
193 if (fork() == 0) {
194 execl(cfg, "cfgDFXVideo", arg, NULL);
195 exit(0);
196 }
197 return;
198 }
199
200 printf("ERROR: cfgDFXVideo file not found!\n");
201}
202
203void SoftDlgProc(void)
204{
205 ExecCfg("CFG");
206}
207
208void AboutDlgProc(void)
209{
210 char args[256];
211
212 sprintf(args, "ABOUT");
213 ExecCfg(args);
214}
215
e906c010 216void ReadConfigGPU(void)
ef79bbde
P
217{
218 // defaults
219 iResX=640;iResY=480;
220 iWinSize=MAKELONG(iResX,iResY);
221 iColDepth=32;
222 iWindowMode=1;
223 iMaintainAspect=0;
ef79bbde
P
224 iFrameLimit=2;
225 fFrameRate=200.0f;
ef79bbde
P
226 iUseFixes=0;
227 iUseNoStretchBlt=0;
ef79bbde 228 iShowFPS=0;
fba06457 229 // pcsx-rearmed: managed by frontend
230 //UseFrameLimit=1;
231 //UseFrameSkip=0;
232 //dwCfgFixes=0;
233 //iUseDither=0;
ef79bbde
P
234
235 // read sets
236 ReadConfigFile();
237
238 // additional checks
239 if(!iColDepth) iColDepth=32;
240 if(iUseFixes) dwActFixes=dwCfgFixes;
241 SetFixes();
242}
243
244void WriteConfig(void) {
245
246 struct stat buf;
247 FILE *out;char t[256];int len, size;
248 char * pB, * p; char t1[8];
249
250 if(pConfigFile)
251 strcpy(t,pConfigFile);
252 else
253 {
254 strcpy(t,"dfxvideo.cfg");
255 out = fopen(t,"rb");
256 if (!out)
257 {
258 strcpy(t,"cfg/dfxvideo.cfg");
259 out = fopen(t,"rb");
260 if(!out) sprintf(t,"%s/.pcsx/plugins/dfxvideo.cfg",getenv("HOME"));
261 else fclose(out);
262 }
263 else fclose(out);
264 }
265
266 if (stat(t, &buf) != -1) size = buf.st_size;
267 else size = 0;
268
269 out = fopen(t,"rb");
270 if (!out) {
271 // defaults
272 iResX=640;iResY=480;
273 iColDepth=32;
274 iWindowMode=1;
275 iMaintainAspect=0;
276 UseFrameLimit=0;
277 UseFrameSkip=0;
278 iFrameLimit=2;
279 fFrameRate=200.0f;
280 dwCfgFixes=0;
281 iUseFixes=0;
282 iUseNoStretchBlt=0;
283 iUseDither=0;
284 iShowFPS=0;
285
286 size = 0;
287 pB=(char *)malloc(4096);
288 memset(pB,0,4096);
289 }
290 else {
291 pB=(char *)malloc(size+4096);
292 memset(pB,0,size+4096);
293
294 len = fread(pB, 1, size, out);
295 fclose(out);
296 }
297
298 SetValue("ResX", iResX);
299 SetValue("ResY", iResY);
300 SetValue("NoStretch", iUseNoStretchBlt);
301 SetValue("Dithering", iUseDither);
302 SetValue("FullScreen", !iWindowMode);
303 SetValue("ShowFPS", iShowFPS);
304 SetValue("Maintain43", iMaintainAspect);
305 SetValue("UseFrameLimit", UseFrameLimit);
306 SetValue("UseFrameSkip", UseFrameSkip);
307 SetValue("FPSDetection", iFrameLimit);
308 SetFloatValue("FrameRate", fFrameRate);
309 SetValue("CfgFixes", (unsigned int)dwCfgFixes);
310 SetValue("UseFixes", iUseFixes);
311
312 out = fopen(t,"wb");
313 if (!out) return;
314
315 len = fwrite(pB, 1, size, out);
316 fclose(out);
317
318 free(pB);
319}