Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm	(revision 193)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm	(revision 227)
@@ -78,9 +78,7 @@
 ;		CS:BP:	Ptr to IDEVARS for the controller
 ;	Returns:
-;		DX:AX or AX:	Number of cylinders
-;		BH:				Number of sectors per track
-;		BL:				Number of heads
-;	Corrupts registers:
-;		CX, (DX)
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, CX, DX
 ;--------------------------------------------------------------------
 .StoreAddressing:
@@ -88,10 +86,10 @@
 	call	AccessDPT_GetPointerToDRVPARAMStoCSBX
 	test	byte [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERCHS    ; User specified CHS?
-	jnz		SHORT .StoreUserDefinedCHSaddressing
+	jnz		SHORT .StoreUserDefinedPCHS
 
 	; Check if LBA supported
 	call	AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI
 	test	BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8
-	jz		SHORT .StoreCHSaddressing
+	jz		SHORT .StoreCHSfromAXBHBL		; Small old drive with CHS addressing only
 
 	; Check if 48-bit LBA supported
@@ -102,48 +100,76 @@
 	or		BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION
 	call	AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI
+	mov		[di+DPT.twLbaSectors], ax
+	mov		[di+DPT.twLbaSectors+2], dx
+	mov		[di+DPT.twLbaSectors+4], bx
 	call	AtaID_GetLbaAssistedCHStoDXAXBLBH
-	jmp		SHORT .StoreChsFromDXAXBX
-
-	; Check if P-CHS to L-CHS translation required
-.StoreUserDefinedCHSaddressing:
+	mov		[di+DPT.bLbaHeads], bl
+	jmp		SHORT .StoreBlockMode
+
+;--------------------------------------------------------------------
+; .StoreUserDefinedPCHS
+;	Parameters:
+;		DS:DI:	Ptr to Disk Parameter Table
+;		ES:SI:	Ptr to 512-byte ATA information read from the drive
+;		CS:BP:	Ptr to IDEVARS for the controller
+;	Returns:
+;		AX:		Number of P-CHS cylinders
+;		BH:		Number of P-CHS sectors per track
+;		BL:		Number of P-CHS heads
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+.StoreUserDefinedPCHS:
 	call	AccessDPT_GetPointerToDRVPARAMStoCSBX
 	mov		ax, [cs:bx+DRVPARAMS.wCylinders]
 	mov		bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
-.StoreCHSaddressing:
-	cmp		ax, MAX_LCHS_CYLINDERS
-	jbe		SHORT .StoreChsFromAXBX		; No translation required
-
-	; We need to get number of bits to shift for translation
+	; Fall to .StoreCHSfromAXBHBL
+
+;--------------------------------------------------------------------
+; .StoreCHSfromAXBHBL
+;	Parameters:
+;		AX:		Number of P-CHS cylinders
+;		BH:		Number of P-CHS sectors per track
+;		BL:		Number of P-CHS heads
+;		DS:DI:	Ptr to Disk Parameter Table
+;		ES:SI:	Ptr to 512-byte ATA information read from the drive
+;		CS:BP:	Ptr to IDEVARS for the controller
+;	Returns:
+;		AX:		Number of P-CHS cylinders
+;		BH:		Number of P-CHS sectors per track
+;		BL:		Number of P-CHS heads
+;	Corrupts registers:
+;		CX
+;--------------------------------------------------------------------
+.StoreCHSfromAXBHBL:
 	push	ax
-	eMOVZX	dx, bl						; Heads now in DX
-	xchg	bx, ax						; Cylinders now in BX
-	call	AccessDPT_ShiftPCHinBXDXtoLCH	; Leaves AX untouched
-	xchg	bx, ax						; Restore HeadsAndSectors to BX
+	push	bx
+	call	AccessDPT_ShiftPCHinAXBLtoLCH	; Get number of bits to shift
+	pop		bx
+	pop		ax
+	jcxz	.StorePCHSfromAXDX				; Small drive so use L-CHS addressing
+
+	; Store P-CHS addressing mode and number of bits to shift in L-CHS to P-CHS translation
 	or		cl, ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION
-	or		[di+DPT.bFlagsLow], cl		; Store bits to shift
-	pop		ax
-	; Fall to .StoreChsFromAXBX
-
-;--------------------------------------------------------------------
-; .StoreChsFromAXBX
-; .StoreChsFromDXAXBX
-;	Parameters:
-;		DX:AX or AX:	Number of cylinders
-;		BH:		Number of sectors per track
-;		BL:		Number of heads
-;		DS:DI:	Ptr to Disk Parameter Table
-;		ES:SI:	Ptr to 512-byte ATA information read from the drive
-;		CS:BP:	Ptr to IDEVARS for the controller
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		DX
-;--------------------------------------------------------------------
-.StoreChsFromAXBX:
-	xor		dx, dx
-.StoreChsFromDXAXBX:
-	mov		[di+DPT.dwCylinders], ax
-	mov		[di+DPT.dwCylinders+2], dx
-	mov		[di+DPT.wHeadsAndSectors], bx
+	or		[di+DPT.bFlagsLow], cl
+	; Fall to .StoreChsFromAXBLBH
+
+;--------------------------------------------------------------------
+; .StoreChsFromAXBLBH
+;	Parameters:
+;		AX:		Number of P-CHS cylinders
+;		BH:		Number of P-CHS sectors per track
+;		BL:		Number of P-CHS heads
+;		DS:DI:	Ptr to Disk Parameter Table
+;		ES:SI:	Ptr to 512-byte ATA information read from the drive
+;		CS:BP:	Ptr to IDEVARS for the controller
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+.StorePCHSfromAXDX:
+	mov		[di+DPT.wPchsCylinders], ax
+	mov		[di+DPT.wPchsHeadsAndSectors], bx
 	; Fall to .StoreBlockMode
 
