home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / modem / suncom.zip / TPZASYNC.PAS < prev    next >
Pascal/Delphi Source File  |  1990-01-18  |  5KB  |  153 lines

  1. UNIT TpzAsync;
  2. (* Modem interface routines for Turbo Pascal Zmodem *)
  3. (* (c)1988 by J.R.Louvau                            *)
  4. (* You will need a copy of PIBASYN45 to compile     *)
  5. (* this unit.                                       *)
  6. INTERFACE
  7. USES Dos, PibAsync, PibTimer, GlobType;
  8.  
  9. FUNCTION Z_AsyncOn(zport: WORD; zbaud: LONGINT): BOOLEAN;
  10. PROCEDURE Z_AsyncOff;
  11. FUNCTION Z_CharAvail: BOOLEAN;
  12. PROCEDURE Z_ClearInbound;
  13. PROCEDURE Z_FlushOutbound;
  14. PROCEDURE Z_ClearOutbound;
  15. PROCEDURE Z_SendBreak;
  16. FUNCTION Z_ReceiveByte: INTEGER;
  17. PROCEDURE Z_SendByte(b: BYTE);
  18. FUNCTION Z_Carrier: BOOLEAN;
  19.  
  20. IMPLEMENTATION
  21.  
  22. FUNCTION Z_CharAvail: BOOLEAN;
  23. (* See if there is a character coming in *)
  24. BEGIN
  25.    Z_CharAvail := Async_Buffer_Check
  26. END;
  27.  
  28. PROCEDURE Z_ClearInbound;
  29. (* Throw away any pending input to clear the line *)
  30. VAR
  31.    n: INTEGER;
  32. BEGIN
  33.    WHILE (Async_Carrier_Detect) AND (Async_Buffer_Check) DO
  34.       Async_Receive_With_Timeout(1,n)
  35. END;
  36.  
  37. PROCEDURE Z_ClearOutbound;
  38. (* Throw away any pending output in the buffer *)
  39. BEGIN
  40.    Async_Flush_Output_Buffer
  41. END;
  42.  
  43. PROCEDURE Z_FlushOutbound;
  44. BEGIN
  45.    REPEAT UNTIL (NOT Async_Carrier_Detect) OR
  46.                 (Async_OBuffer_Head = Async_OBuffer_Tail)
  47. END;
  48.  
  49. PROCEDURE Z_SendBreak;
  50. (* Send a break signal *)
  51. BEGIN
  52.    Async_Send_Break
  53. END;
  54.  
  55. PROCEDURE Z_SendByte(b: BYTE);
  56. (* Output one byte *)
  57. BEGIN
  58.    Async_Send(Chr(b))
  59. END;
  60.  
  61. FUNCTION Z_ReceiveByte: INTEGER;
  62. (* Input one byte (N.B.: RETURNS AN INTEGER!) *)
  63. VAR
  64.    n: INTEGER;
  65. BEGIN
  66.    Async_Receive_With_Timeout(0,n);
  67.    Z_ReceiveByte := (n AND $00FF)
  68. END;
  69.  
  70. FUNCTION Z_Carrier: BOOLEAN;
  71. (* Checks for the presence of a carrier *)
  72. BEGIN
  73.    Z_Carrier := (Async_Carrier_Detect)
  74. END;
  75.  
  76. PROCEDURE Z_AsyncOff;
  77. VAR
  78.    I : INTEGER;
  79.    M : INTEGER;
  80. BEGIN  (* Async_Close *)
  81.                    (* Read the RBR and reset any pending error conditions. *)
  82.                    (* First turn off the Divisor Access Latch Bit to allow *)
  83.                    (* access to RBR, etc.                                  *)
  84.    INLINE($FA);  (* disable interrupts *)
  85.    Port[UART_LCR + Async_Base] := Port[UART_LCR + Async_Base] AND $7F;
  86.                    (* Read the Line Status Register to reset any errors *)
  87.                    (* it indicates                                      *)
  88.    I := Port[UART_LSR + Async_Base];
  89.                    (* Read the Receiver Buffer Register in case it *)
  90.                    (* contains a character                         *)
  91.    I := Port[UART_RBR + Async_Base];
  92.                          (* enable the irq on the 8259 controller *)
  93.    I := Port[8088];  (* get the interrupt mask register *)
  94.    M := (1 SHL Async_Irq) XOR $00FF;
  95.    Port[8088] := I AND M;
  96.                    (* enable OUT2 on 8250 *)
  97.    I := Port[UART_MCR + Async_Base];
  98.    Port[UART_MCR + Async_Base] := I OR $0B;
  99.                    (* enable the data ready interrupt on the 8250 *)
  100.    Port[UART_IER + Async_Base] := $0F;
  101.                    (* Re-enable 8259 *)
  102.    Port[$20] := $20;
  103.    INLINE($FB); (* enable interrupts *)
  104.    IF Async_Open_Flag THEN
  105.       BEGIN
  106.                      (* disable the IRQ on the 8259 *)
  107.          INLINE($FA);                 (* disable interrupts *)
  108.          I := Port[8088];        (* get the interrupt mask register *)
  109.          M := 1 SHL Async_Irq;        (* set mask to turn off interrupt  *)
  110.          Port[8088] := I OR M;
  111.                      (* disable the 8250 interrupts *)
  112.          Port[UART_IER + Async_Base] := 0;
  113.                      (* Disable OUT2, RTS, OUT1 on the 8250, but *)
  114.                      (* possibly leave DTR enabled.              *)
  115.          Port[UART_MCR + Async_Base] := 1;
  116.          INLINE($FB);                 (* enable interrupts *)
  117.                      (* re-initialize our data areas so we know *)
  118.                      (* the port is closed                      *)
  119.          Async_Open_Flag := FALSE;
  120.          Async_XOFF_Sent := FALSE;
  121.                      (* Restore the previous interrupt pointers *)
  122.          SetIntVec( Async_Irq + 8 , Async_Save_Iaddr );
  123.             I := Port[UART_LSR + Async_Base];
  124.                 (* Read the Receiver Buffer Register in case it *)
  125.                 (* contains a character                         *)
  126.          I := Port[UART_RBR + Async_Base];
  127.              (* enable the irq on the 8259 controller *)
  128.          I := Port[8088];  (* get the interrupt mask register *)
  129.          M := (1 SHL Async_Irq) XOR $00FF;
  130.          Port[8088] := I AND M;
  131.             (* enable OUT2 on 8250 *)
  132.          I := Port[UART_MCR + Async_Base];
  133.          Port[UART_MCR + Async_Base] := I OR $0B;
  134.             (* enable the data ready interrupt on the 8250 *)
  135.          Port[UART_IER + Async_Base] := $0F;
  136.             (* Re-enable 8259 *)
  137.          Port[$20] := $20;
  138.          INLINE($FB); (* enable interrupts *)
  139.       END;
  140. END    (* Async_Close *);
  141.  
  142. FUNCTION Z_AsyncOn(zport: WORD; zbaud: LONGINT): BOOLEAN;
  143. BEGIN
  144.    Async_Do_CTS := FALSE;
  145.    Async_Do_DSR := FALSE;
  146.    Async_Do_XonXoff := FALSE;
  147.    Async_Hard_Wired_On := FALSE;
  148.    Async_Break_Length := 500;
  149.    Async_Init(2048,2048,0,0,0);
  150.    Z_AsyncOn := Async_Open(zport,zbaud,'N',8,1)
  151. END;
  152. END.
  153.