Index: /trunk/XTIDE_Universal_BIOS/Inc/BootVars.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/BootVars.inc	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Inc/BootVars.inc	(revision 473)
@@ -37,9 +37,13 @@
 	.dwPostStack		resb	4		; POST stack pointer when entering INT 19h
 
+%ifdef MODULE_8BIT_IDE
+	.wNextXTCFportToScan	resb	2	; Needed for XT-CF port autodetection
+%endif
+
 	.clearToZeroFromThisPoint:
 %ifdef MODULE_HOTKEYS
 	.hotkeyVars			resb	HOTKEYVARS_size
 %endif
-	
+
 	.rgDrvDetectInfo:					; Array containing DRVDETECTINFO structs
 endstruc
Index: /trunk/XTIDE_Universal_BIOS/Inc/Controllers/JRIDE_ISA.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/Controllers/JRIDE_ISA.inc	(revision 473)
+++ /trunk/XTIDE_Universal_BIOS/Inc/Controllers/JRIDE_ISA.inc	(revision 473)
@@ -0,0 +1,28 @@
+; Project name	:	XTIDE Universal BIOS
+; Description	:	JR-IDE/ISA specifications.
+
+;
+; 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
+;
+
+%ifndef JRIDEISA_INC
+%define JRIDEISA_INC
+
+JRIDE_SECTOR_ACCESS_WINDOW_OFFSET			EQU	3C00h	; 512 byte IDE Sector Access Window
+JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET	EQU	3E00h	; 8 byte CS0 IDE Register Window
+JRIDE_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET	EQU	3E08h	; 8 byte CS1 IDE Register Window
+
+
+%endif ; JRIDEISA_INC
Index: /trunk/XTIDE_Universal_BIOS/Inc/Controllers/XTCF.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/Controllers/XTCF.inc	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Inc/Controllers/XTCF.inc	(revision 473)
@@ -23,4 +23,7 @@
 %define XTCF_INC
 
+XTCF_DMA_MODE_MAX_BLOCK_SIZE		EQU		64		; Sectors
+OFFSET_TO_CONTROL_BLOCK_REGISTERS	EQU		8
+
 ; Possible base addresses. Note that all XT-CF IDE registers are SHL 1 compared
 ; to standard IDE registers.
@@ -42,4 +45,7 @@
 ; 8-bit PIO transfers (port I/O) are used if Control Register is zero.
 ; Any other value means DMA transfers (using DMA channel 3).
+XTCF_8BIT_PIO_MODE					EQU		0
+XTCF_MEMORY_MAPPED_MODE				EQU		0A0h
+
 
 
Index: /trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc	(revision 473)
@@ -24,5 +24,5 @@
 ; Base DPT for all device types
 struc DPT
-	; General Disk Parameter Table related (Bytes 0...3)
+	; General Disk Parameter Table related
 	.wFlags:
 	.bFlagsLow				resb	1
@@ -30,6 +30,7 @@
 	.bIdevarsOffset			resb	1	; Offset to IDEVARS for this drive
 	.bInitError				resb	1	; Flags for AH=09h initialization errors
+	.wBasePort				resb	2	; Segment for JR-IDE/ISA
 
-	; CHS variables (Bytes 4...8)
+	; CHS variables
 	.wLchsCylinders			resb	2	; (1...1027, yes 1027)
 	.wLchsHeadsAndSectors:
@@ -43,8 +44,4 @@
 	.wPchsCylinders			resb	2
 	.twLbaSectors			resb	6	; 48-bit sector count for LBA addressing
-%endif
-
-%ifdef MODULE_8BIT_IDE
-	.wXTCFport				resb	2	; Autodetected XT-CF port
 %endif
 							alignb	2	; WORD alignent for DPT_SERIAL or DPT_ATA
@@ -96,13 +93,13 @@
 	FLG_INITERROR_FAILED_TO_SET_PIO_MODE				EQU (1<<5)
 	FLG_INITERROR_FAILED_TO_INITIALIZE_STANDBY_TIMER	EQU	(1<<6)
-	FLG_INITERROR_FAILED_TO_ENABLE_8BIT_PIO_MODE		EQU	(1<<7)
+	FLG_INITERROR_FAILED_TO_SET_XTCF_MODE				EQU	(1<<7)
 
 
 
 ; DPT for ATA devices
-struc DPT_ATA	; 10/18 bytes + 2 bytes = 12/20 bytes
+struc DPT_ATA
 	.dpt					resb	DPT_size
+	.bDevice				resb	1	; Device Type from IDEVARS (overrided when 32-bit controller detected)
 	.bBlockSize				resb	1	; Current block size in sectors (do not set to zero!)
-	.bDevice				resb	1	; Device Type from IDEVARS (overrided when 32-bit controller detected)
 endstruc
 
@@ -112,5 +109,5 @@
 ; EBDA must be reserved for DPTs when using these!
 %ifdef MODULE_ADVANCED_ATA
-struc DPT_ADVANCED_ATA	; 12/20 bytes + 8 bytes = 20/28 bytes
+struc DPT_ADVANCED_ATA
 	.dpt_ata				resb	DPT_ATA_size
 	.wControllerID			resb	2	; Controller specific ID WORD (from Advanced Controller detection)
@@ -125,5 +122,5 @@
 ; DPT for Serial devices
 %ifdef MODULE_SERIAL
-struc DPT_SERIAL	; 8/18 bytes + 2 bytes = 10/20 bytes
+struc DPT_SERIAL
 	.dpt					resb	DPT_size
 	.wSerialPortAndBaud:
Index: /trunk/XTIDE_Universal_BIOS/Inc/DeviceIDE.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/DeviceIDE.inc	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Inc/DeviceIDE.inc	(revision 473)
@@ -32,9 +32,9 @@
 
 %ifdef MODULE_FEATURE_SETS
-TIMEOUT_BSY				EQU		TIMEOUT_MOTOR_STARTUP
-TIMEOUT_DRDY			EQU		TIMEOUT_MOTOR_STARTUP
+	TIMEOUT_BSY			EQU		TIMEOUT_MOTOR_STARTUP
+	TIMEOUT_DRDY		EQU		TIMEOUT_MOTOR_STARTUP
 %else
-TIMEOUT_BSY				EQU		(2600/55)	; 2600 ms
-TIMEOUT_DRDY			EQU		(2600/55)	; 2600 ms
+	TIMEOUT_BSY			EQU		(2600/55)	; 2600 ms
+	TIMEOUT_DRDY		EQU		(2600/55)	; 2600 ms
 %endif
 
Index: /trunk/XTIDE_Universal_BIOS/Inc/IdeIO.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/IdeIO.inc	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Inc/IdeIO.inc	(revision 473)
@@ -21,14 +21,7 @@
 %define IDE_IO_INC
 
-JRIDE_SECTOR_ACCESS_WINDOW_OFFSET			EQU	3C00h	; 512 byte IDE Sector Access Window
-JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET	EQU	3E00h	; 8 byte CS0 IDE Register Window
-JRIDE_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET	EQU	3E08h	; 8 byte CS1 IDE Register Window
-JRIDE_SECTOR_ACCESS_WINDOW_SIZE				EQU	512		; 512 bytes
-
-
 ;--------------------------------------------------------------------
-; OUTPUT_AL_TO_IDE_REGISTER_IN_DL
-; JUMP_TO_OUTPUT_AL_TO_IDE_REGISTER_IN_DL
-; OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER_IN_DL
+; OUTPUT_AL_TO_IDE_REGISTER
+; OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER
 ;	Parameters:
 ;		AL:		Byte to output
@@ -42,22 +35,41 @@
 ;--------------------------------------------------------------------
 %macro OUTPUT_AL_TO_IDE_REGISTER 1
-%ifnidni %1, dl
-	mov		dl, %1
+%ifndef MODULE_8BIT_IDE	; Standard IDE controllers only
+
+	%ifnidni %1, dx
+		mov		dx, %1
+	%endif
+	add		dx, [di+DPT.wBasePort]
+	out		dx, al
+
+%else	; Register translations required
+
+	%ifnidni %1, dl
+		mov		dl, %1
+	%endif
+	call	IdeIO_OutputALtoIdeRegisterInDL
+
 %endif
-	call	IdeIO_OutputALtoIdeRegisterInDL
 %endmacro
 
-%macro JUMP_TO_OUTPUT_AL_TO_IDE_REGISTER 1
-%ifnidni %1, dl
-	mov		dl, %1
-%endif
-	jmp		IdeIO_OutputALtoIdeRegisterInDL
-%endmacro
 
 %macro OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER 1
-%ifnidni %1, dl
-	mov		dl, %1
+%ifndef MODULE_8BIT_IDE	; Standard IDE controllers only
+
+	%ifnidni %1, dx
+		mov		dx, %1
+	%endif
+	eMOVZX	bx, BYTE [di+DPT.bIdevarsOffset]
+	add		dx, [cs:bx+IDEVARS.wControlBlockPort]
+	out		dx, al
+
+%else	; Register translations required
+
+	%ifnidni %1, dl
+		mov		dl, %1
+	%endif
+	call	IdeIO_OutputALtoIdeControlBlockRegisterInDL
+
 %endif
-	call	IdeIO_OutputALtoIdeControlBlockRegisterInDL
 %endmacro
 
@@ -74,8 +86,20 @@
 ;--------------------------------------------------------------------
 %macro INPUT_TO_AL_FROM_IDE_REGISTER 1
-%ifnidni %1, dl
-	mov		dl, %1
+%ifndef MODULE_8BIT_IDE	; Standard IDE controllers only
+
+	%ifnidni %1, dx
+		mov		dx, %1
+	%endif
+	add		dx, [di+DPT.wBasePort]
+	in		al, dx
+
+%else	; Register translations required
+
+	%ifnidni %1, dl
+		mov		dl, %1
+	%endif
+		call	IdeIO_InputToALfromIdeRegisterInDL
+
 %endif
-	call	IdeIO_InputToALfromIdeRegisterInDL
 %endmacro
 
Index: /trunk/XTIDE_Universal_BIOS/Inc/IdeRegisters.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/IdeRegisters.inc	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Inc/IdeRegisters.inc	(revision 473)
@@ -103,4 +103,5 @@
 FEATURE_ENABLE_8BIT_PIO_TRANSFER_MODE	EQU		01h		; CFA feature set only
 FEATURE_ENABLE_WRITE_CACHE				EQU		02h
+FEATURE_DISABLE_8BIT_PIO_TRANSFER_MODE	EQU		81h		; CFA feature set only
 FEATURE_DISABLE_WRITE_CACHE				EQU		82h		; Can also be used to flush cache
 FEATURE_SET_TRANSFER_MODE				EQU		03h		; Transfer mode goes to the Sector Count Register
Index: /trunk/XTIDE_Universal_BIOS/Inc/ModuleDependency.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/ModuleDependency.inc	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Inc/ModuleDependency.inc	(revision 473)
@@ -32,10 +32,4 @@
 %endif
 
-%ifdef MODULE_JRIDE
-	%ifndef MODULE_8BIT_IDE
-		%define MODULE_8BIT_IDE
-	%endif
-%endif
-
 
 
@@ -44,4 +38,5 @@
 	%include "IDE_8bit.inc"			; For IDE 8-bit data port macros
 	%include "XTCF.inc"				; For Lo-tech XT-CF
+	%include "JRIDE_ISA.inc"		; For JR-IDE/ISA
 %endif
 
@@ -104,10 +99,4 @@
 %endif
 
-%ifdef MODULE_JRIDE
-	MAIN_FLG_MODULE_JRIDE	EQU	FLG_ROMVARS_MODULE_JRIDE
-%else
-	MAIN_FLG_MODULE_JRIDE	EQU	0
-%endif
-
 %ifdef MODULE_SERIAL
 	MAIN_FLG_MODULE_SERIAL	EQU	FLG_ROMVARS_MODULE_SERIAL
@@ -134,3 +123,3 @@
 %endif
 
-MASK_ROMVARS_INCLUDED_MODULES	EQU	MAIN_FLG_MODULE_8BIT_IDE | MAIN_FLG_MODULE_ADVANCED_ATA | MAIN_FLG_MODULE_BOOT_MENU | MAIN_FLG_MODULE_EBIOS | MAIN_FLG_MODULE_HOTKEYS | MAIN_FLG_MODULE_IRQ | MAIN_FLG_MODULE_JRIDE | MAIN_FLG_MODULE_SERIAL | MAIN_FLG_MODULE_SERIAL_FLOPPY | MAIN_FLG_MODULE_STRINGS_COMPRESSED | MAIN_FLG_MODULE_FEATURE_SETS
+MASK_ROMVARS_INCLUDED_MODULES	EQU	MAIN_FLG_MODULE_8BIT_IDE | MAIN_FLG_MODULE_ADVANCED_ATA | MAIN_FLG_MODULE_BOOT_MENU | MAIN_FLG_MODULE_EBIOS | MAIN_FLG_MODULE_HOTKEYS | MAIN_FLG_MODULE_IRQ | MAIN_FLG_MODULE_SERIAL | MAIN_FLG_MODULE_SERIAL_FLOPPY | MAIN_FLG_MODULE_STRINGS_COMPRESSED | MAIN_FLG_MODULE_FEATURE_SETS
Index: /trunk/XTIDE_Universal_BIOS/Inc/RomVars.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/RomVars.inc	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Inc/RomVars.inc	(revision 473)
@@ -72,5 +72,5 @@
 FLG_ROMVARS_MODULE_FEATURE_SETS			EQU	(1<<5)
 FLG_ROMVARS_MODULE_8BIT_IDE				EQU	(1<<6)
-FLG_ROMVARS_MODULE_JRIDE				EQU (1<<7)
+
 FLG_ROMVARS_MODULE_ADVANCED_ATA			EQU	(1<<8)
 FLG_ROMVARS_MODULE_BOOT_MENU			EQU	(1<<9)
@@ -91,10 +91,11 @@
 ;;; Word 0
 	.wSerialPortAndBaud:					; Serial connection port (low, divided by 4) and baud rate divisor (high)
-	.wPort:									; IDE Base Port for Command Block (usual) Registers
+	.wBasePort:								; IDE Base Port for Command Block (usual) Registers
 	.bSerialPort				resb	1
 	.bSerialBaud				resb	1
 
 ;;; Word 1
-	.wPortCtrl:
+	.wControlBlockPort:
+	.bXTCFcontrolRegister:					; XT-CF autodetects ports
 	.bSerialUnused				resb	1	; IDE Base Port for Control Block Registers
 
@@ -104,5 +105,4 @@
 ;;; Word 2
 	.bDevice					resb	1	; Device type
-
 	.bIRQ						resb	1	; Interrupt Request Number
 
@@ -137,16 +137,22 @@
 
 ; Device types for IDEVARS.bDevice
+; IDE Devices are grouped so device numbers cannot be changed without modifying code elsewhere!
 ;
-DEVICE_8BIT_JRIDE_ISA					EQU	(0<<1)	; JR-IDE/ISA (must be 0)
-DEVICE_8BIT_XTCF						EQU	(1<<1)	; Lo-tech XT-CF
-DEVICE_8BIT_XTIDE_REV2					EQU	(2<<1)	; Or rev 1 with swapped A0 and A3 (must be 1 or 2)
-DEVICE_8BIT_XTIDE_REV1					EQU	(3<<1)	; Must be 4
-COUNT_OF_8BIT_IDE_DEVICES				EQU	4
-
-DEVICE_16BIT_ATA						EQU	(COUNT_OF_8BIT_IDE_DEVICES<<1)
-DEVICE_32BIT_ATA						EQU	((COUNT_OF_8BIT_IDE_DEVICES+1)<<1)
-COUNT_OF_16BIT_IDE_DEVICES				EQU	2
-COUNT_OF_ALL_IDE_DEVICES				EQU	(COUNT_OF_8BIT_IDE_DEVICES + COUNT_OF_16BIT_IDE_DEVICES)
-
+COUNT_OF_STANDARD_IDE_DEVICES			EQU	2
+COUNT_OF_8BIT_IDE_DEVICES				EQU	6
+COUNT_OF_ALL_IDE_DEVICES				EQU	(COUNT_OF_8BIT_IDE_DEVICES + COUNT_OF_STANDARD_IDE_DEVICES)
+; Standard port mapped I/O
+DEVICE_16BIT_ATA						EQU	(0<<1)
+DEVICE_32BIT_ATA						EQU	(1<<1)
+DEVICE_8BIT_XTIDE_REV1					EQU	(COUNT_OF_STANDARD_IDE_DEVICES<<1)
+; Address lines A0 and A3 are swapped
+DEVICE_8BIT_XTIDE_REV2					EQU	((COUNT_OF_STANDARD_IDE_DEVICES+1)<<1)	; Or rev 1 with swapped A0 and A3
+; IDE Register offsets are SHL 1
+DEVICE_8BIT_XTCF_PIO8					EQU	((COUNT_OF_STANDARD_IDE_DEVICES+2)<<1)	; XT-CF using 8-bit PIO mode
+DEVICE_8BIT_XTCF_DMA					EQU	((COUNT_OF_STANDARD_IDE_DEVICES+3)<<1)	; XT-CF using DMA
+DEVICE_8BIT_XTCF_MEMMAP					EQU	((COUNT_OF_STANDARD_IDE_DEVICES+4)<<1)	; XT-CF using Memory Mapped transfers (not I/O)
+; Memory Mapped I/O
+DEVICE_8BIT_JRIDE_ISA					EQU	((COUNT_OF_STANDARD_IDE_DEVICES+5)<<1)	; JR-IDE/ISA (Memory Mapped I/O)
+; Virtual devices
 DEVICE_SERIAL_PORT						EQU	(COUNT_OF_ALL_IDE_DEVICES<<1)
 
Index: /trunk/XTIDE_Universal_BIOS/Inc/Version.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/Version.inc	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Inc/Version.inc	(revision 473)
@@ -42,6 +42,6 @@
 
 %define	TITLE_STRING			TITLE_STRING_START, TITLE_STRING_END
-%define	ROM_VERSION_STRING		"v2.0.0",BETA,"2 (",__DATE__,")",NULL
-%define	FLASH_SIGNATURE			"XTIDE201"	; Do not terminate with NULL
+%define	ROM_VERSION_STRING		"v2.0.0",BETA,"2+ (",__DATE__,")",NULL
+%define	FLASH_SIGNATURE			"XTIDE203"	; Do not terminate with NULL
 
 
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm	(revision 473)
@@ -82,4 +82,5 @@
 ;	Parameters:
 ;		BH:		Drive Select byte for Drive and Head Select Register
+;		DX:		Autodetected port (for devices that support autodetection)
 ;		DS:		Segment to RAMVARS
 ;		ES:SI:	Ptr to normalized buffer to receive 512-byte IDE Information
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 473)
@@ -56,4 +56,5 @@
 ;	Parameters:
 ;		BH:		Drive Select byte for Drive and Head Select Register
+;		DX:		Autodetected port for XT-CF
 ;		DS:		Segment to RAMVARS
 ;		ES:SI:	Ptr to buffer to receive 512-byte IDE Information
@@ -70,12 +71,12 @@
 	eMOVZX	ax, bh
 	mov		[di+DPT.wFlags], ax
-	mov		[di+DPT.bIdevarsOffset], bp
+	call	CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI
+	call	IdeDPT_StoreDeviceTypeToDPTinDSDIfromIdevarsInCSBP
 	mov		BYTE [di+DPT_ATA.bBlockSize], 1	; Block = 1 sector
-	call	IdeDPT_StoreDeviceTypeFromIdevarsInCSBPtoDPTinDSDI
 
 	; Wait until drive motors have reached full speed
-	cmp		bp, BYTE ROMVARS.ideVars0		; First controller?
+	cmp		bp, BYTE ROMVARS.ideVars0	; First controller?
 	jne		SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
-	test	bh, FLG_DRVNHEAD_DRV			; Wait already done for Master
+	test	bh, FLG_DRVNHEAD_DRV		; Wait already done for Master
 	jnz		SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
 	call	AHDh_WaitUntilDriveMotorHasReachedFullSpeed
@@ -87,10 +88,16 @@
 
 %ifdef MODULE_8BIT_IDE
-	; Enable 8-bit PIO mode for Lo-tech XT-CF
+	; We set XT-CF to 8-bit PIO mode for Identify Device command.
+	; Correct XT-CF mode is later set on AH=09h (after all drives are detected).
+	call	AccessDPT_IsThisDeviceXTCF
+	jne		SHORT .SkipXTCFmodeChange
+
+	xor		al, al						; XTCF_8BIT_PIO_MODE
 	push	si
-	call	AH9h_Enable8bitPioModeForXTCF
+	call	AH1Eh_ChangeXTCFmodeBasedOnControlRegisterInAL
 	pop		si
 	jc		SHORT .FailedToSet8bitMode
-%endif
+.SkipXTCFmodeChange:
+%endif ; MODULE_8BIT_IDE
 
 	; Prepare to output Identify Device command
@@ -170,7 +177,8 @@
 	cmp		bl, FLG_STATUS_DRQ				; Data transfer started?
 	jne		SHORT .WaitUntilNonTransferCommandCompletes
-%ifdef MODULE_JRIDE
-	cmp		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_JRIDE_ISA
-	je		SHORT JrIdeTransfer_StartWithCommandInAL
+%ifdef MODULE_8BIT_IDE
+	cmp		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_DMA
+	je		SHORT 0 ; IdeDma_StartTransferWithCommandInAL
+	ja		SHORT JrIdeTransfer_StartWithCommandInAL	; DEVICE_8BIT_XTCF_MEMMAP or DEVICE_8BIT_JRIDE_ISA
 %endif
 	jmp		IdeTransfer_StartWithCommandInAL
@@ -205,11 +213,12 @@
 	; We use different timeout value when detecting drives.
 	; This prevents unnecessary long delays when drive is not present.
-	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRDY, FLG_STATUS_DRDY)
+	mov		cx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRDY, FLG_STATUS_DRDY)
 	cmp		WORD [RAMVARS.wDrvDetectSignature], RAMVARS_DRV_DETECT_SIGNATURE
-	eCMOVE	bh, TIMEOUT_SELECT_DRIVE_DURING_DRIVE_DETECTION
+	eCMOVE	ch, TIMEOUT_SELECT_DRIVE_DURING_DRIVE_DETECTION
 
 	; Select Master or Slave Drive
 	mov		al, [bp+IDEPACK.bDrvAndHead]
 	OUTPUT_AL_TO_IDE_REGISTER	DRIVE_AND_HEAD_SELECT_REGISTER
+	mov		bx, cx
 	call	IdeWait_PollStatusFlagInBLwithTimeoutInBH
 
@@ -248,3 +257,4 @@
 
 	mov		al, ch
-	JUMP_TO_OUTPUT_AL_TO_IDE_REGISTER	LBA_HIGH_REGISTER
+	OUTPUT_AL_TO_IDE_REGISTER	LBA_HIGH_REGISTER
+	ret
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDPT.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDPT.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDPT.asm	(revision 473)
@@ -64,5 +64,5 @@
 ;--------------------------------------------------------------------
 .StoreDeviceType:
-	call	IdeDPT_StoreDeviceTypeFromIdevarsInCSBPtoDPTinDSDI
+	call	IdeDPT_StoreDeviceTypeToDPTinDSDIfromIdevarsInCSBP
 
 
@@ -111,5 +111,5 @@
 ;--------------------------------------------------------------------
 .DetectAdvancedIdeController:
-	call	AccessDPT_GetIdeBasePortToBX
+	mov		bx, [di+DPT.wBasePort]
 	call	AdvAtaInit_DetectControllerForIdeBaseInBX
 	mov		[di+DPT_ADVANCED_ATA.wControllerID], ax	; Store zero if none detected
@@ -138,5 +138,5 @@
 
 ;--------------------------------------------------------------------
-; IdeDPT_StoreDeviceTypeFromIdevarsInCSBPtoDPTinDSDI
+; IdeDPT_StoreDeviceTypeToDPTinDSDIfromIdevarsInCSBP
 ;	Parameters:
 ;		DS:DI:	Ptr to Disk Parameter Table
@@ -147,5 +147,5 @@
 ;		AL
 ;--------------------------------------------------------------------
-IdeDPT_StoreDeviceTypeFromIdevarsInCSBPtoDPTinDSDI:
+IdeDPT_StoreDeviceTypeToDPTinDSDIfromIdevarsInCSBP:
 	mov		al, [cs:bp+IDEVARS.bDevice]
 	mov		[di+DPT_ATA.bDevice], al
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm	(revision 473)
@@ -1,4 +1,5 @@
 ; Project name	:	XTIDE Universal BIOS
-; Description	:	IDE Register I/O functions.
+; Description	:	IDE Register I/O functions when supporting 8-bit
+;					devices that need address translations.
 
 ;
@@ -22,4 +23,68 @@
 
 ;--------------------------------------------------------------------
+; IdeIO_InputStatusRegisterToAL
+;	Parameters:
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;	Returns:
+;		AL:		IDE Status Register contents
+;	Corrupts registers:
+;		BX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+IdeIO_InputStatusRegisterToAL:
+%ifndef MODULE_8BIT_IDE
+	INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
+	ret
+
+%else
+	mov		dl, STATUS_REGISTER_in
+	; Fall to IdeIO_InputToALfromIdeRegisterInDL
+
+;--------------------------------------------------------------------
+; IdeIO_InputToALfromIdeRegisterInDL
+;	Parameters:
+;		DL:		IDE Register
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;	Returns:
+;		AL:		Inputted byte
+;	Corrupts registers:
+;		BX, DX
+;--------------------------------------------------------------------
+IdeIO_InputToALfromIdeRegisterInDL:
+	xor		dh, dh	; IDE Register index now in DX
+
+	mov		al, [di+DPT_ATA.bDevice]
+	cmp		al, DEVICE_8BIT_XTIDE_REV2
+	je		SHORT .ReverseA0andA3fromRegisterIndexInDX
+	jb		SHORT .InputToALfromRegisterInDX	; Standard IDE controllers and XTIDE rev 1
+	cmp		al, DEVICE_8BIT_JRIDE_ISA
+	jne		SHORT .ShlRegisterIndexInDX			; All XT-CF modes
+	; Fall to .InputToALfromMemoryMappedRegisterInDX
+
+.InputToALfromMemoryMappedRegisterInDX:
+	mov		bx, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET
+	add		bx, dx
+	push	ds
+	mov		ds, [di+DPT.wBasePort]	; Segment for JR-IDE/ISA
+	mov		al, [bx]
+	pop		ds
+	ret
+
+.ReverseA0andA3fromRegisterIndexInDX:
+	mov		bx, dx
+	mov		dl, [cs:bx+g_rgbSwapA0andA3fromIdeRegisterIndex]
+	SKIP2B	bx	; Skip shl dx, 1
+
+.ShlRegisterIndexInDX:
+	shl		dx, 1
+	; Fall to .InputToALfromRegisterInDX
+
+.InputToALfromRegisterInDX:
+	add		dx, [di+DPT.wBasePort]
+	in		al, dx
+	ret
+
+
+;--------------------------------------------------------------------
 ; IdeIO_OutputALtoIdeControlBlockRegisterInDL
 ;	Parameters:
@@ -33,18 +98,29 @@
 ;--------------------------------------------------------------------
 IdeIO_OutputALtoIdeControlBlockRegisterInDL:
-	%ifdef MODULE_8BIT_IDE
-		mov		dh, [di+DPT_ATA.bDevice]
-		%ifdef MODULE_JRIDE
-			test	dh, dh
-			jnz		SHORT .OutputToIoMappedIde
-		
-			add		dx, JRIDE_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET
-			jmp		SHORT OutputToJrIdeRegister
-		.OutputToIoMappedIde:
-		%endif	; MODULE_JRIDE
-	%endif	; MODULE_8BIT_IDE
+	; Note! We do not need to reverse A0 and A3 for XTIDE rev 2 since
+	; the only Control Block Register we access is DEVICE_CONTROL_REGISTER_out
+	; at offset 6 (0110b).
+	xor		dh, dh	; IDE Register index now in DX
 
-	mov		bl, IDEVARS.wPortCtrl
-	jmp		SHORT OutputALtoIdeRegisterInDLwithIdevarsOffsetToBasePortInBL
+	mov		bl, [di+DPT_ATA.bDevice]
+	cmp		bl, DEVICE_8BIT_XTIDE_REV2
+	jbe		SHORT .OutputALtoControlBlockRegisterInDX	; Standard IDE controllers and XTIDE rev 1
+	cmp		bl, DEVICE_8BIT_JRIDE_ISA
+	jne		SHORT .ShlRegisterIndexInDX		; All XT-CF modes
+	; Fall to .OutputALtoMemoryMappedRegisterInDX
+
+.OutputALtoMemoryMappedRegisterInDX:
+	mov		bx, JRIDE_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET
+	jmp 	SHORT IdeIO_OutputALtoIdeRegisterInDL.OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX
+
+.ShlRegisterIndexInDX:
+	add		dl, OFFSET_TO_CONTROL_BLOCK_REGISTERS
+	shl		dx, 1
+	jmp		SHORT OutputALtoRegisterInDX
+
+.OutputALtoControlBlockRegisterInDX:
+	call	AccessDPT_GetIdevarsToCSBX
+	add		dx, [cs:bx+IDEVARS.wControlBlockPort]
+	jmp		SHORT OutputALtoPortInDX
 
 
@@ -62,123 +138,52 @@
 ALIGN JUMP_ALIGN
 IdeIO_OutputALtoIdeRegisterInDL:
-	%ifdef MODULE_8BIT_IDE
-		mov		dh, [di+DPT_ATA.bDevice]
-		%ifdef MODULE_JRIDE
-			test	dh, dh
-			jnz		SHORT OutputALtoIOmappedIdeRegisterInDL
-		
-		%if JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET & 0FFh = 0
-			mov		dh, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET >> 8
-		%else
-			add		dx, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET
-		%endif
-		OutputToJrIdeRegister:
-			mov		bx, dx
-			mov		[cs:bx], al
-			ret
-		ALIGN JUMP_ALIGN
-		OutputALtoIOmappedIdeRegisterInDL:
-		%endif	; MODULE_JRIDE
-	%endif	; MODULE_8BIT_IDE
+	xor		dh, dh	; IDE Register index now in DX
 
-	mov		bl, IDEVARS.wPort
-OutputALtoIdeRegisterInDLwithIdevarsOffsetToBasePortInBL:
-	call	GetIdePortToDX
+	mov		bl, [di+DPT_ATA.bDevice]
+	cmp		bl, DEVICE_8BIT_XTIDE_REV2
+	je		SHORT .ReverseA0andA3fromRegisterIndexInDX
+	jb		SHORT OutputALtoRegisterInDX	; Standard IDE controllers and XTIDE rev 1
+	cmp		bl, DEVICE_8BIT_JRIDE_ISA
+	jne		SHORT .ShlRegisterIndexInDX		; All XT-CF modes
+	; Fall to .OutputALtoMemoryMappedRegisterInDX
+
+.OutputALtoMemoryMappedRegisterInDX:
+	mov		bx, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET
+.OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX:
+	add		bx, dx
+	push	ds
+	mov		ds, [di+DPT.wBasePort]	; Segment for JR-IDE/ISA
+	mov		[bx], al
+	pop		ds
+	ret
+
+.ReverseA0andA3fromRegisterIndexInDX:
+	mov		bx, dx
+	mov		dl, [cs:bx+g_rgbSwapA0andA3fromIdeRegisterIndex]
+	SKIP2B	bx	; Skip shl dx, 1
+
+.ShlRegisterIndexInDX:
+	shl		dx, 1
+	; Fall to OutputALtoRegisterInDX
+
+ALIGN JUMP_ALIGN
+OutputALtoRegisterInDX:
+	add		dx, [di+DPT.wBasePort]
+OutputALtoPortInDX:
 	out		dx, al
 	ret
 
 
-;--------------------------------------------------------------------
-; IdeIO_InputStatusRegisterToAL
-;	Parameters:
-;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;	Returns:
-;		AL:		IDE Status Register contents
-;	Corrupts registers:
-;		BX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-IdeIO_InputStatusRegisterToAL:
-	mov		dl, STATUS_REGISTER_in
-	; Fall to IdeIO_InputToALfromIdeRegisterInDL
 
-;--------------------------------------------------------------------
-; IdeIO_InputToALfromIdeRegisterInDL
-;	Parameters:
-;		DL:		IDE Register
-;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;	Returns:
-;		AL:		Inputted byte
-;	Corrupts registers:
-;		BX, DX
-;--------------------------------------------------------------------
-IdeIO_InputToALfromIdeRegisterInDL:
-	%ifdef MODULE_8BIT_IDE
-		mov		dh, [di+DPT_ATA.bDevice]
-		%ifdef MODULE_JRIDE
-			test	dh, dh
-			jnz		SHORT .InputToALfromIOmappedIdeRegisterInDL
-		
-		%if JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET & 0FFh = 0
-			mov		dh, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET >> 8
-		%else
-			add		dx, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET
-		%endif
-			mov		bx, dx
-			mov		al, [cs:bx]
-			ret
-		.InputToALfromIOmappedIdeRegisterInDL:
-		%endif	; MODULE_JRIDE
-	%endif	; MODULE_8BIT_IDE
-	mov		bl, IDEVARS.wPort
-	call	GetIdePortToDX
-	in		al, dx
-	ret
+; A0 <-> A3 lookup table
+g_rgbSwapA0andA3fromIdeRegisterIndex:
+	db	0000b	; <-> 0000b, 0
+	db	1000b	; <-> 0001b, 1
+	db	0010b	; <-> 0010b, 2
+	db	1010b	; <-> 0011b, 3
+	db	0100b	; <-> 0100b, 4
+	db	1100b	; <-> 0101b, 5
+	db	0110b	; <-> 0110b, 6
+	db	1110b	; <-> 0111b, 7
 
-
-;--------------------------------------------------------------------
-; GetIdePortToDX
-;	Parameters:
-;		BL:		Offset to port in IDEVARS (IDEVARS.wPort or IDEVARS.wPortCtrl)
-;		DH:		Device Type (IDEVARS.bDevice)
-;		DL:		IDE Register
-;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;	Returns:
-;		DX:		Source/Destination Port
-;	Corrupts registers:
-;		BX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-GetIdePortToDX:
-%ifdef MODULE_8BIT_IDE
-	; Point CS:BX to IDEVARS
-	xor		bh, bh
-	add		bl, [di+DPT.bIdevarsOffset]			; CS:BX now points port address
-
-	; Load port address and check if A0 and A3 address lines need to be reversed
-	cmp		dh, DEVICE_8BIT_XTIDE_REV1
-	mov		dh, bh								; DX now has IDE register offset
-	jae		SHORT .ReturnUntranslatedPortInDX	; No need to swap address lines
-
-	; Exchange address lines A0 and A3 from DL
-	add		dx, [cs:bx]							; DX now has port address
-	mov		bl, dl								; Port low byte to BL
-	and		bl, MASK_A3_AND_A0_ADDRESS_LINES	; Clear all bits except A0 and A3
-	jz		SHORT .ReturnTranslatedPortInDX		; A0 and A3 both zeroes, no change needed
-	cmp		bl, MASK_A3_AND_A0_ADDRESS_LINES
-	je		SHORT .ReturnTranslatedPortInDX		; A0 and A3 both ones, no change needed
-	xor		dl, MASK_A3_AND_A0_ADDRESS_LINES	; Invert A0 and A3
-.ReturnTranslatedPortInDX:
-	ret
-
-.ReturnUntranslatedPortInDX:
-	add		dx, [cs:bx]
-	ret
-
-%else	; Only standard IDE devices
-	xor		bh, bh
-	add		bl, [di+DPT.bIdevarsOffset]			; CS:BX now points port address
-	xor		dh, dh
-	add		dx, [cs:bx]							; DX now has port address
-	ret
-%endif
+%endif ; MODULE_8BIT_IDE
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm	(revision 473)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm	(revision 473)
@@ -0,0 +1,269 @@
+; Project name	:	XTIDE Universal BIOS
+; Description	:	IDE Read/Write functions for transferring
+;					block using PIO modes.
+;					These functions should only be called from IdeTransfer.asm.
+
+;
+; 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
+;
+
+; Section containing code
+SECTION .text
+
+%ifdef MODULE_8BIT_IDE
+
+;--------------------------------------------------------------------
+; IdePioBlock_ReadFromXtideRev1
+;	Parameters:
+;		CX:		Block size in 512 byte sectors
+;		DX:		IDE Data port address
+;		ES:DI:	Normalized ptr to buffer to receive data
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, CX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+IdePioBlock_ReadFromXtideRev1:
+	UNROLL_SECTORS_IN_CX_TO_OWORDS
+	mov		bl, 8		; Bit mask for toggling data low/high reg
+ALIGN JUMP_ALIGN
+.InswLoop:
+	%rep 8 ; WORDs
+		XTIDE_INSW
+	%endrep
+	loop	.InswLoop
+	ret
+
+
+;--------------------------------------------------------------------
+; IdePioBlock_ReadFromXtideRev2		or rev 1 with swapped A0 and A3 (chuck-mod)
+;	Parameters:
+;		CX:		Block size in 512 byte sectors
+;		DX:		IDE Data port address
+;		ES:DI:	Normalized ptr to buffer to receive data
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, CX
+;--------------------------------------------------------------------
+%ifndef USE_186			; 8086/8088 compatible WORD read
+
+ALIGN JUMP_ALIGN
+IdePioBlock_ReadFromXtideRev2:
+	UNROLL_SECTORS_IN_CX_TO_OWORDS
+ALIGN JUMP_ALIGN
+.ReadNextOword:
+	%rep 8	; WORDs
+		in		ax, dx		; Read WORD
+		stosw				; Store WORD to [ES:DI]
+	%endrep
+		loop	.ReadNextOword
+		ret
+
+%endif
+
+
+;--------------------------------------------------------------------
+; IdePioBlock_ReadFrom8bitDataPort		CF-XT when using 8-bit PIO
+;	Parameters:
+;		CX:		Block size in 512 byte sectors
+;		DX:		IDE Data port address
+;		ES:DI:	Normalized ptr to buffer to receive data
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, CX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+IdePioBlock_ReadFrom8bitDataPort:
+%ifdef USE_186
+	shl		cx, 9		; Sectors to BYTEs
+	rep insb
+	ret
+
+%else ; If 8088/8086
+	UNROLL_SECTORS_IN_CX_TO_OWORDS
+ALIGN JUMP_ALIGN
+.ReadNextOword:
+	%rep 16	; BYTEs
+		in		al, dx		; Read BYTE
+		stosb				; Store BYTE to [ES:DI]
+	%endrep
+	loop	.ReadNextOword
+	ret
+%endif
+
+
+;--------------------------------------------------------------------
+; IdePioBlock_WriteToXtideRev1
+;	Parameters:
+;		CX:		Block size in 512-byte sectors
+;		DX:		IDE Data port address
+;		ES:SI:	Normalized ptr to buffer containing data
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, CX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+IdePioBlock_WriteToXtideRev1:
+	push	ds
+	UNROLL_SECTORS_IN_CX_TO_QWORDS
+	mov		bl, 8		; Bit mask for toggling data low/high reg
+	push	es			; Copy ES...
+	pop		ds			; ...to DS
+ALIGN JUMP_ALIGN
+.OutswLoop:
+	%rep 4	; WORDs
+		XTIDE_OUTSW
+	%endrep
+	loop	.OutswLoop
+	pop		ds
+	ret
+
+
+;--------------------------------------------------------------------
+; IdePioBlock_WriteToXtideRev2	or rev 1 with swapped A0 and A3 (chuck-mod)
+;	Parameters:
+;		CX:		Block size in 512-byte sectors
+;		DX:		IDE Data port address
+;		ES:SI:	Normalized ptr to buffer containing data
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, CX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+IdePioBlock_WriteToXtideRev2:
+	UNROLL_SECTORS_IN_CX_TO_QWORDS
+	push	ds
+	push	es			; Copy ES...
+	pop		ds			; ...to DS
+ALIGN JUMP_ALIGN
+.WriteNextQword:
+	%rep 4	; WORDs
+		XTIDE_MOD_OUTSW
+	%endrep
+	loop	.WriteNextQword
+	pop		ds
+	ret
+
+
+;--------------------------------------------------------------------
+; IdePioBlock_WriteTo8bitDataPort		XT-CF when using 8-bit PIO
+;	Parameters:
+;		CX:		Block size in 512-byte sectors
+;		DX:		IDE Data port address
+;		ES:SI:	Normalized ptr to buffer containing data
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, CX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+IdePioBlock_WriteTo8bitDataPort:
+
+%ifdef USE_186
+	shl		cx, 9		; Sectors to BYTEs
+	es					; Source is ES segment
+	rep outsb
+	ret
+
+%else ; If 8088/8086
+	UNROLL_SECTORS_IN_CX_TO_DWORDS
+	push	ds
+	push	es
+	pop		ds
+ALIGN JUMP_ALIGN
+.WriteNextDword:
+	%rep 4	; BYTEs
+		lodsb				; Load BYTE from [DS:SI]
+		out		dx, al		; Write BYTE
+	%endrep
+	loop	.WriteNextDword
+	pop		ds
+	ret
+%endif
+
+%endif ; MODULE_8BIT_IDE
+
+
+;--------------------------------------------------------------------
+; IdePioBlock_ReadFromXtideRev2			(when 80186/80188 instructions are available)
+; IdePioBlock_ReadFrom16bitDataPort		Normal 16-bit IDE
+; IdePioBlock_ReadFrom32bitDataPort		VLB/PCI 32-bit IDE
+;	Parameters:
+;		CX:		Block size in 512 byte sectors
+;		DX:		IDE Data port address
+;		ES:DI:	Normalized ptr to buffer to receive data
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, CX
+;--------------------------------------------------------------------
+%ifdef USE_186	; Also used by XTIDE rev 2 when 80186/80188 commands allowed
+ALIGN JUMP_ALIGN
+IdePioBlock_ReadFromXtideRev2:
+IdePioBlock_ReadFrom16bitDataPort:
+	xchg	cl, ch		; Sectors to WORDs
+	rep insw
+	ret
+%endif
+
+;--------------------------------------------------------------------
+%ifdef USE_AT
+ALIGN JUMP_ALIGN
+IdePioBlock_ReadFrom32bitDataPort:
+	shl		cx, 7		; Sectors to DWORDs
+	rep
+	db		66h			; Override operand size to 32-bit
+	db		6Dh			; INSW/INSD
+	ret
+%endif
+
+
+;--------------------------------------------------------------------
+; IdePioBlock_WriteTo16bitDataPort		Normal 16-bit IDE
+; IdePioBlock_WriteTo32bitDataPort		VLB/PCI 32-bit IDE
+;	Parameters:
+;		CX:		Block size in 512-byte sectors
+;		DX:		IDE Data port address
+;		ES:SI:	Normalized ptr to buffer containing data
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, CX, DX
+;--------------------------------------------------------------------
+%ifdef USE_AT
+
+ALIGN JUMP_ALIGN
+IdePioBlock_WriteTo16bitDataPort:
+	xchg	cl, ch		; Sectors to WORDs
+	es					; Source is ES segment
+	rep outsw
+	ret
+
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+IdePioBlock_WriteTo32bitDataPort:
+	shl		cx, 7		; Sectors to DWORDs
+	es					; Source is ES segment
+	rep
+	db		66h			; Override operand size to 32-bit
+	db		6Fh			; OUTSW/OUTSD
+	ret
+
+%endif ; USE_AT
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 473)
@@ -206,6 +206,8 @@
 ALIGN JUMP_ALIGN
 InitializePiovarsInSSBPwithSectorCountInAH:
-	; Store sizes
+	; Store sizes and Data Port
 	mov		[bp+PIOVARS.bSectorsLeft], ah
+	mov		ax, [di+DPT.wBasePort]
+	mov		[bp+PIOVARS.wDataPort], ax
 	eMOVZX	ax, [di+DPT_ATA.bBlockSize]
 	mov		[bp+PIOVARS.wSectorsInBlock], ax
@@ -214,10 +216,6 @@
 	; Get transfer function based on bus type
 	xchg	ax, bx								; Lookup table offset to AX
-	mov		bl, [di+DPT.bIdevarsOffset]			; CS:BX now points to IDEVARS
-	mov		dx, [cs:bx+IDEVARS.wPort]			; Load IDE Data port address
 	mov		bl, [di+DPT_ATA.bDevice]
 	add		bx, ax
-
-	mov		[bp+PIOVARS.wDataPort], dx
 	mov		ax, [cs:bx]							; Load offset to transfer function
 	mov		[bp+PIOVARS.fnXfer], ax
@@ -225,225 +223,31 @@
 
 
-;--------------------------------------------------------------------
-; ReadBlockFromXtideRev1		XTIDE rev 1
-; ReadBlockFromXtideRev2		XTIDE rev 2 or rev 1 with swapped A0 and A3 (chuck-mod)
-; ReadBlockFrom8bitDataPort		CF-XT when using 8-bit PIO
-; ReadBlockFrom16bitDataPort	Normal 16-bit IDE
-; ReadBlockFrom32bitDataPort	VLB/PCI 32-bit IDE
-;	Parameters:
-;		CX:		Block size in 512 byte sectors
-;		DX:		IDE Data port address
-;		ES:DI:	Normalized ptr to buffer to receive data
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, BX, CX
-;--------------------------------------------------------------------
-%ifdef MODULE_8BIT_IDE
-
-	ALIGN JUMP_ALIGN
-	ReadBlockFromXtideRev1:
-		UNROLL_SECTORS_IN_CX_TO_OWORDS
-		mov		bl, 8		; Bit mask for toggling data low/high reg
-	ALIGN JUMP_ALIGN
-	.InswLoop:
-	%rep 8	; WORDs
-		XTIDE_INSW
-	%endrep
-		loop	.InswLoop
-		ret
-
-	;--------------------------------------------------------------------
-	%ifndef USE_186			; 8086/8088 compatible WORD read
-		ALIGN JUMP_ALIGN
-		ReadBlockFromXtideRev2:
-			UNROLL_SECTORS_IN_CX_TO_OWORDS
-		ALIGN JUMP_ALIGN
-		.ReadNextOword:
-		%rep 8	; WORDs
-			in		ax, dx		; Read WORD
-			stosw				; Store WORD to [ES:DI]
-		%endrep
-			loop	.ReadNextOword
-			ret
-	%endif
-
-	;--------------------------------------------------------------------
-	%ifdef USE_186
-		ALIGN JUMP_ALIGN
-		ReadBlockFrom8bitDataPort:
-			shl		cx, 9		; Sectors to BYTEs
-			rep insb
-			ret
-
-	%else ; If 8088/8086
-		ALIGN JUMP_ALIGN
-		ReadBlockFrom8bitDataPort:
-			UNROLL_SECTORS_IN_CX_TO_OWORDS
-		ALIGN JUMP_ALIGN
-		.ReadNextOword:
-		%rep 16	; BYTEs
-			in		al, dx		; Read BYTE
-			stosb				; Store BYTE to [ES:DI]
-		%endrep
-			loop	.ReadNextOword
-			ret
-	%endif
-%endif	; MODULE_8BIT_IDE
-
-;--------------------------------------------------------------------
-%ifdef USE_186
-	ALIGN JUMP_ALIGN
-	ReadBlockFrom16bitDataPort:
-		xchg	cl, ch		; Sectors to WORDs
-		rep insw
-		ret
-%endif
-
-;--------------------------------------------------------------------
-%ifdef USE_AT
-	ALIGN JUMP_ALIGN
-	ReadBlockFrom32bitDataPort:
-		shl		cx, 7		; Sectors to DWORDs
-		rep
-		db		66h			; Override operand size to 32-bit
-		db		6Dh			; INSW/INSD
-		ret
-%endif
-
-
-;--------------------------------------------------------------------
-; WriteBlockToXtideRev1			XTIDE rev 1
-; WriteBlockToXtideRev2			XTIDE rev 2 or rev 1 with swapped A0 and A3 (chuck-mod)
-; WriteBlockTo8bitDataPort		XT-CF when using 8-bit PIO
-; WriteBlockTo16bitDataPort		Normal 16-bit IDE
-; WriteBlockTo32bitDataPort		VLB/PCI 32-bit IDE
-;	Parameters:
-;		CX:		Block size in 512-byte sectors
-;		DX:		IDE Data port address
-;		ES:SI:	Normalized ptr to buffer containing data
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, BX, CX, DX
-;--------------------------------------------------------------------
-%ifdef MODULE_8BIT_IDE
-
-	ALIGN JUMP_ALIGN
-	WriteBlockToXtideRev1:
-		push	ds
-		UNROLL_SECTORS_IN_CX_TO_QWORDS
-		mov		bl, 8		; Bit mask for toggling data low/high reg
-		push	es			; Copy ES...
-		pop		ds			; ...to DS
-	ALIGN JUMP_ALIGN
-	.OutswLoop:
-	%rep 4	; WORDs
-		XTIDE_OUTSW
-	%endrep
-		loop	.OutswLoop
-		pop		ds
-		ret
-
-	;--------------------------------------------------------------------
-	ALIGN JUMP_ALIGN
-	WriteBlockToXtideRev2:
-		UNROLL_SECTORS_IN_CX_TO_QWORDS
-		push	ds
-		push	es			; Copy ES...
-		pop		ds			; ...to DS
-	ALIGN JUMP_ALIGN
-	.WriteNextQword:
-	%rep 4	; WORDs
-		XTIDE_MOD_OUTSW
-	%endrep
-		loop	.WriteNextQword
-		pop		ds
-		ret
-
-	;--------------------------------------------------------------------
-	%ifdef USE_186
-		ALIGN JUMP_ALIGN
-		WriteBlockTo8bitDataPort:
-			shl		cx, 9		; Sectors to BYTEs
-			es					; Source is ES segment
-			rep outsb
-			ret
-
-	%else ; If 8088/8086
-		ALIGN JUMP_ALIGN
-		WriteBlockTo8bitDataPort:
-			UNROLL_SECTORS_IN_CX_TO_DWORDS
-			push	ds
-			push	es
-			pop		ds
-		ALIGN JUMP_ALIGN
-		.WriteNextDword:
-		%rep 4	; BYTEs
-			lodsb				; Load BYTE from [DS:SI]
-			out		dx, al		; Write BYTE
-		%endrep
-			loop	.WriteNextDword
-			pop		ds
-			ret
-	%endif
-%endif	; MODULE_8BIT_IDE
-
-;--------------------------------------------------------------------
-%ifdef USE_AT
-ALIGN JUMP_ALIGN
-WriteBlockTo16bitDataPort:
-	xchg	cl, ch		; Sectors to WORDs
-	es					; Source is ES segment
-	rep outsw
-	ret
-
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-WriteBlockTo32bitDataPort:
-	shl		cx, 7		; Sectors to DWORDs
-	es					; Source is ES segment
-	rep
-	db		66h			; Override operand size to 32-bit
-	db		6Fh			; OUTSW/OUTSD
-	ret
-%endif ; USE_AT
-
-
 
 ; Lookup tables to get transfer function based on bus type
 ALIGN WORD_ALIGN
 g_rgfnPioRead:
+%ifdef USE_AT
+		dw		IdePioBlock_ReadFrom16bitDataPort	; 0, DEVICE_16BIT_ATA
+		dw		IdePioBlock_ReadFrom32bitDataPort	; 1, DEVICE_32BIT_ATA
+%else
+		dd		0
+%endif
 %ifdef MODULE_8BIT_IDE
-		dw		0							; 0, DEVICE_8BIT_JRIDE_ISA
-		dw		ReadBlockFrom8bitDataPort	; 1, DEVICE_8BIT_XTCF
-	%ifdef USE_186
-		dw		ReadBlockFrom16bitDataPort	; 2, DEVICE_8BIT_XTIDE_REV2
-	%else
-		dw		ReadBlockFromXtideRev2		; 2, DEVICE_8BIT_XTIDE_REV2
+		dw		IdePioBlock_ReadFromXtideRev1		; 2, DEVICE_8BIT_XTIDE_REV1
+	%ifndef USE_AT
+		g_rgfnPioWrite:
 	%endif
-		dw		ReadBlockFromXtideRev1		; 3, DEVICE_XTIDE_REV1
-
-%else
-		times	COUNT_OF_8BIT_IDE_DEVICES	dw	0
-%endif
+		dw		IdePioBlock_ReadFromXtideRev2		; 3, DEVICE_8BIT_XTIDE_REV2
+		dw		IdePioBlock_ReadFrom8bitDataPort	; 4, DEVICE_8BIT_XTCF_PIO8
+%endif
+
 %ifdef USE_AT
-		dw		ReadBlockFrom16bitDataPort	; 4, DEVICE_16BIT_ATA
-		dw		ReadBlockFrom32bitDataPort	; 5, DEVICE_32BIT_ATA
-%endif
-
-
 g_rgfnPioWrite:
+		dw		IdePioBlock_WriteTo16bitDataPort	; 0, DEVICE_16BIT_ATA
+		dw		IdePioBlock_WriteTo32bitDataPort	; 1, DEVICE_32BIT_ATA
+%endif
 %ifdef MODULE_8BIT_IDE
-		dw		0							; 0, DEVICE_8BIT_JRIDE_ISA
-		dw		WriteBlockTo8bitDataPort	; 1, DEVICE_8BIT_XTCF
-		dw		WriteBlockToXtideRev2		; 2, DEVICE_XTIDE_REV2
-		dw		WriteBlockToXtideRev1		; 3, DEVICE_XTIDE_REV1
-
-%else
-		times	COUNT_OF_8BIT_IDE_DEVICES	dw	0
-%endif
-%ifdef USE_AT
-		dw		WriteBlockTo16bitDataPort	; 4, DEVICE_16BIT_ATA
-		dw		WriteBlockTo32bitDataPort	; 5, DEVICE_32BIT_ATA
-%endif
+		dw		IdePioBlock_WriteToXtideRev1		; 2, DEVICE_8BIT_XTIDE_REV1
+		dw		IdePioBlock_WriteToXtideRev2		; 3, DEVICE_8BIT_XTIDE_REV2
+		dw		IdePioBlock_WriteTo8bitDataPort		; 4, DEVICE_8BIT_XTCF_PIO8
+%endif
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm	(revision 473)
@@ -28,4 +28,6 @@
 endstruc
 
+SECTOR_ACCESS_WINDOW_SIZE	EQU		512	; 512 bytes
+
 
 ; Section containing code
@@ -37,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
+;		ES:SI:	Ptr to normalized data buffer (SI 0...15)
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
 ;		SS:BP:	Ptr to IDEPACK
@@ -49,20 +51,37 @@
 ALIGN JUMP_ALIGN
 JrIdeTransfer_StartWithCommandInAL:
-	push	cs	; We push CS here (segment of SAW) and later pop it to DS (reads) or ES (writes)
-
-	; Initialize PIOVARS
-	xor		cx, cx
-	mov		[bp+MEMPIOVARS.bSectorsDone], cl
-	mov		cl, [bp+IDEPACK.bSectorCount]
-	mov		[bp+MEMPIOVARS.bSectorsLeft], cl
-	mov		cl, [di+DPT_ATA.bBlockSize]
-	mov		[bp+MEMPIOVARS.wSectorsInBlock], cx
+	; Initialize MEMPIOVARS
+	xchg	cx, ax			; IDE command to CL
+	xor		ax, ax
+	mov		[bp+MEMPIOVARS.bSectorsDone], al
+	mov		al, [bp+IDEPACK.bSectorCount]
+	mov		[bp+MEMPIOVARS.bSectorsLeft], al
+	mov		al, [di+DPT_ATA.bBlockSize]
+	mov		[bp+MEMPIOVARS.wSectorsInBlock], ax
 	mov		[bp+MEMPIOVARS.fpDPT], di
 	mov		[bp+MEMPIOVARS.fpDPT+2], ds
 
+	; Get far pointer to Sector Access Window
+	mov		dx, [di+DPT.wBasePort]
+	cmp		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_JRIDE_ISA
+	jne		SHORT .GetSectorAccessWindowForXTCF
+
+	; Get Sector Access Window for JR-IDE/ISA
+	mov		di, JRIDE_SECTOR_ACCESS_WINDOW_OFFSET
+	mov		ds, dx		; Segment for JR-IDE/ISA
+	jmp		SHORT .SectorAccessWindowLoadedToDSDI
+
+.GetSectorAccessWindowForXTCF:
+	xor		di, di
+	add		dl, XTCF_CONTROL_REGISTER
+	in		al, dx					; Read high byte for Sector Access Window segment
+	xchg	ah, al
+	mov		ds, ax
+
 	; Are we reading or writing?
-	test	al, 16	; Bit 4 is cleared on all the read commands but set on 3 of the 4 write commands
+.SectorAccessWindowLoadedToDSDI:
+	test	cl, 16	; Bit 4 is cleared on all the read commands but set on 3 of the 4 write commands
 	jnz		SHORT WriteToSectorAccessWindow
-	cmp		al, COMMAND_WRITE_MULTIPLE
+	cmp		cl, COMMAND_WRITE_MULTIPLE
 	je		SHORT WriteToSectorAccessWindow
 	; Fall to ReadFromSectorAccessWindow
@@ -71,5 +90,5 @@
 ; ReadFromSectorAccessWindow
 ;	Parameters:
-;		Stack:	Segment part of ptr to Sector Access Window
+;		DS:DI:	Ptr to Sector Access Window
 ;		ES:SI:	Normalized ptr to buffer to receive data
 ;		SS:BP:	Ptr to MEMPIOVARS
@@ -84,8 +103,5 @@
 ;--------------------------------------------------------------------
 ReadFromSectorAccessWindow:
-	pop		ds		; CS -> DS
-	mov		di, si	; ES:DI = destination
-	mov		si, JRIDE_SECTOR_ACCESS_WINDOW_OFFSET	; DS:SI = source
-
+	xchg	si, di	; DS:SI = source, ES:DI = Destination
 	call	WaitUntilReadyToTransferNextBlock
 	jc		SHORT ReturnWithMemoryIOtransferErrorInAH
@@ -140,5 +156,5 @@
 ; WriteToSectorAccessWindow
 ;	Parameters:
-;		Stack:	Segment part of ptr to Sector Access Window
+;		DS:DI:	Ptr to Sector Access Window
 ;		ES:SI:	Normalized ptr to buffer containing data
 ;		SS:BP:	Ptr to MEMPIOVARS
@@ -155,7 +171,7 @@
 WriteToSectorAccessWindow:
 	push	es
-	pop		ds
-	pop		es	; CS -> ES
-	mov		di, JRIDE_SECTOR_ACCESS_WINDOW_OFFSET
+	push	ds
+	pop		es		; ES:DI = Sector Access Window (destination)
+	pop		ds		; DS:SI = Ptr to source buffer
 
 	; Always poll when writing first block (IRQs are generated for following blocks)
@@ -205,5 +221,5 @@
 ALIGN JUMP_ALIGN
 .WriteBlock:
-	mov		ch, JRIDE_SECTOR_ACCESS_WINDOW_SIZE >> 9
+	mov		ch, SECTOR_ACCESS_WINDOW_SIZE >> 9
 	rep movsw
 	mov		di, bx	; Reset for next sector
@@ -232,5 +248,5 @@
 ALIGN JUMP_ALIGN
 .ReadBlock:
-	mov		ch, JRIDE_SECTOR_ACCESS_WINDOW_SIZE >> 9
+	mov		ch, SECTOR_ACCESS_WINDOW_SIZE >> 9
 	rep movsw
 	mov		si, bx	; Reset for next sector
@@ -261,5 +277,5 @@
 
 
-%if JRIDE_SECTOR_ACCESS_WINDOW_SIZE <> 512
-	%error "JRIDE_SECTOR_ACCESS_WINDOW_SIZE is no longer equal to 512. JrIdeTransfer.asm needs changes."
+%if SECTOR_ACCESS_WINDOW_SIZE <> 512
+	%error "SECTOR_ACCESS_WINDOW_SIZE is no longer equal to 512. JrIdeTransfer.asm needs changes."
 %endif
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 473)
@@ -38,18 +38,17 @@
 ;--------------------------------------------------------------------
 AH1Eh_HandlerForXTCFfeatures:
-	xor		ah, ah		; Subcommand now in AX
 %ifndef USE_186
-	call	AH1Eh_ProcessXTCFsubcommandFromAX
+	call	AH1Eh_ProcessXTCFsubcommandFromAL
 	jmp		Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
 %else
 	push	Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
-	; Fall to AH1Eh_ProcessXTCFsubcommandFromAX
+	; Fall to AH1Eh_ProcessXTCFsubcommandFromAL
 %endif
 
 
 ;--------------------------------------------------------------------
-; AH1Eh_ProcessXTCFsubcommandFromAX
+; AH1Eh_ProcessXTCFsubcommandFromAL
 ;	Parameters:
-;		AX:		XT-CF subcommand (see XTCF.inc for more info)
+;		AL:		XT-CF subcommand (see XTCF.inc for more info)
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
 ;		SS:BP:	Ptr to IDEPACK
@@ -58,30 +57,67 @@
 ;		CF:		0 if successful, 1 if error
 ;	Corrupts registers:
-;		AL, BX, CX, DX
+;		AL, BX, CX, DX, SI
 ;--------------------------------------------------------------------
-AH1Eh_ProcessXTCFsubcommandFromAX:
+AH1Eh_ProcessXTCFsubcommandFromAL:
 	; IS_THIS_DRIVE_XTCF. We check this for all commands.
-	dec		ax		; Subcommand
-	mov		dx, [di+DPT.wXTCFport]
-	test	dx, dx	; Never zero for XT-CF, Always zero for other devices
-	jz		SHORT XTCFnotFound
+	call	AccessDPT_IsThisDeviceXTCF
+	jne		SHORT XTCFnotFound
+	and		ax, BYTE 7Fh				; Subcommand now in AX
+	jz		SHORT .ReturnWithSuccess	; IS_THIS_DRIVE_XTCF
 
 	; READ_XTCF_CONTROL_REGISTER_TO_DH
-	add		dl, XTCF_CONTROL_REGISTER	; DX to Control Register
-	dec		ax		; Subcommand
+	dec		ax							; Subcommand
 	jnz		SHORT .SkipReadXtcfControlRegisterToDH
+	mov		dx, [di+DPT.wBasePort]
+	add		dl, XTCF_CONTROL_REGISTER
 	in		al, dx
 	mov		[bp+IDEPACK.intpack+INTPACK.dh], al
-	jmp		SHORT .ReturnWithSuccess
+.ReturnWithSuccess:
+	xor		ah, ah
+	ret
 .SkipReadXtcfControlRegisterToDH:
 
 	; WRITE_DH_TO_XTCF_CONTROL_REGISTER
-	dec		ax		; Subcommand
+	dec		ax							; Subcommand
 	jnz		SHORT XTCFnotFound			; Invalid subcommand
 	mov		al, [bp+IDEPACK.intpack+INTPACK.dh]
+	; Fall to AH1Eh_ChangeXTCFmodeBasedOnControlRegisterInAL
+
+
+;--------------------------------------------------------------------
+; AH1Eh_ChangeXTCFmodeBasedOnControlRegisterInAL
+;	Parameters:
+;		AL:		XT-CF Control Register
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;		SS:BP:	Ptr to IDEPACK
+;	Returns:
+;		AH:		Int 13h return status
+;		CF:		0 if successful, 1 if error
+;	Corrupts registers:
+;		AL, BX, CX, DX, SI
+;--------------------------------------------------------------------
+AH1Eh_ChangeXTCFmodeBasedOnControlRegisterInAL:
+	; Output Control Register
+	mov		dx, [di+DPT.wBasePort]
+	add		dl, XTCF_CONTROL_REGISTER
 	out		dx, al
-.ReturnWithSuccess:
-	xor		ah, ah
-	ret
+
+	; Convert Control Register Contents to device code
+	test	al, al
+	jz		SHORT .Set8bitPioMode
+	cmp		al, XTCF_MEMORY_MAPPED_MODE
+	jae		SHORT .SetMemoryMappedMode
+
+	; Set DMA Mode
+	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_DMA
+	jmp		AH23h_Disable8bitPioMode
+
+.SetMemoryMappedMode:
+	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_MEMMAP
+	jmp		AH23h_Disable8bitPioMode
+
+.Set8bitPioMode:
+	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_PIO8
+	jmp		AH23h_Enable8bitPioMode
 
 
@@ -96,7 +132,8 @@
 ;				Set if XT-CF not found
 ;	Corrupts registers:
-;		AL, DX
+;		AL
 ;--------------------------------------------------------------------
 AH1Eh_DetectXTCFwithBasePortInDX:
+	push	dx
 	add		dl, XTCT_CONTROL_REGISTER_INVERTED_in	; set DX to XT-CF config register (inverted)
 	in		al, dx		; get value
@@ -104,9 +141,11 @@
 	inc		dx			; set DX to XT-CF config register (non-inverted)
 	in		al, dx		; get value
-	not		al			; invert it
+	not		al			; invert value
+	pop		dx
 	sub		ah, al		; do they match? (clear AH if they do)
 	jz		SHORT XTCFfound
 
 XTCFnotFound:
+AH1Eh_LoadInvalidCommandToAHandSetCF:
 	stc					; set carry flag since XT-CF not found
 	mov		ah, RET_HD_INVALID
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm	(revision 473)
@@ -74,2 +74,24 @@
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
 	jmp		Idepack_StoreNonExtParametersAndIssueCommandFromAL
+
+
+%ifdef MODULE_8BIT_IDE
+;--------------------------------------------------------------------
+; AH23h_Enable8bitPioMode
+; AH23h_Disable8bitPioMode
+;	Parameters:
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;		SS:BP:	Ptr to IDEPACK
+;	Returns:
+;		AH:		Int 13h return status
+;		CF:		0 if successful, 1 if error
+;	Corrupts registers:
+;		AL, BX, CX, DX, SI
+;--------------------------------------------------------------------
+AH23h_Enable8bitPioMode:
+	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/AH24h_HSetBlocks.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH24h_HSetBlocks.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH24h_HSetBlocks.asm	(revision 473)
@@ -59,4 +59,14 @@
 ;--------------------------------------------------------------------
 AH24h_SetBlockSize:
+	; XT-CF does not support largest block size in DMA mode.
+%ifdef MODULE_8BIT_IDE
+	call	AccessDPT_IsThisDeviceXTCF
+	cmp		ah, DEVICE_8BIT_XTCF_DMA
+	jne		SHORT .NoNeedToLimitBlockSize
+	cmp		al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
+	ja		SHORT AH1Eh_LoadInvalidCommandToAHandSetCF
+.NoNeedToLimitBlockSize:
+%endif ; MODULE_8BIT_IDE
+
 	push	bx
 
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm	(revision 473)
@@ -104,4 +104,17 @@
 	jmp		.ReturnWithErrorCodeInAH
 .ContinueInitializationSinceDriveSelectedSuccesfully:
+
+
+;;; Set XT-CF mode
+%ifdef MODULE_8BIT_IDE
+	call	AccessDPT_IsThisDeviceXTCF
+	jne		SHORT .DoNotSetXTCFmode
+
+	call	AccessDPT_GetIdevarsToCSBX
+	mov		al, [cs:bx+IDEVARS.bXTCFcontrolRegister]
+	call	AH1Eh_ChangeXTCFmodeBasedOnControlRegisterInAL
+	STORE_ERROR_FLAG_TO_DPT		FLG_INITERROR_FAILED_TO_SET_XTCF_MODE
+.DoNotSetXTCFmode:
+%endif
 
 
@@ -125,11 +138,4 @@
 	STORE_ERROR_FLAG_TO_DPT		FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS
 .SkipInitializeDeviceParameters:
-
-
-%ifdef MODULE_8BIT_IDE
-;;; Enable 8-bit PIO Transfer Mode for Lo-tech XT-CF (CF and Microdrives only)
-	call	AH9h_Enable8bitPioModeForXTCF
-	STORE_ERROR_FLAG_TO_DPT		FLG_INITERROR_FAILED_TO_ENABLE_8BIT_PIO_MODE
-%endif
 
 
@@ -244,5 +250,4 @@
 ;		Nothing
 ;--------------------------------------------------------------------
-DoNotEnable8bitMode:
 IgnoreInvalidCommandError:
 	xor		ah, ah	; Clears CF
@@ -256,24 +261,2 @@
 .NoErrorFlagToSet:
 	ret
-
-
-%ifdef MODULE_8BIT_IDE
-;--------------------------------------------------------------------
-; AH9h_Enable8bitPioModeForXTCF
-;	Parameters:
-;		DS:DI:	Ptr to DPT
-;		SS:BP:	Ptr to IDEPACK
-;	Returns:
-;		AH:		Int 13h return status
-;		CF:		0 if successful, 1 if error
-;	Corrupts registers:
-;		AL, BX, CX, DX, SI
-;--------------------------------------------------------------------
-AH9h_Enable8bitPioModeForXTCF:
-	eMOVZX	bx, [di+DPT.bIdevarsOffset]
-	cmp		BYTE [cs:bx+IDEVARS.bDevice], DEVICE_8BIT_XTCF
-	jne		SHORT DoNotEnable8bitMode
-
-	mov		si, FEATURE_ENABLE_8BIT_PIO_TRANSFER_MODE
-	jmp		AH23h_SetControllerFeatures
-%endif ; MODULE_8BIT_IDE
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm	(revision 473)
@@ -70,5 +70,6 @@
 
 	; Initialize Master and Slave drives
-	eMOVZX	ax, [di+DPT.bIdevarsOffset]			; (AL) pointer to controller we are looking to reset
+	call	AccessDPT_GetIdevarsToCSBX
+	xchg	ax, bx								; (AL) pointer to controller we are looking to reset
 												; (AH) initialize error code, assume success
 
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/Vision.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/Vision.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/Vision.asm	(revision 473)
@@ -179,5 +179,5 @@
 	; QD6500 has only one channel that can be Primary at 1F0h or Secondary at 170h.
 	; QD6580 always has Primary channel at 1F0h. Secondary channel at 170h can be Enabled or Disabled.
-	call	AccessDPT_GetIdeBasePortToBX
+	mov		bx, [di+DPT.wBasePort]
 	cmp		bx, DEVICE_ATA_PRIMARY_PORT
 	je		SHORT .CalculateTimingTicksForQD6580	; Primary Channel so no need to modify DX
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 473)
@@ -150,5 +150,5 @@
 ;       None
 ;	Corrupts registers:
-;		AX, BX, CX, DX, SI, DI
+;		AX, BL, CX, DX, SI, DI
 ;--------------------------------------------------------------------
 StartDetectionWithDriveSelectByteInBHandStringInCX:
@@ -157,5 +157,38 @@
 	call	HotkeyBar_UpdateDuringDriveDetection
 %endif
+	; Fall to .AutodetectXTCFport or .ReadAtaInfoFromHardDisk
+
+
+%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 we can safely update port
+	; for next drive (another XT-CF card on same system)
+.DetectNextPort:
+	call	BootVars_GetNextXTCFportToDetectToDX
+	cmp		dx, XTCF_BASE_PORT_4
+	ja		SHORT DetectDrives_DriveNotFound	; XT-CF not found from any port
+
+	call	AH1Eh_DetectXTCFwithBasePortInDX
+	jc		SHORT .DetectNextPort				; XT-CF not found from this port
+.SkipXTCFportDetection:
 	; Fall to .ReadAtaInfoFromHardDisk
+%endif ; MODULE_8BIT_IDE
+
 
 ;--------------------------------------------------------------------
@@ -163,4 +196,5 @@
 ;	Parameters:
 ;		BH:		Drive Select byte for Drive and Head Register
+;		DX:		Autodetected port (for devices that support autodetection)
 ;		CS:BP:	Ptr to IDEVARS for the drive
 ;		DS:		RAMVARS segment
@@ -176,7 +210,9 @@
 	push	es
 	push	si
+	push	dx
 	push	bx
 	call	Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
 	pop		bx
+	pop		dx
 	pop		si
 	pop		es
@@ -208,4 +244,5 @@
 ;	Parameters:
 ;		BH:		Drive Select byte for Drive and Head Register
+;		DX:		Autodetected port (for devices that support autodetection)
 ;		CS:BP:	Ptr to IDEVARS for the drive
 ;		ES:SI	Ptr to ATA information for the drive
@@ -226,2 +263,25 @@
 	call	DriveDetectInfo_CreateForHardDisk
 	jmp		SHORT DetectPrint_DriveNameFromDrvDetectInfoInESBX
+
+
+%ifdef MODULE_8BIT_IDE
+;--------------------------------------------------------------------
+; DetectDrives_DoesIdevarsInCSBPbelongToXTCF
+;	Parameters:
+;		CS:BP:	Ptr to IDEVARS for the drive
+;	Returns:
+;		ZF:		Set if IDEVARS belongs to XT-CF device
+;				Cleared if some other device
+;	Corrupts registers:
+;		AL
+;--------------------------------------------------------------------
+DetectDrives_DoesIdevarsInCSBPbelongToXTCF:
+	mov		al, [cs:bp+IDEVARS.bDevice]
+	cmp		al, DEVICE_8BIT_XTCF_PIO8
+	je		SHORT .DeviceIsXTCF
+	cmp		al, DEVICE_8BIT_XTCF_DMA
+	je		SHORT .DeviceIsXTCF
+	cmp		al, DEVICE_8BIT_XTCF_MEMMAP
+.DeviceIsXTCF:
+	ret
+%endif ; MODULE_8BIT_IDE
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm	(revision 473)
@@ -79,14 +79,10 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, SI, DI, CX
+;		AX, SI, DI, CX, DX
 ;--------------------------------------------------------------------
 DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP:
-	mov		ax, [cs:bp+IDEVARS.wPort]    	; for IDE: AX=port address, DH=.bDevice
+	mov		ax, [cs:bp+IDEVARS.wBasePort]   ; for IDE: AX=port address, DH=.bDevice
 	mov		dx, [cs:bp+IDEVARS.bDevice-1]   ; for Serial: AL=port address>>2, AH=baud rate
 											;			  DL=COM number character, DH=.bDevice
-%ifdef MODULE_JRIDE
-	cmp		dh, DEVICE_8BIT_JRIDE_ISA
-	eCMOVE	ax, cs							; Use segment address for JR-IDE/ISA
-%endif
 
 	push	bp								; setup stack for call to
Index: /trunk/XTIDE_Universal_BIOS/Src/Main.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 473)
@@ -88,29 +88,31 @@
 	at	ROMVARS.bIdleTimeout,	db	0						; Standby timer disabled by default
 
-	at	ROMVARS.ideVars0+IDEVARS.wPort,			dw	DEVICE_ATA_PRIMARY_PORT 		; Controller Command Block base port
-	at	ROMVARS.ideVars0+IDEVARS.wPortCtrl,		dw	DEVICE_ATA_PRIMARY_PORTCTRL 	; Controller Control Block base port
-	at	ROMVARS.ideVars0+IDEVARS.bDevice,		db	DEVICE_16BIT_ATA
-	at	ROMVARS.ideVars0+IDEVARS.bIRQ,			db	0
+	at	ROMVARS.ideVars0+IDEVARS.wBasePort,			dw	DEVICE_ATA_PRIMARY_PORT 		; Controller Command Block base port
+	at	ROMVARS.ideVars0+IDEVARS.wControlBlockPort,	dw	DEVICE_ATA_PRIMARY_PORTCTRL 	; Controller Control Block base port
+	at	ROMVARS.ideVars0+IDEVARS.bDevice,			db	DEVICE_16BIT_ATA
+	at	ROMVARS.ideVars0+IDEVARS.bIRQ,				db	0
 	at	ROMVARS.ideVars0+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	dw	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 	at	ROMVARS.ideVars0+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	dw	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 
-	at	ROMVARS.ideVars1+IDEVARS.wPort,			dw	DEVICE_ATA_SECONDARY_PORT
-	at	ROMVARS.ideVars1+IDEVARS.wPortCtrl,		dw	DEVICE_ATA_SECONDARY_PORTCTRL
-	at	ROMVARS.ideVars1+IDEVARS.bDevice,		db	DEVICE_16BIT_ATA
-	at	ROMVARS.ideVars1+IDEVARS.bIRQ,			db	0
+	at	ROMVARS.ideVars1+IDEVARS.bXTCFcontrolRegister,	db	0
+	at	ROMVARS.ideVars1+IDEVARS.bDevice,				db	DEVICE_8BIT_XTCF_PIO8
+	;at	ROMVARS.ideVars1+IDEVARS.wBasePort,		dw	DEVICE_ATA_SECONDARY_PORT
+	;at	ROMVARS.ideVars1+IDEVARS.wControlBlockPort,		dw	DEVICE_ATA_SECONDARY_PORTCTRL
+	;at	ROMVARS.ideVars1+IDEVARS.bDevice,		db	DEVICE_16BIT_ATA
+	;at	ROMVARS.ideVars1+IDEVARS.bIRQ,			db	0
 	at	ROMVARS.ideVars1+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	dw	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 	at	ROMVARS.ideVars1+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	dw	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 
-	at	ROMVARS.ideVars2+IDEVARS.wPort,			dw	DEVICE_ATA_TERTIARY_PORT
-	at	ROMVARS.ideVars2+IDEVARS.wPortCtrl,		dw	DEVICE_ATA_TERTIARY_PORTCTRL
-	at	ROMVARS.ideVars2+IDEVARS.bDevice,		db	DEVICE_16BIT_ATA
-	at	ROMVARS.ideVars2+IDEVARS.bIRQ,			db	0
+	at	ROMVARS.ideVars2+IDEVARS.wBasePort,			dw	DEVICE_ATA_TERTIARY_PORT
+	at	ROMVARS.ideVars2+IDEVARS.wControlBlockPort,	dw	DEVICE_ATA_TERTIARY_PORTCTRL
+	at	ROMVARS.ideVars2+IDEVARS.bDevice,			db	DEVICE_16BIT_ATA
+	at	ROMVARS.ideVars2+IDEVARS.bIRQ,				db	0
 	at	ROMVARS.ideVars2+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	dw	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 	at	ROMVARS.ideVars2+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	dw	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 
-	at	ROMVARS.ideVars3+IDEVARS.wPort,			dw	DEVICE_ATA_QUATERNARY_PORT
-	at	ROMVARS.ideVars3+IDEVARS.wPortCtrl,		dw	DEVICE_ATA_QUATERNARY_PORTCTRL
-	at	ROMVARS.ideVars3+IDEVARS.bDevice,		db	DEVICE_16BIT_ATA
-	at	ROMVARS.ideVars3+IDEVARS.bIRQ,			db	0
+	at	ROMVARS.ideVars3+IDEVARS.wBasePort,			dw	DEVICE_ATA_QUATERNARY_PORT
+	at	ROMVARS.ideVars3+IDEVARS.wControlBlockPort,	dw	DEVICE_ATA_QUATERNARY_PORTCTRL
+	at	ROMVARS.ideVars3+IDEVARS.bDevice,			db	DEVICE_16BIT_ATA
+	at	ROMVARS.ideVars3+IDEVARS.bIRQ,				db	0
 	at	ROMVARS.ideVars3+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	dw	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 	at	ROMVARS.ideVars3+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	dw	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
@@ -128,5 +130,5 @@
 		at	ROMVARS.wBootTimeout,	dw	BOOT_MENU_DEFAULT_TIMEOUT
 %endif
-	at	ROMVARS.bIdeCnt,		db	1						; Number of supported controllers
+	at	ROMVARS.bIdeCnt,		db	2						; Number of supported controllers
 	at	ROMVARS.bBootDrv,		db	80h						; Boot Menu default drive
 	at	ROMVARS.bMinFddCnt, 	db	0						; Do not force minimum number of floppy drives
@@ -134,10 +136,12 @@
 	at	ROMVARS.bIdleTimeout,	db	0						; Standby timer disabled by default
 
-	at	ROMVARS.ideVars0+IDEVARS.wPort,			dw	DEVICE_XTIDE_DEFAULT_PORT			; Controller Command Block base port
-	at	ROMVARS.ideVars0+IDEVARS.wPortCtrl,		dw	DEVICE_XTIDE_DEFAULT_PORTCTRL		; Controller Control Block base port
-	at	ROMVARS.ideVars0+IDEVARS.bDevice,		db	DEVICE_8BIT_XTIDE_REV1
+	at	ROMVARS.ideVars0+IDEVARS.wBasePort,			dw	DEVICE_XTIDE_DEFAULT_PORT			; Controller Command Block base port
+	at	ROMVARS.ideVars0+IDEVARS.wControlBlockPort,	dw	DEVICE_XTIDE_DEFAULT_PORTCTRL		; Controller Control Block base port
+	at	ROMVARS.ideVars0+IDEVARS.bDevice,			db	DEVICE_8BIT_XTIDE_REV1
 	at	ROMVARS.ideVars0+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 	at	ROMVARS.ideVars0+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 
+	at	ROMVARS.ideVars1+IDEVARS.bXTCFcontrolRegister,	db	0
+	at	ROMVARS.ideVars1+IDEVARS.bDevice,				db	DEVICE_8BIT_XTCF_PIO8
 	at	ROMVARS.ideVars1+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 	at	ROMVARS.ideVars1+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
@@ -223,8 +227,9 @@
 %endif
 	%include "IdeCommand.asm"
-%ifdef MODULE_JRIDE
+%ifdef MODULE_8BIT_IDE
 	%include "JrIdeTransfer.asm"	; Must be included after IdeCommand.asm
 %endif
 	%include "IdeTransfer.asm"
+	%include "IdePioBlock.asm"
 	%include "IdeWait.asm"
 	%include "IdeError.asm"			; Must be included after IdeWait.asm
Index: /trunk/XTIDE_Universal_BIOS/Src/Menus/BootMenu/BootMenuPrintCfg.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Menus/BootMenu/BootMenuPrintCfg.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Menus/BootMenu/BootMenuPrintCfg.asm	(revision 473)
@@ -88,5 +88,5 @@
 
 ;--------------------------------------------------------------------
-; PushBusType
+; PushDeviceType
 ;	Parameters:
 ;		DS:DI:	Ptr to DPT
@@ -97,11 +97,18 @@
 ;		AX, DX
 ;--------------------------------------------------------------------
-.PushBusType:
-	mov		al,g_szBusTypeValues_Displacement
-	mul		BYTE [cs:bx+IDEVARS.bDevice]
+.PushDeviceType:
+	mov		al,g_szDeviceTypeValues_Displacement
+%ifdef MODULE_SERIAL
+	mov		ah, [cs:bx+IDEVARS.bDevice]
+	test	BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
+	eCMOVZ	ah, [di+DPT_ATA.bDevice]	; DPT_ATA contains up to date device information for IDE drives
+	mul		ah
+%else	
+	mul		BYTE [di+DPT_ATA.bDevice]
+%endif
 
 	shr		ax,1			; divide by 2 since IDEVARS.bDevice is multiplied by 2
 
-	add		ax,g_szBusTypeValues
+	add		ax, g_szDeviceTypeValues
 	push	ax
 
Index: /trunk/XTIDE_Universal_BIOS/Src/Strings.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Strings.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/Strings.asm	(revision 473)
@@ -117,38 +117,46 @@
 %endif
 
-g_szBusTypeValues:
-g_szBusTypeValues_8JrIde:		db		"M8 ",NULL
-g_szBusTypeValues_8Fast:		db		"F8 ",NULL
-g_szBusTypeValues_8Reversed:	db		"X8 ",NULL
-g_szBusTypeValues_8Dual:		db		"D8 ",NULL
-g_szBusTypeValues_16:			db		" 16",NULL
-g_szBusTypeValues_32:			db		" 32",NULL
-g_szBusTypeValues_Serial:		db		"SER",NULL
-
-g_szBusTypeValues_Displacement equ (g_szBusTypeValues_8Fast - g_szBusTypeValues)
-;
-; Ensure that bus type strings are correctly spaced in memory
-;
-%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
-	%if g_szBusTypeValues_8JrIde <> g_szBusTypeValues
-		%error "g_szBusTypeValues Displacement Incorrect 1"
-	%endif
-	%if g_szBusTypeValues_8Fast <> g_szBusTypeValues + g_szBusTypeValues_Displacement
-		%error "g_szBusTypeValues Displacement Incorrect 2"
-	%endif
-	%if g_szBusTypeValues_8Reversed <> g_szBusTypeValues_8Fast + g_szBusTypeValues_Displacement
-		%error "g_szBusTypeValues Displacement Incorrect 3"
-	%endif
-	%if g_szBusTypeValues_8Dual <> g_szBusTypeValues_8Reversed + g_szBusTypeValues_Displacement
-		%error "g_szBusTypeValues Displacement Incorrect 4"
-	%endif
-	%if g_szBusTypeValues_16 <> g_szBusTypeValues_8Dual + g_szBusTypeValues_Displacement
-		%error "g_szBusTypeValues Displacement Incorrect 5"
-	%endif
-	%if g_szBusTypeValues_32 <> g_szBusTypeValues_16 + g_szBusTypeValues_Displacement
-		%error "g_szBusTypeValues Displacement Incorrect 6"
-	%endif
-	%if g_szBusTypeValues_Serial <> g_szBusTypeValues_32 + g_szBusTypeValues_Displacement
-		%error "g_szBusTypeValues Displacement Incorrect 7"
+g_szDeviceTypeValues:
+g_szDeviceTypeValues_16bit:		db		" 16",NULL
+g_szDeviceTypeValues_32bit:		db		" 32",NULL
+g_szDeviceTypeValues_XTIDEr1:	db		"D8 ",NULL	; Dual 8-bit
+g_szDeviceTypeValues_XTIDEr2:	db		"X8 ",NULL	; A0<->A3 swapped 8-bit
+g_szDeviceTypeValues_XTCFpio8:	db		"T8 ",NULL	; True 8-bit
+g_szDeviceTypeValues_XTCFdma:	db		"8MA",NULL	; DMA 8-bit
+g_szDeviceTypeValues_XTCFmem:	db		"M8 ",NULL	; Memory Mapped 8-bit
+g_szDeviceTypeValues_JrIde:		db		"M8 ",NULL
+g_szDeviceTypeValues_Serial:	db		"SER",NULL
+
+g_szDeviceTypeValues_Displacement equ (g_szDeviceTypeValues_32bit - g_szDeviceTypeValues)
+;
+; Ensure that device type strings are correctly spaced in memory
+;
+%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
+	%if g_szDeviceTypeValues_16bit <> g_szDeviceTypeValues
+		%error "g_szDeviceTypeValues Displacement Incorrect 1"
+	%endif
+	%if g_szDeviceTypeValues_32bit <> g_szDeviceTypeValues + g_szDeviceTypeValues_Displacement
+		%error "g_szDeviceTypeValues Displacement Incorrect 2"
+	%endif
+	%if g_szDeviceTypeValues_XTIDEr1 <> g_szDeviceTypeValues_32bit + g_szDeviceTypeValues_Displacement
+		%error "g_szDeviceTypeValues Displacement Incorrect 3"
+	%endif
+	%if g_szDeviceTypeValues_XTIDEr2 <> g_szDeviceTypeValues_XTIDEr1 + g_szDeviceTypeValues_Displacement
+		%error "g_szDeviceTypeValues Displacement Incorrect 4"
+	%endif
+	%if g_szDeviceTypeValues_XTCFpio8 <> g_szDeviceTypeValues_XTIDEr2 + g_szDeviceTypeValues_Displacement
+		%error "g_szDeviceTypeValues Displacement Incorrect 5"
+	%endif
+	%if g_szDeviceTypeValues_XTCFdma <> g_szDeviceTypeValues_XTCFpio8 + g_szDeviceTypeValues_Displacement
+		%error "g_szDeviceTypeValues Displacement Incorrect 6"
+	%endif
+	%if g_szDeviceTypeValues_XTCFmem <> g_szDeviceTypeValues_XTCFdma + g_szDeviceTypeValues_Displacement
+		%error "g_szDeviceTypeValues Displacement Incorrect 7"
+	%endif
+	%if g_szDeviceTypeValues_JrIde <> g_szDeviceTypeValues_XTCFmem + g_szDeviceTypeValues_Displacement
+		%error "g_szDeviceTypeValues Displacement Incorrect 8"
+	%endif
+	%if g_szDeviceTypeValues_Serial <> g_szDeviceTypeValues_JrIde + g_szDeviceTypeValues_Displacement
+		%error "g_szDeviceTypeValues Displacement Incorrect 9"
 	%endif
 %endif
Index: /trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm	(revision 473)
@@ -217,59 +217,73 @@
 %endif
 
-g_szBusTypeValues:
-g_szBusTypeValues_8JrIde:		; db		"M8 ",NULL
-                         		; db		 4dh,  38h,  20h,  00h    ; uncompressed
-                         		  db		 53h,  31h,  00h          ; compressed
-
-g_szBusTypeValues_8Fast:		; db		"F8 ",NULL
-                        		; db		 46h,  38h,  20h,  00h    ; uncompressed
-                        		  db		 4ch,  31h,  00h          ; compressed
-
-g_szBusTypeValues_8Reversed:	; db		"X8 ",NULL
-                            	; db		 58h,  38h,  20h,  00h    ; uncompressed
-                            	  db		 5eh,  31h,  00h          ; compressed
-
-g_szBusTypeValues_8Dual:		; db		"D8 ",NULL
-                        		; db		 44h,  38h,  20h,  00h    ; uncompressed
-                        		  db		 4ah,  31h,  00h          ; compressed
-
-g_szBusTypeValues_16:			; db		" 16",NULL
-                     			; db		 20h,  31h,  36h,  00h    ; uncompressed
-                     			  db		 20h,  2bh,  10h          ; compressed
-
-g_szBusTypeValues_32:			; db		" 32",NULL
-                     			; db		 20h,  33h,  32h,  00h    ; uncompressed
-                     			  db		 20h,  2dh,  0ch          ; compressed
-
-g_szBusTypeValues_Serial:		; db		"SER",NULL
-                         		; db		 53h,  45h,  52h,  00h    ; uncompressed
-                         		  db		 59h,  4bh,  98h          ; compressed
-
-
-g_szBusTypeValues_Displacement equ (g_szBusTypeValues_8Fast - g_szBusTypeValues)
-;
-; Ensure that bus type strings are correctly spaced in memory
+g_szDeviceTypeValues:
+g_szDeviceTypeValues_16bit:		; db		" 16",NULL
+                           		; db		 20h,  31h,  36h,  00h    ; uncompressed
+                           		  db		 20h,  2bh,  10h          ; compressed
+
+g_szDeviceTypeValues_32bit:		; db		" 32",NULL
+                           		; db		 20h,  33h,  32h,  00h    ; uncompressed
+                           		  db		 20h,  2dh,  0ch          ; compressed
+
+g_szDeviceTypeValues_XTIDEr1:	; db		"D8 ",NULL	; Dual 8-bit
+                             	; db		 44h,  38h,  20h,  00h    ; uncompressed
+                             	  db		 4ah,  31h,  00h          ; compressed
+
+g_szDeviceTypeValues_XTIDEr2:	; db		"X8 ",NULL	; A0<->A3 swapped 8-bit
+                             	; db		 58h,  38h,  20h,  00h    ; uncompressed
+                             	  db		 5eh,  31h,  00h          ; compressed
+
+g_szDeviceTypeValues_XTCFpio8:	; db		"T8 ",NULL	; True 8-bit
+                              	; db		 54h,  38h,  20h,  00h    ; uncompressed
+                              	  db		 5ah,  31h,  00h          ; compressed
+
+g_szDeviceTypeValues_XTCFdma:	; db		"8MA",NULL	; DMA 8-bit
+                             	; db		 38h,  4dh,  41h,  00h    ; uncompressed
+                             	  db		 31h,  53h,  87h          ; compressed
+
+g_szDeviceTypeValues_XTCFmem:	; db		"M8 ",NULL	; Memory Mapped 8-bit
+                             	; db		 4dh,  38h,  20h,  00h    ; uncompressed
+                             	  db		 53h,  31h,  00h          ; compressed
+
+g_szDeviceTypeValues_JrIde:		; db		"M8 ",NULL
+                           		; db		 4dh,  38h,  20h,  00h    ; uncompressed
+                           		  db		 53h,  31h,  00h          ; compressed
+
+g_szDeviceTypeValues_Serial:	; db		"SER",NULL
+                            	; db		 53h,  45h,  52h,  00h    ; uncompressed
+                            	  db		 59h,  4bh,  98h          ; compressed
+
+
+g_szDeviceTypeValues_Displacement equ (g_szDeviceTypeValues_32bit - g_szDeviceTypeValues)
+;
+; Ensure that device type strings are correctly spaced in memory
 ;
 %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
-%if g_szBusTypeValues_8JrIde <> g_szBusTypeValues
-%error "g_szBusTypeValues Displacement Incorrect 1"
-%endif
-%if g_szBusTypeValues_8Fast <> g_szBusTypeValues + g_szBusTypeValues_Displacement
-%error "g_szBusTypeValues Displacement Incorrect 2"
-%endif
-%if g_szBusTypeValues_8Reversed <> g_szBusTypeValues_8Fast + g_szBusTypeValues_Displacement
-%error "g_szBusTypeValues Displacement Incorrect 3"
-%endif
-%if g_szBusTypeValues_8Dual <> g_szBusTypeValues_8Reversed + g_szBusTypeValues_Displacement
-%error "g_szBusTypeValues Displacement Incorrect 4"
-%endif
-%if g_szBusTypeValues_16 <> g_szBusTypeValues_8Dual + g_szBusTypeValues_Displacement
-%error "g_szBusTypeValues Displacement Incorrect 5"
-%endif
-%if g_szBusTypeValues_32 <> g_szBusTypeValues_16 + g_szBusTypeValues_Displacement
-%error "g_szBusTypeValues Displacement Incorrect 6"
-%endif
-%if g_szBusTypeValues_Serial <> g_szBusTypeValues_32 + g_szBusTypeValues_Displacement
-%error "g_szBusTypeValues Displacement Incorrect 7"
+%if g_szDeviceTypeValues_16bit <> g_szDeviceTypeValues
+%error "g_szDeviceTypeValues Displacement Incorrect 1"
+%endif
+%if g_szDeviceTypeValues_32bit <> g_szDeviceTypeValues + g_szDeviceTypeValues_Displacement
+%error "g_szDeviceTypeValues Displacement Incorrect 2"
+%endif
+%if g_szDeviceTypeValues_XTIDEr1 <> g_szDeviceTypeValues_32bit + g_szDeviceTypeValues_Displacement
+%error "g_szDeviceTypeValues Displacement Incorrect 3"
+%endif
+%if g_szDeviceTypeValues_XTIDEr2 <> g_szDeviceTypeValues_XTIDEr1 + g_szDeviceTypeValues_Displacement
+%error "g_szDeviceTypeValues Displacement Incorrect 4"
+%endif
+%if g_szDeviceTypeValues_XTCFpio8 <> g_szDeviceTypeValues_XTIDEr2 + g_szDeviceTypeValues_Displacement
+%error "g_szDeviceTypeValues Displacement Incorrect 5"
+%endif
+%if g_szDeviceTypeValues_XTCFdma <> g_szDeviceTypeValues_XTCFpio8 + g_szDeviceTypeValues_Displacement
+%error "g_szDeviceTypeValues Displacement Incorrect 6"
+%endif
+%if g_szDeviceTypeValues_XTCFmem <> g_szDeviceTypeValues_XTCFdma + g_szDeviceTypeValues_Displacement
+%error "g_szDeviceTypeValues Displacement Incorrect 7"
+%endif
+%if g_szDeviceTypeValues_JrIde <> g_szDeviceTypeValues_XTCFmem + g_szDeviceTypeValues_Displacement
+%error "g_szDeviceTypeValues Displacement Incorrect 8"
+%endif
+%if g_szDeviceTypeValues_Serial <> g_szDeviceTypeValues_JrIde + g_szDeviceTypeValues_Displacement
+%error "g_szDeviceTypeValues Displacement Incorrect 9"
 %endif
 %endif
@@ -475,5 +489,5 @@
 ;; translated usage stats
 ;; 33:1
-;; 32:26
+;; 32:27
 ;; 181:1
 ;; 53:2
@@ -490,5 +504,5 @@
 ;; 34:3
 ;; 49:1
-;; 56:4
+;; 56:6
 ;; 45:1
 ;; 175:1
@@ -519,10 +533,10 @@
 ;; 63,?:
 ;; 64,@:1
-;; 65,A:4
+;; 65,A:5
 ;; 66,B:8
 ;; 67,C:2
 ;; 68,D:10
 ;; 69,E:3
-;; 70,F:4
+;; 70,F:3
 ;; 71,G:3
 ;; 72,H:2
@@ -531,5 +545,5 @@
 ;; 75,K:1
 ;; 76,L:4
-;; 77,M:5
+;; 77,M:7
 ;; 78,N:2
 ;; 79,O:2
@@ -538,5 +552,5 @@
 ;; 82,R:7
 ;; 83,S:3
-;; 84,T:
+;; 84,T:1
 ;; 85,U:2
 ;; 86,V:
@@ -576,5 +590,5 @@
 ;; 120,x:
 ;; 121,y:2
-;; alphabet used count: 44
+;; alphabet used count: 45
 %endif ; STRINGSCOMPRESSED_TABLES
 
Index: /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm	(revision 472)
+++ /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 472)
+++ /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 472)
+++ /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 472)
+++ /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
Index: /trunk/XTIDE_Universal_BIOS/makefile
===================================================================
--- /trunk/XTIDE_Universal_BIOS/makefile	(revision 472)
+++ /trunk/XTIDE_Universal_BIOS/makefile	(revision 473)
@@ -16,5 +16,4 @@
 # Following modules can be included or excluded:                                                   #
 # MODULE_8BIT_IDE             Support for 8-BIT IDE cards like XTIDE                               #
-# MODULE_JRIDE                Support for JR-IDE/ISA                                               #
 # MODULE_ADVANCED_ATA         Native support for some VLB IDE controllers                          #
 # MODULE_BOOT_MENU            Boot Menu for selection of drive to boot from                        #
@@ -98,5 +97,5 @@
 DEFINES_COMMON_LARGE = MODULE_BOOT_MENU
 
-DEFINES_XT = $(DEFINES_COMMON) ELIMINATE_CGA_SNOW MODULE_8BIT_IDE MODULE_JRIDE MODULE_SERIAL MODULE_SERIAL_FLOPPY
+DEFINES_XT = $(DEFINES_COMMON) ELIMINATE_CGA_SNOW MODULE_8BIT_IDE MODULE_SERIAL MODULE_SERIAL_FLOPPY
 DEFINES_XTPLUS = $(DEFINES_COMMON) $(DEFINES_XT) USE_186
 DEFINES_AT = $(DEFINES_COMMON) USE_AT USE_286 RELOCATE_INT13H_STACK MODULE_IRQ MODULE_SERIAL MODULE_SERIAL_FLOPPY MODULE_ADVANCED_ATA
@@ -104,5 +103,5 @@
 DEFINES_XT_LARGE = $(DEFINES_XT) $(DEFINES_COMMON_LARGE)
 DEFINES_XTPLUS_LARGE = $(DEFINES_XTPLUS) $(DEFINES_COMMON_LARGE)
-DEFINES_AT_LARGE = $(DEFINES_AT) $(DEFINES_COMMON_LARGE)
+DEFINES_AT_LARGE = $(DEFINES_AT) $(DEFINES_COMMON_LARGE) MODULE_8BIT_IDE
 
 DEFINES_XT_TINY = MODULE_STRINGS_COMPRESSED MODULE_8BIT_IDE
