Use uint64_t across the board for joykeys.

This commit is contained in:
Themaister 2012-03-04 13:55:35 +01:00
parent 6e0da33c60
commit 2463924d69
5 changed files with 47 additions and 11 deletions

View File

@ -463,6 +463,30 @@ bool config_get_int(config_file_t *conf, const char *key, int *in)
return false;
}
bool config_get_uint64(config_file_t *conf, const char *key, uint64_t *in)
{
struct entry_list *list = conf->entries;
while (list)
{
if (strcmp(key, list->key) == 0)
{
errno = 0;
uint64_t val = strtoull(list->value, NULL, 0);
if (errno == 0)
{
*in = val;
return true;
}
return
false;
}
list = list->next;
}
return false;
}
bool config_get_uint(config_file_t *conf, const char *key, unsigned *in)
{
struct entry_list *list = conf->entries;
@ -631,6 +655,13 @@ void config_set_int(config_file_t *conf, const char *key, int val)
config_set_string(conf, key, buf);
}
void config_set_uint64(config_file_t *conf, const char *key, uint64_t val)
{
char buf[128];
snprintf(buf, sizeof(buf), "%llu", (long long unsigned)val);
config_set_string(conf, key, buf);
}
void config_set_char(config_file_t *conf, const char *key, char val)
{
char buf[2];

View File

@ -55,7 +55,9 @@ bool config_get_float(config_file_t *conf, const char *entry, float *in);
bool config_get_int(config_file_t *conf, const char *entry, int *in);
// Extracts an uint from config file.
bool config_get_uint(config_file_t *conf, const char *entry, unsigned *in);
// Extracts an int from config file. (Hexadecimal)
// Extracts an uint64 from config file.
bool config_get_uint64(config_file_t *conf, const char *entry, uint64_t *in);
// Extracts an unsigned int from config file treating input as hex.
bool config_get_hex(config_file_t *conf, const char *entry, unsigned *in);
// Extracts a single char. If value consists of several chars, this is an error.
bool config_get_char(config_file_t *conf, const char *entry, char *in);
@ -71,6 +73,7 @@ bool config_get_bool(config_file_t *conf, const char *entry, bool *in);
void config_set_double(config_file_t *conf, const char *entry, double value);
void config_set_float(config_file_t *conf, const char *entry, float value);
void config_set_int(config_file_t *conf, const char *entry, int val);
void config_set_uint64(config_file_t *conf, const char *entry, uint64_t val);
void config_set_char(config_file_t *conf, const char *entry, char val);
void config_set_string(config_file_t *conf, const char *entry, const char *val);
void config_set_bool(config_file_t *conf, const char *entry, bool val);

View File

@ -20,6 +20,7 @@
#define CONFIG_FILE_MACROS_H__
// Macros to ease config getting.
#include <stdint.h>
#define CONFIG_GET_BOOL_BASE(conf, base, var, key) do { \
bool tmp; \
@ -33,6 +34,12 @@
base.var = tmp; \
} while(0)
#define CONFIG_GET_UINT64_BASE(conf, base, var, key) do { \
uint64_t tmp; \
if (config_get_int(conf, key, &tmp)) \
base.var = tmp; \
} while(0)
#define CONFIG_GET_FLOAT_BASE(conf, base, var, key) do { \
float tmp; \
if (config_get_float(conf, key, &tmp)) \
@ -44,6 +51,7 @@
#define CONFIG_GET_BOOL(var, key) CONFIG_GET_BOOL_BASE(conf, g_settings, var, key)
#define CONFIG_GET_INT(var, key) CONFIG_GET_INT_BASE(conf, g_settings, var, key)
#define CONFIG_GET_UINT64(var, key) CONFIG_GET_UINT64_BASE(conf, g_settings, var, key)
#define CONFIG_GET_FLOAT(var, key) CONFIG_GET_FLOAT_BASE(conf, g_settings, var, key)
#define CONFIG_GET_STRING(var, key) CONFIG_GET_STRING_BASE(conf, g_settings, var, key)

View File

@ -68,18 +68,12 @@ enum
SSNES_BIND_LIST_END
};
#ifdef __CELLOS_LV2__
typedef uint64_t ssnes_joykey_t;
#else
typedef uint16_t ssnes_joykey_t;
#endif
struct snes_keybind
{
bool valid;
int id;
enum ssnes_key key;
ssnes_joykey_t joykey;
uint64_t joykey; // PC only uses lower 16-bits.
uint32_t joyaxis;
};
@ -117,7 +111,7 @@ typedef struct audio_driver
#define AXIS_NEG_GET(x) (((uint32_t)(x) >> 16) & UINT16_C(0xFFFF))
#define AXIS_POS_GET(x) ((uint32_t)(x) & UINT16_C(0xFFFF))
#define NO_BTN ((ssnes_joykey_t)-1) // I hope no joypad will ever have this many buttons ... ;)
#define NO_BTN UINT64_C(0xFFFFFFFFFFFFFFFF) // I hope no joypad will ever have this many buttons ... ;)
#define HAT_UP_MASK (1 << 15)
#define HAT_DOWN_MASK (1 << 14)

View File

@ -748,7 +748,7 @@ static void read_keybinds_button(config_file_t *conf, unsigned player, unsigned
if (*btn == 'h')
parse_hat(bind, btn + 1);
else
bind->joykey = strtol(tmp, NULL, 0);
bind->joykey = strtoull(tmp, NULL, 0);
}
}
}
@ -870,7 +870,7 @@ static void save_keybind_joykey(config_file_t *conf,
save_keybind_hat(conf, map, bind);
#endif
else
config_set_int(conf, map->btn, bind->joykey);
config_set_uint64(conf, map->btn, bind->joykey);
}
static void save_keybind_axis(config_file_t *conf,