Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm	(revision 542)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm	(revision 543)
@@ -20,4 +20,5 @@
 ; Section containing code
 SECTION .text
+
 
 ;--------------------------------------------------------------------
@@ -101,8 +102,5 @@
 AH8h_GetDriveParameters:
 	call	AccessDPT_GetLCHStoAXBLBH
-%ifdef RESERVE_DIAGNOSTIC_CYLINDER
-	dec		ax
-%endif
-	MIN_U	ax, MAX_LCHS_CYLINDERS
+	call	AH8h_LimitAXtoMaximumLCylinders
 	; Fall to .PackReturnValues
 
@@ -141,4 +139,22 @@
 	ret
 
+
+;--------------------------------------------------------------------
+; AH8h_LimitAXtoMaximumLCylinders
+;	Parameters:
+;		AX:		Number of total L-CHS cylinders (1...1027)
+;	Returns:
+;		AX:		Number of usable L-CHS cylinders (1...1024)
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+AH8h_LimitAXtoMaximumLCylinders:
+%ifdef RESERVE_DIAGNOSTIC_CYLINDER
+	dec		ax
+%endif
+	MIN_U	ax, MAX_LCHS_CYLINDERS
+	ret
+
+
 %ifdef MODULE_SERIAL_FLOPPY
 ;
Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CompatibleDPT.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CompatibleDPT.asm	(revision 542)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CompatibleDPT.asm	(revision 543)
@@ -89,4 +89,6 @@
 ;--------------------------------------------------------------------
 FillToESDIusingDPTfromDSSI:
+	mov		ax, [si+DPT.wLchsCylinders]
+	call	AH8h_LimitAXtoMaximumLCylinders
 	test	BYTE [si+DPT.bFlagsLow], MASKL_DPT_TRANSLATEMODE
 	jz		SHORT FillStandardDPTtoESDIfromDPTinDSSI
@@ -96,4 +98,5 @@
 ; FillTranslatedDPTtoESDIfromDPTinDSSI
 ;	Parameters:
+;		AX:		Number of Logical Cylinders
 ;		CL:		Device Control Byte
 ;		DS:SI:	Ptr to DPT
@@ -106,6 +109,4 @@
 FillTranslatedDPTtoESDIfromDPTinDSSI:
 	xor		dx, dx						; Clear for checksum
-	mov		ax, [si+DPT.wLchsCylinders]
-	;MIN_U	ax, MAX_LCHS_CYLINDERS		; Our DPT can have up to 1027
 	call	StoswThenAddALandAHtoDL		; Bytes 0 and 1 (Logical number of cylinders)
 
@@ -144,4 +145,5 @@
 ; FillStandardDPTtoESDIfromDPTinDSSI
 ;	Parameters:
+;		AX:		Number of Physical Cylinders == Number of Logical Cylinders
 ;		CL:		Device Control Byte
 ;		DS:SI:	Ptr to DPT
@@ -153,5 +155,4 @@
 ;--------------------------------------------------------------------
 FillStandardDPTtoESDIfromDPTinDSSI:
-	mov		ax, [si+DPT.wLchsCylinders]
 	stosw				; Bytes 0 and 1 (Physical number of cylinders)
 	eMOVZX	ax, BYTE [si+DPT.bLchsHeads]
Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm	(revision 542)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm	(revision 543)
@@ -144,11 +144,14 @@
 	xchg	cx, ax
 	div		cx								; AX = new P-Cylinders
+
+	; We could remove wPchsCylinders from DPT if we calculate it on AH=48h
+	; but that would require extra code so we save ROM space instead.
 	mov		[di+DPT.wPchsCylinders], ax
 
-	; Store CHS sector count as total sector count
+	; Store CHS sector count as total sector count. We must not use
+	; LBA sector count if it is 15,482,880 or less.
 	mul		cx
 	xor		bx, bx
-	xor		cx, cx							; Clear LBA48 flag
-	jmp		SHORT .StoreTotalSectorsFromBXDXAXandLBA48flagFromCL
+	jmp		SHORT .StoreTotalSectorsFromBXDXAX
 	; Fall to .StoreNumberOfLbaSectors
 
@@ -167,6 +170,6 @@
 	; Store LBA 28/48 total sector count
 	call	AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI
-.StoreTotalSectorsFromBXDXAXandLBA48flagFromCL:
-	or		[di+DPT.bFlagsLow], cl
+	or		[di+DPT.bFlagsLow], cl		; LBA48 flag
+.StoreTotalSectorsFromBXDXAX:
 	mov		[di+DPT.twLbaSectors], ax
 	mov		[di+DPT.twLbaSectors+2], dx
Index: trunk/XTIDE_Universal_BIOS/makefile
===================================================================
--- trunk/XTIDE_Universal_BIOS/makefile	(revision 542)
+++ trunk/XTIDE_Universal_BIOS/makefile	(revision 543)
@@ -33,4 +33,5 @@
 # RESERVE_DIAGNOSTIC_CYLINDER Reserve one L-CHS cylinder for compatibility with old BIOSes         #
 # CREATE_COMPATIBLE_DPT       Presents compatible DPTs for ill behaving applications               #
+# DANGEROUS_DETECTION         Scans Advanced Controllers from dangerous ports like mirrored PIC    #
 # 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)#
