home *** CD-ROM | disk | FTP | other *** search
/ TopWare Tools / TOOLS.iso / tools / top1190 / devices.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-31  |  17.2 KB  |  362 lines

  1. Title   DeviceS.ASM -- Display DOS Device Chain - 22-May-1989 - 03:10
  2.         DOSSEG
  3.         .MODEL  small
  4.         .STACK
  5.         .DATA
  6. Fail DB ' Device Header Chain NOT Found '
  7. FlgS DW 4C00h,0,0                       ; ErrLvl, Last Drive & RePlaced
  8. Kind DB 'BlockDrivesABCDEFGHIJKLMNetWorkCharacterReplacedMappable Drives'
  9.      DB 'System Date/TimeEMMXXXX0Expanded Mem MgrXMFXXXX0HI-MEM Busy Rpt'
  10. NewL DB 13,10,'        $'
  11. HdgM DB ' Address Strat Inter Attr Type Device  Name         Remarks     '
  12. Dev  Struc
  13.      DB 'R',63  DUP (32)
  14. Dev     EndS
  15. DevS    Dev 32  DUP (<>)
  16. sz      Equ SIZE    Dev
  17.         .CODE
  18. Main    Proc
  19.         mov     ax,@data                ; Make Data
  20.         mov     ds,ax                   ; Addressable
  21.         mov     ax,40h                  ; Search Data
  22.         mov     es,ax                   ; Segment of
  23.         xor     di,di                   ; DOS for
  24.         mov     al,'C'                  ; CON Device
  25.         mov     dl,'O'                  ; Segment to
  26.         mov     dh,'N'                  ; Store NUL and
  27.         mov     cx,-1                   ; Other Devices
  28.         xor     bp,bp                   ; Within DevS Array and
  29.         call    DevFind                 ; Make Data Addressable by
  30.         mov     ax,@data                ; Extra Segment Register
  31.         mov     es,ax                   ; If DeviceS Found
  32.         jnz     DoHdr                   ; Then Display Heading
  33.         mov     byte ptr FlgS,1         ; Else Display
  34.         mov     dx,offset Fail          ; Error Message
  35.         mov     cx,31                   ; and Exit
  36.         jmp     short Show
  37. DoHdr:  mov     dx,offset HdgM          ; Heading
  38.         mov     cx,sz                   ; Line
  39.         call    ShowMsg
  40.         mov     bx,bp                   ; Set Limit for Sort by
  41.         xor     bp,bp                   ; Ascending Addresses
  42.         call    DevSort
  43. DoDev:  mov     dx,offset DevS          ; Point to DeviceS at
  44.         add     bp,sz                   ; Place Where Unit(s)
  45.         add     dx,bp                   ; Will be Changed to
  46.         mov     di,dx                   ; Disk Drive Letters
  47.         add     di,40
  48.         mov     cx,sz                   ; Set Line Length
  49. Show:   call    ShowMsg                 ; If More Lines
  50.         cmp     bp,bx                   ; To be Displayed
  51.         jc      DoDev                   ; Then Loop for Next
  52. Exit:   mov     ah,9                    ; Else End
  53.         mov     dx,offset NewL          ; Last Line
  54.         int     21h
  55.         mov     ax,FlgS                 ; ErrorLevel
  56.         int     21h                     ; Exit to DOS
  57. Main    EndP
  58.  
  59. DevSort Proc
  60.         add     bp,sz                   ; If Next Device Level
  61.         mov     dx,bp                   ; Is ABOVE the Top Floor
  62.         cmp     bp,bx                   ; Then Sorting is Done
  63.         ja      DSexit                  ;
  64.         mov     cx,8                    ; Else If Address
  65.         mov     si,offset DevS          ; Of Device at
  66.         add     si,bp                   ; New Level is
  67.         mov     di,si                   ; Less Than Next
  68.         add     di,sz                   ; Level Address
  69.         rep     cmpsb
  70.         jc      DevSort                 ; Then Advance
  71.         mov     cx,sz                   ; Else Copy
  72.         mov     si,offset DevS          ; Next Level
  73.         add     si,bp                   ; Device Line
  74.         add     si,sz                   ; Into Basement or
  75.         mov     di,offset DevS          ; Zero Array Member
  76.         push    si
  77.         rep     movsb
  78.         mov     cx,sz                   ; Copy
  79.         mov     si,offset DevS          ; Current
  80.         add     si,bp                   ; Level Into
  81.         pop     di                      ; Level Above
  82.         rep     movsb
  83.         mov     cx,sz                   ; Complete
  84.         mov     si,offset DevS          ; Swap by
  85.         mov     di,si                   ; Copying Zero
  86.         add     di,bp                   ; Level to Current
  87.         rep     movsb
  88. DSsink: cmp     bp,sz                   ; If ABOVE Ground Level
  89.         ja      DSdown                  ; Then Sink to the Ground
  90. DSdone: mov     bp,dx                   ; Else Restore Pre-Sink Level
  91.         jmp     short DevSort           ;  and Resume Sort Ascending
  92.  
  93. DSdown: mov     cx,8                    ; Compare the
  94.         mov     di,offset DevS          ; Current Level
  95.         add     di,bp                   ; Address With
  96.         mov     si,di                   ; Address in
  97.         sub     si,sz                   ; Lower Level
  98.         rep     cmpsb                   ; If Current Higher
  99.         jc      DSdone                  ; Then Sinking Done
  100.         mov     si,offset DevS          ; Else Copy
  101.         mov     di,si                   ; Lower Level
  102.         add     si,bp                   ; Device Line
  103.         sub     si,sz                   ; Into Zero or
  104.         mov     cx,sz                   ; Basement Level
  105.         rep     movsb
  106.         mov     di,si                   ; Copy Current
  107.         sub     di,sz                   ; Into Lower
  108.         mov     cx,sz
  109.         rep     movsb
  110.         mov     si,offset DevS          ; Complete Swap by
  111.         mov     di,si                   ; Moving Previous
  112.         add     di,bp                   ; From Basement
  113.         mov     cx,sz                   ; Into Current
  114.         rep     movsb
  115.         sub     bp,sz                   ; Do Next Lower Level
  116.         jmp     short DSsink            ; Until Ground Level
  117. DSexit: Xor     bp,bp                   ; Return BP=basement
  118.         ret                             ;    and BX=top floor
  119. DevSort EndP
  120.  
  121. DevFind Proc
  122.         repne   scasb                   ; If NO "C"
  123.         jcxz    DFexit                  ; Then Exit
  124.         jne     DevFind                 ; Else If
  125.         cmp     es:[di],dx              ; NO C"ON"
  126.         jne     DevFind                 ; Then Look On
  127.         mov     bx,es:[di-7]            ; Or If Attribute
  128.         and     bx,801Fh                ; Word Is NOT
  129.         cmp     bx,8013h                ; One for CON
  130.         jne     DevFind                 ; Then Look Further
  131.         sub     di,11                   ; Else Use Next
  132.         mov     es,es:[di+2]            ; Device Segment to
  133.         xor     di,di                   ; Scan for "NU"L
  134.         mov     ax,'UN'                 ; Device Header
  135.  
  136. FNloop: repne   scasw                   ; If Search in Vain
  137.         jcxz    DFexit                  ; Then Zero Flag Exit
  138.         cmp     byte ptr es:[di],"L"    ; Else If NOT NU"L"
  139.         jne     FNloop                  ; Then Look Some More
  140.         mov     bx,es:[di-8]            ; Else If Attribute
  141.         and     bx,801Fh                ; Word Is NOT Right
  142.         cmp     bx,8004h                ;  for NUL Device
  143.         jne     FNloop                  ; Then Look Some More
  144.         push    cx                      ; Else Preserve Counter
  145.         sub     di,12                   ; Store NUL Data First
  146.  
  147. DFnext: add     bp,sz                   ; Index of Next
  148.         mov     bx,offset DevS          ; Array Member
  149.         Call    DevLine                 ; Store Device Data
  150.         mov     bx,es:[di]              ; Adjust ES:DI to
  151.         mov     es,es:[di+2]            ; Next Device Address
  152.         mov     di,bx                   ; If Next Offset
  153.         cmp     bx,-1                   ; Is NOT End of Chain
  154.         jne     DFnext                  ; Then Store Next Member
  155.         pop     cx                      ; Else Restore Counter
  156. DFexit: cmp     cx,0                    ; Return NZ If Found
  157.         ret                             ; OR ZR If NOT Found
  158. DevFind EndP
  159.  
  160. DevLine Proc
  161.         mov     ax,es                   ; Store Segment
  162.         add     bx,bp                   ; of Next Device
  163.         call    AX2ASCh                 ; as HEX Address
  164.         push    di                      ; Preserve and
  165.         mov     ax,di                   ; Store Offset
  166.         call    AX2ASCh                 ; HEX Address
  167.         mov     ax,es:[di+6]            ; Store Strategy
  168.         call    AX2ASCh                 ; Offset HEX Word
  169.         mov     ax,es:[di+8]            ; Store Interrupt
  170.         call    AX2ASCh                 ; Offset HEX Word
  171.         mov     ax,es:[di+4]
  172.         inc     bx                      ; Position for
  173.         mov     dx,ax                   ; Attributes
  174.         call    AX2ASCh                 ; Storage
  175.         add     di,10                   ; If Attribute of
  176.         test    dx,8000h                ; Character Device
  177.         jnz     DoName                  ; Then Has a Name
  178.         mov     si,offset Kind          ; Else Copy
  179.         mov     cx,5                    ; "Block"
  180.         call    SI2BX                   ; Type
  181.         test    ax,1000h                ; If NOT NetWork
  182.         jz      DoDisk                  ; Then Is Disk Drive
  183.         add     si,20                   ; Else Point Source to
  184.         mov     cx,8                    ; Copy "NetWork " to
  185.         add     bx,cx                   ; Name Field and
  186.         call    SI2BX                   ; End The Record
  187.         jmp     DLdone
  188. DoDisk: inc     bx                      ; Leave a Space
  189.         mov     al,es:[di]              ; If Number of
  190.         aam                             ; Units is More
  191.         cmp     al,1                    ; Than Singular
  192.         mov     cx,6                    ; Then "Drives"
  193.         ja      Drives                  ; Else Cut to
  194.         dec     cx                      ; "Drive"
  195. Drives: push    bx                      ; Preserve Destination
  196.         call    SI2BX                   ; While Outputting
  197.         pop     bx                      ; So As to be Able to
  198.         add     bx,8                    ; Find "Name" Location
  199.         mov     [bx],al                 ; and Store Unit(s)
  200.         cmp     dx,0840h                ; If NOT OCRM and IOCTL
  201.         jne     DLlily                  ; Then NO Remarks
  202.         mov     si,offset Kind+48       ; Else Make
  203.         add     bx,8                    ; Remark
  204.         mov     cx,15                   ; "Mappable
  205.         call    SI2BX                   ;  Drives"
  206. DLlily: jmp     DLdone                  ; Lily Pad to Done
  207. DoName: mov     si,offset Kind+31       ; Store Type as
  208.         mov     cx,9                    ; "Character"
  209.         call    SI2BX
  210.         add     bx,4                    ; Adjust Pointer to
  211.         xor     si,si                   ; "Name" Zero Offset
  212.         xchg    si,bx                   ; Swap Pointers to
  213.         mov     cx,8                    ; Copy "dev_Name"
  214. DNloop: mov     al,es:[di+bx]           ; Put a Name
  215.         mov     ds:[si+bx],al           ; Byte in Data
  216.         inc     bx                      ; Advance Index
  217.         loop    DNloop                  ; Until 8 Bytes
  218.         add     bx,si                   ; Point to
  219.         inc     bx                      ; "Remarks"
  220.         mov     si,offset Kind+79       ; If "EMMXXXX0"
  221.         push    di                      ; Is NOT
  222.         mov     cx,8                    ; Name In
  223.         rep     cmpsb                   ; Device Line
  224.         pop     di                      ; Restored
  225.         jne     HIMEM?                  ; Then Check HI-MEM
  226.         jmp     short DLlast            ; Else Copy Remark
  227. HIMEM?: mov     si,offset Kind+103      ; If "XMFXXXX0"
  228.         mov     cx,8                    ; Is NOT Name
  229.         rep     cmpsb                   ; In Device Line
  230.         jne     DLbusy                  ; Then Check Busy
  231.         mov     cx,7                    ; Else Copy "HI-MEM "
  232.         call    SI2BX                   ; Into Remarks
  233. DLbusy: test    dx,2000h                ; If NOT Busy
  234.         jz      DL?CON                  ; Then CONorCLK Replaced?
  235.         mov     si,offset Kind+117      ; Else " Busy Rpt"
  236.         mov     cx,9
  237.         call    SI2BX
  238. DL?CON: mov     si,offset Kind+40       ; Pointer to
  239.         mov     cx,8                    ; "Replaced"
  240.         cmp     dx,8013h                ; If NOT CON
  241.         jne     DL?CLK                  ; Then Clock?
  242.         test    byte ptr FlgS+4,3       ; Else If Previous
  243.         jnz     DLrepl                  ; Then IS Replaced
  244.         or      byte ptr FlgS+4,3       ; Else Flag First
  245.         jmp     short DLdone
  246. DL?CLK: cmp     dx,8008h                ; If NOT Clock
  247.         jne     DLdone                  ; Then Line Done
  248.         test    byte ptr FlgS+5,8       ; Else If Previous
  249.         jnz     DLrepl                  ; Then IS Replaced
  250.         or      byte ptr FlgS+5,8       ; Else Flag System Clock
  251.         mov     si,offset Kind+63
  252. DLlast: mov     cx,16                   ; Copy Full Width
  253.         call    SI2BX                   ; Remark and Done
  254.         jmp     short DLdone
  255. DLrepl: push    cx                      ; Remark IS
  256.         call    SI2BX                   ; "Replaced"
  257.         mov     si,offset HdgM+30       ; " Device "
  258.         pop     cx
  259.         call    SI2BX
  260. DLdone: pop     di                      ; Restore Offset
  261.         ret                             ; to Device Header
  262. DevLine EndP
  263.  
  264. SI2BX   Proc
  265.         push    ax
  266. SI2BXl: lodsb                           ; Transfer CX
  267.         mov     [bx],al                 ; Characters
  268.         inc     bx                      ; From [SI] to [BX]
  269.         loop    SI2BXl                  ; SI and BX are
  270.         pop     ax                      ; Advanced by CX
  271.         ret
  272. SI2BX   EndP
  273. AX2ASCh Proc
  274.         push    ax                      ; Preserve Value
  275.         mov     al,ah                   ; Copy High Byte
  276.         call    AX2HEX                  ; Do 2 HEX Digits
  277.         add     bx,2                    ; Advance Index
  278.         pop     ax                      ; Restore Value
  279.         call    AX2HEX                  ; Do 2 HEX Digits
  280.         add     bx,3                    ; Advance Index
  281.         ret
  282. AX2ASCh Endp
  283.  
  284. AX2HEX  Proc
  285.         mov     ah,al                   ; Preserve Byte
  286.         mov     cx,4                    ; Isolate High
  287.         shr     al,cl                   ; Nibble and
  288.         call    AL2HEX                  ; Make HEX
  289.         mov     [bx],al                 ; Store it
  290.         mov     al,ah                   ; Recover Byte
  291.         and     al,0Fh                  ; Isolate Low
  292.         call    AL2HEX                  ; Nibble to
  293.         mov     [bx+1],al               ; HEX digit
  294.         ret
  295. AX2HEX  EndP
  296.  
  297. AL2HEX  Proc
  298.         add     al,'0'                  ; Make ASCII
  299.         cmp     al,'9'                  ; If Decimal
  300.         jle     ALexit                  ; Then Ok for HEX
  301.         add     al,7                    ; Else Make Letter
  302. ALexit: ret
  303.  
  304. AL2HEX  EndP
  305.  
  306. ShowMsg Proc
  307.         push    bx                      ; Preserve
  308.         push    cx                      ; Counts and
  309.         mov     si,dx                   ; Pointer
  310.         mov     dx,offset NewL          ; Carriage
  311.         mov     ah,9                    ; Return and
  312.         int     21h                     ; Line Feed
  313.         pop     cx                      ; Restore Count
  314.         cmp     byte ptr [si],' '       ; If a Record
  315.         jne     SMproc                  ; Then Process
  316.         mov     bx,09h                  ; Else Underline
  317.         jmp     short SMnext
  318. SMproc: mov     al,es:[di]              ; If Byte as a
  319.         cbw                             ; Word Value
  320.         cmp     al,' '                  ; Is Printable
  321.         jnc     SMblue                  ; Then Display
  322.         push    si                      ; Else Preserve
  323.         mov     si,FlgS+2               ; Pointer While
  324.         add     si,offset Kind+11       ; Up-Date Next
  325.         add     FlgS+2,ax               ; Drive Letter
  326.         movsb                           ; Replace Unit(s)
  327.         dec     ax                      ; If UnitS
  328.         jnz     SMmore                  ; Then Show More
  329.         pop     si                      ; Else Restore
  330.         jmp     short SMblue            ; Display Pointer
  331.  
  332. SMmore: dec     ax                      ; Adjust for
  333.         add     si,ax                   ; Last Drive
  334.         lodsb                           ; Letter and
  335.         mov     ah,' '                  ; Put Space
  336.         xchg    ah,al                   ; Ahead of it
  337.         push    ax                      ; Store
  338.         mov     ah,'-'
  339.         stosw                           ; " - " and Last
  340.         pop     ax
  341.         stosw                           ; Store Last and
  342.         pop     si                      ; Restore Pointer
  343. SMblue: mov     bx,1Fh                  ; White on Blue
  344.         mov     di,si                   ; Adjust Index to
  345.         add     di,sz                   ; Next Record
  346. SMnext: cmp     cx,12h                  ; When Down to
  347.         jnc     SMcolr                  ; Below 18 Bytes
  348.         mov     bx,4Fh                  ; Use White on Red
  349. SMcolr: push    cx                      ; Preserve Count
  350.         mov     cx,1                    ; While We
  351.         mov     ax,920h                 ; Color me
  352.         int     10h                     ; "purple"
  353.         pop     cx                      ; Restore Count
  354.         mov     ah,0Eh                  ; Teletype
  355. SMbyte: lodsb                           ; Bytes
  356.         int     10h                     ; Until
  357.         loop    SMnext                  ; CX done
  358.         pop     bx
  359.         ret
  360. ShowMsg EndP
  361.         End     Main
  362.