SI/DeviceGBA: Fix SI timings to actually closely match hardware

This commit is contained in:
Vicki Pfau 2021-03-02 21:51:29 -08:00
parent 8d2b0fff8a
commit 4ce3362bce
1 changed files with 17 additions and 9 deletions

View File

@ -43,42 +43,50 @@ enum EJoybusCmds
CMD_WRITE = 0x15 CMD_WRITE = 0x15
}; };
constexpr auto BITS_PER_SECOND = 115200; constexpr auto GC_BITS_PER_SECOND = 200000;
constexpr auto BYTES_PER_SECOND = BITS_PER_SECOND / 8; constexpr auto GBA_BITS_PER_SECOND = 250000;
constexpr auto GC_STOP_BIT_NS = 6500;
constexpr auto GBA_STOP_BIT_NS = 14000;
constexpr auto SEND_MAX_SIZE = 5, RECV_MAX_SIZE = 5; constexpr auto SEND_MAX_SIZE = 5, RECV_MAX_SIZE = 5;
// --- GameBoy Advance "Link Cable" --- // --- GameBoy Advance "Link Cable" ---
static int GetTransferTime(u8 cmd) static int GetTransferTime(u8 cmd)
{ {
u64 bytes_transferred = 0; u64 gc_bytes_transferred = 1;
u64 gba_bytes_transferred = 1;
u64 stop_bits_ns = GC_STOP_BIT_NS + GBA_STOP_BIT_NS;
switch (cmd) switch (cmd)
{ {
case CMD_RESET: case CMD_RESET:
case CMD_STATUS: case CMD_STATUS:
{ {
bytes_transferred = 4; gba_bytes_transferred = 3;
break; break;
} }
case CMD_READ: case CMD_READ:
{ {
bytes_transferred = 6; gba_bytes_transferred = 5;
break; break;
} }
case CMD_WRITE: case CMD_WRITE:
{ {
bytes_transferred = 1; gc_bytes_transferred = 5;
break; break;
} }
default: default:
{ {
bytes_transferred = 1; gba_bytes_transferred = 0;
break; break;
} }
} }
return static_cast<int>(bytes_transferred * SystemTimers::GetTicksPerSecond() /
(std::max(s_num_connected, 1) * BYTES_PER_SECOND)); u64 cycles =
(gba_bytes_transferred * 8 * SystemTimers::GetTicksPerSecond() / GBA_BITS_PER_SECOND) +
(gc_bytes_transferred * 8 * SystemTimers::GetTicksPerSecond() / GC_BITS_PER_SECOND) +
(stop_bits_ns * SystemTimers::GetTicksPerSecond() / 1000000000LL);
return static_cast<int>(cycles);
} }
static void GBAConnectionWaiter() static void GBAConnectionWaiter()