home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / 80x0393.zip / SERTYPE.ASM < prev    next >
Assembly Source File  |  1992-07-30  |  6KB  |  223 lines

  1. comment *
  2.     SERTYPE.ASM
  3.     Purpose:
  4.     Determines the type of UART in each serial port
  5.  
  6.     Author:
  7.     Douglas Boling, in PcMag. With some modifications by Yousuf Khan.
  8. *
  9.  
  10. dosseg
  11.  
  12. bdseg   segment at 40h  ;bios data segment
  13.         com1    dw      ?
  14.         com2    dw      ?
  15.         com3    dw      ?
  16.         com4    dw      ?
  17.         ends
  18.  
  19. _data   segment para 'data'
  20.         uart1   db      0
  21.         uart2   db      0
  22.         uart3   db      0
  23.         uart4   db      0
  24.         portmsg db      "COMx: $"
  25.         x8250   db      "NS 8250 (non-FIFO)",13,10,"$"
  26.         x16450  db      "NS 8250A/16450/16550 (non-FIFO)",13,10,"$"
  27.         xfifo   db      "NS 16550A/Intel 82510 (FIFO)",13,10,"$"
  28.         xdma    db      "IBM type 3 (FIFO/DMA)",13,10,"$"
  29.         pas_de_ports    db      "No serial ports detected",13,10,"$"
  30.         ends
  31.  
  32. _stack  segment para stack 'stack'
  33.         db      200h dup (?)
  34.         ends
  35.  
  36. cseg    segment para 'code'
  37.         mov     ax, bdseg
  38.         mov     es, ax          ;ES := Bdseg
  39.         mov     ax, _data
  40.         mov     ds, ax          ;DS := _data
  41.         assume  cs:cseg, ds:_data, es:bdseg, ss:_stack
  42.         xor     al, al          ;# of serial ports = 0
  43.         mov     dx, [com1]
  44.         cmp     dx, 0
  45.         je      eoproc
  46.         inc     al              ;# of serial ports = 1
  47.         push    ax
  48.         call    uartdet
  49.         mov     [uart1], al     ;remember the type of this UART
  50.         pop     ax
  51.         mov     dx, [com2]
  52.         cmp     dx, 0
  53.         je      eoproc
  54.         inc     al              ;# of serial ports = 2
  55.         push    ax
  56.         call    uartdet
  57.         mov     [uart2], al
  58.         pop     ax
  59.         mov     dx, [com3]
  60.         cmp     dx, 0
  61.         je      eoproc
  62.         inc     al              ;# of serial ports = 3
  63.         push    ax
  64.         call    uartdet
  65.         mov     [uart3], al
  66.         pop     ax
  67.         mov     dx, [com4]
  68.         cmp     dx, 0
  69.         je      eoproc
  70.         inc     al              ;# of serial ports = 4
  71.         push    ax
  72.         call    uartdet
  73.         mov     [uart4], al
  74.         pop     ax
  75.  
  76. eoproc:
  77.         call    disp
  78.         mov     ah, 4ch
  79.         int     21h
  80.  
  81. delay   macro
  82.         jmp     $+2
  83.         endm
  84.  
  85. uartdet proc    near
  86.         push    bx
  87.         push    cx
  88.         mov     bx, dx          ;save starting i/o addr
  89.         add     dx, 4           ;point to modem ctrl reg
  90.         in      al, dx          ;disable interrupts
  91.         push    ax
  92.         and     al, 11111011b
  93.         out     dx, al
  94.         mov     ch, 0           ;assume type 0
  95.         mov     dx, bx
  96.         add     dx, 7           ;see if scratch reg exists
  97.         mov     al, 55h
  98.         cli
  99.         out     dx, al          ;write to scratch reg
  100.         delay
  101.         in      al, dx          ;read back
  102.         cmp     al, 55h
  103.         jne     endudet
  104.         mov     al, 0AAh
  105.         out     dx, al          ;write to scratch reg
  106.         delay
  107.         in      al, dx          ;read back
  108.         sti
  109.         cmp     al, 0AAh
  110.         jne     endudet
  111.         inc     ch              ;assume type 1
  112.         mov     dx, bx
  113.         add     dx, 2           ;point to FIFO ctrl reg
  114.         mov     al, 7           ;attempt to enable FIFOs
  115.         cli
  116.         out     dx, al
  117.         delay
  118.         in      al, dx          ;read interrupt ID reg
  119.         sti
  120.         and     al, 0c0h        ;strip all but FIFO bits
  121.         jz      endudet         ;if bits 0, 16450/16550
  122.         inc     ch              ;assume type 2
  123.         mov     dx, bx
  124.         add     dx, 8003h       ;point to enhanced reg 1
  125.         cli
  126.         in      al, dx
  127.         push    ax
  128.         or      al, 01000000b   ;enable DMA transmission
  129.         out     dx, al
  130.         push    dx
  131.         mov     dx, bx
  132.         add     dx, 2
  133.         in      al, dx
  134.         mov     cl, al
  135.         pop     dx              ;restore enhanced reg 1
  136.         pop     ax
  137.         out     dx, al
  138.         sti
  139.         and     cl, 0c0h        ;again mask all but FIFO ID
  140.         cmp     cl, 40h
  141.         jne     endudet         ;must be type 2 (FIFO)
  142.         inc     ch              ;must be type 3 (DMA)
  143.  
  144. endudet:
  145.         pop     ax
  146.         mov     dx, bx
  147.         add     dx, 4           ;point to modem ctrl reg
  148.         out     dx, al          ;restore initial condition
  149.         xor     ax, ax
  150.         mov     al, ch
  151.         mov     dx, bx
  152.         pop     cx
  153.         pop     bx
  154.         ret
  155. uartdet endp
  156.  
  157. disp    proc    near
  158.         push    ax      ;save AX
  159.         cmp     al, 0   ;no serial ports?
  160.         je      noports
  161.         mov     bx, offset ds:[uart1]   ;offset of UART type field
  162.         mov     di, offset ds:[portmsg][3] ;offset of 4th char in message
  163.         mov     cx, 0
  164.         mov     cl, al  ;number of iterations
  165.  
  166. @l1:
  167.         ;
  168.         ;write "COMx: " message substituting "x" for proper comport #
  169.         ;
  170.         mov     dl, 4
  171.         sub     dl, cl
  172.         add     dl, 30h ;convert to ASCII number
  173.         mov     [di], dl
  174.         lea     dx, portmsg
  175.         mov     ah, 9
  176.         int     21h
  177.         ;
  178.         ;write the UART type now
  179.         ;
  180.         mov     dl, [bx]
  181.         cmp     dl, 0
  182.         jne     @t2
  183.         lea     dx, x8250
  184.         mov     ah, 9
  185.         int     21h
  186.         jmp     @eot
  187.  
  188. @t2:    cmp     dl, 1
  189.         jne     @t3
  190.         lea     dx, x16450
  191.         mov     ah, 9
  192.         int     21h
  193.         jmp     @eot
  194.  
  195. @t3:    cmp     dl, 2
  196.         jne     @t4
  197.         lea     dx, xfifo
  198.         mov     ah, 9
  199.         int     21h
  200.         jmp     @eot
  201.  
  202. @t4:    lea     dx, xdma
  203.         mov     ah, 9
  204.         int     21h
  205.  
  206. @eot:   inc     bx
  207.         loop    @l1
  208.         jmp     eoproc2
  209.  
  210. noports:
  211.         lea     dx, pas_de_ports
  212.         mov     ah, 9
  213.         int     21h
  214.  
  215. eoproc2:
  216.         pop     ax
  217.         ret
  218. disp    endp
  219.  
  220.         ends
  221.         end
  222.  
  223. ; EOF SERTYPE.ASM