1 /* Pcsx - Pc Psx Emulator
2 * Copyright (C) 1999-2002 Pcsx Team
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA
27 /* TODO escaping/unescaping would be nice, as would maxchars */
28 static void GetValue(char *src, char *name, char *outvar) {
32 tmp = strstr(src, name);
33 if (tmp == NULL) return;
36 while ((*tmp == ' ') || (*tmp == '=')) tmp++;
38 while (*tmp != '\n' && *tmp != 0)
45 static long GetValuel(char *src, char *name) {
46 char *tmp = strstr(src, name);
49 while ((*tmp == ' ') || (*tmp == '=')) tmp++;
50 if (*tmp != '\n') return atol(tmp);
55 static boolean GetValueb(char *src, char *name) {
56 char *tmp = strstr(src, name);
59 while ((*tmp == ' ') || (*tmp == '=')) tmp++;
60 if (*tmp != '\n') return (atoi(tmp) != 0);
65 #define SetValue(name, var) \
66 fprintf(f, "%s = %s\n", name, var);
68 #define SetValuel(name, var) \
69 fprintf(f, "%s = %x\n", name, var);
71 #define SetValueb(name, var) \
72 fprintf(f, "%s = %d\n", name, (var) ? 1 : 0);
74 int LoadConfig(PcsxConfig *Conf) {
80 /* TODO local var called cfgfile */
82 // Ryan says: use dotdir, dotdir is GOOD
83 // No giant homedir names
84 strncpy(cfgfile, getenv("HOME"), 200);
85 strcat(cfgfile, PCSX_DOT_DIR);
87 // proceed to load the cfg file
89 strcat(cfgfile, cfgfile_basename);
91 // file is now ~/.pcsx/pcsx.cfg (or whatever cfgfile_basename is)
92 if (stat(cfgfile, &buf) == -1) {
93 // the config file doesn't exist!
94 /* TODO Error checking? */
95 printf("Configuration file %s couldn't be found\n", cfgfile);
101 /* TODO Error checking for the next two lines, and at least log failures */
102 f = fopen(cfgfile, "r");
103 if (f == NULL) return -1;
105 data = (char *)malloc(size + 1);
106 if (data == NULL) return -1;
108 fread(data, 1, buf.st_size, f);
113 GetValue(data, "Bios", Config.Bios);
114 GetValue(data, "Gpu", Config.Gpu);
115 GetValue(data, "Spu", Config.Spu);
116 GetValue(data, "Cdr", Config.Cdr);
117 GetValue(data, "Pad1", Config.Pad1);
118 GetValue(data, "Pad2", Config.Pad2);
119 GetValue(data, "Net", Config.Net);
120 GetValue(data, "Mcd1", Config.Mcd1);
121 GetValue(data, "Mcd2", Config.Mcd2);
122 GetValue(data, "BiosDir", Config.BiosDir);
123 GetValue(data, "PluginsDir", Config.PluginsDir);
125 Config.Xa = GetValueb(data, "Xa");
126 Config.Sio = GetValueb(data, "Sio");
127 Config.Mdec = GetValueb(data, "Mdec");
128 Config.PsxAuto = GetValueb(data, "PsxAuto");
129 Config.Cdda = GetValueb(data, "Cdda");
130 Config.Debug = GetValueb(data, "Dbg");
131 Config.PsxOut = GetValueb(data, "PsxOut");
132 Config.SpuIrq = GetValueb(data, "SpuIrq");
133 Config.RCntFix = GetValueb(data, "RCntFix");
134 Config.VSyncWA = GetValueb(data, "VSyncWA");
136 Config.Cpu = GetValuel(data, "Cpu");
137 Config.PsxType = GetValuel(data, "PsxType");
147 /* TODO Error checking for the next two lines, and at least log
148 failures - suggest a file dialog to specify a new file or
150 f = fopen(cfgfile, "w");
151 if (f == NULL) return;
153 SetValue("Bios", Config.Bios);
154 SetValue("Gpu", Config.Gpu);
155 SetValue("Spu", Config.Spu);
156 SetValue("Cdr", Config.Cdr);
157 SetValue("Net", Config.Net);
158 SetValue("Pad1", Config.Pad1);
159 SetValue("Pad2", Config.Pad2);
160 SetValue("Mcd1", Config.Mcd1);
161 SetValue("Mcd2", Config.Mcd2);
162 SetValue("BiosDir", Config.BiosDir);
163 SetValue("PluginsDir", Config.PluginsDir);
165 SetValueb("Xa", Config.Xa);
166 SetValueb("Sio", Config.Sio);
167 SetValueb("Mdec", Config.Mdec);
168 SetValueb("PsxAuto", Config.PsxAuto);
169 SetValueb("Cdda", Config.Cdda);
170 SetValueb("Dbg", Config.Debug);
171 SetValueb("PsxOut", Config.PsxOut);
172 SetValueb("SpuIrq", Config.SpuIrq);
173 SetValueb("RCntFix", Config.RCntFix);
174 SetValueb("VSyncWA", Config.VSyncWA);
176 SetValuel("Cpu", Config.Cpu);
177 SetValuel("PsxType", Config.PsxType);