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

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

Changes:

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