[102] | 1 | ; Project name : XTIDE Universal BIOS |
---|
[3] | 2 | ; Description : Various floppy drive related functions that |
---|
| 3 | ; Boot Menu uses. |
---|
| 4 | |
---|
| 5 | ; Section containing code |
---|
| 6 | SECTION .text |
---|
| 7 | |
---|
| 8 | ;-------------------------------------------------------------------- |
---|
| 9 | ; Checks is floppy drive handler installed to interrupt vector 40h. |
---|
| 10 | ; |
---|
| 11 | ; FloppyDrive_IsInt40hInstalled |
---|
| 12 | ; Parameters: |
---|
| 13 | ; ES: BDA and Interrupt Vector segment (zero) |
---|
| 14 | ; Returns: |
---|
| 15 | ; CF: Set if INT 40h is installed |
---|
| 16 | ; Cleared if INT 40h is not installed |
---|
| 17 | ; Corrupts registers: |
---|
| 18 | ; BX, CX, DI |
---|
[86] | 19 | ;-------------------------------------------------------------------- |
---|
[3] | 20 | FloppyDrive_IsInt40hInstalled: |
---|
[152] | 21 | cmp WORD [es:BIOS_DISKETTE_INTERRUPT_40h*4+2], 0C000h ; Any ROM segment? |
---|
[102] | 22 | %ifdef USE_AT ; No need to verify on XT systems. |
---|
[39] | 23 | jb SHORT .Int40hHandlerIsNotInstalled |
---|
| 24 | call .VerifyInt40hHandlerSinceSomeBiosesSimplyReturnFromInt40h |
---|
[102] | 25 | .Int40hHandlerIsNotInstalled: |
---|
[99] | 26 | %endif |
---|
[27] | 27 | cmc |
---|
[3] | 28 | ret |
---|
| 29 | |
---|
[39] | 30 | ;-------------------------------------------------------------------- |
---|
| 31 | ; .VerifyInt40hHandlerSinceSomeBiosesSimplyReturnFromInt40h |
---|
| 32 | ; Parameters: |
---|
| 33 | ; Nothing |
---|
| 34 | ; Returns: |
---|
| 35 | ; CF: Cleared if INT 40h is installed |
---|
| 36 | ; Set if INT 40h is not installed |
---|
| 37 | ; Corrupts registers: |
---|
| 38 | ; BX, CX, DI |
---|
[86] | 39 | ;-------------------------------------------------------------------- |
---|
[99] | 40 | %ifdef USE_AT |
---|
[39] | 41 | .VerifyInt40hHandlerSinceSomeBiosesSimplyReturnFromInt40h: |
---|
| 42 | push es |
---|
| 43 | push dx |
---|
| 44 | push ax |
---|
[3] | 45 | |
---|
[39] | 46 | call .LoadInt40hVerifyParameters |
---|
[152] | 47 | int BIOS_DISK_INTERRUPT_13h |
---|
[99] | 48 | jc SHORT .Int40hIsInstalled ; Maybe there are not any floppy drives at all |
---|
| 49 | push es |
---|
| 50 | push di |
---|
[39] | 51 | |
---|
| 52 | call .LoadInt40hVerifyParameters |
---|
[152] | 53 | int BIOS_DISKETTE_INTERRUPT_40h |
---|
[39] | 54 | |
---|
| 55 | pop dx |
---|
| 56 | pop cx |
---|
| 57 | cmp dx, di ; Difference in offsets? |
---|
| 58 | jne SHORT .Int40hNotInstalled |
---|
| 59 | mov dx, es |
---|
| 60 | cmp cx, dx ; Difference in segments? |
---|
[99] | 61 | je SHORT .Int40hIsInstalled |
---|
[39] | 62 | .Int40hNotInstalled: |
---|
| 63 | stc |
---|
| 64 | .Int40hIsInstalled: |
---|
| 65 | pop ax |
---|
| 66 | pop dx |
---|
| 67 | pop es |
---|
| 68 | ret |
---|
| 69 | |
---|
[3] | 70 | ;-------------------------------------------------------------------- |
---|
[39] | 71 | ; .LoadInt40hVerifyParameters |
---|
| 72 | ; Parameters: |
---|
| 73 | ; Nothing |
---|
| 74 | ; Returns: |
---|
| 75 | ; AH: 08h (Get Drive Parameters) |
---|
| 76 | ; DL: 00h (floppy drive) |
---|
| 77 | ; ES:DI: 0:0h (to guard against BIOS bugs) |
---|
| 78 | ; Corrupts registers: |
---|
| 79 | ; DH |
---|
[86] | 80 | ;-------------------------------------------------------------------- |
---|
[39] | 81 | .LoadInt40hVerifyParameters: |
---|
[86] | 82 | mov ah, 08h ; Get Drive Parameters |
---|
| 83 | cwd ; Floppy drive 0 |
---|
[39] | 84 | mov di, dx |
---|
| 85 | mov es, dx ; ES:DI = 0000:0000h to guard against BIOS bugs |
---|
| 86 | ret |
---|
[99] | 87 | %endif |
---|
[39] | 88 | |
---|
| 89 | |
---|
| 90 | ;-------------------------------------------------------------------- |
---|
[3] | 91 | ; Returns floppy drive type. |
---|
| 92 | ; PC/XT system do not support AH=08h but FLOPPY_TYPE_525_OR_35_DD |
---|
| 93 | ; is still returned for them. |
---|
| 94 | ; |
---|
| 95 | ; FloppyDrive_GetType |
---|
| 96 | ; Parameters: |
---|
| 97 | ; DL: Floppy Drive number |
---|
| 98 | ; Returns: |
---|
| 99 | ; BX: Floppy Drive Type: |
---|
| 100 | ; FLOPPY_TYPE_525_OR_35_DD |
---|
| 101 | ; FLOPPY_TYPE_525_DD |
---|
| 102 | ; FLOPPY_TYPE_525_HD |
---|
| 103 | ; FLOPPY_TYPE_35_DD |
---|
| 104 | ; FLOPPY_TYPE_35_HD |
---|
| 105 | ; FLOPPY_TYPE_35_ED |
---|
| 106 | ; CF: Set if AH=08h not supported (XT systems) or error |
---|
| 107 | ; Cleared if type read correctly (AT systems) |
---|
| 108 | ; Corrupts registers: |
---|
| 109 | ; AX, CX, DX, DI, ES |
---|
| 110 | ;-------------------------------------------------------------------- |
---|
| 111 | ALIGN JUMP_ALIGN |
---|
| 112 | FloppyDrive_GetType: |
---|
| 113 | mov ah, 08h ; Get Drive Parameters |
---|
| 114 | xor bx, bx ; FLOPPY_TYPE_525_OR_35_DD when function not supported |
---|
[152] | 115 | int BIOS_DISKETTE_INTERRUPT_40h |
---|
[3] | 116 | ret |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | ;-------------------------------------------------------------------- |
---|
| 120 | ; Returns number of Floppy Drives in system. |
---|
| 121 | ; |
---|
[258] | 122 | ; FloppyDrive_GetCountToAX |
---|
[3] | 123 | ; Parameters: |
---|
[258] | 124 | ; DS: RAMVARS Segment |
---|
[3] | 125 | ; Returns: |
---|
[258] | 126 | ; AX: Number of Floppy Drives |
---|
[3] | 127 | ;-------------------------------------------------------------------- |
---|
| 128 | ALIGN JUMP_ALIGN |
---|
[258] | 129 | FloppyDrive_GetCountToAX: |
---|
| 130 | %ifdef MODULE_SERIAL_FLOPPY |
---|
| 131 | call RamVars_UnpackFlopCntAndFirstToAL |
---|
| 132 | adc al,1 ; adds in the drive count bit, and adds 1 for count vs. 0-index, |
---|
| 133 | ; but still won't impact SF |
---|
| 134 | jns .UseInternalNumber ; need to clear CH on the way out, and add in additional drive numbers |
---|
| 135 | |
---|
[99] | 136 | %endif |
---|
[258] | 137 | call FloppyDrive_GetCountFromBIOS_or_BDA |
---|
| 138 | |
---|
| 139 | .UseInternalNumber: |
---|
| 140 | mov ah, [cs:ROMVARS.bMinFddCnt] |
---|
| 141 | MAX_U al, ah |
---|
| 142 | cbw |
---|
| 143 | |
---|
[3] | 144 | ret |
---|
| 145 | |
---|
[258] | 146 | ALIGN JUMP_ALIGN |
---|
| 147 | FloppyDrive_GetCountFromBIOS_or_BDA: |
---|
| 148 | push es |
---|
[3] | 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 | ; |
---|
[124] | 155 | ; GetCountFromBIOS |
---|
[3] | 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 | ;-------------------------------------------------------------------- |
---|
[99] | 165 | %ifdef USE_AT |
---|
[3] | 166 | ALIGN JUMP_ALIGN |
---|
[258] | 167 | .GetCountFromBIOS: |
---|
[3] | 168 | push di |
---|
| 169 | push dx |
---|
| 170 | push bx |
---|
| 171 | |
---|
| 172 | mov ah, 08h ; Get Drive Parameters |
---|
[86] | 173 | cwd ; Floppy Drive 00h |
---|
[152] | 174 | int BIOS_DISKETTE_INTERRUPT_40h |
---|
[258] | 175 | mov al, dl ; Number of Floppy Drives to AL |
---|
[3] | 176 | |
---|
| 177 | pop bx |
---|
| 178 | pop dx |
---|
| 179 | pop di |
---|
[99] | 180 | %endif |
---|
[3] | 181 | |
---|
| 182 | ;-------------------------------------------------------------------- |
---|
| 183 | ; Reads Floppy Drive Count (0...4) from BIOS Data Area. |
---|
| 184 | ; This function should be used only if FloppyDrive_GetCountFromBIOS fails. |
---|
| 185 | ; |
---|
[124] | 186 | ; GetCountFromBDA |
---|
[3] | 187 | ; Parameters: |
---|
| 188 | ; Nothing |
---|
| 189 | ; Returns: |
---|
| 190 | ; CL: Number of Floppy Drives |
---|
| 191 | ; Corrupts registers: |
---|
| 192 | ; CH, ES |
---|
| 193 | ;-------------------------------------------------------------------- |
---|
[99] | 194 | %ifndef USE_AT |
---|
[3] | 195 | ALIGN JUMP_ALIGN |
---|
[258] | 196 | .GetCountFromBDA: |
---|
| 197 | LOAD_BDA_SEGMENT_TO es, ax |
---|
| 198 | mov al, [es:BDA.wEquipment] ; Load Equipment WORD low byte |
---|
| 199 | mov ah, al ; Copy it to CH |
---|
| 200 | and ax, 0C001h ; Leave bits 15..14 and 0 |
---|
| 201 | eROL_IM ah, 2 ; EW low byte bits 7..6 to 1..0 |
---|
| 202 | add al, ah ; CL = Floppy Drive count |
---|
| 203 | %endif |
---|
| 204 | |
---|
| 205 | pop es |
---|
[3] | 206 | ret |
---|
[258] | 207 | |
---|