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

Last change on this file since 592 was 592, checked in by krille_n_, 6 years ago

Changes:

  • The problem with NASM in the previous revision (r591) has been fixed.
  • The colors used by the boot menu and hotkey bar can now be customized by selecting one of a number of pre-defined color themes. Suggestions for additional themes are more than welcome!
  • Large builds are now 10 KB. Small builds are still 8 KB with the exception of the Tiny build which is now 4 KB. In other words, builds are now as small as possible to make it easier to combine them with other BIOSes.
  • Added code to the library to improve drive error handling. XTIDECFG can now handle "Drive Not Ready" errors.
  • Fixed a couple of potential bugs in AtaID.asm (AtaID_GetMaxPioModeToAXandMinCycleTimeToCX); 1) ATA1.bPioMode was treated as a WORD variable. 2) ATA2.bPIOSupp was assumed to be non-zero which would result in PIO mode 3 being returned if the assumption was wrong.
  • Made the same changes in the equivalent function used by BIOSDRVS (DisplayPioModeInformationUsingAtaInfoFromDSBX in AtaInfo.asm).
  • Fixed a bug from r587 in PDC20x30.asm in PDC20x30_GetMaxPioModeToALandMinPioCycleTimeToBX.
  • Fixed a bug from r523 in XTIDECFG where Auto Configure would only set the IRQ on one IDE interface on AT-builds.
  • XTIDECFG will now restore the default settings for the "Serial port virtual device" when reselecting it in the list of device types. This makes it behave consistently for all device types.
  • The eAAM macro is now used regardless if USE_UNDOC_INTEL is defined or not because it is apparently supported on all processors including the NEC V20/V30 CPUs.
  • Renamed the EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS define to EXCLUDE_FROM_XUB.
  • Added a define to exclude unused library code from BIOSDRVS (EXCLUDE_FROM_BIOSDRVS). This makes it a lot smaller than in previous revisions.
  • All unnecessary CLD-instructions are now under a new define 'CLD_NEEDED' which is only enabled for the BIOS. It is disabled for XTIDECFG and BIOSDRVS but can be enabled if needed by adding this define to the respective makefile. This change was made because these unnecessary instructions are wasteful and should never be needed. In fact, they only serve to hide bugs (in other peoples code) which I strongly believe should be avoided. I recommend people making their own BIOSes from source to not use this define as it's extremely unlikely to be needed.
  • Updated the copyright info in SerDrive and changed an URL to point to the new site.
  • Updated the copyright info and version number in BIOSDRVS.
  • Updated the copyright info in XTIDECFG.
  • Optimizations in general.
File size: 5.7 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    bx
134    push    ax
135
136    inc     dx          ; Default drive is 00h and first drive is 01h
137    mov     ax, CHECK_IF_BLOCK_DEVICE_REMOTE    ; Needs DOS 3.1+
138    mov     bx, dx
139    push    dx
140    int     DOS_INTERRUPT_21h
141    pop     dx
142    jnc     SHORT .DriveIsValid
143    cmp     ax, ERR_DOS_INVALID_DRIVE
144    je      SHORT .DriveIsNotValid
145    ; Fall back to old method if ERR_DOS_FUNCTION_NUMBER_INVALID
146
147    mov     ah, GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE
148    int     DOS_INTERRUPT_21h
149.DriveIsValid:
150.DriveIsNotValid:
151    dec     dx
152    test    al, al
153
154    pop     ax
155    pop     bx
156    pop     ds
157    ret
158
159;--------------------------------------------------------------------
160; .SetFlagToBXAXfromDriveInDL
161;   Parameters:
162;       DL:     Drive number (0...31)
163;       BX:AX:  Flags containing drive numbers
164;   Returns:
165;       BX:AX:  Flags with wanted drive bit set
166;   Corrupts registers:
167;       Nothing
168;--------------------------------------------------------------------
169ALIGN JUMP_ALIGN
170.SetFlagToBXAXfromDriveInDL:
171    push    cx
172
173    mov     cl, dl
174    xchg    dx, bx
175    call    Bit_SetToDXAXfromIndexInCL
176    xchg    bx, dx
177
178    pop     cx
179    ret
180
181
182;--------------------------------------------------------------------
183; Drive_GetDefaultToAL
184;   Parameters:
185;       Nothing
186;   Returns:
187;       AL:     Current default drive (00h=A:, 01h=B: ...)
188;   Corrupts registers:
189;       AH
190;--------------------------------------------------------------------
191ALIGN JUMP_ALIGN
192Drive_GetDefaultToAL:
193    mov     ah, GET_CURRENT_DEFAULT_DRIVE
194    SKIP2B  f   ; cmp ax, <next instruction>
195    ; Fall to Drive_SetDefaultFromDL
196
197
198;--------------------------------------------------------------------
199; Drive_SetDefaultFromDL
200;   Parameters:
201;       DL:     New default drive (00h=A:, 01h=B: ...)
202;   Returns:
203;       AL:     Number of potentially valid drive letters available
204;   Corrupts registers:
205;       AH
206;--------------------------------------------------------------------
207Drive_SetDefaultFromDL:
208    mov     ah, SELECT_DEFAULT_DRIVE
209    int     DOS_INTERRUPT_21h
210    ret
Note: See TracBrowser for help on using the repository browser.