From e05680a2b9bd5e079aa29a0c39c03cc9b90c5911 Mon Sep 17 00:00:00 2001 From: kub Date: Mon, 3 Oct 2022 08:41:37 +0000 Subject: [PATCH] core, add TH pad pin latency (regression after 5 min) --- pico/memory.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pico/memory.c b/pico/memory.c index 860dfed1..2ca6f2c2 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -328,7 +328,11 @@ static NOINLINE u32 port_read(int i) // disables output before doing TH-low read, so don't emulate it for TH. // Decap Attack reportedly doesn't work on Nomad but works on must // other MD revisions (different pull-up strength?). - u32 mask = 0x3f | (padTHLatency[i] < SekCyclesDone() ? 0x40 : 0); + u32 mask = 0x3f; + if (CYCLES_GE(SekCyclesDone(), padTHLatency[i])) { + mask |= 0x40; + padTHLatency[i] = SekCyclesDone(); + } out |= mask & ~ctrl_reg; in = port_readers[i](i, out); @@ -407,10 +411,13 @@ NOINLINE void io_ports_write(u32 a, u32 d) Pico.m.padTHPhase[a - 1]++; } - // after pulling down TH there's a latency before the new value can be read - // back as input (see Decap Attack, not in Samurai Showdown, 32x WWF Raw) - if (a >= 4 && a <= 5 && !(d & 0x40)) - padTHLatency[a - 4] = SekCyclesDone() + 25; + // after switching TH to input there's a latency before the pullup value is + // read back as input (see Decap Attack, not in Samurai Showdown, 32x WWF Raw) + if (a >= 4 && a <= 5) { + padTHLatency[a - 4] = SekCyclesDone(); // if output, effective immediately + if ((PicoMem.ioports[a] & 0x40) && !(d & 0x40)) + padTHLatency[a - 4] += 25; // latency after switching to input + } // certain IO ports can be used as RAM PicoMem.ioports[a] = d; -- 2.39.2