From 3a95b30d631fcbce31207d3e7d47924d0a0c1031 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Fri, 12 Mar 2021 02:26:43 -0800 Subject: [PATCH] GBA SIO: Improve readability --- include/mgba/internal/gba/sio.h | 8 ++++++-- src/gba/io.c | 5 +++-- src/gba/sio/joybus.c | 14 +++++++++----- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/mgba/internal/gba/sio.h b/include/mgba/internal/gba/sio.h index 0f60f8f74..e5656da0c 100644 --- a/include/mgba/internal/gba/sio.h +++ b/include/mgba/internal/gba/sio.h @@ -29,8 +29,12 @@ enum { 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); diff --git a/src/gba/io.c b/src/gba/io.c index ea2e1dc8d..8088af38e 100644 --- a/src/gba/io.c +++ b/src/gba/io.c @@ -532,7 +532,7 @@ void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t 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 @@ void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value) { case REG_DEBUG_FLAGS: if (gba->debug) { GBADebug(gba, value); + return; } // Fall through @@ -835,7 +836,7 @@ uint16_t GBAIORead(struct GBA* gba, uint32_t address) { 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: diff --git a/src/gba/sio/joybus.c b/src/gba/sio/joybus.c index 3b6a7111b..c5a339883 100644 --- a/src/gba/sio/joybus.c +++ b/src/gba/sio/joybus.c @@ -31,7 +31,7 @@ uint16_t GBASIOJOYWriteRegister(struct GBASIODriver* sio, uint32_t address, uint 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 @@ int GBASIOJOYSendCommand(struct GBASIODriver* sio, enum GBASIOJOYCommand command 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 @@ int GBASIOJOYSendCommand(struct GBASIODriver* sio, enum GBASIOJOYCommand command } 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) {