diff --git a/CHANGES b/CHANGES index d079b3a50..37fb3e7c3 100644 --- a/CHANGES +++ b/CHANGES @@ -53,6 +53,7 @@ Misc: - 3DS: Update to new ctrulib API - GBA RR: Add preliminary SRAM support for VBM loading - GBA RR: Add support for resets in movies + - GBA Input: Consolidate GBA_KEY_NONE and GBA_NO_MAPPING 0.3.2: (2015-12-16) Bugfixes: diff --git a/src/gba/input.c b/src/gba/input.c index 6ae95844c..bcc4c7a1d 100644 --- a/src/gba/input.c +++ b/src/gba/input.c @@ -95,7 +95,11 @@ static struct GBAInputMapImpl* _guaranteeMap(struct GBAInputMap* map, uint32_t t map->numMaps = 1; impl = &map->maps[0]; impl->type = type; - impl->map = calloc(GBA_KEY_MAX, sizeof(int)); + impl->map = malloc(GBA_KEY_MAX * sizeof(int)); + int i; + for (i = 0; i < GBA_KEY_MAX; ++i) { + impl->map[i] = GBA_KEY_NONE; + } TableInit(&impl->axes, 2, free); } else { impl = _lookupMap(map, type); @@ -110,7 +114,11 @@ static struct GBAInputMapImpl* _guaranteeMap(struct GBAInputMap* map, uint32_t t } if (impl) { impl->type = type; - impl->map = calloc(GBA_KEY_MAX, sizeof(int)); + impl->map = malloc(GBA_KEY_MAX * sizeof(int)); + int i; + for (i = 0; i < GBA_KEY_MAX; ++i) { + impl->map[i] = GBA_KEY_NONE; + } } else { map->maps = realloc(map->maps, sizeof(*map->maps) * map->numMaps * 2); for (m = map->numMaps * 2 - 1; m > map->numMaps; --m) { @@ -120,7 +128,11 @@ static struct GBAInputMapImpl* _guaranteeMap(struct GBAInputMap* map, uint32_t t map->numMaps *= 2; impl = &map->maps[m]; impl->type = type; - impl->map = calloc(GBA_KEY_MAX, sizeof(int)); + impl->map = malloc(GBA_KEY_MAX * sizeof(int)); + int i; + for (i = 0; i < GBA_KEY_MAX; ++i) { + impl->map[i] = GBA_KEY_NONE; + } } TableInit(&impl->axes, 2, free); } @@ -378,18 +390,18 @@ void GBAInputUnbindKey(struct GBAInputMap* map, uint32_t type, enum GBAKey input return; } if (impl) { - impl->map[input] = GBA_NO_MAPPING; + impl->map[input] = GBA_KEY_NONE; } } int GBAInputQueryBinding(const struct GBAInputMap* map, uint32_t type, enum GBAKey input) { if (input >= GBA_KEY_MAX) { - return 0; + return GBA_KEY_NONE; } const struct GBAInputMapImpl* impl = _lookupMapConst(map, type); if (!impl || !impl->map) { - return 0; + return GBA_KEY_NONE; } return impl->map[input]; diff --git a/src/gba/input.h b/src/gba/input.h index 2332b7e75..c1c89a9cf 100644 --- a/src/gba/input.h +++ b/src/gba/input.h @@ -22,8 +22,6 @@ struct GBAAxis { int32_t deadLow; }; -#define GBA_NO_MAPPING -1 - extern const char* GBAKeyNames[]; void GBAInputMapInit(struct GBAInputMap*); diff --git a/src/platform/qt/GBAKeyEditor.cpp b/src/platform/qt/GBAKeyEditor.cpp index 7acae67a3..f8f901c77 100644 --- a/src/platform/qt/GBAKeyEditor.cpp +++ b/src/platform/qt/GBAKeyEditor.cpp @@ -249,7 +249,7 @@ void GBAKeyEditor::lookupBinding(const GBAInputMap* map, KeyEditor* keyEditor, G #ifdef BUILD_SDL if (m_type == SDL_BINDING_BUTTON) { int value = GBAInputQueryBinding(map, m_type, key); - if (value != GBA_NO_MAPPING) { + if (value != GBA_KEY_NONE) { keyEditor->setValueButton(value); } return;