home *** CD-ROM | disk | FTP | other *** search
- ;
- ; Check if a character in input comm buffer
- ;
- MOV AX,[>Async_Buffer_Tail]
- CMP AX,[>Async_Buffer_Head]
- JNE Rec1
- ;
- ; Buffer empty -- begin wait loop.
- ;
- MOV AX,[BP+<Secs] ;Get seconds to wait
- MOV CX,10 ;Shift count = 2 ** 10 = 1024
- SHL AX,CL ;Seconds * 1024 = milleseconds
- MOV CX,AX ;Move to looping register
- ;
- ; Delay for 1 ms.
- ;
- Delay: PUSH CX ;Save milleseconds to go
- MOV CX,[>Async_OneMSDelay] ;Get delay loop value for 1 ms
- Delay1: LOOP Delay1 ;Tight loop for 1 ms delay
- ;
- ; Check if any character yet.
- ;
- POP CX ;Get back millesecond count
- ;
- MOV AX,[>Async_Buffer_Tail]
- CMP AX,[>Async_Buffer_Head]
- JNE Rec1
- ;
- ; Buffer still empty -- decrement elapsed time
- ;
- LOOP Delay ;Decrement millesecond count and loop
- ;
- ; Dropped through -- no character arrived in specified interval.
- ; Return TimeOut as result.
- ;
- MOV BX,>TimeOut ;Pick up timeout value
- LES DI,[BP+<C] ;Get result character address
- ES: MOV [DI],BX ;Store timeout value
- JMP Return ;Return to caller
- ;
- ; Buffer not empty -- pick up next character.
- ;
- Rec1: LES DI,[>Async_Buffer_Ptr] ;Pick up buffer address
- ADD DI,AX ;Add character offset
- ES: MOV BL,[DI] ;Get character from buffer
- ;
- XOR BH,BH ;Clear high-order bits
- LES DI,[BP+<C] ;Get result address
- ES: MOV [DI],BX ;Store character from buffer
- ;
- INC AX ;Increment tail pointer
- CMP AX,[>Async_Buffer_Size] ;Past end of buffer?
- JLE Rec2 ;No -- skip wrapping
- XOR AX,AX ;Yes -- point to start of buffer
- Rec2: MOV [>Async_Buffer_Tail],AX ;Update tail pointer
- DEC Word [>Async_Buffer_Used] ;Update buffer usage count
- ;
- ; If XOFF previously sent because buffer was too full, and
- ; now buffer is reasonably empty, send XON to get things rolling again.
- ;
- TEST BYTE [<Async_XOff_Sent],1 ;Check if Xoff sent
- JZ Return ;No -- skip.
- ;
- MOV AX,[>Async_Buffer_Used] ;Pick up amount of buffer used
- CMP AX,[>Async_Buffer_Low] ;Check if low enough
- JG Return ;Still too full, skip
- ;
- MOV AX,>XON ;Push XON onto stack
- PUSH AX
- CALL FAR [>Async_Send_Addr] ;Call output routine
- ;
- MOV BYTE [>Async_XOff_Sent],0 ;Clear Xoff flag
- ;
- Return: AND Byte [>Async_Line_Status],$FD ;Remove overflow flag
-
-