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

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

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 6.2 KB
RevLine 
[102]1; Project name  :   XTIDE Universal BIOS
[3]2; Description   :   Various floppy drive related functions that
3;                   Boot Menu uses.
4
[376]5;
6; XTIDE Universal BIOS and Associated Tools 
7; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
8;
9; This program is free software; you can redistribute it and/or modify
10; it under the terms of the GNU General Public License as published by
11; the Free Software Foundation; either version 2 of the License, or
12; (at your option) any later version.
13; 
14; This program is distributed in the hope that it will be useful,
15; but WITHOUT ANY WARRANTY; without even the implied warranty of
16; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17; GNU General Public License for more details.     
18; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19;       
20
[3]21; Section containing code
22SECTION .text
23
24;--------------------------------------------------------------------
25; Checks is floppy drive handler installed to interrupt vector 40h.
26;
27; FloppyDrive_IsInt40hInstalled
28;   Parameters:
29;       ES:     BDA and Interrupt Vector segment (zero)
30;   Returns:
31;       CF:     Set if INT 40h is installed
32;               Cleared if INT 40h is not installed
33;   Corrupts registers:
34;       BX, CX, DI
[86]35;--------------------------------------------------------------------
[3]36FloppyDrive_IsInt40hInstalled:
[152]37    cmp     WORD [es:BIOS_DISKETTE_INTERRUPT_40h*4+2], 0C000h   ; Any ROM segment?
[102]38%ifdef USE_AT   ; No need to verify on XT systems.
[39]39    jb      SHORT .Int40hHandlerIsNotInstalled
40    call    .VerifyInt40hHandlerSinceSomeBiosesSimplyReturnFromInt40h
[102]41.Int40hHandlerIsNotInstalled:
[99]42%endif
[27]43    cmc
[3]44    ret
45
[39]46;--------------------------------------------------------------------
47; .VerifyInt40hHandlerSinceSomeBiosesSimplyReturnFromInt40h
48;   Parameters:
49;       Nothing
50;   Returns:
51;       CF:     Cleared if INT 40h is installed
52;               Set if INT 40h is not installed
53;   Corrupts registers:
54;       BX, CX, DI
[86]55;--------------------------------------------------------------------
[99]56%ifdef USE_AT
[39]57.VerifyInt40hHandlerSinceSomeBiosesSimplyReturnFromInt40h:
58    push    es
59    push    dx
60    push    ax
[3]61
[39]62    call    .LoadInt40hVerifyParameters
[152]63    int     BIOS_DISK_INTERRUPT_13h
[99]64    jc      SHORT .Int40hIsInstalled    ; Maybe there are not any floppy drives at all
65    push    es
66    push    di
[39]67
68    call    .LoadInt40hVerifyParameters
[152]69    int     BIOS_DISKETTE_INTERRUPT_40h
[39]70
71    pop     dx
72    pop     cx
73    cmp     dx, di                      ; Difference in offsets?
74    jne     SHORT .Int40hNotInstalled
75    mov     dx, es
76    cmp     cx, dx                      ; Difference in segments?
[99]77    je      SHORT .Int40hIsInstalled
[39]78.Int40hNotInstalled:
79    stc
80.Int40hIsInstalled:
81    pop     ax
82    pop     dx
83    pop     es
84    ret
85
[3]86;--------------------------------------------------------------------
[39]87; .LoadInt40hVerifyParameters
88;   Parameters:
89;       Nothing
90;   Returns:
91;       AH:     08h (Get Drive Parameters)
92;       DL:     00h (floppy drive)
93;       ES:DI:  0:0h (to guard against BIOS bugs)
94;   Corrupts registers:
95;       DH
[86]96;--------------------------------------------------------------------
[39]97.LoadInt40hVerifyParameters:
[86]98    mov     ah, 08h             ; Get Drive Parameters
99    cwd                         ; Floppy drive 0
[39]100    mov     di, dx
101    mov     es, dx              ; ES:DI = 0000:0000h to guard against BIOS bugs
102    ret
[99]103%endif
[39]104
105
106;--------------------------------------------------------------------
[3]107; Returns floppy drive type.
108; PC/XT system do not support AH=08h but FLOPPY_TYPE_525_OR_35_DD
109; is still returned for them.
110;
111; FloppyDrive_GetType
112;   Parameters:
113;       DL:     Floppy Drive number
114;   Returns:
115;       BX:     Floppy Drive Type:
116;                   FLOPPY_TYPE_525_OR_35_DD
117;                   FLOPPY_TYPE_525_DD
118;                   FLOPPY_TYPE_525_HD
119;                   FLOPPY_TYPE_35_DD
120;                   FLOPPY_TYPE_35_HD
121;                   FLOPPY_TYPE_35_ED
122;       CF:     Set if AH=08h not supported (XT systems) or error
123;               Cleared if type read correctly (AT systems)
124;   Corrupts registers:
125;       AX, CX, DX, DI, ES
126;--------------------------------------------------------------------
127FloppyDrive_GetType:
128    mov     ah, 08h         ; Get Drive Parameters
129    xor     bx, bx          ; FLOPPY_TYPE_525_OR_35_DD when function not supported
[152]130    int     BIOS_DISKETTE_INTERRUPT_40h
[3]131    ret
132
133
134;--------------------------------------------------------------------
135; Returns number of Floppy Drives in system.
136;
[258]137; FloppyDrive_GetCountToAX
[3]138;   Parameters:
[258]139;       DS:     RAMVARS Segment
[3]140;   Returns:
[258]141;       AX:     Number of Floppy Drives
[3]142;--------------------------------------------------------------------
[294]143FloppyDrive_GetCountToAX:
[258]144%ifdef MODULE_SERIAL_FLOPPY
145    call    RamVars_UnpackFlopCntAndFirstToAL
[270]146    js      .UseBIOSorBDA               ; We didn't add in any drives, counts here are not valid
[294]147
148    adc     al,1                        ; adds in the drive count bit, and adds 1 for count vs. 0-index,
[270]149    jmp     .FinishCalc                 ; need to clear AH on the way out, and add in minimum drive numbers
[258]150
[294]151.UseBIOSorBDA:
[99]152%endif
[258]153    call    FloppyDrive_GetCountFromBIOS_or_BDA
[270]154
[294]155.FinishCalc:
[258]156    mov     ah, [cs:ROMVARS.bMinFddCnt]
157    MAX_U   al, ah
158    cbw
[294]159
[3]160    ret
161
[258]162FloppyDrive_GetCountFromBIOS_or_BDA:
163    push    es
[3]164
165;--------------------------------------------------------------------
166; Reads Floppy Drive Count from BIOS.
[294]167; Does not work on most XT systems. Call .GetCountFromBDA
[3]168; if this function fails.
169;
[294]170; .GetCountFromBIOS
[3]171;   Parameters:
172;       Nothing
173;   Returns:
[274]174;       AL:     Number of Floppy Drives
[294]175;       CF:     Cleared if successful
[3]176;               Set if BIOS function not supported
177;   Corrupts registers:
[274]178;       ES
[3]179;--------------------------------------------------------------------
[99]180%ifdef USE_AT
[258]181.GetCountFromBIOS:
[3]182    push    di
[274]183    push    bx
184    push    cx
[3]185    push    dx
186
187    mov     ah, 08h                 ; Get Drive Parameters
[86]188    cwd                             ; Floppy Drive 00h
[152]189    int     BIOS_DISKETTE_INTERRUPT_40h
[258]190    mov     al, dl                  ; Number of Floppy Drives to AL
[3]191
[274]192    pop     dx
193    pop     cx
[3]194    pop     bx
195    pop     di
[99]196%endif
[3]197
198;--------------------------------------------------------------------
199; Reads Floppy Drive Count (0...4) from BIOS Data Area.
[294]200; This function should be used only if .GetCountFromBIOS fails.
[3]201;
[294]202; .GetCountFromBDA
[3]203;   Parameters:
204;       Nothing
205;   Returns:
[294]206;       AL:     Number of Floppy Drives
[3]207;   Corrupts registers:
[294]208;       AH, ES
[3]209;--------------------------------------------------------------------
[99]210%ifndef USE_AT
[258]211.GetCountFromBDA:
212    LOAD_BDA_SEGMENT_TO es, ax
213    mov     al, [es:BDA.wEquipment]         ; Load Equipment WORD low byte
[294]214    mov     ah, al                          ; Copy it to AH
[258]215    and     ax, 0C001h                      ; Leave bits 15..14 and 0
216    eROL_IM ah, 2                           ; EW low byte bits 7..6 to 1..0
[294]217    add     al, ah                          ; AL = Floppy Drive count
[258]218%endif
219
220    pop     es
[3]221    ret
Note: See TracBrowser for help on using the repository browser.