[3] | 1 | ; File name : FloppyDrive.asm |
---|
| 2 | ; Project name : IDE BIOS |
---|
| 3 | ; Created date : 25.3.2010 |
---|
[39] | 4 | ; Last update : 13.9.2010 |
---|
[3] | 5 | ; Author : Tomi Tilli |
---|
| 6 | ; Description : Various floppy drive related functions that |
---|
| 7 | ; Boot Menu uses. |
---|
| 8 | |
---|
| 9 | ; Section containing code |
---|
| 10 | SECTION .text |
---|
| 11 | |
---|
| 12 | ;-------------------------------------------------------------------- |
---|
| 13 | ; Checks is floppy drive handler installed to interrupt vector 40h. |
---|
| 14 | ; |
---|
| 15 | ; FloppyDrive_IsInt40hInstalled |
---|
| 16 | ; Parameters: |
---|
| 17 | ; ES: BDA and Interrupt Vector segment (zero) |
---|
| 18 | ; Returns: |
---|
| 19 | ; CF: Set if INT 40h is installed |
---|
| 20 | ; Cleared if INT 40h is not installed |
---|
| 21 | ; Corrupts registers: |
---|
| 22 | ; BX, CX, DI |
---|
| 23 | ;-------------------------------------------------------------------- |
---|
[39] | 24 | ;ALIGN JUMP_ALIGN |
---|
[3] | 25 | FloppyDrive_IsInt40hInstalled: |
---|
| 26 | cmp WORD [es:INTV_FLOPPY_FUNC*4+2], 0C000h ; Any ROM segment? |
---|
[39] | 27 | jb SHORT .Int40hHandlerIsNotInstalled |
---|
| 28 | call .VerifyInt40hHandlerSinceSomeBiosesSimplyReturnFromInt40h |
---|
| 29 | .Int40hHandlerIsNotInstalled: |
---|
[27] | 30 | cmc |
---|
[3] | 31 | ret |
---|
| 32 | |
---|
[39] | 33 | ;-------------------------------------------------------------------- |
---|
| 34 | ; .VerifyInt40hHandlerSinceSomeBiosesSimplyReturnFromInt40h |
---|
| 35 | ; Parameters: |
---|
| 36 | ; Nothing |
---|
| 37 | ; Returns: |
---|
| 38 | ; CF: Cleared if INT 40h is installed |
---|
| 39 | ; Set if INT 40h is not installed |
---|
| 40 | ; Corrupts registers: |
---|
| 41 | ; BX, CX, DI |
---|
| 42 | ;-------------------------------------------------------------------- |
---|
| 43 | ;ALIGN JUMP_ALIGN |
---|
| 44 | .VerifyInt40hHandlerSinceSomeBiosesSimplyReturnFromInt40h: |
---|
| 45 | push es |
---|
| 46 | push dx |
---|
| 47 | push ax |
---|
[3] | 48 | |
---|
[39] | 49 | call .LoadInt40hVerifyParameters |
---|
| 50 | int INTV_DISK_FUNC |
---|
| 51 | jc SHORT .AH08hNotSupported ; AH=08h not supported on XTs but that doesn't |
---|
| 52 | push es ; matter since INT 40h does not need to be verified |
---|
| 53 | push di ; on XTs |
---|
| 54 | |
---|
| 55 | call .LoadInt40hVerifyParameters |
---|
| 56 | int INTV_FLOPPY_FUNC |
---|
| 57 | |
---|
| 58 | pop dx |
---|
| 59 | pop cx |
---|
| 60 | cmp dx, di ; Difference in offsets? |
---|
| 61 | jne SHORT .Int40hNotInstalled |
---|
| 62 | mov dx, es |
---|
| 63 | cmp cx, dx ; Difference in segments? |
---|
| 64 | jne SHORT .Int40hNotInstalled |
---|
| 65 | .AH08hNotSupported: |
---|
| 66 | clc |
---|
| 67 | jmp SHORT .Int40hIsInstalled |
---|
| 68 | .Int40hNotInstalled: |
---|
| 69 | stc |
---|
| 70 | .Int40hIsInstalled: |
---|
| 71 | pop ax |
---|
| 72 | pop dx |
---|
| 73 | pop es |
---|
| 74 | ret |
---|
| 75 | |
---|
[3] | 76 | ;-------------------------------------------------------------------- |
---|
[39] | 77 | ; .LoadInt40hVerifyParameters |
---|
| 78 | ; Parameters: |
---|
| 79 | ; Nothing |
---|
| 80 | ; Returns: |
---|
| 81 | ; AH: 08h (Get Drive Parameters) |
---|
| 82 | ; DL: 00h (floppy drive) |
---|
| 83 | ; ES:DI: 0:0h (to guard against BIOS bugs) |
---|
| 84 | ; Corrupts registers: |
---|
| 85 | ; DH |
---|
| 86 | ;-------------------------------------------------------------------- |
---|
| 87 | ;ALIGN JUMP_ALIGN |
---|
| 88 | .LoadInt40hVerifyParameters: |
---|
| 89 | xor dx, dx ; Floppy drive 0 |
---|
| 90 | mov di, dx |
---|
| 91 | mov es, dx ; ES:DI = 0000:0000h to guard against BIOS bugs |
---|
| 92 | mov ah, 08h ; Get Drive Parameters |
---|
| 93 | ret |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | ;-------------------------------------------------------------------- |
---|
[3] | 97 | ; Returns floppy drive type. |
---|
| 98 | ; PC/XT system do not support AH=08h but FLOPPY_TYPE_525_OR_35_DD |
---|
| 99 | ; is still returned for them. |
---|
| 100 | ; |
---|
| 101 | ; FloppyDrive_GetType |
---|
| 102 | ; Parameters: |
---|
| 103 | ; DL: Floppy Drive number |
---|
| 104 | ; Returns: |
---|
| 105 | ; BX: Floppy Drive Type: |
---|
| 106 | ; FLOPPY_TYPE_525_OR_35_DD |
---|
| 107 | ; FLOPPY_TYPE_525_DD |
---|
| 108 | ; FLOPPY_TYPE_525_HD |
---|
| 109 | ; FLOPPY_TYPE_35_DD |
---|
| 110 | ; FLOPPY_TYPE_35_HD |
---|
| 111 | ; FLOPPY_TYPE_35_ED |
---|
| 112 | ; CF: Set if AH=08h not supported (XT systems) or error |
---|
| 113 | ; Cleared if type read correctly (AT systems) |
---|
| 114 | ; Corrupts registers: |
---|
| 115 | ; AX, CX, DX, DI, ES |
---|
| 116 | ;-------------------------------------------------------------------- |
---|
| 117 | ALIGN JUMP_ALIGN |
---|
| 118 | FloppyDrive_GetType: |
---|
| 119 | mov ah, 08h ; Get Drive Parameters |
---|
| 120 | xor bx, bx ; FLOPPY_TYPE_525_OR_35_DD when function not supported |
---|
| 121 | int INTV_FLOPPY_FUNC |
---|
| 122 | ret |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | ;-------------------------------------------------------------------- |
---|
| 126 | ; Returns number of Floppy Drives in system. |
---|
| 127 | ; |
---|
| 128 | ; FloppyDrive_GetCount |
---|
| 129 | ; Parameters: |
---|
| 130 | ; Nothing |
---|
| 131 | ; Returns: |
---|
| 132 | ; CX: Number of Floppy Drives |
---|
| 133 | ; Corrupts registers: |
---|
| 134 | ; Nothing |
---|
| 135 | ;-------------------------------------------------------------------- |
---|
| 136 | ALIGN JUMP_ALIGN |
---|
| 137 | FloppyDrive_GetCount: |
---|
| 138 | push es |
---|
| 139 | call FloppyDrive_GetCountFromBIOS |
---|
| 140 | jnc SHORT .CompareToUserMinimum |
---|
| 141 | call FloppyDrive_GetCountFromBDA |
---|
| 142 | ALIGN JUMP_ALIGN |
---|
| 143 | .CompareToUserMinimum: |
---|
| 144 | MAX_U cl, [cs:ROMVARS.bMinFddCnt] |
---|
| 145 | xor ch, ch |
---|
| 146 | pop es |
---|
| 147 | ret |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | ;-------------------------------------------------------------------- |
---|
| 151 | ; Reads Floppy Drive Count from BIOS. |
---|
| 152 | ; Does not work on most XT systems. Call FloppyDrive_GetCountFromBDA |
---|
| 153 | ; if this function fails. |
---|
| 154 | ; |
---|
| 155 | ; FloppyDrive_GetCountFromBIOS |
---|
| 156 | ; Parameters: |
---|
| 157 | ; Nothing |
---|
| 158 | ; Returns: |
---|
| 159 | ; CL: Number of Floppy Drives |
---|
| 160 | ; CF: Cleared if successfull |
---|
| 161 | ; Set if BIOS function not supported |
---|
| 162 | ; Corrupts registers: |
---|
| 163 | ; CH, ES |
---|
| 164 | ;-------------------------------------------------------------------- |
---|
| 165 | ALIGN JUMP_ALIGN |
---|
| 166 | FloppyDrive_GetCountFromBIOS: |
---|
| 167 | push di |
---|
| 168 | push dx |
---|
| 169 | push bx |
---|
| 170 | push ax |
---|
| 171 | |
---|
| 172 | mov ah, 08h ; Get Drive Parameters |
---|
| 173 | xor dx, dx ; Floppy Drive 00h |
---|
| 174 | int INTV_FLOPPY_FUNC |
---|
| 175 | mov cl, dl ; Number of Floppy Drives to CL |
---|
| 176 | |
---|
| 177 | pop ax |
---|
| 178 | pop bx |
---|
| 179 | pop dx |
---|
| 180 | pop di |
---|
| 181 | ret |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | ;-------------------------------------------------------------------- |
---|
| 185 | ; Reads Floppy Drive Count (0...4) from BIOS Data Area. |
---|
| 186 | ; This function should be used only if FloppyDrive_GetCountFromBIOS fails. |
---|
| 187 | ; |
---|
| 188 | ; FloppyDrive_GetCountFromBDA |
---|
| 189 | ; Parameters: |
---|
| 190 | ; Nothing |
---|
| 191 | ; Returns: |
---|
| 192 | ; CL: Number of Floppy Drives |
---|
| 193 | ; Corrupts registers: |
---|
| 194 | ; CH, ES |
---|
| 195 | ;-------------------------------------------------------------------- |
---|
| 196 | ALIGN JUMP_ALIGN |
---|
| 197 | FloppyDrive_GetCountFromBDA: |
---|
| 198 | LOAD_BDA_SEGMENT_TO es, cx |
---|
| 199 | mov cl, [es:BDA.wEquipment] ; Load Equipment WORD low byte |
---|
| 200 | mov ch, cl ; Copy it to CH |
---|
| 201 | and cx, 0C001h ; Leave bits 15..14 and 0 |
---|
| 202 | eROL_IM ch, 2 ; EW low byte bits 7..6 to 1..0 |
---|
| 203 | add cl, ch ; CL = Floppy Drive count |
---|
| 204 | ret |
---|