home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / getbaud / getbaud.asm
Assembly Source File  |  1993-08-27  |  3KB  |  75 lines

  1. ;--------------------------------------------------------------------
  2. ; GetBaud Procedure for TASM - 08/26/93
  3. ; written by Dave Navarro, Jr.  (CIS 73002,3506)
  4. ;
  5. ;  This procedure is donated to the Public Domain with no
  6. ;  copyrights of any kind and may be used without restriction.
  7. ;
  8. ;  If you do make any changes, please send a copy to me on
  9. ;  Compuserve, either as electronic mail, or in the IBMPRO forum.
  10. ;
  11. ;--------------------------------------------------------------------
  12. ; GetBaud - Get the baud rate of the specified port
  13. ;       Call with:  Port number (1-4) on stack
  14. ;         Returns:  DX:AX baud rate of specified port
  15.  
  16.  
  17. Code    Segment Byte
  18.         Assume  CS: Code
  19.  
  20. HighBaud DD     115200
  21.  
  22.         Public  GetBaud
  23.  
  24. GetBaud Proc    Far
  25.  
  26. ARG     Port:   WORD = Retbytes
  27.  
  28.         push    BP                      ;
  29.         mov     BP,SP                   ;
  30.         push    DS                      ;
  31.  
  32.         xor     DX,DX                   ; clear DX
  33.         mov     AX, Port                ; get port number
  34.         or      AX,AX                   ; is it 0?
  35.         jz      Exit                    ; yes, exit
  36.         cmp     AX,4                    ; is it greater than 4?
  37.  
  38.         ja      Exit                    ; yes, exit
  39.         shl     AX,1                    ; multiply it times 2
  40.         add     AX,3FEh                 ; add 3FEh to it
  41.         mov     DS,DX                   ; put segment into DS
  42.         mov     BX,AX                   ; put offset into BX
  43.         mov     DX, DS: [BX]            ; get port address
  44.  
  45.         add     DX,3                    ; line control register
  46.         in      AL,DX                   ; get status
  47.         push    AX                      ; save it
  48.         or      AL,80h                  ; set Divisor Latch Bit on
  49.         out     DX,AL                   ; turn on Divisor Latch Bit
  50.         sub     DX,3                    ; port i/o address
  51.         in      AL,DX                   ; get lsb of divisor
  52.  
  53.         mov     BL,AL                   ; save it
  54.         inc     DX                      ; port i/o address + 1
  55.         in      AL,DX                   ; get msb of divisor
  56.         mov     BH,AL                   ; save it
  57.         pop     AX                      ; get old status
  58.         add     DX,2                    ; line control register
  59.         out     DX,AL                   ; restore status
  60.  
  61.         mov     AX, Word ptr HighBaud+2 ; high part of maxium baud
  62.         xor     DX, DX                  ; clear DX
  63.         div     BX                      ; divide
  64.         mov     CX, AX                  ; hold high part of result
  65.         mov     AX, Word ptr HighBaud   ; DX has remainder of first half divide
  66.         div     BX                      ; divide
  67.  
  68.         xchg    CX, DX                  ; result in DX:AX, remainder in CX
  69. Exit:
  70.         pop     DS                      ;
  71.         pop     BP                      ;
  72.         retf    RetBytes                ;
  73. Getbaud EndP
  74. Code    EndS
  75.         End