iic_writebyte
        Push     "R0-R3, R14"

        MOV      R2, R0      ; Pop the byte into R2
        MOV      R1, #&80    ; 2^7 bit mask
iic_writebyte_loop
        ANDS     R0, R2, R1  ; zero if bit is zero
        MOVNE    R0, #1
        BL       iic_sendbit
        MOVS     R1, R1, LSR #1
        BNE      iic_writebyte_loop

        ; Do the fake ninth bit (for ack)
        MOV      R1, #(SDA_HIGH + SCL_LOW)
        BL       toggle_printer
        MOV      R1, #(SDA_HIGH + SCL_HIGH)
        BL       toggle_printer

        ; At this point, SCL should have been pulled
        ; LOW by the slave if it is requesting
        ; a pause. We dont support this, and if we
        ; did - wed need a timeout in case of some
        ; kind of hardware fault.

        ; Read the Ack state
        MOV      R0, #0
        SWI      XParallel_Op
        ; ignore errors
        AND      R3, R2, #SDA_IN
        ; mask it and stuff it in R3 to skip...

        ; leave bus in ready state
        MOV      R1, #(SDA_HIGH + SCL_LOW)
        BL       toggle_printer
        ; Has slave pulled SDA LOW? (bit set=LOW)
        CMP      R3, #SDA_IN
        BNE      iic_writebyte_noack ; no=Ack failed

        Pull     "R0-R3, PC"


iic_writebyte_noack
        ; clear the IC bus (it floats high)
        MOV      R1, #(SDA_HIGH + SCL_HIGH)
        BL       toggle_printer

        ; abort from EVERYTHING!
        Pull     "R0-R3, R14"
        Pull     "R0-R6, R14"
                                             ; ***********************************
        ADR      R0, iicnorepmsg             ;            !!! NOTE !!!
        SetV                                 ; YOU NEED TO DEFINE THIS ERROR BLOCK
                                             ; ***********************************
        Return



iic_sendbit
        ; Sends a bit of data
        Push     "R0-R2, R6, R14"

        MOV      R6, R0           ; stash bit in R6
        ; Put the bit out with SCL low
        RSB      R1, R6, #1       ; = (1 - bit)
        ADD      R1, R1, #SCL_LOW
        BL       toggle_printer
        ; With the bit out, bring SCL high
        RSB      R1, R6, #1       ; = (1 - bit)
        ADD      R1, R1, #SCL_HIGH
        BL       toggle_printer

        ; Push SCL low again
        RSB      R1, R6, #1       ; = (1 - bit)
        ADD      R1, R1, #SCL_LOW
        BL       toggle_printer

        Pull     "R0-R2, R6, PC"
