Index: trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc	(revision 505)
@@ -71,8 +71,8 @@
 %endif
 %ifdef MODULE_FEATURE_SETS
-	FLGH_DPT_POWER_MANAGEMENT_SUPPORTED	EQU (1<<5)	; Bit 4, Drive supports power management
+	FLGH_DPT_POWER_MANAGEMENT_SUPPORTED	EQU (1<<5)	; Bit 5, Drive supports power management
 %endif
 %ifdef MODULE_ADVANCED_ATA
-	FLGH_DPT_IORDY						EQU	(1<<7)	; Bit 5, Controller and Drive supports IORDY
+	FLGH_DPT_IORDY						EQU	(1<<7)	; Bit 7, Controller and Drive supports IORDY
 %endif
 
Index: trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 505)
@@ -3,5 +3,5 @@
 
 ;
-; XTIDE Universal BIOS and Associated Tools 
+; XTIDE Universal BIOS and Associated Tools
 ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
 ;
@@ -10,9 +10,9 @@
 ; the Free Software Foundation; either version 2 of the License, or
 ; (at your option) any later version.
-; 
+;
 ; This program is distributed in the hope that it will be useful,
 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-; GNU General Public License for more details.		
+; GNU General Public License for more details.
 ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 ;
@@ -23,12 +23,9 @@
 ; Segment when RAMVARS is stored to top of interrupt vectors.
 %ifndef USE_AT
-LITE_MODE_RAMVARS_SEGMENT	EQU		30h
+	LITE_MODE_RAMVARS_SEGMENT	EQU		30h
 %endif
 
-%ifdef MODULE_SERIAL_FLOPPY
-	%define NEED_XLATEVARS
-%endif
 
-%ifdef MODULE_DRIVEXLATE
+%ifdef MODULE_SERIAL_FLOPPY OR MODULE_DRIVEXLATE
 	%define NEED_XLATEVARS
 %endif
@@ -77,5 +74,5 @@
 										; and number of drives (low order bit, max 2 drives supported).
 										; During initialization, until the end of DetectDrives_FromAllIDEControllers,
-										; this byte contains the raw number of floppy drives seen 
+										; this byte contains the raw number of floppy drives seen
 										; (using .bFlopCreateCnt)
 	%else
@@ -105,5 +102,5 @@
 
 ;
-; IDEPACK NOTE: The first six bytes of this structure are directly put on the 
+; IDEPACK NOTE: The first six bytes of this structure are directly put on the
 ; wire for MODULE_SERIAL, please do not change the order or insert other members.
 ;
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm	(revision 505)
@@ -56,8 +56,9 @@
 	mov		al, [di+DPT_ATA.bDevice]
 	cmp		al, DEVICE_8BIT_XTIDE_REV2
+	jb		SHORT .InputToALfromRegisterInDX	; Standard IDE controllers and XTIDE rev 1
+
+%ifdef MODULE_8BIT_IDE_ADVANCED
 	je		SHORT .ReverseA0andA3fromRegisterIndexInDX
-	jb		SHORT .InputToALfromRegisterInDX	; Standard IDE controllers and XTIDE rev 1
-		
-%ifdef MODULE_8BIT_IDE_ADVANCED
+
 	cmp		al, DEVICE_8BIT_JRIDE_ISA
 	jne		SHORT .ShlRegisterIndexInDX			; All XT-CF modes
@@ -71,5 +72,5 @@
 	ret
 %endif
-		
+
 .ReverseA0andA3fromRegisterIndexInDX:
 	mov		dl, [cs:bx+g_rgbSwapA0andA3fromIdeRegisterIndex]
@@ -77,5 +78,5 @@
 
 .ShlRegisterIndexInDX:
-	shl		dx, 1
+	eSHL_IM	dx, 1
 	; Fall to .InputToALfromRegisterInDX
 
@@ -102,8 +103,9 @@
 	mov		bl, [di+DPT_ATA.bDevice]
 	cmp		bl, DEVICE_8BIT_XTIDE_REV2
+	jb		SHORT .OutputALtoControlBlockRegisterInDX	; Standard IDE controllers and XTIDE rev 1
+
+%ifdef MODULE_8BIT_IDE_ADVANCED
 	je		SHORT .ReverseA0andA3fromRegisterIndexInDX
-	jb		SHORT .OutputALtoControlBlockRegisterInDX	; Standard IDE controllers and XTIDE rev 1
-
-%ifdef MODULE_8BIT_IDE_ADVANCED
+
 	cmp		bl, DEVICE_8BIT_JRIDE_ISA
 	jne		SHORT .ShlRegisterIndexInDX		; All XT-CF modes
@@ -125,5 +127,5 @@
 
 .ShlRegisterIndexInDX:
-	shl		dx, 1
+	eSHL_IM	dx, 1
 	add		dx, BYTE XTCF_CONTROL_BLOCK_OFFSET
 	jmp		SHORT OutputALtoRegisterInDX
@@ -152,8 +154,9 @@
 	mov		bl, [di+DPT_ATA.bDevice]
 	cmp		bl, DEVICE_8BIT_XTIDE_REV2
+	jb		SHORT OutputALtoRegisterInDX	; Standard IDE controllers and XTIDE rev 1
+
+%ifdef MODULE_8BIT_IDE_ADVANCED
 	je		SHORT .ReverseA0andA3fromRegisterIndexInDX
-	jb		SHORT OutputALtoRegisterInDX	; Standard IDE controllers and XTIDE rev 1
-
-%ifdef MODULE_8BIT_IDE_ADVANCED
+
 	cmp		bl, DEVICE_8BIT_JRIDE_ISA
 	jne		SHORT .ShlRegisterIndexInDX		; All XT-CF modes
@@ -177,5 +180,5 @@
 
 .ShlRegisterIndexInDX:
-	shl		dx, 1
+	eSHL_IM	dx, 1
 	; Fall to OutputALtoRegisterInDX
 
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm	(revision 505)
@@ -39,6 +39,6 @@
 AH0h_HandlerForDiskControllerReset:
 	; Reset foreign Floppy and Hard Drives (those handled by other BIOSes)
-	xor		bx, bx										; Zero BH to assume no errors
-	or		bl, dl										; Copy requested drive to BL
+	eMOVZX	bx, dl										; Copy requested drive to BL and zero BH to assume no errors
+
 	xor		ah, ah										; Disk Controller Reset
 	call	Int13h_CallPreviousInt13hHandler			; Reset floppy drives only or floppy drives and foreign hard disks
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 505)
@@ -102,4 +102,8 @@
 	out		dx, al
 
+	; 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 Control Register Contents to device code
 	test	al, al
@@ -108,22 +112,24 @@
 	jae		SHORT .SetMemoryMappedMode
 
+; We need to limit block size here. Consider this scenario;
+; 1. While in PIO mode or memory mapped mode, the drive is set to do
+;    block transfers larger than XTCF_DMA_MODE_MAX_BLOCK_SIZE.
+; 2. A call is subsequently made to change device mode to DEVICE_8BIT_XTCF_DMA.
+; 3. The call to AH24h_SetBlockSize fails but the change in device mode has been made.
+
 	; Set DMA Mode
 	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_DMA
 	mov		al, [di+DPT_ATA.bBlockSize]
-	call	AH24h_SetBlockSize	; AH=24h limits block size if necessary
-	jmp		SHORT .Enable8bitPioMode
+	MIN_U	al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
+	jmp		SHORT AH24h_SetBlockSize	; Returns via AH23h_Enable8bitPioMode
 
 .SetMemoryMappedMode:
-	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_MEMMAP
-	jmp		SHORT .Enable8bitPioMode
+	mov		al, DEVICE_8BIT_XTCF_MEMMAP
+	SKIP2B	bx
 
 .Set8bitPioMode:
-	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_PIO8
-	; Fall to .Enable8bitPioMode
-
-	; We always need to enable 8-bit mode since 16-bit mode is restored
-	; when controller is reset (AH=00h or 0Dh)
-.Enable8bitPioMode:
-	jmp		AH23h_Enable8bitPioMode
+	mov		al, DEVICE_8BIT_XTCF_PIO8
+	mov		[di+DPT_ATA.bDevice], al
+	ret		; Via AH23h_Enable8bitPioMode
 
 
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm	(revision 505)
@@ -101,7 +101,11 @@
 	call	Device_SelectDrive
 	STORE_ERROR_FLAG_TO_DPT		FLG_INITERROR_FAILED_TO_SELECT_DRIVE
+%ifdef USE_386
+	jc		.ReturnWithErrorCodeInAH
+%else
 	jnc		SHORT .ContinueInitializationSinceDriveSelectedSuccesfully
 	jmp		.ReturnWithErrorCodeInAH
 .ContinueInitializationSinceDriveSelectedSuccesfully:
+%endif
 
 
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int19h.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int19h.asm	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int19h.asm	(revision 505)
@@ -3,5 +3,5 @@
 
 ;
-; XTIDE Universal BIOS and Associated Tools 
+; XTIDE Universal BIOS and Associated Tools
 ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
 ;
@@ -10,11 +10,11 @@
 ; the Free Software Foundation; either version 2 of the License, or
 ; (at your option) any later version.
-; 
+;
 ; This program is distributed in the hope that it will be useful,
 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-; GNU General Public License for more details.		
+; GNU General Public License for more details.
 ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
-;		
+;
 
 ; Section containing code
@@ -107,9 +107,9 @@
 ; The following macro could be easily inlined below.  Why a macro?  Depending on the combination
 ; of MODULE_HOTKEYS or MODULE_BOOT_MENU, this code needs to either come before or after the
-; call to the boot menu.  
+; call to the boot menu.
 ;
 %macro TRY_TO_BOOT_DL_AND_DH_DRIVES 0
 	push	dx									; it's OK if this is left on the stack, if we are
-												; are successful, the following call does not return
+												; successful, the following call does not return
 	call	TryToBootFromPrimaryOrSecondaryBootDevice_AndBoot
 	pop		dx
@@ -117,12 +117,12 @@
 	call	TryToBootFromPrimaryOrSecondaryBootDevice_AndBoot
 %endmacro
-				
-%ifdef MODULE_HOTKEYS
-	call	HotkeyBar_ScanHotkeysFromKeyBufferAndStoreToBootvars		
+
+%ifdef MODULE_HOTKEYS
+	call	HotkeyBar_ScanHotkeysFromKeyBufferAndStoreToBootvars
 	cmp		al, ROM_BOOT_HOTKEY_SCANCODE
-	jz		.RomBoot							; CF clear so ROM boot
+	je		.RomBoot							; CF clear so ROM boot
 %ifdef MODULE_BOOT_MENU
 	cmp		al, BOOT_MENU_HOTKEY_SCANCODE
-	jz		.BootMenu
+	je		.BootMenu
 %endif
 	call	HotkeyBar_GetBootDriveNumbersToDX
@@ -130,30 +130,28 @@
 	TRY_TO_BOOT_DL_AND_DH_DRIVES
 	;; falls through to boot menu, if it is present.  If not present, falls through to rom boot.
-%endif
+%endif ; MODULE_HOTKEYS
 
 %ifdef MODULE_BOOT_MENU
-.BootMenu:		
+.BootMenu:
 	call	BootMenu_DisplayAndReturnDriveInDLRomBootClearCF
 	jnc		.RomBoot							; CF clear so ROM boot
 
 	mov		dh, dl								; Setup for secondary drive
-	not		dh									; Floppy goes to HD, or vice veras
-	and		dh, 080h							; Go to first drive of the floppy or HD set
+	not		dh									; Floppy goes to HD, or vice versa
+	and		dh, 80h								; Go to first drive of the floppy or HD set
 
 %ifdef MODULE_HOTKEYS
 	jmp		.TryUsingHotKeysCode
 %else
-	TRY_TO_BOOT_DL_AND_DH_DRIVES		
+	TRY_TO_BOOT_DL_AND_DH_DRIVES
 	jmp		.BootMenu
 %endif
-%endif
-
-%ifndef MODULE_HOTKEYS
-%ifndef MODULE_BOOT_MENU
+%endif ; MODULE_BOOT_MENU
+
+%ifndef MODULE_HOTKEYS OR MODULE_BOOT_MENU
 	xor		dl, dl			; Try to boot from Floppy Drive A
 	call	TryToBootFromPrimaryOrSecondaryBootDevice_AndBoot
 	mov		dl, 80h			; Try to boot from Hard Drive C
 	call	TryToBootFromPrimaryOrSecondaryBootDevice_AndBoot
-%endif
 %endif
 
@@ -162,5 +160,5 @@
 	call	DriveXlate_Reset					; Clean up any drive mappings before Rom Boot
 %endif
-	clc		
+	clc
 	;; fall through to JumpToBootSector_or_RomBoot
 
@@ -174,5 +172,5 @@
 ;	Parameters:
 ;		DL:		Drive to boot from (translated, 00h or 80h)
-;       CF:     Set for Boot Sector Boot 
+;       CF:     Set for Boot Sector Boot
 ;               Clear for ROM Boot
 ;	   	ES:BX:	(if CF set) Ptr to boot sector
@@ -187,5 +185,5 @@
 
 ; clear segment registers before boot sector or rom call
-	mov		ds, ax		
+	mov		ds, ax
 	mov		es, ax
 %ifdef USE_386
@@ -202,9 +200,9 @@
 ; Boot by calling INT 18h (ROM Basic of ROM DOS)
 .romboot:
-	int		BIOS_BOOT_FAILURE_INTERRUPT_18h	; Never returns	
-
-
-;--------------------------------------------------------------------
-; TryToBootFromPrimaryOrSecondaryBootDevice
+	int		BIOS_BOOT_FAILURE_INTERRUPT_18h	; Never returns
+
+
+;--------------------------------------------------------------------
+; TryToBootFromPrimaryOrSecondaryBootDevice_AndBoot
 ;	Parameters
 ;		DL:		Drive selected as boot device
@@ -229,6 +227,5 @@
 
 TryToBoot_FallThroughTo_BootSector_TryToLoadFromDriveDL_AndBoot:
-; fall through to BootSector_TryToLoadFromDriveDL_AndBoot				
-%endif
-		
-
+; fall through to BootSector_TryToLoadFromDriveDL_AndBoot
+%endif
+
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int19h/BootSector.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int19h/BootSector.asm	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int19h/BootSector.asm	(revision 505)
@@ -3,5 +3,5 @@
 
 ;
-; XTIDE Universal BIOS and Associated Tools 
+; XTIDE Universal BIOS and Associated Tools
 ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
 ;
@@ -10,11 +10,11 @@
 ; the Free Software Foundation; either version 2 of the License, or
 ; (at your option) any later version.
-; 
+;
 ; This program is distributed in the hope that it will be useful,
 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ; GNU General Public License for more details.
-; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html				
-;		
+; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+;
 
 ; Section containing code
@@ -22,5 +22,5 @@
 
 ;--------------------------------------------------------------------
-; BootSector_TryToLoadFromDriveDL
+; BootSector_TryToLoadFromDriveDL_AndBoot
 ;	Parameters:
 ;		DL:		Drive to boot from (translated, 00h or 80h)
@@ -36,5 +36,9 @@
 	call	DetectPrint_TryToBootFromDL
 	call	LoadFirstSectorFromDriveDL
+%ifndef USE_386
 	jc		SHORT .FailedToLoadFirstSector
+%else
+	jc		DetectPrint_FailedToLoadFirstSector
+%endif
 
 	test	dl, dl
@@ -44,14 +48,16 @@
 .AlwaysBootFromFloppyDriveForBooterGames:
 	stc
-	jmp		SHORT JumpToBootSector_or_RomBoot		
+	jmp		SHORT JumpToBootSector_or_RomBoot
+
+%ifndef USE_386
 .FailedToLoadFirstSector:
-	call	DetectPrint_FailedToLoadFirstSector
-	ret
+	jmp		DetectPrint_FailedToLoadFirstSector
+%endif
+
 .FirstHardDiskSectorNotBootable:
 	mov		si, g_szBootSectorNotFound
-	call	DetectPrint_NullTerminatedStringFromCSSIandSetCF
-	ret
+	jmp		DetectPrint_NullTerminatedStringFromCSSIandSetCF
 
-%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS		
+%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
   %ifdef MODULE_DRIVEXLATE
     %if TryToBoot_FallThroughTo_BootSector_TryToLoadFromDriveDL_AndBoot <> BootSector_TryToLoadFromDriveDL_AndBoot
@@ -79,35 +85,21 @@
 
 .ReadRetryLoop:
-	call	.LoadFirstSectorFromDLtoESBX
-	jnc		SHORT .Return
+	mov		ax, 0201h						; Read 1 sector
+	mov		cx, 1							; Cylinder 0, Sector 1
+	xor		dh, dh							; Head 0
+	int		BIOS_DISK_INTERRUPT_13h
+	jc		SHORT .FailedToLoadFirstSector
+.Return:
+	ret
+
+.FailedToLoadFirstSector:
 	dec		di								; Decrement retry counter (preserve CF)
 	jz		SHORT .Return					; Loop while retries left
 
 	; Reset drive and retry
-	xor		ax, ax							; AH=0h, Disk Controller Reset
+	xor		ax, ax							; AH=00h, Disk Controller Reset
 	test	dl, dl							; Floppy drive?
-	eCMOVS	ah, RESET_HARD_DISK				; AH=Dh, Reset Hard Disk (Alternate reset)
+	eCMOVS	ah, RESET_HARD_DISK				; AH=0Dh, Reset Hard Disk (Alternate reset)
 	int		BIOS_DISK_INTERRUPT_13h
 	jmp		SHORT .ReadRetryLoop
 
-
-;--------------------------------------------------------------------
-; .LoadFirstSectorFromDLtoESBX
-;	Parameters:
-;		DL:		Drive to boot from (translated, 00h or 80h)
-;		ES:BX:	Destination buffer for boot sector
-;	Returns:
-;		AH:		INT 13h error code
-;		ES:BX:	Ptr to boot sector
-;		CF:		Cleared if read successful
-;				Set if any error
-;	Corrupts registers:
-;		AL, CX, DH
-;--------------------------------------------------------------------
-.LoadFirstSectorFromDLtoESBX:
-	mov		ax, 0201h						; Read 1 sector
-	mov		cx, 1							; Cylinder 0, Sector 1
-	xor		dh, dh							; Head 0
-	int		BIOS_DISK_INTERRUPT_13h
-.Return:
-	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 505)
@@ -50,5 +50,5 @@
 %ifdef MODULE_HOTKEYS
 	call	HotkeyBar_ScanHotkeysFromKeyBufferAndStoreToBootvars		; Done here while CX is still protected
-%endif				
+%endif
 
 	pop		cx
@@ -73,6 +73,6 @@
 %ifdef MODULE_HOTKEYS
 	cmp		al, COM_DETECT_HOTKEY_SCANCODE  ; Set by last call to HotkeyBar_UpdateDuringDriveDetection above
-	jz		.DriveDetectLoop
-%endif		
+	je		.DriveDetectLoop
+%endif
 
 	mov		al,[cs:ROMVARS.wFlags]			; Configurator set to always scan?
@@ -201,6 +201,6 @@
 %ifdef MODULE_HOTKEYS
 	call	HotkeyBar_UpdateDuringDriveDetection
-%endif				
-		
+%endif
+
 %ifdef MODULE_8BIT_IDE_ADVANCED
 	pop		dx
@@ -248,5 +248,5 @@
 ;		Nothing
 ;	Returns:
-;		CF:     Set (from BootMenuPrint_NullTerminatedStringFromCSSIandSetCF)
+;		CF:     Set (from DetectPrint_NullTerminatedStringFromCSSIandSetCF)
 ;	Corrupts registers:
 ;		AX, SI
Index: trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm	(revision 505)
@@ -3,5 +3,5 @@
 
 ;
-; XTIDE Universal BIOS and Associated Tools 
+; XTIDE Universal BIOS and Associated Tools
 ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
 ;
@@ -10,11 +10,11 @@
 ; the Free Software Foundation; either version 2 of the License, or
 ; (at your option) any later version.
-; 
+;
 ; This program is distributed in the hope that it will be useful,
 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-; GNU General Public License for more details.		
+; GNU General Public License for more details.
 ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
-;		
+;
 
 ; Section containing code
@@ -31,8 +31,7 @@
 ;--------------------------------------------------------------------
 DetectPrint_InitializeDisplayContext:
-	CALL_DISPLAY_LIBRARY	InitializeDisplayContext
-	ret
-
-		
+	JMP_DISPLAY_LIBRARY InitializeDisplayContext
+
+
 %ifdef MODULE_HOTKEYS
 ;--------------------------------------------------------------------
@@ -46,9 +45,8 @@
 ;--------------------------------------------------------------------
 DetectPrint_GetSoftwareCoordinatesToAX:
-	CALL_DISPLAY_LIBRARY	GetSoftwareCoordinatesToAX
-	ret
+	JMP_DISPLAY_LIBRARY GetSoftwareCoordinatesToAX
 %endif
 
-		
+
 ;--------------------------------------------------------------------
 ; DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
@@ -75,5 +73,5 @@
 ;	Corrupts registers:
 ;		AX, CX, DX, SI, DI
-;--------------------------------------------------------------------	
+;--------------------------------------------------------------------
 DetectPrint_StartDetectWithAutodetectedBasePortInAXandIdeVarsInCSBP:
 	mov		dx, [cs:bp+IDEVARS.bDevice-1]   ; for Serial: AL=port address>>2, AH=baud rate
@@ -152,5 +150,5 @@
 DetectPrint_DriveNameFromDrvDetectInfoInESBX:
 	push	bp
-	mov		bp,sp	
+	mov		bp,sp
 	lea		si,[bx+DRVDETECTINFO.szDrvName]
 	push	si
@@ -158,5 +156,5 @@
 	jmp		SHORT DetectPrint_FormatCSSIfromParamsInSSBP
 
-				
+
 ;--------------------------------------------------------------------
 ; Prints BIOS name and segment address where it is found.
@@ -175,5 +173,5 @@
 										; so that it can be a different value when using .BootMenuEntry
 
-.BootMenuEntry:	
+.BootMenuEntry:
 	push	bp
 	mov		bp, sp
@@ -186,5 +184,5 @@
 	push	ax
 %else
-	; szTitle and szVersion have the high order byte of their addresses zero, 
+	; szTitle and szVersion have the high order byte of their addresses zero,
 	; so these push instructions are only 2 bytes
 	;
@@ -259,5 +257,5 @@
 
 	mov		si, g_szTryToBoot
-	jmp		SHORT DetectPrint_FormatCSSIfromParamsInSSBP	
+	jmp		SHORT DetectPrint_FormatCSSIfromParamsInSSBP
 
 
Index: trunk/XTIDE_Universal_BIOS/Src/Menus/BootMenu/BootMenu.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Menus/BootMenu/BootMenu.asm	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Src/Menus/BootMenu/BootMenu.asm	(revision 505)
@@ -3,5 +3,5 @@
 
 ;
-; XTIDE Universal BIOS and Associated Tools 
+; XTIDE Universal BIOS and Associated Tools
 ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
 ;
@@ -10,11 +10,11 @@
 ; the Free Software Foundation; either version 2 of the License, or
 ; (at your option) any later version.
-; 
+;
 ; This program is distributed in the hope that it will be useful,
 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ; GNU General Public License for more details.
-; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html		
-;		
+; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+;
 
 ; Section containing code
@@ -24,5 +24,5 @@
 ; Displays Boot Menu and returns Drive or Function number.
 ;
-; BootMenu_DisplayAndStoreSelection
+; BootMenu_DisplayAndReturnDriveInDLRomBootClearCF
 ;	Parameters:
 ;		DS:		RAMVARS segment
@@ -41,5 +41,5 @@
 
 	xchg	cx, ax
-		
+
 	; Clear Boot Menu from screen
 	mov		ax, ' ' | (MONO_NORMAL<<8)
@@ -52,14 +52,14 @@
 ;	Parameters:
 ;		CX:		Index of menuitem selected from Boot Menu
+;		DS:		RAMVARS segment
 ;	Returns:
 ;		DX:		Drive number to be used for booting
-;		DS:		RAMVARS segment
 ;       CF:     Set: There is a selected menu item, DL is valid
 ;               Clear: The item selected is Rom Boot, DL is not valid
 ;	Corrupts registers:
-;		AX, BX, DI
+;		AX, BX
 ;
 ; NOTE: We can't use the menu structure in here, as we are falling through
-; through from BootMenu_DisplayAndReturnDriveInDLRomBootClearCF when the
+; from BootMenu_DisplayAndReturnDriveInDLRomBootClearCF when the
 ; menu structure has already been destroyed.
 ;--------------------------------------------------------------------
@@ -73,5 +73,5 @@
 	sub		dl, al							; Remove floppy drives from index
 	call	RamVars_GetHardDiskCountFromBDAtoAX
-	or		al, 80h							; Or 80h into AL before the sub				
+	or		al, 80h							; Or 80h into AL before the sub
 	cmp		dl, al							; Set CF if hard disk
 											; Clear CF if last item, beyond hard disk list, which indicates ROM boot
Index: trunk/XTIDE_Universal_BIOS/Src/Menus/DriveXlate.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Menus/DriveXlate.asm	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Src/Menus/DriveXlate.asm	(revision 505)
@@ -3,5 +3,5 @@
 
 ;
-; XTIDE Universal BIOS and Associated Tools 
+; XTIDE Universal BIOS and Associated Tools
 ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
 ;
@@ -10,11 +10,11 @@
 ; the Free Software Foundation; either version 2 of the License, or
 ; (at your option) any later version.
-; 
+;
 ; This program is distributed in the hope that it will be useful,
 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-; GNU General Public License for more details.		
+; GNU General Public License for more details.
 ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
-;		
+;
 
 ; Section containing code
@@ -48,7 +48,7 @@
 %if HotkeyBar_FallThroughTo_DriveXlate_ConvertDriveLetterInDLtoDriveNumber <> DriveXlate_ConvertDriveLetterInDLtoDriveNumber
 	%error "DriveXlate_ConvertDriveLetterInDLtoDriveNumber must be at the top of DriveXlate.asm, and that file must immediately follow HotKeys.asm"
-%endif		
 %endif
-		
+%endif
+
 ;--------------------------------------------------------------------
 ; DriveXlate_ConvertDriveNumberFromDLtoDriveLetter
@@ -64,10 +64,9 @@
 ;--------------------------------------------------------------------
 DriveXlate_ConvertDriveNumberFromDLtoDriveLetter:
-	test	dl, dl
-	jns		SHORT .GetDefaultFloppyDrive
+	xor		dl, 80h
+	js		SHORT .GetDefaultFloppyDrive
 
 	; Store default hard drive to boot from
 	call	DriveXlate_GetLetterForFirstHardDriveToAX
-	sub		dl, 80h
 	add		dl, al
 	stc
@@ -75,5 +74,5 @@
 
 .GetDefaultFloppyDrive:
-	add		dl, DEFAULT_FLOPPY_DRIVE_LETTER		; Clears CF
+	sub		dl, 80h - DEFAULT_FLOPPY_DRIVE_LETTER	; Clears CF
 	ret
 
@@ -96,5 +95,5 @@
 	MAX_U	al, DEFAULT_HARD_DRIVE_LETTER
 	ret
-				
+
 
 ;--------------------------------------------------------------------
@@ -168,5 +167,5 @@
 	mov		al, dl				; Store floppy translation
 	SKIP2B	di
-.SetHardDriveToSwap:	
+.SetHardDriveToSwap:
 	mov		ah, dl				; Store HD translation
 	mov		WORD [RAMVARS.xlateVars+XLATEVARS.wFDandHDswap], ax
Index: trunk/XTIDE_Universal_BIOS/Src/Menus/HotkeyBar.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Menus/HotkeyBar.asm	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Src/Menus/HotkeyBar.asm	(revision 505)
@@ -34,6 +34,6 @@
 	call	HotkeyBar_ScanHotkeysFromKeyBufferAndStoreToBootvars
 	; Fall to HotkeyBar_DrawToTopOfScreen
-		
-		
+
+
 ;--------------------------------------------------------------------
 ; HotkeyBar_DrawToTopOfScreen
@@ -127,5 +127,5 @@
 	call	FormatFunctionHotkeyString
 %endif
-	; Fall to .PrintRomBootHotkey		
+	; Fall to .PrintRomBootHotkey
 
 ;--------------------------------------------------------------------
@@ -169,11 +169,10 @@
 ;--------------------------------------------------------------------
 HotkeyBar_ClearRestOfTopRow:
-	CALL_DISPLAY_LIBRARY	GetColumnsToALandRowsToAH
+	CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH
 	eMOVZX	cx, al
-	CALL_DISPLAY_LIBRARY	GetSoftwareCoordinatesToAX
+	CALL_DISPLAY_LIBRARY GetSoftwareCoordinatesToAX
 	sub		cl, al
 	mov		al, ' '
-	CALL_DISPLAY_LIBRARY	PrintRepeatedCharacterFromALwithCountInCX
-	ret
+	JMP_DISPLAY_LIBRARY PrintRepeatedCharacterFromALwithCountInCX
 
 
@@ -216,5 +215,5 @@
 
 	mov		si, ATTRIBUTE_CHARS.cHurryTimeout		; Selected hotkey
-	jz		SHORT GetDescriptionAttributeToDX		; From compare with bScancode above
+	je		SHORT GetDescriptionAttributeToDX		; From compare with bScancode above
 
 GetNonSelectedHotkeyDescriptionAttributeToDX:
@@ -226,5 +225,5 @@
 	call	MenuAttribute_GetToAXfromTypeInSI
 	xchg	dx, ax					; DX = Description attribute
-	;;  fall through to PushHotkeyParamsAndFormat 
+	;;  fall through to PushHotkeyParamsAndFormat
 
 
@@ -232,5 +231,5 @@
 
 	mov		dx, (COLOR_ATTRIBUTE(COLOR_YELLOW, COLOR_CYAN) << 8) | MONO_REVERSE_BLINK
-	jz		SHORT SelectAttributeFromDHorDLbasedOnVideoMode			; From compare with bScancode above
+	je		SHORT SelectAttributeFromDHorDLbasedOnVideoMode		; From compare with bScancode above
 
 GetNonSelectedHotkeyDescriptionAttributeToDX:
@@ -245,5 +244,5 @@
 	mov		dl, dh
 .AttributeLoadedToDL:
-	;;  fall through to PushHotkeyParamsAndFormat 		
+	;;  fall through to PushHotkeyParamsAndFormat
 
 %endif ; MODULE_BOOT_MENU
@@ -277,5 +276,5 @@
 	push	di				; Description string
 	push	cx				; Description string parameter
-		
+
 	push	si				; Key attribute for last space
 
@@ -308,6 +307,5 @@
 ;--------------------------------------------------------------------
 HotkeyBar_RestoreCursorCoordinatesFromAX:
-	CALL_DISPLAY_LIBRARY	SetCursorCoordinatesFromAX
-	ret
+	JMP_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
 
 
@@ -325,5 +323,5 @@
 HotkeyBar_StoreHotkeyToBootvarsForDriveLetterInDL:
 	eMOVZX	ax, dl
-	xor		al, 32	; Upper case drive letter to lower case keystroke
+	or		al, 32	; Upper case drive letter to lower case keystroke
 	jmp		SHORT HotkeyBar_StoreHotkeyToBootvarsIfValidKeystrokeInAX
 
@@ -364,11 +362,11 @@
 	; All scancodes are saved, even if it wasn't a drive letter,
 	; which also covers our function key case.  Invalid function keys
-	; will not do anything (won't be printed, won't be accepted as input)		
+	; will not do anything (won't be printed, won't be accepted as input)
 	mov		[es:di], ah
-		
+
 	; Drive letter hotkeys remaining, allow 'a' to 'z'
 	call	Char_IsLowerCaseLetterInAL
 	jnc		SHORT .KeystrokeIsNotValidDriveLetter
-	xor		al, 32					; We want to print upper case letters
+	and		al, ~32					; We want to print upper case letters
 
 	; Clear HD First flag to assume Floppy Drive hotkey
@@ -377,5 +375,5 @@
 
 	; Determine if Floppy or Hard Drive hotkey
-	eMOVZX	cx, al					; Clear CH to clear scancode
+	xchg	cx, ax
 	call	DriveXlate_GetLetterForFirstHardDriveToAX
 	cmp		cl, al
@@ -386,9 +384,9 @@
 
 .StoreDriveLetter:
-	sbb		di, BYTE 1			; Sub CF if Floppy Drive
+	sbb		di, BYTE 1				; Sub CF if Floppy Drive
 	xchg	ax, cx
-	mov		[es:di], al			; AH = zero to clear function hotkey
-
-.KeystrokeIsNotValidDriveLetter:		
+	mov		[es:di], al
+
+.KeystrokeIsNotValidDriveLetter:
 NoHotkeyToProcess:
 	mov		al, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode]
@@ -407,12 +405,12 @@
 HotkeyBar_GetBootDriveNumbersToDX:
 	mov		dx, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wFddAndHddLetters]
-	test	BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bFlags], FLG_HOTKEY_HD_FIRST		
+	test	BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bFlags], FLG_HOTKEY_HD_FIRST
 	jnz		.noflip
 	xchg	dl, dh
-.noflip:	
+.noflip:
 	call	DriveXlate_ConvertDriveLetterInDLtoDriveNumber
 	xchg	dl, dh
-	; Fall to HotkeyBar_FallThroughTo_DriveXlate_ConvertDriveLetterInDLtoDriveNumber		
-		
-HotkeyBar_FallThroughTo_DriveXlate_ConvertDriveLetterInDLtoDriveNumber:		
-
+	; Fall to HotkeyBar_FallThroughTo_DriveXlate_ConvertDriveLetterInDLtoDriveNumber
+
+HotkeyBar_FallThroughTo_DriveXlate_ConvertDriveLetterInDLtoDriveNumber:
+
Index: trunk/XTIDE_Universal_BIOS/Src/Strings.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Strings.asm	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Src/Strings.asm	(revision 505)
@@ -86,8 +86,8 @@
 g_szRomBootDash:		db	" -  "					; String fall through to g_szRomBoot
 %endif
-%ifdef MODULE_HOTKEYS OR MODULE_BOOT_MENU		
-g_szRomBoot:			db	"Rom%cBoot", NULL		; "RomBoot" or "Rom Boot"
-%endif
-		
+%ifdef MODULE_HOTKEYS OR MODULE_BOOT_MENU
+g_szRomBoot:			db	"Rom%cBoot",NULL		; "RomBoot" or "Rom Boot"
+%endif
+
 
 %ifdef MODULE_BOOT_MENU
Index: trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm	(revision 505)
@@ -177,6 +177,6 @@
 
 %endif
-%ifdef MODULE_HOTKEYS OR MODULE_BOOT_MENU		
-g_szRomBoot:			; db	"Rom%cBoot", NULL		; "RomBoot" or "Rom Boot"
+%ifdef MODULE_HOTKEYS OR MODULE_BOOT_MENU
+g_szRomBoot:			; db	"Rom%cBoot",NULL		; "RomBoot" or "Rom Boot"
             			; db	 52h,  6fh,  6dh,  25h,  63h,  42h,  6fh,  6fh,  74h,  00h    ; uncompressed
             			  db	 58h,  75h,  73h,  3ch,  48h,  75h,  75h, 0bah                ; compressed
Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm	(revision 505)
@@ -3,5 +3,5 @@
 
 ;
-; XTIDE Universal BIOS and Associated Tools 
+; XTIDE Universal BIOS and Associated Tools
 ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
 ;
@@ -10,11 +10,11 @@
 ; the Free Software Foundation; either version 2 of the License, or
 ; (at your option) any later version.
-; 
+;
 ; This program is distributed in the hope that it will be useful,
 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-; GNU General Public License for more details.		
+; GNU General Public License for more details.
 ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
-;		
+;
 
 ; Section containing code
@@ -98,5 +98,5 @@
 ;; when entering the boot menu and also before transferring control at boot time and
 ;; for ROM boots (in int19h.asm).
-		
+
 	pop		es
 	ret
@@ -158,5 +158,5 @@
 	call	RamVars_GetCountOfKnownDrivesToAX
 	push	ds
-	LOAD_BDA_SEGMENT_TO	ds, cx
+	LOAD_BDA_SEGMENT_TO	ds, bx
 	mov		bl, [BDA.bHDCount]
 	MAX_U	al, bl
Index: trunk/XTIDE_Universal_BIOS/makefile
===================================================================
--- trunk/XTIDE_Universal_BIOS/makefile	(revision 503)
+++ trunk/XTIDE_Universal_BIOS/makefile	(revision 505)
@@ -16,5 +16,5 @@
 # Following modules can be included or excluded:                                                   #
 # 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_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_BOOT_MENU            Boot Menu for selection of drive to boot from                        #
@@ -101,5 +101,5 @@
 DEFINES_XT = $(DEFINES_COMMON) ELIMINATE_CGA_SNOW MODULE_8BIT_IDE MODULE_SERIAL MODULE_SERIAL_FLOPPY
 DEFINES_XTPLUS = $(DEFINES_COMMON) $(DEFINES_XT) USE_186
-DEFINES_AT = $(DEFINES_COMMON) USE_AT USE_286 USE_UNDOC_INTEL RELOCATE_INT13H_STACK MODULE_IRQ MODULE_SERIAL MODULE_SERIAL_FLOPPY MODULE_ADVANCED_ATA 
+DEFINES_AT = $(DEFINES_COMMON) USE_AT USE_286 USE_UNDOC_INTEL RELOCATE_INT13H_STACK MODULE_IRQ MODULE_SERIAL MODULE_SERIAL_FLOPPY MODULE_ADVANCED_ATA
 
 DEFINES_XT_LARGE = $(DEFINES_XT) $(DEFINES_COMMON_LARGE)
