Skip to content

Commit

Permalink
[#17] Support non-dispatching accesses to regp registers.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Jul 10, 2021
1 parent b815b7c commit 2adc516
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions z80.h
Original file line number Diff line number Diff line change
Expand Up @@ -2029,8 +2029,8 @@ class internals::cpu_state_base : public B {
fast_u16 get_pc() const { return pc.get(); }
void set_pc(fast_u16 n) { pc.set(n); }

fast_u16 get_sp() const { return sp.get(); }
void set_sp(fast_u16 n) { sp.set(n); }
fast_u16 get_sp() const { return ref_rp(regp::sp).get(); }
void set_sp(fast_u16 n) { ref_rp(regp::sp).set(n); }

bool is_int_disabled() const { return int_disabled.get(); }
void set_is_int_disabled(bool disabled) { int_disabled.set(disabled); }
Expand Down Expand Up @@ -2078,6 +2078,16 @@ class internals::cpu_state_base : public B {
// increasing performance.
bool on_dispatch_register_accesses() { return true; }

using base::on_get_regp;
fast_u16 on_get_regp(regp rp) {
return self().on_dispatch_register_accesses() ?
base::on_get_regp(rp) : ref_rp(rp).get(); }

using base::on_set_regp;
void on_set_regp(regp rp, fast_u16 nn) {
return self().on_dispatch_register_accesses() ?
base::on_set_regp(rp, nn) : ref_rp(rp).set(nn); }

using base::on_get_regp2;
fast_u16 on_get_regp2(regp2 rp) {
return self().on_dispatch_register_accesses() ?
Expand All @@ -2098,6 +2108,11 @@ class internals::cpu_state_base : public B {
using base::self;

private:
regp_value &ref_rp(regp rp) {
return rps[rp == regp::sp ? 4 : static_cast<unsigned>(rp)]; }
const regp_value &ref_rp(regp rp) const {
return rps[rp == regp::sp ? 4 : static_cast<unsigned>(rp)]; }

regp_value &ref_rp(regp2 rp) {
return rps[static_cast<unsigned>(rp)]; }
const regp_value &ref_rp(regp2 rp) const {
Expand All @@ -2106,8 +2121,7 @@ class internals::cpu_state_base : public B {
// Most frequently used registers shall come first to reduce cache stress.
reg16_value pc;
flipflop int_disabled;
regp_value rps[4]; // bc, de, hl, af
reg16_value sp;
regp_value rps[5]; // bc, de, hl, af, sp
flipflop halted;

template<typename XB> friend class i8080_state;
Expand Down

0 comments on commit 2adc516

Please sign in to comment.