source: xtideuniversalbios/trunk/Assembly_Library/Src/File/Drive.asm@ 72

Last change on this file since 72 was 41, checked in by Tomi Tilli, 14 years ago

Initial commit for Assembly Library.

File size: 4.7 KB
Line 
1; File name : Drive.asm
2; Project name : Assembly Library
3; Created date : 1.9.2010
4; Last update : 3.9.2010
5; Author : Tomi Tilli
6; Description : Functions for accessing drives.
7
8
9; Section containing code
10SECTION .text
11
12;--------------------------------------------------------------------
13; Drive_GetNumberOfAvailableDrivesToAX
14; Parameters:
15; Nothing
16; Returns:
17; AX: Number of available drives
18; Corrupts registers:
19; Nothing
20;--------------------------------------------------------------------
21ALIGN JUMP_ALIGN
22Drive_GetNumberOfAvailableDrivesToAX:
23 push dx
24 push cx
25
26 call Drive_GetFlagsForAvailableDrivesToDXAX
27 call Bit_GetSetCountToCXfromDXAX
28 xchg ax, cx
29
30 pop cx
31 pop dx
32 ret
33
34
35;--------------------------------------------------------------------
36; Drive_GetFlagsForAvailableDrivesToDXAX
37; Parameters:
38; Nothing
39; Returns:
40; DX:AX: Flags containing valid drives (bit 0 = drive A, bit 1 = drive B ...)
41; Corrupts registers:
42; Nothing
43;--------------------------------------------------------------------
44ALIGN JUMP_ALIGN
45Drive_GetFlagsForAvailableDrivesToDXAX:
46 push cx
47 push bx
48 mov dx, DosCritical_HandlerToIgnoreAllErrors
49 call DosCritical_InstallNewHandlerFromCSDX
50
51 call .GetNumberOfPotentiallyValidDriveLettersToCX
52 xor bx, bx
53 xor ax, ax ; Temporary use BX:AX for flags
54 xor dx, dx ; Start from drive 0
55 call .CheckDriveValidityUntilCXisZero
56 mov dx, bx ; Flags now in DX:AX
57
58 call DosCritical_RestoreDosHandler
59 pop bx
60 pop cx
61 ret
62
63;--------------------------------------------------------------------
64; .GetNumberOfPotentiallyValidDriveLettersToCX
65; Parameters:
66; Nothing
67; Returns:
68; CX: Number of potentially valid drive letters available
69; Corrupts registers:
70; AX, DX
71;--------------------------------------------------------------------
72ALIGN JUMP_ALIGN
73.GetNumberOfPotentiallyValidDriveLettersToCX:
74 call Drive_GetDefaultToAL
75 xchg dx, ax ; Default drive to DL
76 call Drive_SetDefaultFromDL
77 eMOVZX cx, al ; Number of potentially valid drive letters available
78 MIN_U cx, 32
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;--------------------------------------------------------------------
92ALIGN JUMP_ALIGN
93.CheckDriveValidityUntilCXisZero:
94 call .IsValidDriveNumberInDL
95 jnz SHORT .PrepareToCheckNextDrive
96 call .SetFlagToBXAXfromDriveInDL
97ALIGN 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;--------------------------------------------------------------------
113ALIGN 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;--------------------------------------------------------------------
140ALIGN 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;--------------------------------------------------------------------
162ALIGN JUMP_ALIGN
163Drive_GetDefaultToAL:
164 mov ah, GET_CURRENT_DEFAULT_DRIVE
165 int DOS_INTERRUPT_21h
166 ret
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;--------------------------------------------------------------------
178ALIGN JUMP_ALIGN
179Drive_SetDefaultFromDL:
180 mov ah, SELECT_DEFAULT_DRIVE
181 int DOS_INTERRUPT_21h
182 ret
183
Note: See TracBrowser for help on using the repository browser.