all repos — mgba @ 3a95b30d631fcbce31207d3e7d47924d0a0c1031

mGBA Game Boy Advance Emulator

GBA SIO: Improve readability
Vicki Pfau vi@endrift.com
Fri, 12 Mar 2021 02:26:43 -0800
commit

3a95b30d631fcbce31207d3e7d47924d0a0c1031

parent

885ef286d2d9c4de4743244bb6d9f36ee0b26e11

3 files changed, 18 insertions(+), 9 deletions(-)

jump to
M include/mgba/internal/gba/sio.hinclude/mgba/internal/gba/sio.h

@@ -29,8 +29,12 @@ JOY_CMD_POLL = 0x00,

JOY_CMD_TRANS = 0x14, JOY_CMD_RECV = 0x15, - JOYSTAT_TRANS_BIT = 8, - JOYSTAT_RECV_BIT = 2, + JOYSTAT_TRANS = 8, + JOYSTAT_RECV = 2, + + JOYCNT_RESET = 1, + JOYCNT_RECV = 2, + JOYCNT_TRANS = 4, }; DECL_BITFIELD(GBASIONormal, uint16_t);
M src/gba/io.csrc/gba/io.c

@@ -532,7 +532,7 @@ GBASIOWriteRCNT(&gba->sio, value);

break; case REG_JOY_TRANS_LO: case REG_JOY_TRANS_HI: - gba->memory.io[REG_JOYSTAT >> 1] |= JOYSTAT_TRANS_BIT; + gba->memory.io[REG_JOYSTAT >> 1] |= JOYSTAT_TRANS; // Fall through case REG_SIODATA32_LO: case REG_SIODATA32_HI:

@@ -576,6 +576,7 @@ return;

case REG_DEBUG_FLAGS: if (gba->debug) { GBADebug(gba, value); + return; } // Fall through

@@ -835,7 +836,7 @@ return 0;

case REG_JOY_RECV_LO: case REG_JOY_RECV_HI: - gba->memory.io[REG_JOYSTAT >> 1] &= ~JOYSTAT_RECV_BIT; + gba->memory.io[REG_JOYSTAT >> 1] &= ~JOYSTAT_RECV; break; case REG_SOUNDBIAS:
M src/gba/sio/joybus.csrc/gba/sio/joybus.c

@@ -31,7 +31,7 @@

int GBASIOJOYSendCommand(struct GBASIODriver* sio, enum GBASIOJOYCommand command, uint8_t* data) { switch (command) { case JOY_RESET: - sio->p->p->memory.io[REG_JOYCNT >> 1] |= 1; + sio->p->p->memory.io[REG_JOYCNT >> 1] |= JOYCNT_RESET; if (sio->p->p->memory.io[REG_JOYCNT >> 1] & 0x40) { GBARaiseIRQ(sio->p->p, IRQ_SIO, 0); }

@@ -40,16 +40,18 @@ case JOY_POLL:

data[0] = 0x00; data[1] = 0x04; data[2] = sio->p->p->memory.io[REG_JOYSTAT >> 1]; + mLOG(GBA_SIO, DEBUG, "JOY %s: %02X (%02X)", command == JOY_POLL ? "poll" : "reset", data[2], sio->p->p->memory.io[REG_JOYCNT >> 1]); return 3; case JOY_RECV: - sio->p->p->memory.io[REG_JOYCNT >> 1] |= 2; - sio->p->p->memory.io[REG_JOYSTAT >> 1] |= 2; + sio->p->p->memory.io[REG_JOYCNT >> 1] |= JOYCNT_RECV; + sio->p->p->memory.io[REG_JOYSTAT >> 1] |= JOYSTAT_RECV; sio->p->p->memory.io[REG_JOY_RECV_LO >> 1] = data[0] | (data[1] << 8); sio->p->p->memory.io[REG_JOY_RECV_HI >> 1] = data[2] | (data[3] << 8); data[0] = sio->p->p->memory.io[REG_JOYSTAT >> 1]; + mLOG(GBA_SIO, DEBUG, "JOY recv: %02X (%02X)", data[0], sio->p->p->memory.io[REG_JOYCNT >> 1]); if (sio->p->p->memory.io[REG_JOYCNT >> 1] & 0x40) {

@@ -57,13 +59,15 @@ GBARaiseIRQ(sio->p->p, IRQ_SIO, 0);

} return 1; case JOY_TRANS: - sio->p->p->memory.io[REG_JOYCNT >> 1] |= 4; - sio->p->p->memory.io[REG_JOYSTAT >> 1] &= ~JOYSTAT_TRANS_BIT; + sio->p->p->memory.io[REG_JOYCNT >> 1] |= JOYCNT_TRANS; + sio->p->p->memory.io[REG_JOYSTAT >> 1] &= ~JOYSTAT_TRANS; + data[0] = sio->p->p->memory.io[REG_JOY_TRANS_LO >> 1]; data[1] = sio->p->p->memory.io[REG_JOY_TRANS_LO >> 1] >> 8; data[2] = sio->p->p->memory.io[REG_JOY_TRANS_HI >> 1]; data[3] = sio->p->p->memory.io[REG_JOY_TRANS_HI >> 1] >> 8; data[4] = sio->p->p->memory.io[REG_JOYSTAT >> 1]; + mLOG(GBA_SIO, DEBUG, "JOY trans: %02X%02X%02X%02X:%02X (%02X)", data[0], data[1], data[2], data[3], data[4], sio->p->p->memory.io[REG_JOYCNT >> 1]); if (sio->p->p->memory.io[REG_JOYCNT >> 1] & 0x40) {