all repos — mgba @ 81cd68cbac0bc374ae29448d9a067cb97f7318b3

mGBA Game Boy Advance Emulator

GB IO: Implement key reading
Jeffrey Pfau jeffrey@endrift.com
Tue, 19 Jan 2016 23:12:25 -0800
commit

81cd68cbac0bc374ae29448d9a067cb97f7318b3

parent

d2f97a8edcb4988b2481d7b36188c937ac33d956

1 files changed, 17 insertions(+), 0 deletions(-)

jump to
M src/gb/io.csrc/gb/io.c

@@ -85,8 +85,25 @@ }

gb->memory.io[address] = value; } +static uint8_t _readKeys(struct GB* gb) { + uint8_t keys = *gb->keySource; + switch (gb->memory.io[REG_JOYP] & 0x30) { + case 0x10: + keys >>= 4; + break; + case 0x20: + break; + default: + // ??? + break; + } + return (gb->memory.io[REG_JOYP] | 0xF) ^ (keys & 0xF); +} + uint8_t GBIORead(struct GB* gb, unsigned address) { switch (address) { + case REG_JOYP: + return _readKeys(gb); case REG_IF: break; case REG_IE: