        ORG 015#000


READ210:			; main read routine
        LCI 060

MOTR002:
        LAI 300		; start motor
        OUT 015
 

; delay after motor start
	CAL TIME132

RNXT215:
        CAL RBYT312		; read MS nibble
        JFP RPER305		; check parity
        LDA
        CAL RBYT312		; read LS nibble
        JFP RPER305		; check parity
        NDI 017			; save data
        LEA
        LBD
        LAD
        RLC			; shift
        RLC
        RLC
        RLC
        NDI 360			; remove SL nibble
        ADE
        LDA
        LAB
        NDI 160
        JTZ READ276		; save to memory and continue
        RLC
        RLC
        JFC READ266		; page or low address
        LHD			; page address
        JMP RNXT215

READ266:			; low address
        RLC
        JFC REND307
        LLD
        JMP RNXT215

READ276:			; save to memory
        LMD
INHL204:			 ; Increment HL
        INL
        JFZ RNXT215
        INH
        JMP RNXT215		; read next

RPER305:			; parity error
        LCI 377
REND307:			; end - stop motor
        XRA
        OUT 015
        JMP 017#000             ; return to monitor

RBYT312:
        LEI 000
        CAL RNIB326		; read 4 LS bits
        CAL RNIB326		; read 4 MS bits
        LAE
        RAL
        NDA
        RET			; return flags and data in ACC

RNIB326:			; read a nibble
        LCI 004
RNIB330:
        INP 003			; wait for high bit
        NDA
        JFS RNIB330
        INP 003			; double check
        NDA
        JFS RNIB330
        LBI 037			; 1.5 bit delay
        CAL TIME142
RNIB347:
        INP 003			; check bit
        NDI 200
        ADE			; add to previous bits
        RAR
        LEA
        LBI 024			; 1 bit delay
        CAL TIME142
        DCC			; all 4 bits present?
        RTZ			; yes, return
        JMP RNIB347

TIME132:
        CAL TIME142
        DCC
        JFZ TIME132
        RET

TIME142:
        DCB
        JFZ TIME142
        RET




