Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HAddress.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HAddress.asm	(revision 3)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HAddress.asm	(revision 150)
@@ -1,7 +1,3 @@
-; File name		:	HAddress.asm
-; Project name	:	IDE BIOS
-; Created date	:	11.3.2010
-; Last update	:	4.4.2010
-; Author		:	Tomi Tilli
+; Project name	:	XTIDE Universal BIOS
 ; Description	:	Functions for address translations.
 
@@ -9,9 +5,15 @@
 SECTION .text
 
+; Jump table for conversion functions
+ALIGN WORD_ALIGN
+g_rgfnAddressTranslation:
+	dw		DoNotConvertLCHS					; 0, ADDR_DPT_LCHS
+	dw		ConvertLCHStoPCHS					; 1, ADDR_DPT_PCHS
+	dw		ConvertLCHStoLBARegisterValues		; 2, ADDR_DPT_LBA28
+	dw		ConvertLCHStoLBARegisterValues		; 3, ADDR_DPT_LBA48
+
+
 ;--------------------------------------------------------------------
-; Outputs sector count, L-CHS address and command to IDE registers.
-; This function does not wait until command has been completed.
-;
-; HAddress_ConvertParamsFromBiosLCHStoIDE
+; HAddress_OldInt13hAddressToIdeAddress
 ;	Parameters:
 ;		CH:		Cylinder number, bits 7...0
@@ -28,22 +30,12 @@
 ;		AX, DX
 ;--------------------------------------------------------------------
-ALIGN WORD_ALIGN
-g_rgfnAddressTranslation:
-	dw		HAddress_DoNotConvertLCHS					; 0, ADDR_DPT_LCHS
-	dw		HAddress_ConvertLCHStoPCHS					; 1, ADDR_DPT_PCHS
-	dw		HAddress_ConvertLCHStoLBARegisterValues		; 2, ADDR_DPT_LBA28
-	dw		HAddress_ConvertLCHStoLBARegisterValues		; 3, ADDR_DPT_LBA48
-
 ALIGN JUMP_ALIGN
-HAddress_ConvertParamsFromBiosLCHStoIDE:
-	mov		bl, [di+DPT.bFlags]
-	and		bx, BYTE MASK_DPT_ADDR						; Addressing mode to BX
+HAddress_OldInt13hAddressToIdeAddress:
+	call	AccessDPT_GetAddressingModeForWordLookToBX
 	push	WORD [cs:bx+g_rgfnAddressTranslation]		; Push return address
-	; Fall to HAddress_ExtractLCHSFromBiosParams
+	; Fall to HAddress_ExtractLCHSparametersFromOldInt13hAddress
 
 ;---------------------------------------------------------------------
-; Extracts L-CHS parameters from BIOS function parameters.
-;
-; HAddress_ExtractLCHSFromBiosParams:
+; HAddress_ExtractLCHSparametersFromOldInt13hAddress
 ;	Parameters:
 ;		CH:		Cylinder number, bits 7...0
@@ -58,6 +50,5 @@
 ;		Nothing
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HAddress_ExtractLCHSFromBiosParams:
+HAddress_ExtractLCHSparametersFromOldInt13hAddress:
 	mov		bl, cl				; Copy sector number...
 	and		bl, 3Fh				; ...and limit to 1...63
@@ -70,5 +61,5 @@
 
 ;---------------------------------------------------------------------
-; Converts BIOS LCHS parameters to IDE P-CHS parameters.
+; Converts LCHS parameters to IDE P-CHS parameters.
 ; PCylinder	= (LCylinder << n) + (LHead / PHeadCount)
 ; PHead		= LHead % PHeadCount
@@ -89,8 +80,8 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-HAddress_ConvertLCHStoPCHS:
+ConvertLCHStoPCHS:
 	; LHead / PHeadCount and LHead % PHeadCount
 	eMOVZX	ax, bh					; Copy L-CHS Head number to AX
-	div		BYTE [di+DPT.bPHeads]	; AL = LHead / PHeadCount, AH = LHead % PHeadCount
+	div		BYTE [di+DPT.bPchsHeads]; AL = LHead / PHeadCount, AH = LHead % PHeadCount
 	mov		bh, ah					; Copy P-CHS Head number to BH
 	xor		ah, ah					; AX = LHead / PHeadCount
@@ -98,10 +89,10 @@
 	; (LCylinder << n) + (LHead / PHeadCount)
 	mov		dx, cx					; Copy L-CHS Cylinder number to DX
-	mov		cl, [di+DPT.bShLtoP]	; Load shift count
+	mov		cl, [di+DPT.wFlags]		; Load shift count
+	and		cl, MASK_DPT_CHS_SHIFT_COUNT
 	shl		dx, cl					; DX = LCylinder << n
 	add		ax, dx					; AX = P-CHS Cylinder number
 	mov		cx, ax					; Copy P-CHS Cylinder number to CX
-ALIGN JUMP_ALIGN
-HAddress_DoNotConvertLCHS:
+DoNotConvertLCHS:
 	ret
 
@@ -109,8 +100,11 @@
 ;---------------------------------------------------------------------
 ; Converts LCHS parameters to 28-bit LBA address.
+; Only 24-bits are used since LHCS to LBA28 conversion has 8.4GB limit.
+; LBA = ((cylToSeek*headsPerCyl+headToSeek)*sectPerTrack)+sectToSeek-1
+;
 ; Returned address is in same registers that
 ; HAddress_DoNotConvertLCHS and HAddress_ConvertLCHStoPCHS returns.
 ;
-; HAddress_ConvertLCHStoLBARegisterValues:
+; ConvertLCHStoLBARegisterValues:
 ;	Parameters:
 ;		BL:		Sector number (1...63)
@@ -127,33 +121,9 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-HAddress_ConvertLCHStoLBARegisterValues:
-	call	HAddress_ConvertLCHStoLBA28
-	mov		bl, al					; Sector Number Register (LBA 7...0)
-	mov		cl, ah					; Low Cylinder Register (LBA 15...8)
-	mov		ch, dl					; High Cylinder Register (LBA 23...16)
-	mov		bh, dh					; Drive and Head Register (LBA 27...24)
-	ret
-
-;---------------------------------------------------------------------
-; Converts LCHS parameters to 28-bit LBA address.
-; Only 24-bits are used since LHCS to LBA28 conversion has 8.4GB limit.
-; LBA = ((cylToSeek*headsPerCyl+headToSeek)*sectPerTrack)+sectToSeek-1
-;
-; HAddress_ConvertLCHStoLBA28:
-;	Parameters:
-;		BL:		Sector number (1...63)
-;		BH:		Head number (0...255)
-;		CX:		Cylinder number (0...1023)
-;		DS:DI:	Ptr to Disk Parameter Table
-;	Returns:
-;		DX:AX:	28-bit LBA address (DH is always zero)
-;	Corrupts registers:
-;		BX, CX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HAddress_ConvertLCHStoLBA28:
+ConvertLCHStoLBARegisterValues:
 	; cylToSeek*headsPerCyl (18-bit result)
 	mov		ax, cx					; Copy Cylinder number to AX
-	mul		WORD [di+DPT.wLHeads]	; DX:AX = cylToSeek*headsPerCyl
+	eMOVZX	dx, BYTE [di+DPT.bLchsHeads]
+	mul		dx						; DX:AX = cylToSeek*headsPerCyl
 
 	; +=headToSeek (18-bit result)
@@ -163,5 +133,5 @@
 
 	; *=sectPerTrack (18-bit by 6-bit multiplication with 24-bit result)
-	eMOVZX	cx, BYTE [di+DPT.bPSect]; Load Sectors per Track
+	eMOVZX	cx, BYTE [di+DPT.bPchsSectors]	; Load Sectors per Track
 	xchg	ax, dx					; Hiword to AX, loword to DX
 	mul		cl						; AX = hiword * Sectors per Track
@@ -176,3 +146,9 @@
 	add		ax, bx					; Add to loword
 	adc		dl, bh					; Add possible carry to byte2, BH=zero
+
+	; Copy DX:AX to proper return registers
+	xchg	bx, ax					; BL = Sector Number Register (LBA 7...0)
+	mov		cl, bh					; Low Cylinder Register (LBA 15...8)
+	mov		ch, dl					; High Cylinder Register (LBA 23...16)
+	mov		bh, dh					; Drive and Head Register (LBA 27...24)
 	ret
