1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/* Pcsx - Pc Psx Emulator
* Copyright (C) 1999-2002 Pcsx Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "Linux.h"
#define GetValue(name, var) \
tmp = strstr(data, name); \
if (tmp != NULL) { \
tmp+=strlen(name); \
while ((*tmp == ' ') || (*tmp == '=')) tmp++; \
if (*tmp != '\n') sscanf(tmp, "%s", var); \
}
#define GetValuel(name, var) \
tmp = strstr(data, name); \
if (tmp != NULL) { \
tmp+=strlen(name); \
while ((*tmp == ' ') || (*tmp == '=')) tmp++; \
if (*tmp != '\n') sscanf(tmp, "%lx", &var); \
}
#define SetValue(name, var) \
fprintf (f,"%s = %s\n", name, var);
#define SetValuel(name, var) \
fprintf (f,"%s = %lx\n", name, var);
int LoadConfig(PcsxConfig *Conf) {
struct stat buf;
FILE *f;
int size;
char *data,*tmp;
if (stat(cfgfile, &buf) == -1) return -1;
size = buf.st_size;
f = fopen(cfgfile,"r");
if (f == NULL) return -1;
data = (char*)malloc(size);
if (data == NULL) return -1;
fread(data, 1, size, f);
fclose(f);
GetValue("Bios", Config.Bios);
GetValue("Gpu", Config.Gpu);
GetValue("Spu", Config.Spu);
GetValue("Cdr", Config.Cdr);
GetValue("Pad1", Config.Pad1);
GetValue("Pad2", Config.Pad2);
GetValue("Mcd1", Config.Mcd1);
GetValue("Mcd2", Config.Mcd2);
GetValue("PluginsDir", Config.PluginsDir);
GetValue("BiosDir", Config.BiosDir);
GetValuel("Xa", Config.Xa);
GetValuel("Sio", Config.Sio);
GetValuel("Mdec", Config.Mdec);
GetValuel("PsxAuto", Config.PsxAuto);
GetValuel("PsxType", Config.PsxType);
GetValuel("Cdda", Config.Cdda);
GetValuel("Cpu", Config.Cpu);
GetValuel("Log", Config.Log);
GetValuel("PsxOut", Config.PsxOut);
GetValuel("SpuIrq", Config.SpuIrq);
GetValuel("CdTiming",Config.CdTiming);
free(data);
return 0;
}
/////////////////////////////////////////////////////////
void SaveConfig() {
FILE *f;
f = fopen(cfgfile,"w");
if (f == NULL) return;
SetValue("Bios", Config.Bios);
SetValue("Gpu", Config.Gpu);
SetValue("Spu", Config.Spu);
SetValue("Cdr", Config.Cdr);
SetValue("Pad1", Config.Pad1);
SetValue("Pad2", Config.Pad2);
SetValue("Mcd1", Config.Mcd1);
SetValue("Mcd2", Config.Mcd2);
SetValue("PluginsDir", Config.PluginsDir);
SetValue("BiosDir", Config.BiosDir);
SetValuel("Xa", Config.Xa);
SetValuel("Sio", Config.Sio);
SetValuel("Mdec", Config.Mdec);
SetValuel("PsxAuto", Config.PsxAuto);
SetValuel("PsxType", Config.PsxType);
SetValuel("Cdda", Config.Cdda);
SetValuel("Cpu", Config.Cpu);
SetValuel("Log", Config.Log);
SetValuel("PsxOut", Config.PsxOut);
SetValuel("SpuIrq", Config.SpuIrq);
SetValuel("CdTiming",Config.CdTiming);
fclose(f);
return;
}
|