diff --git a/DevTools/UserspaceEmulator/SoftCPU.cpp b/DevTools/UserspaceEmulator/SoftCPU.cpp index cb967970a6..cdae654a05 100644 --- a/DevTools/UserspaceEmulator/SoftCPU.cpp +++ b/DevTools/UserspaceEmulator/SoftCPU.cpp @@ -343,12 +343,17 @@ static T op_sub(SoftCPU& cpu, const T& dest, const T& src) return result; } -template -static T op_sbb(SoftCPU& cpu, const T& dest, const T& src) +template +static T op_sbb_impl(SoftCPU& cpu, const T& dest, const T& src) { T result = 0; u32 new_flags = 0; + if constexpr (cf) + asm volatile("stc"); + else + asm volatile("clc"); + if constexpr (sizeof(T) == 4) { asm volatile("sbbl %%ecx, %%eax\n" : "=a"(result) @@ -374,6 +379,14 @@ static T op_sbb(SoftCPU& cpu, const T& dest, const T& src) return result; } +template +static T op_sbb(SoftCPU& cpu, T& dest, const T& src) +{ + if (cpu.cf()) + return op_sbb_impl(cpu, dest, src); + return op_sbb_impl(cpu, dest, src); +} + template static T op_add(SoftCPU& cpu, T& dest, const T& src) {