home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-1.ZIP / GCOMM / _ASIFIRS.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-08-14  |  7.7 KB  |  208 lines

  1. ;
  2. ; The Greenleaf Comm Library
  3. ;
  4. ; Copyright (C) 1990 Greenleaf Software Inc.  All Rights Reserved.
  5. ;
  6.         .xlist
  7.         include model.h
  8.         include prologue.h
  9.         include asiports.equ
  10.         .list
  11.  
  12.         extrn   serv0:far
  13.  
  14.         dseg    _commlib
  15.         extrn   inttbl:word
  16.         endds
  17.  
  18.         pseg    _asinew
  19. ;==>--  int _asifirst(port,latch,p)
  20. ;       int port,latch;
  21. ;       struct PORT_TABLE *p;
  22. ;
  23. ;       Responsible for taking information from the table and
  24. ;       "Setting up the machine"
  25. ;
  26.         cproc   _asifirst,,_asifirs,,,<DS,ES,NOSI,EXIT,OKEXIT>
  27.         if      _LDATA
  28.          lds    bx,parm3_
  29.         else
  30.          mov    bx,parm3_
  31.         endif
  32.         mov     ax,ds
  33.         mov     es,ax                   ;es=ds
  34.         mov     cx,[bx+base_8250]       ;check for non 0 8250 i/o address
  35.         or      cx,cx
  36.         mov     ax,ASINVPAR
  37.         jnz     ok8250
  38.         funcexit                        ;exit function AX=Error code
  39. ok8250: mov     dx,cx                   ;read character from 8250
  40.         in      al,dx
  41.         KILL_TIME
  42.         mov     dx,INTID
  43.         add     dx,cx                   ;see if there is really an 8250 by
  44.         in      al,dx                   ;looking at the interrupt id register
  45.         KILL_TIME
  46.         and     al,0f8h                 ;bits 3-7 should be 0 if installed
  47.         mov     ax,ASNO8250
  48.         jz      in8250
  49.         funcexit                        ;exit function, AX = Error code
  50. in8250: cld                             ;strings do auto-increment
  51.         xor     ah,ah
  52.         lea     di,[bx+p_8250lcr]       ;es:di point to save area for 8250
  53.         mov     dx,LCREG
  54.         add     dx,cx                   ;dx=line control register address
  55.         in      al,dx
  56.         KILL_TIME
  57.         stosw                           ;save in structure
  58.         and     al,not DLAB                                     ;**2.10
  59.         out     dx,al                   ;set DLAB = 0           ;**2.10
  60.         KILL_TIME
  61.         inc     dx                      ;dx=modem control register port
  62.         in      al,dx
  63.         KILL_TIME
  64.         stosw                           ;save in structure
  65.         test    al,RTS                  ;is RTS asserted?
  66.         jz      rtslow
  67.         or      word ptr[bx+chst_bits],RTSACTIVE
  68.                                         ;update status bit in structure
  69. rtslow: mov     dx,INTER
  70.         add     dx,cx                   ;dx=interrupt enable register port
  71.         in      al,dx
  72.         KILL_TIME
  73.         stosw                           ;read and save it.
  74.         xor     al,al                   ;shut down any interrupt enables
  75.         out     dx,al
  76.         KILL_TIME
  77.         mov     dx,LCREG                ;now set dlab to 1 so we can read
  78.         add     dx,cx                   ;the baud rate divisor
  79.         in      al,dx
  80.         KILL_TIME
  81.         or      al,DLAB
  82.         out     dx,al
  83.         KILL_TIME
  84.         mov     dx,cx                   ;read least significant byte of
  85.         in      al,dx                   ;baud rate divisor
  86.         KILL_TIME
  87.         stosw                           ;and save in structure
  88.         inc     dx
  89.         in      al,dx                   ;read most significant byte
  90.         KILL_TIME
  91.         stosw
  92.         mov     dx,LCREG                ;set dlab to 0 once and for all!
  93.         add     dx,cx
  94.         in      al,dx
  95.         KILL_TIME
  96.         and     al,not DLAB
  97.         out     dx,al
  98.         KILL_TIME
  99.         mov     dx,LSREG
  100.         add     dx,cx
  101.         in      al,dx
  102.         KILL_TIME
  103.         xor     ah,ah                   ;set up line status field in structure
  104.         mov     [bx+line_stat],ax
  105.         mov     dx,MSREG                ;do the same thing with modem_stat
  106.         add     dx,cx
  107.         in      al,dx
  108.         KILL_TIME
  109.         mov     [bx+modem_stat],ax
  110.         and     byte ptr parm2_,1
  111.         jz      no8259                  ;if parameter = 0 then don't set
  112.         mov     ax,[bx+intrpt_num]      ;get interrupt number to al
  113.         or      al,al                   ;see if we have one to set
  114.         jz      novect                  ;if not don't bother it
  115.         mov     ah,35h
  116.         mov     di,bx                   ;stash bx for dos function 35h
  117.         int     21h                     ;get what is at interrupt vector
  118.         xchg    bx,di                   ;bx points back to structure, es:di^
  119.         mov     word ptr[bx+p_vector],di ;save offset
  120.         mov     word ptr[bx+p_vector+2],es ;&segment
  121.         mov     ax,[bx+intrpt_num]      ;get interrupt number to al
  122.         push    ds
  123.         push    bx
  124.         ifdef   DSNOTHING
  125.           mov   bx,__commlib_DATA
  126.         else
  127.           mov   bx,DGROUP
  128.         endif
  129.         mov     ds,bx
  130.         mov     bl,parm1_               ;get port number for this structure
  131.         xor     bh,bh
  132.         shl     bx,1                    ;*2;
  133.         mov     dx,inttbl[bx]           ;get address of this port's routine
  134.         mov     bx,seg serv0
  135.         mov     ds,bx                   ;ds=cs
  136.         mov     ah,25h
  137.         int     21h                     ;set interrupt vector
  138.         pop     bx
  139.         pop     ds
  140. novect: mov     cx,[bx+irq_8259]        ;prepare to enable 8259
  141.         or      cx,cx                   ;check for 0
  142.         jz      no8259
  143.         mov     al,1
  144.         shl     al,cl                   ;shift 1 bit into correct position
  145.         not     al
  146.         mov     cl,al
  147.         mov     dx,[bx+port_8259]       ;get i/o address of 8259
  148.         inc     dx                      ;++port
  149.         in      al,dx
  150.         KILL_TIME
  151.         xor     ah,ah
  152.         mov     [bx+p_8259],ax          ;save previous setting
  153.         and     al,cl                   ;enable correct bit
  154.         out     dx,al                   ;and set in 8259
  155.         KILL_TIME
  156. no8259:
  157.         mov     cx,[bx+base_8250]
  158.         mov     dx,LSREG                ;read line status register
  159.         add     dx,cx                   ;and store starting variables in struc
  160.         in      al,dx
  161.         KILL_TIME
  162.         push    ax                      ;save for now
  163.         mov     ah,al
  164.         not     ah
  165.         mov     [bx+line_stat],ax
  166.         mov     dx,MSREG                ;read modem status register
  167.         add     dx,cx
  168.         in      al,dx
  169.         KILL_TIME
  170.         mov     dl,al                   ;save modem status register in dl
  171.         mov     ah,al
  172.         not     ah
  173.         mov     [bx+modem_stat],ax      ;save in structure
  174.         and     dl,0f0h                 ;mask bits 0-3 out
  175.         pop     ax                      ;get line status back to al
  176.         and     al,0eh                  ;mask un wanted bits
  177.         or      al,dl                   ;merge the two
  178.         xor     ah,ah
  179.         mov     [bx+wide_stat],ax       ;save in structure
  180.         mov     dx,cx                   ;read receiver to clear possible int.
  181.         in      al,dx
  182.         KILL_TIME
  183.         mov     dx,INTID
  184.         add     dx,cx
  185.         in      al,dx                   ;read interrupt I.D. register
  186.         KILL_TIME
  187.         mov     dx,INTER                ;enable modem/line status ;**2.10
  188.         add     dx,cx
  189.         mov     al,ENRXS+ENMS
  190.         cli
  191.         out     dx,al
  192.         KILL_TIME
  193.         out     dx,al                   ;do it twice (per National) ;**2.10
  194.         KILL_TIME
  195.         sti
  196.         mov     dx,MCREG                ;enable out2
  197.         add     dx,cx
  198.         in      al,dx                   ;read what's there first
  199.         KILL_TIME
  200.         or      al,OUT2                 ;assert OUT2
  201.         out     dx,al
  202.         KILL_TIME
  203.         xor   ax,ax                     ;Exit function with success
  204.         cproce
  205.         endps
  206.         end
  207.  
  208.