Index: /trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc	(revision 473)
+++ /trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc	(revision 474)
@@ -128,4 +128,10 @@
 	.bSerialBaud			resb 	1	; Serial connection baud rate divisor
 endstruc
+
+; On performance critical situations we compare DPT_ATA.bDevice without checking FLGH_DPT_SERIAL_DEVICE
+; first! DPT_ATA.bDevice uses small values so there will be no problems.
+%if DPT_SERIAL.bSerialPort <> DPT_ATA.bDevice
+	%error "DPT_ATA.bDevice and DPT_SERIAL.bSerialPort must be in same offsets!"
+%endif
 %endif
 
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 473)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 474)
@@ -179,8 +179,12 @@
 %ifdef MODULE_8BIT_IDE
 	cmp		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_DMA
-	je		SHORT 0 ; IdeDma_StartTransferWithCommandInAL
+	je		SHORT .StartDmaTransfer
 	ja		SHORT JrIdeTransfer_StartWithCommandInAL	; DEVICE_8BIT_XTCF_MEMMAP or DEVICE_8BIT_JRIDE_ISA
-%endif
 	jmp		IdeTransfer_StartWithCommandInAL
+.StartDmaTransfer:
+	jmp		IdeDmaTransfer_StartWithCommandInAL
+%else
+	jmp		IdeTransfer_StartWithCommandInAL
+%endif
 
 .WaitUntilNonTransferCommandCompletes:
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDmaTransfer.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDmaTransfer.asm	(revision 474)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDmaTransfer.asm	(revision 474)
@@ -0,0 +1,45 @@
+; Project name	:	XTIDE Universal BIOS
+; Description	:	IDE Device DMA transfer functions.
+
+;
+; XTIDE Universal BIOS and Associated Tools
+; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
+;
+; This program is free software; you can redistribute it and/or modify
+; it under the terms of the GNU General Public License as published by
+; the Free Software Foundation; either version 2 of the License, or
+; (at your option) any later version.
+;
+; This program is distributed in the hope that it will be useful,
+; but WITHOUT ANY WARRANTY; without even the implied warranty of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+; GNU General Public License for more details.
+; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+;
+
+; Structure containing variables for DMA transfer functions.
+; This struct must not be larger than IDEPACK without INTPACK.
+struc DMAVARS	; Must not be larger than 9 bytes! See IDEPACK in RamVars.inc.
+endstruc
+
+
+; Section containing code
+SECTION .text
+
+;--------------------------------------------------------------------
+; IdeDmaTransfer_StartWithCommandInAL
+;	Parameters:
+;		AL:		IDE command that was used to start the transfer
+;				(all PIO read and write commands including Identify Device)
+;		ES:SI:	Ptr to normalized data buffer
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;		SS:BP:	Ptr to IDEPACK
+;	Returns:
+;		AH:		INT 13h Error Code
+;		CX:		Number of successfully transferred sectors
+;		CF:		Cleared if success, Set if error
+;	Corrupts registers:
+;		AL, BX, DX, SI, ES
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+IdeDmaTransfer_StartWithCommandInAL:
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm	(revision 473)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm	(revision 474)
@@ -39,5 +39,5 @@
 ;		AL:		IDE command that was used to start the transfer
 ;				(all PIO read and write commands including Identify Device)
-;		ES:SI:	Ptr to normalized data buffer (SI 0...15)
+;		ES:SI:	Ptr to normalized data buffer
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
 ;		SS:BP:	Ptr to IDEPACK
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 473)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 474)
@@ -111,12 +111,14 @@
 	; Set DMA Mode
 	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_DMA
-	jmp		AH23h_Disable8bitPioMode
+	mov		al, [di+DPT_ATA.bBlockSize]
+	jmp		AH24h_SetBlockSize	; AH=24h limits block size if necessary
 
 .SetMemoryMappedMode:
 	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_MEMMAP
-	jmp		AH23h_Disable8bitPioMode
+	jmp		SHORT .Enable8bitPioMode
 
 .Set8bitPioMode:
 	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_PIO8
+.Enable8bitPioMode:	
 	jmp		AH23h_Enable8bitPioMode
 
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm	(revision 473)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm	(revision 474)
@@ -79,5 +79,4 @@
 ;--------------------------------------------------------------------
 ; AH23h_Enable8bitPioMode
-; AH23h_Disable8bitPioMode
 ;	Parameters:
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
@@ -92,6 +91,3 @@
 	mov		si, FEATURE_ENABLE_8BIT_PIO_TRANSFER_MODE
 	jmp		SHORT AH23h_SetControllerFeatures
-AH23h_Disable8bitPioMode:
-	mov		si, FEATURE_DISABLE_8BIT_PIO_TRANSFER_MODE
-	jmp		SHORT AH23h_SetControllerFeatures
 %endif ; MODULE_8BIT_IDE
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Tools/Prepare.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Tools/Prepare.asm	(revision 473)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Tools/Prepare.asm	(revision 474)
@@ -82,4 +82,5 @@
 ;	Parameters:
 ;		AL:		Number of sectors to transfer
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
 ;		SS:BP:	Ptr to IDEPACK
 ;	Parameters on INTPACK:
@@ -93,5 +94,21 @@
 ALIGN JUMP_ALIGN
 Prepare_BufferToESSIforOldInt13hTransfer:
-	; Normalize buffer pointer
+	cmp		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_DMA
+	jne		SHORT .NormalizeForSmallestPossibleOffset
+
+	; Normalize segment for physical 64k pages
+	xor		bx, bx
+	mov		si, [bp+IDEPACK.intpack+INTPACK.es]	; Load segment
+%rep 4
+	shl		si, 1
+	rcl		bx, 1
+%endrep
+	add		si, [bp+IDEPACK.intpack+INTPACK.bx]
+	adc		bx, BYTE 0
+	mov		es, bx								; ES:SI now has physical address
+	jmp		SHORT Prepare_ByValidatingSectorsInALforOldInt13h
+
+	; Normalize segment for 16b pages
+.NormalizeForSmallestPossibleOffset:
 	mov		bx, [bp+IDEPACK.intpack+INTPACK.bx]	; Load offset
 	mov		si, bx
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 473)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 474)
@@ -153,28 +153,12 @@
 ;--------------------------------------------------------------------
 StartDetectionWithDriveSelectByteInBHandStringInCX:
-	call	DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
-%ifdef MODULE_HOTKEYS
-	call	HotkeyBar_UpdateDuringDriveDetection
-%endif
-	; Fall to .AutodetectXTCFport or .ReadAtaInfoFromHardDisk
-
-
+	; Autodetect port for XT-CF
 %ifdef MODULE_8BIT_IDE
-;--------------------------------------------------------------------
-; .AutodetectXTCFport
-;	Parameters:
-;		BH:		Drive Select byte for Drive and Head Register
-;		CS:BP:	Ptr to IDEVARS for the drive
-;		DS:		RAMVARS segment
-;		ES:		Zero (BDA segment)
-;	Returns:
-;       DX:		Autodetected port (for devices that support autodetection)
-;	Corrupts registers:
-;		AX
-;--------------------------------------------------------------------
-.AutodetectXTCFport:
-	; Detect port for XTCF
 	call	DetectDrives_DoesIdevarsInCSBPbelongToXTCF
 	jne		SHORT .SkipXTCFportDetection
+
+	; XT-CF do not support slave drives so skip detection
+	test	bh, FLG_DRVNHEAD_DRV
+	jnz		SHORT NoSlaveDriveAvailable
 
 	; XT-CF do not support slave drives so we can safely update port
@@ -183,11 +167,29 @@
 	call	BootVars_GetNextXTCFportToDetectToDX
 	cmp		dx, XTCF_BASE_PORT_4
-	ja		SHORT DetectDrives_DriveNotFound	; XT-CF not found from any port
+	ja		SHORT .SkipXTCFportDetection		; XT-CF not found from any port
 
 	call	AH1Eh_DetectXTCFwithBasePortInDX
 	jc		SHORT .DetectNextPort				; XT-CF not found from this port
+
+	; We now have autodetected port in DX
+	push	dx
+	xchg	ax, dx								; Port to print in AX
+	call	DetectPrint_StartDetectWithAutodetectedBasePortInAXandIdeVarsInCSBP
+	jmp		SHORT .DriveDetectionStringPrintedOnScreen
+
+	; Print detect string for devices that do not support autodetection 	
 .SkipXTCFportDetection:
+	push	dx
+%endif ; MODULE_8BIT_IDE
+
+	call	DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
+.DriveDetectionStringPrintedOnScreen:
+%ifdef MODULE_HOTKEYS
+	call	HotkeyBar_UpdateDuringDriveDetection
+%endif
+%ifdef MODULE_8BIT_IDE
+	pop		dx
+%endif
 	; Fall to .ReadAtaInfoFromHardDisk
-%endif ; MODULE_8BIT_IDE
 
 
@@ -284,4 +286,5 @@
 	cmp		al, DEVICE_8BIT_XTCF_MEMMAP
 .DeviceIsXTCF:
+NoSlaveDriveAvailable:
 	ret
 %endif ; MODULE_8BIT_IDE
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm	(revision 473)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm	(revision 474)
@@ -75,15 +75,27 @@
 ;		CS:CX:	Ptr to "Master" or "Slave" string
 ;		CS:BP:	Ptr to IDEVARS
-;       SI:		Ptr to template string
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, SI, DI, CX, DX
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, CX, DX, SI, DI
 ;--------------------------------------------------------------------
 DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP:
 	mov		ax, [cs:bp+IDEVARS.wBasePort]   ; for IDE: AX=port address, DH=.bDevice
+	; Fall to DetectPrint_StartDetectWithAutodetectedBasePortInAX
+
+;--------------------------------------------------------------------
+; DetectPrint_StartDetectWithAutodetectedBasePortInAXandIdeVarsInCSBP
+;	Parameters:
+;		AX:		Base Port Address
+;		CS:CX:	Ptr to "Master" or "Slave" string
+;		CS:BP:	Ptr to IDEVARS
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, CX, DX, SI, DI
+;--------------------------------------------------------------------	
+DetectPrint_StartDetectWithAutodetectedBasePortInAXandIdeVarsInCSBP:
 	mov		dx, [cs:bp+IDEVARS.bDevice-1]   ; for Serial: AL=port address>>2, AH=baud rate
 											;			  DL=COM number character, DH=.bDevice
-
 	push	bp								; setup stack for call to
 	mov		bp, sp							; BootMenuPrint_FormatCSSIfromParamsInSSBP
Index: /trunk/XTIDE_Universal_BIOS/Src/Main.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 473)
+++ /trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 474)
@@ -229,4 +229,5 @@
 %ifdef MODULE_8BIT_IDE
 	%include "JrIdeTransfer.asm"	; Must be included after IdeCommand.asm
+	%include "IdeDmaTransfer.asm"
 %endif
 	%include "IdeTransfer.asm"
