source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Initialization/FloppyDrive.asm @ 181

Last change on this file since 181 was 181, checked in by krille_n_@…, 12 years ago

Changes to all parts of the project:

  • Size optimizations.
  • Added a define (EXCLUDE_FROM_XTIDECFG) to exclude unused library code from XTIDECFG.
  • Tried to minimize time spent with interrupts disabled.
  • Some minor attempts to improve speed (reordering instructions etc).
  • Tried to improve readability, did some cleanup and fixed some errors in comments.
File size: 5.3 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   Various floppy drive related functions that
3;                   Boot Menu uses.
4
5; Section containing code
6SECTION .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
19;--------------------------------------------------------------------
20FloppyDrive_IsInt40hInstalled:
21    cmp     WORD [es:BIOS_DISKETTE_INTERRUPT_40h*4+2], 0C000h   ; Any ROM segment?
22%ifdef USE_AT   ; No need to verify on XT systems.
23    jb      SHORT .Int40hHandlerIsNotInstalled
24    call    .VerifyInt40hHandlerSinceSomeBiosesSimplyReturnFromInt40h
25.Int40hHandlerIsNotInstalled:
26%endif
27    cmc
28    ret
29
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
39;--------------------------------------------------------------------
40%ifdef USE_AT
41.VerifyInt40hHandlerSinceSomeBiosesSimplyReturnFromInt40h:
42    push    es
43    push    dx
44    push    ax
45
46    call    .LoadInt40hVerifyParameters
47    int     BIOS_DISK_INTERRUPT_13h
48    jc      SHORT .Int40hIsInstalled    ; Maybe there are not any floppy drives at all
49    push    es
50    push    di
51
52    call    .LoadInt40hVerifyParameters
53    int     BIOS_DISKETTE_INTERRUPT_40h
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?
61    je      SHORT .Int40hIsInstalled
62.Int40hNotInstalled:
63    stc
64.Int40hIsInstalled:
65    pop     ax
66    pop     dx
67    pop     es
68    ret
69
70;--------------------------------------------------------------------
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
80;--------------------------------------------------------------------
81.LoadInt40hVerifyParameters:
82    mov     ah, 08h             ; Get Drive Parameters
83    cwd                         ; Floppy drive 0
84    mov     di, dx
85    mov     es, dx              ; ES:DI = 0000:0000h to guard against BIOS bugs
86    ret
87%endif
88
89
90;--------------------------------------------------------------------
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;--------------------------------------------------------------------
111ALIGN JUMP_ALIGN
112FloppyDrive_GetType:
113    mov     ah, 08h         ; Get Drive Parameters
114    xor     bx, bx          ; FLOPPY_TYPE_525_OR_35_DD when function not supported
115    int     BIOS_DISKETTE_INTERRUPT_40h
116    ret
117
118
119;--------------------------------------------------------------------
120; Returns number of Floppy Drives in system.
121;
122; FloppyDrive_GetCountToCX
123;   Parameters:
124;       Nothing
125;   Returns:
126;       CX:     Number of Floppy Drives
127;   Corrupts registers:
128;       Nothing
129;--------------------------------------------------------------------
130ALIGN JUMP_ALIGN
131FloppyDrive_GetCountToCX:
132    push    es
133%ifdef USE_AT
134    call    GetCountFromBIOS
135%else
136    call    GetCountFromBDA
137%endif
138    mov     ch, [cs:ROMVARS.bMinFddCnt]
139    MAX_U   cl, ch
140    pop     es
141    xor     ch, ch
142    ret
143
144
145;--------------------------------------------------------------------
146; Reads Floppy Drive Count from BIOS.
147; Does not work on most XT systems. Call FloppyDrive_GetCountFromBDA
148; if this function fails.
149;
150; GetCountFromBIOS
151;   Parameters:
152;       Nothing
153;   Returns:
154;       CL:     Number of Floppy Drives
155;       CF:     Cleared if successfull
156;               Set if BIOS function not supported
157;   Corrupts registers:
158;       CH, ES
159;--------------------------------------------------------------------
160%ifdef USE_AT
161ALIGN JUMP_ALIGN
162GetCountFromBIOS:
163    push    di
164    push    dx
165    push    bx
166    push    ax
167
168    mov     ah, 08h                 ; Get Drive Parameters
169    cwd                             ; Floppy Drive 00h
170    int     BIOS_DISKETTE_INTERRUPT_40h
171    mov     cl, dl                  ; Number of Floppy Drives to CL
172
173    pop     ax
174    pop     bx
175    pop     dx
176    pop     di
177    ret
178%endif
179
180
181;--------------------------------------------------------------------
182; Reads Floppy Drive Count (0...4) from BIOS Data Area.
183; This function should be used only if FloppyDrive_GetCountFromBIOS fails.
184;
185; GetCountFromBDA
186;   Parameters:
187;       Nothing
188;   Returns:
189;       CL:     Number of Floppy Drives
190;   Corrupts registers:
191;       CH, ES
192;--------------------------------------------------------------------
193%ifndef USE_AT
194ALIGN JUMP_ALIGN
195GetCountFromBDA:
196    LOAD_BDA_SEGMENT_TO es, cx
197    mov     cl, [es:BDA.wEquipment]         ; Load Equipment WORD low byte
198    mov     ch, cl                          ; Copy it to CH
199    and     cx, 0C001h                      ; Leave bits 15..14 and 0
200    eROL_IM ch, 2                           ; EW low byte bits 7..6 to 1..0
201    add     cl, ch                          ; CL = Floppy Drive count
202    ret
203%endif
Note: See TracBrowser for help on using the repository browser.