static uint8_t dreamload_get_byte_old(void) { unsigned int i; iec_bus_t tmp; uint8_t result = 0; for (i=0; i<2; i++) { /* shift bits to upper nibble */ result <<= 4; /* wait until ATN is low */ while (IEC_ATN) ; /* read two bits a moment later */ delay_us(3); tmp = iec_bus_read(); result |= (!(tmp & IEC_BIT_CLOCK)) << 3; result |= (!(tmp & IEC_BIT_DATA)) << 1; /* wait until ATN is high */ while (!IEC_ATN) ; /* read two bits a moment later */ delay_us(3); tmp = iec_bus_read(); result |= (!(tmp & IEC_BIT_CLOCK)) << 2; result |= (!(tmp & IEC_BIT_DATA)) << 0; } return result; }
/** * read_bus_at - reads the IEC bus at a certain time * @time: read time in 100ns after reference_time * * This function returns the current IEC bus state at a certain time * after the reference_time set by a previous wait_* function. */ static __attribute__((unused)) uint32_t read_bus_at(uint32_t time) { /* check if requested time is possible */ // FIXME: Wrap in debugging macro? if (IEC_TIMER_A->TC >= reference_time+time) set_test_led(1); // FIXME: This could be done in hardware using DMA /* Wait until specified time */ while (IEC_TIMER_A->TC < reference_time+time) ; return iec_bus_read(); }
/* DolphinDOS XQ command */ void load_dolphin(void) { /* find the already open buffer */ buffer_t *buf = find_buffer(0); if (!buf) return; buf->position = 2; /* initial handshaking */ // note about the delays: 100us work, not optimized // (doesn't matter much outside the loop) delay_us(100); // experimental delay parallel_set_dir(PARALLEL_DIR_OUT); set_clock(0); parallel_clear_rxflag(); delay_us(100); // experimental delay parallel_send_handshake(); uart_flush(); delay_us(100); // experimental delay /* every sector except the last */ uint8_t i; while (!buf->sendeoi) { iec_bus_t bus_state = iec_bus_read(); /* transmit first byte */ dolphin_write_hs(buf->data[2]); /* check DATA state before transmission */ if (bus_state & IEC_BIT_DATA) { cleanup_and_free_buffer(buf); return; } /* transmit the rest of the sector */ for (i = 3; i != 0; i++) dolphin_write_hs(buf->data[i]); /* read next sector */ if (buf->refill(buf)) { cleanup_and_free_buffer(buf); return; } } /* last sector */ i = 2; do { dolphin_write_hs(buf->data[i]); } while (i++ < buf->lastused); /* final handshake */ set_clock(1); while (!IEC_DATA) ; parallel_send_handshake(); parallel_set_dir(PARALLEL_DIR_IN); cleanup_and_free_buffer(buf); }