Skip to content

Commit

Permalink
[#6] Deprecate flags-related functions that we want to get rid of.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Jul 1, 2021
1 parent 3fafa35 commit 11a990e
Showing 1 changed file with 31 additions and 43 deletions.
74 changes: 31 additions & 43 deletions z80.h
Original file line number Diff line number Diff line change
Expand Up @@ -2431,37 +2431,25 @@ class i8080_executor : public internals::executor_base<B> {
return sf(res8) | zf(res8) | hf(ops) | pf(res8) | cf9(res9);
}

void unpack_flags(fast_u32 flags, fast_u8 &b, fast_u16 &w) {
b = mask8(flags >> 16);
w = mask16(flags);
}

// TODO: Make this public once lazy flags are fully supported.
// TODO: Test calls to this function.
fast_u32 on_get_flags() {
fast_u32 x_on_get_flags() {
return self().on_get_f();
}

void on_set_flags(fast_u32 flags) {
#if 0 // TODO
flag_op fop;
fast_u8 b;
fast_u16 w;
unpack_flags(flags, fop, b, w);
self().on_set_f(eval_flags(fop, b, w));
#endif
void x_on_set_flags(fast_u32 flags) {
self().on_set_f(static_cast<fast_u8>(flags));
}

static fast_u8 get_cf(fast_u32 flags) {
static fast_u8 x_get_cf(fast_u32 flags) {
return flags & cf_mask;
}

static fast_u32 set_cf(fast_u32 flags, fast_u32 cf) {
static fast_u32 x_set_cf(fast_u32 flags, fast_u32 cf) {
return (flags & ~cf_mask) | cf;
}

static fast_u8 get_hf_cf(fast_u32 flags) {
static fast_u8 x_get_hf_cf(fast_u32 flags) {
return flags & (hf_mask | cf_mask);
}

Expand All @@ -2473,7 +2461,7 @@ class i8080_executor : public internals::executor_base<B> {
if(((static_cast<unsigned>(k) + 1) & 0x7) < 5) {
// ADD, ADC, SUB, SBC, CP
fast_u8 cfv = (k == alu::adc || k == alu::sbc) ?
get_cf(self().on_get_flags()) : 0;
x_get_cf(self().x_on_get_flags()) : 0;
if(k <= alu::adc) {
t = a + n + cfv;
b = a ^ n ^ static_cast<fast_u8>(t);
Expand All @@ -2499,7 +2487,7 @@ class i8080_executor : public internals::executor_base<B> {
}
if(k != alu::cp)
self().on_set_a(mask8(t));
self().on_set_flags(eval_flags(b, t));
self().x_on_set_flags(eval_flags(b, t));
}

void on_add_irp_rp(regp rp) {
Expand All @@ -2508,11 +2496,11 @@ class i8080_executor : public internals::executor_base<B> {

fast_u16 i = self().on_get_hl();
fast_u16 n = self().on_get_regp(rp);
fast_u32 flags = self().on_get_flags();
fast_u32 flags = self().x_on_get_flags();
fast_u32 r32 = i + n;
self().on_set_wz(inc16(i));
self().on_set_hl(mask16(r32));
self().on_set_flags(set_cf(flags, r32 >> 16)); }
self().x_on_set_flags(x_set_cf(flags, r32 >> 16)); }
void on_alu_r(alu k, reg r) {
do_alu(k, self().on_get_reg(r)); }
void on_call_cc_nn(condition cc, fast_u16 nn) {
Expand All @@ -2522,13 +2510,13 @@ class i8080_executor : public internals::executor_base<B> {
self().on_set_wz(nn);
}
void on_ccf() {
fast_u32 flags = self().on_get_flags();
self().on_set_flags(set_cf(flags, get_cf(flags) ^ 1)); }
fast_u32 flags = self().x_on_get_flags();
self().x_on_set_flags(x_set_cf(flags, x_get_cf(flags) ^ 1)); }
void on_cpl() {
self().on_set_a(self().on_get_a() ^ 0xff); }
void on_daa() {
fast_u8 a = self().on_get_a();
fast_u8 f = get_hf_cf(self().on_get_flags());
fast_u8 f = x_get_hf_cf(self().x_on_get_flags());

fast_u8 r = a;
fast_u8 t = r + 6;
Expand All @@ -2542,14 +2530,14 @@ class i8080_executor : public internals::executor_base<B> {
r = mask8(t2);

self().on_set_a(r);
self().on_set_flags(eval_flags(hfv, w | r)); }
self().x_on_set_flags(eval_flags(hfv, w | r)); }
void on_dec_r(reg r) {
fast_u8 n = self().on_get_reg(r);
fast_u32 flags = self().on_get_flags();
fast_u32 flags = self().x_on_get_flags();
fast_u8 t = mask8(n - 1);
self().on_set_reg(r, t);
self().on_set_flags(eval_flags(n ^ t ^ hf_mask,
(get_cf(flags) << 8) | t)); }
self().x_on_set_flags(eval_flags(n ^ t ^ hf_mask,
(x_get_cf(flags) << 8) | t)); }
void on_di() {
self().set_iff_on_di(false); }
void on_ei() {
Expand All @@ -2575,11 +2563,11 @@ class i8080_executor : public internals::executor_base<B> {
self().on_set_a(self().on_input_cycle(n)); }
void on_inc_r(reg r) {
fast_u8 n = self().on_get_reg(r);
fast_u32 flags = self().on_get_flags();
fast_u32 flags = self().x_on_get_flags();
fast_u8 t = mask8(n + 1);
self().on_set_reg(r, t);
self().on_set_flags(eval_flags(n ^ t,
(get_cf(flags) << 8) | t)); }
self().x_on_set_flags(eval_flags(n ^ t,
(x_get_cf(flags) << 8) | t)); }
void on_ld_r_n(reg r, fast_u8 n) {
self().on_set_reg(r, n); }
void on_ld_r_r(reg rd, reg rs) {
Expand Down Expand Up @@ -2617,31 +2605,31 @@ class i8080_executor : public internals::executor_base<B> {
self().on_set_regp2(rp, nn); }
void on_rla() {
fast_u8 a = self().on_get_a();
fast_u32 flags = self().on_get_flags();
fast_u16 t = (a << 1) | get_cf(flags);
fast_u32 flags = self().x_on_get_flags();
fast_u16 t = (a << 1) | x_get_cf(flags);
self().on_set_a(mask8(t));
self().on_set_flags(set_cf(flags, t >> 8)); }
self().x_on_set_flags(x_set_cf(flags, t >> 8)); }
void on_rra() {
fast_u8 a = self().on_get_a();
fast_u32 flags = self().on_get_flags();
fast_u8 r = (a >> 1) | (get_cf(flags) << 7);
fast_u32 flags = self().x_on_get_flags();
fast_u8 r = (a >> 1) | (x_get_cf(flags) << 7);
self().on_set_a(r);
self().on_set_flags(set_cf(flags, a & 1)); }
self().x_on_set_flags(x_set_cf(flags, a & 1)); }
void on_rlca() {
fast_u8 a = self().on_get_a();
fast_u32 flags = self().on_get_flags();
fast_u32 flags = self().x_on_get_flags();
a = rol8(a);
self().on_set_a(a);
self().on_set_flags(set_cf(flags, a & 1)); }
self().x_on_set_flags(x_set_cf(flags, a & 1)); }
void on_rrca() {
fast_u8 a = self().on_get_a();
fast_u32 flags = self().on_get_flags();
fast_u32 flags = self().x_on_get_flags();
a = ror8(a);
self().on_set_a(a);
self().on_set_flags(set_cf(flags, a >> 7)); }
self().x_on_set_flags(x_set_cf(flags, a >> 7)); }
void on_scf() {
fast_u32 flags = self().on_get_flags();
self().on_set_flags(set_cf(flags, 1)); }
fast_u32 flags = self().x_on_get_flags();
self().x_on_set_flags(x_set_cf(flags, 1)); }

protected:
using base::self;
Expand Down

0 comments on commit 11a990e

Please sign in to comment.