X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/d66348b4fb147eb01c30aa9b3a8904ce6c59a4c1..18d57acbf4ccd7220e59fe1f2ac1556837c5da83:/avr/z80-if.c diff --git a/avr/z80-if.c b/avr/z80-if.c index 62199bb..f36466c 100644 --- a/avr/z80-if.c +++ b/avr/z80-if.c @@ -72,6 +72,7 @@ #define WR 2 #define P_BUSREQ PORTD #define BUSREQ 7 +#define PIN_BUSREQ PIND #define DDR_BUSREQ DDRD #define P_BUSACK PORTD #define PIN_BUSACK PIND @@ -105,6 +106,7 @@ #define Z80_O_RD SBIT(P_RD, 3) #define Z80_O_WR SBIT(P_WR, 2) #define Z80_O_BUSREQ SBIT(P_BUSREQ, 7) +#define Z80_I_BUSREQ SBIT(PIN_BUSREQ, 7) //#define Z80_O_NMI SBIT(P_NMI, ) #define Z80_O_RST SBIT(P_RST, 5) #define Z80_I_RST SBIT(PIN_RST, 5) @@ -161,7 +163,6 @@ ISR(TIMER4_COMPB_vect) ISR(TIMER5_COMPA_vect) { - uint8_t i = timer; if (i) @@ -293,6 +294,16 @@ zstate_t z80_bus_state(void) return zstate; } +void z80_toggle_reset(void) +{ + Z80_I_RST = 1; +} + +void z80_toggle_busreq(void) +{ + Z80_I_BUSREQ = 1; +} + static void z80_busreq_hpulse(void) { @@ -387,10 +398,10 @@ zstate_t z80_bus_cmd(bus_cmd_t cmd) busack_cycles = 0; busack_cycles_ovl = 0; ATOMIC_BLOCK(ATOMIC_FORCEON) { - //z80_reset_inactive(); Z80_I_RST = 1; /* Toggle RESET --> inactive */ OCR4B = TCNT4; TIFR4 = _BV(OCF4B); /* Clear compare match flag */ +// TIMSK4 &= ~_BV(OCIE4A); /* Disable Output Compare A interrupt */ } TIMSK4 |= _BV(OCIE4B); /* Enable compare match interrupt */ @@ -402,6 +413,7 @@ zstate_t z80_bus_cmd(bus_cmd_t cmd) ovl_cnt = busack_cycles_ovl; ifr = TIFR4; TIMSK4 &= ~_BV(OCIE4B); /* Disable compare match interrupt */ +// TIMSK4 |= _BV(OCIE4A); /* Enable Output Compare A interrupt */ } if (Z80_I_BUSACK == 0) { if ((ifr & _BV(OCF4B)) && !(tcnt & (1<<15))) @@ -505,6 +517,106 @@ zstate_t z80_bus_cmd(bus_cmd_t cmd) return zstate; } +/*--------------------------------------------------------------------------*/ + +#define DEBUG_FREQ 0 /* set to 1 to debug */ + +#define debug_cpu(fmt, args...) \ + debug_cond(DEBUG_FREQ, fmt, ##args) + +#if 0 +static +char * ulltoa (uint64_t val, char *s) +{ + char *p = s; + + while (val >= 10) { + *p++ = (val % 10) + '0'; + val = val / 10; + } + *p++ = val + '0'; + *p = '\0'; + + return strrev(s); +} +#endif + +uint32_t z80_measure_phi(uint_fast8_t cycles) +{ + uint16_t ref_stop; + uint16_t ref_ovfl; + uint8_t x_ovfl; + uint32_t x_freq; + + + PRR1 &= ~_BV(PRTIM3); + TCCR3A = 0; + TCCR3B = 0b000< 0 || x_tmp >= 100000; sc--) x_tmp = (x_tmp + 5)/10; + x_freq = x_tmp; + for ( ; sc < 0; sc++) x_freq *= 10; + + return x_freq; +} /*--------------------------------------------------------------------------*/