[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
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
| 24 | ; Drive_GetNumberOfAvailableDrivesToAX
|
---|
| 25 | ; Parameters:
|
---|
| 26 | ; Nothing
|
---|
| 27 | ; Returns:
|
---|
| 28 | ; AX: Number of available drives
|
---|
| 29 | ; Corrupts registers:
|
---|
| 30 | ; Nothing
|
---|
| 31 | ;--------------------------------------------------------------------
|
---|
[592] | 32 | %ifndef EXCLUDE_FROM_XTIDECFG
|
---|
[41] | 33 | ALIGN JUMP_ALIGN
|
---|
| 34 | Drive_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
|
---|
[592] | 45 | %endif
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
| 57 | ALIGN JUMP_ALIGN
|
---|
| 58 | Drive_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
|
---|
[133] | 67 | cwd ; Start from drive 0
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
| 85 | ALIGN JUMP_ALIGN
|
---|
| 86 | .GetNumberOfPotentiallyValidDriveLettersToCX:
|
---|
| 87 | call Drive_GetDefaultToAL
|
---|
| 88 | xchg dx, ax ; Default drive to DL
|
---|
| 89 | call Drive_SetDefaultFromDL
|
---|
[589] | 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
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
| 109 | ALIGN JUMP_ALIGN
|
---|
| 110 | .CheckDriveValidityUntilCXisZero:
|
---|
| 111 | call .IsValidDriveNumberInDL
|
---|
| 112 | jnz SHORT .PrepareToCheckNextDrive
|
---|
| 113 | call .SetFlagToBXAXfromDriveInDL
|
---|
| 114 | ALIGN 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 | ;--------------------------------------------------------------------
|
---|
| 130 | ALIGN 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
|
---|
[589] | 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 |
|
---|
[41] | 147 | mov ah, GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE
|
---|
| 148 | int DOS_INTERRUPT_21h
|
---|
[589] | 149 | .DriveIsValid:
|
---|
| 150 | .DriveIsNotValid:
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
| 169 | ALIGN 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 | ;--------------------------------------------------------------------
|
---|
| 191 | ALIGN JUMP_ALIGN
|
---|
| 192 | Drive_GetDefaultToAL:
|
---|
| 193 | mov ah, GET_CURRENT_DEFAULT_DRIVE
|
---|
[133] | 194 | SKIP2B f ; cmp ax, <next instruction>
|
---|
| 195 | ; Fall to Drive_SetDefaultFromDL
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
| 207 | Drive_SetDefaultFromDL:
|
---|
| 208 | mov ah, SELECT_DEFAULT_DRIVE
|
---|
| 209 | int DOS_INTERRUPT_21h
|
---|
| 210 | ret
|
---|