diff --git a/src/core/pad.cpp b/src/core/pad.cpp index 386a78b04..3935371c5 100644 --- a/src/core/pad.cpp +++ b/src/core/pad.cpp @@ -152,6 +152,9 @@ u32 Pad::ReadRegister(u32 offset) { case 0x00: // JOY_DATA { + if (IsTransmitting()) + m_transfer_event->InvokeEarly(); + const u8 value = m_receive_buffer_full ? m_receive_buffer : 0xFF; Log_DebugPrintf("JOY_DATA (R) -> 0x%02X%s", ZeroExtend32(value), m_receive_buffer_full ? "" : "(EMPTY)"); m_receive_buffer_full = false; @@ -163,6 +166,9 @@ u32 Pad::ReadRegister(u32 offset) case 0x04: // JOY_STAT { + if (IsTransmitting()) + m_transfer_event->InvokeEarly(); + const u32 bits = m_JOY_STAT.bits; m_JOY_STAT.ACKINPUT = false; return bits; @@ -388,13 +394,10 @@ void Pad::DoTransfer(TickCount ticks_late) } else { - const TickCount ack_timer = GetACKTicks(); + const TickCount ack_timer = GetACKTicks(m_active_device == ActiveDevice::MemoryCard); Log_DebugPrintf("Delaying ACK for %d ticks", ack_timer); m_state = State::WaitingForACK; - if (ticks_late >= ack_timer) - DoACK(); - else - m_transfer_event->SetPeriodAndSchedule(ack_timer - ticks_late); + m_transfer_event->SetPeriodAndSchedule(ack_timer); } UpdateJoyStat(); diff --git a/src/core/pad.h b/src/core/pad.h index 4e4492599..300eabcff 100644 --- a/src/core/pad.h +++ b/src/core/pad.h @@ -92,7 +92,12 @@ private: bool CanTransfer() const { return m_transmit_buffer_full && m_JOY_CTRL.SELECT && m_JOY_CTRL.TXEN; } TickCount GetTransferTicks() const { return static_cast(ZeroExtend32(m_JOY_BAUD) * 8); } - TickCount GetACKTicks() const { return 32; } + + // From @JaCzekanski + // ACK lasts ~96 ticks or approximately 2.84us at master clock (not implemented). + // ACK delay is between 6.8us-13.7us, or ~338 ticks at master clock for approximately 9.98us. + // Memory card responds faster, approximately 5us or ~170 ticks. + static constexpr TickCount GetACKTicks(bool memory_card) { return memory_card ? 170 : 450; } void SoftReset(); void UpdateJoyStat();