Skip to content

Commit

Permalink
[#5] Refine evaluation of flags for ALU SUB and CP instructions.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Oct 31, 2020
1 parent 6eb9cbb commit f967881
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions z80.h
Original file line number Diff line number Diff line change
Expand Up @@ -2410,6 +2410,8 @@ class i8080_executor : public internals::executor_base<B> {
return (res >> (8 - base::cf_bit)) & cf_mask; }
fast_u8 hf1(fast_u8 op1, fast_u8 op2, fast_u8 cfv) {
return (op1 & 0xf) + (op2 & 0xf) + cfv > 0xf ? hf_mask : 0; }
fast_u8 hf2(fast_u8 op1, fast_u8 op2) {
return (op1 & 0xf) >= (op2 & 0xf) ? hf_mask : 0; }

void do_alu(alu k, fast_u8 n) {
fast_u8 a = self().on_get_a();
Expand All @@ -2426,10 +2428,10 @@ class i8080_executor : public internals::executor_base<B> {
break; }
case alu::sub:
case alu::cp: {
fast_u8 t = sub8(a, n);
fast_u8 hf = (a & 0xf) >= (n & 0xf) ? hf_mask : 0;
f = (t & sf_mask) | (f & (yf_mask | xf_mask | nf_mask)) |
zf_ari(t) | hf | pf_log(t) | cf_ari(t > a);
fast_u16 t16 = a - n;
fast_u8 t = mask8(t16);
f = sf(t) | yf(f) | xf(f) | nf(f) |
zf1(t) | hf2(a, n) | pf1(t) | cf1(t16);
a = t;
break; }
case alu::sbc: {
Expand Down

0 comments on commit f967881

Please sign in to comment.