Index: trunk/BIOS_Drive_Information_Tool/Src/AtaInfo.asm
===================================================================
--- trunk/BIOS_Drive_Information_Tool/Src/AtaInfo.asm	(revision 612)
+++ trunk/BIOS_Drive_Information_Tool/Src/AtaInfo.asm	(revision 613)
@@ -36,5 +36,5 @@
 
 	; Read ATA Information from the drive
-	call	Bios_ReadAtaInfoFromDriveDLtoBX
+	call	Bios_ReadAtaInfoFromDriveDLtoBX	; Unaltered ATA information
 	call	Print_ErrorMessageFromAHifError	; AH=25h is not available on many BIOSes
 	jc		SHORT .SkipAtaInfoSinceError
@@ -44,5 +44,15 @@
 
 	; Print Drive P-CHS parameters
-	call	DisplayPCHSusingAtaInfoFromDSBX
+	call	DisplayPCHSusingAtaInfoFromDSBX	; Unaltered
+
+	; Fix and display values (ATA Info will stay fixed)
+	xor		ah, ah							; Successfully read ATA ID
+	push	ds
+	pop		es
+	mov		si, bx
+	call	AtaID_FixIllegalValuesFromESSI	; Modify ATA information if necessary
+	mov		si, g_szWillBeModified
+	call	Print_NullTerminatedStringFromSI
+	call	DisplayPCHSusingAtaInfoFromDSBX	; Display fixed values
 
 	; Print Drive CHS sector count
Index: trunk/BIOS_Drive_Information_Tool/Src/Bios.asm
===================================================================
--- trunk/BIOS_Drive_Information_Tool/Src/Bios.asm	(revision 612)
+++ trunk/BIOS_Drive_Information_Tool/Src/Bios.asm	(revision 613)
@@ -118,5 +118,5 @@
 ;				Set = BIOS error code stored in AH
 ;	Corrupts registers:
-;		ES
+;		CX, ES
 ;--------------------------------------------------------------------
 Bios_ReadAtaInfoFromDriveDLtoBX:
@@ -124,4 +124,5 @@
 	push	ds
 	pop		es
+	mov		cx, XUB_INT13h_SIGNATURE	; Signature to read unaltered ATA ID
 	mov		ah, GET_DRIVE_INFORMATION
 	int		BIOS_DISK_INTERRUPT_13h
Index: trunk/BIOS_Drive_Information_Tool/Src/Main.asm
===================================================================
--- trunk/BIOS_Drive_Information_Tool/Src/Main.asm	(revision 612)
+++ trunk/BIOS_Drive_Information_Tool/Src/Main.asm	(revision 613)
@@ -25,4 +25,5 @@
 %include "Version.inc"			; From XTIDE Universal BIOS
 %include "ATA_ID.inc"			; From XTIDE Universal BIOS
+%include "Ramvars.inc"			; From XTIDE Universal BIOS (needed by Int13h.inc)
 %include "Int13h.inc"			; From XTIDE Universal BIOS
 %include "EBIOS.inc"			; From XTIDE Universal BIOS
@@ -42,4 +43,5 @@
 ; Include library and other sources
 %include "AssemblyLibrary.asm"
+%include "AtaID.asm"			; From XTIDE Universal BIOS
 %include "AtaGeometry.asm"		; From XTIDE Universal BIOS
 %include "Strings.asm"
Index: trunk/BIOS_Drive_Information_Tool/Src/Strings.asm
===================================================================
--- trunk/BIOS_Drive_Information_Tool/Src/Strings.asm	(revision 612)
+++ trunk/BIOS_Drive_Information_Tool/Src/Strings.asm	(revision 613)
@@ -37,4 +37,5 @@
 g_szLBA:			db	"LBA   ",NULL
 g_szFormatCHS:		db	" Cylinders    : %5u, Heads: %3u, Sectors: %2u",NULL
+g_szWillBeModified:	db	"Will be modified to:",CR,LF,NULL		
 g_szChsSectors:		db	" CHS   sectors: ",NULL
 g_szLBA28:			db	" LBA28 sectors: ",NULL
Index: trunk/BIOS_Drive_Information_Tool/makefile
===================================================================
--- trunk/BIOS_Drive_Information_Tool/makefile	(revision 612)
+++ trunk/BIOS_Drive_Information_Tool/makefile	(revision 613)
@@ -45,4 +45,5 @@
 LIBS += ../Assembly_Library/Src/Util/
 LIBS += ../XTIDE_Universal_BIOS/Inc/
+LIBS += ../XTIDE_Universal_BIOS/Src/Initialization/
 LIBS += ../XTIDE_Universal_BIOS/Src/VariablesAndDPTs/
 HEADERS += $(LIBS)
Index: trunk/XTIDE_Universal_BIOS/Inc/Int13h.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/Int13h.inc	(revision 612)
+++ trunk/XTIDE_Universal_BIOS/Inc/Int13h.inc	(revision 613)
@@ -20,4 +20,7 @@
 %ifndef INT13H_INC
 %define INT13H_INC
+
+; Signature for XTIDE Universal BIOS specific functions
+XUB_INT13h_SIGNATURE	EQU		RAMVARS_RAM_SIGNATURE
 
 ; Hard Disk function (INT 13h) return status codes in AH
Index: trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm	(revision 612)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm	(revision 613)
@@ -88,4 +88,6 @@
 ;	Parameters:
 ;		BH:		Drive Select byte for Drive and Head Select Register
+;		CX:		XUB_INT13h_SIGNATURE to ignore illegal ATA-ID values, otherwise
+;				correct them (only used if NOT build with NO_ATAID_CORRECTION)
 ;		DX:		Autodetected port (for devices that support autodetection)
 ;		DS:		Segment to RAMVARS
@@ -98,6 +100,15 @@
 ;		AL, BX, CX, DX, SI, DI, ES
 ;--------------------------------------------------------------------
+Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
+%ifndef NO_ATAID_CORRECTION
+	cmp		cx, XUB_INT13h_SIGNATURE
+	je		SHORT .DoNotFixAtaInformation
+	push	es
+	push	si
+	ePUSH_T	cx, AtaID_PopESSIandFixIllegalValuesFromESSI	; Here we modify ATA information if necessary
+.DoNotFixAtaInformation:
+%endif
+
 %ifdef MODULE_SERIAL	; IDE + Serial
-Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
 	cmp		BYTE [cs:bp+IDEVARS.bDevice], DEVICE_SERIAL_PORT
 %ifdef USE_386
@@ -112,5 +123,5 @@
 
 %else					; IDE
-	Device_IdentifyToBufferInESSIwithDriveSelectByteInBH	EQU		IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
+	jmp		IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
 %endif
 
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH25h_HDrvID.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH25h_HDrvID.asm	(revision 612)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH25h_HDrvID.asm	(revision 613)
@@ -26,9 +26,11 @@
 ; AH25h_HandlerForGetDriveInformation
 ;	Parameters:
-;		ES:		Same as in INTPACK
+;		CX, ES:	Same as in INTPACK
 ;		DL:		Translated Drive number
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
 ;		SS:BP:	Ptr to IDEPACK
 ;	Parameters on INTPACK:
+;		CX:		XUB_INT13h_SIGNATURE to ignore illegal ATA-ID values, otherwise
+;				correct them (only used if NOT build with NO_ATAID_CORRECTION)
 ;		ES:BX:	Ptr to buffer to receive 512-byte drive information
 ;	Returns with INTPACK:
Index: trunk/XTIDE_Universal_BIOS/Src/Initialization/AtaID.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Initialization/AtaID.asm	(revision 612)
+++ trunk/XTIDE_Universal_BIOS/Src/Initialization/AtaID.asm	(revision 613)
@@ -22,4 +22,44 @@
 SECTION .text
 
+;--------------------------------------------------------------------
+; Adjust ATA information for compatibility, debug, etc purposes.
+; We can also completely ignore the drive if necessary.
+;
+; AtaID_FixIllegalValuesFromESSI
+;	Parameters:
+;		AH:		INT 13h Error Code from reading ATA information
+;		CF:		Cleared if successfully read ATA information,
+;				Set if failed to read ATA information
+;		ES:SI:	Ptr to 512-byte ATA information read from the drive
+;	Returns:
+;		ES:SI:	Ata information with possible corrections made
+;		AH:		INT 13h Error Code from reading ATA information
+;		CF 		cleared if drive now accepted
+;	Corrupts registers:
+;		AL, BX, CX, DX, DI
+;--------------------------------------------------------------------
+%ifndef NO_ATAID_CORRECTION
+%ifndef EXCLUDE_FROM_BIOSDRVS
+AtaID_PopESSIandFixIllegalValuesFromESSI:
+	pop		si
+	pop		es
+%endif
+AtaID_FixIllegalValuesFromESSI:
+	jc		SHORT .Return	; Nothing to fix since failed to read ATA Info
+
+	; Only correct cylinders since there are no reports that head or sectors could be wrong
+	MIN_U	WORD [es:si+ATA1.wCylCnt], MAX_VALID_PCHS_CYLINDERS		; Limit to max allowed value
+	
+	; Note! There are ATA ID words 54-58 that also need to be modified! However,
+	; the drive itself should modify them when we do Initialize Device Parameters command at AH=9h.
+	; Verification from real drive needed before we fix them manually
+	
+	clc						; Return success
+.Return:
+	ret
+%endif ; NO_ATAID_CORRECTION
+
+
+%ifndef EXCLUDE_FROM_BIOSDRVS
 ;--------------------------------------------------------------------
 ; AtaID_VerifyFromESSI
@@ -233,2 +273,4 @@
 
 %endif ; MODULE_ADVANCED_ATA
+
+%endif ; EXCLUDE_FROM_BIOSDRVS
Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AtaGeometry.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AtaGeometry.asm	(revision 612)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AtaGeometry.asm	(revision 613)
@@ -239,9 +239,4 @@
 	mov		bl, [es:si+ATA1.wHeadCnt]	; Heads (1...16)
 	mov		bh, [es:si+ATA1.wSPT]		; Sectors per Track (1...63)
-%ifndef EXCLUDE_FROM_BIOSDRVS	; We want the true value in BIOSDRVS
-	; Some CF cards (for example Sandisk Ultra 16/32 GB) violates
-	; the ATA specification by reporting more than 16383 cylinders.
-	MIN_U	ax, MAX_PCHS_CYLINDERS		; Limit the count to avoid problems.
-%endif
 	ret
 
Index: trunk/XTIDE_Universal_BIOS/makefile
===================================================================
--- trunk/XTIDE_Universal_BIOS/makefile	(revision 612)
+++ trunk/XTIDE_Universal_BIOS/makefile	(revision 613)
@@ -37,4 +37,5 @@
 # RELOCATE_INT13H_STACK **    Relocates INT 13h stack to beginning of stolen conventional memory   #
 # NO_ATAID_VALIDATION ***     Excludes code that tries to ensure proper communication with drives  #
+# NO_ATAID_CORRECTION		  Excludes code that corrects illegal CHS values from some CF cards    #
 # USE_186                     Use instructions supported by 80188/80186 and V20/V30 and later      #
 # USE_286                     Use instructions supported by 286 and later (defines USE_UNDOC_INTEL)#
@@ -117,5 +118,5 @@
 DEFINES_AT_LARGE = $(DEFINES_AT) $(DEFINES_COMMON_LARGE)
 
-DEFINES_XT_TINY = MODULE_STRINGS_COMPRESSED MODULE_8BIT_IDE NO_ATAID_VALIDATION CLD_NEEDED
+DEFINES_XT_TINY = MODULE_STRINGS_COMPRESSED MODULE_8BIT_IDE NO_ATAID_VALIDATION NO_ATAID_CORRECTION CLD_NEEDED
 DEFINES_386 = $(DEFINES_AT) USE_386 MODULE_ADVANCED_ATA MODULE_WIN9X_CMOS_HACK
 DEFINES_386_LARGE = $(DEFINES_386) $(DEFINES_COMMON_LARGE)
