home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / ASIO.ASM next >
Encoding:
Assembly Source File  |  1990-05-30  |  11.7 KB  |  440 lines

  1.         page    58,132
  2.  
  3. ; asio.asm
  4. ; contains: as_getc(),as_putc(),as_stat(),as_iniw(),as_rts(),as_dtr()
  5. ; contains: as_break(),as_reset()
  6. ;
  7.  
  8.         include    model.h
  9.         include    prologue.h
  10.         name    asio
  11.         pseg    asio
  12.  
  13. ;****
  14. ;  _as_wcts Usage:  This variable's value is transferred in to this
  15. ;  local variable when the asiinit() function is called.  When set to 0,
  16. ;  NO DELAY is taken to wait for CTS or DSR on transmit or receive.  To use
  17. ;  the normal (per delay constants in "asports.h") delay, say _as_wcts=1;
  18. ;  before calling the asiinit() function.
  19.  
  20. as_wcts        dw    0
  21.  
  22. ;==>--    int as_getc(port,timeout)
  23. ;
  24. ;;    ARGUMENTS:
  25. ;      (unsigned)    port    -    base I/O address of 8250
  26. ;      (int)        timeout    -    timeout constant 0=get status once
  27. ;
  28. ;;    DESCRIPTION:
  29. ;      Read character (if available) from comm port
  30. ;
  31. ;;    RETURNS:
  32. ;      Either a character or -1 if (a) no character available, or (b)
  33. ;      there is an error on receive.
  34. ;
  35. ;;    AUTHOR:
  36. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  37. ;
  38. ;;    MODIFICATIONS:
  39. ;
  40. ;;;
  41.     cproc    as_getc
  42.     mov    dx,parm1_    ;get port i/o address base
  43.     add    dx,6        ;address modem status register
  44.     mov    bl,parm2_    ;get timeout constant to BL
  45.     cmp    cs:as_wcts,0
  46.     jz    assk2
  47.     mov    bh,00100000b    ;check for DSR bit
  48.     call    wfs        ;wait for status
  49.     jnz    asgrm1        ;hop if NOT OK
  50. assk2:    dec    dx        ;point to line status register
  51.     mov    bh,000000001b    ;Buffer Full bit
  52.     call    wfs        ;wait for status
  53.     jnz    asgrm1        ;hop if NOT OK
  54.     in    al,dx        ;get status again
  55.     test    al,00011110b    ;see if any errors
  56.     jnz    asgrm1        ;if any, return -1
  57.     mov    dx,parm1_    ;get data reg i/o address
  58.     in    al,dx        ;read the character
  59.     jmp    short asgret
  60. asgrm1:    mov    ax,-1        ;not OK so return -1
  61. asgret:
  62.     cproce
  63.  
  64. ;==>--    int as_putc(port,timeout,character)
  65. ;
  66. ;;    ARGUMENTS:
  67. ;      (unsigned)    port    -    base I/O address of 8250
  68. ;      (int)        timeout -    timeout constant 0=get status once
  69. ;      (char)    character -    character to transmit
  70. ;
  71. ;;    DESCRIPTION:
  72. ;      Transmit the character out the COMM port.
  73. ;
  74. ;;    RETURNS:
  75. ;      Status if successful, -1 if lost CTS or DSR, or if Tx
  76. ;      holding register was not empty.
  77. ;
  78. ;;    AUTHOR:
  79. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved 
  80. ;
  81. ;;    MODIFICATIONS:
  82. ;
  83. ;;;
  84.     cproc    as_putc
  85.     mov    dx,parm1_    ;get port number
  86.     add    dx,6        ;point dx to modem status register
  87.     cmp    cs:as_wcts,0
  88.     jz    assk1
  89.     mov    bl,parm2_    ;bl = timeout
  90.     mov    bh,00110000b    ;DSR, CTS bits
  91.     call    wfs        ;wait for status..
  92.     jnz    asprm1        ;not OK so return -1
  93. assk1:    dec    dx        ;point to line status reg
  94.     mov    bh,00100000b    ;Tx Hold reg empty
  95.     call    wfs        ;wait for status
  96.     jnz    asprm1
  97.     sub    dx,5        ;address data port
  98.     mov    al,@ab+4[bp]    ;get the char to send
  99.     out    dx,al        ;send him
  100.     jmp    short aspret
  101. asprm1:    mov    ax,-1        ; not OK so return -1
  102. aspret:
  103.     cproce
  104.  
  105. ;==>--    unsigned as_stat(port)
  106. ;
  107. ;;    ARGUMENTS:
  108. ;      (unsigned)    port    -    base i/o address of 8250
  109. ;
  110. ;;    DESCRIPTION:
  111. ;      Get line and modem status to AH and AL respectively
  112. ;
  113. ;;    RETURNS:
  114. ;      modem status in high order 8 bits, line status in low
  115. ;      order 8 bits
  116. ;
  117. ;;    AUTHOR:
  118. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  119. ;;;
  120.     cproc    as_stat
  121.     mov    dx,@ab[bp]        ;get i/o addr base
  122.     add    dx,5            ;address line status port
  123.     in    al,dx            ;..and get line status
  124.     jmp    short _fpf3
  125. _fpf3:
  126.     mov    ah,al            ;..to AH
  127.     inc    dx            ;point to modem status port
  128.     in    al,dx            ;get modem status
  129.     cproce
  130.  
  131. ;==>--    int as_iniw(port,baudrate,controlword,aswcts)
  132. ;
  133. ;;    ARGUMENTS:
  134. ;      (unsigned)    port    -    base i/o address of 8250
  135. ;      (int)        baudrate -    baud rate multiplier
  136. ;      (int)        controlword -
  137. ;      (int)        aswcts    -    how long to wait for CTS
  138. ;
  139. ;       bits:  7 6 5 => not used here due to baud multiplier above.
  140. ;         4 3 => parity
  141. ;           2 => stopbits: 0=1 1=2
  142. ;         1 0 => word length: 10 = 7, 11 = 8
  143. ;
  144. ;;    DESCRIPTION:
  145. ;      Initialize Port - Worker.  Drive from "asinit"
  146. ;
  147. ;;    SIDE EFFECTS:
  148. ;      operating parameters of 8250 will be changed
  149. ;
  150. ;;    RETURNS:
  151. ;      status or -1 if argument is out of range
  152. ;
  153. ;;    AUTHOR:
  154. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  155. ;;;
  156.     cproc    as_iniw
  157.     mov    ax,@ab+6[bp]    ;get value of _as_wcts
  158.     mov    cs:as_wcts,ax
  159.     mov    dx,@ab[bp]    ;get port i/o address base
  160.     add    dx,3        ;address 8250 control register
  161.     mov    al,80h        ;set DLAB = 1
  162.     out    dx,al        ;..to enable loading the baud rate
  163.     jmp    short _fpf4
  164. _fpf4:
  165.     mov    ax,@ab+2[bp]    ;get baud multiplier
  166.     mov    dx,@ab[bp]    ;get port i/o address base = LSB
  167.     out    dx,al        ;Least Significant Byte here
  168.     jmp    short _fpf5
  169. _fpf5:
  170.     inc    dx        ;point to MSB latch
  171.     mov    al,ah        ;.put MSB in AL
  172.     out    dx,al        ;..and output that
  173.     jmp    short _fpf6
  174. _fpf6:
  175.     inc    dx
  176.     inc    dx        ;point to line control register
  177.     mov    ax,@ab+4[bp]    ;get control word to AL
  178.     and    al,00111111b    ;turn off DLAB, break, stick_parity
  179.     out    dx,al        ;..initialize word_length,stop_bits,parity
  180.     jmp    short _fpf7
  181. _fpf7:
  182.     dec    dx
  183.     dec    dx        ;point to interrupt enable register
  184.     sub    al,al        ;get a 0
  185.     out    dx,al        ;set int enables all off
  186.     jmp    short _fpf8
  187. _fpf8:
  188.     add    dx,4        ;point to line status register
  189.     in    al,dx        ;get line status
  190.     jmp    short _fpf9
  191. _fpf9:
  192.     mov    ah,al        ;..to AH
  193.     inc    dx        ;point to modem status reg
  194.     in    al,dx        ;...get that to AL
  195.     cproce
  196.  
  197. ;==>--    void as_rts(port,control)
  198. ;
  199. ;;    ARGUMENTS:
  200. ;      (unsigned)    port    -    Base I/O address of 8250
  201. ;      (int)        control    -    1=Assert RTS, 0=Deassert RTS
  202. ;
  203. ;;    DESCRIPTION:
  204. ;      Function to control RTS
  205. ;
  206. ;;    SIDE EFFECTS:
  207. ;      rts will change
  208. ;
  209. ;;    AUTHOR:
  210. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  211. ;;;
  212.     cproc    as_rts
  213.     mov    dx,@ab[bp]    ;get port i/o base address
  214.     add    dx,4        ;address modem control register
  215.     in    al,dx        ;read current command
  216.     mov    bx,@ab+2[bp]    ;get control argument
  217.     cmp    bx,1        ;is it ON ?
  218.     jne    asrts0        ;hop if OFF instead
  219.     or    al,2        ;set the RTS bit
  220.     jmp     short    asrtsw        ;now write modified command
  221.                 ;back to the modem ctrl register
  222. asrts0:    and    al,11111101b    ;turn OFF the RTS bit here.
  223. asrtsw:    out    dx,al        ;update command to device
  224.     cproce
  225.  
  226. ;==>--    void as_dtr(port,control)
  227. ;
  228. ;;    ARGUMENTS:
  229. ;      (unsigned)    port    -    base I/O address of 8250
  230. ;      (int)        control    -    1=Assert DTR, 0=DeAssert DTR
  231. ;
  232. ;;    DESCRIPTION:
  233. ;      Control state of DTR signal
  234. ;
  235. ;;    SIDE EFFECTS:
  236. ;      DTR signal will change
  237. ;
  238. ;;    AUTHOR:
  239. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  240. ;;;
  241.     cproc    as_dtr
  242.     mov    dx,@ab[bp]
  243.     add    dx,4        ;address modem ctrl reg
  244.     in    al,dx        ;read current command
  245.     mov    bx,@ab+2[bp]    ;get control argument
  246.     cmp    bx,1        ;is it ON ?
  247.     jne    asdtr0        ;nop if OFF instead
  248.     or    al,1        ;set the DTR bit
  249.     jmp     short    asdtrw        ;now write modified command
  250. asdtr0:    and    al,11111110b    ;turn DTR OFF.
  251. asdtrw:    out    dx,al        ;write updated command
  252.     cproce
  253.  
  254. ;==>--    int as_break(port,timeout)
  255. ;
  256. ;;    ARGUMENTS:
  257. ;      (unsigned)    port    -    base I/O address of 8250
  258. ;      (int)        timeout    -    multiple of 1ms
  259. ;
  260. ;;    DESCRIPTION:
  261. ;
  262. ;        Send break of duration 200 milliseconds.  If it is desired to change
  263. ;       this period, the user may, within the range 1-32768 ms, change as
  264. ;       indicated below.
  265. ;
  266. ;      Timeout argument is multiple of 1 ms to use for initial status - if
  267. ;      DSR and RTS are not high initially, wait this long for them to be 
  268. ;      high, if not found high within timeout period, return (-1).  
  269. ;      Else return 0.
  270. ;
  271. ;;    RETURNS:
  272. ;      (see description)
  273. ;
  274. ;;    AUTHOR:
  275. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  276. ;;;
  277.     cproc    as_break
  278.     mov    dx,@ab[bp]    ;get port address base
  279.     add    dx,6        ;point to modem status reg
  280.     mov    bx,@ab+2[bp]    ;get write timeout constant
  281.     mov    bh,00110000b    ;DSR and CTS bits
  282.     call    wfs        ;wait for status..
  283.     jz    asbrk1        ;OK so proceed
  284.     mov    ax,-1        ;NOT OK, return -1
  285.     pop    bp
  286.     ret
  287. asbrk1:    mov    dx,@ab[bp]    ;get port address base
  288.     add    dx,3        ;address line control reg
  289.     in    al,dx        ;get current line ctrl word
  290.     jmp    short _fpf10
  291. _fpf10:
  292.     mov    ah,al        ;store this for later..
  293.     push    ax
  294.     or    al,01000000b    ;set BREAK, xmit spacing..
  295.     out    dx,al        ;update control word.
  296.     mov    bx,128        ;load multiple of 1 ms.
  297. asbrk2:    call    asbdly        ;go delay 1 ms.
  298.     dec    bx        ;decrement multiplier
  299.     jnz    asbrk2        ;loop while not zero multiplier
  300.     mov    al,ah        ;get original command word
  301.     pop    ax
  302.     out    dx,al        ;..turn BREAK off now.
  303.     cproce
  304.  
  305. ;==>--    void as_reset(port)
  306. ;
  307. ;;    ARGUMENTS:
  308. ;      (unsigned)    port    -    base I/O address of 8250
  309. ;
  310. ;;    DESCRIPTION:
  311. ;      Reset an 8250 to quiescent state with 300 baud, odd parity,
  312. ;      1 stop-bit, 8 data bits, DTR and RTS OFF.
  313. ;
  314. ;;    SIDE EFFECTS:
  315. ;      internal 8250 settings will be changed
  316. ;
  317. ;;    AUTHOR:
  318. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  319. ;;;
  320.     cproc    as_reset
  321.     mov    dx,@ab[bp]    ;get port i/o base address
  322.     add    dx,4        ;point to modem control reg
  323.     mov    al,0        ;turn off all bits..
  324.     out    dx,al        ;do it.
  325.     jmp    short _fpf11
  326. _fpf11:    
  327.     dec    dx        ;point to line control reg
  328.     mov    al,00001011b    ;odd parity, 1 stop bit, 8 data bits
  329.     out    dx,al
  330.     jmp    short _fpf12
  331. _fpf12:
  332.     mov    al,10001011b    ;turn on DLAB = 1
  333.     out    dx,al
  334.     jmp    short _fpf13
  335. _fpf13:
  336.     mov    dx,@ab[bp]    ;address LSB reg for divisor
  337.     mov    ax,384        ;divisor for 300 bps
  338.     out    dx,al
  339.     jmp    short _fpf14
  340. _fpf14:
  341.     mov    al,ah        ;get MSB for 300 bps
  342.     inc    dx        ;point to MSB register
  343.     out    dx,al
  344.     jmp    short _fpf15
  345. _fpf15:
  346.     inc    dx
  347.     inc    dx        ;point to line control reg again
  348.     mov    al,00001011b    ;be kind - turn off DLAB bit.
  349.     out    dx,al
  350.     cproce
  351.  
  352.  
  353. ;********************
  354. ;
  355. ;  Wait for Status.
  356. ;
  357. ;  Input:    Physical Port address in DX
  358. ;        BL = number of iterations before timeout
  359. ;        BH = status bits to match
  360. ; Output:    AH = last status read
  361. ;        Zero Flag set if timeout occurred
  362. ;
  363. ;  Depending upon the time constant (TC) stored at _rswtc[n], this function
  364. ;  will wait a certain number of iterations in a loop waiting for a match
  365. ;  between the status obtained from physical port DX and the bits in BH.
  366. ;
  367. ;  However, if (global) _as_wcts = 0, do not wait at all.
  368. ;
  369. ;  If TC = 0, return with Zero Flag ON if match on status, else OFF
  370. ;  If match found between status read and BH, return Zero Flag ON
  371. ;  If iterations exahsted and no match on status, return Zero Flag OFF
  372.  
  373. wfs    proc    near
  374.     push    bx        ;preserve this
  375.     cmp    cs:as_wcts,0        ; *5/31*
  376.     jnz    wfscx        ;if no override on wait *5/31*
  377.     mov    bl,0        ;else just get status and return *5/31*    
  378. wfscx:    call    wfsx
  379.     pop    bx        ;restore time constant and mask
  380.     ret
  381. wfs    endp
  382.  
  383. ;***********
  384. ;
  385. ;  Alternate "Wait-For-Status" routine
  386. ;
  387. wfsx     proc     near
  388.     cmp    bl,0        ;is loop count zero ?
  389.     jne    wfsxst        ;if not do the loop
  390.     in    al,dx        ;read status
  391.     mov    ah,al        ;position for output
  392.     and    al,bh        ;check these bits
  393.     cmp    al,bh        ; just like this
  394.     ret            ;indicate status to caller.
  395. ;
  396. ; Nonzero Time Constant, so return only after status match or timeout
  397. ;
  398. ;  For 4.77 mhz clock, inner loop is 37 clocks @ 210 ns = 7.75 usec;
  399. ;  ..129 x 7.75 = 1000 usec = 1 msec per external time constant.
  400. ;
  401. wfsxst:
  402. wfsx0:    mov    cx,129        ;inner loop count
  403. wfsx1:    in    al,dx        ;read status
  404.     jmp    short _fpf16    ;*5/31*
  405. _fpf16:
  406.     mov    ah,al        ;position it for output
  407.     and    al,bh        ;check these bits
  408.     cmp    al,bh        ;just as they are
  409.     je    wfsxe        ; and hop out if status same
  410.     loop    wfsx1        ;  else do inner loop here
  411.     dec    bl        ;  ..now do outer loop
  412.     jnz    wfsx0        ;   ..here
  413. ;If you get here you have a timeout with no status match.
  414.     or    bh,bh        ;set Zero Flag OFF
  415. wfsxe:    ret
  416. wfsx     endp
  417.  
  418.  
  419. ;**********
  420. ;
  421. ;  Delay 1 ms.  This is used in as_break to time the break
  422. ;
  423. asbdly    proc    near
  424.     push    cx
  425. ;
  426. ;  The instructions at absdl1 and absdl2 together use 33 clock periods
  427. ;  if the loop transfers back up to absdl1.  In the IBM PC, each clock
  428. ;  period is 210 ns, so each time thru the loop is 6.93 usec.  To delay
  429. ;  a total of about 1 millisecond, do this 144 times.
  430. ;
  431. asbdl0: mov    cx,144
  432. asbdl1:    jmp     short    asbdl2        ;15 clocks
  433.     nop            ;never get here.. for clarity only.
  434. asbdl2:    loop    asbdl1        ;18 clocks if CX not 0 yet
  435.     pop    cx        ;done ! Restore this and exit
  436.     ret
  437. asbdly    endp
  438.     endps
  439.     end
  440.