Index: /trunk/Assembly_Library/Inc/Menu.inc
===================================================================
--- /trunk/Assembly_Library/Inc/Menu.inc	(revision 524)
+++ /trunk/Assembly_Library/Inc/Menu.inc	(revision 525)
@@ -5,8 +5,9 @@
 
 ;--------------------------------------------------------------------
-; Menu Library users need to use this macro since it will provide
+; Menu Library users need to use these macros since it will provide
 ; compatibility with future library versions.
 ;
 ; CALL_MENU_LIBRARY
+; JMP_MENU_LIBRARY
 ;	Parameters:
 ;		%1:			Function to call (functionName from MENU_LIB)
@@ -21,32 +22,48 @@
 	%ifidn %1, CloseMenuIfExitEventAllows
 		call	MenuInit_CloseMenuIfExitEventAllows
-
 	%elifidn %1, Close
 		call	MenuInit_CloseMenuWindow
-
 	%elifidn %1, SetUserDataFromDSSI
 		call	MenuInit_SetUserDataFromDSSI
-
 	%elifidn %1, GetUserDataToDSSI
 		call	MenuInit_GetUserDataToDSSI
-
 	%elifidn %1, SetTitleHeightFromAL
 		call	MenuInit_SetTitleHeightFromAL
-
 	%elifidn %1, GetHighlightedItemToAX
 		call	MenuInit_GetHighlightedItemToAX
-
 	%elifidn %1, SetTotalItemsFromAX
 		call	MenuInit_SetTotalItemsFromAX
-
 	%elifidn %1, SetInformationHeightFromAL
 		call	MenuInit_SetInformationHeightFromAL
-
 	%elifidn %1, SetTimeoutValueFromAX
 		call	MenuTime_SetSelectionTimeoutValueFromAX
-
 	%else
 		mov		di, %1
 		call	Menu_FunctionFromDI
+	%endif
+%endmacro
+
+%macro JMP_MENU_LIBRARY 1
+	%ifidn %1, CloseMenuIfExitEventAllows
+		jmp		MenuInit_CloseMenuIfExitEventAllows
+	%elifidn %1, Close
+		jmp		MenuInit_CloseMenuWindow
+	%elifidn %1, SetUserDataFromDSSI
+		jmp		MenuInit_SetUserDataFromDSSI
+	%elifidn %1, GetUserDataToDSSI
+		jmp		MenuInit_GetUserDataToDSSI
+	%elifidn %1, SetTitleHeightFromAL
+		jmp		MenuInit_SetTitleHeightFromAL
+	%elifidn %1, GetHighlightedItemToAX
+		jmp		MenuInit_GetHighlightedItemToAX
+	%elifidn %1, SetTotalItemsFromAX
+		jmp		MenuInit_SetTotalItemsFromAX
+	%elifidn %1, SetInformationHeightFromAL
+		jmp		MenuInit_SetInformationHeightFromAL
+	%elifidn %1, SetTimeoutValueFromAX
+		jmp		MenuTime_SetSelectionTimeoutValueFromAX
+	%else
+		mov		di, %1
+		jmp		Menu_FunctionFromDI
 	%endif
 %endmacro
Index: /trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm
===================================================================
--- /trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 524)
+++ /trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 525)
@@ -714,6 +714,5 @@
 	call	InitializeNullStringsToDialogInputInDSSI
 	mov		WORD [si+DIALOG_INPUT.fszTitle], g_szSelectNewDrive
-	CALL_MENU_LIBRARY GetDriveWithIoInDSSI
-	ret
+	JMP_MENU_LIBRARY GetDriveWithIoInDSSI
 
 ;--------------------------------------------------------------------
Index: /trunk/BIOS_Drive_Information_Tool/Src/Print.asm
===================================================================
--- /trunk/BIOS_Drive_Information_Tool/Src/Print.asm	(revision 524)
+++ /trunk/BIOS_Drive_Information_Tool/Src/Print.asm	(revision 525)
@@ -210,5 +210,5 @@
 	loop	.ReverseNextWord
 	dec		di
-	xor		ax, ax
+	xchg	cx, ax
 	stosb				; Terminate with NULL
 
Index: /trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 524)
+++ /trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 525)
@@ -37,10 +37,10 @@
 struc RAMVARS
 %ifdef RELOCATE_INT13H_STACK
-						resb	256	; Size of our stack
-	.rgbTopOfStack:
+						resb	252
+	.dwStackChangeDSDI:
+	.wStackChangeDI		resb	2	; Used during stack
+	.wStackChangeDS		resb	2	; switching only
+	.rgbTopOfStack:					; 256 bytes of stack
 	.fpInt13hEntryStack	resb	4
-	.dwStackChangeDSDI:
-	.wStackChangeDI		resb	2
-	.wStackChangeDS		resb	2
 %endif
 	.wDrvDetectSignature:			; Signature when BIOS is in drive detection mode
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 524)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 525)
@@ -37,19 +37,26 @@
 ALIGN JUMP_ALIGN
 Int13h_DiskFunctionsHandlerWithStackChange:
-	push	ds
+	sti			; Enable interrupts
+	; TODO: Maybe we need to save Flags (DF) as well?
+	push	ds	; Save DS:DI on the original stack
 	push	di
 	call	RamVars_GetSegmentToDS
 
 	; Store entry registers to RAMVARS
+%ifdef USE_386
+	pop		DWORD [RAMVARS.dwStackChangeDSDI]
+%else
+	pop		WORD [RAMVARS.wStackChangeDI]	; Pop DS:DI to the top of what
+	pop		WORD [RAMVARS.wStackChangeDS]	; is to become the new stack
+%endif
 	mov		[RAMVARS.fpInt13hEntryStack], sp
 	mov		[RAMVARS.fpInt13hEntryStack+2], ss
-	pop		WORD [RAMVARS.wStackChangeDI]
-	pop		WORD [RAMVARS.wStackChangeDS]
 
 	; Load new stack and restore DS and DI
-	mov		di, ds		; We do not want to overwrite DS and DI in stack
-	mov		ss, di
-	mov		sp, RAMVARS.rgbTopOfStack
-	lds		di, [RAMVARS.dwStackChangeDSDI]
+	mov		di, ds		; We can save 2 bytes by using PUSH/POP but it's slower
+	mov		ss, di		; No need to wrap with CLI/STI since this is for AT only (286+)
+	mov		sp, RAMVARS.rgbTopOfStack-4
+	pop		di			; DI before stack change
+	pop		ds			; DS before stack change
 
 	; Call INT 13h
@@ -59,13 +66,12 @@
 
 	; Restore stack (we must not corrupt FLAGS!)
-	cli
 %ifdef USE_386
 	lss		sp, [ss:RAMVARS.fpInt13hEntryStack]
 %else
+	cli
 	mov		sp, [ss:RAMVARS.fpInt13hEntryStack]
 	mov		ss, [ss:RAMVARS.fpInt13hEntryStack+2]
-%endif
-	pop		di			; DI before stack change
-	pop		ds			; DS before stack change
+	sti
+%endif
 	retf	2			; Skip FLAGS from stack
 %endif ; RELOCATE_INT13H_STACK
@@ -88,5 +94,7 @@
 ALIGN JUMP_ALIGN
 Int13h_DiskFunctionsHandler:
+%ifndef RELOCATE_INT13H_STACK
 	sti									; Enable interrupts
+%endif
 	cld									; String instructions to increment pointers
 	CREATE_FRAME_INTPACK_TO_SSBP	SIZE_OF_IDEPACK_WITHOUT_INTPACK
@@ -398,5 +406,5 @@
 	dw	AH1Eh_HandlerForXTCFfeatures				; 1Eh, Lo-tech XT-CF features (XTIDE Universal BIOS)
 %else
-	dw	UnsupportedFunction							; 1Eh, 
+	dw	UnsupportedFunction							; 1Eh,
 %endif
 	dw	UnsupportedFunction							; 1Fh,
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 524)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 525)
@@ -112,15 +112,11 @@
 	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]
-	MIN_U	al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
-	jmp		SHORT AH24h_SetBlockSize	; Returns via AH23h_Enable8bitPioMode
+	cmp		al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
+	jbe		SHORT AH24h_SetBlockSize
+	mov		al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
+	jmp		SHORT AH24h_SetBlockSize
 
 .SetMemoryMappedMode:
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/AutoConfigure.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/AutoConfigure.asm	(revision 524)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/AutoConfigure.asm	(revision 525)
@@ -174,6 +174,9 @@
 ALIGN JUMP_ALIGN
 StoreAndDisplayNumberOfControllers:
-	mov		ax, 1
-	MAX_U	al, cl						; Cannot store zero
+	xor		ax, ax
+	or		al, cl
+	jnz		SHORT .AtLeastOneController
+	inc		ax							; Cannot store zero
+.AtLeastOneController:
 	test	BYTE [di+ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
 	jnz		SHORT .FullModeSoNoNeedToLimit
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Dialogs.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Dialogs.asm	(revision 524)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Dialogs.asm	(revision 525)
@@ -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
@@ -190,6 +190,5 @@
 	mov		dx, ds
 	mov		ax, bx
-	CALL_MENU_LIBRARY StartProgressTaskWithIoInDSSIandParamInDXAX
-	ret
+	JMP_MENU_LIBRARY StartProgressTaskWithIoInDSSIandParamInDXAX
 
 
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Main.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Main.asm	(revision 524)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Main.asm	(revision 525)
@@ -1,3 +1,3 @@
-; Project name	:	XTIDE Univeral BIOS Configurator v2
+; Project name	:	XTIDE Universal BIOS Configurator v2
 ; Description	:	Program start and exit.
 
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/MenuEvents.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/MenuEvents.asm	(revision 524)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/MenuEvents.asm	(revision 525)
@@ -33,6 +33,5 @@
 MenuEvents_DisplayMenu:
 	mov		bx, MenuEventHandler
-	CALL_MENU_LIBRARY DisplayWithHandlerInBXandUserDataInDXAX
-	ret
+	JMP_MENU_LIBRARY DisplayWithHandlerInBXandUserDataInDXAX
 
 
@@ -218,5 +217,6 @@
 	jnz		SHORT .PrintNameOfLoadedFile
 	test	ax, FLG_CFGVARS_ROMLOADED
-	jnz		SHORT .PrintLoadedEeprom
+	mov		si, g_szEEPROM
+	jnz		SHORT .PrintNameOfLoadedFileOrEeprom
 	; Fall to .PrintNothingLoaded
 
@@ -228,14 +228,11 @@
 .PrintNameOfLoadedFile:
 	mov		si, g_cfgVars+CFGVARS.szOpenedFile
-	CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
-	jmp		SHORT .PrintTypeOfLoadedBios
-
-ALIGN JUMP_ALIGN
-.PrintLoadedEeprom:
-	mov		si, g_szEEPROM
+	; Fall to .PrintNameOfLoadedFileOrEeprom
+
+ALIGN JUMP_ALIGN
+.PrintNameOfLoadedFileOrEeprom:
 	CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
 	; Fall to .PrintTypeOfLoadedBios
 
-ALIGN JUMP_ALIGN
 .PrintTypeOfLoadedBios:
 	mov		si, g_szSourceAndTypeSeparator
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menuitem.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menuitem.asm	(revision 524)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menuitem.asm	(revision 525)
@@ -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
@@ -168,5 +168,5 @@
 	call	GetConfigurationBufferToESDIforMenuitemInDSSI
 	add		di, [si+MENUITEM.itemValue+ITEM_VALUE.wRomvarsValueOffset]
-		
+
 	push	bx
 	mov		bx,[si+MENUITEM.itemValue+ITEM_VALUE.fnValueWriter]
@@ -176,5 +176,5 @@
 .NoWriter:
 	pop		bx
-		
+
 	jmp		[cs:bx+.rgfnJumpToStoreValueBasedOnItemType]
 .InvalidItemType:
@@ -295,6 +295,5 @@
 	CALL_MENU_LIBRARY RefreshTitle
 	CALL_MENU_LIBRARY GetHighlightedItemToAX
-	CALL_MENU_LIBRARY RefreshItemFromAX
-	ret
+	JMP_MENU_LIBRARY RefreshItemFromAX
 
 ALIGN JUMP_ALIGN
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupage.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupage.asm	(revision 524)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupage.asm	(revision 525)
@@ -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
@@ -39,6 +39,5 @@
 	xor		ax, ax
 	CALL_MENU_LIBRARY HighlightItemFromAX
-	CALL_MENU_LIBRARY RefreshWindow
-	ret
+	JMP_MENU_LIBRARY RefreshWindow
 
 
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/MainMenu.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/MainMenu.asm	(revision 524)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/MainMenu.asm	(revision 525)
@@ -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 initialized data
@@ -29,5 +29,5 @@
 iend
 
-g_MenuitemMainMenuLicense:		
+g_MenuitemMainMenuLicense:
 istruc MENUITEM
 	at	MENUITEM.fnActivate,		dw	Menuitem_DisplayHelpMessageFromDSSI
@@ -35,8 +35,8 @@
 	at	MENUITEM.szQuickInfo,		dw	g_szNfoMainLicense
 	at	MENUITEM.szHelp,			dw	g_szHelpMainLicense
-	at	MENUITEM.bFlags,			db	FLG_MENUITEM_VISIBLE		
-	at	MENUITEM.bType,				db	TYPE_MENUITEM_ACTION
-iend
-		
+	at	MENUITEM.bFlags,			db	FLG_MENUITEM_VISIBLE
+	at	MENUITEM.bType,				db	TYPE_MENUITEM_ACTION
+iend
+
 g_MenuitemMainMenuLoadBiosFromFile:
 istruc MENUITEM
@@ -89,5 +89,5 @@
 iend
 
-g_MenuitemMainMenuSaveFile:		
+g_MenuitemMainMenuSaveFile:
 istruc MENUITEM
 	at	MENUITEM.fnActivate,		dw	BiosFile_SaveUnsavedChanges
@@ -97,5 +97,5 @@
 	at	MENUITEM.bFlags,			db	NULL
 	at	MENUITEM.bType,				db	TYPE_MENUITEM_ACTION
-iend		
+iend
 
 g_MenuitemMainMenuExitToDos:
@@ -109,5 +109,5 @@
 iend
 
-g_MenuitemMainMenuHomePage:		
+g_MenuitemMainMenuHomePage:
 istruc MENUITEM
 	at	MENUITEM.fnActivate,		dw	Menuitem_DisplayHelpMessageFromDSSI
@@ -115,7 +115,7 @@
 	at	MENUITEM.szQuickInfo,		dw	g_szNfoMainHomePage
 	at	MENUITEM.szHelp,			dw	g_szNfoMainHomePage
-	at	MENUITEM.bFlags,			db	FLG_MENUITEM_VISIBLE		
-	at	MENUITEM.bType,				db	TYPE_MENUITEM_ACTION
-iend						
+	at	MENUITEM.bFlags,			db	FLG_MENUITEM_VISIBLE
+	at	MENUITEM.bType,				db	TYPE_MENUITEM_ACTION
+iend
 
 
@@ -139,5 +139,5 @@
 	call	.EnableOrDisableConfigureXtideUniversalBios
 	call	.EnableOrDisableFlashEeprom
-	call	.EnableOrDisableSave			
+	call	.EnableOrDisableSave
 	mov		si, g_MenupageForMainMenu
 	jmp		Menupage_ChangeToNewMenupageInDSSI
@@ -220,6 +220,6 @@
 ;		Nothing
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN		
-.EnableOrDisableSave:	
+ALIGN JUMP_ALIGN
+.EnableOrDisableSave:
 	test	WORD [g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_FILELOADED
 	jz		SHORT .DisableSave
@@ -227,9 +227,9 @@
 	ret
 
-ALIGN JUMP_ALIGN				
+ALIGN JUMP_ALIGN
 .DisableSave:
 	and		BYTE [g_MenuitemMainMenuSaveFile+MENUITEM.bFlags], ~FLG_MENUITEM_VISIBLE
 	ret
-				
+
 ;--------------------------------------------------------------------
 ; MENUITEM activation functions (.fnActivate)
@@ -243,7 +243,5 @@
 ALIGN JUMP_ALIGN
 ExitToDosSelectedFromMenu:
-	CALL_MENU_LIBRARY CloseMenuIfExitEventAllows
-ExitToDosFromBackButton:
-	ret
+	JMP_MENU_LIBRARY CloseMenuIfExitEventAllows
 
 
@@ -262,4 +260,5 @@
 .CancelFileLoading:
 	add		sp, BYTE FILE_DIALOG_IO_size
+ExitToDosFromBackButton:
 	ret
 
@@ -284,4 +283,2 @@
 	jmp		Dialogs_DisplayNotificationFromCSDX
 
-
-	
