Skip to content

Commit

Permalink
[#6] Support lazy flags in conditional jumps.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Jul 2, 2021
1 parent 1ab24a9 commit 87f4883
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion z80.h
Original file line number Diff line number Diff line change
Expand Up @@ -2490,8 +2490,29 @@ class i8080_executor : public internals::executor_base<B> {
}

bool check_condition(condition cc) {
// TODO: Would it make sense to store flags in a different order?
auto n = static_cast<unsigned>(cc);
if(self().on_is_to_use_lazy_flags()) {
fast_u16 flags = self().on_get_flags();
fast_u8 res8 = get_low8(flags);
switch(cc) {
case condition::nz:
case condition::z:
return (((res8 == 0) | (flags >> (zf_bit + 8))) ^ n ^ 1) & 0x1;
case condition::nc:
case condition::c:
return ((flags >> (cf_bit + 8)) ^ n ^ 1) & 0x1;
case condition::po:
case condition::pe:
return ((pf_log(res8) | (flags >> (pf_bit + 8))) ^ n ^ 1) & 0x1;
case condition::p:
case condition::m:
return (((flags >> (sf_bit + 8)) |
(flags >> sf_bit)) ^ n ^ 1) & 0x1;
}
unreachable("Unknown condition code.");
}

// TODO: Would it make sense to store flags in a different order?
unsigned flag_bits = (zf_bit << 0) | (zf_bit << 4) |
(cf_bit << 8) | (cf_bit << 12) |
(pf_bit << 16) | (pf_bit << 20) |
Expand Down

0 comments on commit 87f4883

Please sign in to comment.