about summary refs log tree commit diff stats
path: root/subx/011run.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-05-12 22:41:19 -0700
committerKartik Agaram <vc@akkartik.com>2019-05-12 22:43:31 -0700
commit82fb58e6068f3718fe7cedd1cde1b405308bbbab (patch)
tree4882cf778e3035ee75c6717ed057b9810e9a5d2b /subx/011run.cc
parent4847a5e615bb2393e537295d02a57005a2b2140c (diff)
downloadmu-82fb58e6068f3718fe7cedd1cde1b405308bbbab.tar.gz
CF needs special handling for some arithmetic ops
Inline some macro definitions.
Diffstat (limited to 'subx/011run.cc')
-rw-r--r--subx/011run.cc18
1 files changed, 15 insertions, 3 deletions
diff --git a/subx/011run.cc b/subx/011run.cc
index 6b18ca06..ccc891c3 100644
--- a/subx/011run.cc
+++ b/subx/011run.cc
@@ -355,9 +355,21 @@ put_new(Name, "05", "add imm32 to EAX (add)");
 //: our first opcode
 :(before "End Single-Byte Opcodes")
 case 0x05: {  // add imm32 to EAX
-  int32_t arg2 = next32();
-  trace(Callstack_depth+1, "run") << "add imm32 0x" << HEXWORD << arg2 << " to reg EAX" << end();
-  BINARY_ARITHMETIC_OP(+, Reg[EAX].i, arg2);
+  int32_t signed_arg2 = next32();
+  trace(Callstack_depth+1, "run") << "add imm32 0x" << HEXWORD << signed_arg2 << " to reg EAX" << end();
+  int64_t signed_full_result = Reg[EAX].i + signed_arg2;
+  Reg[EAX].i += signed_arg2;
+  trace(Callstack_depth+1, "run") << "storing 0x" << HEXWORD << Reg[EAX].i << end();
+  SF = (Reg[EAX].i < 0);
+  ZF = (Reg[EAX].i == 0);
+  OF = (Reg[EAX].i != signed_full_result);
+  // set CF
+  uint32_t unsigned_arg1 = static_cast<uint32_t>(Reg[EAX].i);
+  uint32_t unsigned_arg2 = static_cast<uint32_t>(signed_arg2);
+  uint32_t unsigned_result = unsigned_arg1 + unsigned_arg2;
+  uint64_t unsigned_full_result = unsigned_arg1 + unsigned_arg2;
+  CF = (unsigned_result != unsigned_full_result);
+  trace(Callstack_depth+1, "run") << "SF=" << SF << "; ZF=" << ZF << "; CF=" << CF << "; OF=" << OF << end();
   break;
 }