This is the past DOS era of the compilation of source code, although has passed, but for the study of the assembly is still helpful, assembly language is just a basic programmer language, most people can grasp, not necessarily in-depth research.
; Drive detection By:lee Hamel (hamell@cs.pdx.edu)-July 6th, 1994
; Partial Credit To:paul Schlyter
;
; Goes thru Drives-A-Z and determines if they:
; 1) Exist
; 2) Are removable or fixed
; 3) Are local, remote, or shared
; 4) Are a floppy, hard, RAM, subst, or CD-ROM drive
. Model Tiny
.286
Drivexists EQU 1
Removedrv EQU 0
Fixeddrv EQU 1
Localdrv EQU 0
Remotedrv EQU 1
Sharedrv EQU 2
Floppy EQU 0
HARD EQU 1
RAM EQU 2
SUBST EQU 3
CDROM EQU 4
. Code
Org 100h
Start:mov ah,19h
int 21h; Get Start Drive
mov [curdrive],al
MOV ax,40h
MOV Es,ax
mov bh,es:[10h]; 40:10H is # of floppies-1
SHR bh,6
Inc BH; # of actual floppy drives
MOV bl,1
MOV Di,offset drives
Nextchkfloppy:mov ax,4409h; Check if drive exists
int 21h
JC Nextsetfloppy
Test dh,10000000b; Check if SUBST drive
JZ Chkfloppy
Dec BH; Dec Actual drive Count
mov byte ptr [di+3],subst
Setfloppyexist:mov byte ptr [di],drivexists
JMP Nextsetfloppy
Chkfloppy:dec BH; Dec Actual drive Count
JS Nextsetfloppy
mov byte ptr [di+1],removedrv
mov byte ptr [di+3],floppy
JMP setfloppyexist
Nextsetfloppy:add di,4
Inc BL
CMP bl,2; If B then jump back
Je nextchkfloppy
MOV ch,24; Loop times (Drives C-z)
MOV cl,3; Start at C:
Drivechkloop:mov ax,4409h; Check if drive exists
MOV bl,cl; Set Drive letter
int 21h; 0 = default, 1 = A:, etc.
JC Nextsetdrv
mov byte ptr [di],drivexists
MOV ax,4408h; Check if removable
int 21h
mov byte ptr [di+1],al; Set removable or FIXED
MOV bx,dx
MOV Dl,dh
SHR dl,7
and dh,00010000b
SHR dh,4
mov byte ptr [DI+2],DH; Set REMOTE or Local
or DL,DL; If not SUBST, then jump
JZ Chkremote
mov byte ptr [di+3],subst
JMP Nextsetdrv
CHKREMOTE:CMP Dh,remotedrv; If REMOTE, then check for CD ROM
Je chkcdrom
Test bh,00000010b; Sharable?
JZ Drivenoshare
mov byte ptr [di+2],sharedrv
Drivenoshare:test bl,00000010b; RAM Drive?
JNZ nextsetdrv
mov byte ptr [di+3],ram
JMP Nextsetdrv
Chkcdrom:push CX
MOV ax,1500h
XOR BX,BX
int 2FH
Pop CX
or BX,BX; MSCDEX driver found?
JZ nextsetdrv; If not, jump to next drive setup
MOV AX,150BH
DEC cl; 0=a:, etc.
int 2FH
INC CL
or Ax,ax
JZ nextsetdrv; Drive supported by MSCDEX?
mov byte ptr [di+3],cdrom
Nextsetdrv:add di,4
INC CL
Dec CH
JNZ Drivechkloop
MOV Ah,0eh
MOV dl,[curdrive]
int 21h; Reset Start Drive
MOV cl, ' A '; Output all existing drives
MOV Di,offset drives
MOV ah,9
DRVDUMPLOOP:CMP byte ptr [di],drivexists
Jne Nextdrvdump
MOV al,cl
int 29h
XOR DH,DH
mov dl,byte ptr [di+1]
SHL dx,4
Add Dx,offset removablemsg
int 21h
XOR DH,DH
mov dl,byte ptr [di+2]
SHL dx,3
Add Dx,offset localmsg
int 21h
XOR DH,DH
mov dl,byte ptr [di+3]
SHL dx,3
Add Dx,offset typemsg
int 21h
MOV dx,offset CRLF
int 21h
Nextdrvdump:add di,4
INC CL
CMP cl, ' Z '
Jbe Drvdumploop
Ret
Curdrive DB 0
Drives DB DUP (0,1,0,1)
; Default to don't exist, fixed, local, hard drive
CRLF DB 10, 13, ' $ '
Removablemsg db ': Removable $ '
DB ': Fixed $ '
Localmsg DB ' local $ '
DB ' Remote $ '
DB ' Shared $ '
Typemsg DB ' Floppy $ '
DB ' Hard $ '
DB ' RAM $ '
DB ' Subst $ '
DB ' CD-ROM $ '
End Start