Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IOMappedIDE.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IOMappedIDE.inc	(revision 238)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IOMappedIDE.inc	(revision 238)
@@ -0,0 +1,69 @@
+; Project name	:	XTIDE Universal BIOS
+; Description	:	Macros for normal I/O mapped ATA controllers.
+
+%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 233)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 238)
@@ -15,10 +15,9 @@
 ;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
-IdeCommand_ResetMasterAndSlaveController:
+IDEDEVICE%+Command_ResetMasterAndSlaveController:
 	; HSR0: Set_SRST
 	call	AccessDPT_GetDeviceControlByteToAL
 	or		al, FLG_DEVCONTROL_SRST | FLG_DEVCONTROL_nIEN	; Set Reset bit
-	mov		dl, DEVICE_CONTROL_REGISTER_out
-	call	IdeIO_OutputALtoIdeControlBlockRegisterInDL
+	OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER DEVICE_CONTROL_REGISTER_out
 	mov		ax, HSR0_RESET_WAIT_US
 	call	Timer_DelayMicrosecondsFromAX
@@ -28,6 +27,5 @@
 	or		al, FLG_DEVCONTROL_nIEN
 	and		al, ~FLG_DEVCONTROL_SRST						; Clear reset bit
-	mov		dl, DEVICE_CONTROL_REGISTER_out
-	call	IdeIO_OutputALtoIdeControlBlockRegisterInDL
+	OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER DEVICE_CONTROL_REGISTER_out
 	mov		ax, HSR1_RESET_WAIT_US
 	call	Timer_DelayMicrosecondsFromAX
@@ -35,5 +33,5 @@
 	; HSR2: Check_status
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_BSY)
-	jmp		IdeWait_PollStatusFlagInBLwithTimeoutInBH
+	jmp		IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
 
 
@@ -51,5 +49,5 @@
 ;		AL, BL, CX, DX, SI, DI, ES
 ;--------------------------------------------------------------------
-IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH:
+IDEDEVICE%+Command_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH:
 	; Create fake DPT to be able to use Device.asm functions
 	call	FindDPT_ForNewDriveToDSDI
@@ -66,5 +64,5 @@
 	jnz		SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_BSY)
-	call	IdeWait_PollStatusFlagInBLwithTimeoutInBH
+	call	IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
 .SkipLongWaitSinceDriveIsNotPrimaryMaster:
 
@@ -100,9 +98,9 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-IdeCommand_OutputWithParameters:
+IDEDEVICE%+Command_OutputWithParameters:
 	push	bx						; Store status register bits to poll
 
 	; Select Master or Slave drive and output head number or LBA28 top bits
-	call	IdeCommand_SelectDrive
+	call	IDEDEVICE%+Command_SelectDrive
 	jc		SHORT .DriveNotReady
 
@@ -119,11 +117,9 @@
 	pop		ds
 .DoNotSetInterruptInServiceFlag:
-	mov		dl, DEVICE_CONTROL_REGISTER_out
-	call	IdeIO_OutputALtoIdeControlBlockRegisterInDL
+	OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER DEVICE_CONTROL_REGISTER_out
 
 	; Output Feature Number
-	mov		dl, FEATURES_REGISTER_out
 	mov		al, [bp+IDEPACK.bFeatures]
-	call	IdeIO_OutputALtoIdeRegisterInDL
+	OUTPUT_AL_TO_IDE_REGISTER FEATURES_REGISTER_out
 
 	; Output Sector Address High (only used by LBA48)
@@ -138,23 +134,22 @@
 
 	; Output command
-	mov		dl, COMMAND_REGISTER_out
 	mov		al, [bp+IDEPACK.bCommand]
-	call	IdeIO_OutputALtoIdeRegisterInDL
+	OUTPUT_AL_TO_IDE_REGISTER COMMAND_REGISTER_out
 
 	; Wait until command completed
 	pop		bx						; Pop status and timeout for polling
 	cmp		bl, FLG_STATUS_DRQ		; Data transfer started?
-	je		SHORT IdeTransfer_StartWithCommandInAL
+	je		SHORT IDEDEVICE%+Transfer_StartWithCommandInAL
 	test	BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
 	jz		SHORT .WaitForIrqOrRdy
-	jmp		IdeWait_PollStatusFlagInBLwithTimeoutInBH
+	jmp		IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
 
 ALIGN JUMP_ALIGN
 .WaitForIrqOrRdy:
-	jmp		IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
+	jmp		IDEDEVICE%+Wait_IRQorStatusFlagInBLwithTimeoutInBH
 
 .DriveNotReady:
 	pop		bx							; Clean stack
-ReturnSinceTimeoutWhenPollingBusy:
+IDEDEVICE%+ReturnSinceTimeoutWhenPollingBusy:
 	ret
 
@@ -172,20 +167,19 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-IdeCommand_SelectDrive:
+IDEDEVICE%+Command_SelectDrive:
 	; Wait until neither Master or Slave Drive is busy
 	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	IdeWait_PollStatusFlagInBLwithTimeoutInBH
-	jc		SHORT ReturnSinceTimeoutWhenPollingBusy
+	call	IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
+	jc		SHORT IDEDEVICE%+ReturnSinceTimeoutWhenPollingBusy
 
 	; Select Master or Slave Drive
-	mov		dl, DRIVE_AND_HEAD_SELECT_REGISTER
 	mov		al, [bp+IDEPACK.bDrvAndHead]
-	call	IdeIO_OutputALtoIdeRegisterInDL
+	OUTPUT_AL_TO_IDE_REGISTER DRIVE_AND_HEAD_SELECT_REGISTER
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRDY, FLG_STATUS_DRDY)
 	cmp		BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
 	eCMOVE	bh, TIMEOUT_IDENTIFY_DEVICE
-	jmp		IdeWait_PollStatusFlagInBLwithTimeoutInBH
+	jmp		IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
 
 
@@ -203,18 +197,16 @@
 ;		AL, BX, DX
 ;--------------------------------------------------------------------
+%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS
 ALIGN JUMP_ALIGN
 OutputSectorCountAndAddress:
-	mov		dl, SECTOR_COUNT_REGISTER
-	call	IdeIO_OutputALtoIdeRegisterInDL
+	OUTPUT_AL_TO_IDE_REGISTER SECTOR_COUNT_REGISTER
 
 	mov		al, ah
-	mov		dl, LBA_LOW_REGISTER
-	call	IdeIO_OutputALtoIdeRegisterInDL
+	OUTPUT_AL_TO_IDE_REGISTER LBA_LOW_REGISTER
 
 	mov		al, cl
-	mov		dl, LBA_MIDDLE_REGISTER
-	call	IdeIO_OutputALtoIdeRegisterInDL
+	OUTPUT_AL_TO_IDE_REGISTER LBA_MIDDLE_REGISTER
 
 	mov		al, ch
-	mov		dl, LBA_HIGH_REGISTER
-	jmp		IdeIO_OutputALtoIdeRegisterInDL
+	JUMP_TO_OUTPUT_AL_TO_IDE_REGISTER LBA_HIGH_REGISTER
+%endif
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeError.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeError.asm	(revision 233)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeError.asm	(revision 238)
@@ -18,8 +18,7 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL:
+IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL:
 	mov		ah, al			; IDE Status Register to AH
-	mov		dl, ERROR_REGISTER_in
-	call	IdeIO_InputToALfromIdeRegisterInDL
+	INPUT_TO_AL_FROM_IDE_REGISTER ERROR_REGISTER_in
 	xchg	al, ah			; Status Register now in AL, Error Register now in AH
 
@@ -45,4 +44,5 @@
 ;		BX
 ;--------------------------------------------------------------------
+%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS
 ALIGN JUMP_ALIGN
 GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX:
@@ -92,2 +92,3 @@
 	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/IdeIrq.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIrq.asm	(revision 233)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIrq.asm	(revision 238)
@@ -111,6 +111,5 @@
 	mov		bl, FLGH_DPT_INTERRUPT_IN_SERVICE
 	call	FindDPT_ToDSDIforFlagsHighInBL
-	mov		dl, STATUS_REGISTER_in
-	call	IdeIO_InputToALfromIdeRegisterInDL
+	INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
 
 	; Clear Interrupt In-Service Flag from DPT
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 233)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 238)
@@ -97,10 +97,11 @@
 .WriteLastBlockToDrive:
 	mov		cx, [bp+PIOVARS.wWordsLeft]
+%ifdef USE_186
+	push	CheckErrorsAfterTransferringLastBlock
+	jmp		[bp+PIOVARS.fnXfer]					; Transfer possibly partial block
+%else
 	call	[bp+PIOVARS.fnXfer]					; Transfer possibly partial block
-
-	; Check for errors in last block
-	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRDY)
-	call	IdeWait_PollStatusFlagInBLwithTimeoutInBH
-	jmp		SHORT ReturnWithTransferErrorInAH
+	jmp		SHORT CheckErrorsAfterTransferringLastBlock
+%endif
 
 
@@ -155,4 +156,5 @@
 	; Check for errors in last block
 	mov		di, si								; DS:DI now points DPT
+CheckErrorsAfterTransferringLastBlock:
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRDY)
 	call	IdeWait_PollStatusFlagInBLwithTimeoutInBH
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeWait.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeWait.asm	(revision 233)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeWait.asm	(revision 238)
@@ -16,8 +16,10 @@
 ;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
-IdeWait_IRQorDRQ:
+IDEDEVICE%+Wait_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
 	test	BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
-	jnz		SHORT IdeWait_PollStatusFlagInBLwithTimeoutInBH	; Interrupt disabled
+	jnz		SHORT IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH	; Interrupt disabled
+%endif
 	; Fall to IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
 
@@ -35,6 +37,8 @@
 ;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
-IdeWait_IRQorStatusFlagInBLwithTimeoutInBH:
+IDEDEVICE%+Wait_IRQorStatusFlagInBLwithTimeoutInBH:
+%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS		; JR-IDE/ISA does not support IRQ
 	call	IdeIrq_WaitForIRQ
+%endif
 	; Always fall to IdeWait_PollStatusFlagInBLwithTimeoutInBH for error processing
 
@@ -52,10 +56,10 @@
 ;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
-IdeWait_PollStatusFlagInBLwithTimeoutInBH:
+IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH:
 	mov		ah, bl
 	mov		cl, bh
 	call	Timer_InitializeTimeoutWithTicksInCL
 	and		ah, ~FLG_STATUS_BSY
-	jz		SHORT PollBsyOnly
+	jz		SHORT IDEDEVICE%+PollBsyOnly
 	; Fall to PollBsyAndFlgInAH
 
@@ -72,17 +76,18 @@
 ;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
+%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS
 PollBsyAndFlgInAH:
-	call	ReadIdeStatusRegisterToAL			; Discard contents for first read
+	call	IDEDEVICE%+ReadIdeStatusRegisterToAL; Discard contents for first read
 ALIGN JUMP_ALIGN
 .PollLoop:
-	call	ReadIdeStatusRegisterToAL
+	call	IDEDEVICE%+ReadIdeStatusRegisterToAL
 	test	al, FLG_STATUS_BSY					; Controller busy?
 	jnz		SHORT .UpdateTimeout				;  If so, jump to timeout update
 	test	al, ah								; Test secondary flag
-	jnz		SHORT IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
+	jnz		SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
 .UpdateTimeout:
 	call	Timer_SetCFifTimeout
 	jnc		SHORT .PollLoop						; Loop if time left
-	call	IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
+	call	IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
 	jc		SHORT .ReturnErrorCodeInAH
 	mov		ah, RET_HD_TIMEOUT					; Expected bit never got set
@@ -90,4 +95,5 @@
 .ReturnErrorCodeInAH:
 	ret
+%endif
 
 
@@ -103,14 +109,14 @@
 ;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
-PollBsyOnly:
-	call	ReadIdeStatusRegisterToAL			; Discard contents for first read
+IDEDEVICE%+PollBsyOnly:
+	call	IDEDEVICE%+ReadIdeStatusRegisterToAL; Discard contents for first read
 ALIGN JUMP_ALIGN
 .PollLoop:
-	call	ReadIdeStatusRegisterToAL
+	call	IDEDEVICE%+ReadIdeStatusRegisterToAL
 	test	al, FLG_STATUS_BSY					; Controller busy?
-	jz		SHORT IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
+	jz		SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
 	call	Timer_SetCFifTimeout				; Update timeout counter
 	jnc		SHORT .PollLoop						; Loop if time left (sets CF on timeout)
-	jmp		SHORT IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
+	jmp		SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
 
 
@@ -125,5 +131,4 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-ReadIdeStatusRegisterToAL:
-	mov		dl, STATUS_REGISTER_in
-	jmp		IdeIO_InputToALfromIdeRegisterInDL
+IDEDEVICE%+ReadIdeStatusRegisterToAL:
+	JUMP_TO_INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
