home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 189.img / TCS120S.ZIP / MODEMDRV.ASM < prev    next >
Assembly Source File  |  1989-01-19  |  6KB  |  379 lines

  1. ; *** CONSTANTS
  2.  
  3. buffer_size    equ    256
  4. int_number    equ    255
  5.  
  6. ; *** PORT DEFINITIONS
  7.  
  8. RBR        EQU    8
  9. THR        EQU    8
  10. DLL        EQU    8
  11. DLH        EQU    9
  12. IER        EQU    9
  13. IIR        EQU    10
  14. LCR        EQU    11
  15. MCR        EQU    12
  16. LSR        EQU    13
  17. MSR        EQU    14
  18.  
  19. ; *** PAGE 0 DEFINITIONS
  20.  
  21. abs0        segment at 0
  22.         assume    es:abs0
  23.         org    int_number*4
  24. intc8vec    dw    ?
  25. abs0        ends
  26.  
  27. ; *** CODE SEGMENT
  28.  
  29. code        segment
  30.         assume    cs:code,ds:code,ss:code
  31.         org    100h
  32. start:        jmp    near ptr main
  33.  
  34. oldc        dw    ?,?        ;Old interrupt vectors
  35. comnum        dw    ?        ;0 or 1 for COM1 or COM2
  36. comport        dw    ?        ;3F0 or 2F0 for COM1 or COM2
  37. comint        dw    ?        ;0C*4 or 0B*4 for COM1 or COM2
  38. comports    dw    3f0h,2f0h
  39. comints        dw    0ch*4,0bh*4
  40. comors        db    16,8        ;Or value to enable interrupt
  41.  
  42. buffer_head    dw    ?        ;Address where next character will go
  43. buffer_tail    dw    ?        ;Address where first character is
  44. buffer_start    dw    ?        ;Pointer: Start of buffer
  45. buffer_end    dw    ?        ;Pointer: End of buffer
  46. buffer        db    buffer_size dup (?)
  47.  
  48.  
  49. ; *** SUBROUTINES
  50.  
  51. rets        proc
  52.  
  53. inc_bx:        inc    bx            ;Add 1 to BX, wrap around
  54.         cmp    bx,buffer_end        ;the buffer
  55.         jne    ibx1
  56.         mov    bx,buffer_start
  57. ibx1:        ret
  58.  
  59. add_char:    push    bx
  60.         mov    bx,buffer_head
  61.         mov    [bx],al
  62.         call    inc_bx
  63.         mov    buffer_head,bx
  64.         pop    bx
  65.         ret
  66.  
  67. ; *** CHECK IF THERE ARE CHARACTERS
  68.  
  69. chars_yn:    push    bx        ;JZ will jump if there are no chars.
  70.         mov    bx,buffer_tail    ;If there are no chars, AL is
  71.         mov    al,[bx]        ;undefined.  If there are characters,
  72.         cmp    bx,buffer_head    ;AL holds the next character but it
  73.         pop    bx        ;is not taken out of the buffer.
  74.         ret
  75.  
  76. ; *** GET CHARACTER FROM BUFFER
  77.  
  78. get_char:    call    chars_yn    ;JZ will jump if there are no chars.
  79.         jnz    gc1        ;If there are chars, the next WILL be
  80.         xor    ax,ax        ;taken out of the buffer as well as
  81.         ret            ;being in AL.  Otherwise, AL will
  82. gc1:        push    bx        ;have 0.
  83.         mov    bx,buffer_tail
  84.         mov    al,[bx]
  85.         call    inc_bx
  86.         mov    buffer_tail,bx
  87.         pop    bx
  88.         xor    ah,ah
  89.         ret
  90.  
  91. num_chars:    mov    ax,buffer_head    ;AX=# of characters in the buffer
  92.         sub    ax,buffer_tail
  93.         cmp    ax,0
  94.         jge    nc1
  95.         add    ax,buffer_size
  96. nc1:        ret
  97.  
  98. ; *** SEND CHARACTER IN AL OVER COMM LINE
  99.  
  100. send_char:    push    dx        ;On exit, AH=128 not allowing to send
  101.         push    ax
  102.         mov    dx,comport
  103.         add    dx,lsr
  104.         xor    cx,cx
  105. sc1:        in    al,dx
  106.         test    al,20h
  107.         jnz    sc2
  108.         loop    sc1
  109.         pop    ax
  110.         mov    ah,80h
  111.         jmp    short sc3
  112. sc2:        add    dx,thr-lsr
  113.         pop    ax
  114.         out    dx,al
  115.         xor    ah,ah
  116. sc3:        pop    dx
  117.         ret
  118.  
  119. rets        endp
  120.  
  121. ;*** NEW INTERRUPT PROCEDURES
  122.  
  123. ints        proc
  124.  
  125. ;*** HANDLE ANOTHER CHARACTER OVER THE COMM LINE
  126.  
  127. newc:        push    es
  128.         push    ds
  129.         push    di
  130.         push    si
  131.         push    bp
  132.         push    dx
  133.         push    cx
  134.         push    bx
  135.         push    ax
  136.         mov    ax,cs
  137.         mov    ds,ax
  138.         xor    ax,ax
  139.         mov    es,ax
  140.         mov    dx,comport
  141.         add    dx,rbr
  142.         in    al,dx
  143.         call    add_char
  144.         mov    al,20h
  145.         out    20h,al
  146.         pop    ax
  147.         pop    bx
  148.         pop    cx
  149.         pop    dx
  150.         pop    bp
  151.         pop    si
  152.         pop    di
  153.         pop    ds
  154.         pop    es
  155.         iret
  156.  
  157. ints        endp
  158.  
  159. ;*** MAIN ROUTINES CALLABLE WITH AN INT 200D
  160. ;AH    Function
  161. ;--    --------
  162. ;0    Initialize; AX=1/2 for COM1: / COM2:.  Buffer is cleared.
  163. ;1    Return # characters in buffer in AX
  164. ;2    Receive characer, if any, else return 0
  165. ;3    Send character
  166. ;4    Disable routines
  167. ;5    Unused
  168. ;6    Hang up
  169. ;7    Set modem paramaters & init COM port and INT C/B
  170. ;        AX= 1: 1=Even parity, 0=No parity
  171. ;        BX= Baud rate
  172.     
  173. mains        proc
  174.  
  175. ;*** INITIALIZE BUFFER
  176.  
  177. init:        cli            ;AX=1 for COM1 or 2 for COM2
  178.         push    dx
  179.         push    bx
  180.         push    ax
  181.         dec    ax
  182.         mov    comnum,ax
  183.         shl    ax,1
  184.         mov    bx,ax
  185.         mov    ax,comports[bx]
  186.         mov    comport,ax
  187.         mov    ax,comints[bx]
  188.         mov    comint,ax
  189.         mov    ax,offset buffer
  190.         mov    buffer_start,ax
  191.         mov    buffer_head,ax
  192.         mov    buffer_tail,ax
  193.         add    ax,buffer_size
  194.         mov    buffer_end,ax
  195.         mov    bx,comint
  196.         mov    cx,cs
  197.         mov    ax,es:[bx+2]
  198.         cmp    ax,cx
  199.         je    already
  200.         mov    ax,es:[bx]
  201.         mov    oldc,ax
  202.         mov    ax,es:[bx+2]
  203.         mov    oldc[2],ax
  204.         mov    ax,offset newc
  205.         mov    es:[bx],ax
  206.         mov    es:[bx+2],cx
  207. already:    mov    dx,comport
  208.         add    dx,ier
  209.         mov    al,1
  210.         out    dx,al        ;ier
  211.         inc    dx
  212.         mov    al,1
  213.         out    dx,al        ;iir
  214.         inc    dx
  215.         mov    al,3
  216.         out    dx,al        ;lcr
  217.         inc    dx
  218.         mov    al,9
  219.         out    dx,al        ;mcr
  220.         inc    dx
  221.         mov    al,60h
  222.         out    dx,al        ;lsr
  223.         inc    dx
  224.         mov    al,30h
  225.         out    dx,al        ;msr
  226.         mov    bx,comnum
  227.         mov    ah,comors[bx]
  228.         xor    ah,255
  229.         in    al,21h
  230.         and    al,ah
  231.         out    21h,al
  232.         pop    ax
  233.         pop    bx
  234.         pop    dx
  235.         sti
  236.         ret
  237.  
  238. disable:    push    dx
  239.         push    cx
  240.         push    bx
  241.         push    ax
  242.         mov    ax,oldc
  243.         mov    cx,oldc[2]
  244.         mov    bx,comint
  245.         cli
  246.         mov    es:[bx],ax
  247.         mov    es:[bx+2],cx
  248.         mov    bx,comnum
  249.         in    al,21h
  250.         or    al,comors[bx]
  251.         out    21h,al
  252.         sti
  253.         pop    ax
  254.         pop    bx
  255.         pop    cx
  256.         pop    dx
  257.         ret
  258.  
  259. enable:        ret
  260.  
  261. hang_up:    push    dx
  262.         push    ax
  263.         mov    dx,comport
  264.         add    dx,mcr
  265.         mov    al,0
  266.         out    dx,al
  267.         pop    ax
  268.         pop    dx
  269.         ret
  270.  
  271. param_tbl    db    3,1ah
  272.  
  273. set_param:    push    dx
  274.         push    cx
  275.         push    bx
  276.         push    ax
  277.         mov    dx,1        ;dxax-1c200h
  278.         mov    ax,0c200h
  279.         div    bx
  280.         mov    bx,ax
  281.         mov    dx,comport
  282.         add    dx,lcr
  283.         mov    al,128
  284.         out    dx,al
  285.         mov    ax,bx
  286.         add    dx,dll-lcr
  287.         out    dx,al
  288.         inc    dx
  289.         mov    al,ah
  290.         out    dx,al
  291.         pop    ax        ;Recover AX
  292.         push    ax        ;Push it back
  293.         mov    bx,ax
  294.         and    bx,1
  295.         add    dx,lcr-dlh
  296.         mov    al,param_tbl[bx]
  297.         out    dx,al
  298.         pop    ax
  299.         pop    bx
  300.         pop    cx
  301.         pop    dx
  302.         ret
  303.  
  304. vectors        dw    init,num_chars,get_char,send_char,disable
  305.         dw    enable,hang_up,set_param
  306. end_vectors    label    byte
  307.  
  308. newc8:        push    es
  309.         push    ds
  310.         push    di
  311.         push    si
  312.         push    bp
  313.         push    dx
  314.         push    cx
  315.         push    bx
  316.         push    ax
  317.         mov    ax,cs
  318.         mov    ds,ax
  319.         xor    ax,ax
  320.         mov    es,ax
  321.         pop    ax
  322.         push    ax
  323.         xor    al,al
  324.         xchg    al,ah
  325.         shl    ax,1
  326.         mov    si,ax
  327.         pop    ax
  328.         add    si,offset vectors
  329.         cmp    si,offset end_vectors
  330.         jae    nfunc
  331.         call    word ptr [si]
  332. nfunc:        pop    bx
  333.         pop    cx
  334.         pop    dx
  335.         pop    bp
  336.         pop    si
  337.         pop    di
  338.         pop    ds
  339.         pop    es
  340.         iret
  341.  
  342. mains        endp
  343.  
  344. eop:
  345.         db    128 dup (?)
  346. eos:
  347.  
  348. ;*** ENTRY PROCEDURE: INITIALIZE INT 0CH, INT 200D
  349.  
  350. main        proc
  351.         mov    ax,cs
  352.         mov    ds,ax
  353.         cli
  354.         mov    ss,ax
  355.         mov    sp,offset eos
  356.         sti
  357.         xor    ax,ax
  358.         mov    es,ax
  359.         mov    ax,es:intc8vec
  360.         cmp    ax,offset newc8
  361.         jne    notinstalled
  362.         mov    dx,offset almsg
  363.         mov    ah,9
  364.         int    21h
  365.         int    20h
  366. almsg:        db    "Modem driver already installed!",13,10,36
  367. notinstalled:    mov    ax,offset newc8
  368.         mov    es:intc8vec,ax
  369.         mov    ax,cs
  370.         mov    es:intc8vec[2],ax
  371.         mov    ax,1            ;Initialize the modem for COM1
  372.         int    int_number
  373.         mov    dx,offset eop+100h
  374.         int    27h
  375. main        endp
  376. code        ends
  377.         end    start
  378.  
  379.