Backport https://github.com/flyinghead/flycast/commit/04cd7db2cd81d516d880e5db4fda608cdf674a18#diff-19595e2c781f23388ecea5069f3af208a3423726fed0278d9c9b72ddadae8c43