source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm @ 262

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

More optimizations. Merged RamVars_IsFunction/DriveHandledByThisBIOS in with FindDPT_ForDriveNumber, since they are often used together, making a returned NULL DI pointer indicate a foreign drive in many places. Revamped the iteration done in the handlers for int13/0dh and int13h/0h. Added serial specific print string during drive detection.

File size: 6.0 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   Int 13h function AH=0h, Disk Controller Reset.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Int 13h function AH=0h, Disk Controller Reset.
9;
10; AH0h_HandlerForDiskControllerReset
11;   Parameters:
12;       DL:     Translated Drive number (ignored so all drives are reset)
13;               If bit 7 is set all hard disks and floppy disks reset.
14;       DS:DI:  Ptr to DPT (in RAMVARS segment)
15;       SS:BP:  Ptr to IDEPACK
16;   Returns with INTPACK:
17;       AH:     Int 13h return status (from drive requested in DL)
18;       CF:     0 if succesfull, 1 if error
19;--------------------------------------------------------------------
20ALIGN JUMP_ALIGN
21AH0h_HandlerForDiskControllerReset:
22    eMOVZX  bx, dl                      ; Copy requested drive to BL, zero BH to assume no errors
23    call    ResetFloppyDrivesWithInt40h
24
25%ifdef MODULE_SERIAL_FLOPPY
26;
27; "Reset" emulatd serial floppy drives, if any.  There is nothing to actually do for this reset,
28; but record the proper error return code if one of these floppy drives is the drive requested.
29;
30    call    RamVars_UnpackFlopCntAndFirstToAL
31    cbw                                                 ; Clears AH (there are flop drives) or ffh (there are not)
32                                                        ; Either AH has success code (flop drives are present)
33                                                        ; or it doesn't matter because we won't match drive ffh
34
35    cwd                                                 ; clears DX (there are flop drives) or ffffh (there are not)
36
37    adc     dl, al                                      ; second drive (CF set) if present
38                                                        ; If no drive is present, this will result in ffh which 
39                                                        ; won't match a drive
40    call    BackupErrorCodeFromTheRequestedDriveToBH
41    mov     dl, al                                      ; We may end up doing the first drive twice (if there is
42    call    BackupErrorCodeFromTheRequestedDriveToBH    ; only one drive), but doing it again is not harmful.
43%endif
44
45    test    bl, bl                                      ; If we were called with a floppy disk, then we are done,
46    jns     SHORT .SkipHardDiskReset                    ; don't do hard disks.
47       
48    call    ResetForeignHardDisks
49    call    AH0h_ResetHardDisksHandledByOurBIOS
50.SkipHardDiskReset:
51    mov     ah, bh
52    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
53
54
55;--------------------------------------------------------------------
56; ResetFloppyDrivesWithInt40h
57;   Parameters:
58;       BL:     Requested drive (DL when entering AH=00h)
59;   Returns:
60;       BH:     Error code from requested drive (if available)
61;   Corrupts registers:
62;       AX, DL, DI
63;--------------------------------------------------------------------
64ALIGN JUMP_ALIGN
65ResetFloppyDrivesWithInt40h:
66    call    GetDriveNumberForForeignBiosesToDL
67    and     dl, 7Fh                     ; Clear hard disk bit
68    xor     ah, ah                      ; Disk Controller Reset
69    int     BIOS_DISKETTE_INTERRUPT_40h
70    jmp     SHORT BackupErrorCodeFromTheRequestedDriveToBH
71
72
73;--------------------------------------------------------------------
74; ResetForeignHardDisks
75;   Parameters:
76;       BL:     Requested drive (DL when entering AH=00h)
77;       DS:     RAMVARS segment
78;   Returns:
79;       BH:     Error code from requested drive (if available)
80;   Corrupts registers:
81;       AX, DL, DI
82;--------------------------------------------------------------------
83ALIGN JUMP_ALIGN
84ResetForeignHardDisks:
85    call    GetDriveNumberForForeignBiosesToDL
86    xor     ah, ah                      ; Disk Controller Reset
87    call    Int13h_CallPreviousInt13hHandler
88;;; fall-through to BackupErrorCodeFromTheRequestedDriveToBH
89
90
91;--------------------------------------------------------------------
92; BackupErrorCodeFromTheRequestedDriveToBH
93;   Parameters:
94;       AH:     Error code from the last resetted drive
95;       DL:     Drive last resetted
96;       BL:     Requested drive (DL when entering AH=00h)
97;   Returns:
98;       BH:     Backuped error code
99;   Corrupts registers:
100;       Nothing
101;--------------------------------------------------------------------
102ALIGN JUMP_ALIGN
103BackupErrorCodeFromTheRequestedDriveToBH:
104    cmp     dl, bl              ; Requested drive?
105    eCMOVE  bh, ah
106    ret
107       
108
109;--------------------------------------------------------------------
110; GetDriveNumberForForeignBiosesToDL
111;   Parameters:
112;       BL:     Requested drive (DL when entering AH=00h)
113;       DS:     RAMVARS segment
114;   Returns:
115;       DL:     BL if foreign drive
116;               80h if our drive
117;   Corrupts registers:
118;       DI
119;--------------------------------------------------------------------
120ALIGN JUMP_ALIGN
121GetDriveNumberForForeignBiosesToDL:
122    mov     dl, bl
123    test    di, di
124    jz      SHORT .Return               ; Return what was in BL unmodified
125    mov     dl, 80h
126.Return:
127    ret
128
129
130;--------------------------------------------------------------------
131; AH0h_ResetHardDisksHandledByOurBIOS
132;   Parameters:
133;       BL:     Requested drive (DL when entering AH=00h)
134;       DS:     RAMVARS segment
135;       SS:BP:  Ptr to IDEPACK
136;   Returns:
137;       BH:     Error code from requested drive (if available)
138;   Corrupts registers:
139;       AX, CX, DX, SI, DI
140;--------------------------------------------------------------------
141ALIGN JUMP_ALIGN
142AH0h_ResetHardDisksHandledByOurBIOS:
143    mov     bl, [di+DPT.bIdevarsOffset]                 ; replace drive number with Idevars pointer for comparisons
144    mov     cl, [cs:ROMVARS.bIdeCnt]                    ; get count of ide controllers
145    mov     ch, 0                                       
146    mov     dl, 0                                       ; starting Idevars offset
147    mov     si, IterateFindFirstDPTforIdevars           ; iteration routine
148.loop:
149    call    IterateAllDPTs                              ; look for the first drive on this controller, if any
150    jc      .notFound
151    call    AHDh_ResetDrive                             ; reset master and slave on that controller
152    call    BackupErrorCodeFromTheRequestedDriveToBH    ; save error code if same controller as initial request
153.notFound:
154    add     dl, IDEVARS_size                            ; move pointer forward
155    loop    .loop                                       ; and repeat
156    ret
157
158;--------------------------------------------------------------------
159; Iteration routine for AH0h_ResetHardDisksHandledByOurBIOS, 
160; for use with IterateAllDPTs
161; 
162; Returns when DPT is found on the controller with Idevars offset in DL
163;--------------------------------------------------------------------
164IterateFindFirstDPTforIdevars:     
165    cmp     dl, [di+DPT.bIdevarsOffset]         ; Clears CF if matched
166    jz      .done
167    stc                                         ; Set CF for not found
168.done: 
169    ret
Note: See TracBrowser for help on using the repository browser.