From 12ab46def9509037e0cf5a40a7908ec6c02f7e68 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 11 Jul 2020 13:45:39 +0200 Subject: [PATCH] UserspaceEmulator: Give SoftCPU an API for evaluating jump conditions There are 16 conditions and they're all based on a combination of the CPU flags. --- DevTools/UserspaceEmulator/SoftCPU.h | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/DevTools/UserspaceEmulator/SoftCPU.h b/DevTools/UserspaceEmulator/SoftCPU.h index 925883b8e3..5620c67502 100644 --- a/DevTools/UserspaceEmulator/SoftCPU.h +++ b/DevTools/UserspaceEmulator/SoftCPU.h @@ -214,6 +214,47 @@ public: void write_memory16(X86::LogicalAddress, u16); void write_memory32(X86::LogicalAddress, u32); + bool evaluate_condition(u8 condition) const + { + switch (condition) { + case 0: + return of(); // O + case 1: + return !of(); // NO + case 2: + return cf(); // B, C, NAE + case 3: + return !cf(); // NB, NC, AE + case 4: + return zf(); // E, Z + case 5: + return !zf(); // NE, NZ + case 6: + return (cf() | zf()); // BE, NA + case 7: + return !(cf() | zf()); // NBE, A + case 8: + return sf(); // S + case 9: + return !sf(); // NS + case 10: + return pf(); // P, PE + case 11: + return !pf(); // NP, PO + case 12: + return sf() ^ of(); // L, NGE + case 13: + return !(sf() ^ of()); // NL, GE + case 14: + return (sf() ^ of()) | zf(); // LE, NG + case 15: + return !((sf() ^ of()) | zf()); // NLE, G + default: + ASSERT_NOT_REACHED(); + } + return 0; + } + private: virtual void AAA(const X86::Instruction&) override; virtual void AAD(const X86::Instruction&) override;