Backport https://github.com/flyinghead/flycast/commit/96c8353364293060d981c3a301a83dbdce134d86#diff-7194c04007dd96b8c496118886760725f8eb7b8bda6916d63bf6e3ea967e44a7