Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm	(revision 203)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm	(revision 227)
@@ -40,68 +40,81 @@
 	ret
 
-		
+
 ;--------------------------------------------------------------------
-; AccessDPT_GetLCHS
+; AccessDPT_GetLCHStoAXBLBH
 ;	Parameters:
 ;		DS:DI:	Ptr to Disk Parameter Table
 ;	Returns:
-;		AX:		Number of L-CHS sectors per track
-;		BX:		Number of L-CHS cylinders
-;		DX:		Number of L-CHS heads
+;		AX:		Number of L-CHS cylinders
+;		BL:		Number of L-CHS heads
+;		BH:		Number of L-CHS sectors per track
 ;	Corrupts registers:
-;		CX
+;		CX, DX
 ;--------------------------------------------------------------------
-AccessDPT_GetLCHS:
-	; Load CHS from DPT
-	eMOVZX	ax, BYTE [di+DPT.bSectors]
-	mov		bx, [di+DPT.dwCylinders]
-	cwd
-	mov		dl, [di+DPT.bHeads]
+AccessDPT_GetLCHStoAXBLBH:
+	; Return LBA-assisted CHS if LBA addressing used
+	test	BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
+	jz		SHORT .ConvertPchsToLchs
 
-	; Only need to limit sectors for LBA assist
-	test	BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
-	jz		SHORT AccessDPT_ShiftPCHinBXDXtoLCH
+	call	AccessDPT_GetLbaSectorCountToBXDXAX
+	call	AtaID_GetLbaAssistedCHStoDXAXBLBH
+	test	dx, dx
+	jnz		SHORT .LimitAXtoMaxLCHScylinders
+	cmp		ax, MAX_LCHS_CYLINDERS
+	jbe		SHORT .returnLCHS
+.LimitAXtoMaxLCHScylinders:
+	mov		ax, MAX_LCHS_CYLINDERS
+.returnLCHS:
+	ret
 
-	cmp		WORD [di+DPT.dwCylinders+2], BYTE 0
-	jnz		SHORT .Return_MAX_LCHS_CYLINDERS
+.ConvertPchsToLchs:
+	mov		ax, [di+DPT.wPchsCylinders]
+	mov		bx, [di+DPT.wPchsHeadsAndSectors]
+	jmp		SHORT AccessDPT_ShiftPCHinAXBLtoLCH
 
-	; Limit cylinders to 1024
-	cmp		bx, MAX_LCHS_CYLINDERS
-	jb		SHORT .Return
-ALIGN JUMP_ALIGN
-.Return_MAX_LCHS_CYLINDERS:
-	mov		bx, MAX_LCHS_CYLINDERS
-ALIGN JUMP_ALIGN, ret
-.Return:
+
+;--------------------------------------------------------------------
+; AccessDPT_GetLbaSectorCountToBXDXAX
+;	Parameters:
+;		DS:DI:	Ptr to Disk Parameter Table
+;	Returns:
+;		BX:DX:AX:	48-bit sector count
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+AccessDPT_GetLbaSectorCountToBXDXAX:
+	mov		ax, [di+DPT.twLbaSectors]
+	mov		dx, [di+DPT.twLbaSectors+2]
+	mov		bx, [di+DPT.twLbaSectors+4]
 	ret
 
 
 ;--------------------------------------------------------------------
-; AccessDPT_ShiftPCHinBXDXtoLCH
+; AccessDPT_ShiftPCHinAXBLtoLCH
 ;	Parameters:
-;		BX:		P-CHS cylinders (1...16383)
-;		DX:		P-CHS heads (1...16)
+;		AX:		P-CHS cylinders (1...16383)
+;		BL:		P-CHS heads (1...16)
 ;	Returns:
-;		BX:		Number of L-CHS cylinders (1...1024)
-;		DX:		Number of L-CHS heads (1...255)
+;		AX:		Number of L-CHS cylinders (1...1024)
+;		BL:		Number of L-CHS heads (1...255)
 ;		CX:		Number of bits shifted
 ;	Corrupts registers:
 ;		Nothing
 ;--------------------------------------------------------------------
-AccessDPT_ShiftPCHinBXDXtoLCH:
+AccessDPT_ShiftPCHinAXBLtoLCH:
 	xor		cx, cx
 .ShiftLoop:
-	cmp		bx, MAX_LCHS_CYLINDERS		; Need to shift?
+	cmp		ax, MAX_LCHS_CYLINDERS		; Need to shift?
 	jbe		SHORT .LimitHeadsTo255		;  If not, return
 	inc		cx							; Increment shift count
-	shr		bx, 1						; Halve cylinders
-	shl		dx, 1						; Double heads
+	shr		ax, 1						; Halve cylinders
+	shl		bl, 1						; Double heads
 	jmp		SHORT .ShiftLoop
 .LimitHeadsTo255:						; DOS does not support drives with 256 heads
-	sub		dl, dh						; DH set only when 256 logical heads
-	xor		dh, dh
+	cmp		bl, cl						; Set CF if BL is zero
+	sbb		bl, ch						; If BL=0 then BL=255
 	ret
 
-		
+
 ;--------------------------------------------------------------------
 ; Returns pointer to DRVPARAMS for master or slave drive.
@@ -144,4 +157,2 @@
 	and		al, MASKL_DPT_ADDRESSING_MODE
 %endmacro
-
-		
Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm	(revision 203)
+++ 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
 
