Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm	(revision 261)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm	(revision 262)
@@ -121,6 +121,6 @@
 GetDriveNumberForForeignBiosesToDL:
 	mov		dl, bl
-	call	RamVars_IsDriveHandledByThisBIOS
-	jc		SHORT .Return				; Return what was in BL unmodified
+	test	di, di
+	jz		SHORT .Return				; Return what was in BL unmodified
 	mov		dl, 80h
 .Return:
@@ -141,69 +141,29 @@
 ALIGN JUMP_ALIGN
 AH0h_ResetHardDisksHandledByOurBIOS:
-	mov		dx, [RAMVARS.wDrvCntAndFirst]	; DL = drive number, DH = drive count
-	test	dh, dh
-	jz		SHORT .AllDrivesReset		; Return if no drives
-	add		dh, dl						; DH = one past last drive to reset
-ALIGN JUMP_ALIGN
-.DriveResetLoop:
-	call	AHDh_ResetDrive
-	call	.BackupErrorCodeFromMasterOrSlaveToBH
-	inc		dx
-	cmp		dl, dh						; All done?
-	jb		SHORT .DriveResetLoop		;  If not, reset next drive
-.AllDrivesReset:
+	mov		bl, [di+DPT.bIdevarsOffset]					; replace drive number with Idevars pointer for comparisons
+	mov		cl, [cs:ROMVARS.bIdeCnt]					; get count of ide controllers
+	mov		ch, 0										
+	mov		dl, 0										; starting Idevars offset
+	mov		si, IterateFindFirstDPTforIdevars			; iteration routine
+.loop:
+	call	IterateAllDPTs								; look for the first drive on this controller, if any
+	jc		.notFound
+	call	AHDh_ResetDrive								; reset master and slave on that controller
+	call	BackupErrorCodeFromTheRequestedDriveToBH	; save error code if same controller as initial request
+.notFound:
+	add		dl, IDEVARS_size							; move pointer forward
+	loop	.loop										; and repeat
 	ret
 
-				
 ;--------------------------------------------------------------------
-; .BackupErrorCodeFromMasterOrSlaveToBH
-;	Parameters:
-;		AH:		Error code for drive DL reset
-;		BL:		Requested drive (DL when entering AH=00h)
-;		DL:		Drive just resetted
-;		DS:		RAMVARS segment
-;	Returns:
-;		BH:		Backuped error code
-;		DL:		Incremented if next drive is slave drive
-;				(=already resetted)
-;	Corrupts registers:
-;		CX, DI
+; Iteration routine for AH0h_ResetHardDisksHandledByOurBIOS, 
+; for use with IterateAllDPTs
+; 
+; Returns when DPT is found on the controller with Idevars offset in DL
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.BackupErrorCodeFromMasterOrSlaveToBH:
-	call	BackupErrorCodeFromTheRequestedDriveToBH
-	call	GetBasePortToCX				; Load base port for resetted drive
-	push	cx
-	inc		dx							; DL to next drive
-	call	GetBasePortToCX
-	pop		di
-	cmp		cx, di						; Next drive is from same controller?
-	je		SHORT BackupErrorCodeFromTheRequestedDriveToBH
-.NoMoreDrivesOrNoSlaveDrive:
-	dec		dx
+IterateFindFirstDPTforIdevars:		
+	cmp		dl, [di+DPT.bIdevarsOffset]			; Clears CF if matched
+	jz		.done
+	stc											; Set CF for not found
+.done:	
 	ret
-
-		
-;--------------------------------------------------------------------
-; GetBasePortToCX
-;	Parameters:
-;		DL:		Drive number
-;		DS:		RAMVARS segment
-;	Returns:
-;		CX:		Base port address
-;		CF:		Set if valid drive number
-;				Cleared if invalid drive number
-;	Corrupts registers:
-;		DI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-GetBasePortToCX:
-	xchg	cx, bx
-	xor		bx, bx
-	call	FindDPT_ForDriveNumber
-	mov		bl, [di+DPT.bIdevarsOffset]
-	mov		bx, [cs:bx+IDEVARS.wPort]
-	xchg	bx, cx
-	ret
-
-
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm	(revision 261)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm	(revision 262)
@@ -25,7 +25,6 @@
 ;--------------------------------------------------------------------
 AH8h_HandlerForReadDiskDriveParameters:
-
-	call	RamVars_IsDriveHandledByThisBIOS
-	jnc		SHORT .OurDrive
+	test	di,di
+	jnz		SHORT .OurDrive
 
 	call	Int13h_CallPreviousInt13hHandler
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm	(revision 261)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm	(revision 262)
@@ -40,5 +40,5 @@
 ;		CF:		0 if succesfull, 1 if error
 ;	Corrupts registers:
-;		AL, CX, SI, DI
+;		AL, CX, SI
 ;--------------------------------------------------------------------
 ;ALIGN JUMP_ALIGN
@@ -46,52 +46,42 @@
 	push	dx
 	push	bx
+	push	di
 
-	call	FindDPT_ForDriveNumber		; DS:DI now points to DPT
 	call	Interrupts_UnmaskInterruptControllerForDriveInDSDI
 	call	Device_ResetMasterAndSlaveController
-	;jc		SHORT .ReturnError			; CF would be set if slave drive present without master
-										; (error register has special values after reset)
+	;jc		SHORT .ReturnError					; CF would be set if slave drive present without master
+												; (error register has special values after reset)
 
 	; Initialize Master and Slave drives
-	eMOVZX	bx, BYTE [di+DPT.bIdevarsOffset]
-	mov		dx, [cs:bx+IDEVARS.wPort]
-	call	InitializeMasterAndSlaveDriveFromPortInDX
+	mov		al, [di+DPT.bIdevarsOffset]			; pointer to controller we are looking to reset
+	mov		ah, 0								; initialize error code, assume success
+		
+	mov		si, IterateAndResetDrives
+	call	IterateAllDPTs
 
+	shr		ah, 1								; Move error code and CF into proper position
+
+	pop		di
 	pop		bx
 	pop		dx
 	ret
 
-
 ;--------------------------------------------------------------------
-; InitializeMasterAndSlaveDriveFromPortInDX
-;	Parameters:
-;		DX:		IDE Base Port address
-;		SS:BP:	Ptr to IDEPACK
-;	Returns:
-;		AH:		Error code
-;		CF:		0 if initialization succesfull
-;				1 if any error
-;	Corrupts registers:
-;		AL, BX, CX, DX, SI, DI
+; IterateAndResetDrives: Iteration routine for use with IterateAllDPTs.
+;
+; When a drive on the controller is found, it is reset, and the error code 
+; merged into overall error code for this controller.  Master will be reset
+; first.  Note that the iteration will go until the end of the DPT list.
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-InitializeMasterAndSlaveDriveFromPortInDX:
-	push	dx							; Store base port address
-	xor		cx, cx						; Assume no errors
-	FindDPT_ToDSDIForIdeMasterAtPortDX
-	jnc		SHORT .InitializeSlave		; Master drive not present
-	call	AH9h_InitializeDriveForUse
-	mov		cl, ah						; Copy error code to CL
-.InitializeSlave:
-	pop		dx							; Restore base port address
-	FindDPT_ToDSDIForIdeSlaveAtPortDX
-	jnc		SHORT .CombineErrors		; Slave drive not present
-	call	AH9h_InitializeDriveForUse
-	mov		ch, ah						; Copy error code to CH
-.CombineErrors:
-	or		cl, ch						; OR error codes, clear CF
-	jz		SHORT .Return
-	mov		ah, RET_HD_RESETFAIL		; Load Reset Failed error code
-	stc
-.Return:
+IterateAndResetDrives:
+	cmp		al, [di+DPT.bIdevarsOffset]			; The right controller?
+	jnz		.done
+	push	ax
+	call	AH9h_InitializeDriveForUse			; Reset Master and Slave (Master will come first in DPT list)
+	pop		ax		
+	jc		.done
+	or		ah, (RET_HD_RESETFAIL << 1) | 1		; OR in Reset Failed error code and CF, will SHR into position later
+.done:
+	stc											; From IterateAllDPTs perspective, the DPT is never found
 	ret
+		
