all repos — mgba @ f5092737ff65837d00b7e71f89b3e2396260adce

mGBA Game Boy Advance Emulator

GBA Input: Add GBAInputMapKeyBits for packed key information
Jeffrey Pfau jeffrey@endrift.com
Sun, 26 Jul 2015 11:19:10 -0700
commit

f5092737ff65837d00b7e71f89b3e2396260adce

parent

1c6d87f578edee720b4e9263403b39c7182917ed

2 files changed, 15 insertions(+), 0 deletions(-)

jump to
M src/gba/input.csrc/gba/input.c

@@ -352,6 +352,20 @@ }

return GBA_KEY_NONE; } +int GBAInputMapKeyBits(const struct GBAInputMap* map, uint32_t type, uint32_t bits, unsigned offset) { + int keys = 0; + for (; bits; bits >>= 1, ++offset) { + if (bits & 1) { + enum GBAKey key = GBAInputMapKey(map, type, offset); + if (key == GBA_KEY_NONE) { + continue; + } + keys |= 1 << key; + } + } + return keys; +} + void GBAInputBindKey(struct GBAInputMap* map, uint32_t type, int key, enum GBAKey input) { struct GBAInputMapImpl* impl = _guaranteeMap(map, type); GBAInputUnbindKey(map, type, input);
M src/gba/input.hsrc/gba/input.h

@@ -30,6 +30,7 @@ void GBAInputMapInit(struct GBAInputMap*);

void GBAInputMapDeinit(struct GBAInputMap*); enum GBAKey GBAInputMapKey(const struct GBAInputMap*, uint32_t type, int key); +int GBAInputMapKeyBits(const struct GBAInputMap* map, uint32_t type, uint32_t bits, unsigned offset); void GBAInputBindKey(struct GBAInputMap*, uint32_t type, int key, enum GBAKey input); void GBAInputUnbindKey(struct GBAInputMap*, uint32_t type, enum GBAKey input); int GBAInputQueryBinding(const struct GBAInputMap*, uint32_t type, enum GBAKey input);