[41] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Functions for accessing drives.
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 | ; Section containing code
|
---|
| 6 | SECTION .text
|
---|
| 7 |
|
---|
| 8 | ;--------------------------------------------------------------------
|
---|
| 9 | ; Drive_GetNumberOfAvailableDrivesToAX
|
---|
| 10 | ; Parameters:
|
---|
| 11 | ; Nothing
|
---|
| 12 | ; Returns:
|
---|
| 13 | ; AX: Number of available drives
|
---|
| 14 | ; Corrupts registers:
|
---|
| 15 | ; Nothing
|
---|
| 16 | ;--------------------------------------------------------------------
|
---|
| 17 | ALIGN JUMP_ALIGN
|
---|
| 18 | Drive_GetNumberOfAvailableDrivesToAX:
|
---|
| 19 | push dx
|
---|
| 20 | push cx
|
---|
| 21 |
|
---|
| 22 | call Drive_GetFlagsForAvailableDrivesToDXAX
|
---|
| 23 | call Bit_GetSetCountToCXfromDXAX
|
---|
| 24 | xchg ax, cx
|
---|
| 25 |
|
---|
| 26 | pop cx
|
---|
| 27 | pop dx
|
---|
| 28 | ret
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | ;--------------------------------------------------------------------
|
---|
| 32 | ; Drive_GetFlagsForAvailableDrivesToDXAX
|
---|
| 33 | ; Parameters:
|
---|
| 34 | ; Nothing
|
---|
| 35 | ; Returns:
|
---|
| 36 | ; DX:AX: Flags containing valid drives (bit 0 = drive A, bit 1 = drive B ...)
|
---|
| 37 | ; Corrupts registers:
|
---|
| 38 | ; Nothing
|
---|
| 39 | ;--------------------------------------------------------------------
|
---|
| 40 | ALIGN JUMP_ALIGN
|
---|
| 41 | Drive_GetFlagsForAvailableDrivesToDXAX:
|
---|
| 42 | push cx
|
---|
| 43 | push bx
|
---|
| 44 | mov dx, DosCritical_HandlerToIgnoreAllErrors
|
---|
| 45 | call DosCritical_InstallNewHandlerFromCSDX
|
---|
| 46 |
|
---|
| 47 | call .GetNumberOfPotentiallyValidDriveLettersToCX
|
---|
| 48 | xor bx, bx
|
---|
| 49 | xor ax, ax ; Temporary use BX:AX for flags
|
---|
[133] | 50 | cwd ; Start from drive 0
|
---|
[41] | 51 | call .CheckDriveValidityUntilCXisZero
|
---|
| 52 | mov dx, bx ; Flags now in DX:AX
|
---|
| 53 |
|
---|
| 54 | call DosCritical_RestoreDosHandler
|
---|
| 55 | pop bx
|
---|
| 56 | pop cx
|
---|
| 57 | ret
|
---|
| 58 |
|
---|
| 59 | ;--------------------------------------------------------------------
|
---|
| 60 | ; .GetNumberOfPotentiallyValidDriveLettersToCX
|
---|
| 61 | ; Parameters:
|
---|
| 62 | ; Nothing
|
---|
| 63 | ; Returns:
|
---|
| 64 | ; CX: Number of potentially valid drive letters available
|
---|
| 65 | ; Corrupts registers:
|
---|
| 66 | ; AX, DX
|
---|
| 67 | ;--------------------------------------------------------------------
|
---|
| 68 | ALIGN JUMP_ALIGN
|
---|
| 69 | .GetNumberOfPotentiallyValidDriveLettersToCX:
|
---|
| 70 | call Drive_GetDefaultToAL
|
---|
| 71 | xchg dx, ax ; Default drive to DL
|
---|
| 72 | call Drive_SetDefaultFromDL
|
---|
| 73 | eMOVZX cx, al ; Number of potentially valid drive letters available
|
---|
| 74 | MIN_U cx, 32
|
---|
| 75 | ret
|
---|
| 76 |
|
---|
| 77 | ;--------------------------------------------------------------------
|
---|
| 78 | ; .CheckDriveValidityUntilCXisZero
|
---|
| 79 | ; Parameters:
|
---|
| 80 | ; CX: Number of potentially valid drive letters left
|
---|
| 81 | ; DL: Drive number (00h=A:, 01h=B: ...)
|
---|
| 82 | ; BX:AX: Flags for drive numbers
|
---|
| 83 | ; Returns:
|
---|
| 84 | ; BX:AX: Flags for valid drive numbers
|
---|
| 85 | ; Corrupts registers:
|
---|
| 86 | ; CX, DX
|
---|
| 87 | ;--------------------------------------------------------------------
|
---|
| 88 | ALIGN JUMP_ALIGN
|
---|
| 89 | .CheckDriveValidityUntilCXisZero:
|
---|
| 90 | call .IsValidDriveNumberInDL
|
---|
| 91 | jnz SHORT .PrepareToCheckNextDrive
|
---|
| 92 | call .SetFlagToBXAXfromDriveInDL
|
---|
| 93 | ALIGN JUMP_ALIGN
|
---|
| 94 | .PrepareToCheckNextDrive:
|
---|
| 95 | inc dx
|
---|
| 96 | loop .CheckDriveValidityUntilCXisZero
|
---|
| 97 | ret
|
---|
| 98 |
|
---|
| 99 | ;--------------------------------------------------------------------
|
---|
| 100 | ; .IsValidDriveNumberInDL
|
---|
| 101 | ; Parameters:
|
---|
| 102 | ; DL: Drive number (00h=A:, 01h=B: ...)
|
---|
| 103 | ; Returns:
|
---|
| 104 | ; ZF: Set if drive number is valid
|
---|
| 105 | ; Cleared if drive number is invalid
|
---|
| 106 | ; Corrupts registers:
|
---|
| 107 | ; Nothing
|
---|
| 108 | ;--------------------------------------------------------------------
|
---|
| 109 | ALIGN JUMP_ALIGN
|
---|
| 110 | .IsValidDriveNumberInDL:
|
---|
| 111 | push ds
|
---|
| 112 | push bx
|
---|
| 113 | push ax
|
---|
| 114 |
|
---|
| 115 | inc dx ; Default drive is 00h and first drive is 01h
|
---|
| 116 | mov ah, GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE
|
---|
| 117 | int DOS_INTERRUPT_21h
|
---|
| 118 | dec dx
|
---|
| 119 | test al, al
|
---|
| 120 |
|
---|
| 121 | pop ax
|
---|
| 122 | pop bx
|
---|
| 123 | pop ds
|
---|
| 124 | ret
|
---|
| 125 |
|
---|
| 126 | ;--------------------------------------------------------------------
|
---|
| 127 | ; .SetFlagToBXAXfromDriveInDL
|
---|
| 128 | ; Parameters:
|
---|
| 129 | ; DL: Drive number (0...31)
|
---|
| 130 | ; BX:AX: Flags containing drive numbers
|
---|
| 131 | ; Returns:
|
---|
| 132 | ; BX:AX: Flags with wanted drive bit set
|
---|
| 133 | ; Corrupts registers:
|
---|
| 134 | ; Nothing
|
---|
| 135 | ;--------------------------------------------------------------------
|
---|
| 136 | ALIGN JUMP_ALIGN
|
---|
| 137 | .SetFlagToBXAXfromDriveInDL:
|
---|
| 138 | push cx
|
---|
| 139 |
|
---|
| 140 | mov cl, dl
|
---|
| 141 | xchg dx, bx
|
---|
| 142 | call Bit_SetToDXAXfromIndexInCL
|
---|
| 143 | xchg bx, dx
|
---|
| 144 |
|
---|
| 145 | pop cx
|
---|
| 146 | ret
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 | ;--------------------------------------------------------------------
|
---|
| 150 | ; Drive_GetDefaultToAL
|
---|
| 151 | ; Parameters:
|
---|
| 152 | ; Nothing
|
---|
| 153 | ; Returns:
|
---|
| 154 | ; AL: Current default drive (00h=A:, 01h=B: ...)
|
---|
| 155 | ; Corrupts registers:
|
---|
| 156 | ; AH
|
---|
| 157 | ;--------------------------------------------------------------------
|
---|
| 158 | ALIGN JUMP_ALIGN
|
---|
| 159 | Drive_GetDefaultToAL:
|
---|
| 160 | mov ah, GET_CURRENT_DEFAULT_DRIVE
|
---|
[133] | 161 | SKIP2B f ; cmp ax, <next instruction>
|
---|
| 162 | ; Fall to Drive_SetDefaultFromDL
|
---|
[41] | 163 |
|
---|
| 164 |
|
---|
| 165 | ;--------------------------------------------------------------------
|
---|
| 166 | ; Drive_SetDefaultFromDL
|
---|
| 167 | ; Parameters:
|
---|
| 168 | ; DL: New default drive (00h=A:, 01h=B: ...)
|
---|
| 169 | ; Returns:
|
---|
| 170 | ; AL: Number of potentially valid drive letters available
|
---|
| 171 | ; Corrupts registers:
|
---|
| 172 | ; AH
|
---|
| 173 | ;--------------------------------------------------------------------
|
---|
| 174 | Drive_SetDefaultFromDL:
|
---|
| 175 | mov ah, SELECT_DEFAULT_DRIVE
|
---|
| 176 | int DOS_INTERRUPT_21h
|
---|
| 177 | ret
|
---|