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