Index: trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm	(revision 157)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm	(revision 158)
@@ -16,5 +16,5 @@
 ;--------------------------------------------------------------------
 Device_FinalizeDPT:
-	test	WORD [di+DPT.wFlags], FLG_DPT_SERIAL_DEVICE
+	test	BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
 	jnz		SHORT ReturnSuccessForSerialPort
 	jmp		IdeDPT_Finalize
@@ -34,5 +34,5 @@
 ;--------------------------------------------------------------------
 Device_ResetMasterAndSlaveController:
-	test	WORD [di+DPT.wFlags], FLG_DPT_SERIAL_DEVICE
+	test	BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
 	jnz		SHORT ReturnSuccessForSerialPort
 	jmp		IdeCommand_ResetMasterAndSlaveController
@@ -76,5 +76,5 @@
 ALIGN JUMP_ALIGN
 Device_OutputCommandWithParameters:
-	test	WORD [di+DPT.wFlags], FLG_DPT_SERIAL_DEVICE
+	test	BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
 	jnz		SHORT .OutputCommandToSerialPort
 	jmp		IdeCommand_OutputWithParameters
@@ -97,5 +97,5 @@
 ALIGN JUMP_ALIGN
 Device_SelectDrive:
-	test	WORD [di+DPT.wFlags], FLG_DPT_SERIAL_DEVICE
+	test	BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
 	jnz		SHORT ReturnSuccessForSerialPort
 	jmp		IdeCommand_SelectDrive
@@ -168,5 +168,5 @@
 ;--------------------------------------------------------------------
 TranslateRegisterAddressInDLifNecessaryThenJumpToBX:
-	test	WORD [di+DPT.wFlags], FLG_DPT_REVERSED_A0_AND_A3
+	test	BYTE [di+DPT.bFlagsHigh], FLGH_DPT_REVERSED_A0_AND_A3
 	jz		SHORT .JumpToIoFunctionInSI
 
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 157)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 158)
@@ -54,8 +54,7 @@
 	; Create fake DPT to be able to use Device.asm functions
 	call	FindDPT_ForNewDriveToDSDI
-	xor		ax, ax
+	eMOVZX	ax, bh
 	cmp		BYTE [cs:bp+IDEVARS.bDevice], DEVICE_XTIDE_WITH_REVERSED_A3_AND_A0
-	eCMOVE	ax, FLG_DPT_REVERSED_A0_AND_A3
-	or		al, bh
+	eCMOVE	ah, FLGH_DPT_REVERSED_A0_AND_A3
 	mov		[di+DPT.wFlags], ax
 	mov		[di+DPT.bIdevarsOffset], bp
@@ -65,5 +64,5 @@
 	cmp		bp, BYTE ROMVARS.ideVars0
 	jne		SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
-	test	bh, FLG_DRVNHEAD_DRV
+	test	al, FLG_DRVNHEAD_DRV
 	jnz		SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_BSY)
@@ -82,5 +81,5 @@
 
 	; Clean stack and return
-	lea		sp, [bp+SIZE_OF_FAKE_IDEPACK]	; This assumes BP hasn't changed between Idepack_FakeToSSBP and here
+	lea		sp, [bp+EXTRA_BYTES_FOR_INTPACK]	; This assumes BP hasn't changed between Idepack_FakeToSSBP and here
 	pop		bp
 	ret
@@ -103,5 +102,5 @@
 ALIGN JUMP_ALIGN
 IdeCommand_OutputWithParameters:
-	push	bx							; Store status register bits to poll
+	push	bx						; Store status register bits to poll
 
 	; Select Master or Slave drive and output head number or LBA28 top bits
@@ -110,14 +109,16 @@
 
 	; Output Device Control Byte to enable or disable interrupts
-	mov		dl, DEVICE_CONTROL_REGISTER_out
 	mov		al, [bp+IDEPACK.bDeviceControl]
-	test	al, FLG_DEVCONTROL_nIEN
+	test	al, FLG_DEVCONTROL_nIEN	; Interrupts disabled?
 	jnz		SHORT .DoNotSetInterruptInServiceFlag
-	or		WORD [di+DPT.wFlags], FLG_DPT_INTERRUPT_IN_SERVICE
+
+	; Clear Task Flag and set Interrupt In-Service Flag
+	or		BYTE [di+DPT.bFlagsHigh], FLGH_DPT_INTERRUPT_IN_SERVICE
 	push	ds
-	LOAD_BDA_SEGMENT_TO	ds, cx, !		; Also zero CX
-	mov		[BDA.bHDTaskFlg], al
+	LOAD_BDA_SEGMENT_TO	ds, dx, !	; Also zero DX
+	mov		[BDA.bHDTaskFlg], dl
 	pop		ds
 .DoNotSetInterruptInServiceFlag:
+	mov		dl, DEVICE_CONTROL_REGISTER_out
 	call	Device_OutputALtoIdeControlBlockRegisterInDL
 
@@ -143,7 +144,7 @@
 
 	; Wait until command completed
-	pop		bx							; Pop status and timeout for polling
-	cmp		bl, FLG_STATUS_DRQ			; Data transfer started?
-	je		SHORT .StartDataTransfer
+	pop		bx						; Pop status and timeout for polling
+	cmp		bl, FLG_STATUS_DRQ		; Data transfer started?
+	je		SHORT IdeTransfer_StartWithCommandInAL
 	test	BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
 	jz		SHORT .WaitForIrqOrRdy
@@ -153,7 +154,4 @@
 .WaitForIrqOrRdy:
 	jmp		IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
-ALIGN JUMP_ALIGN
-.StartDataTransfer:
-	jmp		IdeTransfer_StartWithCommandInAL
 
 .DriveNotReady:
@@ -179,5 +177,5 @@
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
 	cmp		BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
-	eCMOVE	bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_IDENTIFY_DEVICE, FLG_STATUS_BSY)
+	eCMOVE	bh, TIMEOUT_IDENTIFY_DEVICE
 	call	IdeWait_PollStatusFlagInBLwithTimeoutInBH
 	jc		SHORT ReturnSinceTimeoutWhenPollingBusy
@@ -189,5 +187,5 @@
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRDY, FLG_STATUS_DRDY)
 	cmp		BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
-	eCMOVE	bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_IDENTIFY_DEVICE, FLG_STATUS_DRDY)
+	eCMOVE	bh, TIMEOUT_IDENTIFY_DEVICE
 	jmp		IdeWait_PollStatusFlagInBLwithTimeoutInBH
 
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIrq.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIrq.asm	(revision 157)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIrq.asm	(revision 158)
@@ -114,5 +114,5 @@
 
 	; Clear Interrupt In-Service Flag from DPT
-	and		WORD [di+DPT.wFlags], ~FLG_DPT_INTERRUPT_IN_SERVICE
+	and		BYTE [di+DPT.bFlagsHigh], ~FLGH_DPT_INTERRUPT_IN_SERVICE
 
 	; Set Task Flag
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 157)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 158)
@@ -166,5 +166,5 @@
 ; InitializePiovarsInSSBPwithSectorCountInAX
 ;	Parameters:
-;		AX:		Number of sectors to transfer (0=65536)
+;		AX:		Number of sectors to transfer (1...65535)
 ;		BX:		Offset to transfer function lookup table
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
@@ -179,7 +179,5 @@
 	; Store number of blocks to transfer
 	eMOVZX	cx, BYTE [di+DPT_ATA.bSetBlock]		; Block size in sectors
-	xor		dx, dx
-	test	ax, ax
-	eCMOVZ	dl, 1		; DX:AX = Sectors to transfer (1...65536)
+	xor		dx, dx		; DX:AX = Sectors to transfer (1...65535)
 	div		cx			; AX = Full blocks to transfer
 	test	dx, dx
@@ -197,5 +195,5 @@
 
 	; Get transfer function based on bus type
-	xchg	ax, bx
+	xchg	ax, bx								; Lookup table offset to AX
 	eMOVZX	bx, BYTE [di+DPT.bIdevarsOffset]	; CS:BX now points to IDEVARS
 	mov		dx, [cs:bx+IDEVARS.wPort]			; Load IDE Data port address
Index: trunk/XTIDE_Universal_BIOS/Src/Device/Idepack.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/Idepack.asm	(revision 157)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/Idepack.asm	(revision 158)
@@ -1,6 +1,4 @@
 ; Project name	:	XTIDE Universal BIOS
 ; Description	:	Functions for managing IDEPACK struct.
-
-SIZE_OF_FAKE_IDEPACK		EQU		(IDEPACK_size - INTPACK_size)
 
 ; Section containing code
@@ -18,5 +16,5 @@
 Idepack_FakeToSSBP:
 	pop		ax
-	sub		sp, BYTE SIZE_OF_FAKE_IDEPACK
+	sub		sp, BYTE EXTRA_BYTES_FOR_INTPACK
 	mov		bp, sp
 	jmp		ax
