1 | ; Project name : Assembly Library
|
---|
2 | ; Description : Functions for accessing drives.
|
---|
3 |
|
---|
4 |
|
---|
5 | ; Section containing code
|
---|
6 | SECTION .text
|
---|
7 |
|
---|
8 | ;--------------------------------------------------------------------
|
---|
9 | ; Drive_GetNumberOfAvailableDrivesToAX
|
---|
10 | ; Parameters:
|
---|
11 | ; Nothing
|
---|
12 | ; Returns:
|
---|
13 | ; AX: Number of available drives
|
---|
14 | ; Corrupts registers:
|
---|
15 | ; Nothing
|
---|
16 | ;--------------------------------------------------------------------
|
---|
17 | ALIGN JUMP_ALIGN
|
---|
18 | Drive_GetNumberOfAvailableDrivesToAX:
|
---|
19 | push dx
|
---|
20 | push cx
|
---|
21 |
|
---|
22 | call Drive_GetFlagsForAvailableDrivesToDXAX
|
---|
23 | call Bit_GetSetCountToCXfromDXAX
|
---|
24 | xchg ax, cx
|
---|
25 |
|
---|
26 | pop cx
|
---|
27 | pop dx
|
---|
28 | ret
|
---|
29 |
|
---|
30 |
|
---|
31 | ;--------------------------------------------------------------------
|
---|
32 | ; Drive_GetFlagsForAvailableDrivesToDXAX
|
---|
33 | ; Parameters:
|
---|
34 | ; Nothing
|
---|
35 | ; Returns:
|
---|
36 | ; DX:AX: Flags containing valid drives (bit 0 = drive A, bit 1 = drive B ...)
|
---|
37 | ; Corrupts registers:
|
---|
38 | ; Nothing
|
---|
39 | ;--------------------------------------------------------------------
|
---|
40 | ALIGN JUMP_ALIGN
|
---|
41 | Drive_GetFlagsForAvailableDrivesToDXAX:
|
---|
42 | push cx
|
---|
43 | push bx
|
---|
44 | mov dx, DosCritical_HandlerToIgnoreAllErrors
|
---|
45 | call DosCritical_InstallNewHandlerFromCSDX
|
---|
46 |
|
---|
47 | call .GetNumberOfPotentiallyValidDriveLettersToCX
|
---|
48 | xor bx, bx
|
---|
49 | xor ax, ax ; Temporary use BX:AX for flags
|
---|
50 | cwd ; Start from drive 0
|
---|
51 | call .CheckDriveValidityUntilCXisZero
|
---|
52 | mov dx, bx ; Flags now in DX:AX
|
---|
53 |
|
---|
54 | call DosCritical_RestoreDosHandler
|
---|
55 | pop bx
|
---|
56 | pop cx
|
---|
57 | ret
|
---|
58 |
|
---|
59 | ;--------------------------------------------------------------------
|
---|
60 | ; .GetNumberOfPotentiallyValidDriveLettersToCX
|
---|
61 | ; Parameters:
|
---|
62 | ; Nothing
|
---|
63 | ; Returns:
|
---|
64 | ; CX: Number of potentially valid drive letters available
|
---|
65 | ; Corrupts registers:
|
---|
66 | ; AX, DX
|
---|
67 | ;--------------------------------------------------------------------
|
---|
68 | ALIGN JUMP_ALIGN
|
---|
69 | .GetNumberOfPotentiallyValidDriveLettersToCX:
|
---|
70 | call Drive_GetDefaultToAL
|
---|
71 | xchg dx, ax ; Default drive to DL
|
---|
72 | call Drive_SetDefaultFromDL
|
---|
73 | eMOVZX cx, al ; Number of potentially valid drive letters available
|
---|
74 | cmp cl, 32
|
---|
75 | jb SHORT .Return
|
---|
76 | mov cl, 32
|
---|
77 | ALIGN JUMP_ALIGN, ret
|
---|
78 | .Return:
|
---|
79 | ret
|
---|
80 |
|
---|
81 | ;--------------------------------------------------------------------
|
---|
82 | ; .CheckDriveValidityUntilCXisZero
|
---|
83 | ; Parameters:
|
---|
84 | ; CX: Number of potentially valid drive letters left
|
---|
85 | ; DL: Drive number (00h=A:, 01h=B: ...)
|
---|
86 | ; BX:AX: Flags for drive numbers
|
---|
87 | ; Returns:
|
---|
88 | ; BX:AX: Flags for valid drive numbers
|
---|
89 | ; Corrupts registers:
|
---|
90 | ; CX, DX
|
---|
91 | ;--------------------------------------------------------------------
|
---|
92 | ALIGN JUMP_ALIGN
|
---|
93 | .CheckDriveValidityUntilCXisZero:
|
---|
94 | call .IsValidDriveNumberInDL
|
---|
95 | jnz SHORT .PrepareToCheckNextDrive
|
---|
96 | call .SetFlagToBXAXfromDriveInDL
|
---|
97 | ALIGN JUMP_ALIGN
|
---|
98 | .PrepareToCheckNextDrive:
|
---|
99 | inc dx
|
---|
100 | loop .CheckDriveValidityUntilCXisZero
|
---|
101 | ret
|
---|
102 |
|
---|
103 | ;--------------------------------------------------------------------
|
---|
104 | ; .IsValidDriveNumberInDL
|
---|
105 | ; Parameters:
|
---|
106 | ; DL: Drive number (00h=A:, 01h=B: ...)
|
---|
107 | ; Returns:
|
---|
108 | ; ZF: Set if drive number is valid
|
---|
109 | ; Cleared if drive number is invalid
|
---|
110 | ; Corrupts registers:
|
---|
111 | ; Nothing
|
---|
112 | ;--------------------------------------------------------------------
|
---|
113 | ALIGN JUMP_ALIGN
|
---|
114 | .IsValidDriveNumberInDL:
|
---|
115 | push ds
|
---|
116 | push bx
|
---|
117 | push ax
|
---|
118 |
|
---|
119 | inc dx ; Default drive is 00h and first drive is 01h
|
---|
120 | mov ah, GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE
|
---|
121 | int DOS_INTERRUPT_21h
|
---|
122 | dec dx
|
---|
123 | test al, al
|
---|
124 |
|
---|
125 | pop ax
|
---|
126 | pop bx
|
---|
127 | pop ds
|
---|
128 | ret
|
---|
129 |
|
---|
130 | ;--------------------------------------------------------------------
|
---|
131 | ; .SetFlagToBXAXfromDriveInDL
|
---|
132 | ; Parameters:
|
---|
133 | ; DL: Drive number (0...31)
|
---|
134 | ; BX:AX: Flags containing drive numbers
|
---|
135 | ; Returns:
|
---|
136 | ; BX:AX: Flags with wanted drive bit set
|
---|
137 | ; Corrupts registers:
|
---|
138 | ; Nothing
|
---|
139 | ;--------------------------------------------------------------------
|
---|
140 | ALIGN JUMP_ALIGN
|
---|
141 | .SetFlagToBXAXfromDriveInDL:
|
---|
142 | push cx
|
---|
143 |
|
---|
144 | mov cl, dl
|
---|
145 | xchg dx, bx
|
---|
146 | call Bit_SetToDXAXfromIndexInCL
|
---|
147 | xchg bx, dx
|
---|
148 |
|
---|
149 | pop cx
|
---|
150 | ret
|
---|
151 |
|
---|
152 |
|
---|
153 | ;--------------------------------------------------------------------
|
---|
154 | ; Drive_GetDefaultToAL
|
---|
155 | ; Parameters:
|
---|
156 | ; Nothing
|
---|
157 | ; Returns:
|
---|
158 | ; AL: Current default drive (00h=A:, 01h=B: ...)
|
---|
159 | ; Corrupts registers:
|
---|
160 | ; AH
|
---|
161 | ;--------------------------------------------------------------------
|
---|
162 | ALIGN JUMP_ALIGN
|
---|
163 | Drive_GetDefaultToAL:
|
---|
164 | mov ah, GET_CURRENT_DEFAULT_DRIVE
|
---|
165 | SKIP2B f ; cmp ax, <next instruction>
|
---|
166 | ; Fall to Drive_SetDefaultFromDL
|
---|
167 |
|
---|
168 |
|
---|
169 | ;--------------------------------------------------------------------
|
---|
170 | ; Drive_SetDefaultFromDL
|
---|
171 | ; Parameters:
|
---|
172 | ; DL: New default drive (00h=A:, 01h=B: ...)
|
---|
173 | ; Returns:
|
---|
174 | ; AL: Number of potentially valid drive letters available
|
---|
175 | ; Corrupts registers:
|
---|
176 | ; AH
|
---|
177 | ;--------------------------------------------------------------------
|
---|
178 | Drive_SetDefaultFromDL:
|
---|
179 | mov ah, SELECT_DEFAULT_DRIVE
|
---|
180 | int DOS_INTERRUPT_21h
|
---|
181 | ret
|
---|