Skip to content

Commit

Permalink
[#15] Combine i8080 and Z80 versions of on_input_cycle() and on_outpu…
Browse files Browse the repository at this point in the history
…t_cycle().
  • Loading branch information
kosarev committed Aug 26, 2021
1 parent 7df1242 commit eefc716
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions z80.h
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,29 @@ class internals::executor_base : public B {
void on_3t_exec_cycle() {
self().on_tick(3); }

fast_u8 on_input_cycle(fast_u16 port) {
// Z80 samples the value at t4 of the input cycle, see
// <http://ramsoft.bbk.org.omegahg.com/floatingbus.html>.
bool z80 = self().on_is_z80();
if(z80) {
// TODO: Should we do the same for i8080?
self().on_set_addr_bus(port);
}
self().on_tick(z80 ? 3 : 2);
self().on_iorq_wait(port);
self().on_tick(1);
return self().on_input(port); }
void on_output_cycle(fast_u16 port, fast_u8 n) {
bool z80 = self().on_is_z80();
if(z80) {
// TODO: Should we do the same for i8080?
self().on_set_addr_bus(port);
}
self().on_tick(z80 ? 3 : 2);
self().on_iorq_wait(port);
self().on_tick(1);
self().on_output(port, n); }

void on_set_addr_bus(fast_u16 addr) {
unused(addr); }

Expand Down Expand Up @@ -2706,17 +2729,6 @@ class i8080_executor : public internals::executor_base<B> {
self().set_pc_on_fetch(inc16(addr));
return n; }

fast_u8 on_input_cycle(fast_u8 port) {
self().on_tick(2);
self().on_iorq_wait(port);
self().on_tick(1);
return self().on_input(port); }
void on_output_cycle(fast_u8 port, fast_u8 n) {
self().on_tick(2);
self().on_iorq_wait(port);
self().on_tick(1);
self().on_output(port, n); }

private:
static fast_u8 cf(fast_u8 f) {
return f & cf_mask; }
Expand Down Expand Up @@ -3950,25 +3962,6 @@ class z80_executor : public internals::executor_base<B> {
self().on_tick(5);
}

fast_u8 on_input_cycle(fast_u16 port) {
// Z80 samples the value at t4 of the input cycle, see
// <http://ramsoft.bbk.org.omegahg.com/floatingbus.html>.
self().on_set_addr_bus(port);
self().on_tick(3);
self().on_iorq_wait(port);
self().on_tick(1);
fast_u8 n = self().on_input(port);
return n;
}

void on_output_cycle(fast_u16 port, fast_u8 n) {
self().on_set_addr_bus(port);
self().on_tick(3);
self().on_iorq_wait(port);
self().on_tick(1);
self().on_output(port, n);
}

protected:
using base::self;
};
Expand Down

0 comments on commit eefc716

Please sign in to comment.