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

Last change on this file since 576 was 526, checked in by krille_n_@…, 12 years ago

Changes:

  • Update of the copyright notices to include the year 2013.
File size: 5.3 KB
RevLine 
[41]1; Project name : Assembly Library
2; Description : Functions for accessing drives.
3
[376]4;
[526]5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[376]7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
[526]12;
[376]13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[526]16; GNU General Public License for more details.
[376]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
[41]19
20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Drive_GetNumberOfAvailableDrivesToAX
25; Parameters:
26; Nothing
27; Returns:
28; AX: Number of available drives
29; Corrupts registers:
30; Nothing
31;--------------------------------------------------------------------
32ALIGN JUMP_ALIGN
33Drive_GetNumberOfAvailableDrivesToAX:
34 push dx
35 push cx
36
37 call Drive_GetFlagsForAvailableDrivesToDXAX
38 call Bit_GetSetCountToCXfromDXAX
39 xchg ax, cx
40
41 pop cx
42 pop dx
43 ret
44
45
46;--------------------------------------------------------------------
47; Drive_GetFlagsForAvailableDrivesToDXAX
48; Parameters:
49; Nothing
50; Returns:
51; DX:AX: Flags containing valid drives (bit 0 = drive A, bit 1 = drive B ...)
52; Corrupts registers:
53; Nothing
54;--------------------------------------------------------------------
55ALIGN JUMP_ALIGN
56Drive_GetFlagsForAvailableDrivesToDXAX:
57 push cx
58 push bx
59 mov dx, DosCritical_HandlerToIgnoreAllErrors
60 call DosCritical_InstallNewHandlerFromCSDX
61
62 call .GetNumberOfPotentiallyValidDriveLettersToCX
63 xor bx, bx
64 xor ax, ax ; Temporary use BX:AX for flags
[133]65 cwd ; Start from drive 0
[41]66 call .CheckDriveValidityUntilCXisZero
67 mov dx, bx ; Flags now in DX:AX
68
69 call DosCritical_RestoreDosHandler
70 pop bx
71 pop cx
72 ret
73
74;--------------------------------------------------------------------
75; .GetNumberOfPotentiallyValidDriveLettersToCX
76; Parameters:
77; Nothing
78; Returns:
79; CX: Number of potentially valid drive letters available
80; Corrupts registers:
81; AX, DX
82;--------------------------------------------------------------------
83ALIGN JUMP_ALIGN
84.GetNumberOfPotentiallyValidDriveLettersToCX:
85 call Drive_GetDefaultToAL
86 xchg dx, ax ; Default drive to DL
87 call Drive_SetDefaultFromDL
88 eMOVZX cx, al ; Number of potentially valid drive letters available
[181]89 cmp cl, 32
90 jb SHORT .Return
91 mov cl, 32
92ALIGN JUMP_ALIGN, ret
93.Return:
[41]94 ret
95
96;--------------------------------------------------------------------
97; .CheckDriveValidityUntilCXisZero
98; Parameters:
99; CX: Number of potentially valid drive letters left
100; DL: Drive number (00h=A:, 01h=B: ...)
101; BX:AX: Flags for drive numbers
102; Returns:
103; BX:AX: Flags for valid drive numbers
104; Corrupts registers:
105; CX, DX
106;--------------------------------------------------------------------
107ALIGN JUMP_ALIGN
108.CheckDriveValidityUntilCXisZero:
109 call .IsValidDriveNumberInDL
110 jnz SHORT .PrepareToCheckNextDrive
111 call .SetFlagToBXAXfromDriveInDL
112ALIGN JUMP_ALIGN
113.PrepareToCheckNextDrive:
114 inc dx
115 loop .CheckDriveValidityUntilCXisZero
116 ret
117
118;--------------------------------------------------------------------
119; .IsValidDriveNumberInDL
120; Parameters:
121; DL: Drive number (00h=A:, 01h=B: ...)
122; Returns:
123; ZF: Set if drive number is valid
124; Cleared if drive number is invalid
125; Corrupts registers:
126; Nothing
127;--------------------------------------------------------------------
128ALIGN JUMP_ALIGN
129.IsValidDriveNumberInDL:
130 push ds
131 push bx
132 push ax
133
134 inc dx ; Default drive is 00h and first drive is 01h
135 mov ah, GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE
136 int DOS_INTERRUPT_21h
137 dec dx
138 test al, al
139
140 pop ax
141 pop bx
142 pop ds
143 ret
144
145;--------------------------------------------------------------------
146; .SetFlagToBXAXfromDriveInDL
147; Parameters:
148; DL: Drive number (0...31)
149; BX:AX: Flags containing drive numbers
150; Returns:
151; BX:AX: Flags with wanted drive bit set
152; Corrupts registers:
153; Nothing
154;--------------------------------------------------------------------
155ALIGN JUMP_ALIGN
156.SetFlagToBXAXfromDriveInDL:
157 push cx
158
159 mov cl, dl
160 xchg dx, bx
161 call Bit_SetToDXAXfromIndexInCL
162 xchg bx, dx
163
164 pop cx
165 ret
166
167
168;--------------------------------------------------------------------
169; Drive_GetDefaultToAL
170; Parameters:
171; Nothing
172; Returns:
173; AL: Current default drive (00h=A:, 01h=B: ...)
174; Corrupts registers:
175; AH
176;--------------------------------------------------------------------
177ALIGN JUMP_ALIGN
178Drive_GetDefaultToAL:
179 mov ah, GET_CURRENT_DEFAULT_DRIVE
[133]180 SKIP2B f ; cmp ax, <next instruction>
181 ; Fall to Drive_SetDefaultFromDL
[41]182
183
184;--------------------------------------------------------------------
185; Drive_SetDefaultFromDL
186; Parameters:
187; DL: New default drive (00h=A:, 01h=B: ...)
188; Returns:
189; AL: Number of potentially valid drive letters available
190; Corrupts registers:
191; AH
192;--------------------------------------------------------------------
193Drive_SetDefaultFromDL:
194 mov ah, SELECT_DEFAULT_DRIVE
195 int DOS_INTERRUPT_21h
196 ret
Note: See TracBrowser for help on using the repository browser.