1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus - Config_nogui.cpp *
3 * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4 * Copyright (C) 2008 Tillin9 *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
47 #define CONFIG_VERSION 2
49 Option configOptions[] =
51 {"#gles2n64 Graphics Plugin for N64", NULL, 0},
52 {"#by Orkin / glN64 developers and Adventus.", NULL, 0},
54 {"config version", &config.version, 0},
57 {"#Window Settings:", NULL, 0},
58 {"window xpos", &config.window.xpos, 0},
59 {"window ypos", &config.window.ypos, 0},
60 {"window width", &config.window.width, 800},
61 {"window height", &config.window.height, 480},
62 {"window refwidth", &config.window.refwidth, 800},
63 {"window refheight", &config.window.refheight, 480},
66 {"#Framebuffer Settings:",NULL,0},
67 // {"framebuffer enable", &config.framebuffer.enable, 0},
68 {"framebuffer bilinear", &config.framebuffer.bilinear, 0},
69 {"framebuffer width", &config.framebuffer.width, 400},
70 {"framebuffer height", &config.framebuffer.height, 240},
71 // {"framebuffer width", &config.framebuffer.width, 800},
72 // {"framebuffer height", &config.framebuffer.height, 480},
75 {"#VI Settings:", NULL, 0},
76 {"video force", &config.video.force, 0},
77 {"video width", &config.video.width, 320},
78 {"video height", &config.video.height, 240},
81 {"#Render Settings:", NULL, 0},
82 {"enable fog", &config.enableFog, 0},
83 {"enable primitive z", &config.enablePrimZ, 1},
84 {"enable lighting", &config.enableLighting, 1},
85 {"enable alpha test", &config.enableAlphaTest, 1},
86 {"enable clipping", &config.enableClipping, 0},
87 {"enable face culling", &config.enableFaceCulling, 1},
88 {"enable noise", &config.enableNoise, 0},
91 {"#Texture Settings:", NULL, 0},
92 {"texture 2xSAI", &config.texture.sai2x, 0},
93 {"texture force bilinear", &config.texture.forceBilinear, 0},
94 {"texture max anisotropy", &config.texture.maxAnisotropy, 0},
95 {"texture use IA", &config.texture.useIA, 0},
96 {"texture fast CRC", &config.texture.fastCRC, 1},
97 {"texture pow2", &config.texture.pow2, 1},
100 {"#Frame skip:", NULL, 0},
101 {"auto frameskip", &config.autoFrameSkip, 0},
102 {"max frameskip", &config.maxFrameSkip, 0},
103 {"target FPS", &config.targetFPS, 20},
104 {"frame render rate", &config.frameRenderRate, 1},
105 {"vertical sync", &config.verticalSync, 0},
108 {"#Other Settings:", NULL, 0},
109 {"update mode", &config.updateMode, SCREEN_UPDATE_AT_VI_UPDATE },
110 {"ignore offscreen rendering", &config.ignoreOffscreenRendering, 0},
111 {"force screen clear", &config.forceBufferClear, 0},
112 {"flip vertical", &config.screen.flipVertical, 0},
113 // paulscode: removed from pre-compile to a config option
114 //// (part of the Galaxy S Zelda crash-fix
115 {"tribuffer opt", &config.tribufferOpt, 1},
119 {"#Hack Settings:", NULL, 0},
120 {"hack banjo tooie", &config.hackBanjoTooie, 0},
121 {"hack zelda", &config.hackZelda, 0},
122 {"hack alpha", &config.hackAlpha, 0},
123 {"hack z", &config.zHack, 0},
127 const int configOptionsSize = sizeof(configOptions) / sizeof(Option);
129 void Config_WriteConfig(const char *filename)
131 config.version = CONFIG_VERSION;
132 FILE* f = fopen(filename, "w");
135 LOG(LOG_ERROR, "Could Not Open %s for writing\n", filename);
138 for(int i=0; i<configOptionsSize; i++)
140 Option *o = &configOptions[i];
141 fprintf(f, "%s", o->name);
142 if (o->data) fprintf(f,"=%i", *(o->data));
150 void Config_SetDefault()
152 for(int i=0; i < configOptionsSize; i++)
154 Option *o = &configOptions[i];
155 if (o->data) *(o->data) = o->initial;
159 void Config_SetOption(char* line, char* val)
161 for(int i=0; i< configOptionsSize; i++)
163 Option *o = &configOptions[i];
164 if (strcasecmp(line, o->name) == 0)
170 LOG(LOG_VERBOSE, "Config Option: %s = %i\n", o->name, v);
177 void Config_LoadRomConfig(unsigned char* header)
181 // get the name of the ROM
182 for (int i=0; i<20; i++) config.romName[i] = header[0x20+i];
183 config.romName[20] = '\0';
184 while (config.romName[strlen(config.romName)-1] == ' ')
186 config.romName[strlen(config.romName)-1] = '\0';
200 config.romPAL = true;
208 config.romPAL = false;
211 // Fallback for unknown codes
213 config.romPAL = false;
216 LOG(LOG_MINIMAL, "Rom is %s\n", config.romPAL ? "PAL" : "NTSC");
217 printf("Rom is %s\n", config.romPAL ? "PAL" : "NTSC");
219 const char *filename = ConfigGetSharedDataFilepath("gles2n64rom.conf");
220 FILE *f = fopen(filename,"r");
223 LOG(LOG_MINIMAL, "Could not find %s Rom settings file, using global.\n", filename);
224 printf("Could not find %s Rom settings file, using global.\n", filename);
229 LOG(LOG_MINIMAL, "[gles2N64]: Searching %s Database for \"%s\" ROM\n", filename, config.romName);
230 printf("[gles2N64]: Searching %s Database for \"%s\" ROM\n", filename, config.romName);
234 fgets(line, 4096, f);
235 if (line[0] == '\n') continue;
237 if (strncmp(line,"rom name=", 9) == 0)
239 //Depending on the editor, end lines could be terminated by "LF" or "CRLF"
240 char* lf = strchr(line, '\n'); //Line Feed
241 char* cr = strchr(line, '\r'); //Carriage Return
244 isRom = (strcasecmp(config.romName, line+9) == 0);
250 char* val = strchr(line, '=');
253 Config_SetOption(line,val);
254 LOG(LOG_MINIMAL, "%s = %s", line, val);
255 printf("%s = %s", line, val);
264 void Config_LoadConfig()
269 // default configuration
272 // read configuration
273 const char *filename = ConfigGetSharedDataFilepath("gles2n64.conf");
274 f = fopen(filename, "r");
277 LOG(LOG_MINIMAL, "[gles2N64]: Couldn't open config file '%s' for reading: %s\n", filename, strerror( errno ) );
278 LOG(LOG_MINIMAL, "[gles2N64]: Attempting to write new Config \n");
279 printf("[gles2N64]: Couldn't open config file '%s' for reading: %s\n", filename, strerror( errno ) );
280 printf("[gles2N64]: Attempting to write new Config \n");
281 Config_WriteConfig(filename);
285 LOG(LOG_MINIMAL, "[gles2n64]: Loading Config from %s \n", filename);
286 printf("[gles2n64]: Loading Config from %s \n", filename);
291 fgets( line, 4096, f );
293 if (line[0] == '#' || line[0] == '\n')
296 val = strchr( line, '=' );
301 Config_SetOption(line,val);
304 if (config.version < CONFIG_VERSION)
306 LOG(LOG_WARNING, "[gles2N64]: Wrong config version, rewriting config with defaults\n");
307 printf("[gles2N64]: Wrong config version, rewriting config with defaults\n");
309 Config_WriteConfig(filename);