; 4-bit parallel codes.
CO_ACK equ 1010b ; yes; acknowledge
CO_NAK equ 1100b ; no; negative acknowledge
CO_ENQ equ 0101b ; enquire; are you there?
CO_RTS equ 1101b ; request to send
CO_STX equ 0110b ; start transmission block
CO_ABT equ 1001b ; abort current transmission/reception
CO_IDL equ 0000b ; idle--no state
CO_TXC equ 1110b ; transmission check
CO_STB equ 10000b ; strobe
; Status port output values.
PST_IDLE equ 0 ; idle
PST_ACK equ 1 ; acknowledge
PST_RCV_ERROR equ 2 ; receive error
PST_RFD equ 4 ; request for data/response
PST_RTS equ 8 ; assert request to send
PST_STROBE equ 16 ; strobe on control port
;* GetByte - Receive a byte.
; -------------------------
;
; Returns it as AX - 00 vv
; if error, returns AX = ee 00
;
; Note that this operates on both the leading and trailing edge of
; the strobe pulse.
;
GetByte proc near private uses dx bx
mov TimeOut,TIME_BYTE
mov dx,pport
; Wait for strobe to go low, grab the nibble.
inc dx
GetByte6:
in al,dx
cmp TimeOut,0 ; see if error
je GetByte18 ; if timeout, quit
test al,(PST_STROBE shl 3)
jnz GetByte6 ; keep looping
mov ah,al
in al,dx
cmp ah,al ; see if match
jne GetByte6 ; if not stable
GetByte8:
dec dx ; back to data
mov bh,al
shr bh,1
shr bh,1
shr bh,1
and bh,15 ; isolate low nibble
mov al,PST_STROBE + PST_ACK
out dx,al ; respond with a strobe
; Okay, now for the high nibble. Wait for the strobe to go high.
inc dx
GetByte10:
in al,dx
cmp TimeOut,0 ; see if error
je GetByte18 ; if timeout, quit
test al,(PST_STROBE shl 3)
jz GetByte10 ; keep looping
mov ah,al
in al,dx
cmp ah,al ; see if match
jne GetByte10 ; if not stable
shl al,1
and al,0f0h ; isolate upper nibble
or bh,al ; form a word
dec dx
mov al,PST_IDLE
out dx,al ; acknowldege the pulse
mov TimeOut,0
xor ah,ah
mov al,bh
GetByte16:
ret ; all done with this one
; Timeout error - Return an ER_TIME
GetByte18:
call _IdlePort ; go to idle status
mov ax,(ER_TIME shl 8)
jmp GetByte16 ; exit
GetByte endp