all repos — mgba @ 8ad2e89cfce6f46f4dd630e6c43ee91afb7feada

mGBA Game Boy Advance Emulator

GBA SIO: Dolphin cleanup
Vicki Pfau vi@endrift.com
Mon, 22 Feb 2021 23:54:05 -0800
commit

8ad2e89cfce6f46f4dd630e6c43ee91afb7feada

parent

2aac9da42b7514ddb3105becf46de8dee5c797f2

3 files changed, 28 insertions(+), 34 deletions(-)

jump to
M src/gba/sio.csrc/gba/sio.c

@@ -182,5 +182,19 @@ uint16_t GBASIOWriteRegister(struct GBASIO* sio, uint32_t address, uint16_t value) {

if (sio->activeDriver && sio->activeDriver->writeRegister) { return sio->activeDriver->writeRegister(sio->activeDriver, address, value); } + // Dummy drivers + switch (sio->mode) { + case SIO_JOYBUS: + switch (address) { + case REG_JOYCNT: + return (value & 0x0040) | (sio->p->memory.io[REG_JOYCNT >> 1] & ~(value & 0x7) & ~0x0040); + case REG_JOYSTAT: + return (value & 0x0030) | (sio->p->memory.io[REG_JOYSTAT >> 1] & ~0x30); + } + break; + default: + // TODO + break; + } return value; }
M src/gba/sio/dolphin.csrc/gba/sio/dolphin.c

@@ -17,15 +17,6 @@ const uint16_t DOLPHIN_CLOCK_PORT = 49420;

const uint16_t DOLPHIN_DATA_PORT = 54970; enum { - CMD_RESET = 0xFF, - CMD_POLL = 0x00, - CMD_TRANS = 0x14, - CMD_RECV = 0x15, - - CMD_NONE = 0x80 -}; - -enum { WAIT_FOR_FIRST_CLOCK = 0, WAIT_FOR_CLOCK, WAIT_FOR_COMMAND,

@@ -147,40 +138,30 @@ int32_t _processCommand(struct GBASIODolphin* dol, uint32_t cyclesLate) {

// This does not include the stop bits due to compatibility reasons int bitsOnLine = 8; uint8_t buffer[6]; - int gotten = SocketRecv(dol->data, &buffer, 5); + int gotten = SocketRecv(dol->data, buffer, 1); if (gotten < 1) { return 0; } switch (buffer[0]) { - case CMD_RESET: - case CMD_POLL: + case JOY_RESET: + case JOY_POLL: bitsOnLine += 24; break; - case CMD_RECV: - mLOG(GBA_SIO, DEBUG, "JOY <: %02X%02X%02X%02X", buffer[1], buffer[2], buffer[3], buffer[4]); + case JOY_RECV: + gotten = SocketRecv(dol->data, &buffer[1], 4); + if (gotten < 4) { + return 0; + } + mLOG(GBA_SIO, DEBUG, "DOL recv: %02X%02X%02X%02X", buffer[1], buffer[2], buffer[3], buffer[4]); // Fall through - case CMD_TRANS: + case JOY_TRANS: bitsOnLine += 40; break; } int sent = GBASIOJOYSendCommand(&dol->d, buffer[0], &buffer[1]); SocketSend(dol->data, &buffer[1], sent); - switch (buffer[0]) { - case CMD_TRANS: - mLOG(GBA_SIO, DEBUG, "JOY >: %02X%02X%02X%02X:%02X", buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]); - break; - case CMD_RECV: - mLOG(GBA_SIO, DEBUG, "JOY <: %02X", buffer[1]); - break; - case CMD_RESET: - mLOG(GBA_SIO, DEBUG, "JOY !: %02X", buffer[3]); - break; - case CMD_POLL: - mLOG(GBA_SIO, DEBUG, "JOY ?: %02X", buffer[3]); - break; - } return bitsOnLine * CYCLES_PER_BIT - cyclesLate; }
M src/gba/sio/joybus.csrc/gba/sio/joybus.c

@@ -24,10 +24,6 @@ case REG_JOYCNT:

return (value & 0x0040) | (sio->p->p->memory.io[REG_JOYCNT >> 1] & ~(value & 0x7) & ~0x0040); case REG_JOYSTAT: return (value & 0x0030) | (sio->p->p->memory.io[REG_JOYSTAT >> 1] & ~0x30); - case REG_JOY_TRANS_LO: - case REG_JOY_TRANS_HI: - sio->p->p->memory.io[REG_JOYSTAT >> 1] |= 8; - break; } return value; }

@@ -44,6 +40,7 @@ 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;

@@ -53,6 +50,7 @@ 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) { GBARaiseIRQ(sio->p->p, IRQ_SIO, 0);

@@ -60,12 +58,13 @@ }

return 1; case JOY_TRANS: sio->p->p->memory.io[REG_JOYCNT >> 1] |= 4; - sio->p->p->memory.io[REG_JOYSTAT >> 1] &= ~8; + sio->p->p->memory.io[REG_JOYSTAT >> 1] &= ~JOYSTAT_TRANS_BIT; 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) { GBARaiseIRQ(sio->p->p, IRQ_SIO, 0);