Index: trunk/XTIDE_Universal_BIOS/Doc/changes.txt
===================================================================
--- trunk/XTIDE_Universal_BIOS/Doc/changes.txt	(revision 28)
+++ trunk/XTIDE_Universal_BIOS/Doc/changes.txt	(revision 32)
@@ -1,3 +1,6 @@
-XTIDE Universal BIOS v1.1.3 (29 July 2010)
+  * Correct number of drives is now returned from AH=08h even when it is redirected to foreign BIOS.
+
+
+XTIDE Universal BIOS v1.1.3 (1 August 2010)
   * v1.1.1 broke booting from foreign drives, it is now fixed.
   * Improved error handling a bit.
Index: trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenu.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenu.asm	(revision 28)
+++ trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenu.asm	(revision 32)
@@ -2,5 +2,5 @@
 ; Project name	:	IDE BIOS
 ; Created date	:	25.3.2010
-; Last update	:	29.7.2010
+; Last update	:	3.8.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Displays Boot Menu.
@@ -57,6 +57,6 @@
 ALIGN JUMP_ALIGN
 BootMenu_GetMenuitemCount:
-	call	RamVars_GetDriveCounts
-	mov		ax, cx
+	call	RamVars_GetHardDiskCountFromBDAtoCX
+	xchg	ax, cx
 	call	FloppyDrive_GetCount
 	add		ax, cx
@@ -254,5 +254,5 @@
 	jb		SHORT .ReturnFloppyDriveInDX
 	sub		dx, cx					; Remove floppy drives from index
-	call	RamVars_GetDriveCounts
+	call	RamVars_GetHardDiskCountFromBDAtoCX
 	cmp		dx, cx					; Hard disk?
 	jb		SHORT .ReturnHardDiskInDX
@@ -330,11 +330,11 @@
 ALIGN JUMP_ALIGN
 BootMenu_IsDriveInSystem:
-	test	dl, 80h					; Floppy drive?
+	test	dl, 80h								; Floppy drive?
 	jz		SHORT .IsFloppyDriveIsInSystem
-	call	RamVars_GetDriveCounts	; Hard Disk count to CX
-	or		cl, 80h					; Set Hard Disk bit to CX
+	call	RamVars_GetHardDiskCountFromBDAtoCX	; Hard Disk count to CX
+	or		cl, 80h								; Set Hard Disk bit to CX
 	jmp		SHORT .CompareDriveNumberToDriveCount
 .IsFloppyDriveIsInSystem:
-	call	FloppyDrive_GetCount	; Floppy Drive count to CX
+	call	FloppyDrive_GetCount				; Floppy Drive count to CX
 .CompareDriveNumberToDriveCount:
 	cmp		dl, cl
Index: trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenuPrint.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenuPrint.asm	(revision 28)
+++ trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenuPrint.asm	(revision 32)
@@ -2,5 +2,5 @@
 ; Project name	:	IDE BIOS
 ; Created date	:	26.3.2010
-; Last update	:	12.4.2010
+; Last update	:	3.8.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for printing boot menu strings.
@@ -24,5 +24,5 @@
 	call	FloppyDrive_GetCount
 	mov		bl, cl					; Floppy Drive count to BL
-	call	RamVars_GetDriveCounts
+	call	RamVars_GetHardDiskCountFromBDAtoCX
 	mov		bh, cl					; Hard Disk count to BH
 	call	BootMenuPrint_GetCoordinatesForBottomStrings
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 28)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 32)
@@ -110,4 +110,24 @@
 	cli									; Disable interrupts as INT would
 	retf
+
+
+;--------------------------------------------------------------------
+; Int13h_CallPreviousInt13hHandler
+;	Parameters:
+;		AH:		Bios function
+;		DS:		RAMVARS segment
+;		Other:	Depends on function to call
+;	Returns:
+;		Depends on function to call
+;	Corrupts registers:
+;		FLAGS
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+Int13h_CallPreviousInt13hHandler:
+	pushf								; Push flags to simulate INT
+	cli									; Disable interrupts since INT does that
+	call	FAR [RAMVARS.fpOldI13h]
+	sti
+	ret
 
 
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm	(revision 28)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm	(revision 32)
@@ -2,10 +2,7 @@
 ; Project name	:	IDE BIOS
 ; Created date	:	27.9.2007
-; Last update	:	29.7.2010
+; Last update	:	3.8.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Int 13h function AH=0h, Disk Controller Reset.
-
-RETRIES_IF_RESET_FAILS		EQU		3
-TIMEOUT_BEFORE_RESET_RETRY	EQU		5		; System timer ticks
 
 ; Section containing code
@@ -82,8 +79,5 @@
 	call	GetDriveNumberForForeignBiosesToDL
 	xor		ah, ah						; Disk Controller 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	Int13h_CallPreviousInt13hHandler
 	jmp		SHORT BackupErrorCodeFromTheRequestedDriveToBH
 
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm	(revision 28)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm	(revision 32)
@@ -2,5 +2,5 @@
 ; Project name	:	IDE BIOS
 ; Created date	:	27.9.2007
-; Last update	:	12.4.2010
+; Last update	:	3.8.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Int 13h function AH=8h, Read Disk Drive Parameters.
@@ -32,7 +32,16 @@
 ALIGN JUMP_ALIGN
 AH8h_HandlerForReadDiskDriveParameters:
+	call	RamVars_IsDriveHandledByThisBIOS
+	jnc		SHORT .GetDriveParametersForForeignHardDiskInDL
+
 	push	bx
 	call	AH8h_GetDriveParameters
 	pop		bx
+	jmp		Int13h_ReturnWithoutSwappingDrives
+
+ALIGN JUMP_ALIGN
+.GetDriveParametersForForeignHardDiskInDL:
+	call	Int13h_CallPreviousInt13hHandler
+	call	RamVars_GetCountOfKnownDrivesToDL
 	jmp		Int13h_ReturnWithoutSwappingDrives
 
@@ -97,4 +106,5 @@
 ;		BX:		Number of L-CHS cylinders available (1...1024)
 ;		DX:		Number of L-CHS heads (1...256)
+;		DS:		RAMVARS segment
 ;	Returns:
 ;		CH:		Maximum cylinder number, bits 7...0
@@ -111,11 +121,7 @@
 	dec		dx						; Head count to max head number
 	mov		dh, dl					; Max head number to DH
-	push	ax
-	call	RamVars_GetDriveCounts	; Hard disk count to CX
-	pop		ax
-	mov		dl, cl					; Hard disk count to DL
 	mov		ch, bl					; Cylinder bits 7...0 to CH
 	mov		cl, bh					; Cylinder bits 9...8 to CL
 	eROR_IM	cl, 2					; Cylinder bits 9...8 to CL bits 7...6
 	or		cl, al					; Sectors per track to CL bits 5...0
-	ret
+	jmp		RamVars_GetCountOfKnownDrivesToDL
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HCapacity.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HCapacity.asm	(revision 28)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HCapacity.asm	(revision 32)
@@ -2,5 +2,5 @@
 ; Project name	:	IDE BIOS
 ; Created date	:	16.3.2010
-; Last update	:	12.4.2010
+; Last update	:	3.8.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for hard disk capacity calculations.
@@ -26,5 +26,5 @@
 HCapacity_GetSectorCountFromForeignAH08h:
 	mov		ah, 08h			; Get Drive Parameters
-	int		INTV_DISK_FUNC
+	call	Int13h_CallPreviousInt13hHandler
 	jmp		SHORT HCapacity_ConvertAH08hReturnValuesToSectorCount
 
Index: trunk/XTIDE_Universal_BIOS/Src/Main.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 28)
+++ trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 32)
@@ -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	"08/01/10"		; Build data (mm/dd/yy)
+	at	ROMVARS.rgbDate,	db	"08/03/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.3 (08/01/10)",STOP
+	at	ROMVARS.szVersion,	db	"v1.1.3 (08/03/10)",STOP
 
 ;---------------------------;
Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm	(revision 28)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm	(revision 32)
@@ -2,5 +2,5 @@
 ; Project name	:	IDE BIOS
 ; Created date	:	14.3.2010
-; Last update	:	2.5.2010
+; Last update	:	3.8.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for accessings RAMVARS.
@@ -130,6 +130,13 @@
 RamVars_IsFunctionHandledByThisBIOS:
 	test	ah, ah			; Reset for all floppy and hard disk drives?
-	jnz		SHORT RamVars_IsDriveHandledByThisBIOS
+	jz		SHORT .FunctionIsHandledByOurBIOS
+	cmp		ah, 08h			; Read Disk Drive Parameters?
+	jne		SHORT RamVars_IsDriveHandledByThisBIOS
+	test	dl, 80h			; We dot not handle floppy drives
+	jz		SHORT .FunctionIsNotHandledByOurBIOS
+ALIGN JUMP_ALIGN
+.FunctionIsHandledByOurBIOS:
 	stc
+.FunctionIsNotHandledByOurBIOS:
 	ret
 
@@ -190,21 +197,39 @@
 
 ;--------------------------------------------------------------------
-; Return number of Hard Disks in system.
-;
-; RamVars_GetDriveCounts
-;	Parameters:
-;		DS:		RAMVARS segment
-;	Returns:
-;		AL:		Number of hard disks handled by our BIOS
-;		CX:		Total number of hard disks in system
-;	Corrupts registers:
-;		AH
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-RamVars_GetDriveCounts:
+; RamVars_GetHardDiskCountFromBDAtoCX
+;	Parameters:
+;		DS:		RAMVARS segment
+;	Returns:
+;		CX:		Total hard disk count
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------	
+ALIGN JUMP_ALIGN
+RamVars_GetHardDiskCountFromBDAtoCX:
 	push	es
+	push	dx
+
 	LOAD_BDA_SEGMENT_TO	es, cx			; Zero CX
-	mov		cl, [es:BDA.bHDCount]		; Total hard drive count
-	mov		al, [RAMVARS.bDrvCnt]		; Our drive count
+	call	RamVars_GetCountOfKnownDrivesToDL
+	MAX_U	dl, [es:BDA.bHDCount]
+	mov		cl, dl
+
+	pop		dx
 	pop		es
 	ret
+
+;--------------------------------------------------------------------
+; RamVars_GetCountOfKnownDrivesToDL
+;	Parameters:
+;		DS:		RAMVARS segment
+;	Returns:
+;		DL:		Total hard disk count
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------	
+ALIGN JUMP_ALIGN
+RamVars_GetCountOfKnownDrivesToDL:
+	mov		dl, [RAMVARS.bFirstDrv]		; Number for our first drive
+	add		dl, [RAMVARS.bDrvCnt]		; Our drives
+	and		dl, 7Fh						; Clear HD bit for drive count
+	ret
