all repos — mgba @ f78f45b60fb1d6ad4ea6d22b55640aefad5c5c0e

mGBA Game Boy Advance Emulator

DS I/O: Key input
Vicki Pfau vi@endrift.com
Thu, 16 Feb 2017 17:09:27 -0800
commit

f78f45b60fb1d6ad4ea6d22b55640aefad5c5c0e

parent

2bbc6e371fee2d2f467b647aeb6796eb568a3871

2 files changed, 31 insertions(+), 6 deletions(-)

jump to
M include/mgba/internal/ds/io.hinclude/mgba/internal/ds/io.h

@@ -61,6 +61,10 @@ DS_REG_TM2CNT_HI = 0x10A,

DS_REG_TM3CNT_LO = 0x10C, DS_REG_TM3CNT_HI = 0x10E, + // Keypad + DS_REG_KEYINPUT = 0x130, + DS_REG_KEYCNT = 0x132, + // IPC DS_REG_IPCSYNC = 0x180, DS_REG_IPCFIFOCNT = 0x184,

@@ -79,8 +83,6 @@ };

enum DS7IORegisters { // Keypad - DS7_REG_KEYINPUT = 0x130, - DS7_REG_KEYCNT = 0x132, DS7_REG_EXTKEYIN = 0x136, DS7_REG_RTC = 0x138,

@@ -207,10 +209,6 @@ DS9_REG_B_BLDCNT = 0x1050,

DS9_REG_B_BLDALPHA = 0x1052, DS9_REG_B_BLDY = 0x1054, DS9_REG_B_MASTER_BRIGHT = 0x106C, - - // Keypad - DS9_REG_KEYINPUT = 0x130, - DS9_REG_KEYCNT = 0x132, // Game card DS9_REG_AUXSPICNT = 0x1A0,
M src/ds/io.csrc/ds/io.c

@@ -5,6 +5,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this

* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include <mgba/internal/ds/io.h> +#include <mgba/core/interface.h> #include <mgba/internal/ds/ds.h> #include <mgba/internal/ds/ipc.h>

@@ -97,6 +98,28 @@ }

return value | 0x10000; } +static uint16_t DSIOReadKeyInput(struct DS* ds) { + uint16_t input = 0x3FF; + if (ds->keyCallback) { + input = ds->keyCallback->readKeys(ds->keyCallback); + } else if (ds->keySource) { + input = *ds->keySource; + } + // TODO: Put back + /*if (!dscore->p->allowOpposingDirections) { + unsigned rl = input & 0x030; + unsigned ud = input & 0x0C0; + input &= 0x30F; + if (rl != 0x030) { + input |= rl; + } + if (ud != 0x0C0) { + input |= ud; + } + }*/ + return 0x3FF ^ input; +} + static void DSIOUpdateTimer(struct DSCommon* dscore, uint32_t address) { switch (address) { case DS_REG_TM0CNT_LO:

@@ -218,6 +241,8 @@ case DS_REG_TM2CNT_LO:

case DS_REG_TM3CNT_LO: DSIOUpdateTimer(&ds->ds7, address); break; + case DS_REG_KEYINPUT: + return DSIOReadKeyInput(ds); case DS_REG_DMA0FILL_LO: case DS_REG_DMA0FILL_HI: case DS_REG_DMA1FILL_LO:

@@ -366,6 +391,8 @@ case DS_REG_TM2CNT_LO:

case DS_REG_TM3CNT_LO: DSIOUpdateTimer(&ds->ds9, address); break; + case DS_REG_KEYINPUT: + return DSIOReadKeyInput(ds); case DS_REG_DMA0FILL_LO: case DS_REG_DMA0FILL_HI: case DS_REG_DMA1FILL_LO: