#include <unistd.h>
#endif
#include "config.h"
+#include "plat.h"
#include "input.h"
#include "lprintf.h"
#include "emu.h"
#include <pico/pico.h>
+// always output DOS endlines
+#ifdef _WIN32
+#define NL "\n"
+#else
#define NL "\r\n"
+#endif
static int seek_sect(FILE *f, const char *section)
{
}
-static void custom_write(FILE *f, const menu_entry *me, int no_def)
-{
- char str24[24];
-
- switch (me->id)
- {
- case MA_OPT2_GAMMA:
- if (no_def && defaultConfig.gamma == currentConfig.gamma) return;
- fprintf(f, "Gamma correction = %.3f", (double)currentConfig.gamma / 100.0);
- break;
- case MA_OPT2_SQUIDGEHACK:
- if (no_def && !((defaultConfig.EmuOpt^currentConfig.EmuOpt)&0x0010)) return;
- fprintf(f, "Squidgehack = %i", (currentConfig.EmuOpt&0x0010)>>4);
- break;
- case MA_CDOPT_READAHEAD:
- if (no_def && defaultConfig.s_PicoCDBuffers == PicoCDBuffers) return;
- sprintf(str24, "%i", PicoCDBuffers * 2);
- fprintf(f, "ReadAhead buffer = %s", str24);
- break;
- /* PSP */
- case MA_OPT3_SCALE:
- if (no_def && defaultConfig.scale == currentConfig.scale) return;
- fprintf(f, "Scale factor = %.2f", currentConfig.scale);
- break;
- case MA_OPT3_HSCALE32:
- if (no_def && defaultConfig.hscale32 == currentConfig.hscale32) return;
- fprintf(f, "Hor. scale (for low res. games) = %.2f", currentConfig.hscale32);
- break;
- case MA_OPT3_HSCALE40:
- if (no_def && defaultConfig.hscale40 == currentConfig.hscale40) return;
- fprintf(f, "Hor. scale (for hi res. games) = %.2f", currentConfig.hscale40);
- break;
- case MA_OPT3_FILTERING:
- if (no_def && defaultConfig.scaling == currentConfig.scaling) return;
- fprintf(f, "Bilinear filtering = %i", currentConfig.scaling);
- break;
- case MA_OPT3_GAMMAA:
- if (no_def && defaultConfig.gamma == currentConfig.gamma) return;
- fprintf(f, "Gamma adjustment = %i", currentConfig.gamma);
- break;
- case MA_OPT3_BLACKLVL:
- if (no_def && defaultConfig.gamma2 == currentConfig.gamma2) return;
- fprintf(f, "Black level = %i", currentConfig.gamma2);
- break;
- case MA_OPT3_VSYNC:
- if (no_def && (defaultConfig.EmuOpt&0x12000) == (currentConfig.gamma2&0x12000)) return;
- strcpy(str24, "never");
- if (currentConfig.EmuOpt & 0x2000)
- strcpy(str24, (currentConfig.EmuOpt & 0x10000) ? "sometimes" : "always");
- fprintf(f, "Wait for vsync = %s", str24);
- break;
-
- default:
- lprintf("unhandled custom_write: %i\n", me->id);
- return;
- }
- fprintf(f, NL);
-}
-
-
static void keys_write(FILE *fn, const char *bind_str, int dev_id, const int *binds, int no_defaults)
{
char act[48];
- int key_count, t, i;
+ int key_count = 0, k, i;
const int *def_binds;
- key_count = in_get_dev_info(dev_id, IN_INFO_BIND_COUNT);
+ in_get_config(dev_id, IN_CFG_BIND_COUNT, &key_count);
def_binds = in_get_dev_def_binds(dev_id);
- for (t = 0; t < key_count; t++)
+ for (k = 0; k < key_count; k++)
{
const char *name;
+ int t, mask;
act[0] = act[31] = 0;
- if (no_defaults && binds[t] == def_binds[t])
- continue;
+ for (t = 0; t < IN_BINDTYPE_COUNT; t++)
+ if (binds[IN_BIND_OFFS(k, t)] != def_binds[IN_BIND_OFFS(k, t)])
+ break;
- name = in_get_key_name(dev_id, t);
-#ifdef __GP2X__
- if (strcmp(name, "SELECT") == 0) continue;
-#endif
+ if (no_defaults && t == IN_BINDTYPE_COUNT)
+ continue; /* no change from defaults */
- if (binds[t] == 0 && def_binds[t] != 0) {
+ name = in_get_key_name(dev_id, k);
+
+ for (t = 0; t < IN_BINDTYPE_COUNT; t++)
+ if (binds[IN_BIND_OFFS(k, t)] != 0 || def_binds[IN_BIND_OFFS(k, t)] == 0)
+ break;
+
+ if (t == IN_BINDTYPE_COUNT) {
+ /* key has default bind removed */
fprintf(fn, "%s %s =" NL, bind_str, name);
continue;
}
for (i = 0; i < sizeof(me_ctrl_actions) / sizeof(me_ctrl_actions[0]); i++) {
- if (me_ctrl_actions[i].mask & binds[t]) {
+ mask = me_ctrl_actions[i].mask;
+ if (mask & binds[IN_BIND_OFFS(k, IN_BINDTYPE_PLAYER12)]) {
strncpy(act, me_ctrl_actions[i].name, 31);
- fprintf(fn, "%s %s = player%i %s" NL, bind_str, name,
- ((binds[t]>>16)&1)+1, mystrip(act));
+ fprintf(fn, "%s %s = player1 %s" NL, bind_str, name, mystrip(act));
+ }
+ mask = me_ctrl_actions[i].mask << 16;
+ if (mask & binds[IN_BIND_OFFS(k, IN_BINDTYPE_PLAYER12)]) {
+ strncpy(act, me_ctrl_actions[i].name, 31);
+ fprintf(fn, "%s %s = player2 %s" NL, bind_str, name, mystrip(act));
}
}
for (i = 0; emuctrl_actions[i].name != NULL; i++) {
- if (emuctrl_actions[i].mask & binds[t]) {
+ mask = emuctrl_actions[i].mask;
+ if (mask & binds[IN_BIND_OFFS(k, IN_BINDTYPE_EMU)]) {
strncpy(act, emuctrl_actions[i].name, 31);
fprintf(fn, "%s %s = %s" NL, bind_str, name, mystrip(act));
}
}
}
-
+/* XXX: this should go to menu structures instead */
static int default_var(const menu_entry *me)
{
switch (me->id)
{
- case MA_OPT_ACC_TIMING:
- case MA_OPT_ACC_SPRITES:
- case MA_OPT_ARM940_SOUND:
- case MA_OPT_6BUTTON_PAD:
- case MA_OPT2_ENABLE_Z80:
case MA_OPT2_ENABLE_YM2612:
case MA_OPT2_ENABLE_SN76496:
- case MA_OPT2_SVP_DYNAREC:
- case MA_CDOPT_CDDA:
+ case MA_OPT2_ENABLE_Z80:
+ case MA_OPT_6BUTTON_PAD:
+ case MA_OPT_ACC_SPRITES:
+ case MA_OPT_ARM940_SOUND:
case MA_CDOPT_PCM:
- case MA_CDOPT_SAVERAM:
+ case MA_CDOPT_CDDA:
case MA_CDOPT_SCALEROT_CHIP:
case MA_CDOPT_BETTER_SYNC:
+ case MA_CDOPT_SAVERAM:
+ case MA_32XOPT_ENABLE_32X:
+ case MA_32XOPT_PWM:
+ case MA_OPT2_SVP_DYNAREC:
+ case MA_OPT2_NO_SPRITE_LIM:
+ case MA_OPT2_NO_IDLE_LOOPS:
return defaultConfig.s_PicoOpt;
+ case MA_OPT_SRAM_STATES:
case MA_OPT_SHOW_FPS:
case MA_OPT_ENABLE_SOUND:
- case MA_OPT_SRAM_STATES:
- case MA_OPT2_A_SN_GAMMA:
- case MA_OPT2_VSYNC:
case MA_OPT2_GZIP_STATES:
+ case MA_OPT2_SQUIDGEHACK:
case MA_OPT2_NO_LAST_ROM:
case MA_OPT2_RAMTIMINGS:
case MA_CDOPT_LEDS:
+ case MA_OPT2_A_SN_GAMMA:
+ case MA_OPT2_VSYNC:
+ case MA_OPT_INTERLACED:
+ case MA_OPT2_DBLBUFF:
+ case MA_OPT2_STATUS_LINE:
+ case MA_OPT2_NO_FRAME_LIMIT:
+ case MA_OPT_TEARING_FIX:
return defaultConfig.EmuOpt;
case MA_CTRL_TURBO_RATE: return defaultConfig.turbo_rate;
case MA_OPT_SCALING: return defaultConfig.scaling;
case MA_OPT_ROTATION: return defaultConfig.rotation;
+ case MA_OPT2_GAMMA: return defaultConfig.gamma;
+ case MA_OPT_FRAMESKIP: return defaultConfig.Frameskip;
+ case MA_OPT_CONFIRM_STATES: return defaultConfig.confirm_save;
+ case MA_OPT_CPU_CLOCKS: return defaultConfig.CPUclock;
+ case MA_OPT_RENDERER: return defaultConfig.renderer;
+ case MA_32XOPT_RENDERER: return defaultConfig.renderer32x;
case MA_OPT_SAVE_SLOT:
+ return 0;
+
default:
+ lprintf("missing default for %d\n", me->id);
return 0;
}
}
+static int is_cust_val_default(const menu_entry *me)
+{
+ switch (me->id)
+ {
+ case MA_OPT_REGION:
+ return defaultConfig.s_PicoRegion == PicoRegionOverride &&
+ defaultConfig.s_PicoAutoRgnOrder == PicoAutoRgnOrder;
+ case MA_OPT_SOUND_QUALITY:
+ return defaultConfig.s_PsndRate == PsndRate &&
+ ((defaultConfig.s_PicoOpt ^ PicoOpt) & POPT_EN_STEREO) == 0;
+ case MA_CDOPT_READAHEAD:
+ return defaultConfig.s_PicoCDBuffers == PicoCDBuffers;
+ case MA_32XOPT_MSH2_CYCLES:
+ return p32x_msh2_multiplier == MSH2_MULTI_DEFAULT;
+ case MA_32XOPT_SSH2_CYCLES:
+ return p32x_ssh2_multiplier == SSH2_MULTI_DEFAULT;
+ default:break;
+ }
+
+ lprintf("is_cust_val_default: unhandled id %i\n", me->id);
+ return 0;
+}
+
int config_writesect(const char *fname, const char *section)
{
FILE *fo = NULL, *fn = NULL; // old and new
if (section != NULL)
fprintf(fn, "[%s]" NL, section);
- me = me_list_get_first();
- while (me != NULL)
+ for (me = me_list_get_first(); me != NULL; me = me_list_get_next())
{
int dummy;
if (!me->need_to_save)
- goto next;
- if (me->beh == MB_OPT_ONOFF) {
+ continue;
+ if (me->name == NULL || me->name[0] == 0)
+ continue;
+
+ if (me->beh == MB_OPT_ONOFF || me->beh == MB_OPT_CUSTONOFF) {
if (!no_defaults || ((*(int *)me->var ^ default_var(me)) & me->mask))
fprintf(fn, "%s = %i" NL, me->name, (*(int *)me->var & me->mask) ? 1 : 0);
- } else if (me->beh == MB_OPT_RANGE) {
+ }
+ else if (me->beh == MB_OPT_RANGE || me->beh == MB_OPT_CUSTRANGE) {
if (!no_defaults || (*(int *)me->var ^ default_var(me)))
fprintf(fn, "%s = %i" NL, me->name, *(int *)me->var);
- } else if (me->name != NULL && me->generate_name != NULL) {
- strncpy(line, me->generate_name(0, &dummy), sizeof(line));
- line[sizeof(line) - 1] = 0;
- mystrip(line);
- fprintf(fn, "%s = %s" NL, me->name, line);
- } else
- custom_write(fn, me, no_defaults);
-next:
- me = me_list_get_next();
+ }
+ else if (me->beh == MB_OPT_ENUM && me->data != NULL) {
+ const char **names = (const char **)me->data;
+ for (t = 0; names[t] != NULL; t++)
+ if (*(int *)me->var == t && (!no_defaults || (*(int *)me->var ^ default_var(me)))) {
+ strncpy(line, names[t], sizeof(line));
+ goto write_line;
+ }
+ }
+ else if (me->generate_name != NULL) {
+ if (!no_defaults || !is_cust_val_default(me)) {
+ strncpy(line, me->generate_name(0, &dummy), sizeof(line));
+ goto write_line;
+ }
+ }
+ else
+ lprintf("config: unhandled write: %i\n", me->id);
+ continue;
+
+write_line:
+ line[sizeof(line) - 1] = 0;
+ mystrip(line);
+ fprintf(fn, "%s = %s" NL, me->name, line);
}
/* input: save device names */
const int *binds = in_get_dev_binds(t);
const char *name = in_get_dev_name(t, 0, 0);
char strbind[16];
- int count;
+ int count = 0;
if (binds == NULL || name == NULL)
continue;
sprintf(strbind, "bind%d", t);
if (t == 0) strbind[4] = 0;
- count = in_get_dev_info(t, IN_INFO_BIND_COUNT);
+ in_get_config(t, IN_CFG_BIND_COUNT, &count);
keys_write(fn, strbind, t, binds, no_defaults);
}
static int custom_read(menu_entry *me, const char *var, const char *val)
{
char *tmp;
- int tmpi;
switch (me->id)
{
- case MA_OPT_RENDERER:
- if (strcasecmp(var, "Renderer") != 0) return 0;
- if (strcasecmp(val, "8bit fast") == 0 || strcasecmp(val, "fast") == 0) {
- PicoOpt |= POPT_ALT_RENDERER;
- }
- else if (strcasecmp(val, "16bit accurate") == 0 || strcasecmp(val, "accurate") == 0) {
- PicoOpt &= ~POPT_ALT_RENDERER;
- currentConfig.EmuOpt |= 0x80;
- }
- else if (strcasecmp(val, "8bit accurate") == 0) {
- PicoOpt &= ~POPT_ALT_RENDERER;
- currentConfig.EmuOpt &= ~0x80;
- }
- else
- return 0;
- return 1;
-
- case MA_OPT_SCALING:
-#ifdef __GP2X__
- if (strcasecmp(var, "Scaling") != 0) return 0;
- if (strcasecmp(val, "OFF") == 0) {
- currentConfig.scaling = 0;
- } else if (strcasecmp(val, "hw horizontal") == 0) {
- currentConfig.scaling = 1;
- } else if (strcasecmp(val, "hw horiz. + vert.") == 0) {
- currentConfig.scaling = 2;
- } else if (strcasecmp(val, "sw horizontal") == 0) {
- currentConfig.scaling = 3;
- } else
- return 0;
- return 1;
-#else
- return 0;
-#endif
-
case MA_OPT_FRAMESKIP:
if (strcasecmp(var, "Frameskip") != 0) return 0;
if (strcasecmp(val, "Auto") == 0)
PsndRate = strtoul(val, &tmp, 10);
if (PsndRate < 8000 || PsndRate > 44100)
PsndRate = 22050;
+ if (*tmp == 'H' || *tmp == 'h') tmp++;
+ if (*tmp == 'Z' || *tmp == 'z') tmp++;
while (*tmp == ' ') tmp++;
if (strcasecmp(tmp, "stereo") == 0) {
PicoOpt |= POPT_EN_STEREO;
return 0;
return 1;
- case MA_OPT_CONFIRM_STATES:
- if (strcasecmp(var, "Confirm savestate") != 0) return 0;
- if (strcasecmp(val, "OFF") == 0) {
- currentConfig.EmuOpt &= ~(5<<9);
- } else if (strcasecmp(val, "writes") == 0) {
- currentConfig.EmuOpt &= ~(5<<9);
- currentConfig.EmuOpt |= 1<<9;
- } else if (strcasecmp(val, "loads") == 0) {
- currentConfig.EmuOpt &= ~(5<<9);
- currentConfig.EmuOpt |= 4<<9;
- } else if (strcasecmp(val, "both") == 0) {
- currentConfig.EmuOpt &= ~(5<<9);
- currentConfig.EmuOpt |= 5<<9;
- } else
- return 0;
- return 1;
-
-#if 0 // TODO rm?
- case MA_OPT_CPU_CLOCKS:
-#ifdef __GP2X__
- if (strcasecmp(var, "GP2X CPU clocks") != 0) return 0;
-#elif defined(PSP)
- if (strcasecmp(var, "PSP CPU clock") != 0) return 0;
-#endif
- currentConfig.CPUclock = atoi(val);
- return 1;
-#endif
-
case MA_OPT2_GAMMA:
if (strcasecmp(var, "Gamma correction") != 0) return 0;
currentConfig.gamma = (int) (atof(val) * 100.0);
return 1;
- case MA_OPT2_SQUIDGEHACK:
- if (strcasecmp(var, "Squidgehack") != 0) return 0;
- tmpi = atoi(val);
- if (tmpi) *(int *)me->var |= me->mask;
- else *(int *)me->var &= ~me->mask;
- return 1;
-
case MA_CDOPT_READAHEAD:
if (strcasecmp(var, "ReadAhead buffer") != 0) return 0;
PicoCDBuffers = atoi(val) / 2;
return 1;
+ case MA_32XOPT_MSH2_CYCLES:
+ case MA_32XOPT_SSH2_CYCLES: {
+ int *mul = (me->id == MA_32XOPT_MSH2_CYCLES) ? &p32x_msh2_multiplier : &p32x_ssh2_multiplier;
+ *mul = ((unsigned int)atoi(val) << SH2_MULTI_SHIFT) / 7670;
+ return 1;
+ }
+
/* PSP */
case MA_OPT3_SCALE:
if (strcasecmp(var, "Scale factor") != 0) return 0;
if (strcasecmp(var, "Hor. scale (for hi res. games)") != 0) return 0;
currentConfig.hscale40 = atof(val);
return 1;
- case MA_OPT3_FILTERING:
- if (strcasecmp(var, "Bilinear filtering") != 0) return 0;
- currentConfig.scaling = atoi(val);
- return 1;
- case MA_OPT3_GAMMAA:
- if (strcasecmp(var, "Gamma adjustment") != 0) return 0;
- currentConfig.gamma = atoi(val);
- return 1;
- case MA_OPT3_BLACKLVL:
- if (strcasecmp(var, "Black level") != 0) return 0;
- currentConfig.gamma2 = atoi(val);
- return 1;
case MA_OPT3_VSYNC:
+ // XXX: use enum
if (strcasecmp(var, "Wait for vsync") != 0) return 0;
if (strcasecmp(val, "never") == 0) {
currentConfig.EmuOpt &= ~0x12000;
return 1;
default:
- lprintf("unhandled custom_read: %i\n", me->id);
+ lprintf("unhandled custom_read %i: %s\n", me->id, var);
return 0;
}
}
static unsigned int keys_encountered = 0;
-static int parse_bind_val(const char *val)
+static int parse_bind_val(const char *val, int *type)
{
int i;
+ *type = IN_BINDTYPE_NONE;
if (val[0] == 0)
return 0;
if (strncasecmp(val, "player", 6) == 0)
{
- unsigned int player;
+ int player, shift = 0;
player = atoi(val + 6) - 1;
+
if (player > 1)
return -1;
+ if (player == 1)
+ shift = 16;
+ *type = IN_BINDTYPE_PLAYER12;
for (i = 0; i < sizeof(me_ctrl_actions) / sizeof(me_ctrl_actions[0]); i++) {
if (strncasecmp(me_ctrl_actions[i].name, val + 8, strlen(val + 8)) == 0)
- return me_ctrl_actions[i].mask | (player<<16);
+ return me_ctrl_actions[i].mask << shift;
}
}
for (i = 0; emuctrl_actions[i].name != NULL; i++) {
- if (strncasecmp(emuctrl_actions[i].name, val, strlen(val)) == 0)
+ if (strncasecmp(emuctrl_actions[i].name, val, strlen(val)) == 0) {
+ *type = IN_BINDTYPE_EMU;
return emuctrl_actions[i].mask;
+ }
}
return -1;
static void keys_parse(const char *key, const char *val, int dev_id)
{
- int binds;
+ int acts, type;
- binds = parse_bind_val(val);
- if (binds == -1) {
+ acts = parse_bind_val(val, &type);
+ if (acts == -1) {
lprintf("config: unhandled action \"%s\"\n", val);
return;
}
- in_config_bind_key(dev_id, key, binds);
+ in_config_bind_key(dev_id, key, acts, type);
}
static int get_numvar_num(const char *var)
static void parse(const char *var, const char *val)
{
menu_entry *me;
- int tmp, ret = 0;
+ int tmp;
if (strcasecmp(var, "LastUsedROM") == 0)
return; /* handled elsewhere */
return;
}
- me = me_list_get_first();
- while (me != NULL && ret == 0)
+ for (me = me_list_get_first(); me != NULL; me = me_list_get_next())
{
+ char *p;
+
if (!me->need_to_save)
- goto next;
- if (me->name != NULL && me->name[0] != 0) {
- if (strcasecmp(var, me->name) != 0)
- goto next; /* surely not this one */
- if (me->beh == MB_OPT_ONOFF) {
- tmp = atoi(val);
- if (tmp) *(int *)me->var |= me->mask;
- else *(int *)me->var &= ~me->mask;
- return;
- } else if (me->beh == MB_OPT_RANGE) {
- tmp = atoi(val);
- if (tmp < me->min) tmp = me->min;
- if (tmp > me->max) tmp = me->max;
- *(int *)me->var = tmp;
- return;
+ continue;
+ if (me->name == NULL || strcasecmp(var, me->name) != 0)
+ continue;
+
+ if (me->beh == MB_OPT_ONOFF) {
+ tmp = strtol(val, &p, 0);
+ if (*p != 0)
+ goto bad_val;
+ if (tmp) *(int *)me->var |= me->mask;
+ else *(int *)me->var &= ~me->mask;
+ return;
+ }
+ else if (me->beh == MB_OPT_RANGE) {
+ tmp = strtol(val, &p, 0);
+ if (*p != 0)
+ goto bad_val;
+ if (tmp < me->min) tmp = me->min;
+ if (tmp > me->max) tmp = me->max;
+ *(int *)me->var = tmp;
+ return;
+ }
+ else if (me->beh == MB_OPT_ENUM) {
+ const char **names, *p1;
+ int i;
+
+ names = (const char **)me->data;
+ if (names == NULL)
+ goto bad_val;
+ for (i = 0; names[i] != NULL; i++) {
+ for (p1 = names[i]; *p1 == ' '; p1++)
+ ;
+ if (strcasecmp(p1, val) == 0) {
+ *(int *)me->var = i;
+ return;
+ }
}
+ goto bad_val;
}
- ret = custom_read(me, var, val);
-next:
- me = me_list_get_next();
+ else if (custom_read(me, var, val))
+ return;
}
- if (!ret) lprintf("config_readsect: unhandled var: \"%s\"\n", var);
+
+ lprintf("config_readsect: unhandled var: \"%s\"\n", var);
+ return;
+
+bad_val:
+ lprintf("config_readsect: unhandled val for \"%s\": %s\n", var, val);
}