home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / asm / SDETECT.ZIP / SDETECT.ASM next >
Encoding:
Assembly Source File  |  1991-11-20  |  3.6 KB  |  133 lines

  1.     .model    small,c
  2. ;
  3. ; The following code assumes small C model (DS=SS).
  4. ;
  5. ; Intended usage:
  6. ;
  7. ;    if ((detect_stacker() != 0)
  8. ;    && (detect_stacker_drive(driveNumber) != 0)
  9. ;          printf("Drive %c is a Stacker drive",'A'+driveNumber);
  10. ;    else
  11. ;          printf("Drive %c is a not a Stacker drive",'A'+driveNumber);
  12. ;
  13.     .DATA
  14. ST_PTR    DD    0            ;pointer to Stacker (0-->not there)
  15.  
  16.     .CODE
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18. ;
  19. ;
  20. ; C declaration:  int detect_stacker(void); 
  21. ;
  22. ; Input: None
  23. ; Output:AX=0  --> Stacker not installed
  24. ;     AX<>0 --> Stacker version*100  (e.g.  1.00 --> 0064H)
  25. ;    
  26. ;    Stacker is detected by making an INT 25H call with invalid
  27. ;    parameters.
  28. ;
  29.  
  30.     PUBLIC detect_stacker
  31.  
  32. detect_stacker proc
  33.     push    bp
  34.     push    si
  35.     push    di
  36.  
  37.     sub    sp,1024            ;use the stack as a temp buffer
  38.                     ;(in case INT 25 returns something!)
  39.  
  40.     mov    ax,0cdcdh        ;invalid drive #
  41.     mov    bx,sp            ;DS:BX --> buffer for INT 25H
  42.     mov    cx,1
  43.     xor    dx,dx            ;read boot sector of invalid drive
  44.     mov    word ptr [bx],dx    ;clear the "return" value
  45.     push    ds            ;(set ES:BP to fix DOS 3 INT 25H bug
  46.     pop    es            ; dealing with invalid drives)
  47.     mov    bp,bx
  48.     int    25H
  49.     pop    cx            ;get rid of flags
  50.  
  51.     xor    ax,ax            ;default is No stacker
  52.     mov    bx,sp            ;point at result
  53.     cmp    word ptr [bx],0CDCDH    ;Stacker INT 25 fills in some fields.
  54.     jnz    gotres            ;Make sure they all match
  55.     cmp    word ptr 2[bx],1
  56.     jnz    gotres
  57.     les    di,4[bx]        ;pointer into Stacker
  58.     cmp    word ptr es:[di],0A55AH    ;must find signature
  59.     jnz    gotres
  60.     mov    word ptr st_ptr  ,di    ;save pointer to show it's found
  61.     mov    word ptr st_ptr+2,es
  62.     mov    ax,es:[di+2]        ;stacker version * 100
  63. gotres:
  64.     add    sp,1024
  65.  
  66.     pop    di            ;restore regs
  67.     pop    si
  68.     pop    bp
  69.     ret
  70. detect_stacker    endp
  71.  
  72. ;
  73. ; C declaration:  int detect_stacker_drive(int driveno);
  74. ;
  75. ; Input: driveno: 0=A, 1=B, 2=C, etc.
  76. ;
  77. ; Output:AX=0 --> Is not a Stacker drive
  78. ;     AX=1 --> Is a Stacker drive
  79. ;    
  80. ; Notes:
  81. ;     In a multitasking environment (e.g. Windows), or with certain TSRs
  82. ;     present, this test may fail if a background process accesses a 
  83. ;     Stacker drive at just the right time, modifying the UNIT_OFFS global
  84. ;     in the Stacker resident driver.  Most Stacker utilities call this
  85. ;     routine until the same result is returned several times in a row,
  86. ;     in order to circumvent this potential (but rare) problem.
  87. ;
  88. ;     This function uses the removeable media ioctl call to detect 
  89. ;     Stacker drives.  However, under DR DOS 5.0, the get logical
  90. ;     device call (440EH) is used, since DR DOS does NOT pass these
  91. ;     calls through to the Stacker device driver.
  92. ;
  93.  
  94. UNIT_OFFS equ    3EH            ;offset with Stacker of 
  95.  
  96.     PUBLIC detect_stacker_drive
  97.  
  98. detect_stacker_drive proc driveno:word
  99.     uses    di,si
  100.  
  101.     cmp    word ptr st_ptr+2,0    ;already found Stacker?
  102.     jnz    stacker_fnd2
  103.     call    detect_stacker        ;if not, try again
  104.     xor    ax,ax            ;return 0 if not found
  105.     cmp    ax,word ptr st_ptr+2    ;is it there?
  106.     jnz    stacker_fnd2        ;
  107. notstk2:ret
  108.     ; Here if Stacker IS installed.
  109. stacker_fnd2:
  110.     mov    ah,30h            ;see if DOS 3.31 (DR DOS or Compaq)
  111.     int    21h            ;handle Compaq 3.31 like DR DOS
  112.     cmp    ax,1F03H
  113.     mov    ax,4408H        ;do an ioctl call (removeable media)
  114.     jnz    chkDrive
  115.     mov    ax,440EH        ;(get logical device for DOS 3.31)
  116. chkDrive:
  117.     mov    bx,driveno
  118.     inc    bx            ;adjust for default
  119.  
  120.     les    di,st_ptr
  121.     mov    byte ptr es:UNIT_OFFS[di],0FFH    ;set unit # in resident driver
  122.     int    21h            ;make the ioctl call
  123.     les    di,st_ptr        ;see if unit # changed during call
  124.     mov    bl,byte ptr es:UNIT_OFFS[di]
  125.  
  126.     xor    ax,ax
  127.     cmp    bl,0FFH            ;set carry unless BL= 0FFH
  128.     adc    al,0            ;propagate carry into AL
  129.     ret
  130. detect_stacker_drive endp
  131.  
  132.     end
  133.