mirror of https://github.com/mgba-emu/mgba.git
GBA SIO: Dolphin cleanup
This commit is contained in:
parent
2aac9da42b
commit
8ad2e89cfc
|
@ -182,5 +182,19 @@ uint16_t GBASIOWriteRegister(struct GBASIO* sio, uint32_t address, uint16_t valu
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -16,15 +16,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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -24,10 +24,6 @@ uint16_t GBASIOJOYWriteRegister(struct GBASIODriver* sio, uint32_t address, uint
|
|||
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 @@ 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;
|
||||
|
@ -53,6 +50,7 @@ int GBASIOJOYSendCommand(struct GBASIODriver* sio, enum GBASIOJOYCommand command
|
|||
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 @@ 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] &= ~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);
|
||||
|
|
Loading…
Reference in New Issue