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

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

Added floppy drive emulation over the serial connection (MODULE_SERIAL_FLOPPY). Along the way, various optimizations were made to stay within the 8K ROM size target. Also, serial code now returns the number of sectors transferred.

File size: 6.5 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    call    ResetForeignHardDisks
25    call    AH0h_ResetHardDisksHandledByOurBIOS
26.SkipHardDiskReset:
27    mov     ah, bh
28    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
29
30
31;--------------------------------------------------------------------
32; ResetFloppyDrivesWithInt40h
33;   Parameters:
34;       BL:     Requested drive (DL when entering AH=00h)
35;   Returns:
36;       BH:     Error code from requested drive (if available)
37;   Corrupts registers:
38;       AX, DL, DI
39;--------------------------------------------------------------------
40ALIGN JUMP_ALIGN
41ResetFloppyDrivesWithInt40h:
42    call    GetDriveNumberForForeignBiosesToDL
43    and     dl, 7Fh                     ; Clear hard disk bit
44    xor     ah, ah                      ; Disk Controller Reset
45    int     BIOS_DISKETTE_INTERRUPT_40h
46    jmp     SHORT BackupErrorCodeFromTheRequestedDriveToBH
47
48
49;--------------------------------------------------------------------
50; ResetForeignHardDisks
51;   Parameters:
52;       BL:     Requested drive (DL when entering AH=00h)
53;       DS:     RAMVARS segment
54;   Returns:
55;       BH:     Error code from requested drive (if available)
56;   Corrupts registers:
57;       AX, DL, DI
58;--------------------------------------------------------------------
59ALIGN JUMP_ALIGN
60ResetForeignHardDisks:
61    call    GetDriveNumberForForeignBiosesToDL
62    xor     ah, ah                      ; Disk Controller Reset
63    call    Int13h_CallPreviousInt13hHandler
64;;; fall-through to BackupErrorCodeFromTheRequestedDriveToBH
65
66
67;--------------------------------------------------------------------
68; BackupErrorCodeFromTheRequestedDriveToBH
69;   Parameters:
70;       AH:     Error code from the last resetted drive
71;       DL:     Drive last resetted
72;       BL:     Requested drive (DL when entering AH=00h)
73;   Returns:
74;       BH:     Backuped error code
75;   Corrupts registers:
76;       Nothing
77;--------------------------------------------------------------------
78ALIGN JUMP_ALIGN
79BackupErrorCodeFromTheRequestedDriveToBH:
80    cmp     dl, bl              ; Requested drive?
81    eCMOVE  bh, ah
82    ret
83       
84
85;--------------------------------------------------------------------
86; GetDriveNumberForForeignBiosesToDL
87;   Parameters:
88;       BL:     Requested drive (DL when entering AH=00h)
89;       DS:     RAMVARS segment
90;   Returns:
91;       DL:     BL if foreign drive
92;               80h if our drive
93;   Corrupts registers:
94;       DI
95;--------------------------------------------------------------------
96ALIGN JUMP_ALIGN
97GetDriveNumberForForeignBiosesToDL:
98    mov     dl, bl
99    call    RamVars_IsDriveHandledByThisBIOS
100    jc      SHORT .Return               ; Return what was in BL unmodified
101    mov     dl, 80h
102.Return:
103    ret
104
105
106;--------------------------------------------------------------------
107; AH0h_ResetHardDisksHandledByOurBIOS
108;   Parameters:
109;       BL:     Requested drive (DL when entering AH=00h)
110;       DS:     RAMVARS segment
111;       SS:BP:  Ptr to IDEPACK
112;   Returns:
113;       BH:     Error code from requested drive (if available)
114;   Corrupts registers:
115;       AX, CX, DX, SI, DI
116;--------------------------------------------------------------------
117ALIGN JUMP_ALIGN
118AH0h_ResetHardDisksHandledByOurBIOS:
119    mov     dx, [RAMVARS.wDrvCntAndFirst]   ; DL = drive number, DH = drive count
120    test    dh, dh
121    jz      SHORT .AllDrivesReset       ; Return if no drives
122    add     dh, dl                      ; DH = one past last drive to reset
123ALIGN JUMP_ALIGN
124.DriveResetLoop:
125    call    AHDh_ResetDrive
126    call    .BackupErrorCodeFromMasterOrSlaveToBH
127    inc     dx
128    cmp     dl, dh                      ; All done?
129    jb      SHORT .DriveResetLoop       ;  If not, reset next drive
130.AllDrivesReset:
131%ifdef MODULE_SERIAL_FLOPPY
132;
133; "Reset" emulatd serial floppy drives, if any.  There is nothing to actually do for this reset,
134; but record the proper error return code if one of these floppy drives is the drive requested.
135;
136    call    RamVars_UnpackFlopCntAndFirstToAL
137
138    cbw                                                 ; Clears AH (there are flop drives) or ffh (there are not)
139                                                        ; Either AH has success code (flop drives are present)
140                                                        ; or it doesn't matter because we won't match drive ffh
141
142    cwd                                                 ; clears DX (there are flop drives) or ffffh (there are not)
143
144    adc     dl, al                                      ; second drive (CF set) if present
145                                                        ; If no drive is present, this will result in ffh which 
146                                                        ; won't match a drive
147    call    BackupErrorCodeFromTheRequestedDriveToBH
148    mov     dl, al                                      ; We may end up doing the first drive twice (if there is
149    jmp     BackupErrorCodeFromTheRequestedDriveToBH    ; only one drive), but doing it again is not harmful.
150%else
151    ret
152%endif
153       
154;--------------------------------------------------------------------
155; .BackupErrorCodeFromMasterOrSlaveToBH
156;   Parameters:
157;       AH:     Error code for drive DL reset
158;       BL:     Requested drive (DL when entering AH=00h)
159;       DL:     Drive just resetted
160;       DS:     RAMVARS segment
161;   Returns:
162;       BH:     Backuped error code
163;       DL:     Incremented if next drive is slave drive
164;               (=already resetted)
165;   Corrupts registers:
166;       CX, DI
167;--------------------------------------------------------------------
168ALIGN JUMP_ALIGN
169.BackupErrorCodeFromMasterOrSlaveToBH:
170    call    BackupErrorCodeFromTheRequestedDriveToBH
171    call    GetBasePortToCX             ; Load base port for resetted drive
172    push    cx
173    inc     dx                          ; DL to next drive
174    call    GetBasePortToCX
175    pop     di
176    cmp     cx, di                      ; Next drive is from same controller?
177    je      SHORT BackupErrorCodeFromTheRequestedDriveToBH
178.NoMoreDrivesOrNoSlaveDrive:
179    dec     dx
180    ret
181
182       
183;--------------------------------------------------------------------
184; GetBasePortToCX
185;   Parameters:
186;       DL:     Drive number
187;       DS:     RAMVARS segment
188;   Returns:
189;       CX:     Base port address
190;       CF:     Set if valid drive number
191;               Cleared if invalid drive number
192;   Corrupts registers:
193;       DI
194;--------------------------------------------------------------------
195ALIGN JUMP_ALIGN
196GetBasePortToCX:
197    xchg    cx, bx
198    xor     bx, bx
199    call    FindDPT_ForDriveNumber
200    mov     bl, [di+DPT.bIdevarsOffset]
201    mov     bx, [cs:bx+IDEVARS.wPort]
202    xchg    bx, cx
203    ret
204
205
Note: See TracBrowser for help on using the repository browser.