Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm	(revision 445)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm	(revision 473)
@@ -20,22 +20,4 @@
 ; Section containing code
 SECTION .text
-
-%ifdef MODULE_ADVANCED_ATA
-;--------------------------------------------------------------------
-; AccessDPT_GetIdeBasePortToBX
-;	Parameters:
-;		DS:DI:	Ptr to Disk Parameter Table
-;	Returns:
-;		BX:		IDE Base Port Address
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-AccessDPT_GetIdeBasePortToBX:
-	eMOVZX	bx, [di+DPT.bIdevarsOffset]			; CS:BX points to IDEVARS
-	mov		bx, [cs:bx+IDEVARS.wPort]
-	ret
-%endif	; MODULE_ADVANCED_ATA
-
 
 ;--------------------------------------------------------------------
@@ -113,4 +95,28 @@
 
 
+%ifdef MODULE_8BIT_IDE
+;--------------------------------------------------------------------
+; AccessDPT_IsThisDeviceXTCF
+;	Parameters:
+;		DS:DI:	Ptr to Disk Parameter Table
+;	Returns:
+;		AH:		Device Type
+;		ZF:		Set if XTCF
+;				Cleared if some other device
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+AccessDPT_IsThisDeviceXTCF:
+	mov		ah, [di+DPT_ATA.bDevice]
+	cmp		ah, DEVICE_8BIT_XTCF_PIO8
+	je		SHORT .DeviceIsXTCF
+	cmp		ah, DEVICE_8BIT_XTCF_DMA
+	je		SHORT .DeviceIsXTCF
+	cmp		ah, DEVICE_8BIT_XTCF_MEMMAP
+.DeviceIsXTCF:
+	ret
+%endif ; MODULE_8BIT_IDE
+
+
 %ifdef MODULE_EBIOS
 ;--------------------------------------------------------------------
@@ -142,7 +148,6 @@
 ;		Nothing
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
 AccessDPT_GetPointerToDRVPARAMStoCSBX:
-	eMOVZX	bx, BYTE [di+DPT.bIdevarsOffset]	; CS:BX points to IDEVARS
+	call	AccessDPT_GetIdevarsToCSBX
 	add		bx, BYTE IDEVARS.drvParamsMaster	; CS:BX points to Master Drive DRVPARAMS
 	test	BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
@@ -150,4 +155,21 @@
 	add		bx, BYTE DRVPARAMS_size				; CS:BX points to Slave Drive DRVPARAMS
 .ReturnPointerToDRVPARAMS:
+	ret
+
+
+;--------------------------------------------------------------------
+; Needed many times during initialization so it is better to
+; make it as a function to save bytes.
+;
+; AccessDPT_GetIdevarsToCSBX
+;	Parameters:
+;		DS:DI:	Ptr to Disk Parameter Table
+;	Returns:
+;		CS:BX:	Ptr to IDEVARS for the drive
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+AccessDPT_GetIdevarsToCSBX:
+	eMOVZX	bx, BYTE [di+DPT.bIdevarsOffset]
 	ret
 
Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/BootVars.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/BootVars.asm	(revision 445)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/BootVars.asm	(revision 473)
@@ -32,4 +32,8 @@
 ;--------------------------------------------------------------------
 BootVars_Initialize:
+%ifdef MODULE_8BIT_IDE
+	mov		WORD [es:BOOTVARS.wNextXTCFportToScan], XTCF_BASE_PORT_1
+%endif
+
 	; Clear to zero
 	mov		al, DRVDETECTINFO_size
@@ -66,2 +70,24 @@
 
 %endif ; MODULE_HOTKEYS
+
+
+%ifdef MODULE_8BIT_IDE
+;--------------------------------------------------------------------
+; BootVars_GetNextXTCFportToDetectToDX
+;	Parameters:
+;		ES:		BDA Segment
+;	Returns:
+;		DX:		Next XT-CF port to detect
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+BootVars_GetNextXTCFportToDetectToDX:
+	mov		dx, [es:BOOTVARS.wNextXTCFportToScan]
+	test	dl, dl
+	jz		SHORT .NextOneIs240hor340h
+	add		WORD [es:BOOTVARS.wNextXTCFportToScan], XTCF_BASE_PORT_3 - XTCF_BASE_PORT_2
+	ret
+.NextOneIs240hor340h:
+	mov		BYTE [es:BOOTVARS.wNextXTCFportToScan], XTCF_BASE_PORT_2 & 0FFh	; 40h
+	ret		
+%endif ; MODULE_8BIT_IDE
Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm	(revision 445)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm	(revision 473)
@@ -28,4 +28,5 @@
 ;	Parameters:
 ;		BH:		Drive Select byte for Drive and Head Register
+;		DX:		Autodetected port (for devices that support autodetection)
 ;		ES:SI:	Ptr to 512-byte ATA information read from the drive
 ;		CS:BP:	Ptr to IDEVARS for the controller
@@ -47,4 +48,5 @@
 ;	Parameters:
 ;		BH:		Drive Select byte for Drive and Head Register
+;		DX:		Autodetected port (for devices that support autodetection)
 ;		DS:DI:	Ptr to Disk Parameter Table
 ;		CS:BP:	Ptr to IDEVARS for the controller
@@ -55,5 +57,5 @@
 ;--------------------------------------------------------------------
 .InitializeDPT:
-	mov		[di+DPT.bIdevarsOffset], bp		; IDEVARS must start in first 256 bytes of ROM
+	call	CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI
 	; Fall to .StoreDriveSelectAndDriveControlByte
 
@@ -230,4 +232,31 @@
 
 ;--------------------------------------------------------------------
+; CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI
+;	Parameters:
+;		DX:		Autodetected port (for devices that support autodetection)
+;		DS:DI:	Ptr to Disk Parameter Table
+;		CS:BP:	Ptr to IDEVARS for the controller
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI:
+	mov		[di+DPT.bIdevarsOffset], bp		; IDEVARS must start in first 256 bytes of ROM
+
+%ifdef MODULE_8BIT_IDE
+	call	DetectDrives_DoesIdevarsInCSBPbelongToXTCF
+	jne		SHORT .DeviceUsesPortSpecifiedInIDEVARS
+	mov		[di+DPT.wBasePort], dx
+	ret
+.DeviceUsesPortSpecifiedInIDEVARS:
+%endif ; MODULE_8BIT_IDE
+
+	mov		ax, [cs:bp+IDEVARS.wBasePort]
+	mov		[di+DPT.wBasePort], ax
+	ret
+
+
+;--------------------------------------------------------------------
 ; GetUserDefinedCapacityToBXAXandFlagsToCXandModeToDXfromROMVARS
 ;	Parameters:
Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm	(revision 445)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm	(revision 473)
@@ -208,9 +208,10 @@
 	ret
 
+
 %ifdef MODULE_SERIAL_FLOPPY
 ;--------------------------------------------------------------------
 ; RamVars_UnpackFlopCntAndFirstToAL
 ;	Parameters:
-;		Nothing
+;		DS:		RAMVARS segment
 ;	Returns:
 ;		AL:		First floppy drive number supported
@@ -226,2 +227,16 @@
 	ret
 %endif
+
+
+;--------------------------------------------------------------------
+; RamVars_IsDriveDetectionInProgress
+;	Parameters:
+;		DS:		RAMVARS segment
+;	Returns:
+;		ZF:		Set if drive detection is in progress (ROM initialization)
+;	Corrupts registers:
+;		None
+;--------------------------------------------------------------------
+RamVars_IsDriveDetectionInProgress:
+	cmp		WORD [RAMVARS.wSignature], RAMVARS_DRV_DETECT_SIGNATURE
+	ret
