home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / sampler1 / dev.asm < prev    next >
Assembly Source File  |  1985-08-28  |  6KB  |  234 lines

  1.         name    dev
  2.         page    60,132
  3.         title   'DEV --- Report installed device drivers'
  4.  
  5. ; DEV --- a utility to report device header information for
  6. ;         all installed device drivers
  7. ; Requires PC-DOS or MS-DOS 2.0.
  8. ;
  9. ; Used in the form:
  10. ; A>DEV 
  11. ;
  12. ; version 1.0   December 12, 1984
  13. ; Copyright (c) 1984 by Ray Duncan
  14.  
  15. cr      equ     0dh             ;ASCII carriage return
  16. lf      equ     0ah             ;ASCII line feed
  17. blank    equ    20h        ;ASCII space code
  18. eom    equ    '$'        ;end of string marker
  19.  
  20.  
  21. cseg    segment    para public 'CODE'
  22.  
  23.     assume    cs:cseg,ds:data,es:data,ss:stack
  24.  
  25.  
  26. dev     proc    far             ;entry point from PC-DOS
  27.  
  28.         push    ds              ;save DS:0000 for final
  29.         xor     ax,ax           ;return to PC-DOS
  30.         push    ax
  31.         mov     ax,data         ;make our data segment
  32.     mov    ds,ax        ;addressable via DS and ES.
  33.     mov     es,ax 
  34.         mov     ah,30h        ;check version of PC-DOS.    
  35.         int     21h
  36.         cmp     al,2
  37.         jae     dev1        ;proceed, DOS 2.0 or greater.
  38.         mov     dx,offset msg2  ;DOS 1.x --- print error message.
  39.     jmp    dev6
  40.  
  41. dev1:    mov    cx,ax        ;save DOS version number.
  42.     mov    ah,15        ;now try and open the "NUL" device.
  43.     mov    dx,offset nulfcb
  44.     int    21h
  45.     or    al,al        ;opened successfully?
  46.     jz    dev2        ;yes, jump.
  47.     mov    dx,offset msg1    ;no, print error msg and exit.
  48.     jmp    dev6
  49.  
  50. dev2:                ;Pick up double pointer to device 
  51.                 ;driver chain out of reserved
  52.                 ;area in fcb.  This area is mapped
  53.                 ;differently in DOS 2.x and DOS 3.x.
  54.     cmp    cl,2        ;is this DOS 2.x?
  55.     ja    dev3        ;no, jump.
  56.     mov    bx,word ptr nulfcb+25
  57.     mov    es,word ptr nulfcb+27
  58.     jmp    dev4
  59.  
  60. dev3:                ;come here if DOS 3.0 or greater.
  61.     mov    bx,word ptr nulfcb+26
  62.     mov    es,word ptr nulfcb+28
  63.  
  64. dev4:    call    header        ;print sign-on message and 
  65.                 ;column headings.
  66.  
  67. dev5:                ;trace through the device chain
  68.  
  69.     call    prdev        ;print device header information
  70.                 ;for driver pointed to by ES:BX.
  71.                 ;pick up addr of next header.
  72.     les    bx,dword ptr es:[bx]
  73.     cmp    bx,-1        ;found last one yet?
  74.     jne    dev5        ;no, try next.
  75.     
  76.           mov    dx,offset msg3    ;yes, print "end of device chain".
  77.  
  78. dev6:     mov    ah,9        ;print the string whose address
  79.     int    21h        ;is in DX.
  80.     ret            ;then return to DOS.
  81.  
  82. dev       endp
  83.  
  84.  
  85. header    proc    near        ;print out headings for device
  86.     mov    dx,offset hdr    ;driver information.
  87.     mov    ah,9
  88.     int    21h
  89.     ret
  90. header    endp
  91.  
  92.  
  93. prdev    proc    near        ;print out device driver info.
  94.                 ;ES:BX is pointer to device header,
  95.                 ;which must be preserved.
  96.     mov    ax,es        ;convert segment of device header
  97.     mov    di,offset inf1
  98.     call    hexasc
  99.     mov    ax,bx        ;convert offset of device header.
  100.     mov    di,offset inf2
  101.     call    hexasc
  102.     mov    ax,es:[bx+4]    ;get attribute word, save a 
  103.     push    ax        ;copy of it, then convert it.
  104.     mov    di,offset inf3
  105.     call    hexasc
  106.     mov    ax,es:[bx+6]    ;convert ptr to device strategy.
  107.     mov    di,offset inf4
  108.     call    hexasc
  109.     mov    ax,es:[bx+8]    ;convert ptr to device int handler.
  110.     mov    di,offset inf5
  111.     call    hexasc
  112.  
  113.                 ;if not char device, clear out name
  114.                 ;field and set number of units.
  115.     pop    ax        ;get back attribute word.
  116.     test    ax,08000h    ;is bit 15 = 1 ?
  117.     jnz    prdev7        ;yes, it's character dev, jump.
  118.                           ;no, it's block device.
  119.                 ;set flag to skip device name.
  120.     mov     byte ptr inf8,eom
  121.     mov    al,es:[bx+10]    ;pick up number of units.
  122.     aam            ;convert to ASCII decimal and
  123.     add    ax,'00'        ;store into output string.
  124.     mov    byte ptr inf7+1,al
  125.     mov    byte ptr inf7,ah
  126.                 ;set type = B for Block
  127.     mov    byte ptr inf6,'B'    
  128.     jmp    prdev9
  129.  
  130. prdev7:                ;if char device, move its 8-character
  131.                 ;name into the output string.
  132.     xor    si,si
  133. prdev8:    mov    al,es:[si+bx+10]
  134.     mov    [si+inf8],al
  135.     inc    si
  136.     cmp    si,8
  137.     jne    prdev8
  138.                 ;remove # of units field.
  139.     mov    word ptr inf7,'  '
  140.                 ;set type = C for Character.
  141.     mov    byte ptr inf6,'C'
  142.  
  143. prdev9: mov    dx,offset inf    ;now print device information
  144.     mov    ah,9        ;and exit.
  145.     int    21h
  146.     ret
  147. prdev    endp
  148.  
  149. hexasc    proc    near        ;convert binary word to hex ASCII.
  150.                 ;call with AX=binary value
  151.                 ;          DI=addr to store string 
  152.                 ;returns AX, CX, DI destroyed.
  153.     push    ax        ;save copy of original value.
  154.     mov    al,ah
  155.     call    btoa        ;convert upper byte.
  156.     add    di,2        ;increment output address.
  157.     pop    ax
  158.     call    btoa        ;convert lower byte.
  159.     ret            ;return to caller.
  160. hexasc    endp
  161.  
  162. btoa    proc    near        ;convert binary byte to hex ASCII.
  163.                 ;call with AL=binary value 
  164.                 ;          DI=addr to store string
  165.                 ;returns AX, CX destroyed.
  166.     mov    ah,al        ;save lower nibble.
  167.     mov    cx,4        ;shift right 4 positions
  168.     shr    al,cl        ;to get upper nibble.
  169.     call    ascii        ;convert 4 bits to ASCII equivalent
  170.     mov    [di],al        ;store into output string.
  171.     mov    al,ah        ;get back lower nibble.
  172.     and    al,0fh
  173.     call    ascii        ;convert 4 bits to ASCII
  174.     mov     [di+1],al    ;and store into output string.
  175.     ret            ;back to caller.
  176. btoa    endp
  177.  
  178. ascii    proc    near        ;convert 4 lower bits of AL
  179.     add    al,'0'        ;into the equivalent ASCII char.
  180.     cmp    al,'9'        ;in the range {0...9,A...F}
  181.     jle    ascii2        ;and return char. in AL.
  182.     add    al,'A'-'9'-1    ;"fudge factor" for range A-F.
  183. ascii2:    ret            ;return to caller.
  184. ascii    endp
  185.  
  186. cseg    ends
  187.  
  188.  
  189. data    segment para public 'DATA'
  190.  
  191. msg1    db    cr,lf
  192.     db    'Failed to open NUL device.'
  193.     db    cr,lf,eom
  194.  
  195. msg2    db      cr,lf
  196.         db      'Requires DOS version 2 or greater.'
  197.         db      cr,lf,eom
  198.  
  199. msg3    db    cr,lf
  200.     db    'End of device chain.'
  201.     db    cr,lf,eom
  202.  
  203. hdr    db    cr,lf
  204.     db    'Addr      Attr '
  205.     db    'Str  Int   Type  Units  Name   '
  206.     db    eom
  207.  
  208.  
  209. inf     db    cr,lf
  210. inf1    db    'XXXX:'        ;seg device header
  211. inf2    db    'XXXX '        ;offs device header
  212. inf3    db    'XXXX '        ;attribute
  213. inf4    db    'XXXX '        ;strategy
  214. inf5    db    'XXXX   '    ;interrupt handler
  215. inf6    db    'X     '    ;type (block or char)
  216. inf7    db    'XX    '    ;units (if block device)
  217. inf8    db    '         '    ;name  (if char device)
  218.     db    eom
  219.  
  220.                 ;fcb to open NUL device
  221. nulfcb    db    0        ;drive
  222.     db    'NUL'        ;name of NUL device
  223.     db    8 dup (' ')
  224.     db    25 dup (0)
  225. data    ends    
  226.  
  227.  
  228. stack   segment para stack 'STACK'
  229.         db      64 dup (?)
  230. stack   ends
  231.  
  232.         end     dev
  233.