Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm	(revision 526)
+++ 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
 
 ;--------------------------------------------------------------------
