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