Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 540)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 545)
@@ -80,5 +80,5 @@
 	test	bh, FLG_DRVNHEAD_DRV		; Wait already done for Master
 	jnz		SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
-	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_DRDY)
+	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_BSY)
 	call	IdeWait_PollStatusFlagInBLwithTimeoutInBH
 .SkipLongWaitSinceDriveIsNotPrimaryMaster:
@@ -88,12 +88,14 @@
 	call	Idepack_FakeToSSBP
 
-%ifdef MODULE_8BIT_IDE_ADVANCED
+%ifdef MODULE_8BIT_IDE
 	; Enable 8-bit PIO mode for 8-bit ATA and XT-CF
 	push	si
 	call	AH9h_Enable8bitModeForDevice8bitAta
-	xor		al, al						; XTCF_8BIT_PIO_MODE
+%ifdef MODULE_8BIT_IDE_ADVANCED
+	mov		al, XTCF_8BIT_PIO_MODE		; initialise with most basic transfer mode
 	call	AH9h_SetModeFromALtoXTCF
+%endif ; MODULE_8BIT_IDE_ADVANCED
 	pop		si
-%endif ; MODULE_8BIT_IDE_ADVANCED
+%endif ; MODULE_8BIT_IDE
 
 	; Prepare to output Identify Device command
@@ -173,6 +175,6 @@
 	jne		SHORT .WaitUntilNonTransferCommandCompletes
 %ifdef MODULE_8BIT_IDE_ADVANCED
-	cmp		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_MEMMAP
-	jae		SHORT JrIdeTransfer_StartWithCommandInAL	; DEVICE_8BIT_XTCF_MEMMAP, DEVICE_8BIT_JRIDE_ISA or DEVICE_8BIT_ADP50L
+	cmp		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_JRIDE_ISA
+	jae		SHORT JrIdeTransfer_StartWithCommandInAL	; DEVICE_8BIT_JRIDE_ISA or DEVICE_8BIT_ADP50L
 %endif
 	jmp		IdeTransfer_StartWithCommandInAL
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDmaBlock.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDmaBlock.asm	(revision 540)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDmaBlock.asm	(revision 545)
@@ -78,5 +78,5 @@
 	; so we never need to separate transfer to more than 2 separate DMA operations.
 
-	; Load XT-CF Control Register port to DX
+	; Load XT-CFv3 Control Register port to DX
 	add		dl, XTCF_CONTROL_REGISTER
 
@@ -90,11 +90,11 @@
 	shl		cx, 1
 %endif
-	cmp		cx, ax
-	jbe		SHORT .TransferLastDmaPageWithSizeInCX
+	cmp		cx, ax									; if we won't cross a physical page boundary...
+	jbe		SHORT .TransferLastDmaPageWithSizeInCX	; ...perform the transfer in one operation
 
-	; Push size for second DMA page
+	; Calculate how much we can transfer on first and second rounds
 	xchg	cx, ax									; CX = BYTEs for first page
 	sub		ax, cx									; AX = BYTEs for second page
-	push	ax
+	push	ax										; Save bytes for second transfer on stack
 
 	; Transfer first DMA page
@@ -108,10 +108,13 @@
 ;--------------------------------------------------------------------
 ; StartDMAtransferForXTCFwithDmaModeInBL
+; Updated for XT-CFv3, 11-Apr-13
 ;	Parameters:
 ;		BL:		Byte for DMA Mode Register
-;		CX:		Number of BYTEs to transfer (1...32768 since max block size is limited to 64)
-;		DX:		XTCF Control Register
+;		CX:		Number of BYTEs to transfer (512...32768 since max block size is limited to 64)
+;		DX:		XT-CFv3 Control Register
+;		ES:		Bits 3..0 have physical address bits 19..16
+;		DI:		Physical address bits 15..0
 ;	Returns:
-;		Nothing
+;		ES:DI updated (CX is added)
 ;	Corrupts registers:
 ;		AX
@@ -122,6 +125,6 @@
 	; Disable Interrupts and DMA Channel 3 during DMA setup
 	mov		al, SET_CH3_MASK_BIT
-	cli										; Disable interrupts
-	out		MASK_REGISTER_DMA8_out, al		; Disable DMA Channel 3
+	cli									; Disable interrupts - programming must be atomic
+	out		MASK_REGISTER_DMA8_out, al	; Disable DMA Channel 3
 
 	; Set DMA Mode (read or write using channel 3)
@@ -129,9 +132,9 @@
 	out		MODE_REGISTER_DMA8_out, al
 
-	; Set address to DMA controller
-	out		CLEAR_FLIPFLOP_DMA8_out, al		; Reset flip-flop to low byte
+	; Send start address to DMA controller
 	mov		ax, es
 	out		PAGE_DMA8_CH_3, al
 	mov		ax, di
+	out		CLEAR_FLIPFLOP_DMA8_out, al							; Reset flip-flop to low byte
 	out		BASE_AND_CURRENT_ADDRESS_REGISTER_DMA8_CH3_out, al	; Low byte
 	mov		al, ah
@@ -140,5 +143,5 @@
 	; Set number of bytes to transfer (DMA controller must be programmed number of bytes - 1)
 	mov		ax, cx
-	dec		ax								; DMA controller is programmed for one byte less
+	dec		ax													; DMA controller is programmed for one byte less
 	out		BASE_AND_CURRENT_COUNT_REGISTER_DMA8_CH3_out, al	; Low byte
 	mov		al, ah
@@ -147,52 +150,46 @@
 	; Enable DMA Channel 3
 	mov		al, CLEAR_CH3_MASK_BIT
-	out		MASK_REGISTER_DMA8_out, al		; Enable DMA Channel 3
-	sti										; Enable interrupts
+	out		MASK_REGISTER_DMA8_out, al							; Enable DMA Channel 3
+	sti															; Enable interrupts
 
+	; XT-CF transfers 16 bytes at a time. We need to manually start transfer for every block by writing (anything)
+	; to the XT-CFv3 Control Register, which raises DRQ thereby passing system control to the 8237 DMA controller.
+	; The XT-CFv3 logic releases DRQ after 16 transfers, thereby handing control back to the CPU and allowing any other IRQs or
+	; DRQs to be serviced (which, on the PC and PC/XT will include DRAM refresh via DMA channel 0).  The 16-byte transfers can
+	; also be interrupted by the DMA controller raising TC (i.e. when done).  Each transfer cannot be otherwise interrupted
+	; and is therefore atomic (and hence fast).
 
-%if 0 ; Slow DMA code
-	; XT-CF transfers 16 bytes at a time. We need to manually
-	; start transfer for every block.
-ALIGN JUMP_ALIGN
-.TransferNextBlock:
-	mov		al, RAISE_DRQ_AND_CLEAR_XTCF_XFER_COUNTER
-	cli									; We want no ISR to read DMA Status Register before we do
-	out		dx, al						; Transfer up to 16 bytes to/from XT-CF card
-	; * Here XT-CF sets CPU to wait states during transfer *
-	in		al, STATUS_REGISTER_DMA8_in
-	sti
-	test	al, FLG_CH3_HAS_REACHED_TERMINAL_COUNT
-	jz		SHORT .TransferNextBlock	; All bytes transferred?
+%if 0	; Slow DMA code - works by checking 8237 status register after each 16-byte transfer, until it reports TC has been raised.
+;ALIGN JUMP_ALIGN
+;.TransferNextBlock:
+;	cli									; We want no ISR to read DMA Status Register before we do
+;	out		dx, al						; Transfer up to 16 bytes to/from XT-CF card
+;	in		al, STATUS_REGISTER_DMA8_in
+;	sti
+;	test	al, FLG_CH3_HAS_REACHED_TERMINAL_COUNT
+;	jz		SHORT .TransferNextBlock	; All bytes transferred?
 %endif ; Slow DMA code
 
-
-%if 1 ; Fast DMA code
-	push	cx
-	add		cx, BYTE 15					; Include any partial DMA block (since we had to divide transfer to 64k physical pages)
-	eSHR_IM	cx, 4						; Drive Block size to 16 Byte DMA Block Size
-
-.JustOneMoreDmaBlock:
-	mov		al, RAISE_DRQ_AND_CLEAR_XTCF_XFER_COUNTER
-ALIGN JUMP_ALIGN
+%if 1	; Fast DMA code - perform computed number of transfers, then check DMA status register to be sure
+	push	cx							; need byte count to update pointer at the end
+	add		cx, BYTE 15					; We'll divide transfers in 16-byte atomic transfers,
+	eSHR_IM	cx, 4						; so include any partial block, which will be terminated
+ALIGN JUMP_ALIGN						; by the DMA controller raising T/C
 .TransferNextDmaBlock:
-	out		dx, al						; Transfer 16 bytes to/from XT-CF card
-	loop	.TransferNextDmaBlock
-
+	out		dx, al						; Transfer up to 16 bytes to/from XT-CF card
+	loop	.TransferNextDmaBlock		; dec CX and loop if CX > 0, also adds required wait-state
 	inc		cx							; set up CX, in case we need to do an extra iteration
-	in		al, STATUS_REGISTER_DMA8_in
-	test	al, FLG_CH3_HAS_REACHED_TERMINAL_COUNT
-	jz		SHORT .JustOneMoreDmaBlock			; it wasn't set so get more bytes
-	pop		cx
+	in		al, STATUS_REGISTER_DMA8_in	; check 8237 DMA controller status flags...
+	test	al, FLG_CH3_HAS_REACHED_TERMINAL_COUNT	; ... for channel 3 terminal count
+	jz		SHORT .TransferNextDmaBlock	; If not set, get more bytes
+	pop		cx							; get back requested bytes
 %endif ; Fast DMA code
 
+	; Update physical address in ES:DI - since IO might need several calls through this function either from here
+	; if crossing a physical page boundary, and from IdeTransfer.asm if requested sectors was > PIOVARS.wSectorsInBlock
+	mov		ax, es						; copy physical page address to ax
+	add		di, cx						; add requested bytes to di
+	adc		al, 0						; and increment physical page address, if required
+	mov		es, ax						; and save it back in es
 
-	; Restore XT-CF to normal operation
-	mov		al, XTCF_DMA_MODE
-	out		dx, al
-
-	; Increment physical address in ES:DI
-	mov		ax, es
-	add		di, cx
-	adc		al, ah
-	mov		es, ax
 	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm	(revision 540)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm	(revision 545)
@@ -52,9 +52,9 @@
 ;--------------------------------------------------------------------
 IdeIO_InputToALfromIdeRegisterInDL:
-	xor		dh, dh	; IDE Register index now in DX
-	mov		bx, dx	; and BX
+	xor		dh, dh	; IDE Register index now in DX...
 	mov		al, [di+DPT_ATA.bDevice]
 	cmp		al, DEVICE_8BIT_XTIDE_REV2
 	jb		SHORT .InputToALfromRegisterInDX	; Standard IDE controllers and XTIDE rev 1
+	mov		bx, dx	; ...and BX for A0<->A3 swap and for memory mapped I/O
 
 %ifdef MODULE_8BIT_IDE_ADVANCED
@@ -109,5 +109,5 @@
 	; At this point remaining controllers (JRIDE, XTCF and ADP50L) all have a control
 	; block offset of 8 or (8<<1) so we add 8 here and do the SHL 1 later if needed.
-	add		dx, 8
+	add		dx, BYTE 8
 	cmp		bl, DEVICE_8BIT_JRIDE_ISA
 	jb		SHORT IdeIO_OutputALtoIdeRegisterInDL.ShlRegisterIndexInDXandOutputAL	; All XT-CF modes
@@ -127,5 +127,5 @@
 	; a small trick since we only access Device Control Register at
 	; offset 6h: Always clear A3 and set A0.
-	mov		bh, dh	; Zero BH
+	call	AccessDPT_GetIdevarsToCSBX
 	add		dx, [cs:bx+IDEVARS.wControlBlockPort]
 	xor		dl, 1001b						; Clear A3, Set A0
@@ -134,5 +134,5 @@
 
 .OutputALtoControlBlockRegisterInDX:
-	call	AccessDPT_GetIdevarsToCSBX		; *FIXME* Why is this call here but not in the above block?
+	call	AccessDPT_GetIdevarsToCSBX
 	add		dx, [cs:bx+IDEVARS.wControlBlockPort]
 	out		dx, al
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm	(revision 540)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm	(revision 545)
@@ -20,6 +20,16 @@
 ;
 
+; Modified by JJP for XT-CFv3 support, Mar-13
+
 ; Section containing code
 SECTION .text
+
+
+; --------------------------------------------------------------------------------------------------
+;
+; READ routines follow
+;
+; --------------------------------------------------------------------------------------------------
+
 
 %ifdef MODULE_8BIT_IDE
@@ -50,8 +60,11 @@
 
 ;--------------------------------------------------------------------
-; 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
+; IdePioBlock_ReadFrom8bitDataPort
+;
+; 8-bit PIO from a single data port.
+;
+;	Parameters:
+;		CX:	Block size in 512 byte sectors
+;		DX:	IDE Data port address
 ;		ES:DI:	Normalized ptr to buffer to receive data
 ;	Returns:
@@ -60,170 +73,58 @@
 ;		AX, BX, CX
 ;--------------------------------------------------------------------
-%ifndef USE_186			; 8086/8088 compatible WORD read
-
-ALIGN JUMP_ALIGN
-IdePioBlock_ReadFromXtideRev2:
+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
+
+%endif	; MODULE_8BIT_IDE
+
+
+;--------------------------------------------------------------------
+; IdePioBlock_ReadFrom16bitDataPort
+;
+; 16-bit PIO from a single data port.
+;
+;	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_ReadFrom16bitDataPort:
+%ifdef USE_186
+	xchg		cl, ch	; Sectors to WORDs
+	rep insw
+	ret
+
+%else ; If 8088/8086
 	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
-
+		in		ax, dx	; Read BYTE
+		stosw			; Store BYTE 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
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-%ifdef USE_186
-%ifdef MODULE_8BIT_IDE
-IdePioBlock_ReadFromXtideRev2:
-%endif
-%endif
-IdePioBlock_ReadFrom16bitDataPort:
-	xchg	cl, ch		; Sectors to WORDs
-	rep
-	db		6Dh			; INSW
-	ret
 
 ;--------------------------------------------------------------------
@@ -239,10 +140,114 @@
 
 
-;--------------------------------------------------------------------
-; IdePioBlock_WriteTo16bitDataPort		Normal 16-bit IDE
+
+; --------------------------------------------------------------------------------------------------
+;
+; WRITE routines follow
+;
+; --------------------------------------------------------------------------------------------------
+
+%ifdef MODULE_8BIT_IDE
+
+;--------------------------------------------------------------------
+; 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	; special macro
+	%endrep
+	loop	.WriteNextQword
+	pop		ds
+	ret
+
+
+;--------------------------------------------------------------------
+; IdePioBlock_WriteTo8bitDataPort
+;	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_QWORDS
+	push		ds
+	;mov		ax, es
+	;mov		ds, ax	; move es to ds via ax (does this run faster on 8088?)
+	push		es
+	pop			ds
+ALIGN JUMP_ALIGN
+.WriteNextQword:
+	%rep 8	; BYTEs
+		lodsb			; Load BYTE from [DS:SI]
+		out	dx, al		; Write BYTE
+	%endrep
+	loop	.WriteNextQword
+	pop		ds
+	ret
+%endif
+
+%endif ; MODULE_8BIT_IDE
+
+
+;--------------------------------------------------------------------
+; IdePioBlock_WriteTo16bitDataPort		Normal 16-bit IDE, XT-CFv3 in BIU Mode
 ; IdePioBlock_WriteTo32bitDataPort		VLB/PCI 32-bit IDE
 ;	Parameters:
-;		CX:		Block size in 512-byte sectors
-;		DX:		IDE Data port address
+;		CX:	Block size in 512-byte sectors
+;		DX:	IDE Data port address
 ;		ES:SI:	Normalized ptr to buffer containing data
 ;	Returns:
@@ -253,9 +258,27 @@
 ALIGN JUMP_ALIGN
 IdePioBlock_WriteTo16bitDataPort:
+%ifdef USE_186
 	xchg	cl, ch		; Sectors to WORDs
 	es					; Source is ES segment
-	rep
-	db		6Fh			; OUTSW
-	ret
+	rep outsw
+	ret
+
+%else ; If 8088/8086
+	UNROLL_SECTORS_IN_CX_TO_QWORDS
+	push	ds
+	;mov	ax, es
+	;mov	ds, ax		; move es to ds via ax (does this run faster on 8088?)
+	push	es
+	pop		ds
+ALIGN JUMP_ALIGN
+.WriteNextQword:
+	%rep 4	; WORDs
+		lodsw			; Load BYTE from [DS:SI]
+		out	dx, ax		; Write BYTE
+	%endrep
+	loop	.WriteNextQword
+	pop		ds
+	ret
+%endif	; if/else USE_186
 
 ;--------------------------------------------------------------------
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 540)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 545)
@@ -346,10 +346,11 @@
 		dw		IdePioBlock_ReadFrom8bitDataPort	; 2, DEVICE_8BIT_ATA
 		dw		IdePioBlock_ReadFromXtideRev1		; 3, DEVICE_8BIT_XTIDE_REV1
-		dw		IdePioBlock_ReadFromXtideRev2		; 4, DEVICE_8BIT_XTIDE_REV2
+		dw		IdePioBlock_ReadFrom16bitDataPort	; 4, DEVICE_8BIT_XTIDE_REV2
+		dw		IdePioBlock_ReadFrom8bitDataPort	; 5, DEVICE_8BIT_XTCF_PIO8
+		dw		IdePioBlock_ReadFrom16bitDataPort	; 6, DEVICE_8BIT_XTCF_PIO8_WITH_BIU_OFFLOAD
 %ifdef MODULE_8BIT_IDE_ADVANCED
-		dw		IdePioBlock_ReadFrom8bitDataPort	; 5, DEVICE_8BIT_XTCF_PIO8
-		dw		IdeDmaBlock_ReadFromXTCF			; 6, DEVICE_8BIT_XTCF_DMA
-%endif
-%endif
+		dw		IdeDmaBlock_ReadFromXTCF			; 7, DEVICE_8BIT_XTCF_DMA
+%endif ; MODULE_8BIT_IDE_ADVANCED
+%endif ; MODULE_8BIT_IDE
 
 
@@ -361,7 +362,8 @@
 		dw		IdePioBlock_WriteToXtideRev1		; 3, DEVICE_8BIT_XTIDE_REV1
 		dw		IdePioBlock_WriteToXtideRev2		; 4, DEVICE_8BIT_XTIDE_REV2
+		dw		IdePioBlock_WriteTo8bitDataPort		; 5, DEVICE_8BIT_XTCF_PIO8
+		dw		IdePioBlock_WriteTo16bitDataPort	; 6, DEVICE_8BIT_XTCF_PIO8_WITH_BIU_OFFLOAD
 %ifdef MODULE_8BIT_IDE_ADVANCED
-		dw		IdePioBlock_WriteTo8bitDataPort		; 5, DEVICE_8BIT_XTCF_PIO8
-		dw		IdeDmaBlock_WriteToXTCF				; 6, DEVICE_8BIT_XTCF_DMA
-%endif
-%endif
+		dw		IdeDmaBlock_WriteToXTCF				; 7, DEVICE_8BIT_XTCF_DMA
+%endif ; MODULE_8BIT_IDE_ADVANCED
+%endif ; MODULE_8BIT_IDE
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm	(revision 540)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm	(revision 545)
@@ -67,21 +67,8 @@
 
 	; Get far pointer to Sector Access Window
-	mov		dx, [di+DPT.wBasePort]
 	cmp		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_JRIDE_ISA
-	jb		SHORT .GetSectorAccessWindowForXTCF
-
-	; Get Sector Access Window for JR-IDE/ISA and ADP50L
-	mov		ds, dx		; Segment for JR-IDE/ISA and ADP50L
-	mov		di, JRIDE_SECTOR_ACCESS_WINDOW_OFFSET
-	je		SHORT .SectorAccessWindowLoadedToDSDI
+	mov		ds, [di+DPT.wBasePort]	; Segment for JR-IDE/ISA and ADP50L
 	mov		di, ADP50L_SECTOR_ACCESS_WINDOW_OFFSET
-	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
+	eCMOVE	di, JRIDE_SECTOR_ACCESS_WINDOW_OFFSET
 
 	; Are we reading or writing?
