Index: /trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm	(revision 159)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm	(revision 160)
@@ -10,4 +10,5 @@
 ;		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
@@ -103,85 +104,2 @@
 	xor		ax, ax
 	ret
-
-
-;--------------------------------------------------------------------
-; Device_OutputALtoIdeRegisterInDL
-;	Parameters:
-;		AL:		Byte to output
-;		DL:		IDE Register
-;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		BX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-Device_OutputALtoIdeRegisterInDL:
-	mov		bx, IdeIO_OutputALtoIdeRegisterInDX
-	jmp		SHORT TranslateRegisterAddressInDLifNecessaryThenJumpToBX
-
-
-;--------------------------------------------------------------------
-; Device_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
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-Device_OutputALtoIdeControlBlockRegisterInDL:
-	mov		bx, IdeIO_OutputALtoIdeControlBlockRegisterInDX
-	jmp		SHORT TranslateRegisterAddressInDLifNecessaryThenJumpToBX
-
-
-;--------------------------------------------------------------------
-; Device_InputToALfromIdeRegisterInDL
-;	Parameters:
-;		DL:		IDE Register
-;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;	Returns:
-;		AL:		Inputted byte
-;	Corrupts registers:
-;		BX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-Device_InputToALfromIdeRegisterInDL:
-	mov		bx, IdeIO_InputToALfromIdeRegisterInDX
-	; Fall to TranslateRegisterAddressInDLifNecessaryThenJumpToBX
-
-
-;--------------------------------------------------------------------
-; TranslateRegisterAddressInDLifNecessaryThenJumpToBX
-;	Parameters:
-;		AL:		Byte to output (if output function in BX)
-;		DL:		IDE Register
-;		BX:		I/O function to jump to
-;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;	Returns:
-;		AL:		Inputted byte (if input function in BX)
-;	Corrupts registers:
-;		BX, DX
-;--------------------------------------------------------------------
-TranslateRegisterAddressInDLifNecessaryThenJumpToBX:
-	test	BYTE [di+DPT.bFlagsHigh], FLGH_DPT_REVERSED_A0_AND_A3
-	jz		SHORT .JumpToIoFunctionInSI
-
-	; Exchange address lines A0 and A3 from DL
-	mov		dh, MASK_A3_AND_A0_ADDRESS_LINES
-	and		dh, dl							; DH = 0, 1, 8 or 9, we can ignore 0 and 9
-	jz		SHORT .JumpToIoFunctionInSI		; Jump out since DH is 0
-	xor		dh, MASK_A3_AND_A0_ADDRESS_LINES
-	jz		SHORT .JumpToIoFunctionInSI		; Jump out since DH was 9
-	and		dl, ~MASK_A3_AND_A0_ADDRESS_LINES
-	or		dl, dh							; Address lines now reversed
-
-ALIGN JUMP_ALIGN
-.JumpToIoFunctionInSI:
-	push	bx
-	xor		dh, dh
-	eMOVZX	bx, BYTE [di+DPT.bIdevarsOffset]; CS:BX now points to IDEVARS
-	ret
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 159)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 160)
@@ -20,5 +20,5 @@
 	or		al, FLG_DEVCONTROL_SRST | FLG_DEVCONTROL_nIEN	; Set Reset bit
 	mov		dl, DEVICE_CONTROL_REGISTER_out
-	call	Device_OutputALtoIdeControlBlockRegisterInDL
+	call	IdeIO_OutputALtoIdeControlBlockRegisterInDL
 	mov		ax, HSR0_RESET_WAIT_US
 	call	Timer_DelayMicrosecondsFromAX
@@ -29,5 +29,5 @@
 	and		al, ~FLG_DEVCONTROL_SRST						; Clear reset bit
 	mov		dl, DEVICE_CONTROL_REGISTER_out
-	call	Device_OutputALtoIdeControlBlockRegisterInDL
+	call	IdeIO_OutputALtoIdeControlBlockRegisterInDL
 	mov		ax, HSR1_RESET_WAIT_US
 	call	Timer_DelayMicrosecondsFromAX
@@ -55,9 +55,8 @@
 	call	FindDPT_ForNewDriveToDSDI
 	eMOVZX	ax, bh
-	cmp		BYTE [cs:bp+IDEVARS.bDevice], DEVICE_XTIDE_WITH_REVERSED_A3_AND_A0
-	eCMOVE	ah, FLGH_DPT_REVERSED_A0_AND_A3
 	mov		[di+DPT.wFlags], ax
 	mov		[di+DPT.bIdevarsOffset], bp
 	mov		BYTE [di+DPT_ATA.bSetBlock], 1	; Block = 1 sector
+	call	IdeDPT_StoreReversedAddressLinesFlagIfNecessary
 
 	; Wait until drive motors have reached max speed
@@ -121,10 +120,10 @@
 .DoNotSetInterruptInServiceFlag:
 	mov		dl, DEVICE_CONTROL_REGISTER_out
-	call	Device_OutputALtoIdeControlBlockRegisterInDL
+	call	IdeIO_OutputALtoIdeControlBlockRegisterInDL
 
 	; Output Feature Number
 	mov		dl, FEATURES_REGISTER_out
 	mov		al, [bp+IDEPACK.bFeatures]
-	call	Device_OutputALtoIdeRegisterInDL
+	call	IdeIO_OutputALtoIdeRegisterInDL
 
 	; Output Sector Address High (only used by LBA48)
@@ -141,5 +140,5 @@
 	mov		dl, COMMAND_REGISTER_out
 	mov		al, [bp+IDEPACK.bCommand]
-	call	Device_OutputALtoIdeRegisterInDL
+	call	IdeIO_OutputALtoIdeRegisterInDL
 
 	; Wait until command completed
@@ -184,5 +183,5 @@
 	mov		dl, DRIVE_AND_HEAD_SELECT_REGISTER
 	mov		al, [bp+IDEPACK.bDrvAndHead]
-	call	Device_OutputALtoIdeRegisterInDL
+	call	IdeIO_OutputALtoIdeRegisterInDL
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRDY, FLG_STATUS_DRDY)
 	cmp		BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
@@ -207,15 +206,15 @@
 OutputSectorCountAndAddress:
 	mov		dl, SECTOR_COUNT_REGISTER
-	call	Device_OutputALtoIdeRegisterInDL
+	call	IdeIO_OutputALtoIdeRegisterInDL
 
 	mov		al, ah
 	mov		dl, LBA_LOW_REGISTER
-	call	Device_OutputALtoIdeRegisterInDL
+	call	IdeIO_OutputALtoIdeRegisterInDL
 
 	mov		al, cl
 	mov		dl, LBA_MIDDLE_REGISTER
-	call	Device_OutputALtoIdeRegisterInDL
+	call	IdeIO_OutputALtoIdeRegisterInDL
 
 	mov		al, ch
 	mov		dl, LBA_HIGH_REGISTER
-	jmp		Device_OutputALtoIdeRegisterInDL
+	jmp		IdeIO_OutputALtoIdeRegisterInDL
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDPT.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDPT.asm	(revision 159)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDPT.asm	(revision 160)
@@ -10,4 +10,5 @@
 ;		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
@@ -23,4 +24,5 @@
 ;		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
@@ -32,6 +34,20 @@
 	mov		ah, [es:si+ATA1.bBlckSize]		; Max block size in sectors
 	mov		[di+DPT_ATA.wSetAndMaxBlock], ax
-	; Fall to .EndDPT
+	; Fall to IdeDPT_StoreReversedAddressLinesFlagIfNecessary
 
+;--------------------------------------------------------------------
+; IdeDPT_StoreReversedAddressLinesFlagIfNecessary
+;	Parameters:
+;		DS:DI:	Ptr to Disk Parameter Table
+;		CS:BP:	Ptr to IDEVARS for the controller
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+IdeDPT_StoreReversedAddressLinesFlagIfNecessary:
+	cmp		BYTE [cs:bp+IDEVARS.bDevice], DEVICE_XTIDE_WITH_REVERSED_A3_AND_A0
+	jne		SHORT .EndDPT
+	or		BYTE [di+DPT.bFlagsHigh], FLGH_DPT_REVERSED_A0_AND_A3
 
 .EndDPT:
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeError.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeError.asm	(revision 159)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeError.asm	(revision 160)
@@ -21,5 +21,5 @@
 	mov		ah, al			; IDE Status Register to AH
 	mov		dl, ERROR_REGISTER_in
-	call	Device_InputToALfromIdeRegisterInDL
+	call	IdeIO_InputToALfromIdeRegisterInDL
 	xchg	al, ah			; Status Register now in AL, Error Register now in AH
 
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm	(revision 159)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm	(revision 160)
@@ -6,17 +6,18 @@
 
 ;--------------------------------------------------------------------
-; IdeIO_OutputALtoIdeRegisterInDX
+; IdeIO_OutputALtoIdeRegisterInDL
 ;	Parameters:
 ;		AL:		Byte to output
-;		DX:		IDE Register
-;		CS:BX:	Ptr to IDEVARS
+;		DL:		IDE Register
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
 ;	Returns:
 ;		Nothing
 ;	Corrupts registers:
-;		DX
+;		BX, DX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-IdeIO_OutputALtoIdeRegisterInDX:
-	add		dx, [cs:bx+IDEVARS.wPort]
+IdeIO_OutputALtoIdeRegisterInDL:
+	mov		bx, IDEVARS.wPort
+	call	GetPortToDXandTranslateA0andA3ifNecessary
 	out		dx, al
 	ret
@@ -24,17 +25,18 @@
 
 ;--------------------------------------------------------------------
-; IdeIO_OutputALtoIdeControlBlockRegisterInDX
+; IdeIO_OutputALtoIdeControlBlockRegisterInDL
 ;	Parameters:
 ;		AL:		Byte to output
-;		DX:		IDE Control Block Register
-;		CS:BX:	Ptr to IDEVARS
+;		DL:		IDE Control Block Register
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
 ;	Returns:
 ;		Nothing
 ;	Corrupts registers:
-;		DX
+;		BX, DX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-IdeIO_OutputALtoIdeControlBlockRegisterInDX:
-	add		dx, [cs:bx+IDEVARS.wPortCtrl]
+IdeIO_OutputALtoIdeControlBlockRegisterInDL:
+	mov		bx, IDEVARS.wPortCtrl
+	call	GetPortToDXandTranslateA0andA3ifNecessary
 	out		dx, al
 	ret
@@ -42,16 +44,49 @@
 
 ;--------------------------------------------------------------------
-; IdeIO_InputToALfromIdeRegisterInDX
+; IdeIO_InputToALfromIdeRegisterInDL
 ;	Parameters:
-;		DX:		IDE Register
-;		CS:BX:	Ptr to IDEVARS
+;		DL:		IDE Register
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
 ;	Returns:
 ;		AL:		Inputted byte
 ;	Corrupts registers:
-;		DX
+;		BX, DX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-IdeIO_InputToALfromIdeRegisterInDX:
-	add		dx, [cs:bx+IDEVARS.wPort]
+IdeIO_InputToALfromIdeRegisterInDL:
+	mov		bx, IDEVARS.wPort
+	call	GetPortToDXandTranslateA0andA3ifNecessary
 	in		al, dx
 	ret
+
+
+;--------------------------------------------------------------------
+; GetPortToDXandTranslateA0andA3ifNecessary
+;	Parameters:
+;		BX:		Offset to port in IDEVARS (IDEVARS.wPort or IDEVARS.wPortCtrl)
+;		DL:		IDE Register
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;	Returns:
+;		DX:		Source/Destination Port
+;	Corrupts registers:
+;		BX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+GetPortToDXandTranslateA0andA3ifNecessary:
+	xor		dh, dh							; DX now has IDE register offset
+	add		bl, [di+DPT.bIdevarsOffset]		; CS:BX now points port address
+	add		dx, [cs:bx]
+	test	BYTE [di+DPT.bFlagsHigh], FLGH_DPT_REVERSED_A0_AND_A3
+	jz		SHORT .ReturnPortInDX
+
+	; Exchange address lines A0 and A3 from DL
+	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
+	xor		bh, MASK_A3_AND_A0_ADDRESS_LINES
+	jz		SHORT .ReturnPortInDX			; Jump out since DH was 9
+	and		dl, ~MASK_A3_AND_A0_ADDRESS_LINES
+	or		dl, bh							; Address lines now reversed
+.ReturnPortInDX:
+	ret
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIrq.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIrq.asm	(revision 159)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIrq.asm	(revision 160)
@@ -111,5 +111,5 @@
 	call	FindDPT_ToDSDIforInterruptInService
 	mov		dl, STATUS_REGISTER_in
-	call	Device_InputToALfromIdeRegisterInDL
+	call	IdeIO_InputToALfromIdeRegisterInDL
 
 	; Clear Interrupt In-Service Flag from DPT
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeWait.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeWait.asm	(revision 159)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeWait.asm	(revision 160)
@@ -127,3 +127,3 @@
 ReadIdeStatusRegisterToAL:
 	mov		dl, STATUS_REGISTER_in
-	jmp		Device_InputToALfromIdeRegisterInDL
+	jmp		IdeIO_InputToALfromIdeRegisterInDL
Index: /trunk/XTIDE_Universal_BIOS/Src/Main.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 159)
+++ /trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 160)
@@ -64,5 +64,5 @@
 	at	ROMVARS.ideVars0+IDEVARS.wPortCtrl,		dw	3F0h			; Controller Control Block base port
 	at	ROMVARS.ideVars0+IDEVARS.bDevice,		db	DEVICE_16BIT_ATA
-	at	ROMVARS.ideVars0+IDEVARS.bIRQ,			db	14
+	at	ROMVARS.ideVars0+IDEVARS.bIRQ,			db	0
 	at	ROMVARS.ideVars0+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	db	FLG_DRVPARAMS_BLOCKMODE
 	at	ROMVARS.ideVars0+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	db	FLG_DRVPARAMS_BLOCKMODE
@@ -71,5 +71,5 @@
 	at	ROMVARS.ideVars1+IDEVARS.wPortCtrl,		dw	370h			; Controller Control Block base port
 	at	ROMVARS.ideVars1+IDEVARS.bDevice,		db	DEVICE_16BIT_ATA
-	at	ROMVARS.ideVars1+IDEVARS.bIRQ,			db	15
+	at	ROMVARS.ideVars1+IDEVARS.bIRQ,			db	0
 	at	ROMVARS.ideVars1+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	db	FLG_DRVPARAMS_BLOCKMODE
 	at	ROMVARS.ideVars1+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	db	FLG_DRVPARAMS_BLOCKMODE
Index: /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm	(revision 159)
+++ /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm	(revision 160)
@@ -103,4 +103,5 @@
 ;		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
@@ -131,4 +132,5 @@
 ;		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
@@ -164,4 +166,5 @@
 ;		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
@@ -181,4 +184,5 @@
 ;		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
@@ -195,4 +199,5 @@
 ;		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
 ;		ES:		BDA Segment
 ;	Returns:
