-static inline bool read_bit(void)
-{
- // ADB Bit Cells
- //
- // bit cell time: 70-130us
- // low part of bit0: 60-70% of bit cell
- // low part of bit1: 30-40% of bit cell
- //
- // bit cell time 70us 130us
- // --------------------------------------------
- // low part of bit0 42-49 78-91
- // high part of bit0 21-28 39-52
- // low part of bit1 21-28 39-52
- // high part of bit1 42-49 78-91
- //
- //
- // bit0:
- // 70us bit cell:
- // ____________~~~~~~
- // 42-49 21-28
- //
- // 130us bit cell:
- // ____________~~~~~~
- // 78-91 39-52
- //
- // bit1:
- // 70us bit cell:
- // ______~~~~~~~~~~~~
- // 21-28 42-49
- //
- // 130us bit cell:
- // ______~~~~~~~~~~~~
- // 39-52 78-91
- //
- // read:
- // ________|~~~~~~~~~
- // 55us
- // Read data line after 55us. If data line is low/high then bit is 0/1.
- // This method might not work at <90us bit cell time.
- //
- // [from Apple IIgs Hardware Reference Second Edition]
- bool bit;
- wait_data_lo(75); // wait the start of bit cell at least 130ms(55+0+75)
- _delay_us(55);
- bit = data_in();
- wait_data_hi(36); // wait high part of bit cell at least 91ms(55+36)
- return bit;
-}
-
-static inline uint8_t read_byte(void)
-{
- uint8_t data = 0;
- for (int i = 0; i < 8; i++) {
- data <<= 1;
- if (read_bit())
- data = data | 1;
- }
- return data;
-}
-
-static inline uint8_t wait_data_lo(uint16_t us)
+// These are carefully coded to take 6 cycles of overhead.
+// inline asm approach became too convoluted
+static inline uint16_t wait_data_lo(uint16_t us)