;
; LetGo.asm
;
; Reads from parallel port until detects a quiescent state.
;
        csect text

	xdef _LetGo

        xref _ciab
        xref _NSamples

        xref _Forbid
        xref _Disable
        xref _Enable
        xref _Permit

data1             equ   $bfe101
dir1              equ   $bfe301

_LetGo
;
; Save registers on stack.
;
         MOVEM.L A2-A6/D2-D7,-(SP)  ;  Push Registers 
;
; Set up parallel port for reading.
;
         move.b   #0,dir1           * all lines read
         move.b   #0,data1
;
; Read from parallel port until see no change for 10000 cycles.
;
again:  move.l   #$2710,_NSamples  ; Initialize the counter to BIG.
                                   ; FFF0 * .1397us/clock * 50 clocks = .5sec
        move.l   #0,d1             ; Zero the detection flag.

loop:   move.b   data1,d0          ; Move byte from parallel port to buffer.
        andi.b   #1,d0             ; Mask off bit of interest.
        bne      over
        addq.l   #$1,d1            ; Found a zero = still getting signal.
over:   subq.l   #$1,_NSamples     ; Decrement counter.
        bne      loop              ; Loop if haven't done 10000 yet.

        tst.l    d1                ; Still receiving signal?
        bne      again
;
; Clean up, restore registers and return.
;
        MOVEM.L (SP)+,A2-A6/D2-D7  ;  Pop Registers
        RTS

        END
