Skip to content

Commit

Permalink
[#15] Move on_m1_fetch_cycle().
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Aug 26, 2021
1 parent 26d6c44 commit de830b8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
22 changes: 14 additions & 8 deletions tests/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,11 +845,14 @@ class machine_base : public B {
unsigned instr_size = 0;
};

class i8080_machine : public machine_base<z80::i8080_cpu<i8080_machine>> {
class i8080_machine
: public machine_base<z80::i8080_executor<
z80::i8080_decoder<z80::generic_state<z80::root<i8080_machine>>>>> {
using base = machine_base<z80::i8080_executor<
z80::i8080_decoder<z80::generic_state<z80::root<i8080_machine>>>>>;

public:
i8080_machine(test_context &context)
: machine_base<z80::i8080_cpu<i8080_machine>>(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); }
Expand All @@ -865,11 +868,14 @@ class i8080_machine : public machine_base<z80::i8080_cpu<i8080_machine>> {
}
};

class z80_machine : public machine_base<z80::z80_cpu<z80_machine>> {
class z80_machine
: public machine_base<z80::z80_executor<
z80::z80_decoder<z80::generic_state<z80::root<z80_machine>>>>> {
using base = machine_base<z80::z80_executor<
z80::z80_decoder<z80::generic_state<z80::root<z80_machine>>>>>;

public:
z80_machine(test_context &context)
: machine_base<z80::z80_cpu<z80_machine>>(context)
{}
z80_machine(test_context &context) : base(context) {}

z80::iregp on_get_iregp_kind() {
assert(instr_size > 0);
Expand Down
37 changes: 24 additions & 13 deletions z80.h
Original file line number Diff line number Diff line change
Expand Up @@ -2402,13 +2402,37 @@ class z80_state : public internals::cpu_state_base<z80_decoder_state<B>> {
state_fields fields;
};

template<typename B>
class generic_state : public z80_state<B> {
using base = z80_state<B>;

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<typename B>
class internals::executor_base : public B {
public:
typedef B base;

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); }
Expand Down Expand Up @@ -3143,13 +3167,6 @@ class z80_executor : public internals::executor_base<B> {

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();
Expand Down Expand Up @@ -3948,12 +3965,6 @@ class z80_executor : public internals::executor_base<B> {
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;
};
Expand Down
5 changes: 1 addition & 4 deletions z80/_z80module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -263,9 +260,9 @@ class machine : public B {

protected:
using base::self;
machine_state state;

private:
machine_state state;
PyObject *on_input_callback = nullptr;
};

Expand Down
7 changes: 5 additions & 2 deletions z80/machine.inc
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ class machine_object
: public z80::machine_state<
machine<z80::z80_executor<
z80::z80_decoder<z80::root<machine_object>>>,
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<z80::z80_disasm<disasm>> {
public:
Expand Down

0 comments on commit de830b8

Please sign in to comment.