Index: trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm	(revision 399)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm	(revision 400)
@@ -27,12 +27,4 @@
 %endmacro
 
-%macro CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE 1
-	xchg	ax, bx
-	eMOVZX	bx, [di+DPT.bIdevarsOffset]
-	cmp		BYTE [cs:bx+IDEVARS.bDevice], DEVICE_JRIDE_ISA
-	xchg	bx, ax				; Restore BX
-	je		SHORT %1
-%endmacro
-
 %macro CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF 2
 	cmp		BYTE [cs:bp+IDEVARS.bDevice], %1
@@ -53,14 +45,14 @@
 ;		AX, BX, CX, DX
 ;--------------------------------------------------------------------
-%ifdef MODULE_SERIAL
+%ifdef MODULE_SERIAL	; IDE + Serial
 Device_FinalizeDPT:
 	; needs to check IDEVARS vs. checking the DPT as the serial bit in the DPT is set in the Finalize routine
-	CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_SERIAL_PORT, .FinalizeDptForSerialPortDevice
+	CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF	DEVICE_SERIAL_PORT, .FinalizeDptForSerialPortDevice
 	jmp		IdeDPT_Finalize
 .FinalizeDptForSerialPortDevice:
 	jmp		SerialDPT_Finalize
 
-%else	; IDE or JR-IDE/ISA
-	Device_FinalizeDPT EQU IdeDPT_Finalize
+%else					; IDE
+	Device_FinalizeDPT		EQU		IdeDPT_Finalize
 %endif
 
@@ -76,29 +68,11 @@
 ;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
-%ifdef MODULE_JRIDE
-	%ifdef MODULE_SERIAL				; IDE + JR-IDE/ISA + Serial
-	Device_ResetMasterAndSlaveController:
-		TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
-		CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .ResetJrIDE
-		jmp		IdeCommand_ResetMasterAndSlaveController
-
-	%else								; IDE + JR-IDE/ISA
-	Device_ResetMasterAndSlaveController:
-		CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .ResetJrIDE
-		jmp		IdeCommand_ResetMasterAndSlaveController
-	%endif
-
-%elifdef MODULE_SERIAL					; IDE + Serial
+%ifdef MODULE_SERIAL	; IDE + Serial
 Device_ResetMasterAndSlaveController:
-	TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
+	TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE	ReturnSuccessForSerialPort
 	jmp		IdeCommand_ResetMasterAndSlaveController
 
-%else									; IDE
-	Device_ResetMasterAndSlaveController EQU IdeCommand_ResetMasterAndSlaveController
-%endif
-
-%ifdef MODULE_JRIDE
-.ResetJrIDE:
-	jmp		MemIdeCommand_ResetMasterAndSlaveController
+%else					; IDE
+	Device_ResetMasterAndSlaveController	EQU		IdeCommand_ResetMasterAndSlaveController
 %endif
 
@@ -117,34 +91,13 @@
 ;		AL, BL, CX, DX, SI, DI, ES
 ;--------------------------------------------------------------------
-%ifdef MODULE_JRIDE
-	%ifdef MODULE_SERIAL				; IDE + JR-IDE/ISA + Serial
-	Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
-		CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_SERIAL_PORT, .IdentifyDriveFromSerialPort
-		CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_JRIDE_ISA, .IdentifyDriveFromJrIde
-		jmp		IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
-
-	%else								; IDE + JR-IDE/ISA
-	Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
-		CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_JRIDE_ISA, .IdentifyDriveFromJrIde
-		jmp		IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
-	%endif
-
-%elifdef MODULE_SERIAL					; IDE + Serial
+%ifdef MODULE_SERIAL	; IDE + Serial
 Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
-	CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_SERIAL_PORT, .IdentifyDriveFromSerialPort
+	CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF	DEVICE_SERIAL_PORT, .IdentifyDriveFromSerialPort
 	jmp		IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
-
-%else									; IDE
-	Device_IdentifyToBufferInESSIwithDriveSelectByteInBH EQU IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
-%endif
-
-%ifdef MODULE_JRIDE
-.IdentifyDriveFromJrIde:
-	jmp		MemIdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
-%endif
-
-%ifdef MODULE_SERIAL
 .IdentifyDriveFromSerialPort:
 	jmp		SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
+
+%else					; IDE
+	Device_IdentifyToBufferInESSIwithDriveSelectByteInBH	EQU		IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
 %endif
 
@@ -165,36 +118,16 @@
 ;		AL, BX, (CX), DX, (ES:SI for data transfer commands)
 ;--------------------------------------------------------------------
-%ifdef MODULE_JRIDE
-	%ifdef MODULE_SERIAL				; IDE + JR-IDE/ISA + Serial
-	Device_OutputCommandWithParameters:
-		TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE .OutputCommandToSerialPort
-		CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .OutputCommandToJrIDE
-		jmp		IdeCommand_OutputWithParameters
-
-	%else								; IDE + JR-IDE/ISA
-	Device_OutputCommandWithParameters:
-		CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .OutputCommandToJrIDE
-		jmp		IdeCommand_OutputWithParameters
-	%endif
-
-%elifdef MODULE_SERIAL					; IDE + Serial
+%ifdef MODULE_SERIAL	; IDE + Serial
+ALIGN JUMP_ALIGN
 Device_OutputCommandWithParameters:
 	TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE .OutputCommandToSerialPort
 	jmp		IdeCommand_OutputWithParameters
 
-%else									; IDE
-	Device_OutputCommandWithParameters EQU IdeCommand_OutputWithParameters
-%endif
-
-%ifdef MODULE_JRIDE
-ALIGN JUMP_ALIGN
-.OutputCommandToJrIDE:
-	jmp		MemIdeCommand_OutputWithParameters
-%endif
-
-%ifdef MODULE_SERIAL
 ALIGN JUMP_ALIGN
 .OutputCommandToSerialPort:
 	jmp		SerialCommand_OutputWithParameters
+
+%else					; IDE
+	Device_OutputCommandWithParameters		EQU		IdeCommand_OutputWithParameters
 %endif
 
@@ -211,31 +144,13 @@
 ;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
-%ifdef MODULE_JRIDE
-	%ifdef MODULE_SERIAL				; IDE + JR-IDE/ISA + Serial
-	Device_SelectDrive:
-		TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
-		CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .SelectJrIdeDrive
-		jmp		IdeCommand_SelectDrive
-
-	%else								; IDE + JR-IDE/ISA
-	Device_SelectDrive:
-		CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .SelectJrIdeDrive
-		jmp		IdeCommand_SelectDrive
-	%endif
-
-%elifdef MODULE_SERIAL					; IDE + Serial
+%ifdef MODULE_SERIAL	; IDE + Serial
 Device_SelectDrive:
-	TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
+	TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE	ReturnSuccessForSerialPort
 	jmp		IdeCommand_SelectDrive
 
-%else									; IDE
-	Device_SelectDrive EQU IdeCommand_SelectDrive
+%else					; IDE
+	Device_SelectDrive		EQU		IdeCommand_SelectDrive
 %endif
 
-%ifdef MODULE_JRIDE
-ALIGN JUMP_ALIGN
-.SelectJrIdeDrive:
-	jmp		MemIdeCommand_SelectDrive
-%endif
 
 %ifdef MODULE_SERIAL
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IOMappedIDE.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IOMappedIDE.inc	(revision 399)
+++ 	(revision )
@@ -1,85 +1,0 @@
-; Project name	:	XTIDE Universal BIOS
-; Description	:	Macros for normal I/O mapped ATA controllers.
-
-;
-; 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 IO_MAPPED_IDE_INC
-%define IO_MAPPED_IDE_INC
-
-;--------------------------------------------------------------------
-; 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
-;	Parameters:
-;		AL:		Byte to output
-;		%1:		IDE Register				(OUTPUT_AL_TO_IDE_REGISTER)
-;				IDE Control Block Register	(OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER)
-;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		BX, DX
-;--------------------------------------------------------------------
-%macro OUTPUT_AL_TO_IDE_REGISTER 1
-%ifnidni %1, dl
-	mov		dl, %1
-%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
-%endif
-	call	IdeIO_OutputALtoIdeControlBlockRegisterInDL
-%endmacro
-
-
-;--------------------------------------------------------------------
-; INPUT_TO_AL_FROM_IDE_REGISTER
-; JUMP_TO_INPUT_TO_AL_FROM_IDE_REGISTER
-;	Parameters:
-;		%1:		IDE Register
-;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;	Returns:
-;		AL:		Inputted byte
-;	Corrupts registers:
-;		BX, DX
-;--------------------------------------------------------------------
-%macro INPUT_TO_AL_FROM_IDE_REGISTER 1
-%ifnidni %1, dl
-	mov		dl, %1
-%endif
-	call	IdeIO_InputToALfromIdeRegisterInDL
-%endmacro
-
-%macro JUMP_TO_INPUT_TO_AL_FROM_IDE_REGISTER 1
-%ifnidni %1, dl
-	mov		dl, %1
-%endif
-	jmp		IdeIO_InputToALfromIdeRegisterInDL
-%endmacro
-
-
-%endif ; IO_MAPPED_IDE_INC
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 399)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 400)
@@ -31,5 +31,5 @@
 ;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
-IDEDEVICE%+Command_ResetMasterAndSlaveController:
+IdeCommand_ResetMasterAndSlaveController:
 	; HSR0: Set_SRST
 	call	AccessDPT_GetDeviceControlByteToAL
@@ -49,5 +49,5 @@
 	; HSR2: Check_status
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_BSY)
-	jmp		IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
+	jmp		IdeWait_PollStatusFlagInBLwithTimeoutInBH
 
 
@@ -65,5 +65,5 @@
 ;		AL, BL, CX, DX, SI, DI, ES
 ;--------------------------------------------------------------------
-IDEDEVICE%+Command_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH:
+IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH:
 	; Create fake DPT to be able to use Device.asm functions
 	call	FindDPT_ForNewDriveToDSDI
@@ -72,18 +72,13 @@
 	mov		[di+DPT.bIdevarsOffset], bp
 	mov		BYTE [di+DPT_ATA.bBlockSize], 1	; Block = 1 sector
-%ifdef MODULE_ADVANCED_ATA
 	call	IdeDPT_StoreDeviceTypeFromIdevarsInCSBPtoDPTinDSDI
-%endif
-%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS
-	call	IdeDPT_StoreReversedAddressLinesFlagIfNecessary
-%endif
 
 	; Wait until drive motors have reached max speed
 	cmp		bp, BYTE ROMVARS.ideVars0
 	jne		SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
-	test	al, FLG_DRVNHEAD_DRV
+	test	bh, FLG_DRVNHEAD_DRV
 	jnz		SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_BSY)
-	call	IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
+	call	IdeWait_PollStatusFlagInBLwithTimeoutInBH
 .SkipLongWaitSinceDriveIsNotPrimaryMaster:
 
@@ -120,14 +115,14 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-IDEDEVICE%+Command_OutputWithParameters:
+IdeCommand_OutputWithParameters:
 	push	bx						; Store status register bits to poll
 
 	; Select Master or Slave drive and output head number or LBA28 top bits
-	call	IDEDEVICE%+Command_SelectDrive
+	call	IdeCommand_SelectDrive
 	jc		SHORT .DriveNotReady
 
 	; Output Device Control Byte to enable or disable interrupts
 	mov		al, [bp+IDEPACK.bDeviceControl]
-%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS	; JR-IDE/ISA
+%ifdef MODULE_IRQ
 	test	al, FLG_DEVCONTROL_nIEN	; Interrupts disabled?
 	jnz		SHORT .DoNotSetInterruptInServiceFlag
@@ -151,5 +146,5 @@
 	eMOVZX	ax, [bp+IDEPACK.bLbaLowExt]		; Zero sector count
 	mov		cx, [bp+IDEPACK.wLbaMiddleAndHighExt]
-	call	IDEDEVICE%+OutputSectorCountAndAddress
+	call	OutputSectorCountAndAddress
 %endif
 
@@ -157,5 +152,5 @@
 	mov		ax, [bp+IDEPACK.wSectorCountAndLbaLow]
 	mov		cx, [bp+IDEPACK.wLbaMiddleAndHigh]
-	call	IDEDEVICE%+OutputSectorCountAndAddress
+	call	OutputSectorCountAndAddress
 
 	; Output command
@@ -164,14 +159,21 @@
 
 	; Wait until command completed
-	pop		bx						; Pop status and timeout for polling
-	cmp		bl, FLG_STATUS_DRQ		; Data transfer started?
-	je		SHORT IDEDEVICE%+Transfer_StartWithCommandInAL
+	pop		bx								; Pop status and timeout for polling
+	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
+%endif
+	jmp		IdeTransfer_StartWithCommandInAL
+
+.WaitUntilNonTransferCommandCompletes:
+%ifdef MODULE_IRQ
 	test	BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
-	jz		SHORT .WaitForIrqOrRdy
-	jmp		IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
-
-ALIGN JUMP_ALIGN
-.WaitForIrqOrRdy:
-	jmp		IDEDEVICE%+Wait_IRQorStatusFlagInBLwithTimeoutInBH
+	jz		SHORT .PollStatusFlagInsteadOfWaitIrq
+	jmp		IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
+.PollStatusFlagInsteadOfWaitIrq:
+%endif
+	jmp		IdeWait_PollStatusFlagInBLwithTimeoutInBH
 
 .DriveNotReady:
@@ -192,12 +194,5 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-IDEDEVICE%+Command_SelectDrive:
-	; Wait until neither Master or Slave Drive is busy.
-	; I don't think this wait is necessary.
-	;mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
-	;cmp		BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
-	;eCMOVE	bh, TIMEOUT_IDENTIFY_DEVICE
-	;call	IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
-
+IdeCommand_SelectDrive:
 	; Select Master or Slave Drive
 	mov		al, [bp+IDEPACK.bDrvAndHead]
@@ -206,5 +201,5 @@
 	cmp		BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
 	eCMOVE	bh, TIMEOUT_IDENTIFY_DEVICE
-	call	IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
+	call	IdeWait_PollStatusFlagInBLwithTimeoutInBH
 
 	; Ignore errors from IDE Error Register (set by previous command)
@@ -232,5 +227,5 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-IDEDEVICE%+OutputSectorCountAndAddress:
+OutputSectorCountAndAddress:
 	OUTPUT_AL_TO_IDE_REGISTER	SECTOR_COUNT_REGISTER
 
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDPT.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDPT.asm	(revision 399)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDPT.asm	(revision 400)
@@ -66,18 +66,4 @@
 %ifdef MODULE_ADVANCED_ATA
 ;--------------------------------------------------------------------
-; .StoreDeviceType
-;	Parameters:
-;		DS:DI:	Ptr to Disk Parameter Table
-;		ES:SI:	Ptr to 512-byte ATA information read from the drive
-;		CS:BP:	Ptr to IDEVARS for the controller
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-.StoreDeviceType:
-	call	IdeDPT_StoreDeviceTypeFromIdevarsInCSBPtoDPTinDSDI
-
-;--------------------------------------------------------------------
 ; .StorePioModeAndTimings
 ;	Parameters:
@@ -124,33 +110,12 @@
 	; it might have been set to 16-bit on IDEVARS
 .ChangeTo32bitDevice:
-	mov		BYTE [di+DPT_ADVANCED_ATA.bDevice], DEVICE_32BIT_ATA
+	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_32BIT_ATA
 
 .NoAdvancedControllerDetected:
+	; Fall to IdeDPT_StoreDeviceTypeFromIdevarsInCSBPtoDPTinDSDI
 
-%endif ; MODULE_ADVANCED_ATA
-
-;--------------------------------------------------------------------
-; IdeDPT_StoreReversedAddressLinesFlagIfNecessary
-;	Parameters:
-;		DS:DI:	Ptr to Disk Parameter Table
-;		CS:BP:	Ptr to IDEVARS for the controller
-;	Returns:
-;		CF:		Always clear
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-IdeDPT_StoreReversedAddressLinesFlagIfNecessary:
-	cmp		BYTE [cs:bp+IDEVARS.bDevice], DEVICE_XTIDE_REV2
-	je		SHORT .SetFlagForSwappedA0andA3
-	cmp		BYTE [cs:bp+IDEVARS.bDevice], DEVICE_FAST_XTIDE
-	jne		SHORT .EndDPT
-.SetFlagForSwappedA0andA3:
-	or		BYTE [di+DPT.bFlagsHigh], FLGH_DPT_REVERSED_A0_AND_A3
-.EndDPT:
-	clc
-	ret
+%endif	; MODULE_ADVANCED_ATA
 
 
-%ifdef MODULE_ADVANCED_ATA
 ;--------------------------------------------------------------------
 ; IdeDPT_StoreDeviceTypeFromIdevarsInCSBPtoDPTinDSDI
@@ -165,6 +130,6 @@
 IdeDPT_StoreDeviceTypeFromIdevarsInCSBPtoDPTinDSDI:
 	mov		al, [cs:bp+IDEVARS.bDevice]
-	mov		[di+DPT_ADVANCED_ATA.bDevice], al
+	mov		[di+DPT_ATA.bDevice], al
+; End DPT
+	clc
 	ret
-
-%endif
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeError.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeError.asm	(revision 399)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeError.asm	(revision 400)
@@ -34,20 +34,8 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL:
+IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL:
 	mov		ah, al			; IDE Status Register to AH
 	INPUT_TO_AL_FROM_IDE_REGISTER	ERROR_REGISTER_in
-
-%ifndef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS	; JR-IDE/ISA
-	jmp		ContinueFromMemIdeError
-%else
-ContinueFromMemIdeError:
 	xchg	al, ah			; Status Register now in AL, Error Register now in AH
-
-	; I don't think anything actually reads these from BDA
-	;push	ds
-	;LOAD_BDA_SEGMENT_TO	ds, dx
-	;mov		[HDBDA.wHDStAndErr], ax
-	;pop		ds
-
 	; Fall to GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
 
@@ -112,3 +100,2 @@
 	db	RET_HD_BADSECTOR	; Bit7=BBK, Bad Block Detected
 	db	RET_HD_STATUSERR	; When Error Register is zero
-%endif
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm	(revision 399)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm	(revision 400)
@@ -23,9 +23,35 @@
 ;--------------------------------------------------------------------
 ; IdeIO_OutputALtoIdeControlBlockRegisterInDL
+;	Parameters:
+;		AL:		Byte to output
+;		DL:		IDE Control Block Register
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		BX, DX
+;--------------------------------------------------------------------
+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
+%endif
+
+	mov		bl, IDEVARS.wPortCtrl
+	jmp		SHORT OutputALtoIdeRegisterInDLwithIdevarsOffsetToBasePortInBL
+
+
+;--------------------------------------------------------------------
 ; IdeIO_OutputALtoIdeRegisterInDL
 ;	Parameters:
 ;		AL:		Byte to output
-;		DL:		IDE Control Block Register	(IdeIO_OutputALtoIdeControlBlockRegisterInDL)
-;				IDE Register				(IdeIO_OutputALtoIdeRegisterInDL)
+;		DL:		IDE Command Block Register
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
 ;	Returns:
@@ -35,15 +61,41 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-IdeIO_OutputALtoIdeControlBlockRegisterInDL:
-	mov		bl, IDEVARS.wPortCtrl
-	SKIP2B	f	; cmp ax, <next instruction>
-	; Fall to IdeIO_OutputALtoIdeRegisterInDL
+IdeIO_OutputALtoIdeRegisterInDL:
+%ifdef MODULE_8BIT_IDE
+	mov		dh, [di+DPT_ATA.bDevice]
+%ifdef MODULE_JRIDE
+	test	dh, dh
+	jnz		SHORT OutputALtoIOmappedIdeRegisterInDL
 
-IdeIO_OutputALtoIdeRegisterInDL:
+	add		dx, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET
+OutputToJrIdeRegister:
+	mov		bx, dx
+	mov		[cs:bx], al
+	ret
+ALIGN JUMP_ALIGN
+OutputALtoIOmappedIdeRegisterInDL:
+%endif
+%endif
+
 	mov		bl, IDEVARS.wPort
-	call	GetPortToDXandTranslateA0andA3ifNecessary
+OutputALtoIdeRegisterInDLwithIdevarsOffsetToBasePortInBL:
+	call	GetIdePortToDX
 	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
 
 ;--------------------------------------------------------------------
@@ -57,8 +109,20 @@
 ;		BX, DX
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
 IdeIO_InputToALfromIdeRegisterInDL:
+%ifdef MODULE_8BIT_IDE
+	mov		dh, [di+DPT_ATA.bDevice]
+%ifdef MODULE_JRIDE
+	test	dh, dh
+	jnz		SHORT .InputToALfromIOmappedIdeRegisterInDL
+
+	add		dx, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET
+	mov		bx, dx
+	mov		al, [cs:bx]
+	ret
+.InputToALfromIOmappedIdeRegisterInDL:
+%endif
+%endif
 	mov		bl, IDEVARS.wPort
-	call	GetPortToDXandTranslateA0andA3ifNecessary
+	call	GetIdePortToDX
 	in		al, dx
 	ret
@@ -66,7 +130,8 @@
 
 ;--------------------------------------------------------------------
-; GetPortToDXandTranslateA0andA3ifNecessary
+; 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)
@@ -77,21 +142,37 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-GetPortToDXandTranslateA0andA3ifNecessary:
+GetIdePortToDX:
+%ifdef MODULE_8BIT_IDE
+	; Point CS:BX to IDEVARS
 	xor		bh, bh
-	add		bl, [di+DPT.bIdevarsOffset]		; CS:BX now points port address
-	xor		dh, dh							; DX now has IDE register offset
-	add		dx, [cs:bx]
-	test	BYTE [di+DPT.bFlagsHigh], FLGH_DPT_REVERSED_A0_AND_A3
-	jz		SHORT .ReturnPortInDX
+	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
 	mov		bh, MASK_A3_AND_A0_ADDRESS_LINES
-	and		bh, bl							; BH = 0, 1, 8 or 9, we can ignore 0 and 9
-	jz		SHORT .ReturnPortInDX			; Jump out since DH is 0
+	and		bh, bl								; BH = 0, 1, 8 or 9, we can ignore 0 and 9
+	jz		SHORT .ReturnTranslatedPortInDX		; Jump out since DH is 0
 	xor		bh, MASK_A3_AND_A0_ADDRESS_LINES
-	jz		SHORT .ReturnPortInDX			; Jump out since DH was 9
+	jz		SHORT .ReturnTranslatedPortInDX		; Jump out since DH was 9
 	and		dl, ~MASK_A3_AND_A0_ADDRESS_LINES
-	or		dl, bh							; Address lines now reversed
-.ReturnPortInDX:
+	or		dl, bh								; Address lines now reversed
+.ReturnTranslatedPortInDX:
 	ret
+
+.ReturnUntranslatedPortInDX:
+	add		dx, [cs:bx]
+	ret
+
+%else	; Only standard IDE devices
+	xor		bh, bh
+	xor		dh, dh
+	add		bl, [di+DPT.bIdevarsOffset]		; CS:BX now points port address
+	add		dx, [cs:bx]						; DX now has port address
+	ret
+%endif
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 399)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 400)
@@ -208,9 +208,5 @@
 	mov		bl, [di+DPT.bIdevarsOffset]			; CS:BX now points to IDEVARS
 	mov		dx, [cs:bx+IDEVARS.wPort]			; Load IDE Data port address
-%ifdef MODULE_ADVANCED_ATA
-	mov		bl, [di+DPT_ADVANCED_ATA.bDevice]
-%else
-	mov		bl, [cs:bx+IDEVARS.bDevice]			; Load device type to BX
-%endif
+	mov		bl, [di+DPT_ATA.bDevice]
 	add		bx, ax
 
@@ -235,4 +231,6 @@
 ;		AX, BX, CX
 ;--------------------------------------------------------------------
+%ifdef MODULE_8BIT_IDE
+
 ALIGN JUMP_ALIGN
 ReadBlockFromXtideRev1:
@@ -267,4 +265,6 @@
 %endif
 
+%endif	; MODULE_8BIT_IDE
+
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -302,4 +302,6 @@
 ;		AX, CX
 ;--------------------------------------------------------------------
+%ifdef MODULE_8BIT_IDE
+
 ALIGN JUMP_ALIGN
 WriteBlockToXtideRev1:
@@ -361,4 +363,6 @@
 %endif
 
+%endif	; MODULE_8BIT_IDE
+
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -387,23 +391,34 @@
 ALIGN WORD_ALIGN
 g_rgfnPioRead:
-	dw		ReadBlockFromXtideRev1		; DEVICE_XTIDE_REV1
-%ifdef USE_186
-	dw		ReadBlockFrom16bitDataPort	; DEVICE_XTIDE_REV2
-	dw		ReadBlockFrom16bitDataPort	; DEVICE_FAST_XTIDE
+%ifdef MODULE_8BIT_IDE
+		dw		ReadBlockFromXtideRev1		; DEVICE_XTIDE_REV1
+	%ifdef USE_186
+		dw		ReadBlockFrom16bitDataPort	; DEVICE_XTIDE_REV2
+		dw		ReadBlockFrom16bitDataPort	; DEVICE_FAST_XTIDE
+	%else
+		dw		ReadBlockFromXtideRev2		; DEVICE_XTIDE_REV2
+		dw		ReadBlockFromXtideRev2		; DEVICE_FAST_XTIDE
+	%endif
+
 %else
-	dw		ReadBlockFromXtideRev2		; DEVICE_XTIDE_REV2
-	dw		ReadBlockFromXtideRev2		; DEVICE_FAST_XTIDE
-%endif
-	dw		ReadBlockFrom16bitDataPort	; DEVICE_16BIT_ATA
-	dw		ReadBlockFrom32bitDataPort	; DEVICE_32BIT_ATA
+		times	COUNT_OF_8BIT_IDE_DEVICES	dw	0
+%endif
+		dw		ReadBlockFrom16bitDataPort	; DEVICE_16BIT_ATA
+		dw		ReadBlockFrom32bitDataPort	; DEVICE_32BIT_ATA
+
 
 g_rgfnPioWrite:
-	dw		WriteBlockToXtideRev1		; DEVICE_XTIDE_REV1
-	dw		WriteBlockToXtideRev2		; DEVICE_XTIDE_REV2
-%ifdef USE_186
-	dw		WriteBlockTo16bitDataPort	; DEVICE_FAST_XTIDE
+%ifdef MODULE_8BIT_IDE
+		dw		WriteBlockToXtideRev1		; DEVICE_XTIDE_REV1
+		dw		WriteBlockToXtideRev2		; DEVICE_XTIDE_REV2
+	%ifdef USE_186
+		dw		WriteBlockTo16bitDataPort	; DEVICE_FAST_XTIDE
+	%else
+		dw		WriteBlockToFastXtide		; DEVICE_FAST_XTIDE
+	%endif
+
 %else
-	dw		WriteBlockToFastXtide		; DEVICE_FAST_XTIDE
-%endif
-	dw		WriteBlockTo16bitDataPort	; DEVICE_16BIT_ATA
-	dw		WriteBlockTo32bitDataPort	; DEVICE_32BIT_ATA
+		times	COUNT_OF_8BIT_IDE_DEVICES	dw	0
+%endif
+		dw		WriteBlockTo16bitDataPort	; DEVICE_16BIT_ATA
+		dw		WriteBlockTo32bitDataPort	; DEVICE_32BIT_ATA
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeWait.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeWait.asm	(revision 399)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeWait.asm	(revision 400)
@@ -32,9 +32,10 @@
 ;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
-IDEDEVICE%+Wait_IRQorDRQ:
+IdeWait_IRQorDRQ:
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRQ)
-%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS		; JR-IDE/ISA does not support IRQ
+
+%ifdef MODULE_IRQ
 	test	BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
-	jnz		SHORT IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH	; Interrupt disabled
+	jnz		SHORT IdeWait_PollStatusFlagInBLwithTimeoutInBH	; Interrupt disabled
 %endif
 	; Fall to IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
@@ -53,9 +54,7 @@
 ;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
-IDEDEVICE%+Wait_IRQorStatusFlagInBLwithTimeoutInBH:
-%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS		; JR-IDE/ISA does not support IRQ
-	%ifdef MODULE_IRQ
-		call	IdeIrq_WaitForIRQ
-	%endif
+IdeWait_IRQorStatusFlagInBLwithTimeoutInBH:
+%ifdef MODULE_IRQ
+	call	IdeIrq_WaitForIRQ
 %endif
 	; Always fall to IdeWait_PollStatusFlagInBLwithTimeoutInBH for error processing
@@ -74,10 +73,10 @@
 ;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
-IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH:
+IdeWait_PollStatusFlagInBLwithTimeoutInBH:
 	mov		ah, bl
 	mov		cl, bh
 	call	Timer_InitializeTimeoutWithTicksInCL
 	and		ah, ~FLG_STATUS_BSY
-	jz		SHORT IDEDEVICE%+PollBsyOnly
+	jz		SHORT PollBsyOnly
 	; Fall to PollBsyAndFlgInAH
 
@@ -94,17 +93,17 @@
 ;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
-IDEDEVICE%+PollBsyAndFlgInAH:
-	INPUT_TO_AL_FROM_IDE_REGISTER	STATUS_REGISTER_in	; Discard contents for first read
-ALIGN JUMP_ALIGN
+IdePollBsyAndFlgInAH:
+	call	IdeIO_InputStatusRegisterToAL		; Discard contents of first read
+
 .PollLoop:
-	INPUT_TO_AL_FROM_IDE_REGISTER	STATUS_REGISTER_in
+	call	IdeIO_InputStatusRegisterToAL
 	test	al, FLG_STATUS_BSY					; Controller busy?
 	jnz		SHORT .UpdateTimeout				;  If so, jump to timeout update
 	test	al, ah								; Test secondary flag
-	jnz		SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
+	jnz		SHORT IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
 .UpdateTimeout:
 	call	Timer_SetCFifTimeout
 	jnc		SHORT .PollLoop						; Loop if time left
-	call	IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
+	call	IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
 	jc		SHORT .ReturnErrorCodeInAH
 	mov		ah, RET_HD_TIMEOUT					; Expected bit never got set
@@ -125,12 +124,12 @@
 ;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
-IDEDEVICE%+PollBsyOnly:
-	INPUT_TO_AL_FROM_IDE_REGISTER	STATUS_REGISTER_in	; Discard contents for first read
-ALIGN JUMP_ALIGN
+PollBsyOnly:
+	call	IdeIO_InputStatusRegisterToAL		; Discard contents of first read
+
 .PollLoop:
-	INPUT_TO_AL_FROM_IDE_REGISTER	STATUS_REGISTER_in
+	call	IdeIO_InputStatusRegisterToAL
 	test	al, FLG_STATUS_BSY					; Controller busy?
-	jz		SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
+	jz		SHORT IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
 	call	Timer_SetCFifTimeout				; Update timeout counter
 	jnc		SHORT .PollLoop						; Loop if time left (sets CF on timeout)
-	jmp		SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
+	jmp		SHORT IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm	(revision 400)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm	(revision 400)
@@ -0,0 +1,258 @@
+; Project name	:	XTIDE Universal BIOS
+; Description	:	Memory mapped IDE Device transfer functions.
+
+;
+; 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
+;				
+
+; Structure containing variables for PIO transfer functions.
+; This struct must not be larger than IDEPACK without INTPACK.
+struc MEMPIOVARS
+	.wSectorsInBlock		resb	2	; 0, Block size in sectors
+	.bSectorsLeft			resb	1	; 2, Sectors left to transfer
+	.bSectorsDone			resb	1	; 3, Number of sectors xferred
+							resb	3	; 4, 5, 6
+							resb	1	; 7, IDEPACK.bDeviceControl
+	.fpDPT					resb	4	; 8, Far pointer to DPT
+endstruc
+
+
+; Section containing code
+SECTION .text
+
+;--------------------------------------------------------------------
+; JrIdeTransfer_StartWithCommandInAL
+;	Parameters:
+;		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
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;		SS:BP:	Ptr to IDEPACK
+;	Returns:
+;		AH:		INT 13h Error Code
+;		CX:		Number of successfully transferred sectors
+;		CF:		Cleared if success, Set if error
+;	Corrupts registers:
+;		AL, BX, DX, SI, ES
+;--------------------------------------------------------------------
+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
+	mov		[bp+MEMPIOVARS.fpDPT], di
+	mov		[bp+MEMPIOVARS.fpDPT+2], ds
+
+	; 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
+	jnz		SHORT WriteToSectorAccessWindow
+	cmp		al, COMMAND_WRITE_MULTIPLE
+	je		SHORT WriteToSectorAccessWindow
+	; Fall to ReadFromSectorAccessWindow
+
+;--------------------------------------------------------------------
+; ReadFromSectorAccessWindow
+;	Parameters:
+;		Stack:	Segment part of ptr to Sector Access Window
+;		ES:SI:	Normalized ptr to buffer to receive data
+;		SS:BP:	Ptr to MEMPIOVARS
+;	Returns:
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;		AH:		BIOS Error code
+;		CX:		Number of successfully transferred sectors
+;		CF:		0 if transfer successful
+;				1 if any error
+;	Corrupts registers:
+;		AL, BX, DX, SI, ES
+;--------------------------------------------------------------------
+ReadFromSectorAccessWindow:
+	pop		ds		; CS -> DS
+	mov		di, si	; ES:DI = destination
+	mov		si, JRIDE_SECTOR_ACCESS_WINDOW_OFFSET	; DS:SI = source
+
+	call	WaitUntilReadyToTransferNextBlock
+	jc		SHORT ReturnWithMemoryIOtransferErrorInAH
+
+	mov		cx, [bp+MEMPIOVARS.wSectorsInBlock]
+
+ALIGN JUMP_ALIGN
+.ReadNextBlockFromDrive:
+	cmp		[bp+MEMPIOVARS.bSectorsLeft], cl
+	jbe		SHORT .ReadLastBlockFromDrive
+	call	ReadSingleBlockFromSectorAccessWindowInDSSItoESDI
+	call	WaitUntilReadyToTransferNextBlock
+	jc		SHORT ReturnWithMemoryIOtransferErrorInAH
+
+	; Increment number of successfully read sectors
+	mov		cx, [bp+MEMPIOVARS.wSectorsInBlock]
+	sub		[bp+MEMPIOVARS.bSectorsLeft], cl
+	add		[bp+MEMPIOVARS.bSectorsDone], cl
+	jmp		SHORT .ReadNextBlockFromDrive
+
+ALIGN JUMP_ALIGN
+.ReadLastBlockFromDrive:
+	mov		cl, [bp+MEMPIOVARS.bSectorsLeft]
+	call	ReadSingleBlockFromSectorAccessWindowInDSSItoESDI
+
+	; Check for errors in last block
+CheckErrorsAfterTransferringLastMemoryMappedBlock:
+	lds		di, [bp+MEMPIOVARS.fpDPT]			; DPT now in DS:DI
+	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRDY)
+	call	IdeWait_PollStatusFlagInBLwithTimeoutInBH
+
+	; Return number of successfully transferred sectors
+ReturnWithMemoryIOtransferErrorInAH:
+	lds		di, [bp+MEMPIOVARS.fpDPT]			; DPT now in DS:DI
+%ifdef USE_386
+	movzx	cx, BYTE [bp+MEMPIOVARS.bSectorsDone]
+%else
+	mov		ch, 0
+	mov		cl, [bp+MEMPIOVARS.bSectorsDone]
+%endif
+	ret
+
+
+;--------------------------------------------------------------------
+; WriteToSectorAccessWindow
+;	Parameters:
+;		Stack:	Segment part of ptr to Sector Access Window
+;		ES:SI:	Normalized ptr to buffer containing data
+;		SS:BP:	Ptr to MEMPIOVARS
+;	Returns:
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;		AH:		BIOS Error code
+;		CX:		Number of successfully transferred sectors
+;		CF:		0 if transfer successful
+;				1 if any error
+;	Corrupts registers:
+;		AL, BX, DX, SI, ES
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+WriteToSectorAccessWindow:
+	push	es
+	pop		ds
+	pop		es	; CS -> ES
+	mov		di, JRIDE_SECTOR_ACCESS_WINDOW_OFFSET
+
+	; Always poll when writing first block (IRQs are generated for following blocks)
+	call	WaitUntilReadyToTransferNextBlock
+	jc		SHORT ReturnWithMemoryIOtransferErrorInAH
+
+	mov		cx, [bp+MEMPIOVARS.wSectorsInBlock]
+
+ALIGN JUMP_ALIGN
+.WriteNextBlockToDrive:
+	cmp		[bp+MEMPIOVARS.bSectorsLeft], cl
+	jbe		SHORT .WriteLastBlockToDrive
+	call	WriteSingleBlockFromDSSIToSectorAccessWindowInESDI
+	call	WaitUntilReadyToTransferNextBlock
+	jc		SHORT ReturnWithMemoryIOtransferErrorInAH
+
+	; Increment number of successfully written WORDs
+	mov		cx, [bp+MEMPIOVARS.wSectorsInBlock]
+	sub		[bp+MEMPIOVARS.bSectorsLeft], cl
+	add		[bp+MEMPIOVARS.bSectorsDone], cl
+	jmp		SHORT .WriteNextBlockToDrive
+
+ALIGN JUMP_ALIGN
+.WriteLastBlockToDrive:
+	mov		cl, [bp+MEMPIOVARS.bSectorsLeft]
+	ePUSH_T	bx, CheckErrorsAfterTransferringLastMemoryMappedBlock
+	; Fall to WriteSingleBlockFromDSSIToSectorAccessWindowInESDI
+
+;--------------------------------------------------------------------
+; WriteSingleBlockFromDSSIToSectorAccessWindowInESDI
+;	Parameters:
+;		CX:		Number of sectors in block
+;		DS:SI:	Normalized ptr to source buffer
+;		ES:DI:	Ptr to Sector Access Window
+;	Returns:
+;		CX, DX:	Zero
+;		SI:		Updated
+;	Corrupts registers:
+;		BX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+WriteSingleBlockFromDSSIToSectorAccessWindowInESDI:
+	mov		bx, di
+	mov		dx, cx
+	xor		cl, cl
+ALIGN JUMP_ALIGN
+.WriteBlock:
+	mov		ch, JRIDE_SECTOR_ACCESS_WINDOW_SIZE >> 9
+	rep movsw
+	mov		di, bx	; Reset for next sector
+	dec		dx
+	jnz		SHORT .WriteBlock
+	ret
+
+
+;--------------------------------------------------------------------
+; ReadSingleBlockFromSectorAccessWindowInDSSItoESDI
+;	Parameters:
+;		CX		Number of sectors in block
+;		ES:DI:	Normalized ptr to buffer to receive data (destination)
+;		DS:SI:	Ptr to Sector Access Window (source)
+;	Returns:
+;		CX, DX:	Zero
+;		DI:		Updated
+;	Corrupts registers:
+;		BX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+ReadSingleBlockFromSectorAccessWindowInDSSItoESDI:
+	mov		bx, si
+	mov		dx, cx
+	xor		cl, cl
+ALIGN JUMP_ALIGN
+.ReadBlock:
+	mov		ch, JRIDE_SECTOR_ACCESS_WINDOW_SIZE >> 9
+	rep movsw
+	mov		si, bx	; Reset for next sector
+	dec		dx
+	jnz		SHORT .ReadBlock
+	ret
+
+
+;--------------------------------------------------------------------
+; WaitUntilReadyToTransferNextBlock
+;	Parameters:
+;		SS:BP:	Ptr to MEMPIOVARS
+;	Returns:
+;		AH:		INT 13h Error Code
+;		CF:		Cleared if success, Set if error
+;	Corrupts registers:
+;		AL, BX, CX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+WaitUntilReadyToTransferNextBlock:
+	push	ds
+	push	di
+	lds		di, [bp+MEMPIOVARS.fpDPT]	; DPT now in DS:DI
+	call	IdeWait_IRQorDRQ			; Always polls
+	pop		di
+	pop		ds
+	ret
+
+
+%if JRIDE_SECTOR_ACCESS_WINDOW_SIZE <> 512
+	%error "JRIDE_SECTOR_ACCESS_WINDOW_SIZE is no longer equal to 512. MemIdeTransfer.asm needs changes."
+%endif
Index: trunk/XTIDE_Universal_BIOS/Src/Device/MemoryMappedIDE/MemIdeTransfer.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/MemoryMappedIDE/MemIdeTransfer.asm	(revision 399)
+++ 	(revision )
@@ -1,259 +1,0 @@
-; Project name	:	XTIDE Universal BIOS
-; Description	:	Memory mapped IDE Device transfer functions.
-
-;
-; 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
-;				
-
-; Structure containing variables for PIO transfer functions.
-; This struct must not be larger than IDEPACK without INTPACK.
-struc MEMPIOVARS
-	.wWordsInBlock			resb	2	; 0, Block size in WORDs
-	.wWordsLeft				resb	2	; 2, WORDs left to transfer
-	.wWordsDone				resb	2	; 4, Number of sectors xferred
-	; TODO: The above word vars could just as well be byte vars?
-							resb	1	; 6,
-							resb	1	; 7, IDEPACK.bDeviceControl
-	.fpDPT					resb	4	; 8, Far pointer to DPT
-endstruc
-
-
-; Section containing code
-SECTION .text
-
-;--------------------------------------------------------------------
-; MemIdeTransfer_StartWithCommandInAL
-;	Parameters:
-;		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
-;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to IDEPACK
-;	Returns:
-;		AH:		INT 13h Error Code
-;		CX:		Number of successfully transferred sectors
-;		CF:		Cleared if success, Set if error
-;	Corrupts registers:
-;		AL, BX, DX, SI, ES
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-MemIdeTransfer_StartWithCommandInAL:
-	push	cs	; We push CS here (segment of SAW) and later pop it to DS (reads) or ES (writes)
-
-	; Initialize MEMPIOVARS
-	xor		cx, cx
-	mov		[bp+MEMPIOVARS.wWordsDone], cx
-	mov		ch, [bp+IDEPACK.bSectorCount]
-	mov		[bp+MEMPIOVARS.wWordsLeft], cx
-	mov		ch, [di+DPT_ATA.bBlockSize]
-	mov		[bp+MEMPIOVARS.wWordsInBlock], cx
-	mov		[bp+MEMPIOVARS.fpDPT], di
-	mov		[bp+MEMPIOVARS.fpDPT+2], ds
-
-	; 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
-	jnz		SHORT WriteToSectorAccessWindow
-	cmp		al, COMMAND_WRITE_MULTIPLE
-	je		SHORT WriteToSectorAccessWindow
-	; Fall to ReadFromSectorAccessWindow
-
-;--------------------------------------------------------------------
-; ReadFromSectorAccessWindow
-;	Parameters:
-;		Stack:	Segment part of ptr to Sector Access Window
-;		ES:SI:	Normalized ptr to buffer to receive data
-;		SS:BP:	Ptr to MEMPIOVARS
-;	Returns:
-;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		AH:		BIOS Error code
-;		CX:		Number of successfully transferred sectors
-;		CF:		0 if transfer successful
-;				1 if any error
-;	Corrupts registers:
-;		AL, BX, DX, SI, ES
-;--------------------------------------------------------------------
-ReadFromSectorAccessWindow:
-	pop		ds		; CS -> DS
-	mov		di, si	; ES:DI = destination
-	mov		si, JRIDE_SECTOR_ACCESS_WINDOW_OFFSET	; DS:SI = source
-
-	call	WaitUntilReadyToTransferNextBlock
-	jc		SHORT ReturnWithMemoryIOtransferErrorInAH
-
-	mov		cx, [bp+MEMPIOVARS.wWordsInBlock]
-
-ALIGN JUMP_ALIGN
-.ReadNextBlockFromDrive:
-	cmp		[bp+MEMPIOVARS.wWordsLeft], cx
-	jbe		SHORT .ReadLastBlockFromDrive
-	call	ReadSingleBlockFromSectorAccessWindowInDSSItoESDI
-	call	WaitUntilReadyToTransferNextBlock
-	jc		SHORT ReturnWithMemoryIOtransferErrorInAH
-
-	; Increment number of successfully read WORDs
-	mov		cx, [bp+MEMPIOVARS.wWordsInBlock]
-	sub		[bp+MEMPIOVARS.wWordsLeft], cx
-	add		[bp+MEMPIOVARS.wWordsDone], cx
-	jmp		SHORT .ReadNextBlockFromDrive
-
-ALIGN JUMP_ALIGN
-.ReadLastBlockFromDrive:
-	mov		ch, [bp+MEMPIOVARS.wWordsLeft+1]	; Sectors left
-	call	ReadSingleBlockFromSectorAccessWindowInDSSItoESDI
-
-	; Check for errors in last block
-CheckErrorsAfterTransferringLastMemoryMappedBlock:
-	lds		di, [bp+MEMPIOVARS.fpDPT]			; DPT now in DS:DI
-	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRDY)
-	call	IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
-
-	; Return number of successfully transferred sectors
-ReturnWithMemoryIOtransferErrorInAH:
-	lds		di, [bp+MEMPIOVARS.fpDPT]			; DPT now in DS:DI
-	mov		cx, [bp+MEMPIOVARS.wWordsDone]
-	jc		SHORT .ConvertTransferredWordsInCXtoSectors
-	add		cx, [bp+MEMPIOVARS.wWordsLeft]		; Never sets CF
-.ConvertTransferredWordsInCXtoSectors:
-	xchg	cl, ch
-	ret
-
-
-;--------------------------------------------------------------------
-; WriteToSectorAccessWindow
-;	Parameters:
-;		Stack:	Segment part of ptr to Sector Access Window
-;		ES:SI:	Normalized ptr to buffer containing data
-;		SS:BP:	Ptr to MEMPIOVARS
-;	Returns:
-;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		AH:		BIOS Error code
-;		CX:		Number of successfully transferred sectors
-;		CF:		0 if transfer successful
-;				1 if any error
-;	Corrupts registers:
-;		AL, BX, DX, SI, ES
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-WriteToSectorAccessWindow:
-	push	es
-	pop		ds
-	pop		es	; CS -> ES
-	mov		di, JRIDE_SECTOR_ACCESS_WINDOW_OFFSET
-
-	; Always poll when writing first block (IRQs are generated for following blocks)
-	call	WaitUntilReadyToTransferNextBlock
-	jc		SHORT ReturnWithMemoryIOtransferErrorInAH
-
-	mov		cx, [bp+MEMPIOVARS.wWordsInBlock]
-
-ALIGN JUMP_ALIGN
-.WriteNextBlockToDrive:
-	cmp		[bp+MEMPIOVARS.wWordsLeft], cx
-	jbe		SHORT .WriteLastBlockToDrive
-	call	WriteSingleBlockFromDSSIToSectorAccessWindowInESDI
-	call	WaitUntilReadyToTransferNextBlock
-	jc		SHORT ReturnWithMemoryIOtransferErrorInAH
-
-	; Increment number of successfully written WORDs
-	mov		cx, [bp+MEMPIOVARS.wWordsInBlock]
-	sub		[bp+MEMPIOVARS.wWordsLeft], cx
-	add		[bp+MEMPIOVARS.wWordsDone], cx
-	jmp		SHORT .WriteNextBlockToDrive
-
-ALIGN JUMP_ALIGN
-.WriteLastBlockToDrive:
-	mov		ch, [bp+MEMPIOVARS.wWordsLeft+1]		; Sectors left
-	ePUSH_T	bx, CheckErrorsAfterTransferringLastMemoryMappedBlock
-	; Fall to WriteSingleBlockFromDSSIToSectorAccessWindowInESDI
-
-;--------------------------------------------------------------------
-; WriteSingleBlockFromDSSIToSectorAccessWindowInESDI
-;	Parameters:
-;		CH:		Number of sectors in block
-;		DS:SI:	Normalized ptr to source buffer
-;		ES:DI:	Ptr to Sector Access Window
-;	Returns:
-;		CX, DX:	Zero
-;		SI:		Updated
-;	Corrupts registers:
-;		BX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-WriteSingleBlockFromDSSIToSectorAccessWindowInESDI:
-	mov		bx, di
-	eMOVZX	dx, ch
-	xor		cl, cl
-ALIGN JUMP_ALIGN
-.WriteBlock:
-	mov		ch, JRIDE_SECTOR_ACCESS_WINDOW_SIZE >> 9
-	rep movsw
-	mov		di, bx	; Reset for next sector
-	dec		dx
-	jnz		SHORT .WriteBlock
-	ret
-
-
-;--------------------------------------------------------------------
-; ReadSingleBlockFromSectorAccessWindowInDSSItoESDI
-;	Parameters:
-;		CH:		Number of sectors in block
-;		ES:DI:	Normalized ptr to buffer to receive data (destination)
-;		DS:SI:	Ptr to Sector Access Window (source)
-;	Returns:
-;		CX, DX:	Zero
-;		DI:		Updated
-;	Corrupts registers:
-;		BX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-ReadSingleBlockFromSectorAccessWindowInDSSItoESDI:
-	mov		bx, si
-	eMOVZX	dx, ch
-	xor		cl, cl
-ALIGN JUMP_ALIGN
-.ReadBlock:
-	mov		ch, JRIDE_SECTOR_ACCESS_WINDOW_SIZE >> 9
-	rep movsw
-	mov		si, bx	; Reset for next sector
-	dec		dx
-	jnz		SHORT .ReadBlock
-	ret
-
-
-;--------------------------------------------------------------------
-; WaitUntilReadyToTransferNextBlock
-;	Parameters:
-;		SS:BP:	Ptr to MEMPIOVARS
-;	Returns:
-;		AH:		INT 13h Error Code
-;		CF:		Cleared if success, Set if error
-;	Corrupts registers:
-;		AL, BX, CX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-WaitUntilReadyToTransferNextBlock:
-	push	ds
-	push	di
-	lds		di, [bp+MEMPIOVARS.fpDPT]			; DPT now in DS:DI
-	call	IDEDEVICE%+Wait_IRQorDRQ			; Always polls
-	pop		di
-	pop		ds
-	ret
-
-
-%if JRIDE_SECTOR_ACCESS_WINDOW_SIZE <> 512
-	%error "JRIDE_SECTOR_ACCESS_WINDOW_SIZE is no longer equal to 512. MemIdeTransfer.asm needs changes."
-%endif
-
Index: trunk/XTIDE_Universal_BIOS/Src/Device/MemoryMappedIDE/MemMappedIDE.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/MemoryMappedIDE/MemMappedIDE.inc	(revision 399)
+++ 	(revision )
@@ -1,84 +1,0 @@
-; Project name	:	XTIDE Universal BIOS
-; Description	:	Macros for memory mapped ATA controllers.
-
-;
-; 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 MEM_MAPPED_IDE_INC
-%define MEM_MAPPED_IDE_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
-;	Parameters:
-;		AL:		Byte to output
-;		%1:		IDE Register				(OUTPUT_AL_TO_IDE_REGISTER)
-;				IDE Control Block Register	(OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER)
-;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		BX, DX
-;--------------------------------------------------------------------
-%unmacro OUTPUT_AL_TO_IDE_REGISTER 1
-%macro OUTPUT_AL_TO_IDE_REGISTER 1
-	mov		[cs:JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET+%1], al
-%endmacro
-
-%unmacro JUMP_TO_OUTPUT_AL_TO_IDE_REGISTER 1
-%macro JUMP_TO_OUTPUT_AL_TO_IDE_REGISTER 1
-	OUTPUT_AL_TO_IDE_REGISTER %1
-	ret
-%endmacro
-
-%unmacro OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER 1
-%macro OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER 1
-	mov		[cs:JRIDE_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET+%1], al
-%endmacro
-
-
-;--------------------------------------------------------------------
-; INPUT_TO_AL_FROM_IDE_REGISTER
-; JUMP_TO_INPUT_TO_AL_FROM_IDE_REGISTER
-;	Parameters:
-;		%1:		IDE Register
-;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;	Returns:
-;		AL:		Inputted byte
-;	Corrupts registers:
-;		BX, DX
-;--------------------------------------------------------------------
-%unmacro INPUT_TO_AL_FROM_IDE_REGISTER 1
-%macro INPUT_TO_AL_FROM_IDE_REGISTER 1
-	mov		al, [cs:JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET+%1]
-%endmacro
-
-%unmacro JUMP_TO_INPUT_TO_AL_FROM_IDE_REGISTER 1
-%macro JUMP_TO_INPUT_TO_AL_FROM_IDE_REGISTER 1
-	INPUT_TO_AL_FROM_IDE_REGISTER %1
-	ret
-%endmacro
-
-
-%endif ; MEM_MAPPED_IDE_INC
