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

Last change on this file since 594 was 593, checked in by Tomi Tilli, 6 years ago

Flashing now works again.
Hack to get Windows 95 to work properly (MODULE_WIN95_CMOS_HACK included for 386 builds by default).
Edited makefile to produce large 386 build.
Fixed recovery time for QDI Vision VLB-IDE controllers.
No more warnings with Nasm 2.13.xx and later.
File dialog now properly restores default drive when file selection is cancelled.

File size: 7.2 KB
Line 
1; Project name : Assembly Library
2; Description : Functions for accessing drives.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
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.
12;
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
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
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;--------------------------------------------------------------------
32%ifndef EXCLUDE_FROM_XTIDECFG
33ALIGN JUMP_ALIGN
34Drive_GetNumberOfAvailableDrivesToAX:
35 push dx
36 push cx
37
38 call Drive_GetFlagsForAvailableDrivesToDXAX
39 call Bit_GetSetCountToCXfromDXAX
40 xchg ax, cx
41
42 pop cx
43 pop dx
44 ret
45%endif
46
47
48;--------------------------------------------------------------------
49; Drive_GetFlagsForAvailableDrivesToDXAX
50; Parameters:
51; Nothing
52; Returns:
53; DX:AX: Flags containing valid drives (bit 0 = drive A, bit 1 = drive B ...)
54; Corrupts registers:
55; Nothing
56;--------------------------------------------------------------------
57ALIGN JUMP_ALIGN
58Drive_GetFlagsForAvailableDrivesToDXAX:
59 push cx
60 push bx
61 mov dx, DosCritical_HandlerToIgnoreAllErrors
62 call DosCritical_InstallNewHandlerFromCSDX
63
64 call .GetNumberOfPotentiallyValidDriveLettersToCX
65 xor bx, bx
66 xor ax, ax ; Temporary use BX:AX for flags
67 cwd ; Start from drive 0
68 call .CheckDriveValidityUntilCXisZero
69 mov dx, bx ; Flags now in DX:AX
70
71 call DosCritical_RestoreDosHandler
72 pop bx
73 pop cx
74 ret
75
76;--------------------------------------------------------------------
77; .GetNumberOfPotentiallyValidDriveLettersToCX
78; Parameters:
79; Nothing
80; Returns:
81; CX: Number of potentially valid drive letters available
82; Corrupts registers:
83; AX, DX
84;--------------------------------------------------------------------
85ALIGN JUMP_ALIGN
86.GetNumberOfPotentiallyValidDriveLettersToCX:
87 call Drive_GetDefaultToAL
88 xchg dx, ax ; Default drive to DL
89 call Drive_SetDefaultFromDL
90 cmp al, 32 ; Number of potentially valid drive letters available
91 jb SHORT .Below32
92 mov al, 32
93.Below32:
94 cbw
95 xchg cx, ax
96 ret
97
98;--------------------------------------------------------------------
99; .CheckDriveValidityUntilCXisZero
100; Parameters:
101; CX: Number of potentially valid drive letters left
102; DL: Drive number (00h=A:, 01h=B: ...)
103; BX:AX: Flags for drive numbers
104; Returns:
105; BX:AX: Flags for valid drive numbers
106; Corrupts registers:
107; CX, DX
108;--------------------------------------------------------------------
109ALIGN JUMP_ALIGN
110.CheckDriveValidityUntilCXisZero:
111 call .IsValidDriveNumberInDL
112 jnz SHORT .PrepareToCheckNextDrive
113 call .SetFlagToBXAXfromDriveInDL
114ALIGN JUMP_ALIGN
115.PrepareToCheckNextDrive:
116 inc dx
117 loop .CheckDriveValidityUntilCXisZero
118 ret
119
120;--------------------------------------------------------------------
121; .IsValidDriveNumberInDL
122; Parameters:
123; DL: Drive number (00h=A:, 01h=B: ...)
124; Returns:
125; ZF: Set if drive number is valid
126; Cleared if drive number is invalid
127; Corrupts registers:
128; Nothing
129;--------------------------------------------------------------------
130ALIGN JUMP_ALIGN
131.IsValidDriveNumberInDL:
132 push ds
133 push ax
134 cmp dl, 1
135 jbe SHORT .FloppyDrive
136
137.MessageSuppressedByInt2FhHandler:
138.MoreThanOneFloppyDrive:
139.NoFloppyDrive:
140 push bx
141
142 inc dx ; Default drive is 00h and first drive is 01h
143 mov ax, CHECK_IF_BLOCK_DEVICE_REMOTE ; Needs DOS 3.1+
144 mov bx, dx
145 push dx
146 int DOS_INTERRUPT_21h
147 pop dx
148 jnc SHORT .DriveIsValid
149 cmp ax, ERR_DOS_INVALID_DRIVE
150 je SHORT .DriveIsNotValid
151 ; Fall back to old method if ERR_DOS_FUNCTION_NUMBER_INVALID
152
153 mov ah, GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE
154 int DOS_INTERRUPT_21h
155.DriveIsValid:
156.DriveIsNotValid:
157 dec dx
158 test al, al
159
160 pop bx
161.ReturnFromFloppyDriveFiltering:
162 pop ax
163 pop ds
164 ret
165
166.FloppyDrive:
167; On single-floppy-drive systems, both A: and B: will point to the same physical drive. The problem is that DOS will print a message telling the user
168; to "insert a disk and press any key to continue" when swapping from one logical drive to the other. To avoid this mess we hook interrupt 2Fh/AX=4A00h
169; to signal to DOS that we will handle this ourselves. However, this only works on DOS 5+ so on older DOS versions we instead try to filter out
170; the "other" logical drive (the one that isn't the current drive) during drive enumeration so the user can't select the "phantom" drive to begin with.
171; This will have the somewhat strange effect of having a drive B: but no drive A: if B: happens to be the current logical floppy drive.
172
173 cmp BYTE [bDosVersionMajor], 5 ; bDosVersionMajor must be provided by the application as it's not part of the library
174 jae SHORT .MessageSuppressedByInt2FhHandler
175 LOAD_BDA_SEGMENT_TO ds, ax
176 mov al, [BDA.wEquipment]
177 test al, 0C0h
178 jnz SHORT .MoreThanOneFloppyDrive ; No phantom drive so no need for any filtering
179 test al, 1 ; Any floppy drive at all?
180 jz SHORT .NoFloppyDrive ; A pre-DOS 5 machine with no FDD is indeed a strange beast. However, don't trust the BIOS - let DOS decide
181 cmp dl, [504h] ; MS-DOS - LOGICAL DRIVE FOR SINGLE-FLOPPY SYSTEM (A: / B:)
182 jmp SHORT .ReturnFromFloppyDriveFiltering
183
184;--------------------------------------------------------------------
185; .SetFlagToBXAXfromDriveInDL
186; Parameters:
187; DL: Drive number (0...31)
188; BX:AX: Flags containing drive numbers
189; Returns:
190; BX:AX: Flags with wanted drive bit set
191; Corrupts registers:
192; Nothing
193;--------------------------------------------------------------------
194ALIGN JUMP_ALIGN
195.SetFlagToBXAXfromDriveInDL:
196 push cx
197
198 mov cl, dl
199 xchg dx, bx
200 call Bit_SetToDXAXfromIndexInCL
201 xchg bx, dx
202
203 pop cx
204 ret
205
206
207;--------------------------------------------------------------------
208; Drive_GetDefaultToAL
209; Parameters:
210; Nothing
211; Returns:
212; AL: Current default drive (00h=A:, 01h=B: ...)
213; Corrupts registers:
214; AH
215;--------------------------------------------------------------------
216ALIGN JUMP_ALIGN
217Drive_GetDefaultToAL:
218 mov ah, GET_CURRENT_DEFAULT_DRIVE
219 SKIP2B f ; cmp ax, <next instruction>
220 ; Fall to Drive_SetDefaultFromDL
221
222
223;--------------------------------------------------------------------
224; Drive_SetDefaultFromDL
225; Parameters:
226; DL: New default drive (00h=A:, 01h=B: ...)
227; Returns:
228; AL: Number of potentially valid drive letters available
229; Corrupts registers:
230; AH
231;--------------------------------------------------------------------
232Drive_SetDefaultFromDL:
233 mov ah, SELECT_DEFAULT_DRIVE
234 int DOS_INTERRUPT_21h
235 ret
Note: See TracBrowser for help on using the repository browser.