Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm	(revision 23)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm	(revision 26)
@@ -2,5 +2,5 @@
 ; Project name	:	IDE BIOS
 ; Created date	:	27.9.2007
-; Last update	:	1.7.2010
+; Last update	:	26.7.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Int 13h function AH=0h, Disk Controller Reset.
@@ -37,11 +37,11 @@
 
 	eMOVZX	bx, dl						; Copy requested drive to BL, zero BH to assume no errors
-	call	AH0h_ResetFloppyDrivesWithInt40h
-	test	bl, 80h						; Reset hard disks too?
-	jz		SHORT .Return
-	call	AH0h_ResetForeignHardDisks
-	call	AH0h_ResetAllOurControllers
+	call	ResetFloppyDrivesWithInt40h
+	test	bl, 80h
+	jz		SHORT .SkipHardDiskReset
+	call	ResetForeignHardDisks
+	call	ResetHardDisksHandledByOurBIOS
 ALIGN JUMP_ALIGN
-.Return:
+.SkipHardDiskReset:
 	mov		ah, bh						; Copy error code to AH
 	xor		al, al						; Zero AL...
@@ -51,5 +51,5 @@
 
 ;--------------------------------------------------------------------
-; AH0h_ResetFloppyDrivesWithInt40h
+; ResetFloppyDrivesWithInt40h
 ;	Parameters:
 ;		BL:		Requested drive (DL when entering AH=00h)
@@ -61,13 +61,13 @@
 ;--------------------------------------------------------------------	
 ALIGN JUMP_ALIGN
-AH0h_ResetFloppyDrivesWithInt40h:
-	xor		ax, ax						; Disk Controller Reset
+ResetFloppyDrivesWithInt40h:
+	xor		ah, ah						; Disk Controller Reset
 	and		dl, 7Fh						; Clear bit 7
 	int		INTV_FLOPPY_FUNC
-	jmp		SHORT AH0h_BackupErrorCodeFromTheRequestedDriveToBH
+	jmp		SHORT BackupErrorCodeFromTheRequestedDriveToBH
 
 
 ;--------------------------------------------------------------------
-; AH0h_ResetForeignHardDisks
+; ResetForeignHardDisks
 ;	Parameters:
 ;		BL:		Requested drive (DL when entering AH=00h)
@@ -79,26 +79,18 @@
 ;--------------------------------------------------------------------	
 ALIGN JUMP_ALIGN
-AH0h_ResetForeignHardDisks:
-	mov		cl, [RAMVARS.bFirstDrv]		; Load number of first our drive
-	and		cx, BYTE 7Fh				; CX = number of drives to reset
-	jz		SHORT .Return
-	mov		dl, 80h						; Start resetting from drive 80h
-ALIGN JUMP_ALIGN
-.DriveResetLoop:
+ResetForeignHardDisks:
+	mov		dl, bl						; Drive to reset
 	mov		ah, 0Dh						; Reset Hard Disk (Alternate reset)
+
 	pushf								; Push flags to simulate INT
 	cli									; Disable interrupts since INT does that
 	call	FAR [RAMVARS.fpOldI13h]
 	sti									; Make sure interrupts are enabled again (some BIOSes fails to enable it)
-	call	AH0h_BackupErrorCodeFromTheRequestedDriveToBH
-	inc		dx							; Next drive to reset
-	loop	.DriveResetLoop
-ALIGN JUMP_ALIGN
-.Return:
-	ret
+
+	jmp		SHORT BackupErrorCodeFromTheRequestedDriveToBH
 
 
 ;--------------------------------------------------------------------
-; AH0h_ResetAllOurControllers
+; ResetHardDisksHandledByOurBIOS
 ;	Parameters:
 ;		BL:		Requested drive (DL when entering AH=00h)
@@ -107,75 +99,78 @@
 ;		BH:		Error code from requested drive (if available)
 ;	Corrupts registers:
-;		AX, CX, DX, DI
+;		AX, CX, DX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-AH0h_ResetAllOurControllers:
-	push	si
-	mov		si, ROMVARS.ideVars0			; Load offset to first IDEVARS
-	call	Initialize_GetIdeControllerCountToCX
+ResetHardDisksHandledByOurBIOS:
+	mov		dh, [RAMVARS.bDrvCnt]		; Load drive count to DH
+	test	dh, dh
+	jz		SHORT .AllDrivesReset		; Return if no drives
+	mov		dl, [RAMVARS.bFirstDrv]		; Load number of first our drive
+	add		dh, dl						; DH = one past last drive to reset
 ALIGN JUMP_ALIGN
-.ResetLoop:
-	call	AH0h_ResetIdevarsControllerMasterAndSlaveDrives
-	add		si, BYTE IDEVARS_size
-	loop	.ResetLoop
-.Return:
-	pop		si
+.DriveResetLoop:
+	call	AHDh_ResetDrive
+	call	BackupErrorCodeFromTheRequestedDriveToBH
+	call	.SkipNextDriveIfItIsSlaveForThisController
+	inc		dx
+	cmp		dl, dh						; All done?
+	jb		SHORT .DriveResetLoop		;  If not, reset next drive
+.AllDrivesReset:
+	ret
+
+;--------------------------------------------------------------------
+; .SkipNextDriveIfItIsSlaveForThisController
+;	Parameters:
+;		DL:		Drive just resetted
+;		DS:		RAMVARS segment
+;	Returns:
+;		DL:		Incremented if next drive is slave drive
+;				(=already resetted)
+;	Corrupts registers:
+;		AX, CX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.SkipNextDriveIfItIsSlaveForThisController:
+	push	di
+
+	call	.GetBasePortToAXfromDriveInDL
+	xchg	cx, ax
+
+	inc		dx
+	call	.GetBasePortToAXfromDriveInDL
+	jnc		SHORT .SkipNextDrive
+
+	cmp		ax, cx
+	je		SHORT .SkipNextDrive		; Same controller so slave already reset
+
+	dec		dx							; Restore DX
+.SkipNextDrive:
+	pop		di
+	ret
+
+;--------------------------------------------------------------------
+; .GetBasePortToAXfromDriveInDL
+;	Parameters:
+;		DL:		Drive whose base port to find
+;		DS:		RAMVARS segment
+;	Returns:
+;		AX:		Base port (if drive found)
+;		CF:		Set if drive found
+;				Cleared if drive not found
+;	Corrupts registers:
+;		DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.GetBasePortToAXfromDriveInDL:
+	call	FindDPT_ForDriveNumber		; Get DPT to DS:DI
+	jnc		SHORT .DriveNotFound
+	eMOVZX	di, BYTE [di+DPT.bIdeOff]	; CS:DI now points to IDEVARS
+	mov		ax, [cs:di+IDEVARS.wPort]
+.DriveNotFound:
 	ret
 
 
 ;--------------------------------------------------------------------
-; AH0h_ResetIdevarsControllerMasterAndSlaveDrives
-;	Parameters:
-;		BL:		Requested drive (DL when entering AH=00h)
-;		CS:SI:	Ptr to IDEVARS
-;		DS:		RAMVARS segment
-;	Returns:
-;		BH:		Error code from requested drive (if available)
-;	Corrupts registers:
-;		AX, DX, DI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-AH0h_ResetIdevarsControllerMasterAndSlaveDrives:
-	mov		dx, [cs:si+IDEVARS.wPort]
-	call	FindDPT_ForIdeMasterAtPort		; Find master drive to DL
-	jc		SHORT AH0h_ResetMasterAndSlaveDriveWithRetries
-	call	FindDPT_ForIdeSlaveAtPort		; Find slave if master not present
-	jc		SHORT AH0h_ResetMasterAndSlaveDriveWithRetries
-	ret
-
-;--------------------------------------------------------------------
-; AH0h_ResetMasterAndSlaveDriveWithRetries
-;	Parameters:
-;		BL:		Requested drive (DL when entering AH=00h)
-;		DL:		Drive number for master or slave drive
-;		DS:		RAMVARS segment
-;	Returns:
-;		BH:		Error code from requested drive (if available)
-;	Corrupts registers:
-;		AX, DI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-AH0h_ResetMasterAndSlaveDriveWithRetries:
-	push	dx
-	push	cx
-	push	bx
-	mov		di, RETRIES_IF_RESET_FAILS
-ALIGN JUMP_ALIGN
-.RetryLoop:
-	call	AHDh_ResetDrive
-	jnc		SHORT .Return				; Jump if successful
-	mov		cx, TIMEOUT_BEFORE_RESET_RETRY
-	call	SoftDelay_TimerTicks
-	dec		di
-	jnz		SHORT .RetryLoop
-ALIGN JUMP_ALIGN
-.Return:
-	pop		bx
-	pop		cx
-	pop		dx
-	; Fall to AH0h_BackupErrorCodeFromTheRequestedDriveToBH
-
-;--------------------------------------------------------------------
-; AH0h_BackupErrorCodeFromTheRequestedDriveToBH
+; BackupErrorCodeFromTheRequestedDriveToBH
 ;	Parameters:
 ;		AH:		Error code from the last resetted drive
@@ -188,6 +183,6 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-AH0h_BackupErrorCodeFromTheRequestedDriveToBH:
-	cmp		dl, bl						; Requested drive?
+BackupErrorCodeFromTheRequestedDriveToBH:
+	cmp		dl, bl				; Requested drive?
 	jne		SHORT .Return
 	mov		bh, ah
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm	(revision 23)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm	(revision 26)
@@ -2,5 +2,5 @@
 ; Project name	:	IDE BIOS
 ; Created date	:	9.12.2007
-; Last update	:	12.4.2010
+; Last update	:	26.7.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Int 13h function AH=Dh, Reset Hard Disk (Alternate reset).
@@ -25,10 +25,6 @@
 ALIGN JUMP_ALIGN
 AHDh_HandlerForResetHardDisk:
-	push	dx
-	push	cx
-	push	bx
-	push	ax
 	call	AHDh_ResetDrive
-	jmp		Int13h_PopXRegsAndReturn
+	jmp		Int13h_PopDiDsAndReturn
 
 
@@ -44,9 +40,14 @@
 ;		CF:		0 if succesfull, 1 if error
 ;	Corrupts registers:
-;		AL, BX, CX, DX
+;		Nothing
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 AHDh_ResetDrive:
 	push	di
+	push	dx
+	push	cx
+	push	bx
+	push	ax
+
 	call	FindDPT_ForDriveNumber		; DS:DI now points to DPT
 	call	AHDh_ResetMasterAndSlave
@@ -57,10 +58,10 @@
 	mov		dx, [RAMVARS.wIdeBase]		; Load base port address
 	call	AHDh_InitializeMasterAndSlave
-	jc		SHORT .ReturnError
-	xor		ax, ax						; Clear AH since success
-	pop		di
-	ret
-.ReturnError:
-	mov		ah, RET_HD_RESETFAIL		; Load Reset Failed error code
+
+	pop		bx							; Pop old AX
+	mov		al, bl						; Restore AL
+	pop		bx
+	pop		cx
+	pop		dx
 	pop		di
 	ret
@@ -110,8 +111,9 @@
 ;		DX:		IDE Base Port address
 ;	Returns:
+;		AH:		Error code
 ;		CF:		0 if initialization succesfull
 ;				1 if any error
 ;	Corrupts registers:
-;		AX, BX, CX, DX, DI
+;		AL, BX, CX, DX, DI
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -136,4 +138,5 @@
 	ret
 .ReturnError:
+	mov		ah, RET_HD_RESETFAIL		; Load Reset Failed error code
 	stc
 	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HPIO.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HPIO.asm	(revision 23)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HPIO.asm	(revision 26)
@@ -232,5 +232,5 @@
 HPIO_WriteToDrive:
 	cld										; OUTS to increment SI
-	call	HStatus_WaitDrqDefTime			; Always poll DRQ for first block
+	call	HStatus_WaitDrqDefTime			; Always poll DRQ for first block, get data port to DX
 	jc		SHORT .RetError					; Return if error (code in AH)
 	sub		dx, BYTE REGR_IDE_ST			; DX to Data Port address
@@ -251,5 +251,5 @@
 	jmp		HStatus_WaitIrqOrRdy			; Check for errors
 
-	
+
 ;--------------------------------------------------------------------
 ; Bus specific transfer functions and lookup table.
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HStatus.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HStatus.asm	(revision 23)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HStatus.asm	(revision 26)
@@ -2,5 +2,5 @@
 ; Project name	:	IDE BIOS
 ; Created date	:	15.12.2009
-; Last update	:	25.5.2010
+; Last update	:	26.6.2010
 ; Author		:	Tomi Tilli
 ; Description	:	IDE Status Register polling functions.
@@ -25,5 +25,5 @@
 ALIGN JUMP_ALIGN
 HStatus_WaitIrqOrRdy:
-	test	BYTE [di+DPT.bDrvCtrl], FLG_IDE_CTRL_nIEN
+	test	BYTE [bx+DPT.bDrvCtrl], FLG_IDE_CTRL_nIEN
 	jnz		SHORT .PollRdySinceIrqsAreDisabled
 	jmp		HIRQ_WaitIRQ
Index: trunk/XTIDE_Universal_BIOS/Src/Main.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 23)
+++ trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 26)
@@ -2,5 +2,5 @@
 ; Project name	:	XTIDE Universal BIOS
 ; Created date	:	28.7.2007
-; Last update	:	1.7.2010
+; Last update	:	26.7.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Main file for BIOS. This is the only file that needs
@@ -38,5 +38,5 @@
 	at	ROMVARS.bRomSize,	db	CNT_ROM_BLOCKS	; ROM size in 512B blocks
 	at	ROMVARS.rgbJump, 	jmp	Initialize_FromMainBiosRomSearch
-	at	ROMVARS.rgbDate,	db	"07/01/10"		; Build data (mm/dd/yy)
+	at	ROMVARS.rgbDate,	db	"07/26/10"		; Build data (mm/dd/yy)
 	at	ROMVARS.rgbSign,	db	"XTIDE110"		; Signature for flash program
 	at	ROMVARS.szTitle
@@ -49,5 +49,5 @@
 		db	" (XT)=-",STOP
 %endif
-	at	ROMVARS.szVersion,	db	"v1.1.1 (07/01/10)",STOP
+	at	ROMVARS.szVersion,	db	"v1.1.2 (07/26/10)",STOP
 
 ;---------------------------;
