Skip to content

Commit

Permalink
[#15] Combine on_decode_exx().
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Aug 29, 2021
1 parent 9e90d4e commit 6b187e0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
16 changes: 10 additions & 6 deletions z80.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ class root {
static_assert(internals::get_false<derived>(),
"on_ex_af_alt_af_regs() has to be implemented!"); }
void on_exx_regs() {
static_assert(internals::get_false<derived>(),
"on_exx_regs() has to be implemented!"); }
static_assert(!derived::z80_enabled,
"on_exx_regs() has to be implemented!"); }

fast_u8 on_read(fast_u16 addr) {
unused(addr);
Expand Down Expand Up @@ -656,6 +656,12 @@ class internals::decoder_base : public B {
self().on_fetch_cycle_extra_2t();
self().on_ld_sp_irp(); }

// Swaps.
void on_decode_exx() {
if(!self().on_is_z80())
return self().on_xret();
self().on_exx(); }

// Arithmetic.
void on_decode_inc_r(reg r) {
fast_u8 d;
Expand Down Expand Up @@ -1186,6 +1192,7 @@ class i8080_decoder : public internals::decoder_base<B> {
public:
typedef internals::decoder_base<B> base;

static const bool z80_enabled = false;
bool on_is_z80() { return false; }

void on_decode_alu_r(alu k, reg r) {
Expand All @@ -1211,8 +1218,6 @@ class i8080_decoder : public internals::decoder_base<B> {
void on_decode_ex_de_hl() {
self().on_fetch_cycle_extra_1t();
self().on_ex_de_hl(); }
void on_decode_exx() {
self().on_xret(); }

protected:
using base::self;
Expand All @@ -1225,6 +1230,7 @@ class z80_decoder : public internals::decoder_base<B> {

z80_decoder() {}

static const bool z80_enabled = true;
bool on_is_z80() { return true; }

void disable_int_on_index_prefix() { self().on_set_is_int_disabled(true); }
Expand Down Expand Up @@ -1254,8 +1260,6 @@ class z80_decoder : public internals::decoder_base<B> {
self().on_ex_af_alt_af(); }
void on_decode_ex_de_hl() {
self().on_ex_de_hl(); }
void on_decode_exx() {
self().on_exx(); }

protected:
using base::self;
Expand Down
11 changes: 0 additions & 11 deletions z80/_z80module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,6 @@ class machine : public B {
std::swap(state.e, state.l);
}

void on_exx_regs() {
std::swap(state.b, state.alt_b);
std::swap(state.c, state.alt_c);

std::swap(state.d, state.alt_d);
std::swap(state.e, state.alt_e);

std::swap(state.h, state.alt_h);
std::swap(state.l, state.alt_l);
}

void on_tick(unsigned t) {
base::on_tick(t);

Expand Down
11 changes: 11 additions & 0 deletions z80/machine.inc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ public:
void on_set_iy(fast_u16 n) { split16(state.iyh, state.iyl, n); }

fast_u16 on_get_ir() const { return make16(state.i, state.r); }

void on_exx_regs() {
std::swap(state.b, state.alt_b);
std::swap(state.c, state.alt_c);

std::swap(state.d, state.alt_d);
std::swap(state.e, state.alt_e);

std::swap(state.h, state.alt_h);
std::swap(state.l, state.alt_l);
}
};

class disasm : public disasm_base<z80::z80_disasm<disasm>> {
Expand Down

0 comments on commit 6b187e0

Please sign in to comment.