From 93eff7fac6c91bbf5f2458fe1ee09979f0d86ac3 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Sun, 29 Aug 2021 11:55:42 +0200 Subject: [PATCH] sh4: fix TMU regression introduced by 05d51cc35c57b9762e7bf12cad532a6003a2f556 fixes SA2 running too fast --- core/hw/sh4/modules/tmu.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/hw/sh4/modules/tmu.cpp b/core/hw/sh4/modules/tmu.cpp index fde9c9816..6e07b4c8a 100644 --- a/core/hw/sh4/modules/tmu.cpp +++ b/core/hw/sh4/modules/tmu.cpp @@ -233,7 +233,8 @@ static int sched_tmu_cb(int ch, int sch_cycl, int jitter) //schedule next trigger by writing the TCNT register u32 tcor = TMU_TCOR(ch); - write_TMU_TCNTch(ch, std::max((s32)(tcor + tcnt), 0)); + // Don't miss an underflow if tcor is less than -tcnt + write_TMU_TCNTch(ch, (u32)std::max((u64)tcor + (s32)tcnt, 0)); } else {