From 631085f1e6fcab094e87ef691f15b299781017af Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Mon, 14 Aug 2023 21:16:43 +0100 Subject: [PATCH] ps1: separate /ack and transfer delays into two counters --- ares/ps1/peripheral/io.cpp | 16 +++++----------- ares/ps1/peripheral/peripheral.cpp | 17 ++++++++++++----- ares/ps1/peripheral/peripheral.hpp | 3 ++- ares/ps1/peripheral/serialization.cpp | 3 ++- ares/ps1/system/serialization.cpp | 2 +- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/ares/ps1/peripheral/io.cpp b/ares/ps1/peripheral/io.cpp index 859a71ad7e..0eea3afedd 100644 --- a/ares/ps1/peripheral/io.cpp +++ b/ares/ps1/peripheral/io.cpp @@ -13,36 +13,30 @@ auto Peripheral::transmit(u8 data) -> void { //Calculate the number of cycles required to transfer a byte at the current baud rate //This is added to the /ACK delay to determine the total duration until /ACK is asserted - //NOTE: transfer time is only emulated for memory cards for now, not controllers - //enabling it for controllers causes games to drop input; needs further investigation u8 factors[4] = {1, 1, 16, 64}; - auto transferCycles = ((io.baudrateReloadValue * factors[io.baudrateReloadFactor])) * 8; + io.transferCounter = ((io.baudrateReloadValue * factors[io.baudrateReloadFactor])) * 8; if(io.slotNumber == 0) { if(!memoryCardPort1.active()) { - io.receiveSize = 1; io.receiveData = controllerPort1.bus(data); - if(controllerPort1.acknowledge()) io.counter = /*transferCycles*/ + 338; // approx 9.98us + if(controllerPort1.acknowledge()) io.ackCounter = 338; // approx 9.98us } if(!controllerPort1.active()) { - io.receiveSize = 1; io.receiveData = memoryCardPort1.bus(data); - if(memoryCardPort1.acknowledge()) io.counter = transferCycles + 170; // approx 5us + if(memoryCardPort1.acknowledge()) io.ackCounter = 170; // approx 5us } } if(io.slotNumber == 1) { if(!memoryCardPort2.active()) { - io.receiveSize = 1; io.receiveData = controllerPort2.bus(data); - if(controllerPort2.acknowledge()) io.counter = /*transferCycles*/ + 338; // approx 9.98us + if(controllerPort2.acknowledge()) io.ackCounter = 338; // approx 9.98us } if(!controllerPort2.active()) { - io.receiveSize = 1; io.receiveData = memoryCardPort2.bus(data); - if(memoryCardPort2.acknowledge()) io.counter = transferCycles + 170; // approx 5us + if(memoryCardPort2.acknowledge()) io.ackCounter = 170; // approx 5us } } } diff --git a/ares/ps1/peripheral/peripheral.cpp b/ares/ps1/peripheral/peripheral.cpp index 937b640772..b5daa750d9 100644 --- a/ares/ps1/peripheral/peripheral.cpp +++ b/ares/ps1/peripheral/peripheral.cpp @@ -18,9 +18,16 @@ auto Peripheral::unload() -> void { } auto Peripheral::main() -> void { - if(io.counter > 0) { - if(--io.counter == 0) { - if(!io.acknowledgeAsserted) { + if(io.transferCounter > 0) { + if(--io.transferCounter == 0) { + //transfer complete, set receive size to 1 byte + io.receiveSize = 1; + } + } + + if(io.transferCounter == 0 && io.ackCounter > 0) { + if(--io.ackCounter == 0) { + if (!io.acknowledgeAsserted) { //Assert /ACK and fire the IRQ io.interruptRequest = 1; io.acknowledgeAsserted = 1; @@ -28,9 +35,9 @@ auto Peripheral::main() -> void { interrupt.raise(Interrupt::Peripheral); } - io.counter = 96; // ACK duration is approx 96 cycles (2.84us) + io.ackCounter = 96; // ACK duration is approx 96 cycles (2.84us) } else { - //Deassert /ACK + //De-assert /ACK io.acknowledgeAsserted = 0; } } diff --git a/ares/ps1/peripheral/peripheral.hpp b/ares/ps1/peripheral/peripheral.hpp index e06beda36e..d38f2f0ff9 100644 --- a/ares/ps1/peripheral/peripheral.hpp +++ b/ares/ps1/peripheral/peripheral.hpp @@ -77,7 +77,8 @@ struct Peripheral : Thread, Memory::Interface { n16 baudrateReloadValue; //internal - i32 counter; + i32 transferCounter; + i32 ackCounter; } io; }; diff --git a/ares/ps1/peripheral/serialization.cpp b/ares/ps1/peripheral/serialization.cpp index 4cd40c3731..576a1af50a 100644 --- a/ares/ps1/peripheral/serialization.cpp +++ b/ares/ps1/peripheral/serialization.cpp @@ -31,5 +31,6 @@ auto Peripheral::serialize(serializer& s) -> void { s(io.slotNumber); s(io.unknownCtrl_14_15); s(io.baudrateReloadValue); - s(io.counter); + s(io.transferCounter); + s(io.ackCounter); } diff --git a/ares/ps1/system/serialization.cpp b/ares/ps1/system/serialization.cpp index 88d21df566..f51606f8b0 100644 --- a/ares/ps1/system/serialization.cpp +++ b/ares/ps1/system/serialization.cpp @@ -1,4 +1,4 @@ -static const string SerializerVersion = "v131"; +static const string SerializerVersion = "v133"; auto System::serialize(bool synchronize) -> serializer { serializer s;