- int result;
- uchar operand;
- int sresult;
- uchar carryin = (regs.P & BIT_C)!=0;
-
- operand = OPERAND(code, prefix);
- result = regs.A + operand + carryin;
- sresult = (signed char)regs.A + (signed char)operand + ((regs.P & BIT_C)!=0);
- FLAG_NZ (result & 0xff);
- FLAG_ASSIGN (BIT_V, (sresult<-128) || (sresult>127));
- /* 0x80 & ((regs.A & operand & ~result)
- | (~regs.A & ~operand & result))); */
- FLAG_ASSIGN (BIT_H, (result & 0xf) < (regs.A & 0xf));
- /* 0x10 & ((regs.A & operand)
- | (operand & ~result)
- | (~result & regs.A))); */
- FLAG_ASSIGN (BIT_C, result & 0x100);
- /* 0x80 & ((regs.A & operand)
- | (operand & ~result)
- | (~result & regs.A))); */
-
-#if 0
- fprintf (stdout, "adc 0x%02x + 0x%02x + %d = 0x%02x ",
- regs.A, operand, carryin, result & 0xff);
- fprintf (stdout, "(V=%d, H=%d, C=%d, N=%d, Z=%d), ",
- (regs.P & BIT_V)!=0,
- (regs.P & BIT_H)!=0,
- (regs.P & BIT_C)!=0,
- (regs.P & BIT_N)!=0,
- (regs.P & BIT_Z)!=0);
-#endif
-
+ int result, operand1, operand2;
+ int carryin = (regs.P & BIT_C)!=0;
+
+ operand1 = regs.A;
+ operand2 = OPERAND(code, prefix);
+ result = operand1 + operand2 + carryin;
+ FLAG_NZ (result);
+ FLAG_ASSIGN (BIT_V, 0x80 & (operand1 ^ operand2 ^ result ^ (result >>1)));
+ FLAG_ASSIGN (BIT_C, 0x100 & result);
+ FLAG_ASSIGN (BIT_H, 0x10 & (operand1 ^ operand2 ^ result));
+