汇编源码系列之sertype

这个都是过去DOS时代的汇编源码,虽然已经过去了,但是对于学习汇编还是有帮助的,汇编语言只是程序员一门基础语言,大多人掌握即可,不一定要深入研究.......

comment *
  SERTYPE.ASM
  Purpose:
  Determines the type of UART in each serial port
  Author:
  Douglas Boling, in PcMag. With some modifications by Yousuf Khan.
*
dosseg
bdseg  segment at 40h ;bios data segment
    com1  dw   ?
    com2  dw   ?
    com3  dw   ?
    com4  dw   ?
    ends
_data  segment para 'data'
    uart1  db   0
    uart2  db   0
    uart3  db   0
    uart4  db   0
    portmsg db   "COMx: $"
    x8250  db   "NS 8250 (non-FIFO)",13,10,"$"
    x16450 db   "NS 8250A/16450/16550 (non-FIFO)",13,10,"$"
    xfifo  db   "NS 16550A/Intel 82510 (FIFO)",13,10,"$"
    xdma  db   "IBM type 3 (FIFO/DMA)",13,10,"$"
    pas_de_ports  db   "No serial ports detected",13,10,"$"
    ends
_stack segment para stack 'stack'
    db   200h dup (?)
    ends
cseg  segment para 'code'
    mov   ax, bdseg
    mov   es, ax     ;ES := Bdseg
    mov   ax, _data
    mov   ds, ax     ;DS := _data
    assume cs:cseg, ds:_data, es:bdseg, ss:_stack
    xor   al, al     ;# of serial ports = 0
    mov   dx, [com1]
    cmp   dx, 0
    je   eoproc
    inc   al       ;# of serial ports = 1
    push  ax
    call  uartdet
    mov   [uart1], al   ;remember the type of this UART
    pop   ax
    mov   dx, [com2]
    cmp   dx, 0
    je   eoproc
    inc   al       ;# of serial ports = 2
    push  ax
    call  uartdet
    mov   [uart2], al
    pop   ax
    mov   dx, [com3]
    cmp   dx, 0
    je   eoproc
    inc   al       ;# of serial ports = 3
    push  ax
    call  uartdet
    mov   [uart3], al
    pop   ax
    mov   dx, [com4]
    cmp   dx, 0
    je   eoproc
    inc   al       ;# of serial ports = 4
    push  ax
    call  uartdet
    mov   [uart4], al
    pop   ax
eoproc:
    call  disp
    mov   ah, 4ch
    int   21h
delay  macro
    jmp   $+2
    endm
uartdet proc  near
    push  bx
    push  cx
    mov   bx, dx     ;save starting i/o addr
    add   dx, 4      ;point to modem ctrl reg
    in   al, dx     ;disable interrupts
    push  ax
    and   al, 11111011b
    out   dx, al
    mov   ch, 0      ;assume type 0
    mov   dx, bx
    add   dx, 7      ;see if scratch reg exists
    mov   al, 55h
    cli
    out   dx, al     ;write to scratch reg
    delay
    in   al, dx     ;read back
    cmp   al, 55h
    jne   endudet
    mov   al, 0AAh
    out   dx, al     ;write to scratch reg
    delay
    in   al, dx     ;read back
    sti
    cmp   al, 0AAh
    jne   endudet
    inc   ch       ;assume type 1
    mov   dx, bx
    add   dx, 2      ;point to FIFO ctrl reg
    mov   al, 7      ;attempt to enable FIFOs
    cli
    out   dx, al
    delay
    in   al, dx     ;read interrupt ID reg
    sti
    and   al, 0c0h    ;strip all but FIFO bits
    jz   endudet     ;if bits 0, 16450/16550
    inc   ch       ;assume type 2
    mov   dx, bx
    add   dx, 8003h    ;point to enhanced reg 1
    cli
    in   al, dx
    push  ax
    or   al, 01000000b  ;enable DMA transmission
    out   dx, al
    push  dx
    mov   dx, bx
    add   dx, 2
    in   al, dx
    mov   cl, al
    pop   dx       ;restore enhanced reg 1
    pop   ax
    out   dx, al
    sti
    and   cl, 0c0h    ;again mask all but FIFO ID
    cmp   cl, 40h
    jne   endudet     ;must be type 2 (FIFO)
    inc   ch       ;must be type 3 (DMA)
endudet:
    pop   ax
    mov   dx, bx
    add   dx, 4      ;point to modem ctrl reg
    out   dx, al     ;restore initial condition
    xor   ax, ax
    mov   al, ch
    mov   dx, bx
    pop   cx
    pop   bx
    ret
uartdet endp
disp  proc  near
    push  ax   ;save AX
    cmp   al, 0  ;no serial ports?
    je   noports
    mov   bx, offset ds:[uart1]  ;offset of UART type field
    mov   di, offset ds:[portmsg][3] ;offset of 4th char in message
    mov   cx, 0
    mov   cl, al ;number of iterations
@l1:
    ;
    ;write "COMx: " message substituting "x" for proper comport #
    ;
    mov   dl, 4
    sub   dl, cl
    add   dl, 30h ;convert to ASCII number
    mov   [di], dl
    lea   dx, portmsg
    mov   ah, 9
    int   21h
    ;
    ;write the UART type now
    ;
    mov   dl, [bx]
    cmp   dl, 0
    jne   @t2
    lea   dx, x8250
    mov   ah, 9
    int   21h
    jmp   @eot
@t2:  cmp   dl, 1
    jne   @t3
    lea   dx, x16450
    mov   ah, 9
    int   21h
    jmp   @eot
@t3:  cmp   dl, 2
    jne   @t4
    lea   dx, xfifo
    mov   ah, 9
    int   21h
    jmp   @eot
@t4:  lea   dx, xdma
    mov   ah, 9
    int   21h
@eot:  inc   bx
    loop  @l1
    jmp   eoproc2
noports:
    lea   dx, pas_de_ports
    mov   ah, 9
    int   21h
eoproc2:
    pop   ax
    ret
disp  endp
    ends
    end
; EOF SERTYPE.ASM

时间: 2024-10-31 16:57:35

汇编源码系列之sertype的相关文章

汇编源码系列之clear

这个都是过去DOS时代的汇编源码,虽然已经过去了,但是对于学习汇编还是有帮助的,汇编语言只是程序员一门基础语言,大多人掌握即可,不一定要深入研究....... name clear page 55,132 title 'CLEAR --- control PC display';; CLEAR Utility to clear display; and set character attributes;; Ray Duncan, Uncopyright (u) August 1983; This

汇编源码系列之clock

这个都是过去DOS时代的汇编源码,虽然已经过去了,但是对于学习汇编还是有帮助的,汇编语言只是程序员一门基础语言,大多人掌握即可,不一定要深入研究....... CGROUP GROUP VECTOR,CODESEGVECTOR SEGMENT AT 0H DB 6CH DUP(?) ;FILLERTIME_LO DW ? ;DOS TIMETIME_HI DW ? ;DOS TIMEVEC_IP DW ;CLOCK UPDATE VECTOR IPVEC_CS DW ;CLOCK UPDATE

汇编源码系列之charop

这个都是过去DOS时代的汇编源码,虽然已经过去了,但是对于学习汇编还是有帮助的,汇编语言只是程序员一门基础语言,大多人掌握即可,不一定要深入研究....... title MSDOS 2.00 Function Library for Lattice Csubttl -;;;;FUNCTION: Sets and returns switch char-;; acter and device availability.;;;;;;CALL:;;;; ret= _charop(al,dl);; i

汇编源码系列之clean

这个都是过去DOS时代的汇编源码,虽然已经过去了,但是对于学习汇编还是有帮助的,汇编语言只是程序员一门基础语言,大多人掌握即可,不一定要深入研究....... name clean page 55,132 title 'CLEAN --- Filter text file';; CLEAN --- a utility to filter text files.; This program removes all control codes except; for line feeds, carr

汇编源码系列之cleanf

这个都是过去DOS时代的汇编源码,虽然已经过去了,但是对于学习汇编还是有帮助的,汇编语言只是程序员一门基础语言,大多人掌握即可,不一定要深入研究....... name cleanf page 55,132 title 'CLEANF - Filter text file';; CLEANF - a DOS 2.0 filter for word processing document files.;; CLEAN.ASM Originally written by Ray Duncan; Co

汇编源码系列之burnout

这个都是过去DOS时代的汇编源码,虽然已经过去了,但是对于学习汇编还是有帮助的,汇编语言只是程序员一门基础语言,大多人掌握即可,不一定要深入研究....... COMMENT * Demo (and semi-useful) program to read/set burnout device parameters. Usage: burnout [ticks] [C+-] [V+-] [H+-] Parameters can be separated by almost anything. W

汇编源码系列之calc

这个都是过去DOS时代的汇编源码,虽然已经过去了,但是对于学习汇编还是有帮助的,汇编语言只是程序员一门基础语言,大多人掌握即可,不一定要深入研究....... PAGE ,132 TITLE CALCCGROUP GROUP CODESEGCODESEG SEGMENT PARA PUBLIC 'CODE' ASSUME CS:CGROUP,DS:CGROUP,ES:CGROUP PUBLIC CALC ORG 100HCALC PROC FAR JMP START;--------------

汇编源码系列之char

这个都是过去DOS时代的汇编源码,虽然已经过去了,但是对于学习汇编还是有帮助的,汇编语言只是程序员一门基础语言,大多人掌握即可,不一定要深入研究....... ctable segment para public 'DATA db 9 dup(' ') db 9,10,' ',12,13 db 13 dup(' ') db 27 db 4 dup(' ') db ' !"#$%&',39,'()*+,-./0123456789:;<=>?@' db 'ABCDEFGHIJKL

汇编源码系列之brk

这个都是过去DOS时代的汇编源码,虽然已经过去了,但是对于学习汇编还是有帮助的,汇编语言只是程序员一门基础语言,大多人掌握即可,不一定要深入研究....... PGROUP Group PROGDGROUP Group DATADATA Segment Public 'DATA'public brkflagbrkflag DW 0DATA endsPROG Segment Para Public 'PROG'public TrapBreaassume cs:PGROUP,DS:DGROUPTra