home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / misc1 / db-comm.lzh / INPORT.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-10-09  |  5.2 KB  |  298 lines

  1.  
  2.     page    66, 120
  3.     title     DBASE III+ Com Port Handler V1.0
  4.     subttl    By Carl R. Weber
  5.  
  6. IF1
  7.     %out    Pass 1
  8. ENDIF
  9. IF2
  10.     %out    Pass 2
  11. ENDIF
  12.  
  13. ;
  14. ;====================================
  15. ;
  16. ;    Get a string of characters from the com port
  17. ;    terminated by a Carriage Return or the end of string
  18. ;    The number of characters received is the length of the
  19. ;    Dbase III+ string passed.
  20. ;    A single character may be obtained if this routine is called
  21. ;    with a string whose length is one.
  22. ;
  23. ;    return ffh if no carrier 
  24. ;    return feh if activity timeout
  25. ;    else characters received with parity stripped
  26. ;
  27. ;    By C.R. Weber
  28. ;    6256 Golden Coin Court
  29. ;    Columbia, MD 21045
  30. ;
  31. ;    8/8/86
  32. ;
  33. ;======================================
  34.  
  35. ;    default comm port to use
  36.  
  37. comline        equ    0000h        ;com 1
  38.  
  39.  
  40. ;    time out defaults
  41.  
  42. carr_time    equ    30        ;time to wait for carrier
  43.                     ;20 seconds now
  44. no_act_time    equ    600        ;no activity timeout
  45.                     ;7 min
  46.  
  47. rs232_port    equ    0000h        ;offset to port addresses at segment 40h
  48.  
  49.  
  50.  
  51. cseg    segment
  52.     assume cs:cseg
  53.  
  54.  
  55. inport     proc    far            ;call this with dbase
  56.  
  57.     push    si            ;save registers
  58.     push    dx
  59.     push    cx
  60.     push     bx
  61.     push    ax
  62.  
  63.     mov    dx,    comline        ;set up for com line
  64.  
  65.     cmp    bx,    0        ;check for valid string passed
  66.     jz    eloop            ;no data if zero
  67.  
  68.     mov    cs:beg_buf,    bx    ;save begining of buffer
  69.                     ;in cs relative storage
  70.  
  71. start    label    near
  72.  
  73.     cmp    byte ptr [bx],0        ;end of original dbase string?
  74.     jz    short    eloop        ;yes then return
  75.  
  76.  
  77. nextch    label    near
  78.  
  79.     call    short    chin        ;get character from modem
  80.     or    al,     al        ;was it a timeout or loss of carrier
  81.     js    opps            ;yes
  82.  
  83.     cmp    al,    13        ;CR?
  84.     jnz    short    nocr
  85.  
  86.  
  87. strend    label    near
  88.  
  89.     mov    byte ptr [bx],    0    ;Yes then terminate the string
  90.     jmp    short    eloop        ;and return to dbase
  91.  
  92.  
  93. nocr    label    near
  94.  
  95.     cmp    al,     8        ;back space?
  96.     jnz    short    nobs
  97.     call    short    erase        ;erase the character
  98.     jmp    short    nextch        ;get next character
  99.  
  100.  
  101. nobs    label    near
  102.  
  103.     cmp    al,     7fh        ;DELETE?
  104.     jnz    short    svchr
  105.     call    short    erase        ;erase the character
  106.     jmp    short    nextch        ;get next char
  107.  
  108.  
  109. svchr    label    near
  110.  
  111.     mov    byte ptr [bx],    al    ;save character
  112.     inc    bx            ;point to next location
  113.     call    short    chout        ;echo it back
  114.     jmp    short    start
  115.  
  116.  
  117. opps    label    near
  118.  
  119.     mov    bx,    cs:beg_buf    ;get begining of str
  120.     mov    byte ptr [bx], al    ;save error code as first character
  121.     inc    bx            ;so dbase can find it
  122.     jmp    short    strend        ;and ret to dbase
  123.  
  124.  
  125. eloop    label    near
  126.  
  127.     pop    ax            ;restore registers
  128.     pop    bx
  129.     pop    cx
  130.     pop    dx
  131.     pop    si
  132.     ret                ;far return to dbase
  133.  
  134.  
  135. inport    endp
  136.  
  137. ;    temp storage for local vars
  138.  
  139. beg_buf    dw    0            ;beg of dbase string buffer
  140. t_cnt    dw    0            ;inactivity timeout count
  141. car_cnt    dw    0            ;no carrier timeount count
  142.  
  143.  
  144. ;======================================
  145. ;    get character from com port
  146. ;
  147. ;    return ffh if no carrier 
  148. ;    return feh if activity timeout
  149. ;    else character received with parity stripped
  150. ;======================================
  151.  
  152.  
  153. chin    proc    near
  154.  
  155.     push    ds
  156.     mov    ax,    40h        ;set up data segment for RS232 port
  157.     mov    ds,    ax        ;address
  158.  
  159.     mov    ax,    no_act_time    ;sec to wait for no activity
  160.     mov    cs:t_cnt,    ax
  161.     mov    ax,    carr_time    ;sec to wait for carrier detect
  162.     mov    cs:car_cnt,    ax
  163.  
  164.     mov    si,    comline        ;get comline index
  165.     shl    si,    1        ;make word offset
  166.     mov    dx,    rs232_port[si]    ;get address of port
  167.  
  168.     add    dx,    4        ;control reg
  169.     mov    al,    1
  170.     out    dx,    al        ;set DTR
  171.  
  172.     add    dx,    2        ;modem status reg
  173.  
  174.  
  175. carr_loop    label    near
  176.  
  177.     mov    ah,    80h        ;Data carrier detect
  178.     call    wait_st            ;wait for DCD
  179.     jz    car_ok            ;timed out no carrier
  180.  
  181.     mov    ax,    cs:car_cnt
  182.     dec    ax
  183.     mov    cs:car_cnt,    ax
  184.     jnz    carr_loop
  185.     pop    ds
  186.     mov    al,    0ffh        ;no carrier
  187.     ret
  188.  
  189.  
  190. car_ok    label    near
  191.  
  192.     dec    dx            ;line status register
  193.  
  194.  
  195. ch_loop    label    near
  196.  
  197.     mov    ah,    1        ;recv char?
  198.     call    wait_st            ;wait for character
  199.     jz    ch_rdy            ;got one ?
  200.  
  201.     mov    ax,    cs:t_cnt    ;no - then check count
  202.     dec    ax
  203.     mov    cs:t_cnt,    ax
  204.     jnz    ch_loop            ;more time
  205.     pop    ds            ;else return error as
  206.     mov    al,    0feh        ;just timeout
  207.     ret
  208.  
  209.  
  210. ch_rdy    label    near
  211.  
  212.     mov    dx,    rs232_port[si]    ;get address of port
  213.     in    al,    dx        ;get char
  214.     and    al,    07fh        ;strip parity anyway
  215.     pop    ds
  216.     ret
  217.  
  218.  
  219. chin    endp
  220.  
  221.  
  222. ;======================================
  223. ;    send out character in al
  224. ;======================================
  225.  
  226.  
  227. chout    proc    near
  228.  
  229.     push    dx
  230.     mov    ah,    1
  231.     mov    dx,    comline
  232.     int    14h
  233.     pop    dx
  234.     ret
  235.  
  236. chout    endp
  237.  
  238.  
  239. ;======================================
  240. ;    erase prev character typed
  241. ;======================================
  242.  
  243.  
  244. erase    proc    near
  245.  
  246.     push    ax
  247.     cmp    bx,    cs:beg_buf    ;make sure that there are characters
  248.     jle    short    era1        ;first character
  249.     dec    bx            ;move pointer back
  250.     mov    al,    8        ;delete char on user's
  251.     call    short    chout        ;screen
  252.     mov    al,    ' '        ;with space
  253.     call    short    chout
  254.     mov    al,    8        ;
  255.     call    short    chout
  256.  
  257.  
  258. era1    label    near
  259.  
  260.     pop    ax
  261.     ret
  262. erase    endp
  263.  
  264.  
  265. ;======================================
  266. ;    wait for a status in port [dx] and bit pattern in ah
  267. ;
  268. ;======================================
  269.  
  270.  
  271. wait_st    proc    near
  272.  
  273.     push    cx
  274.     xor    cx,    cx        ;set up loop count
  275.  
  276.  
  277. w1    label    near
  278.  
  279.     in    al,    dx        ;get stat
  280.     and    al,    ah        ;strip unwanted bits
  281.     cmp    al,    ah        ;check for all set
  282.     je    w_end            ;yes?
  283.     loop    w1            ;loop again
  284.  
  285.     or    ah,    ah        ;zero flag off - error
  286.  
  287.  
  288. w_end    label    near
  289.  
  290.     pop    cx
  291.     ret
  292.  
  293. wait_st    endp
  294.  
  295.  
  296. cseg    ends
  297.     end
  298.