#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)
{
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 */
+ /* TODO: this should be rm'd when PSP menu is converted */
case MA_OPT3_SCALE:
if (no_def && defaultConfig.scale == currentConfig.scale) return;
fprintf(f, "Scale factor = %.2f", currentConfig.scale);
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, k, i;
const int *def_binds;
key_count = in_get_dev_info(dev_id, IN_INFO_BIND_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 */
+
+ 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 (binds[t] == 0 && def_binds[t] != 0) {
+ 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 = 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 = player%i %s" NL, bind_str, name,
- ((binds[t]>>16)&1)+1, mystrip(act));
+ 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_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_CPU_CLOCKS: return defaultConfig.CPUclock;
case MA_OPT_SAVE_SLOT:
default:
}
}
+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_OPT_CONFIRM_STATES:
+ return !((defaultConfig.EmuOpt ^ currentConfig.EmuOpt) &
+ (EOPT_CONFIRM_LOAD|EOPT_CONFIRM_SAVE)) == 0;
+ case MA_OPT_RENDERER:
+ return ((defaultConfig.s_PicoOpt ^ PicoOpt) & POPT_ALT_RENDERER) == 0 &&
+ ((defaultConfig.EmuOpt ^ currentConfig.EmuOpt) & EOPT_16BPP) == 0;
+ case MA_CDOPT_READAHEAD:
+ return defaultConfig.s_PicoCDBuffers == PicoCDBuffers;
+ 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
int dummy;
if (!me->need_to_save)
goto next;
- if (me->beh == MB_OPT_ONOFF) {
+ 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);
+ if (!no_defaults || !is_cust_val_default(me)) {
+ 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:
#ifdef __GP2X__
if (strcasecmp(var, "Scaling") != 0) return 0;
if (strcasecmp(val, "OFF") == 0) {
- currentConfig.scaling = 0;
+ currentConfig.scaling = EOPT_SCALE_NONE;
} else if (strcasecmp(val, "hw horizontal") == 0) {
- currentConfig.scaling = 1;
+ currentConfig.scaling = EOPT_SCALE_HW_H;
} else if (strcasecmp(val, "hw horiz. + vert.") == 0) {
- currentConfig.scaling = 2;
+ currentConfig.scaling = EOPT_SCALE_HW_HV;
} else if (strcasecmp(val, "sw horizontal") == 0) {
- currentConfig.scaling = 3;
+ currentConfig.scaling = EOPT_SCALE_SW_H;
} else
- return 0;
+ currentConfig.scaling = atoi(val);
return 1;
#else
return 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_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;
-
case MA_OPT2_GAMMA:
if (strcasecmp(var, "Gamma correction") != 0) return 0;
currentConfig.gamma = (int) (atof(val) * 100.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)