home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / jr_tools / jrcom201.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-07-15  |  5.4 KB  |  181 lines

  1. Unit JRCOM201 ;
  2.  
  3. (*╔═════════════════════════════════════════════════════════════════════════╗*)
  4. (*║                                                                         ║*)
  5. (*║             JR Unit Library  -  Version 2.01  -  June xxrd 1988         ║*)
  6. (*║                                                                         ║*)
  7. (*║                   Serial port functions and procedures                  ║*)
  8. (*║                                                                         ║*)
  9. (*╚═════════════════════════════════════════════════════════════════════════╝*)
  10.  
  11. Interface
  12.  
  13. (*───────────────────────────────────────────────────────────────────────────*)
  14.  
  15. Uses Dos , JRBIT201  ;
  16.  
  17. (*───────────────────────────────────────────────────────────────────────────*)
  18.  
  19. Const _BIOSSerialService   = $14 ;
  20.  
  21.  
  22.       _COM1 = 0 ; _COM2 = 1 ;
  23.  
  24.        _110baud = $00 ;  _150baud = $20 ;  _300baud = $40 ;  _600baud = $60 ;
  25.       _1200baud = $80 ; _2400baud = $A0 ; _4800baud = $C0 ; _9600baud = $E0 ;
  26.  
  27.       _none = $00 ; _odd  = $08 ; _even = $18 ;
  28.  
  29.       _one = $00 ; _two = $04 ;
  30.  
  31.       _7bit = $02 ; _8bit = $03 ;
  32.  
  33.       _on = 1 ; _off = 0 ;
  34.  
  35.       _portadr : Array(.0..1.) Of Word = ($3F8,$2F8) ;
  36.  
  37. (*───────────────────────────────────────────────────────────────────────────*)
  38.  
  39. Var   _regs8086    : Registers ;
  40.  
  41. (*───────────────────────────────────────────────────────────────────────────*)
  42.  
  43. Procedure _InitComPort(_portnr   , _baudrate , _parity ,
  44.                         _stopbit  , _charsize  : Byte ;
  45.                         Var _error : Integer) ;
  46. Procedure _Send1Char(_portnr     : Word ;
  47.                       _char       : Char ;
  48.                       Var _error  : Byte) ;
  49. Procedure _Read1Char(_portnr     : Word ;
  50.                       Var _char   : Char ;
  51.                       Var _error  : Byte) ;
  52. Function  _SerialPortStatus(_portnr : Word) : Integer ;
  53. Procedure _SetDTR(_portnr,_mode : Word) ;
  54. Procedure _SetRTS(_portnr,_mode : Word) ;
  55. Function  _CTS(_portnr : Word) : Boolean ;
  56. Function  _DSR(_portnr : Word) : Boolean ;
  57. Function  _RI(_portnr : Word) : Boolean ;
  58. Function  _CD(_portnr : Word) : Boolean ;
  59.  
  60.  
  61. (*───────────────────────────────────────────────────────────────────────────*)
  62.  
  63. Implementation
  64.  
  65. (*───────────────────────────────────────────────────────────────────────────*)
  66.  
  67. Procedure _InitComPort ;
  68. (*  Version 1.01  *)
  69. (*  Modified 1.02 *)
  70. Begin ;
  71.    With _regs8086 Do Begin ;
  72.       ah:=0 ; dx:=_portnr ;
  73.       al:=_baudrate Or _parity Or _stopbit Or _charsize ;
  74.    End ;
  75.    Intr(_BIOSSerialService,_regs8086) ;
  76.    _error:=_regs8086.ax ;
  77. End  (* Procedure _InitComPort *) ;
  78.  
  79. (*───────────────────────────────────────────────────────────────────────────*)
  80.  
  81. Procedure _Send1Char ;
  82. (*  Version 1.02 *)
  83. (*  Ej kollad    *)
  84. Begin ;
  85.    With _regs8086 Do Begin ;
  86.       ah:=1 ;           (* Service 1            *)
  87.       al:=Ord(_char) ; (* Character to be send *)
  88.       dx:=_portnr ;    (* Define com port      *)
  89.    End ;
  90.    Intr(_BIOSSerialService,_regs8086) ;
  91.    _error:=_regs8086.ah ;
  92. End  (* Procedure Send1Char *) ;
  93.  
  94. (*───────────────────────────────────────────────────────────────────────────*)
  95.  
  96. Procedure _Read1Char ;
  97. (*  Version 1.02 *)
  98. (*  Ej kollad    *)
  99. Begin ;
  100.    With _regs8086 Do Begin ;
  101.       ah:=2 ;           (* Service 2            *)
  102.       dx:=_portnr ;    (* Define com port      *)
  103.    End ;
  104.    Intr(_BIOSSerialService,_regs8086) ;
  105.    _char:=Chr(_regs8086.al) ;
  106.    _error:=_regs8086.ah ;
  107. End  (* Procedure Read1Char *) ;
  108.  
  109. (*───────────────────────────────────────────────────────────────────────────*)
  110.  
  111. Function _SerialPortStatus ;
  112. (*  Version  1.01 *)
  113. (*  Modified 1.02 *)
  114. Begin ;
  115.    With _regs8086 Do Begin ;
  116.       ah:=3 ; dx:=_portnr ;
  117.    End ;
  118.    Intr(_BIOSSerialService,_regs8086) ;
  119.    _SerialPortStatus:=_regs8086.ax ;
  120. End  (* Function _SerialPortStatus *) ;
  121.  
  122.  
  123. (*───────────────────────────────────────────────────────────────────────────*)
  124.  
  125. Procedure _SetDTR ;
  126. (*  Version 2.01 *)
  127. Var _b : Byte ;
  128. Begin ;
  129.    _b:=Port(._portadr(._portnr.)+5.) ;
  130.    If (_mode=_on) Then _SetBit(_b,0) Else _ResetBit(_b,0) ;
  131.    Port(._portadr(._portnr.)+5.):=_b ;
  132. End  (* Procedure _SetDTR *) ;
  133.  
  134. (*───────────────────────────────────────────────────────────────────────────*)
  135.  
  136. Procedure _SetRTS ;
  137. (*  Version 2.01 *)
  138. Var _b : Byte ;
  139. Begin ;
  140.    _b:=Port(._portadr(._portnr.)+5.) ;
  141.    If (_mode=_on) Then _SetBit(_b,1) Else _ResetBit(_b,1) ;
  142.    Port(._portadr(._portnr.)+5.):=_b ;
  143. End  (* Procedure _SetRTS *) ;
  144.  
  145. (*───────────────────────────────────────────────────────────────────────────*)
  146.  
  147. Function _CTS ;
  148. (*  Version 2.01 *)
  149. Begin ;
  150.    _CTS:=_Bit(Port(._portadr(._portnr.)+6.),4) ;
  151. End  (* Function _CTS *) ;
  152.  
  153. (*───────────────────────────────────────────────────────────────────────────*)
  154.  
  155. Function _DSR ;
  156. (*  Version 2.01 *)
  157. Begin ;
  158.    _DSR:=_Bit(Port(._portadr(._portnr.)+6.),5) ;
  159. End  (* Function _DSR *) ;
  160.  
  161. (*───────────────────────────────────────────────────────────────────────────*)
  162.  
  163. Function _RI ;
  164. (*  Version 2.01 *)
  165. Begin ;
  166.    _RI:=_Bit(Port(._portadr(._portnr.)+6.),6) ;
  167. End  (* Function _RI *) ;
  168.  
  169. (*───────────────────────────────────────────────────────────────────────────*)
  170.  
  171. Function _CD ;
  172. (*  Version 2.01 *)
  173. Var _b : Byte ;
  174. Begin ;
  175.    _CD:=_Bit(Port(._portadr(._portnr.)+6.),7) ;
  176. End  (* Function _CD *) ;
  177.  
  178. (*───────────────────────────────────────────────────────────────────────────*)
  179.  
  180. End  (* Of Unit JRCOM201 *).
  181.