home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / pibasy.zip / TIMEREC.ASM < prev   
Assembly Source File  |  1987-11-11  |  3KB  |  76 lines

  1. ;
  2. ;  Check if a character in input comm buffer
  3. ;
  4.          MOV   AX,[>Async_Buffer_Tail]
  5.          CMP   AX,[>Async_Buffer_Head]
  6.          JNE   Rec1
  7. ;
  8. ;  Buffer empty -- begin wait loop.
  9. ;
  10.          MOV   AX,[BP+<Secs]                 ;Get seconds to wait
  11.          MOV   CX,10                         ;Shift count = 2 ** 10 = 1024
  12.          SHL   AX,CL                         ;Seconds * 1024 = milleseconds
  13.          MOV   CX,AX                         ;Move to looping register
  14. ;
  15. ;  Delay for 1 ms.
  16. ;
  17. Delay:   PUSH  CX                            ;Save milleseconds to go
  18.          MOV   CX,[>Async_OneMSDelay]        ;Get delay loop value for 1 ms
  19. Delay1:  LOOP  Delay1                        ;Tight loop for 1 ms delay
  20. ;
  21. ;  Check if any character yet.
  22. ;
  23.          POP   CX                            ;Get back millesecond count
  24. ;
  25.          MOV   AX,[>Async_Buffer_Tail]
  26.          CMP   AX,[>Async_Buffer_Head]
  27.          JNE   Rec1
  28. ;
  29. ;  Buffer still empty -- decrement elapsed time
  30. ;
  31.          LOOP  Delay                         ;Decrement millesecond count and loop
  32. ;
  33. ;  Dropped through -- no character arrived in specified interval.
  34. ;  Return TimeOut as result.
  35. ;
  36.          MOV   BX,>TimeOut                   ;Pick up timeout value
  37.          LES   DI,[BP+<C]                    ;Get result character address
  38.     ES:  MOV   [DI],BX                       ;Store timeout value
  39.          JMP   Return                        ;Return to caller
  40. ;
  41. ;  Buffer not empty -- pick up next character.
  42. ;
  43. Rec1:    LES   DI,[>Async_Buffer_Ptr]        ;Pick up buffer address
  44.          ADD   DI,AX                         ;Add character offset
  45.      ES: MOV   BL,[DI]                       ;Get character from buffer
  46. ;
  47.          XOR   BH,BH                         ;Clear high-order bits
  48.          LES   DI,[BP+<C]                    ;Get result address
  49.      ES: MOV   [DI],BX                       ;Store character from buffer
  50. ;
  51.          INC   AX                            ;Increment tail pointer
  52.          CMP   AX,[>Async_Buffer_Size]       ;Past end of buffer?
  53.          JLE   Rec2                          ;No -- skip wrapping
  54.          XOR   AX,AX                         ;Yes -- point to start of buffer
  55. Rec2:    MOV   [>Async_Buffer_Tail],AX       ;Update tail pointer
  56.          DEC   Word [>Async_Buffer_Used]     ;Update buffer usage count
  57. ;
  58. ; If XOFF previously sent because buffer was too full, and
  59. ; now buffer is reasonably empty, send XON to get things rolling again.
  60. ;
  61.          TEST  BYTE [<Async_XOff_Sent],1     ;Check if Xoff sent
  62.          JZ    Return                        ;No -- skip.
  63. ;
  64.          MOV   AX,[>Async_Buffer_Used]       ;Pick up amount of buffer used
  65.          CMP   AX,[>Async_Buffer_Low]        ;Check if low enough
  66.          JG    Return                        ;Still too full, skip
  67. ;
  68.          MOV   AX,>XON                       ;Push XON onto stack
  69.          PUSH  AX
  70.          CALL  FAR [>Async_Send_Addr]        ;Call output routine
  71. ;
  72.          MOV   BYTE [>Async_XOff_Sent],0     ;Clear Xoff flag
  73. ;
  74. Return:  AND   Byte [>Async_Line_Status],$FD ;Remove overflow flag
  75.  
  76.