Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm	(revision 269)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm	(revision 271)
@@ -8,9 +8,12 @@
 ; Int 13h function AH=0h, Disk Controller Reset.
 ;
+; Note: We handle all AH=0h calls, even for drives handled by other
+; BIOSes!
+;
 ; AH0h_HandlerForDiskControllerReset
 ;	Parameters:
 ;		DL:		Translated Drive number (ignored so all drives are reset)
 ;				If bit 7 is set all hard disks and floppy disks reset.
-;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;		DS:DI:	Ptr to DPT (only if DL is our drive)
 ;		SS:BP:	Ptr to IDEPACK
 ;	Returns with INTPACK:
@@ -49,6 +52,7 @@
 
 	; Resetting our hard disks will modify dl and bl such that this call must be the last in the list
-	;
-	call	AH0h_ResetHardDisksHandledByOurBIOS			
+	call	GetDriveNumberForForeignHardDiskHandlerToDL	; Load DPT for our drive
+	jc		SHORT .SkipHardDiskReset					; Our drive not requested so let's not reset them
+	call	ResetHardDisksHandledByOurBIOS			
 
 .SkipHardDiskReset:
@@ -66,7 +70,6 @@
 ;		AX, DL, DI
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
 ResetFloppyDrivesWithInt40h:
-	call	GetDriveNumberForForeignBiosesToDL
+	call	GetDriveNumberForForeignHardDiskHandlerToDL
 	and		dl, 7Fh						; Clear hard disk bit
 	xor		ah, ah						; Disk Controller Reset
@@ -85,7 +88,6 @@
 ;		AX, DL, DI
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
 ResetForeignHardDisks:
-	call	GetDriveNumberForForeignBiosesToDL
+	call	GetDriveNumberForForeignHardDiskHandlerToDL
 	xor		ah, ah						; Disk Controller Reset
 	call	Int13h_CallPreviousInt13hHandler
@@ -104,37 +106,53 @@
 ;		Nothing
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
 BackupErrorCodeFromTheRequestedDriveToBH:
 	cmp		dl, bl				; Requested drive?
 	eCMOVE	bh, ah
 	ret
-		
+
 
 ;--------------------------------------------------------------------
-; GetDriveNumberForForeignBiosesToDL
+; GetDriveNumberForForeignHardDiskHandlerToDL
 ;	Parameters:
 ;		BL:		Requested drive (DL when entering AH=00h)
 ;		DS:		RAMVARS segment
 ;	Returns:
+;		DS:DI:	Ptr to DPT if our drive
 ;		DL:		BL if foreign drive
 ;				80h if our drive
+;		CF:		Set if foreign drive
+;				Cleared if our drive
 ;	Corrupts registers:
-;		DI
+;		(DI)
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-GetDriveNumberForForeignBiosesToDL:
+GetDriveNumberForForeignHardDiskHandlerToDL:
 	mov		dl, bl
-	test	di, di
-	jz		SHORT .Return				; Return what was in BL unmodified
-	mov		dl, 80h
-.Return:
+	call	FindDPT_ForDriveNumberInDL
+	jc		SHORT .ReturnWithForeignDriveInDL
+	mov		dl, 80h				; First possible Hard Disk should be safe value
+.ReturnWithForeignDriveInDL:
 	ret
 
 
 ;--------------------------------------------------------------------
-; AH0h_ResetHardDisksHandledByOurBIOS
+; AH0h_ResetAllOurHardDisksAtTheEndOfDriveInitialization
+;	Parameters:
+;		DS:		RAMVARS segment
+;		SS:BP:	Ptr to IDEPACK
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, CX, DX, SI, DI
+;--------------------------------------------------------------------
+AH0h_ResetAllOurHardDisksAtTheEndOfDriveInitialization:
+	mov		bl, [RAMVARS.bFirstDrv]
+	call	GetDriveNumberForForeignHardDiskHandlerToDL
+	; Fall to ResetHardDisksHandledByOurBIOS
+
+;--------------------------------------------------------------------
+; ResetHardDisksHandledByOurBIOS
 ;	Parameters:
 ;		BL:		Requested drive (DL when entering AH=00h)
-;		DS:		RAMVARS segment
+;		DS:DI:	Ptr to DPT for requested drive
 ;		SS:BP:	Ptr to IDEPACK
 ;	Returns:
@@ -143,16 +161,12 @@
 ;		AX, CX, DX, SI, DI
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-AH0h_ResetHardDisksHandledByOurBIOS:
+ResetHardDisksHandledByOurBIOS:
 	mov		bl, [di+DPT.bIdevarsOffset]					; replace drive number with Idevars pointer for cmp with dl
 	mov		dl, ROMVARS.ideVars0						; starting Idevars offset
 
-	call	RamVars_GetIdeControllerCountToCX
+	call	RamVars_GetIdeControllerCountToCX			; get count of ide controllers
 	jcxz	.done										; just in case bIdeCnt is zero (shouldn't be)
-
-	mov		si, IterateFindFirstDPTforIdevars			; iteration routine (see below)
-
 .loop:
-	call	IterateAllDPTs								; look for the first drive on this controller, if any
+	call	FindDPT_ForIdevarsOffsetInDL				; look for the first drive on this controller, if any
 	jc		.notFound
 
@@ -166,15 +180,2 @@
 .done:
 	ret
-
-;--------------------------------------------------------------------
-; Iteration routine for AH0h_ResetHardDisksHandledByOurBIOS, 
-; for use with IterateAllDPTs
-; 
-; Returns when DPT is found on the controller with Idevars offset in DL
-;--------------------------------------------------------------------
-IterateFindFirstDPTforIdevars:		
-	cmp		dl, [di+DPT.bIdevarsOffset]			; Clears CF if matched
-	jz		.done
-	stc											; Set CF for not found
-.done:	
-	ret
