diff --git a/tests/tester.cpp b/tests/tester.cpp index 4049697..ab455ee 100644 --- a/tests/tester.cpp +++ b/tests/tester.cpp @@ -845,11 +845,14 @@ class machine_base : public B { unsigned instr_size = 0; }; -class i8080_machine : public machine_base> { +class i8080_machine + : public machine_base>>>> { + using base = machine_base>>>>; + public: - i8080_machine(test_context &context) - : machine_base>(context) - {} + i8080_machine(test_context &context) : base(context) {} void on_set_wz(fast_u16 wz) { match_set_rp("wz", 0, wz); return base::on_set_wz(wz); } @@ -865,11 +868,14 @@ class i8080_machine : public machine_base> { } }; -class z80_machine : public machine_base> { +class z80_machine + : public machine_base>>>> { + using base = machine_base>>>>; + public: - z80_machine(test_context &context) - : machine_base>(context) - {} + z80_machine(test_context &context) : base(context) {} z80::iregp on_get_iregp_kind() { assert(instr_size > 0); diff --git a/z80.h b/z80.h index d345560..10eef1b 100644 --- a/z80.h +++ b/z80.h @@ -2402,6 +2402,18 @@ class z80_state : public internals::cpu_state_base> { state_fields fields; }; +template +class generic_state : public z80_state { + using base = z80_state; + +public: + bool get_iff() { return base::get_iff1(); } + void set_iff(bool f) { base::set_iff1(f); } + + bool on_get_iff() { return base::on_get_iff1(); } + void on_set_iff(bool f) { base::on_set_iff1(f); } +}; + template class internals::executor_base : public B { public: @@ -2409,6 +2421,18 @@ class internals::executor_base : public B { executor_base() {} + void on_inc_r_reg() { + // TODO: Consider splitting R into R[7] and R[6:0]. + fast_u8 r = self().on_get_r(); + r = (r & 0x80) | (inc8(r) & 0x7f); + self().on_set_r(r); } + + fast_u8 on_m1_fetch_cycle() { + fast_u8 n = self().on_fetch_cycle(); + if(self().on_is_z80()) + self().on_inc_r_reg(); + return n; } + fast_u8 on_disp_read_cycle(fast_u16 addr) { assert(self().on_is_z80()); return self().on_read_cycle(addr); } @@ -3143,13 +3167,6 @@ class z80_executor : public internals::executor_base { void set_i_on_ld(fast_u8 i) { self().on_set_i(i); } - void on_inc_r_reg() { - // TODO: Consider splitting R into R[7] and R[6:0]. - fast_u8 r = self().on_get_r(); - r = (r & 0x80) | (inc8(r) & 0x7f); - self().on_set_r(r); - } - fast_u16 on_get_ix() { // Always get the low byte first. fast_u8 l = self().on_get_ixl(); @@ -3948,12 +3965,6 @@ class z80_executor : public internals::executor_base { return n; } - fast_u8 on_m1_fetch_cycle() { - fast_u8 n = self().on_fetch_cycle(); - self().on_inc_r_reg(); - return n; - } - protected: using base::self; }; diff --git a/z80/_z80module.cpp b/z80/_z80module.cpp index 43c01a6..f17c7e3 100644 --- a/z80/_z80module.cpp +++ b/z80/_z80module.cpp @@ -169,9 +169,6 @@ class machine : public B { fast_u8 on_get_i() const { return state.i; } void on_set_i(fast_u8 n) { state.i = n; } - fast_u8 on_get_r() const { return state.r; } - void on_set_r(fast_u8 n) { state.r = n; } - fast_u16 on_get_ir() const { return make16(state.i, state.r); } fast_u16 on_get_pc() const { return state.pc; } @@ -263,9 +260,9 @@ class machine : public B { protected: using base::self; + machine_state state; private: - machine_state state; PyObject *on_input_callback = nullptr; }; diff --git a/z80/machine.inc b/z80/machine.inc index 98e56cc..64a3f4c 100644 --- a/z80/machine.inc +++ b/z80/machine.inc @@ -78,8 +78,11 @@ class machine_object : public z80::machine_state< machine>>, - object_state>> -{}; + object_state>> { +public: + fast_u8 on_get_r() const { return state.r; } + void on_set_r(fast_u8 n) { state.r = n; } +}; class disasm : public disasm_base> { public: