Index: trunk/Assembly_Library/Inc/Emulate.inc
===================================================================
--- trunk/Assembly_Library/Inc/Emulate.inc	(revision 178)
+++ trunk/Assembly_Library/Inc/Emulate.inc	(revision 181)
@@ -452,5 +452,6 @@
 		times %2	%3		%1, 1
 	%else
-		%if %2 > 7
+;		%if %2 > 7	; Original value
+		%if %2 > 3	; Size optimized value
 			push	cx
 			mov		cl, %2
Index: trunk/Assembly_Library/Inc/Math.inc
===================================================================
--- trunk/Assembly_Library/Inc/Math.inc	(revision 178)
+++ trunk/Assembly_Library/Inc/Math.inc	(revision 181)
@@ -43,5 +43,5 @@
 ;		%2:		Operand 2
 ;	Returns:
-;		%1:		Lesser operand
+;		%1:		Greater operand
 ;	Corrupts registers:
 ;		Nothing
Index: trunk/Assembly_Library/Src/Display/Display.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/Display.asm	(revision 178)
+++ trunk/Assembly_Library/Src/Display/Display.asm	(revision 181)
@@ -57,38 +57,38 @@
 	jmp		ax
 
-		
-%define InitializeDisplayContext						DisplayContext_Initialize
+
+	%define InitializeDisplayContext						DisplayContext_Initialize
 
 %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
-%define SetCharacterPointerFromBXAX						DisplayContext_SetCharacterPointerFromBXAX
+	%define SetCharacterPointerFromBXAX						DisplayContext_SetCharacterPointerFromBXAX
 %endif
-%define SetCharOutputFunctionFromAXwithAttribFlagInBL	DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
-%define SetCharacterOutputParameterFromAX				DisplayContext_SetCharacterOutputParameterFromAX
-%define SetCharacterAttributeFromAL						DisplayContext_SetCharacterAttributeFromAL
-%define SetCursorShapeFromAX							DisplayCursor_SetShapeFromAX
-%define SetCursorCoordinatesFromAX						DisplayCursor_SetCoordinatesFromAX
-%define SetNewPageFromAL								DisplayPage_SetFromAL
-%define SynchronizeDisplayContextToHardware				DisplayContext_SynchronizeToHardware
+	%define SetCharOutputFunctionFromAXwithAttribFlagInBL	DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
+	%define SetCharacterOutputParameterFromAX				DisplayContext_SetCharacterOutputParameterFromAX
+	%define SetCharacterAttributeFromAL						DisplayContext_SetCharacterAttributeFromAL
+	%define SetCursorShapeFromAX							DisplayCursor_SetShapeFromAX
+	%define SetCursorCoordinatesFromAX						DisplayCursor_SetCoordinatesFromAX
+	%define SetNewPageFromAL								DisplayPage_SetFromAL
+	%define SynchronizeDisplayContextToHardware				DisplayContext_SynchronizeToHardware
 
 %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
-%define GetCharacterPointerToBXAX						DisplayContext_GetCharacterPointerToBXAX
+	%define GetCharacterPointerToBXAX						DisplayContext_GetCharacterPointerToBXAX
 %endif
-%define GetSoftwareCoordinatesToAX						DisplayCursor_GetSoftwareCoordinatesToAX
-%define GetColumnsToALandRowsToAH						DisplayPage_GetColumnsToALandRowsToAH
+	%define GetSoftwareCoordinatesToAX						DisplayCursor_GetSoftwareCoordinatesToAX
+	%define GetColumnsToALandRowsToAH						DisplayPage_GetColumnsToALandRowsToAH
 
-%define FormatNullTerminatedStringFromCSSI				Display_FormatNullTerminatedStringFromCSSI
+	%define FormatNullTerminatedStringFromCSSI				Display_FormatNullTerminatedStringFromCSSI
 %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
-%define PrintSignedWordFromAXWithBaseInBX				DisplayPrint_SignedWordFromAXWithBaseInBX
+	%define PrintSignedWordFromAXWithBaseInBX				DisplayPrint_SignedWordFromAXWithBaseInBX
 %endif
-%define PrintWordFromAXwithBaseInBX						DisplayPrint_WordFromAXWithBaseInBX
-%define PrintCharBufferFromBXSIwithLengthInCX			DisplayPrint_CharacterBufferFromBXSIwithLengthInCX
-%define PrintNullTerminatedStringFromBXSI				DisplayPrint_NullTerminatedStringFromBXSI
-%define PrintNullTerminatedStringFromCSSI				DisplayPrint_NullTerminatedStringFromCSSI
-%define PrintRepeatedCharacterFromALwithCountInCX		DisplayPrint_RepeatCharacterFromALwithCountInCX
-%define PrintCharacterFromAL							DisplayPrint_CharacterFromAL
-%define PrintNewlineCharacters							DisplayPrint_Newline
+	%define PrintWordFromAXwithBaseInBX						DisplayPrint_WordFromAXWithBaseInBX
+	%define PrintCharBufferFromBXSIwithLengthInCX			DisplayPrint_CharacterBufferFromBXSIwithLengthInCX
+	%define PrintNullTerminatedStringFromBXSI				DisplayPrint_NullTerminatedStringFromBXSI
+	%define PrintNullTerminatedStringFromCSSI				DisplayPrint_NullTerminatedStringFromCSSI
+	%define PrintRepeatedCharacterFromALwithCountInCX		DisplayPrint_RepeatCharacterFromALwithCountInCX
+	%define PrintCharacterFromAL							DisplayPrint_CharacterFromAL
+	%define PrintNewlineCharacters							DisplayPrint_Newline
 %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
-%define ClearAreaWithHeightInAHandWidthInAL				DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
+	%define ClearAreaWithHeightInAHandWidthInAL				DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
 %endif
-%define ClearScreenWithCharInALandAttrInAH				DisplayPrint_ClearScreenWithCharInALandAttributeInAH
+	%define ClearScreenWithCharInALandAttrInAH				DisplayPrint_ClearScreenWithCharInALandAttributeInAH
 
Index: trunk/Assembly_Library/Src/Display/DisplayContext.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayContext.asm	(revision 178)
+++ trunk/Assembly_Library/Src/Display/DisplayContext.asm	(revision 181)
@@ -268,10 +268,10 @@
 ;		Nothing
 ;--------------------------------------------------------------------
-;%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS	; This appears to be completely unused
-;ALIGN JUMP_ALIGN
-;DisplayContext_GetCharacterOutputParameterToDX:
-;	mov		dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
-;	ret
-;%endif
+%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS OR EXCLUDE_FROM_XTIDECFG	; This is currently unused (dead code)
+ALIGN JUMP_ALIGN
+DisplayContext_GetCharacterOutputParameterToDX:
+	mov		dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
+	ret
+%endif
 
 
Index: trunk/Assembly_Library/Src/Display/DisplayFormat.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayFormat.asm	(revision 178)
+++ trunk/Assembly_Library/Src/Display/DisplayFormat.asm	(revision 181)
@@ -52,6 +52,6 @@
 	dec		bp
 	dec		bp				; SS:BP now points to next parameter
-	test	cx, cx
-	jnz		SHORT PrependOrAppendSpaces
+	inc		cx
+	loop	PrependOrAppendSpaces
 ReturnFromFormat:
 	ret
Index: trunk/Assembly_Library/Src/Display/DisplayPrint.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayPrint.asm	(revision 178)
+++ trunk/Assembly_Library/Src/Display/DisplayPrint.asm	(revision 181)
@@ -158,5 +158,5 @@
 	loop	.PrintNextCharacter
 
-	mov		ds, cx	; Restore DS to BDA. Not needed unless DisplayPrint_CharacterFromAL changes DS.
+	;mov		ds, cx	; Restore DS to BDA. Not needed unless DisplayPrint_CharacterFromAL changes DS.
 	pop		cx
 	pop		si
@@ -304,5 +304,5 @@
 ;		DI:		Updated offset to video RAM
 ;	Corrupts registers:
-;		AX, DX
+;		DX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
Index: trunk/Assembly_Library/Src/File/Drive.asm
===================================================================
--- trunk/Assembly_Library/Src/File/Drive.asm	(revision 178)
+++ trunk/Assembly_Library/Src/File/Drive.asm	(revision 181)
@@ -72,5 +72,9 @@
 	call	Drive_SetDefaultFromDL
 	eMOVZX	cx, al			; Number of potentially valid drive letters available
-	MIN_U	cx, 32
+	cmp		cl, 32
+	jb		SHORT .Return
+	mov		cl, 32
+ALIGN JUMP_ALIGN, ret
+.Return:
 	ret
 
Index: trunk/Assembly_Library/Src/Menu/CharOutLineSplitter.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/CharOutLineSplitter.asm	(revision 178)
+++ trunk/Assembly_Library/Src/Menu/CharOutLineSplitter.asm	(revision 181)
@@ -104,5 +104,5 @@
 ;--------------------------------------------------------------------
 .GetOffsetToPartialWordToSIandSizeToCX:
-	xor		cx, cx
+	mov		cx, di
 	mov		si, di
 ALIGN JUMP_ALIGN
@@ -111,12 +111,8 @@
 	dec		si
 	cmp		BYTE [es:si], ' '
-	je		SHORT .PartialWordFound
-	inc		cx
-	jmp		SHORT .ScanNextCharacter
-ALIGN JUMP_ALIGN
-.PartialWordFound:
+	jne		SHORT .ScanNextCharacter
 	inc		si
 	inc		si			; SI now points one past space
-	shl		cx, 1		; Characters to bytes
+	sub		cx, si
 	; Fall to .ChangeLine
 
Index: trunk/Assembly_Library/Src/Menu/Dialog/Dialog.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/Dialog.asm	(revision 178)
+++ trunk/Assembly_Library/Src/Menu/Dialog/Dialog.asm	(revision 181)
@@ -127,4 +127,5 @@
 	ret
 
+
 ;--------------------------------------------------------------------
 ; .GetWidthBasedOnParentMenuToAL
@@ -141,6 +142,11 @@
 	mov		al, [ss:bx+MENUINIT.bWidth]
 	sub		al, DIALOG_DELTA_WIDTH_FROM_PARENT
-	MIN_U	al, DIALOG_MAX_WIDTH
-	ret
+	cmp		al, DIALOG_MAX_WIDTH
+	jb		.ALlessThanDIALOG_MAX_WIDTH
+	mov		al, DIALOG_MAX_WIDTH
+ALIGN JUMP_ALIGN, ret
+.ALlessThanDIALOG_MAX_WIDTH:
+	ret
+
 
 ;--------------------------------------------------------------------
@@ -161,6 +167,14 @@
 	add		ah, [bp+MENUINIT.bInfoLines]
 	add		ah, BYTE MENU_VERTICAL_BORDER_LINES
-	MIN_U	ah, bh
-	MIN_U	ah, DIALOG_MAX_HEIGHT
+	cmp		ah, bh
+	jb		.AHlessThanBH
+	xchg	bx, ax
+ALIGN JUMP_ALIGN
+.AHlessThanBH:
+	cmp		ah, DIALOG_MAX_HEIGHT
+	jb		.AHlessThanDIALOG_MAX_HEIGHT
+	mov		ah, DIALOG_MAX_HEIGHT
+ALIGN JUMP_ALIGN, ret
+.AHlessThanDIALOG_MAX_HEIGHT:
 	ret
 
Index: trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 178)
+++ trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 181)
@@ -265,5 +265,5 @@
 .FilterCurrentDirectory:
 	cmp		WORD [si+DTA.szFile], CURRENTDIR_CHARACTERS
-	je		SHORT .ReturnWithFiltering
+	je		SHORT .DoFilter
 	ret
 
@@ -274,5 +274,5 @@
 	cmp		WORD [si+DTA.szFile], UPDIR_CHARACTERS
 	jne		SHORT .ReturnWithoutFiltering
-.ReturnWithFiltering:
+.DoFilter:
 	add		sp, BYTE 2		; Remove return address from stack
 ALIGN JUMP_ALIGN, ret
@@ -375,16 +375,15 @@
 SortDirectoryContentsStringFromESDIwithCountInCX:
 	call	Registers_CopyESDItoDSSI
-	call	.AddDirectoryContentsStringLengthToDI
-	mov		bx, .FileStringComparator
-	xchg	dx, cx
-	mov		cx, FILE_STRING_LENGTH
-	jmp		Sort_ItemsFromDSSIwithCountInDXsizeInCXandComparatorInBX
-
-ALIGN JUMP_ALIGN
-.AddDirectoryContentsStringLengthToDI:
+
+	; Add directory contents string length to DI
 	mov		ax, FILE_STRING_LENGTH
+	push	ax
 	mul		cx
 	add		di, ax
-	ret
+
+	mov		dx, cx
+	pop		cx
+	mov		bx, .FileStringComparator
+	jmp		Sort_ItemsFromDSSIwithCountInDXsizeInCXandComparatorInBX
 
 ;--------------------------------------------------------------------
@@ -395,5 +394,5 @@
 ;		ES:DI:	Ptr to second item to compare
 ;	Returns:
-;		FLAGS:	Signed comparition between first and second item
+;		FLAGS:	Signed comparison between first and second item
 ;	Corrupts registers:
 ;		Nothing
Index: trunk/Assembly_Library/Src/Menu/Dialog/DialogProgress.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/DialogProgress.asm	(revision 178)
+++ trunk/Assembly_Library/Src/Menu/Dialog/DialogProgress.asm	(revision 181)
@@ -1,7 +1,3 @@
-; File name		:	DialogProgress.asm
 ; Project name	:	Assembly Library
-; Created date	:	15.8.2010
-; Last update	:	10.12.2010
-; Author		:	Tomi Tilli
 ; Description	:	Displays progress bar dialog and starts progress task.
 
@@ -41,8 +37,10 @@
 	lds		si, [bp+DIALOG.fpDialogIO]
 	mov		bx, [si+PROGRESS_DIALOG_IO.wMaxProgressValue]
-	MIN_U	ax, bx
-	cmp		ax, bx	; Make sure that last progress character is shown
-	je		SHORT .UpdateProgressBar
-
+	cmp		ax, bx
+	jb		SHORT .AXlessThanBX
+	mov		ax, bx
+	jmp		SHORT .UpdateProgressBar
+ALIGN JUMP_ALIGN
+.AXlessThanBX:
 	mov		bx, ax
 	sub		bx, [si+PROGRESS_DIALOG_IO.wCurrentProgressValue]
@@ -172,26 +170,5 @@
 ALIGN JUMP_ALIGN
 DrawProgressBarFromDialogIoInDSSI:
-	call	.GetFullCharsToCXandEmptyCharsToDXwithDialogIoInDSSI
-
-	mov		al, PROGRESS_COMPLETE_CHARACTER
-	call	.RepeatProgressCharacterCXtimesFromAL
-
-	mov		cx, dx
-	mov		al, PROGRESS_INCOMPLETE_CHARACTER
-	jmp		SHORT .RepeatProgressCharacterCXtimesFromAL
-
-;--------------------------------------------------------------------
-; .GetFullCharsToCXandEmptyCharsToDXwithDialogIoInDSSI
-;	Parameters:
-;		DS:SI:	Ptr to PROGRESS_DIALOG_IO
-;		SS:BP:	Ptr to DIALOG
-;	Returns:
-;		CX:		Number of full progress bar characters
-;		DX:		Number of empty progress bar characters
-;	Corrupts:
-;		AX, BX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.GetFullCharsToCXandEmptyCharsToDXwithDialogIoInDSSI:
+	; Get full chars to CX and empty chars to DX
 	call	MenuLocation_GetMaxTextLineLengthToAX
 	mov		cx, ax
@@ -200,8 +177,13 @@
 	div		bx
 	xchg	cx, ax		; AX = Text line length, CX = Number of full chars
-
 	sub		ax, cx
 	xchg	dx, ax		; DX = Number of empty chars
-	ret
+
+	mov		al, PROGRESS_COMPLETE_CHARACTER
+	call	.RepeatProgressCharacterCXtimesFromAL
+
+	mov		cx, dx
+	mov		al, PROGRESS_INCOMPLETE_CHARACTER
+	; Fall to .RepeatProgressCharacterCXtimesFromAL
 
 ;--------------------------------------------------------------------
@@ -239,5 +221,5 @@
 	ret
 
-	
+
 ;--------------------------------------------------------------------
 ; DrawTimeElapsedFromDX
@@ -286,8 +268,8 @@
 
 	sub		cx, [si+PROGRESS_DIALOG_IO.wMinProgressValue]
-	jcxz	.PreventDivisionByZero
+	jz		SHORT .PreventDivisionByZero
 	div		cx			; AX = Estimated ticks left
 	xchg	dx, ax
-	jmp		SHORT FormatTicksFromDX
+	SKIP2B	f	; cmp ax, <next instruction>
 .PreventDivisionByZero:
 	xor		dx, dx
Index: trunk/Assembly_Library/Src/Menu/Dialog/ItemLineSplitter.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/ItemLineSplitter.asm	(revision 178)
+++ trunk/Assembly_Library/Src/Menu/Dialog/ItemLineSplitter.asm	(revision 181)
@@ -115,8 +115,7 @@
 ALIGN JUMP_ALIGN
 .CheckLineLength:
-	cmp		cx, [bp+ITEM_LINE_SPLITTER.wMaxTextLineLength]
-	ja		SHORT .ChangeToNextLine
-	clc
-	ret
+	cmp		[bp+ITEM_LINE_SPLITTER.wMaxTextLineLength], cx
+	jb		SHORT .ChangeToNextLine
+	ret		; With CF cleared
 
 ALIGN JUMP_ALIGN
Index: trunk/Assembly_Library/Src/Menu/Menu.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Menu.asm	(revision 178)
+++ trunk/Assembly_Library/Src/Menu/Menu.asm	(revision 181)
@@ -31,35 +31,35 @@
 
 
-%define DisplayWithHandlerInBXandUserDataInDXAX		MenuInit_DisplayMenuWithHandlerInBXandUserDataInDXAX
-;%define Close										MenuInit_CloseMenuWindow				; Special case in CALL_MENU_LIBRARY
-%define RefreshWindow						MenuInit_RefreshMenuWindow
+	%define DisplayWithHandlerInBXandUserDataInDXAX			MenuInit_DisplayMenuWithHandlerInBXandUserDataInDXAX
+	;%define Close											MenuInit_CloseMenuWindow				; Special case in CALL_MENU_LIBRARY
+	%define RefreshWindow									MenuInit_RefreshMenuWindow
 
-;%define SetUserDataFromDSSI				MenuInit_SetUserDataFromDSSI			; Special case in CALL_MENU_LIBRARY
-;%define GetUserDataToDSSI					MenuInit_GetUserDataToDSSI				; Special case in CALL_MENU_LIBRARY
+	;%define SetUserDataFromDSSI							MenuInit_SetUserDataFromDSSI			; Special case in CALL_MENU_LIBRARY
+	;%define GetUserDataToDSSI								MenuInit_GetUserDataToDSSI				; Special case in CALL_MENU_LIBRARY
 
-;%define SetTitleHeightFromAL				MenuInit_SetTitleHeightFromAL			; Special case in CALL_MENU_LIBRARY
-%define ClearTitleArea						MenuText_ClearTitleArea
-%define RefreshTitle						MenuText_RefreshTitle
+	;%define SetTitleHeightFromAL							MenuInit_SetTitleHeightFromAL			; Special case in CALL_MENU_LIBRARY
+	%define ClearTitleArea									MenuText_ClearTitleArea
+	%define RefreshTitle									MenuText_RefreshTitle
 
-%define HighlightItemFromAX					MenuInit_HighlightItemFromAX
-;%define SetTotalItemsFromAX				MenuInit_SetTotalItemsFromAX			; Special case in CALL_MENU_LIBRARY
-%define RefreshItemFromAX					MenuText_RefreshItemFromAX
+	%define HighlightItemFromAX								MenuInit_HighlightItemFromAX
+	;%define SetTotalItemsFromAX							MenuInit_SetTotalItemsFromAX			; Special case in CALL_MENU_LIBRARY
+	%define RefreshItemFromAX								MenuText_RefreshItemFromAX
 
-;%define SetInformationHeightFromAL						MenuInit_SetInformationHeightFromAL		; Special case in CALL_MENU_LIBRARY
-%define ClearInformationArea							MenuText_ClearInformationArea
-%define RefreshInformation								MenuText_RefreshInformation
+	;%define SetInformationHeightFromAL						MenuInit_SetInformationHeightFromAL		; Special case in CALL_MENU_LIBRARY
+	%define ClearInformationArea							MenuText_ClearInformationArea
+	%define RefreshInformation								MenuText_RefreshInformation
 
-%define StartSelectionTimeoutWithTicksInAX				MenuTime_StartSelectionTimeoutWithTicksInAX
+	%define StartSelectionTimeoutWithTicksInAX				MenuTime_StartSelectionTimeoutWithTicksInAX
 
 %ifdef INCLUDE_MENU_DIALOGS
-%define StartProgressTaskWithIoInDSSIandParamInDXAX		DialogProgress_StartProgressTaskWithIoInDSSIandParamInDXAX
-%define SetProgressValueFromAX							DialogProgress_SetProgressValueFromAX
+	%define StartProgressTaskWithIoInDSSIandParamInDXAX		DialogProgress_StartProgressTaskWithIoInDSSIandParamInDXAX
+	%define SetProgressValueFromAX							DialogProgress_SetProgressValueFromAX
 
-%define DisplayMessageWithInputInDSSI					DialogMessage_DisplayMessageWithInputInDSSI
-%define GetSelectionToAXwithInputInDSSI					DialogSelection_GetSelectionToAXwithInputInDSSI
-%define GetWordWithIoInDSSI								DialogWord_GetWordWithIoInDSSI
-%define GetStringWithIoInDSSI							DialogString_GetStringWithIoInDSSI
-%define GetFileNameWithIoInDSSI							DialogFile_GetFileNameWithIoInDSSI
-%define GetDriveWithIoInDSSI							DialogDrive_GetDriveWithIoInDSSI
+	%define DisplayMessageWithInputInDSSI					DialogMessage_DisplayMessageWithInputInDSSI
+	%define GetSelectionToAXwithInputInDSSI					DialogSelection_GetSelectionToAXwithInputInDSSI
+	%define GetWordWithIoInDSSI								DialogWord_GetWordWithIoInDSSI
+	%define GetStringWithIoInDSSI							DialogString_GetStringWithIoInDSSI
+	%define GetFileNameWithIoInDSSI							DialogFile_GetFileNameWithIoInDSSI
+	%define GetDriveWithIoInDSSI							DialogDrive_GetDriveWithIoInDSSI
 %endif
 
Index: trunk/Assembly_Library/Src/Menu/MenuLocation.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuLocation.asm	(revision 178)
+++ trunk/Assembly_Library/Src/Menu/MenuLocation.asm	(revision 181)
@@ -4,26 +4,4 @@
 ; Section containing code
 SECTION .text
-
-;--------------------------------------------------------------------
-; MenuLocation_GetTitleTextTopLeftCoordinatesToAX
-; MenuLocation_GetInformationTextTopLeftCoordinatesToAX
-;	Parameters
-;		SS:BP:	Ptr to MENU
-;	Returns:
-;		AL:		Column (X)
-;		AH:		Row (Y)
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-MenuLocation_GetTitleTextTopLeftCoordinatesToAX:
-	mov		ax, (MENU_TEXT_ROW_OFFSET<<8) | MENU_TEXT_COLUMN_OFFSET
-	jmp		SHORT MenuLocation_AddTitleBordersTopLeftCoordinatesToAX
-
-ALIGN JUMP_ALIGN
-MenuLocation_GetInformationTextTopLeftCoordinatesToAX:
-	mov		ax, (MENU_TEXT_ROW_OFFSET<<8) | MENU_TEXT_COLUMN_OFFSET
-	jmp		SHORT AddInformationBordersTopLeftCoordinatesToAX
-
 
 ;--------------------------------------------------------------------
@@ -43,10 +21,12 @@
 	xchg	al, ah								; Line to AH, clear AL
 	add		ax, (MENU_TEXT_ROW_OFFSET<<8) | MENU_TEXT_COLUMN_OFFSET
-	jmp		SHORT AddItemBordersTopLeftCoordinatesToAX
-
+	SKIP2B	f	; cmp ax, <next instruction>
+	; Fall to MenuLocation_GetItemBordersTopLeftCoordinatesToAX
 
 ;--------------------------------------------------------------------
+; MenuLocation_GetItemBordersTopLeftCoordinatesToAX
+; MenuLocation_GetTitleTextTopLeftCoordinatesToAX
 ; MenuLocation_GetTitleBordersTopLeftCoordinatesToAX
-; MenuLocation_GetItemBordersTopLeftCoordinatesToAX
+; MenuLocation_GetInformationTextTopLeftCoordinatesToAX
 ; MenuLocation_GetBottomBordersTopLeftCoordinatesToAX
 ;	Parameters
@@ -58,5 +38,12 @@
 ;		Nothing
 ;--------------------------------------------------------------------
+MenuLocation_GetItemBordersTopLeftCoordinatesToAX:
+	xor		ax, ax
+	jmp		SHORT AddItemBordersTopLeftCoordinatesToAX
+
 ALIGN JUMP_ALIGN
+MenuLocation_GetTitleTextTopLeftCoordinatesToAX:
+	mov		ax, (MENU_TEXT_ROW_OFFSET<<8) | MENU_TEXT_COLUMN_OFFSET
+	SKIP2B	f	; cmp ax, <next instruction>
 MenuLocation_GetTitleBordersTopLeftCoordinatesToAX:
 	xor		ax, ax
@@ -64,7 +51,7 @@
 
 ALIGN JUMP_ALIGN
-MenuLocation_GetItemBordersTopLeftCoordinatesToAX:
-	xor		ax, ax
-	jmp		SHORT AddItemBordersTopLeftCoordinatesToAX
+MenuLocation_GetInformationTextTopLeftCoordinatesToAX:
+	mov		ax, (MENU_TEXT_ROW_OFFSET<<8) | MENU_TEXT_COLUMN_OFFSET
+	jmp		SHORT AddInformationBordersTopLeftCoordinatesToAX
 
 ALIGN JUMP_ALIGN
Index: trunk/Assembly_Library/Src/Menu/MenuScrollbars.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuScrollbars.asm	(revision 178)
+++ trunk/Assembly_Library/Src/Menu/MenuScrollbars.asm	(revision 181)
@@ -37,15 +37,19 @@
 MenuScrollbars_GetScrollCharacterToALForLineInDI:
 	call	MenuScrollbars_GetMaxVisibleItemsOnPageToCX
-	call	.GetFirstThumbLineToAX
+	; Get first thumb line to AX
+	mov		ax, [bp+MENU.wFirstVisibleItem]
+	call	.CalculateFirstOrLastThumbLineToAX
+
 	cmp		di, ax				; Before first thumb line?
 	jb		SHORT .ReturnTrackCharacter
 	call	.GetLastThumbLineToAX
-	cmp		di, ax				; After last thumb line?
-	ja		SHORT .ReturnTrackCharacter
-	mov		al, SCROLL_THUMB_CHARACTER
-	ret
+	cmp		ax, di				; After last thumb line?
 ALIGN JUMP_ALIGN
 .ReturnTrackCharacter:
 	mov		al, SCROLL_TRACK_CHARACTER
+	jb		SHORT .Return
+	mov		al, SCROLL_THUMB_CHARACTER
+ALIGN JUMP_ALIGN, ret
+.Return:
 	ret
 
@@ -63,9 +67,10 @@
 .GetLastThumbLineToAX:
 	call	MenuScrollbars_GetLastVisibleItemOnPageToAX
-	jmp		SHORT .CalculateFirstOrLastThumbLineToAX
-
-;--------------------------------------------------------------------
-; .GetFirstThumbLineToAX
-;	Parameters
+	; Fall to .CalculateFirstOrLastThumbLineToAX
+
+;--------------------------------------------------------------------
+; .CalculateFirstOrLastThumbLineToAX
+;	Parameters
+;		AX:		Index of first or last visible item on page
 ;		CX:		Max visible items on page
 ;		SS:BP:	Ptr to MENU
@@ -76,6 +81,4 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-.GetFirstThumbLineToAX:
-	mov		ax, [bp+MENU.wFirstVisibleItem]
 .CalculateFirstOrLastThumbLineToAX:
 	mul		cx
@@ -98,5 +101,26 @@
 	mov		cx, [bp+MENUINIT.wHighlightedItem]
 	add		cx, ax
-	call	.RotateItemInCX
+	; Fall to .RotateItemInCX
+
+;--------------------------------------------------------------------
+; .RotateItemInCX
+;	Parameters
+;		CX:		Possibly under of overflown item to be rotated
+;		SS:BP:	Ptr to MENU
+;	Returns:
+;		CX:		Valid item index
+;	Corrupts registers:
+;		DX
+;--------------------------------------------------------------------
+;.RotateItemInCX:
+	mov		dx, [bp+MENUINIT.wItems]
+	test	cx, cx
+	js		SHORT .RotateNegativeItemInCX
+	sub		cx, dx
+	jae		SHORT .ScrollPageForNewItemInCX
+
+ALIGN JUMP_ALIGN
+.RotateNegativeItemInCX:
+	add		cx, dx
 	; Fall to .ScrollPageForNewItemInCX
 
@@ -111,4 +135,5 @@
 ;		AX, BX, CX, DX, SI, DI
 ;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
 .ScrollPageForNewItemInCX:
 	call	MenuScrollbars_IsItemInCXonVisiblePage
@@ -117,8 +142,24 @@
 	mov		dx, [bp+MENU.wFirstVisibleItem]
 	sub		dx, [bp+MENUINIT.wHighlightedItem]
+
+	; Get MaxFirstVisibleItem to AX
+	push	cx
+	call	MenuScrollbars_GetMaxVisibleItemsOnPageToCX
+	mov		ax, [bp+MENUINIT.wItems]
+	sub		ax, cx
+	pop		cx
+
 	add		dx, cx
-	MAX_S	dx, 0
-	call	.GetMaxFirstVisibleItemToAX
-	MIN_U	ax, dx
+	jns		.DXisPositive
+	cwd		; This won't work if MaxFirstVisibleItem > 32767
+
+ALIGN JUMP_ALIGN
+.DXisPositive:
+	cmp		ax, dx
+	jb		.AXisLessThanDX
+	xchg	dx, ax
+
+ALIGN JUMP_ALIGN
+.AXisLessThanDX:
 	mov		[bp+MENU.wFirstVisibleItem], ax
 	call	MenuText_RefreshAllItems
@@ -127,55 +168,4 @@
 .HighlightNewItemOnCX:
 	jmp		MenuEvent_HighlightItemFromCX
-
-;--------------------------------------------------------------------
-; .GetMaxFirstVisibleItemToAX
-;	Parameters
-;		SS:BP:	Ptr to MENU
-;	Returns:
-;		AX:		Max first visible item
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.GetMaxFirstVisibleItemToAX:
-	push	cx
-
-	call	MenuScrollbars_GetMaxVisibleItemsOnPageToCX
-	mov		ax, [bp+MENUINIT.wItems]
-	sub		ax, cx
-
-	pop		cx
-	ret
-
-;--------------------------------------------------------------------
-; .RotateItemInCX
-;	Parameters
-;		CX:		Possibly under of overflown item to be rotated
-;		SS:BP:	Ptr to MENU
-;	Returns:
-;		CX:		Valid item index
-;	Corrupts registers:
-;		DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.RotateItemInCX:
-	mov		dx, [bp+MENUINIT.wItems]
-	test	cx, cx
-	js		SHORT .RotateNegativeItemInCX
-	cmp		cx, dx
-	jae		SHORT .RotatePositiveItemInCX
-	ret
-
-ALIGN JUMP_ALIGN
-.RotatePositiveItemInCX:
-	sub		cx, dx
-	;jae	SHORT .RotatePositiveItemInCX	; Not needed by scrolling
-	ret
-
-ALIGN JUMP_ALIGN
-.RotateNegativeItemInCX:
-	add		cx, dx
-	;js		SHORT .RotateNegativeItemInCX	; Not needed by scrolling
-	ret
 
 
@@ -216,12 +206,9 @@
 ALIGN JUMP_ALIGN
 MenuScrollbars_GetLastVisibleItemOnPageToAX:
-	push	cx
-
+	xchg	cx, ax
 	call	MenuScrollbars_GetActualVisibleItemsOnPageToCX
 	xchg	ax, cx
 	dec		ax
 	add		ax, [bp+MENU.wFirstVisibleItem]
-
-	pop		cx
 	ret
 
@@ -239,5 +226,9 @@
 MenuScrollbars_GetActualVisibleItemsOnPageToCX:
 	call	MenuScrollbars_GetMaxVisibleItemsOnPageToCX
-	MIN_U	cx, [bp+MENUINIT.wItems]
+	cmp		cx, [bp+MENUINIT.wItems]
+	jb		SHORT .Return
+	mov		cx, [bp+MENUINIT.wItems]
+ALIGN JUMP_ALIGN, ret
+.Return:
 	ret
 
Index: trunk/Assembly_Library/Src/String/Char.asm
===================================================================
--- trunk/Assembly_Library/Src/String/Char.asm	(revision 178)
+++ trunk/Assembly_Library/Src/String/Char.asm	(revision 181)
@@ -161,8 +161,5 @@
 Char_ALtoLowerCaseLetter:
 	call	Char_IsUpperCaseLetterInAL	; Is upper case character?
-	jnc		SHORT .Return				;  If not, return
-	add		al, 'a'-'A'					; Convert to lower case
-.Return:
-	ret
+	jmp		SHORT Char_ALtoUpperCaseLetter.CheckCF
 %endif
 
@@ -179,9 +176,21 @@
 Char_ALtoUpperCaseLetter:
 	call	Char_IsLowerCaseLetterInAL	; Is lower case character?
-	jnc		SHORT .Return				;  If not, return
-	sub		al, 'a'-'A'					; Convert to upper case
+.CheckCF:
+	jnc		SHORT Char_ChangeCaseInAL.Return
+	; Fall to Char_ChangeCaseInAL
+
+;--------------------------------------------------------------------
+; Char_ChangeCaseInAL
+;	Parameters:
+;		AL:		Character to convert (must be A-Z or a-z)
+;	Returns:
+;		AL:		Character converted
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+Char_ChangeCaseInAL:
+	xor		al, 32
 .Return:
 	ret
-
 
 ;--------------------------------------------------------------------
Index: trunk/Assembly_Library/Src/Util/Math.asm
===================================================================
--- trunk/Assembly_Library/Src/Util/Math.asm	(revision 178)
+++ trunk/Assembly_Library/Src/Util/Math.asm	(revision 181)
@@ -17,6 +17,7 @@
 ;		AX
 ;--------------------------------------------------------------------
+%ifndef EXCLUDE_FROM_XTIDECFG	; Not used in XTIDECFG
 ALIGN JUMP_ALIGN
-Math_DivQWatSSBPbyCX:		; This procedure is included but not used in XTIDECFG
+Math_DivQWatSSBPbyCX:
 	xor		dx, dx
 	mov		ax, [bp+6]		; Load highest divident WORD to DX:AX
@@ -36,4 +37,5 @@
 	mov		[bp], ax
 	ret
+%endif
 
 
@@ -49,7 +51,7 @@
 ;		Nothing
 ;--------------------------------------------------------------------
-%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
+%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS OR EXCLUDE_FROM_XTIDECFG
 ALIGN JUMP_ALIGN
-Math_DivDXAXbyCX:			; This procedure is included but not used in XTIDECFG
+Math_DivDXAXbyCX:	; This is currently unused (dead code)
 	xor		bx, bx
 	xchg	bx, ax
