/*
* Human-readable config file management for PicoDrive
- * (c) notaz, 2008
+ * (C) notaz, 2008-2010
+ *
+ * This work is licensed under the terms of MAME license.
+ * See COPYING file in the top-level directory.
*/
#include <stdio.h>
#ifdef __EPOC32__
#include <unistd.h>
#endif
+
+#include "../libpicofe/input.h"
+#include "../libpicofe/plat.h"
+#include "../libpicofe/lprintf.h"
#include "config.h"
-#include "plat.h"
-#include "input.h"
-#include "lprintf.h"
static char *mystrip(char *str);
#ifndef _MSC_VER
-#include "menu.h"
+#include "menu_pico.h"
#include "emu.h"
#include <pico/pico.h>
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, k, 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 (k = 0; k < key_count; k++)
continue;
}
- for (i = 0; i < sizeof(me_ctrl_actions) / sizeof(me_ctrl_actions[0]); i++) {
+ for (i = 0; me_ctrl_actions[i].name != NULL; i++) {
mask = me_ctrl_actions[i].mask;
if (mask & binds[IN_BIND_OFFS(k, IN_BINDTYPE_PLAYER12)]) {
strncpy(act, me_ctrl_actions[i].name, 31);
int dummy;
if (!me->need_to_save)
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))
goto write_line;
}
}
- else if (me->name != NULL && me->generate_name != NULL) {
+ 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;
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);
}
shift = 16;
*type = IN_BINDTYPE_PLAYER12;
- for (i = 0; i < sizeof(me_ctrl_actions) / sizeof(me_ctrl_actions[0]); i++) {
+ for (i = 0; me_ctrl_actions[i].name != NULL; i++) {
if (strncasecmp(me_ctrl_actions[i].name, val + 8, strlen(val + 8)) == 0)
return me_ctrl_actions[i].mask << shift;
}
if (!me->need_to_save)
continue;
- if (me->name != NULL && me->name[0] != 0) {
- if (strcasecmp(var, me->name) != 0)
- continue; /* surely not this one */
- 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;
+ if (me->name == NULL || strcasecmp(var, me->name) != 0)
+ continue;
- 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;
- }
- }
+ 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;
}
- if (!custom_read(me, var, val))
- break;
- return;
+ else if (custom_read(me, var, val))
+ return;
}
lprintf("config_readsect: unhandled var: \"%s\"\n", var);
keys_encountered = 0;
memset(input_dev_map, 0xff, sizeof(input_dev_map));
- in_config_start();
while (!feof(f))
{
ret = config_get_var_val(f, line, sizeof(line), &var, &val);
parse(var, val);
}
- in_config_end();
fclose(f);
return 0;