mirror of https://github.com/mgba-emu/mgba.git
GBA SIO: Improve readability
This commit is contained in:
parent
885ef286d2
commit
3a95b30d63
|
@ -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);
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue