Index: trunk/XTIDE_Universal_BIOS/Inc/BootVars.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/BootVars.inc	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Inc/BootVars.inc	(revision 589)
@@ -41,5 +41,5 @@
 	.dwPostStack		resb	4		; POST stack pointer when entering INT 19h
 %ifdef MODULE_HOTKEYS
-	.hotkeyVars				resb	HOTKEYVARS_size
+	.hotkeyVars			resb	HOTKEYVARS_size
 %endif
 	.rgDrvDetectInfo:					; Array containing DRVDETECTINFO structs
Index: trunk/XTIDE_Universal_BIOS/Inc/Controllers/AdvancedID.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/Controllers/AdvancedID.inc	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Inc/Controllers/AdvancedID.inc	(revision 589)
@@ -32,7 +32,7 @@
 ; Vision
 ; QDI Vision Controller Identification nibbles used by hardware so do not modify these
-ID_QD6580_ALTERNATE			EQU		5
-ID_QD6580					EQU		10
-ID_QD6500					EQU		12
+ID_QD6580_ALTERNATE			EQU		80
+ID_QD6580					EQU		160
+ID_QD6500					EQU		192
 
 
Index: trunk/XTIDE_Universal_BIOS/Inc/Controllers/PDC20x30.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/Controllers/PDC20x30.inc	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Inc/Controllers/PDC20x30.inc	(revision 589)
@@ -2,6 +2,4 @@
 ; Description	:	Promise PDC 20230-C and 20630 VLB IDE controller
 ;					specifications.
-;
-;					Specifications can be found at 
 
 ;
Index: trunk/XTIDE_Universal_BIOS/Inc/Controllers/XTCF.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/Controllers/XTCF.inc	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Inc/Controllers/XTCF.inc	(revision 589)
@@ -56,8 +56,8 @@
 ; the mode via a call to Int 13h function 1Eh accordingly (see AH1Eh_XTCF.asm).
 ;
-XTCF_8BIT_PIO_MODE					EQU		0	; XT-CF using 8-bit PIO mode
-XTCF_8BIT_PIO_MODE_WITH_BIU_OFFLOAD	EQU		1	; XT-CF using 8-bit PIO mode, but with 16-bit instructions
-XTCF_16BIT_PIO_WITH_BIU_OFFLOAD		EQU		2	; Lo-tech 8-bit IDE Adapter
-XTCF_DMA_MODE						EQU		3	; XT-CFv3 using DMA
+XTCF_8BIT_PIO_MODE						EQU		0	; XT-CF using 8-bit PIO mode
+XTCF_8BIT_PIO_MODE_WITH_BIU_OFFLOAD		EQU		1	; XT-CF using 8-bit PIO mode, but with 16-bit instructions
+XTCF_16BIT_PIO_MODE_WITH_BIU_OFFLOAD	EQU		2	; Lo-tech 8-bit IDE Adapter
+XTCF_DMA_MODE							EQU		3	; XT-CFv3 using DMA
 
 
Index: trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc	(revision 589)
@@ -84,5 +84,5 @@
 
 
-	; Flags for DPT_ADVANCED_ATA.bInitError
+	; Flags for DPT.bInitError
 	FLG_INITERROR_FAILED_TO_SELECT_DRIVE				EQU (1<<0)
 	FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS	EQU (1<<1)
Index: trunk/XTIDE_Universal_BIOS/Inc/IDE_8bit.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/IDE_8bit.inc	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Inc/IDE_8bit.inc	(revision 589)
@@ -21,46 +21,4 @@
 %ifndef IDE_8BIT_INC
 %define IDE_8BIT_INC
-
-;--------------------------------------------------------------------
-; UNROLL_SECTORS_IN_CX_TO_DWORDS
-; UNROLL_SECTORS_IN_CX_TO_QWORDS
-; UNROLL_SECTORS_IN_CX_TO_OWORDS
-;	Parameters:
-;		CX:		Number of sectors in block
-;	Returns:
-;		CX:		Number of DWORDs, QWORDs or OWORDs in block
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-%macro UNROLL_SECTORS_IN_CX_TO_DWORDS 0
-%ifdef USE_186
-	shl		cx, 7
-%else
-	xchg	cl, ch		; Sectors to WORDs (SHL CX, 8)
-	shr		cx, 1
-%endif
-%endmacro
-
-%macro UNROLL_SECTORS_IN_CX_TO_QWORDS 0
-%ifdef USE_186
-	shl		cx, 6
-%else
-	UNROLL_SECTORS_IN_CX_TO_DWORDS
-	shr		cx, 1
-%endif
-%endmacro
-
-%macro UNROLL_SECTORS_IN_CX_TO_OWORDS 0
-%ifdef USE_186
-	shl		cx, 5
-%else
-;	UNROLL_SECTORS_IN_CX_TO_QWORDS
-;	shr		cx, 1
-	mov		ch, cl		; 2 bytes shorter but possibly slower
-	mov		cl, 3
-	shr		cx, cl
-%endif
-%endmacro
-
 
 ;--------------------------------------------------------------------
Index: trunk/XTIDE_Universal_BIOS/Inc/IdeIO.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/IdeIO.inc	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Inc/IdeIO.inc	(revision 589)
@@ -105,3 +105,45 @@
 
 
+;--------------------------------------------------------------------
+; UNROLL_SECTORS_IN_CX_TO_DWORDS
+; UNROLL_SECTORS_IN_CX_TO_QWORDS
+; UNROLL_SECTORS_IN_CX_TO_OWORDS
+;	Parameters:
+;		CX:		Number of sectors in block
+;	Returns:
+;		CX:		Number of DWORDs, QWORDs or OWORDs in block
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+%macro UNROLL_SECTORS_IN_CX_TO_DWORDS 0
+%ifdef USE_186
+	shl		cx, 7
+%else
+	xchg	cl, ch		; Sectors to WORDs (SHL CX, 8)
+	shr		cx, 1
+%endif
+%endmacro
+
+%macro UNROLL_SECTORS_IN_CX_TO_QWORDS 0
+%ifdef USE_186
+	shl		cx, 6
+%else
+	UNROLL_SECTORS_IN_CX_TO_DWORDS
+	shr		cx, 1
+%endif
+%endmacro
+
+%macro UNROLL_SECTORS_IN_CX_TO_OWORDS 0
+%ifdef USE_186
+	shl		cx, 5
+%else
+;	UNROLL_SECTORS_IN_CX_TO_QWORDS
+;	shr		cx, 1
+	mov		ch, cl		; 2 bytes shorter but possibly slower
+	mov		cl, 3
+	shr		cx, cl
+%endif
+%endmacro
+
+
 %endif ; IDE_IO_INC
Index: trunk/XTIDE_Universal_BIOS/Inc/ModuleDependency.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/ModuleDependency.inc	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Inc/ModuleDependency.inc	(revision 589)
@@ -26,5 +26,4 @@
 %endif
 
-
 %ifdef MODULE_SERIAL_FLOPPY
 	%ifndef MODULE_SERIAL
@@ -41,5 +40,4 @@
 %endif
 
-; Include module specific .INC files
 %ifdef MODULE_8BIT_IDE
 	%include "IDE_8bit.inc"			; For IDE 8-bit data port macros
@@ -47,4 +45,7 @@
 
 %ifdef MODULE_ADVANCED_ATA
+	%ifndef USE_386
+		%error "MODULE_ADVANCED_ATA requires USE_386!"
+	%endif
 	%include "AdvancedID.inc"
 	%include "PDC20x30.inc"			; For Promise PDC 20230-C and 20630 controllers
@@ -79,49 +80,49 @@
 ; Included modules for ROMVARS.wFlags
 %ifdef MODULE_8BIT_IDE
-	MAIN_FLG_MODULE_8BIT_IDE	EQU	FLG_ROMVARS_MODULE_8BIT_IDE
+	MAIN_FLG_MODULE_8BIT_IDE			EQU	FLG_ROMVARS_MODULE_8BIT_IDE
 %else
-	MAIN_FLG_MODULE_8BIT_IDE	EQU	0
+	MAIN_FLG_MODULE_8BIT_IDE			EQU	0
 %endif
 
 %ifdef MODULE_ADVANCED_ATA
-	MAIN_FLG_MODULE_ADVANCED_ATA	EQU	FLG_ROMVARS_MODULE_ADVANCED_ATA
+	MAIN_FLG_MODULE_ADVANCED_ATA		EQU	FLG_ROMVARS_MODULE_ADVANCED_ATA
 %else
-	MAIN_FLG_MODULE_ADVANCED_ATA	EQU	0
+	MAIN_FLG_MODULE_ADVANCED_ATA		EQU	0
 %endif
 
 %ifdef MODULE_BOOT_MENU
-	MAIN_FLG_MODULE_BOOT_MENU	EQU	FLG_ROMVARS_MODULE_BOOT_MENU
+	MAIN_FLG_MODULE_BOOT_MENU			EQU	FLG_ROMVARS_MODULE_BOOT_MENU
 %else
-	MAIN_FLG_MODULE_BOOT_MENU	EQU	0
+	MAIN_FLG_MODULE_BOOT_MENU			EQU	0
 %endif
 
 %ifdef MODULE_EBIOS
-	MAIN_FLG_MODULE_EBIOS	EQU	FLG_ROMVARS_MODULE_EBIOS
+	MAIN_FLG_MODULE_EBIOS				EQU	FLG_ROMVARS_MODULE_EBIOS
 %else
-	MAIN_FLG_MODULE_EBIOS	EQU	0
+	MAIN_FLG_MODULE_EBIOS				EQU	0
 %endif
 
 %ifdef MODULE_HOTKEYS
-	MAIN_FLG_MODULE_HOTKEYS	EQU	FLG_ROMVARS_MODULE_HOTKEYS
+	MAIN_FLG_MODULE_HOTKEYS				EQU	FLG_ROMVARS_MODULE_HOTKEYS
 %else
-	MAIN_FLG_MODULE_HOTKEYS	EQU	0
+	MAIN_FLG_MODULE_HOTKEYS				EQU	0
 %endif
 
 %ifdef MODULE_IRQ
-	MAIN_FLG_MODULE_IRQ		EQU	FLG_ROMVARS_MODULE_IRQ
+	MAIN_FLG_MODULE_IRQ					EQU	FLG_ROMVARS_MODULE_IRQ
 %else
-	MAIN_FLG_MODULE_IRQ		EQU	0
+	MAIN_FLG_MODULE_IRQ					EQU	0
 %endif
 
 %ifdef MODULE_SERIAL
-	MAIN_FLG_MODULE_SERIAL	EQU	FLG_ROMVARS_MODULE_SERIAL
+	MAIN_FLG_MODULE_SERIAL				EQU	FLG_ROMVARS_MODULE_SERIAL
 %else
-	MAIN_FLG_MODULE_SERIAL	EQU	0
+	MAIN_FLG_MODULE_SERIAL				EQU	0
 %endif
 
 %ifdef MODULE_SERIAL_FLOPPY
-	MAIN_FLG_MODULE_SERIAL_FLOPPY	EQU	FLG_ROMVARS_MODULE_SERIAL_FLOPPY
+	MAIN_FLG_MODULE_SERIAL_FLOPPY		EQU	FLG_ROMVARS_MODULE_SERIAL_FLOPPY
 %else
-	MAIN_FLG_MODULE_SERIAL_FLOPPY	EQU	0
+	MAIN_FLG_MODULE_SERIAL_FLOPPY		EQU	0
 %endif
 
@@ -145,3 +146,2 @@
 
 MASK_ROMVARS_INCLUDED_MODULES	EQU	MAIN_FLG_MODULE_8BIT_IDE | MAIN_FLG_MODULE_ADVANCED_ATA | MAIN_FLG_MODULE_BOOT_MENU | MAIN_FLG_MODULE_EBIOS | MAIN_FLG_MODULE_HOTKEYS | MAIN_FLG_MODULE_IRQ | MAIN_FLG_MODULE_SERIAL | MAIN_FLG_MODULE_SERIAL_FLOPPY | MAIN_FLG_MODULE_STRINGS_COMPRESSED | MAIN_FLG_MODULE_POWER_MANAGEMENT | MAIN_FLG_MODULE_8BIT_IDE_ADVANCED
-
Index: trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 589)
@@ -132,4 +132,6 @@
 %endif
 
+							alignb	2	; Keep the INTPACK structure and stack pointer WORD aligned
+
 	.intpack				resb	INTPACK_size
 endstruc
Index: trunk/XTIDE_Universal_BIOS/Inc/RomVars.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/RomVars.inc	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Inc/RomVars.inc	(revision 589)
@@ -71,5 +71,6 @@
 												; (Conveniently, this is 8, a fact we exploit when testing the bit)
 
-; Here in case the configuration needs to know functionality is present
+; Here in case the configuration needs to know functionality is present. Note! Changing the order/location of these flags
+; also requires changes elsewhere as they are usually tested using byte-accesses for efficiency.
 FLG_ROMVARS_MODULE_POWER_MANAGEMENT		EQU	(1<<5)
 FLG_ROMVARS_MODULE_8BIT_IDE				EQU	(1<<6)
@@ -146,5 +147,4 @@
 ; Device types for IDEVARS.bDevice
 ; IDE Devices are grouped so device numbers cannot be changed without modifying code elsewhere!
-; (IdeTransfer.asm)
 COUNT_OF_STANDARD_IDE_DEVICES			EQU	2	; 16- and 32-bit controllers
 COUNT_OF_8BIT_IDE_DEVICES				EQU	9
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 589)
@@ -33,6 +33,10 @@
 IdeCommand_ResetMasterAndSlaveController:
 	; HSR0: Set_SRST
-	call	AccessDPT_GetDeviceControlByteToAL
-	or		al, FLG_DEVCONTROL_SRST | FLG_DEVCONTROL_nIEN	; Set Reset bit
+; Used to be:
+;	call	AccessDPT_GetDeviceControlByteToAL
+;	or		al, FLG_DEVCONTROL_SRST | FLG_DEVCONTROL_nIEN	; Set Reset bit
+; Is now:
+	mov		al, FLG_DEVCONTROL_SRST | FLG_DEVCONTROL_nIEN
+; ---
 	OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER		DEVICE_CONTROL_REGISTER_out
 	mov		ax, HSR0_RESET_WAIT_US
@@ -40,7 +44,11 @@
 
 	; HSR1: Clear_wait
-	call	AccessDPT_GetDeviceControlByteToAL
-	or		al, FLG_DEVCONTROL_nIEN
-	and		al, ~FLG_DEVCONTROL_SRST						; Clear reset bit
+; Used to be:
+;	call	AccessDPT_GetDeviceControlByteToAL
+;	or		al, FLG_DEVCONTROL_nIEN
+;	and		al, ~FLG_DEVCONTROL_SRST						; Clear reset bit
+; Is now:
+	mov		al, FLG_DEVCONTROL_nIEN
+; ---
 	OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER		DEVICE_CONTROL_REGISTER_out
 	mov		ax, HSR1_RESET_WAIT_US
@@ -51,4 +59,11 @@
 	jmp		IdeWait_PollStatusFlagInBLwithTimeoutInBH
 
+; *FIXME* AccessDPT_GetDeviceControlByteToAL currently always returns with
+; AL cleared (0) or with only bit 1 set (FLG_DEVCONTROL_nIEN = 2).
+; The commented away instructions above sets FLG_DEVCONTROL_nIEN anyway
+; making the call to AccessDPT_GetDeviceControlByteToAL redundant.
+; I have left this code as is since I don't know if it's a mistake
+; (from all the way back to r150) or if it's coded this way in anticipation
+; of some future changes to AccessDPT_GetDeviceControlByteToAL.
 
 ;--------------------------------------------------------------------
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDmaBlock.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDmaBlock.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDmaBlock.asm	(revision 589)
@@ -94,9 +94,9 @@
 	; When DI is zero only one transfer is required since we've limited the
 	; XT-CFv3 block size to 32k
-	jnc		SHORT .TransferLastDmaPageWithSizeInCX
+	jnc		SHORT StartDMAtransferForXTCFwithDmaModeInBL
 
 	; CF was set, so DI != 0 and we might need one or two transfers
-	cmp		cx, ax									; if we won't cross a physical page boundary...
-	jbe		SHORT .TransferLastDmaPageWithSizeInCX	; ...perform the transfer in one operation
+	cmp		cx, ax											; if we won't cross a physical page boundary...
+	jbe		SHORT StartDMAtransferForXTCFwithDmaModeInBL	; ...perform the transfer in one operation
 
 	; Calculate how much we can transfer on first and second rounds
@@ -108,6 +108,4 @@
 	call	StartDMAtransferForXTCFwithDmaModeInBL
 	pop		cx										; Pop size for second DMA page
-
-.TransferLastDmaPageWithSizeInCX:
 	; Fall to StartDMAtransferForXTCFwithDmaModeInBL
 
@@ -115,5 +113,4 @@
 ;--------------------------------------------------------------------
 ; StartDMAtransferForXTCFwithDmaModeInBL
-; Updated for XT-CFv3, 11-Apr-13
 ;	Parameters:
 ;		BL:		Byte for DMA Mode Register
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm	(revision 589)
@@ -29,7 +29,5 @@
 ; --------------------------------------------------------------------------------------------------
 
-
 %ifdef MODULE_8BIT_IDE
-
 ;--------------------------------------------------------------------
 ; IdePioBlock_ReadFromXtideRev1
@@ -57,8 +55,7 @@
 
 ;--------------------------------------------------------------------
+; 8-bit PIO from a single data port.
+;
 ; IdePioBlock_ReadFrom8bitDataPort
-;
-; 8-bit PIO from a single data port.
-;
 ;	Parameters:
 ;		CX:		Block size in 512 byte sectors
@@ -68,5 +65,5 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, BX, CX
+;		AX, CX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -87,13 +84,12 @@
 	ret
 %endif
-
-%endif	; MODULE_8BIT_IDE
-
-
-;--------------------------------------------------------------------
+%endif ; MODULE_8BIT_IDE
+
+
+;--------------------------------------------------------------------
+; 16-bit and 32-bit PIO from a single data port.
+;
 ; IdePioBlock_ReadFrom16bitDataPort
-;
-; 16-bit PIO from a single data port.
-;
+; IdePioBlock_ReadFrom32bitDataPort
 ;	Parameters:
 ;		CX:		Block size in 512 byte sectors
@@ -103,10 +99,10 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, BX, CX
+;		AX, CX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 IdePioBlock_ReadFrom16bitDataPort:
 %ifdef USE_186
-	xchg	cl, ch	; Sectors to WORDs
+	xchg	cl, ch		; Sectors to WORDs
 	rep insw
 	ret
@@ -126,14 +122,11 @@
 
 ;--------------------------------------------------------------------
+%ifdef MODULE_ADVANCED_ATA
 ALIGN JUMP_ALIGN
 IdePioBlock_ReadFrom32bitDataPort:
-	db		0C1h		; SHL
-	db		0E1h		; CX
-	db		7			; 7 (Sectors to DWORDs)
-	rep
-	db		66h			; Override operand size to 32-bit
-	db		6Dh			; INSW/INSD
-	ret
-
+	shl		cx, 7		; Sectors to DWORDs
+	rep insd
+	ret
+%endif ; MODULE_ADVANCED_ATA
 
 
@@ -145,5 +138,4 @@
 
 %ifdef MODULE_8BIT_IDE
-
 ;--------------------------------------------------------------------
 ; IdePioBlock_WriteToXtideRev1
@@ -151,5 +143,5 @@
 ;		CX:		Block size in 512-byte sectors
 ;		DX:		IDE Data port address
-;		ES:SI:	Normalized ptr to buffer containing data
+;		DS:SI:	Normalized ptr to buffer containing data
 ;	Returns:
 ;		Nothing
@@ -159,9 +151,6 @@
 ALIGN JUMP_ALIGN
 IdePioBlock_WriteToXtideRev1:
-	push	ds
 	UNROLL_SECTORS_IN_CX_TO_QWORDS
 	mov		bl, 8		; Bit mask for toggling data low/high reg
-	push	es
-	pop		ds
 ALIGN JUMP_ALIGN
 .OutswLoop:
@@ -170,5 +159,4 @@
 	%endrep
 	loop	.OutswLoop
-	pop		ds
 	ret
 
@@ -179,16 +167,13 @@
 ;		CX:		Block size in 512-byte sectors
 ;		DX:		IDE Data port address
-;		ES:SI:	Normalized ptr to buffer containing data
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, BX, CX
+;		DS:SI:	Normalized ptr to buffer containing data
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, CX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 IdePioBlock_WriteToXtideRev2:
 	UNROLL_SECTORS_IN_CX_TO_QWORDS
-	push	ds
-	push	es
-	pop		ds
 ALIGN JUMP_ALIGN
 .WriteNextQword:
@@ -197,5 +182,4 @@
 	%endrep
 	loop	.WriteNextQword
-	pop		ds
 	ret
 
@@ -206,9 +190,9 @@
 ;		CX:		Block size in 512-byte sectors
 ;		DX:		IDE Data port address
-;		ES:SI:	Normalized ptr to buffer containing data
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, BX, CX
+;		DS:SI:	Normalized ptr to buffer containing data
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, CX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -216,5 +200,4 @@
 %ifdef USE_186
 	shl		cx, 9		; Sectors to BYTEs
-	es					; Source is ES segment
 	rep outsb
 	ret
@@ -222,7 +205,4 @@
 %else ; 808x
 	UNROLL_SECTORS_IN_CX_TO_QWORDS
-	push	ds
-	push	es
-	pop		ds
 ALIGN JUMP_ALIGN
 .WriteNextQword:
@@ -232,8 +212,6 @@
 	%endrep
 	loop	.WriteNextQword
-	pop		ds
-	ret
-%endif
-
+	ret
+%endif
 %endif ; MODULE_8BIT_IDE
 
@@ -245,9 +223,9 @@
 ;		CX:		Block size in 512-byte sectors
 ;		DX:		IDE Data port address
-;		ES:SI:	Normalized ptr to buffer containing data
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, BX, CX
+;		DS:SI:	Normalized ptr to buffer containing data
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, CX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -255,5 +233,4 @@
 %ifdef USE_186
 	xchg	cl, ch		; Sectors to WORDs
-	es					; Source is ES segment
 	rep outsw
 	ret
@@ -261,7 +238,4 @@
 %else ; 808x
 	UNROLL_SECTORS_IN_CX_TO_QWORDS
-	push	ds
-	push	es
-	pop		ds
 ALIGN JUMP_ALIGN
 .WriteNextQword:
@@ -271,17 +245,13 @@
 	%endrep
 	loop	.WriteNextQword
-	pop		ds
-	ret
-%endif
-
-;--------------------------------------------------------------------
+	ret
+%endif
+
+;--------------------------------------------------------------------
+%ifdef MODULE_ADVANCED_ATA
 ALIGN JUMP_ALIGN
 IdePioBlock_WriteTo32bitDataPort:
-	db		0C1h		; SHL
-	db		0E1h		; CX
-	db		7			; 7 (Sectors to DWORDs)
-	es					; Source is ES segment
-	rep
-	db		66h			; Override operand size to 32-bit
-	db		6Fh			; OUTSW/OUTSD
-	ret
+	shl		cx, 7		; Sectors to DWORDs
+	rep outsd
+	ret
+%endif ; MODULE_ADVANCED_ATA
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 589)
@@ -173,6 +173,9 @@
 	cmp		[bp+PIOVARS.bSectorsLeft], cl
 	jbe		SHORT .WriteLastBlockToDrive
+	push	ds
+	push	es
+	pop		ds
 	call	[bp+PIOVARS.fnXfer]
-
+	pop		ds
 	; Wait until ready for next block and check for errors
 	call	IdeWait_IRQorDRQ					; Wait until ready to transfer
@@ -189,5 +192,9 @@
 	mov		cl, [bp+PIOVARS.bSectorsLeft]		; CH is already zero
 	push	cx
+	push	ds
+	push	es
+	pop		ds
 	call	[bp+PIOVARS.fnXfer]					; Transfer possibly partial block
+	pop		ds
 	jmp		SHORT CheckErrorsAfterTransferringLastBlock
 
@@ -237,5 +244,4 @@
 	; Convert ES:SI to physical address
 %ifdef USE_386
-
 	mov		dx, es
 	xor		ax, ax
@@ -247,52 +253,26 @@
 
 %elifdef USE_186
-						; Bytes	EU Cycles(286)
-	mov		ax, es		; 2		2
-	rol		ax, 4		; 3		9
-	mov		dx, ax		; 2		2
-	and		ax, BYTE 0Fh; 3		3
-	xor		dx, ax		; 2		2
-	add		si, dx		; 2		2
-	adc		al, ah		; 2		2
-	mov		es, ax		; 2		2
-	;------------------------------------
-						; 18	24
+	mov		ax, es
+	rol		ax, 4
+	mov		dx, ax
+	and		ax, 0Fh
+	xor		dx, ax
+	add		si, dx
+	adc		al, ah
+	mov		es, ax
+
 %else ; 808x
-						; Bytes	EU Cycles(808x)
-	mov		al, 4		; 2		4
-	mov		dx, es		; 2		2
-	xchg	cx, ax		; 1		3
-	rol		dx, cl		; 2		24
-	mov		cx, dx		; 2		2
-	xchg	cx, ax		; 1		3
-	and		ax, BYTE 0Fh; 3		4
-	xor		dx, ax		; 2		3
-	add		si, dx		; 2		3
-	adc		al, ah		; 2		3
-	mov		es, ax		; 2		2
-	;------------------------------------
-						; 21	53
-;
-; Judging by the Execution Unit cycle count the above block of code is
-; apparently slower. However, the shifts and rotates in the block below
-; execute faster than the Bus Interface Unit on an 8088 can fetch them,
-; thus causing the EU to starve. The difference in true execution speed
-; (if any) might not be worth the extra 5 bytes.
-; In other words, we could use a real world test here.
-;
-%if 0
-						; Bytes	EU Cycles(808x/286)
-	xor		dx, dx		; 2		3/2
-	mov		ax, es		; 2		2/2
-%rep 4
-	shl		ax, 1		; 8		8/8
-	rcl		dx, 1		; 8		8/8
-%endrep
-	add		si, ax		; 2		3/2
-	adc		dl, dh		; 2		3/2
-	mov		es, dx		; 2		2/2
-	;------------------------------------
-						; 26	29/26
-%endif ; 0
+	mov		al, 4
+	mov		dx, es
+	xchg	cx, ax
+	rol		dx, cl
+	mov		cx, dx
+	xchg	cx, ax
+	and		ax, 0Fh
+	xor		dx, ax
+	add		si, dx
+	adc		al, ah
+	mov		es, ax
+
 %endif
 
@@ -334,7 +314,11 @@
 %ifdef USE_AT		; CF is always clear for XT builds
 	; AH = RET_HD_INVALID (01) if CF set, RET_HD_SUCCESS (00) if not. CF unchanged.
+%ifdef USE_386
+	setc	ah
+%else
 	sbb		ah, ah
 	neg		ah
 %endif
+%endif ; USE_AT
 	ret
 
@@ -345,5 +329,9 @@
 g_rgfnPioRead:
 		dw		IdePioBlock_ReadFrom16bitDataPort	; 0, DEVICE_16BIT_ATA
+%ifdef MODULE_ADVANCED_ATA
 		dw		IdePioBlock_ReadFrom32bitDataPort	; 1, DEVICE_32BIT_ATA
+%elifdef MODULE_8BIT_IDE
+		dw		NULL
+%endif ; MODULE_ADVANCED_ATA
 %ifdef MODULE_8BIT_IDE
 		dw		IdePioBlock_ReadFrom8bitDataPort	; 2, DEVICE_8BIT_ATA
@@ -361,5 +349,9 @@
 g_rgfnPioWrite:
 		dw		IdePioBlock_WriteTo16bitDataPort	; 0, DEVICE_16BIT_ATA
+%ifdef MODULE_ADVANCED_ATA
 		dw		IdePioBlock_WriteTo32bitDataPort	; 1, DEVICE_32BIT_ATA
+%elifdef MODULE_8BIT_IDE
+		dw		NULL
+%endif ; MODULE_ADVANCED_ATA
 %ifdef MODULE_8BIT_IDE
 		dw		IdePioBlock_WriteTo8bitDataPort		; 2, DEVICE_8BIT_ATA
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 589)
@@ -98,5 +98,13 @@
 %endif
 	cld									; String instructions to increment pointers
-	CREATE_FRAME_INTPACK_TO_SSBP	SIZE_OF_IDEPACK_WITHOUT_INTPACK
+	ePUSHA
+	push	ds
+	push	es
+%ifdef USE_386
+;	push	fs
+;	push	gs
+%endif
+	sub		sp, BYTE SIZE_OF_IDEPACK_WITHOUT_INTPACK
+	mov		bp, sp
 	call	RamVars_GetSegmentToDS
 
@@ -297,6 +305,14 @@
 	; on INT 13h to enable interrupts.
 	or		BYTE [bp+IDEPACK.intpack+INTPACK.flags+1], (FLG_FLAGS_IF>>8)
-	mov		sp, bp	; This makes possible to exit anytime, no matter what is on stack
-	RESTORE_FRAME_INTPACK_FROM_SSBP		SIZE_OF_IDEPACK_WITHOUT_INTPACK
+
+	lea		sp, [bp+SIZE_OF_IDEPACK_WITHOUT_INTPACK]
+%ifdef USE_386
+;	pop		gs
+;	pop		fs
+%endif
+	pop		es
+	pop		ds
+	ePOPA
+	iret
 
 
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 589)
@@ -152,44 +152,4 @@
 
 
-%if 0
-	; We always need to enable 8-bit mode since 16-bit mode is restored
-	; when controller is reset (AH=00h or 0Dh)
-	ePUSH_T	bx, AH23h_Enable8bitPioMode
-
-	; Convert mode to device type (see XTCF.inc for full details)
-	and		ax, 3
-	jz		SHORT .Set8bitPioMode	; XTCF_8BIT_PIO_MODE = 0
-	dec		ax						; XTCF_8BIT_PIO_MODE_WITH_BIU_OFFLOAD = 1
-	jz		SHORT .Set8bitPioModeWithBIUOffload
-	dec		ax						; XTCF_16BIT_PIO_WITH_BIU_OFFLOAD = 2
-	jz		SHORT .Set16bitPioModeWithBIUOffload
-
-	; XTCF_DMA_MODE = 3
-	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_DMA
-
-	; DMA transfers have limited block size
-	mov		al, [di+DPT_ATA.bBlockSize]
-	cmp		al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
-	jbe		SHORT AH24h_SetBlockSize
-	mov		al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
-	jmp		SHORT AH24h_SetBlockSize
-
-.Set16bitPioModeWithBIUOffload:
-	pop		bx								; Do not enable 8-bit PIO...
-	ePUSH_T	bx, AH23h_Disable8bitPioMode	; ...disable it instead
-	mov		al, DEVICE_8BIT_XTCF_PIO16_WITH_BIU_OFFLOAD
-	SKIP2B	bx
-
-.Set8bitPioMode:
-	mov		al, DEVICE_8BIT_XTCF_PIO8
-	SKIP2B	bx
-
-.Set8bitPioModeWithBIUOffload:
-	mov		al, DEVICE_8BIT_XTCF_PIO8_WITH_BIU_OFFLOAD
-	mov		[di+DPT_ATA.bDevice], al
-	ret
-%endif ; 0
-
-
 ;--------------------------------------------------------------------
 ; AH1Eh_GetCurrentXTCFmodeToAX
@@ -197,5 +157,5 @@
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
 ;	Returns:
-;		AX:		XT-CF mode (XTCF_8BIT_PIO_MODE, XTCF_8BIT_PIO_MODE_WITH_BIU_OFFLOAD, XTCF_16BIT_PIO_WITH_BIU_OFFLOAD or XTCF_DMA_MODE)
+;		AX:		XT-CF mode (see XTCF.inc)
 ;		CF:		Clear
 ;	Corrupts registers:
@@ -208,9 +168,2 @@
 	ret
 
-%if 0
-	mov		al, [di+DPT_ATA.bDevice]
-	shr		al, 1
-	cbw
-	sub		al, XTCF_DEVICE_OFFSET >> 1
-	ret
-%endif ; 0
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm	(revision 589)
@@ -92,4 +92,6 @@
 	mov		si, FEATURE_ENABLE_8BIT_PIO_TRANSFER_MODE
 	jmp		SHORT AH23h_SetControllerFeatures
+
+%ifdef MODULE_8BIT_IDE_ADVANCED
 AH23h_Disable8bitPioMode:
 	mov		si, FEATURE_DISABLE_8BIT_PIO_TRANSFER_MODE
@@ -97,3 +99,4 @@
 	xor		ah, ah			; Clear error since modern drives might not understand the command and are
 	ret						; always in 16-bit mode anyway
-%endif
+%endif ; MODULE_8BIT_IDE_ADVANCED
+%endif ; MODULE_8BIT_IDE
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH2h_HRead.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH2h_HRead.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH2h_HRead.asm	(revision 589)
@@ -40,5 +40,5 @@
 ;		AH:		Int 13h/40h floppy return status
 ;		AL:		Burst error length if AH returns 11h (we never return error code 11h)
-;				Number of sectors actually read (only valid if CF set for someBIOSes)
+;				Number of sectors actually read (only valid if CF set for some BIOSes)
 ;		CF:		0 if successful, 1 if error
 ;--------------------------------------------------------------------
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH3h_HWrite.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH3h_HWrite.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH3h_HWrite.asm	(revision 589)
@@ -39,5 +39,5 @@
 ;	Returns with INTPACK:
 ;		AH:		Int 13h/40h floppy return status
-;		AL:		Number of sectors actually written (only valid if CF set for someBIOSes)
+;		AL:		Number of sectors actually written (only valid if CF set for some BIOSes)
 ;		CF:		0 if successful, 1 if error
 ;--------------------------------------------------------------------
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm	(revision 589)
@@ -184,6 +184,6 @@
 
 	; Advanced PIO mode 3 and above
-	mov		dl, [di+DPT_ADVANCED_ATA.bPioMode]
-	or		dl, PIO_FLOW_CONTROL_MODE_xxx
+	mov		dl, PIO_FLOW_CONTROL_MODE_xxx
+	or		dl, [di+DPT_ADVANCED_ATA.bPioMode]
 
 .IordyNotSupported:
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Tools/Address.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Tools/Address.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Tools/Address.asm	(revision 589)
@@ -174,13 +174,9 @@
 	; +=sectToSeek-1 (24-bit result)
 	; Max = 16,450,497 + 63 - 1 = 16,450,559 = FB03FFh
-	xor		bh, bh					; Sector number now in BX
+	mov		bh, ch					; Sector number now in BX, CH=zero
 	dec		bx						; sectToSeek-=1
-	add		ax, bx					; Add to loword
-	adc		dl, bh					; Add possible carry to byte2, BH=zero
-
-	; Copy DX:AX to proper return registers
-	xchg	bx, ax					; BL = Sector Number Register (LBA 7...0)
-	mov		cl, bh					; Low Cylinder Register (LBA 15...8)
-	mov		ch, dl					; High Cylinder Register (LBA 23...16)
-	mov		bh, dh					; Drive and Head Register (LBA 27...24)
+	add		bx, ax					; Add loword to BX (BL = Sector Number Register (LBA 7...0))
+	adc		ch, dl					; Add possible carry to byte2 (CH = High Cylinder Register (LBA 23...16))
+	mov		cl, bh					; CL = Low Cylinder Register (LBA 15...8)
+	mov		bh, dh					; BH = Drive and Head Register (LBA 27...24)
 	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/AdvAtaInit.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/AdvAtaInit.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/AdvAtaInit.asm	(revision 589)
@@ -37,15 +37,19 @@
 AdvAtaInit_DetectControllerForIdeBaseInBX:
 	call	Vision_DetectAndReturnIDinAXandPortInDXifControllerPresent
-	jne		SHORT .NoAdvancedControllerForPortBX
+	jnz		SHORT .NoVisionControllerFound
+
 	call	Vision_DoesIdePortInBXbelongToControllerWithIDinAX
-	jne		SHORT .NoAdvancedControllerForPortBX
+	jz		SHORT .AdvancedControllerFoundForPortBX
+
+.NoVisionControllerFound:
 	call	PDC20x30_DetectControllerForIdeBaseInBX
 	jnc		SHORT .NoAdvancedControllerForPortBX
 
-	stc		; Advanced Controller found for port BX
+.AdvancedControllerFoundForPortBX:
+	stc
 	ret
 
 .NoAdvancedControllerForPortBX:
-	xor		ax, ax
+	xor		ax, ax		; Clear ID in AX and CF
 	ret
 
@@ -66,8 +70,13 @@
 AdvAtaInit_GetControllerMaxPioModeToALandMinPioCycleTimeToBX:
 	cmp		ah, ID_QD6580_ALTERNATE
+%ifdef USE_386
+	jae		Vision_GetMaxPioModeToALandMinCycleTimeToBX
+	jmp		PDC20x30_GetMaxPioModeToALandMinPioCycleTimeToBX
+%else
 	jae		SHORT .Vision
 	jmp		PDC20x30_GetMaxPioModeToALandMinPioCycleTimeToBX
 .Vision:
 	jmp		Vision_GetMaxPioModeToALandMinCycleTimeToBX
+%endif
 
 
@@ -88,5 +97,5 @@
 	test	ax, ax
 	jz		SHORT .NoAdvancedController	; Return with CF cleared
-	
+
 	cmp		ah, ID_QD6580_ALTERNATE
 	jae		SHORT .Vision
@@ -98,5 +107,5 @@
 
 	call	AdvAtaInit_LoadMasterDPTtoDSSIifSlaveInDSDI
-	call	Vision_InitializeWithIDinAHandConfigInAL
+	call	Vision_InitializeWithIDinAH
 	xor		ax, ax						; Success
 
@@ -116,5 +125,5 @@
 ;				Zero if Slave Drive not present
 ;	Corrupts registers:
-;		AX
+;		AL
 ;--------------------------------------------------------------------
 AdvAtaInit_LoadMasterDPTtoDSSIifSlaveInDSDI:
Index: trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/PDC20x30.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/PDC20x30.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/PDC20x30.asm	(revision 589)
@@ -36,9 +36,42 @@
 	mov		dx, bx
 	call	EnablePdcProgrammingMode
-	jz		.ControllerDetected
-	clc
-	ret
-.ControllerDetected:
-	call	GetPdcIDtoAX
+	jnz		SHORT DisablePdcProgrammingMode.Return	; PDC controller not detected
+;	ePUSH_T	ax, DisablePdcProgrammingMode			; Uncomment this if GetPdcIDtoAX needs to be a real function
+	; Fall to GetPdcIDtoAX
+
+;--------------------------------------------------------------------
+; Programming mode must be enabled for this function.
+; This function also enables PDC 20630 extra registers.
+;
+; GetPdcIDtoAX
+;	Parameters:
+;		DX:		IDE Base port
+;	Returns:
+;		AH:		PDC ID
+;	Corrupts registers:
+;		AL, BX
+;--------------------------------------------------------------------
+GetPdcIDtoAX:
+	push	dx
+
+	; Try to enable PDC 20630 extra registers
+	add		dx, BYTE LOW_CYLINDER_REGISTER
+	in		al, dx
+	or		al, FLG_PDCLCR_ENABLE_EXTRA_REGISTERS
+	out		dx, al
+
+	; Try to access PDC 20630 registers to see if they are available
+	; Hopefully this does not cause problems for systems with PDC 20230
+	add		dx, BYTE PDC20630_INDEX_REGISTER - LOW_CYLINDER_REGISTER
+	mov		al, PDCREG7_STATUS	; Try to access PDC 20630 status register
+	out		dx, al
+	xchg	bx, ax
+	in		al, dx				; Does index register contain status register index?
+	cmp		al, bl
+	mov		ah, ID_PDC20630
+	eCMOVNE	ah, ID_PDC20230
+
+	pop		dx
+;	ret							; Uncomment this to make GetPdcIDtoAX a real function
 	; Fall to DisablePdcProgrammingMode
 
@@ -49,5 +82,5 @@
 ;		DX:		Base port
 ;	Returns:
-;		Nothing
+;		CF:		Set
 ;	Corrupts registers:
 ;		AL
@@ -56,6 +89,6 @@
 	add		dx, BYTE HIGH_CYLINDER_REGISTER
 	in		al, dx
-	sub		dx, BYTE HIGH_CYLINDER_REGISTER
-	stc		; Set for PDC20x30_DetectControllerForIdeBaseInBX
+	add		dx, -HIGH_CYLINDER_REGISTER		; Sets CF for PDC20x30_DetectControllerForIdeBaseInBX
+.Return:
 	ret
 
@@ -66,4 +99,5 @@
 ;		DX:		Base port
 ;	Returns:
+;		CF:		Cleared
 ;		ZF:		Set if programming mode enabled
 ;	Corrupts registers:
@@ -72,6 +106,7 @@
 EnablePdcProgrammingMode:
 	; Set bit 7 to sector count register
-	add		dx, BYTE SECTOR_COUNT_REGISTER
-	in		al, dx
+	inc		dx
+	inc		dx
+	in		al, dx	; 1F2h (SECTOR_COUNT_REGISTER)
 	or		al, 80h
 	out		dx, al
@@ -93,38 +128,7 @@
 	; PDC20230C and PDC20630 clears the bit we set at the beginning
 	in		al, dx
-	sub		dx, BYTE SECTOR_COUNT_REGISTER
-	test	al, 80h
-	ret
-
-
-;--------------------------------------------------------------------
-; Programming mode must be enabled for this function.
-; This function also enables PDC 20630 extra registers.
-;
-; GetPdcIDtoAX
-;	Parameters:
-;		DX:		IDE Base port
-;	Returns:
-;		AX:		PDC ID word
-;	Corrupts registers:
-;		BX
-;--------------------------------------------------------------------
-GetPdcIDtoAX:
-	; Try to enable PDC 20630 extra registers
-	add		dx, BYTE LOW_CYLINDER_REGISTER
-	in		al, dx
-	or		al, FLG_PDCLCR_ENABLE_EXTRA_REGISTERS
-	out		dx, al
-
-	; Try to access PDC 20630 registers to see if they are available
-	; Hopefully this does not cause problems for systems with PDC 20230
-	add		dx, BYTE PDC20630_INDEX_REGISTER - LOW_CYLINDER_REGISTER
-	mov		al, PDCREG7_STATUS	; Try to access PDC 20630 status register
-	out		dx, al
-	xchg	bx, ax
-	in		al, dx				; Does index register contain status register index?
-	cmp		al, bl
-	mov		ah, ID_PDC20630
-	eCMOVNE	ah, ID_PDC20230
+	dec		dx
+	dec		dx		; Base port
+	test	al, 80h	; Clears CF
 	ret
 
@@ -145,9 +149,9 @@
 PDC20x30_GetMaxPioModeToALandMinPioCycleTimeToBX:
 	cmp		ah, ID_PDC20630
-	je		SHORT .return		; No need to limit anything
+	je		SHORT .Return		; No need to limit anything
 	mov		ax, 2				; Limit PIO to 2 for ID_PDC20230
 	mov		bx, PIO_2_MIN_CYCLE_TIME_NS
 	stc
-.return:
+.Return:
 	ret
 
@@ -165,7 +169,15 @@
 ;--------------------------------------------------------------------
 PDC20x30_InitializeForDPTinDSDI:
+%ifdef USE_386
+	xor		ch, ch
+	test	BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
+	setnz	cl
+%else
 	xor		cx, cx
 	test	BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
-	eCSETNZ	cl
+	jz		SHORT .NotSlave
+	inc		cx
+.NotSlave:
+%endif
 
 	mov		dx, [di+DPT.wBasePort]
@@ -173,7 +185,7 @@
 	call	SetSpeedForDriveInCX
 	cmp		BYTE [di+DPT_ADVANCED_ATA.wControllerID+1], ID_PDC20630
-	jne		.initializationCompleted
+	jne		SHORT .InitializationCompleted
 	call	SetPdc20630SpeedForDriveInCX
-.initializationCompleted:
+.InitializationCompleted:
 	mov		dx, [di+DPT.wBasePort]
 	call	DisablePdcProgrammingMode
@@ -201,15 +213,17 @@
 	mov		bh, ~MASK_PDCSCR_DEV1SPEED	; Assume slave
 	inc		cx
-	loop	.setSpeed
+	loop	.SetSpeed
 	eSHL_IM	bl, POS_PDCSCR_DEV0SPEED
 	mov		bh, ~MASK_PDCSCR_DEV0SPEED
-.setSpeed:
+.SetSpeed:
 	in		al, dx
 	and		al, bh
 	or		al, bl
 	cmp		bl, 7
-	jb		SHORT OutputNewValue
+	jb		SHORT .OutputNewValue
 	or		al, FLG_PDCSCR_UNKNOWN_BIT7	; Flag for PIO 2 and above?
-	jmp		SHORT OutputNewValue
+.OutputNewValue:
+	out		dx, al
+	ret
 
 .rgbPioModeToPDCspeedValue:
@@ -228,20 +242,18 @@
 ;		DX:		Low Cylinder Register
 ;	Corrupts registers:
-;		AX, CX
+;		AX
 ;--------------------------------------------------------------------
 SetPdc20630SpeedForDriveInCX:
 	inc		dx		; LOW_CYLINDER_REGISTER
-	mov		ah, FLG_PDCLCR_DEV0SPEED_BIT4 | FLG_PDCLCR_DEV0IORDY
-	shr		ah, cl
-	in		al, dx
-	not		ah
+	mov		ah, ~(FLG_PDCLCR_DEV0SPEED_BIT4 | FLG_PDCLCR_DEV0IORDY)
+	ror		ah, cl
+	in		al, dx
 	and		al, ah	; Clear drive specific bits
 	cmp		BYTE [di+DPT_ADVANCED_ATA.bPioMode], 2
-	jbe		.clearBitsOnly
+	jbe		.ClearBitsOnly
 	not		ah
 	or		al, ah
-.clearBitsOnly:
-OutputNewValue:
-	out		dx, al
-	ret
-
+.ClearBitsOnly:
+	out		dx, al
+	ret
+
Index: trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/Vision.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/Vision.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/Vision.asm	(revision 589)
@@ -29,5 +29,5 @@
 ;		AX:		ID WORD specific for QDI Vision Controllers
 ;				(AL = QD65xx Config Register contents)
-;				(AH = QDI Vision Controller ID (bits 4...7))
+;				(AH = QDI Vision Controller ID)
 ;		DX:		Controller port (not IDE port)
 ;		ZF:		Set if controller found
@@ -46,8 +46,8 @@
 	; from Axh to Bxh.
 	call	IsConfigRegisterWithIDinAL
-	je		SHORT VisionControllerDetected
+	je		SHORT VisionControllerDetected.Return
 
 	; Check QD65xx alternative base port
-	or		dl, QD65XX_ALTERNATIVE_BASE_PORT
+	mov		dl, QD65XX_ALTERNATIVE_BASE_PORT
 	in		al, QD65XX_ALTERNATIVE_BASE_PORT + QD65XX_CONFIG_REGISTER_in
 %endif ; DANGEROUS_DETECTION
@@ -68,11 +68,12 @@
 	mov		ah, al
 	and		al, MASK_QDCONFIG_CONTROLLER_ID
-	cmp		al, ID_QD6500 << 4
+	cmp		al, ID_QD6500
 	je		SHORT VisionControllerDetected
-	cmp		al, ID_QD6580 << 4
+	cmp		al, ID_QD6580
 	je		SHORT VisionControllerDetected
-	cmp		al, ID_QD6580_ALTERNATE << 4
+	cmp		al, ID_QD6580_ALTERNATE
 VisionControllerDetected:
 	xchg	ah, al
+.Return:
 	ret
 
@@ -82,5 +83,5 @@
 ;	Parameters:
 ;		AL:		QD65xx Config Register contents
-;		AH:		QDI Vision Controller ID (bits 4...7)
+;		AH:		QDI Vision Controller ID
 ;		BX:		IDE Base port to check
 ;		DX:		Vision Controller port
@@ -92,5 +93,5 @@
 ;--------------------------------------------------------------------
 Vision_DoesIdePortInBXbelongToControllerWithIDinAX:
-	cmp		ah, ID_QD6500 << 4
+	cmp		ah, ID_QD6500
 	je		SHORT .DoesIdePortInDXbelongToQD6500
 
@@ -128,5 +129,5 @@
 ;	Parameters:
 ;		AL:		QD65xx Config Register contents
-;		AH:		QDI Vision Controller ID (bits 4...7)
+;		AH:		QDI Vision Controller ID
 ;	Returns:
 ;		AL:		Max supported PIO mode
@@ -139,5 +140,5 @@
 ;--------------------------------------------------------------------
 Vision_GetMaxPioModeToALandMinCycleTimeToBX:
-	cmp		ah, ID_QD6500 << 4
+	cmp		ah, ID_QD6500
 	jne		SHORT .NoNeedToLimitForQD6580
 
@@ -149,8 +150,7 @@
 
 ;--------------------------------------------------------------------
-; Vision_InitializeWithIDinAHandConfigInAL
-;	Parameters:
-;		AL:		QD65xx Config Register contents
-;		AH:		QDI Vision Controller ID (bits 4...7)
+; Vision_InitializeWithIDinAH
+;	Parameters:
+;		AH:		QDI Vision Controller ID
 ;		DS:DI:	Ptr to DPT for Single or Slave Drive
 ;		SI:		Offset to Master DPT if Slave Drive present
@@ -162,7 +162,7 @@
 ;		AX, BX, CX, DX, BP
 ;--------------------------------------------------------------------
-Vision_InitializeWithIDinAHandConfigInAL:
+Vision_InitializeWithIDinAH:
 	; QD6580 has a Control Register that needs to be programmed
-	cmp		ah, ID_QD6500 << 4
+	cmp		ah, ID_QD6500
 	mov		dx, [di+DPT_ADVANCED_ATA.wControllerBasePort]
 	mov		bp, QD6500_MAX_ACTIVE_TIME_CLOCKS | (QD6500_MIN_ACTIVE_TIME_CLOCKS << 8)	; Assume QD6500
Index: trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 589)
@@ -81,5 +81,5 @@
 	mov		al, [cs:ROMVARS.wFlags]			; Configurator set to always scan?
 	or		al, [es:BDA.bKBFlgs1]			; Or, did the user hold down the ALT key?
-	and		al, 8							; 8 = alt key depressed, same as FLG_ROMVARS_SERIAL_ALWAYSDETECT
+	and		al, 8							; 8 = alt key depressed, same as FLG_ROMVARS_SERIAL_SCANDETECT
 	jnz		.DriveDetectLoop
 %endif ; MODULE_SERIAL
@@ -135,5 +135,5 @@
 
 	shr		ch, 1							; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
-	rcl		al, 1							; starting drive number in upper 7 bits, number of drives in low bit
+	eRCL_IM	al, 1							; starting drive number in upper 7 bits, number of drives in low bit
 .NoFloppies:
 	mov		[RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
Index: trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm	(revision 589)
@@ -90,6 +90,5 @@
 %ifdef MODULE_SERIAL
 	cmp		dh, DEVICE_SERIAL_PORT			; Check if this is a serial device
-
-	jnz		.pushAndPrint					; CX = string to print, AX = port address, DX won't be used
+	jne		SHORT .pushAndPrint				; CX = string to print, AX = port address, DX won't be used
 
 	mov		cl, (g_szDetectCOM-$$) & 0xff	; Setup print string for COM ports
@@ -106,21 +105,21 @@
 
 	test	dl, dl							; Check if serial port "Auto"
-	jz		.pushAndPrintSerial				; CX = string to print, AX and DX won't be used
+	jz		SHORT .pushAndPrintSerial		; CX = string to print, AX and DX won't be used
 
 	mov		cl, (g_szDetectCOMLarge-$$) & 0xff	; Setup secondary print string for "COMn/xx.yK"
 
-	mov		al,ah							; baud rate divisor to AL
+	mov		al, ah							; baud rate divisor to AL
 	cbw										; clear AH, AL will always be less than 128
-	xchg	si,ax							; move AX to SI for divide
-	mov		ax,1152							; baud rate to display is 115200/divisor, the "00" is handled
+	xchg	si, ax							; move AX to SI for divide
+	mov		ax, 1152						; baud rate to display is 115200/divisor, the "00" is handled
 											; in the print strings
 	cwd										; clear top 16-bits of dividend
 	div		si								; and divide...  Now AX = baud rate/100, DX = 0 (always a clean divide)
 
-	mov		si,10							; Now separate the whole portion from the fractional for "K" display
+	mov		si, 10							; Now separate the whole portion from the fractional for "K" display
 	div		si								; and divide...  Now AX = baud rate/1000, DX = low order digit
 
-	cmp		ax,si							; < 10: "2400", "9600", etc.; >= 10: "19.2K", "38.4K", etc.
-	jae		.pushAndPrintSerial
+	cmp		ax, si							; < 10: "2400", "9600", etc.; >= 10: "19.2K", "38.4K", etc.
+	jae		SHORT .pushAndPrintSerial
 
 	mov		cl, (g_szDetectCOMSmall-$$) & 0xff	; Setup secondary print string for "COMn/XXy00"
@@ -150,8 +149,8 @@
 DetectPrint_DriveNameFromDrvDetectInfoInESBX:
 	push	bp
-	mov		bp,sp
-	lea		si,[bx+DRVDETECTINFO.szDrvName]
+	mov		bp, sp
+	lea		si, [bx+DRVDETECTINFO.szDrvName]
 	push	si
-	mov		si,g_szDriveName
+	mov		si, g_szDriveName
 	jmp		SHORT DetectPrint_FormatCSSIfromParamsInSSBP
 
@@ -276,5 +275,5 @@
 ;
 	push	bp
-	mov		bp,sp
+	mov		bp, sp
 	; Fall to DetectPrint_FormatCSSIfromParamsInSSBP
 
Index: trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm	(revision 589)
@@ -240,7 +240,6 @@
 	push	cx
 	xchg	ax, cx				; IRQ index to CL
-	mov		ch, 1				; Load 1 to be shifted
-	shl		ch, cl				; Shift bit to correct position
-	not		ch					; Invert to create bit mask for clearing
+	mov		ch, ~1				; Load bit mask to be rotated
+	rol		ch, cl				; Rotate mask to correct position for clearing
 	in		al, dx				; Read Interrupt Mask Register
 	and		al, ch				; Clear wanted bit
Index: trunk/XTIDE_Universal_BIOS/Src/Main.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 589)
@@ -117,5 +117,5 @@
 
 %ifdef MODULE_SERIAL
-	at	ROMVARS.ideVarsSerialAuto+IDEVARS.bDevice,		db	DEVICE_SERIAL_PORT
+	at	ROMVARS.ideVarsSerialAuto+IDEVARS.bDevice,	db	DEVICE_SERIAL_PORT
 %endif
 %else
@@ -134,26 +134,39 @@
 	at	ROMVARS.bIdleTimeout,	db	0						; Standby timer disabled by default
 
-%ifdef MODULE_8BIT_IDE_ADVANCED
-	at	ROMVARS.ideVars0+IDEVARS.wBasePort,				dw	DEVICE_XTIDE_DEFAULT_PORT		; Controller Command Block base port
-	at	ROMVARS.ideVars0+IDEVARS.bDevice,				db	DEVICE_8BIT_XTCF_PIO8
+%ifndef MODULE_8BIT_IDE
+	at	ROMVARS.ideVars0+IDEVARS.wBasePort,			dw	DEVICE_ATA_PRIMARY_PORT 		; Controller Command Block base port
+	at	ROMVARS.ideVars0+IDEVARS.wControlBlockPort,	dw	DEVICE_ATA_PRIMARY_PORTCTRL 	; Controller Control Block base port
+	at	ROMVARS.ideVars0+IDEVARS.bDevice,			db	DEVICE_16BIT_ATA
+%elifdef MODULE_8BIT_IDE_ADVANCED
+	at	ROMVARS.ideVars0+IDEVARS.wBasePort,			dw	DEVICE_XTIDE_DEFAULT_PORT		; Controller Command Block base port
+	at	ROMVARS.ideVars0+IDEVARS.bDevice,			db	DEVICE_8BIT_XTCF_PIO8
 %else
-	at	ROMVARS.ideVars0+IDEVARS.wBasePort,				dw	DEVICE_XTIDE_DEFAULT_PORT		; Controller Command Block base port
-	at	ROMVARS.ideVars0+IDEVARS.wControlBlockPort,		dw	DEVICE_XTIDE_DEFAULT_PORTCTRL	; Controller Control Block base port
-	at	ROMVARS.ideVars0+IDEVARS.bDevice,				db	DEVICE_8BIT_XTIDE_REV1
+	at	ROMVARS.ideVars0+IDEVARS.wBasePort,			dw	DEVICE_XTIDE_DEFAULT_PORT		; Controller Command Block base port
+	at	ROMVARS.ideVars0+IDEVARS.wControlBlockPort,	dw	DEVICE_XTIDE_DEFAULT_PORTCTRL	; Controller Control Block base port
+	at	ROMVARS.ideVars0+IDEVARS.bDevice,			db	DEVICE_8BIT_XTIDE_REV1
 %endif
 	at	ROMVARS.ideVars0+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 	at	ROMVARS.ideVars0+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 
+	at	ROMVARS.ideVars1+IDEVARS.wBasePort,			dw	DEVICE_ATA_SECONDARY_PORT
+	at	ROMVARS.ideVars1+IDEVARS.wControlBlockPort,	dw	DEVICE_ATA_SECONDARY_PORTCTRL
+	at	ROMVARS.ideVars1+IDEVARS.bDevice,			db	DEVICE_16BIT_ATA
 	at	ROMVARS.ideVars1+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 	at	ROMVARS.ideVars1+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 
+	at	ROMVARS.ideVars2+IDEVARS.wBasePort,			dw	DEVICE_ATA_TERTIARY_PORT
+	at	ROMVARS.ideVars2+IDEVARS.wControlBlockPort,	dw	DEVICE_ATA_TERTIARY_PORTCTRL
+	at	ROMVARS.ideVars2+IDEVARS.bDevice,			db	DEVICE_16BIT_ATA
 	at	ROMVARS.ideVars2+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 	at	ROMVARS.ideVars2+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 
+	at	ROMVARS.ideVars3+IDEVARS.wBasePort,			dw	DEVICE_ATA_QUATERNARY_PORT
+	at	ROMVARS.ideVars3+IDEVARS.wControlBlockPort,	dw	DEVICE_ATA_QUATERNARY_PORTCTRL
+	at	ROMVARS.ideVars3+IDEVARS.bDevice,			db	DEVICE_16BIT_ATA
 	at	ROMVARS.ideVars3+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 	at	ROMVARS.ideVars3+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 
 %ifdef MODULE_SERIAL
-	at	ROMVARS.ideVarsSerialAuto+IDEVARS.bDevice,		db	DEVICE_SERIAL_PORT
+	at	ROMVARS.ideVarsSerialAuto+IDEVARS.bDevice,	db	DEVICE_SERIAL_PORT
 %endif
 %endif
@@ -286,2 +299,15 @@
 	%include "AH41h_CheckIfExtensionsPresent.asm"
 %endif
+
+
+; Although it's very unlikely to happen, we give warnings for builds that cannot be automatically checksummed due to the size being too large.
+; In some cases it's theoretically possible to checksum the build anyway (manually) which is why these are warnings and not errors.
+%if BIOS_SIZE = 8192				; A small build, possibly a candidate for the ROM socket on a 3Com 3C503 card.
+	%if ($-$$) <= BIOS_SIZE			; Only give warnings when the problem isn't obvious anyway.
+		%if ($-$$) > BIOS_SIZE - 3
+			%warning "This build is too large to be auto-checksummed!"
+		%endif
+	%endif
+%elif ($-$$) = BIOS_SIZE			; A large build.
+	%warning "This build is too large to be auto-checksummed!"
+%endif
Index: trunk/XTIDE_Universal_BIOS/Src/Menus/BootMenu/BootMenuPrint.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Menus/BootMenu/BootMenuPrint.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Menus/BootMenu/BootMenuPrint.asm	(revision 589)
@@ -39,20 +39,20 @@
 	mov		si, g_szRomBootDash						; Standard "Rom Boot" but with a "-" at the front
 	mov		al, 20h									; The space between "Rom" and "Boot"
-	jnc		.ROMBoot								; display "Rom Boot" option for last entry
+	jnc		SHORT .ROMBoot							; display "Rom Boot" option for last entry
 
 	call	FindDPT_ForDriveNumberInDL
-	jc		.notOurs
+	jc		SHORT .notOurs
 
 	call	DriveDetectInfo_ConvertDPTtoBX
 	mov		si, g_szDriveNumBOOTNFO					; special g_szDriveNum that prints from BDA
-	jmp		.go
+	jmp		SHORT .go
 
 .notOurs:
-	mov		si,g_szDriveNum
-	mov		bx,g_szForeignHD						; assume a hard disk for the moment
+	mov		si, g_szDriveNum
+	mov		bx, g_szForeignHD						; assume a hard disk for the moment
 
 	test	dl, dl
-	js		.go
-	mov		bl,((g_szFloppyDrv)-$$ & 0xff)			; and revisit the earlier assumption...
+	js		SHORT .go
+	mov		bl, ((g_szFloppyDrv)-$$ & 0xff)			; and revisit the earlier assumption...
 
 .go:
@@ -60,8 +60,6 @@
 	call	DriveXlate_ToOrBack
 
-	test	dl, 0f0h								; if there is a character in the upper nibble
-	jnz		.noSpace
-	dec		si										; backup a character to a leading space
-.noSpace:
+	cmp		dl, 10h									; Check if there is a character in the upper nibble
+	sbb		si, 0									; If not, backup a character to a leading space
 
 	push	dx										; translated drive number
@@ -86,5 +84,5 @@
 ;--------------------------------------------------------------------
 BootMenuPrint_TitleStrings:
-	xor		di,di						; Null character will be eaten
+	xor		di, di						; Null character will be eaten
 	mov		si, g_szBootMenuTitle
 	jmp		DetectPrint_RomFoundAtSegment.BootMenuEntry
@@ -105,5 +103,5 @@
 
 	call	BootMenu_GetDriveToDXforMenuitemInCX
-	jnc		BootMenuEvent_Completed						; nothing to display if "Rom Boot" option
+	jnc		SHORT BootMenuEvent_Completed				; nothing to display if "Rom Boot" option
 
 	push	bp
@@ -116,9 +114,9 @@
 	inc		dl											; are we a hard disk?
 	dec		dl											; inc/dec will set SF, without modifying CF or DL
-	js		.HardDiskRefreshInformation
-
-	jnc		.ours										; Based on CF from FindDPT_ForDriveNumberInDL above
+	js		SHORT .HardDiskRefreshInformation
+
+	jnc		SHORT .ours									; Based on CF from FindDPT_ForDriveNumberInDL above
 	call	FloppyDrive_GetType							; Get Floppy Drive type to BX
-	jmp		.around
+	jmp		SHORT .around
 .ours:
 	call	AH8h_GetDriveParameters
@@ -132,5 +130,4 @@
 	cmp		bl, FLOPPY_TYPE_35_ED
 	ja		SHORT .PushAXAndOutput
-
 	; Fall to .PrintKnownFloppyType
 
@@ -162,5 +159,5 @@
 	mov		al, (g_szFddThreeHalf - $$) & 0xff
 	cmp		bl, FLOPPY_TYPE_525_HD
-	ja		.ThreeHalf
+	ja		SHORT .ThreeHalf
 	mov		al, (g_szFddFiveQuarter - $$) & 0xff
 .ThreeHalf:
@@ -168,5 +165,5 @@
 
 	xor		bh, bh
-	mov		al,FloppyTypes.rgbCapacityMultiplier
+	mov		al, FloppyTypes.rgbCapacityMultiplier
 	mul		BYTE [cs:bx+FloppyTypes.rgbCapacity - 1]	; -1 since 0 is handled above and not in the table
 
@@ -184,16 +181,35 @@
 ;	Parameters:
 ;		DS:		RAMVARS segment
+;		DI:		Zero if foreign drive
+;				Offset to DPT if our drive
+;		CF:		Set if foreign drive
+;				Clear if our drive
 ;	Returns:
 ;		CF:		Set since menu event was handled successfully
 ;	Corrupts registers:
-;		BX, CX, DX, SI, DI, ES
+;		AX, BX, CX, DX, SI, DI, ES
 ;--------------------------------------------------------------------
 .HardDiskRefreshInformation:
-	jc		.HardDiskMenuitemInfoForForeignDrive		; Based on CF from FindDPT_ForDriveNumberInDL (way) above
+	jc		SHORT .HardDiskMenuitemInfoForForeignDrive	; Based on CF from FindDPT_ForDriveNumberInDL (way) above
 
 .HardDiskMenuitemInfoForOurDrive:
 	ePUSH_T ax, g_szInformation							; Add substring for our hard disk information
-	call	GetTotalSectorCount
-	jmp		.ConvertSectorCountInBXDXAXtoSizeAndPushForFormat
+
+%ifdef MODULE_EBIOS
+	ePUSH_T ax, .ConvertSectorCountInBXDXAXtoSizeAndPushForFormat
+	test	BYTE [di+DPT.bFlagsLow], FLGL_DPT_LBA
+%ifdef USE_386
+	jnz		AccessDPT_GetLbaSectorCountToBXDXAX
+	jmp		AH15h_GetSectorCountToBXDXAX
+%else ; ~USE_386
+	jz		SHORT .NoLBA
+	jmp		AccessDPT_GetLbaSectorCountToBXDXAX
+.NoLBA:
+	jmp		AH15h_GetSectorCountToBXDXAX
+%endif
+%else ; ~MODULE_EBIOS
+	call	AH15h_GetSectorCountToBXDXAX
+	jmp		SHORT .ConvertSectorCountInBXDXAXtoSizeAndPushForFormat
+%endif ; MODULE_EBIOS
 
 .HardDiskMenuitemInfoForForeignDrive:
@@ -226,18 +242,2 @@
 	db		2880  / FloppyTypes.rgbCapacityMultiplier    ;  type 5
 	db		2880  / FloppyTypes.rgbCapacityMultiplier    ;  type 6
-
-
-;--------------------------------------------------------------------
-; GetTotalSectorCount
-;	Parameters:
-;		DS:DI:		DPT Pointer
-;	Returns:
-;		BX:DX:AX:	48-bit sector count
-;	Corrupts registers:
-;		CX
-;--------------------------------------------------------------------
-%ifdef MODULE_EBIOS
-GetTotalSectorCount		EQU		AccessDPT_GetLbaSectorCountToBXDXAX
-%else
-GetTotalSectorCount		EQU		AH15h_GetSectorCountToBXDXAX
-%endif
Index: trunk/XTIDE_Universal_BIOS/Src/Strings.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Strings.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/Strings.asm	(revision 589)
@@ -136,8 +136,11 @@
 g_szDeviceTypeValues:
 g_szDeviceTypeValues_16bit:			db	" 16",NULL
+%ifdef MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
 g_szDeviceTypeValues_32bit:			db	" 32",NULL
+%ifdef MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
 g_szDeviceTypeValues_8bit:			db	"  8",NULL
 g_szDeviceTypeValues_XTIDEr1:		db	"D8 ",NULL	; Dual 8-bit
 g_szDeviceTypeValues_XTIDEr2:		db	"X8 ",NULL	; A0<->A3 swapped 8-bit
+%ifdef MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
 g_szDeviceTypeValues_XTCFpio8:		db	"T8 ",NULL	; True 8-bit
 g_szDeviceTypeValues_XTCFpio8BIU:	db	"T8B",NULL
@@ -146,7 +149,13 @@
 g_szDeviceTypeValues_JrIde:			db	"M8 ",NULL	; Memory Mapped 8-bit
 g_szDeviceTypeValues_ADP50L:		db	"M8 ",NULL	; Memory Mapped 8-bit
+%ifdef MODULE_SERIAL
 g_szDeviceTypeValues_Serial:		db	"SER",NULL
-
-g_szDeviceTypeValues_Displacement equ (g_szDeviceTypeValues_32bit - g_szDeviceTypeValues)
+%endif ; MODULE_SERIAL
+%endif ; MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+%endif ; MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+%endif ; MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
+g_szDeviceTypeValues_Displacement equ 3		; 3 compressed, 4 uncompressed
+;g_szDeviceTypeValues_Displacement equ (g_szDeviceTypeValues_32bit - g_szDeviceTypeValues)
 ;
 ; Ensure that device type strings are correctly spaced in memory
@@ -156,7 +165,13 @@
 		%error "g_szDeviceTypeValues Displacement Incorrect 1"
 	%endif
+
+	%ifdef MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 	%if g_szDeviceTypeValues_32bit <> g_szDeviceTypeValues_16bit + g_szDeviceTypeValues_Displacement
 		%error "g_szDeviceTypeValues Displacement Incorrect 2"
 	%endif
+
+	%ifdef MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 	%if g_szDeviceTypeValues_8bit <> g_szDeviceTypeValues_32bit + g_szDeviceTypeValues_Displacement
 		%error "g_szDeviceTypeValues Displacement Incorrect 3"
@@ -168,4 +183,7 @@
 		%error "g_szDeviceTypeValues Displacement Incorrect 5"
 	%endif
+
+	%ifdef MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 	%if g_szDeviceTypeValues_XTCFpio8 <> g_szDeviceTypeValues_XTIDEr2 + g_szDeviceTypeValues_Displacement
 		%error "g_szDeviceTypeValues Displacement Incorrect 6"
@@ -186,7 +204,16 @@
 		%error "g_szDeviceTypeValues Displacement Incorrect 11"
 	%endif
+
+	%ifdef MODULE_SERIAL
+
 	%if g_szDeviceTypeValues_Serial <> g_szDeviceTypeValues_ADP50L + g_szDeviceTypeValues_Displacement
 		%error "g_szDeviceTypeValues Displacement Incorrect 12"
 	%endif
+
+	%endif ; MODULE_SERIAL
+	%endif ; MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+	%endif ; MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+	%endif ; MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 %endif
 
Index: trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm	(revision 589)
@@ -257,8 +257,10 @@
                            			  db	 20h,  2bh,  0fh          ; compressed
 
+%ifdef MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
 g_szDeviceTypeValues_32bit:			; db	" 32",NULL
                            			; db	 20h,  33h,  32h,  00h    ; uncompressed
                            			  db	 20h,  2dh,  0ch          ; compressed
 
+%ifdef MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
 g_szDeviceTypeValues_8bit:			; db	"  8",NULL
                           			; db	 20h,  20h,  38h,  00h    ; uncompressed
@@ -273,4 +275,5 @@
                              		  db	 5eh,  30h,  00h          ; compressed
 
+%ifdef MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
 g_szDeviceTypeValues_XTCFpio8:		; db	"T8 ",NULL	; True 8-bit
                               		; db	 54h,  38h,  20h,  00h    ; uncompressed
@@ -297,10 +300,16 @@
                             		  db	 53h,  30h,  00h          ; compressed
 
+%ifdef MODULE_SERIAL
 g_szDeviceTypeValues_Serial:		; db	"SER",NULL
                             		; db	 53h,  45h,  52h,  00h    ; uncompressed
                             		  db	 59h,  4bh,  98h          ; compressed
 
-
-g_szDeviceTypeValues_Displacement equ (g_szDeviceTypeValues_32bit - g_szDeviceTypeValues)
+%endif ; MODULE_SERIAL
+%endif ; MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+%endif ; MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+%endif ; MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
+g_szDeviceTypeValues_Displacement equ 3		; 3 compressed, 4 uncompressed
+;g_szDeviceTypeValues_Displacement equ (g_szDeviceTypeValues_32bit - g_szDeviceTypeValues)
 ;
 ; Ensure that device type strings are correctly spaced in memory
@@ -310,7 +319,13 @@
 %error "g_szDeviceTypeValues Displacement Incorrect 1"
 %endif
+
+%ifdef MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 %if g_szDeviceTypeValues_32bit <> g_szDeviceTypeValues_16bit + g_szDeviceTypeValues_Displacement
 %error "g_szDeviceTypeValues Displacement Incorrect 2"
 %endif
+
+%ifdef MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 %if g_szDeviceTypeValues_8bit <> g_szDeviceTypeValues_32bit + g_szDeviceTypeValues_Displacement
 %error "g_szDeviceTypeValues Displacement Incorrect 3"
@@ -322,4 +337,7 @@
 %error "g_szDeviceTypeValues Displacement Incorrect 5"
 %endif
+
+%ifdef MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 %if g_szDeviceTypeValues_XTCFpio8 <> g_szDeviceTypeValues_XTIDEr2 + g_szDeviceTypeValues_Displacement
 %error "g_szDeviceTypeValues Displacement Incorrect 6"
@@ -340,7 +358,16 @@
 %error "g_szDeviceTypeValues Displacement Incorrect 11"
 %endif
+
+%ifdef MODULE_SERIAL
+
 %if g_szDeviceTypeValues_Serial <> g_szDeviceTypeValues_ADP50L + g_szDeviceTypeValues_Displacement
 %error "g_szDeviceTypeValues Displacement Incorrect 12"
 %endif
+
+%endif ; MODULE_SERIAL
+%endif ; MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+%endif ; MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+%endif ; MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 %endif
 
@@ -567,38 +594,38 @@
 
 ;; translated usage stats
-;; 172:2
-;; 47:2
-;; 171:2
-;; 46:3
-;; 48:2
-;; 181:1
-;; 200:1
-;; 54:2
-;; 45:2
-;; 49:2
 ;; 34:3
 ;; 179:8
-;; 56:8
+;; 46:3
+;; 44:1
+;; 200:1
+;; 48:2
+;; 175:1
+;; 171:2
+;; 51:3
+;; 50:2
 ;; 33:1
 ;; 53:2
+;; 45:2
+;; 47:2
+;; 172:2
+;; 56:8
 ;; 32:34
-;; 175:1
-;; 44:1
-;; 50:2
-;; 51:3
+;; 181:1
+;; 54:2
+;; 49:2
 ;; total translated: 20
 
 ;; format usage stats
-;; z:2
+;; 5-x:1
+;; 2-u:1
+;; s:14
 ;; nl:12
-;; u:6
-;; 5-x:1
-;; c:13
 ;; A:4
-;; s:14
 ;; 5-u:2
 ;; x:5
-;; 2-u:1
 ;; 2-I:1
+;; z:2
+;; u:6
+;; c:13
 ;; total format: 11
 
Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm	(revision 589)
@@ -62,5 +62,5 @@
 
 	jnz		SHORT .EnableDeviceIrq
-	or		al, FLG_DEVCONTROL_nIEN	; Disable IRQ
+	mov		al, FLG_DEVCONTROL_nIEN	; Disable IRQ
 .EnableDeviceIrq:
 %else
Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CompatibleDPT.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CompatibleDPT.asm	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CompatibleDPT.asm	(revision 589)
@@ -231,13 +231,15 @@
 
 	xor		dl, dl							; Clear DL for checksum
+	push	bp
+	mov		bp, StoswThenAddALandAHtoDL
 
 	; DPTE.wBasePort
 	mov		ax, [si+DPT.wBasePort]
-	call	StoswThenAddALandAHtoDL			; Bytes 0 and 1
+	call	bp								; Bytes 0 and 1
 
 	; DPTE.wControlBlockPort
 	eMOVZX	bx, [si+DPT.bIdevarsOffset]
 	mov		ax, [cs:bx+IDEVARS.wControlBlockPort]
-	call	StoswThenAddALandAHtoDL			; Bytes 2 and 3
+	call	bp								; Bytes 2 and 3
 
 	; DPTE.bDrvnhead and DPTE.bBiosVendor
@@ -245,14 +247,14 @@
 	call	AccessDPT_GetDriveSelectByteToAL
 	xchg	si, di
-	call	StoswThenAddALandAHtoDL			; Bytes 4 and 5
+	call	bp								; Bytes 4 and 5
 
 	; DPTE.bIRQ and DPTE.bBlockSize
 	mov		al, [cs:bx+IDEVARS.bIRQ]		; No way to define that we might not use IRQ
-	mov		ah, [si+DPT_ATA.bBlockSize]
-	cmp		ah, 1
-	jbe		SHORT .DoNotSetBlockModeFlag
+	mov		ah, [si+DPT_ATA.bBlockSize]		; DPT_ATA.bBlockSize must never be zero!
+	sahf									; Only block size = 1 sets CF
+	jc		SHORT .DoNotSetBlockModeFlag
 	or		cl, FLG_BLOCK_MODE_ENABLED
 .DoNotSetBlockModeFlag:
-	call	StoswThenAddALandAHtoDL			; Bytes 6 and 7
+	call	bp								; Bytes 6 and 7
 
 	; DPTE.bDmaChannelAndType and DPTE.bPioMode
@@ -266,5 +268,5 @@
 	sbb		cl, -1	; FLG_FAST_PIO_ENABLED (if .wControllerID > 0)
 .DoNotSetFastPioFlag:
-	call	StoswThenAddALandAHtoDL			; Bytes 8 and 9
+	call	bp								; Bytes 8 and 9
 %endif
 
@@ -279,5 +281,6 @@
 .NoChsTranslationOrBitShiftTranslationSet:
 	xchg	ax, cx
-	call	StoswThenAddALandAHtoDL			; Bytes 10 and 11
+	call	bp								; Bytes 10 and 11
+	pop		bp
 
 	; DPTE.wReserved (must be zero)
Index: trunk/XTIDE_Universal_BIOS/makefile
===================================================================
--- trunk/XTIDE_Universal_BIOS/makefile	(revision 588)
+++ trunk/XTIDE_Universal_BIOS/makefile	(revision 589)
@@ -18,5 +18,5 @@
 # MODULE_8BIT_IDE             Support for 8-BIT IDE cards like XTIDE                               #
 # MODULE_8BIT_IDE_ADVANCED    Support for memory mapped and DMA based cards like JRIDE and XTCF    #
-# MODULE_ADVANCED_ATA         Native support for some VLB IDE controllers                          #
+# MODULE_ADVANCED_ATA         Native support for some VLB IDE controllers (requires USE_386)       #
 # MODULE_COMPATIBLE_TABLES    Support for ill behaving software that tries to access DPT directly  #
 # MODULE_BOOT_MENU            Boot Menu for selection of drive to boot from                        #
@@ -108,5 +108,5 @@
 DEFINES_XT = $(DEFINES_COMMON) ELIMINATE_CGA_SNOW MODULE_8BIT_IDE_ADVANCED
 DEFINES_XTPLUS = $(DEFINES_XT) USE_186
-DEFINES_AT = $(DEFINES_COMMON) USE_AT USE_286 MODULE_IRQ MODULE_ADVANCED_ATA MODULE_COMPATIBLE_TABLES
+DEFINES_AT = $(DEFINES_COMMON) USE_AT USE_286 MODULE_IRQ MODULE_COMPATIBLE_TABLES
 
 DEFINES_XT_LARGE = $(DEFINES_XT) $(DEFINES_COMMON_LARGE)
@@ -115,5 +115,5 @@
 
 DEFINES_XT_TINY = MODULE_STRINGS_COMPRESSED MODULE_8BIT_IDE NO_ATAID_VALIDATION
-DEFINES_386_8K = $(DEFINES_AT) USE_386
+DEFINES_386_8K = $(DEFINES_AT) USE_386 MODULE_ADVANCED_ATA
 
 DEFINES_ALL_FEATURES = MODULE_8BIT_IDE MODULE_8BIT_IDE_ADVANCED MODULE_ADVANCED_ATA MODULE_EBIOS MODULE_BOOT_MENU MODULE_HOTKEYS MODULE_IRQ MODULE_SERIAL MODULE_SERIAL_FLOPPY MODULE_STRINGS_COMPRESSED MODULE_POWER_MANAGEMENT MODULE_COMPATIBLE_TABLES
