Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 545)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 558)
@@ -40,4 +40,5 @@
 ;		AH:		Int 13h return status
 ;		CF:		0 if successful, 1 if error
+;		DX:		Command return values (see XTCF.inc)
 ;--------------------------------------------------------------------
 AH1Eh_HandlerForXTCFfeatures:
@@ -46,5 +47,5 @@
 	jmp		Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
 %else
-	push		Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
+	push	Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
 	; Fall to ProcessXTCFsubcommandFromAL
 %endif
@@ -60,5 +61,4 @@
 ;		AH:		Int 13h return status
 ;		CF:		0 if successful, 1 if error
-;		DX		Command return values (see XTCF.inc)
 ;	Corrupts registers:
 ;		AL, BX, CX, DX, SI
@@ -68,5 +68,5 @@
 	call	AccessDPT_IsThisDeviceXTCF
 	jne		SHORT .XTCFnotFound
-	and		ax, BYTE 7Fh				; Subcommand now in AX (clears AH and CF)
+	and		ax, 0FFh					; Subcommand now in AX (clears AH and CF)
 	jz		SHORT .XTCFfound			; Sub-function IS_THIS_DRIVE_XTCF (=0)
 
@@ -75,23 +75,23 @@
 
 	dec		ax							; Test subcommand for value 2 (GET_XTCF_TRANSFER_MODE)
-	jnz		SHORT .XTCFnotFound			; Invalid subcommand
+	jnz		SHORT .AH1Eh_LoadInvalidCommandToAHandSetCF
 
 	; GET_XTCF_TRANSFER_MODE
 	call	AH1Eh_GetCurrentXTCFmodeToAX
+	mov		dh, al
 	mov		dl, [di+DPT_ATA.bBlockSize]
-	mov		[bp+IDEPACK.intpack+INTPACK.dh], al	; return mode value...
-	mov		[bp+IDEPACK.intpack+INTPACK.dl], dl	; ...and block size, via INTPACK...
+	mov		[bp+IDEPACK.intpack+INTPACK.dx], dx	; Return mode value (DH) and block size (DL) via INTPACK
 .XTCFfound:
-	ret											; ...with AH and CF cleared
+	ret		; With AH and CF cleared
 
 .XTCFnotFound:
 .AH1Eh_LoadInvalidCommandToAHandSetCF:
-	stc					; set carry flag since XT-CF not found
+	stc		; Set carry flag since XT-CF not found or invalid subcommand
 	mov		ah, RET_HD_INVALID
-	ret					; and return
+	ret
 
 .SetXTCFtransferMode:
-	mov		al, [bp+IDEPACK.intpack+INTPACK.dh]	; get specified mode (eg XTCF_DMA_MODE) 
-	; and fall to AH1Eh_ChangeXTCFmodeBasedOnControlRegisterInAL
+	mov		al, [bp+IDEPACK.intpack+INTPACK.dh]	; Get specified mode (eg XTCF_DMA_MODE)
+	; Fall to AH1Eh_ChangeXTCFmodeBasedOnModeInAL
 
 
@@ -102,5 +102,5 @@
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
 ;		SS:BP:	Ptr to IDEPACK
-;	Returns:	
+;	Returns:
 ;		AH:		Int 13h return status
 ;		CF:		0 if successful, 1 if error
@@ -110,13 +110,10 @@
 AH1Eh_ChangeXTCFmodeBasedOnModeInAL:
 	; Note: Control register (as of XT-CFv3) is now a write-only register,
-	;       whos purpose is *only* to raise DRQ.  The register cannot be read.
+	;       whose purpose is *only* to raise DRQ.  The register cannot be read.
 	;       Selected transfer mode is stored in BIOS variable (DPT_ATA.bDevice).
 
-	; We always need to enable 8-bit mode since 16-bit mode is restored
-	; when controller is reset (AH=00h or 0Dh)
-	; 
 	; Note that when selecting 'DEVICE_8BIT_PIO_MODE_WITH_BIU_OFFLOAD' mode,
 	; the ATA device (i.e. CompactFlash card) will operate in 8-bit mode, but
-	; data will be transferred from it's data register using 16-bit CPU instructions
+	; data will be transferred from its data register using 16-bit CPU instructions
 	; like REP INSW.  This works because XT-CF adapters are 8-bit cards, and
 	; the BIU in the machine splits each WORD requested by the CPU into two 8-bit
@@ -125,33 +122,37 @@
 	; the data for presentation to the CPU.
 	;
-	; Also note though that some machines, noteably AT&T PC6300, have hardware
-	; errors in the BIU logic, resulting in reversed byte ordering.  Therefore,
-	; mode DEVICE_8BIT_PIO is the default transfer mode for best system
-	; compatibility.
+	; Also note that some machines, noteably the Olivetti M24 (also known as
+	; the AT&T PC6300 and Xerox 6060), have hardware errors in the BIU logic,
+	; resulting in reversed byte ordering.  Therefore, mode DEVICE_8BIT_PIO is
+	; the default transfer mode for best system compatibility.
 
+	; We always need to enable 8-bit mode since 16-bit mode is restored
+	; when controller is reset (AH=00h or 0Dh)
 	ePUSH_T	bx, AH23h_Enable8bitPioMode
 
 	; Convert mode to device type (see XTCF.inc for full details)
 	and		ax, 3
-	jz	SHORT .Set8bitPioMode	; XTCF_8BIT_PIO_MODE = 0
-	dec		ax					; XTCF_8BIT_PIO_MODE_WITH_BIU_OFFLOAD = 1
-	jz	SHORT .Set8bitPioModeWithBIUOffload
+	jz		SHORT .Set8bitPioMode	; XTCF_8BIT_PIO_MODE = 0
+	dec		ax						; XTCF_8BIT_PIO_MODE_WITH_BIU_OFFLOAD = 1
+	jz		SHORT .Set8bitPioModeWithBIUOffload
 
 	; XTCF_DMA_MODE = 2 (allow 3 as well for more optimized code)
 	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_DMA
 
-	; DMA transfers have limited block sizee
+	; DMA transfers have limited block size
 	mov		al, [di+DPT_ATA.bBlockSize]
-	MIN_U	al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
-	jmp		AH24h_SetBlockSize
-	; exit via ret in AH24_SetBlockSize then through AH23h_Enable8bitPioMode
+	cmp		al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
+	jbe		SHORT AH24h_SetBlockSize
+	mov		al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
+	jmp		SHORT AH24h_SetBlockSize
 
 .Set8bitPioMode:
-	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_PIO8
-	ret		; through AH23h_Enable8bitPioMode
+	mov		al, DEVICE_8BIT_XTCF_PIO8
+	SKIP2B	bx
 
 .Set8bitPioModeWithBIUOffload:
-	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_PIO8_WITH_BIU_OFFLOAD
-	ret		; through AH23h_Enable8bitPioMode
+	mov		al, DEVICE_8BIT_XTCF_PIO8_WITH_BIU_OFFLOAD
+	mov		[di+DPT_ATA.bDevice], al
+	ret
 
 
@@ -160,5 +161,5 @@
 ;	Parameters:
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;	Returns:	
+;	Returns:
 ;		AX:		XT-CF mode (XTCF_8BIT_PIO_MODE, XTCF_8BIT_PIO_MODE_WITH_BIU_OFFLOAD or XTCF_DMA_MODE)
 ;		CF:		Clear
@@ -167,6 +168,7 @@
 ;--------------------------------------------------------------------
 AH1Eh_GetCurrentXTCFmodeToAX:
-	eMOVZX	ax, BYTE [di+DPT_ATA.bDevice]	; get current mode from DPT
-	sub		al, DEVICE_8BIT_XTCF_PIO8
-	shr		ax, 1							; Device type to XT-CF mode
+	mov		al, [di+DPT_ATA.bDevice]
+	shr		al, 1
+	cbw
+	sub		al, DEVICE_8BIT_XTCF_PIO8 >> 1
 	ret
