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},
79 {"video stretch", &config.stretchVideo, 0},
82 {"#Render Settings:", NULL, 0},
83 {"enable fog", &config.enableFog, 0},
84 {"enable primitive z", &config.enablePrimZ, 1},
85 {"enable lighting", &config.enableLighting, 1},
86 {"enable alpha test", &config.enableAlphaTest, 1},
87 {"enable clipping", &config.enableClipping, 0},
88 {"enable face culling", &config.enableFaceCulling, 1},
89 {"enable noise", &config.enableNoise, 0},
92 {"#Texture Settings:", NULL, 0},
93 {"texture 2xSAI", &config.texture.sai2x, 0},
94 {"texture force bilinear", &config.texture.forceBilinear, 0},
95 {"texture max anisotropy", &config.texture.maxAnisotropy, 0},
96 {"texture use IA", &config.texture.useIA, 0},
97 {"texture fast CRC", &config.texture.fastCRC, 1},
98 {"texture pow2", &config.texture.pow2, 1},
101 {"#Frame skip:", NULL, 0},
102 {"auto frameskip", &config.autoFrameSkip, 0},
103 {"max frameskip", &config.maxFrameSkip, 0},
104 {"target FPS", &config.targetFPS, 20},
105 {"frame render rate", &config.frameRenderRate, 1},
106 {"vertical sync", &config.verticalSync, 0},
109 {"#Other Settings:", NULL, 0},
110 {"update mode", &config.updateMode, SCREEN_UPDATE_AT_VI_UPDATE },
111 {"ignore offscreen rendering", &config.ignoreOffscreenRendering, 0},
112 {"force screen clear", &config.forceBufferClear, 0},
113 {"flip vertical", &config.screen.flipVertical, 0},
114 // paulscode: removed from pre-compile to a config option
115 //// (part of the Galaxy S Zelda crash-fix
116 {"tribuffer opt", &config.tribufferOpt, 1},
120 {"#Hack Settings:", NULL, 0},
121 {"hack banjo tooie", &config.hackBanjoTooie, 0},
122 {"hack zelda", &config.hackZelda, 0},
123 {"hack alpha", &config.hackAlpha, 0},
124 {"hack z", &config.zHack, 0}
128 const int configOptionsSize = sizeof(configOptions) / sizeof(Option);
130 void Config_WriteConfig(const char *filename)
132 config.version = CONFIG_VERSION;
133 FILE* f = fopen(filename, "w");
136 LOG(LOG_ERROR, "Could Not Open %s for writing\n", filename);
139 for(int i=0; i<configOptionsSize; i++)
141 Option *o = &configOptions[i];
142 fprintf(f, "%s", o->name);
143 if (o->data) fprintf(f,"=%i", *(o->data));
151 void Config_SetDefault()
153 for(int i=0; i < configOptionsSize; i++)
155 Option *o = &configOptions[i];
156 if (o->data) *(o->data) = o->initial;
160 void Config_SetOption(char* line, char* val)
162 for(int i=0; i< configOptionsSize; i++)
164 Option *o = &configOptions[i];
165 if (strcasecmp(line, o->name) == 0)
171 LOG(LOG_VERBOSE, "Config Option: %s = %i\n", o->name, v);
178 void Config_LoadRomConfig(unsigned char* header)
182 // get the name of the ROM
183 for (int i=0; i<20; i++) config.romName[i] = header[0x20+i];
184 config.romName[20] = '\0';
185 while (config.romName[strlen(config.romName)-1] == ' ')
187 config.romName[strlen(config.romName)-1] = '\0';
201 config.romPAL = true;
209 config.romPAL = false;
212 // Fallback for unknown codes
214 config.romPAL = false;
217 LOG(LOG_MINIMAL, "Rom is %s\n", config.romPAL ? "PAL" : "NTSC");
218 printf("Rom is %s\n", config.romPAL ? "PAL" : "NTSC");
220 const char *filename = ConfigGetSharedDataFilepath("gles2n64rom.conf");
221 FILE *f = fopen(filename,"r");
224 LOG(LOG_MINIMAL, "Could not find %s Rom settings file, using global.\n", filename);
225 printf("Could not find %s Rom settings file, using global.\n", filename);
230 LOG(LOG_MINIMAL, "[gles2N64]: Searching %s Database for \"%s\" ROM\n", filename, config.romName);
231 printf("[gles2N64]: Searching %s Database for \"%s\" ROM\n", filename, config.romName);
235 fgets(line, 4096, f);
236 if (line[0] == '\n') continue;
238 if (strncmp(line,"rom name=", 9) == 0)
240 //Depending on the editor, end lines could be terminated by "LF" or "CRLF"
241 char* lf = strchr(line, '\n'); //Line Feed
242 char* cr = strchr(line, '\r'); //Carriage Return
245 isRom = (strcasecmp(config.romName, line+9) == 0);
251 char* val = strchr(line, '=');
254 Config_SetOption(line,val);
255 LOG(LOG_MINIMAL, "%s = %s", line, val);
256 printf("%s = %s", line, val);
265 void Config_LoadConfig()
270 // default configuration
273 // read configuration
274 const char *filename = ConfigGetSharedDataFilepath("gles2n64.conf");
275 f = fopen(filename, "r");
278 LOG(LOG_MINIMAL, "[gles2N64]: Couldn't open config file '%s' for reading: %s\n", filename, strerror( errno ) );
279 LOG(LOG_MINIMAL, "[gles2N64]: Attempting to write new Config \n");
280 printf("[gles2N64]: Couldn't open config file '%s' for reading: %s\n", filename, strerror( errno ) );
281 printf("[gles2N64]: Attempting to write new Config \n");
282 Config_WriteConfig(filename);
286 LOG(LOG_MINIMAL, "[gles2n64]: Loading Config from %s \n", filename);
287 printf("[gles2n64]: Loading Config from %s \n", filename);
292 fgets( line, 4096, f );
294 if (line[0] == '#' || line[0] == '\n')
297 val = strchr( line, '=' );
302 Config_SetOption(line,val);
305 if (config.version < CONFIG_VERSION)
307 LOG(LOG_WARNING, "[gles2N64]: Wrong config version, rewriting config with defaults\n");
308 printf("[gles2N64]: Wrong config version, rewriting config with defaults\n");
310 Config_WriteConfig(filename);