home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / CLIPDL11.ZIP / MODEM.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-11-26  |  4.9 KB  |  227 lines

  1. ;**************************************************************************
  2. ;*:*********************************************************************
  3. ;*:
  4. ;*:      Program: MODEM.ASM
  5. ;*:
  6. ;*:       System: Clipdial Intelligent Phone Dialer V#1.0
  7. ;*:       Author: Glendon Todd / Vega Group
  8. ;*:    Copyright (c) 1987, Public Domain by Glendon Todd
  9. ;*:
  10. ;*:
  11. ;*: Documented: 11/26/87       12:20                   SNAP! version 2.01
  12. ;*:*********************************************************************
  13.  
  14. ;  This source file contains the assembly language routines that Clipdial
  15. ;  uses to control and to communicate with the PC serial ports.    Included
  16. ;  are serial port initialization code, a routine that returns the status of
  17. ;  the serial port's DSR status line, and a routine which transmits modem
  18. ;  command strings (AT-prefixed) to a Hayes-compatible modem and which
  19. ;  controls the serial port's DTR line appropriately.
  20. ;
  21. ;  The DTR control and command transmission code are based on the DOSMODEM
  22. ;  utilities written by Donovan Kuhn and John Niedfeldt.
  23.  
  24. ;  For support, comments, questions or whatever, contact :
  25. ;           
  26. ;                             Glendon Todd
  27. ;                             312 Van Buren St.
  28. ;                             Falls Church, VA    22046
  29. ;                             Compuserve 71121,352
  30. ;                             Voice (703) 532-8191   
  31.  
  32.  
  33. upcase    macro    char
  34.     local    nocvt
  35.  
  36.     ifb    <char>
  37.  
  38.     upcase    al
  39.  
  40.     else
  41.  
  42.     cmp    char,'a'
  43.     jb    nocvt
  44.     cmp    char,'z'
  45.     ja    nocvt
  46.     sub    char,32
  47. nocvt:
  48.     endif
  49.     endm
  50.  
  51.  
  52.  
  53.     page    66,132
  54.         extrn   _retl:far    ; return logical true or false
  55.  
  56. prog    segment    byte public 'PROG'
  57.     assume    CS:prog, DS:prog
  58.  
  59. arg_str equ     byte ptr es:[si]
  60.  
  61. public  auxout
  62.  
  63. auxout    proc    far
  64.     push    ax
  65.     mov    dx,base
  66.     add    dx,5
  67.  
  68. txlp:
  69.     in    al,dx
  70.     and    al,20h
  71.     jz    txlp
  72.  
  73.     pop    ax
  74.     sub    dx,5
  75.     out    dx,al    
  76.     ret
  77. auxout    endp
  78.  
  79. ;        DSR - Procedure returns value of DSR line from modem.
  80. ;        Currently works for Com1 only.
  81. ;        Input arguments - none.
  82. ;        Returns status as logical True/False.
  83. public  dsr
  84. dsr    proc    far
  85.     mov    dx,03FEh
  86.     in    al,dx
  87.         and     ax,0030h
  88.  
  89.         push     ax             ; put return value on the stack
  90.         call     _retl          ; return logical value to clipper
  91.         pop      ax             ; restore the stack
  92.         ret
  93.  
  94. dsr    endp
  95.  
  96. ;        MODEMCMD - Transmits a command string to a Hayes-compatible modem.
  97. ;        Input arguments - Pointer to string - command to be transmitted.
  98. ;        Modemcmd will initialize the comm. port, control DTR as necessary,
  99. ;        prefix the command with "AT", and terminate it with a CR (0Dh).
  100. public  modemcmd
  101. modemcmd    proc    far
  102.     jmp    modemcmd1
  103.  
  104. base    dw    0
  105.  
  106. modemcmd1:
  107.         push    bp
  108.         mov     bp,sp
  109.         push    es
  110.         mov     es,[bp+8]
  111.         mov     bx,[bp+6]
  112.     mov    ch,0            ;default com port (COM1:)
  113.     mov    si,bx
  114. modemcmd2:
  115.     mov    cl,[arg_str]        ;space off leading spaces
  116.     cmp    cl,' '
  117.     jz    modemcmd2
  118.  
  119.     cmp    cl,'?'
  120.     jz    errexit
  121.  
  122.     upcase    cl            ;using UPCASE without a parameter
  123.     cmp    cl,'C'            ;(defaults to AL)
  124.     jnz    nocom
  125.  
  126.     mov    cl,[arg_str][1]
  127.     upcase    cl            ;using UPCASE using another register
  128.     cmp    cl,'O'
  129.     jnz    nocom
  130.                 
  131.  
  132.     mov    cl,[arg_str][2]
  133.     upcase    cl            ;using UPCASE with cl as the parm
  134.     cmp    cl,'M'
  135.     jnz    nocom
  136.  
  137.     cmp    byte ptr [arg_str][4],':'
  138.     jz    check_port
  139.  
  140. errexit:
  141.     lea    dx,errmsg
  142. errexit1:
  143.     mov    ah,9
  144.     int    21h
  145.         jmp     exit
  146.  
  147. check_port:
  148.     mov    al,[arg_str][3]        ;get the com number
  149.     sub    al,'1'            ;convert to binary
  150.     cmp    al,3            ;greater than com4?
  151.     ja    errexit
  152.  
  153.     add    si,5
  154.  
  155.     mov    ch,al
  156. nocom:
  157.     xor    bh,bh    
  158.     shl    ch,1                    ;ch holds comm. port number
  159.  
  160.         mov     ah,0                    ;service 0 - initialize comm. port
  161.         mov     al,83h                  ;sets port to 1200,N,8,1
  162.                                         ;change 83h to 43h for 300 baud,
  163.                                         ;0A3h for 2400 baud
  164.         mov     dh,0                    
  165.         mov     dl,ch                   ;serial port number from ch
  166.         int     14h                     
  167.  
  168.     mov    ax,40h
  169.     mov    ds,ax
  170.         push    bx
  171.         mov     bh,0
  172.         mov     bl,ch
  173.     mov    ax,ds:[bx]
  174.         pop     bx
  175.     push    cs
  176.     pop    ds
  177.  
  178.     cmp    ax,0
  179.     jnz    comok
  180.  
  181.     lea    dx,ncstr
  182.     jmp    errexit1
  183.  
  184.  
  185. comok:
  186.     mov    base,ax         ;comm port base address
  187.  
  188.     mov    dx,ax
  189.     add    dx,4
  190.     in    al,dx           ;get comm port status
  191.     or    al,3        ;set dtr bit
  192.     out    dx,al
  193.         push    dx
  194.  
  195.     mov    al,'A'
  196.     call    auxout
  197.     mov    al,'T'
  198.     call    auxout
  199.  
  200. outlp:
  201.     mov    al,[arg_str]
  202.     inc    si
  203.     cmp    al,0
  204.     jz    atdone
  205.     call    auxout
  206.     jmp    outlp
  207. atdone:
  208.     mov    al,0Dh         ;CR
  209.     call    auxout
  210.         pop     dx
  211.     in    al,dx
  212.     and    al,0fch
  213.     out    dx,al
  214. exit:
  215.         pop     es
  216.         pop     bp
  217.         ret
  218. modemcmd    endp
  219.  
  220.  
  221. errmsg    db    'Usage:  AT [COM1:|COM2:|COM3:|COM4:] command string',13,10,'$'
  222. ncstr    db    'COM port not found',13,10,'$'
  223.  
  224.  
  225. prog    ends
  226.         end    
  227.