Index: trunk/Assembly_Library/Inc/CgaSnow.inc
===================================================================
--- trunk/Assembly_Library/Inc/CgaSnow.inc	(revision 51)
+++ trunk/Assembly_Library/Inc/CgaSnow.inc	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	AssemblyLibrary
 ; Created date	:	8.10.2010
-; Last update	:	8.10.2010
+; Last update	:	11.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Macros for preventing CGA snow.
@@ -28,6 +28,4 @@
 	%elifidn %1, stosw
 		call	CgaSnow_Stosw
-	%elifidn %1, scasb
-		call	CgaSnow_Scasb
 	%elifidn %1, rep movsb
 		call	CgaSnow_RepMovsb
Index: trunk/Assembly_Library/Inc/Display.inc
===================================================================
--- trunk/Assembly_Library/Inc/Display.inc	(revision 51)
+++ trunk/Assembly_Library/Inc/Display.inc	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	AssemblyLibrary
 ; Created date	:	25.6.2010
-; Last update	:	9.10.2010
+; Last update	:	11.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Defines for display library.
@@ -26,6 +26,6 @@
 	%elifidn %1, PopDisplayContext
 		call	DisplayContext_Pop
-	%elifidn %1, PrepareOffScreenBufferInESBXtoESDI
-		call	DisplayContext_PrepareOffScreenBufferInESBXtoESDI
+	%elifidn %1, PrepareOffScreenBufferInESBXwithLengthInCX
+		call	DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX
 	%else
 		mov		di, DISPLAY_LIB.%1
@@ -39,5 +39,4 @@
 	.PushDisplayContext:
 	.PopDisplayContext:
-	.PrepareOffScreenBufferInESBXtoESDI:
 	.InitializeDisplayContext						resb	2
 
Index: trunk/Assembly_Library/Inc/Menu.inc
===================================================================
--- trunk/Assembly_Library/Inc/Menu.inc	(revision 51)
+++ trunk/Assembly_Library/Inc/Menu.inc	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	13.7.2010
-; Last update	:	5.10.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Defines for Menu library.
@@ -95,4 +95,5 @@
 	.wTimeoutTicks					resb	2	; Selection timeout in system timer ticks
 	.wItems							resb	2	; Number of items in menu
+	.wHighlightedItem				resb	2	; Index for highlighted item
 
 	.wTitleAndInfoLines:
@@ -115,6 +116,4 @@
 									resb	1
 	.wTimeoutCounter				resb	2
-
-	.wHighlightedItem				resb	2	; Index for highlighted item
 	.wFirstVisibleItem				resb	2	; Index for first visible item on the menu
 endstruc
Index: trunk/Assembly_Library/Src/AssemblyLibrary.asm
===================================================================
--- trunk/Assembly_Library/Src/AssemblyLibrary.asm	(revision 51)
+++ trunk/Assembly_Library/Src/AssemblyLibrary.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	15.9.2010
-; Last update	:	8.10.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Assembly Library main file. This is the only file that
@@ -33,4 +33,5 @@
 
 %ifdef INCLUDE_MENU_LIBRARY
+	%include "CharOutLineSplitter.asm"
 	%include "Menu.asm"
 	%include "MenuAttributes.asm"
@@ -53,5 +54,5 @@
 		%include "DialogString.asm"
 		%include "DialogWord.asm"
-		%include "LineSplitter.asm"
+		%include "ItemLineSplitter.asm"
 		%include "StringsForDialogs.asm"
 	%endif
@@ -61,4 +62,5 @@
 	%include "Char.asm"
 	%include "String.asm"
+	%include "StringProcess.asm"
 %endif
 
Index: trunk/Assembly_Library/Src/Display/CgaSnow.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/CgaSnow.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Display/CgaSnow.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	8.10.2010
-; Last update	:	9.10.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for preventing CGA snow.
@@ -23,7 +23,8 @@
 	cmp		WORD [BDA.wVidPort], CGA_STATUS_REGISTER - OFFSET_TO_CGA_STATUS_REGISTER
 	jne		SHORT .CgaNotFound
-	call	DisplayPage_GetColumnsToALandRowsToAH
-	cmp		ah, [BDA.bVidRows]		; Video rows stored only by EGA and later
-	je		SHORT .CgaNotFound		; Must be EGA or later
+
+	; All standard CGA modes use 25 rows but only EGA and later store it to BDA.
+	cmp		BYTE [BDA.bVidRows], 25
+	jge		SHORT .CgaNotFound
 	stc
 	ret
@@ -83,30 +84,4 @@
 
 ;--------------------------------------------------------------------
-; CgaSnow_Scasb
-;	Parameters:
-;		AL:		Byte for comparison
-;		DS:		BDA segment (zero)
-;		ES:DI:	Ptr to video memory where to output
-;	Returns:
-;		DI:		Incremented for next character
-;	Corrupts registers:
-;		AX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-CgaSnow_Scasb:
-	call	LoadCgaStatusRegisterAddressToDXifCgaPresent
-	jz		SHORT .ScasbWithoutWaitSinceUnknownPort
-
-	mov		ah, al
-	cli				; Interrupt request would mess up timing
-	WAIT_UNTIL_SAFE_CGA_WRITE
-	mov		al, ah
-.ScasbWithoutWaitSinceUnknownPort:
-	scasb
-	sti
-	ret
-
-
-;--------------------------------------------------------------------
 ; CgaSnow_RepMovsb
 ;	Parameters:
Index: trunk/Assembly_Library/Src/Display/DisplayContext.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayContext.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Display/DisplayContext.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	25.6.2010
-; Last update	:	9.10.2010
+; Last update	:	11.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for managing display context.
@@ -119,14 +119,15 @@
 
 ;--------------------------------------------------------------------
-; DisplayContext_PrepareOffScreenBufferInESBXtoESDI
-;	Parameters:
-;		BX:AX:	Ptr to off screen buffer
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-DisplayContext_PrepareOffScreenBufferInESBXtoESDI:
+; DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX
+;	Parameters:
+;		CX:		Off screen buffer length in characters
+;		ES:BX:	Ptr to off screen buffer
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX:
 	push	ds
 
@@ -139,4 +140,5 @@
 	mov		ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
 	call	DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
+	mov		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], cx
 
 	mov		bx, di
Index: trunk/Assembly_Library/Src/Display/DisplayPrint.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayPrint.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Display/DisplayPrint.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	26.6.2010
-; Last update	:	27.9.2010
+; Last update	:	11.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for display output.
@@ -326,9 +326,8 @@
 ALIGN JUMP_ALIGN
 DisplayPrint_Newline:
+	mov		al, LF
+	call	DisplayPrint_CharacterFromAL
 	mov		al, CR
-	call	DisplayPrint_CharacterFromAL
-	mov		al, LF
 	; Fall to DisplayPrint_CharacterFromAL
-
 
 ;--------------------------------------------------------------------
Index: trunk/Assembly_Library/Src/Keyboard/Keyboard.asm
===================================================================
--- trunk/Assembly_Library/Src/Keyboard/Keyboard.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Keyboard/Keyboard.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	5.7.2010
-; Last update	:	7.10.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for managing keyboard.
@@ -26,25 +26,24 @@
 ALIGN JUMP_ALIGN
 Keyboard_ReadUserInputtedWordWhilePrinting:
-	push	es
-	push	di
+	push	ds
+	push	si
 	push	cx
 
-	eENTER_STRUCT BUFFER_SIZE_FOR_WORD_INPUT
-	call	Memory_CopySSBPtoESDI
-
 	mov		cx, BUFFER_SIZE_FOR_WORD_INPUT
+	call	Memory_ReserveCXbytesFromStackToDSSI
+
 	call	Char_GetFilterFunctionToDXforNumericBaseInBX
+	call	Memory_ExchangeDSSIwithESDI
 	call	Keyboard_ReadUserInputtedStringToESDIWhilePrinting
-	jz		SHORT .Return
-
-	call	Memory_ExchangeDSSIwithESDI
+	call	Memory_ExchangeDSSIwithESDI	; Does not modify FLAGS
+	jz		SHORT .CancelledByUser
+
 	call	String_ConvertWordToAXfromStringInDSSIwithBaseInBX
-	call	Memory_ExchangeDSSIwithESDI
-.Return:
-	eLEAVE_STRUCT BUFFER_SIZE_FOR_WORD_INPUT
+.CancelledByUser:
+	add		sp, BYTE BUFFER_SIZE_FOR_WORD_INPUT
 	test	cx, cx					; Set ZF if string length is zero
 	pop		cx
-	pop		di
-	pop		es
+	pop		si
+	pop		ds
 	ret
 
Index: trunk/Assembly_Library/Src/LibraryTests.asm
===================================================================
--- trunk/Assembly_Library/Src/LibraryTests.asm	(revision 51)
+++ trunk/Assembly_Library/Src/LibraryTests.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	27.6.2010
-; Last update	:	27.9.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Tests for Assembly Library.
@@ -71,6 +71,5 @@
 	mov		BYTE [si+MENUINIT.bTitleLines], TEST_MENU_TITLE_LINES
 	mov		BYTE [si+MENUINIT.bInfoLines], TEST_MENU_INFO_LINES
-	mov		ax, 1
-	CALL_MENU_LIBRARY HighlightItemFromAX
+	mov		WORD [si+MENUINIT.wHighlightedItem], 1
 	stc
 	ret
@@ -95,5 +94,5 @@
 	ret
 .szInfoTitle:
-	db		"Information line 1,",CR,LF,
+	db		"Information line 1,",LF,CR,
 	db		"Information line 2. ",
 	db		"This comes (12) right after Information line 2.",NULL
@@ -615,11 +614,11 @@
 	db		"so scroll bars and message dialog can be tested. This string does not use "
 	db		"formatting so it should be simple to display this correctly. This string "
-	db		"does, however, use newline characters. Lets change line right now!",CR,LF,
+	db		"does, however, use newline characters. Lets change line right now!",LF,CR,
 	db		"Well did it work? Let's try line feed alone",LF,"Well? "
+	db		"Now two LFs:",LF,LF,"What happened? "
 	db		"We could also see what two spaces does _  _. There was two spaces between "
 	db		"underscores. Lets try three this time _   _. Well, did they work correctly? "
-	db		"What next, I guess that was all, no wait. Let's see what TAB does! Here it "
-	db		"goes:",TAB,"Well did it work? Just one more time:",TAB,"Well are we good? "
-	db		"No since LF is the only supported control character, unfortunately. "
+	db		"Too bad that LF, CR and BS (backspace) are the only supported control "
+	db		"characters. Others don't either work or they break line splitting. "
 	db		"This is the last sentence of this long string!",NULL
 
Index: trunk/Assembly_Library/Src/Menu/CharOutLineSplitter.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/CharOutLineSplitter.asm	(revision 52)
+++ trunk/Assembly_Library/Src/Menu/CharOutLineSplitter.asm	(revision 52)
@@ -0,0 +1,180 @@
+; File name		:	CharOutLineSplitter.asm
+; Project name	:	Assembly Library
+; Created date	:	11.10.2010
+; Last update	:	12.10.2010
+; Author		:	Tomi Tilli
+; Description	:	Functions for splitting menu lines during character output.
+
+; Section containing code
+SECTION .text
+
+;--------------------------------------------------------------------
+; CharOutLineSplitter_PrepareForPrintingTextLines
+;	Parameters:
+;		SS:BP:	Ptr to MENU
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, DX, DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+CharOutLineSplitter_PrepareForPrintingTextLines:
+	call	.GetLastTextLineColumnOffsetToDX
+	call	CharOutLineSplitter_GetFirstTextLineColumnOffsetToAX
+	mov		ah, dl			; AL = Text line first column, AH = Text line last column
+	CALL_DISPLAY_LIBRARY SetCharacterOutputParameterFromAX
+	ret
+
+;--------------------------------------------------------------------
+; .GetLastTextLineColumnOffsetToDX
+;	Parameters:
+;		SS:BP:	Ptr to MENU
+;	Returns:
+;		DX:		Offset to last (allowed) character in text line
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.GetLastTextLineColumnOffsetToDX:
+	call	CharOutLineSplitter_GetFirstTextLineColumnOffsetToAX
+	xchg	dx, ax
+	call	MenuLocation_GetMaxTextLineLengthToAX
+	shl		ax, 1
+	add		dx, ax
+	ret
+
+
+;--------------------------------------------------------------------
+; CharOutLineSplitter_GetFirstTextLineColumnOffsetToAX
+; CharOutLineSplitter_GetFirstBorderLineColumnOffsetToAX
+;	Parameters:
+;		SS:BP:	Ptr to MENU
+;	Returns:
+;		AX:		Offset to end of text line (first border area character)
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+CharOutLineSplitter_GetFirstTextLineColumnOffsetToAX:
+	call	CharOutLineSplitter_GetFirstBorderLineColumnOffsetToAX
+	add		al, MENU_TEXT_COLUMN_OFFSET<<1
+	ret
+
+ALIGN JUMP_ALIGN
+CharOutLineSplitter_GetFirstBorderLineColumnOffsetToAX:
+	call	MenuLocation_GetTitleBordersTopLeftCoordinatesToAX
+	xor		ah, ah
+	shl		ax, 1
+	ret
+
+
+;--------------------------------------------------------------------
+; CharOutLineSplitter_IsCursorAtTheEndOfTextLine
+;	Parameters:
+;		DS:		BDA segment (zero)
+;		ES:DI:	Ptr to cursor location in video memory
+;	Returns:
+;		CF:		Set if end of text line
+;				Clear if more characters fit on current text line
+;	Corrupts registers:
+;		DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+CharOutLineSplitter_IsCursorAtTheEndOfTextLine:
+	push	ax
+
+	mov		dl, [VIDEO_BDA.wColumns]
+	shl		dl, 1			; DX = bytes per row
+	mov		ax, di
+	div		dl				; AL = row index, AH = column index
+	cmp		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam+1], ah
+
+	pop		ax
+	ret
+
+
+;--------------------------------------------------------------------
+; CharOutLineSplitter_MovePartialWordToNewTextLine
+;	Parameters:
+;		AL:		Character to output
+;		AH:		Attribute to output
+;		DS:		BDA segment (zero)
+;		ES:DI:	Ptr to end of text line in video memory
+;	Returns:
+;		DI:		Updated to next character for new text line
+;	Corrupts registers:
+;		AX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+CharOutLineSplitter_MovePartialWordToNewTextLine:
+	push	si
+	push	cx
+	push	ax
+
+	call	GetOffsetToPartialWordToSIandSizeToCX
+	call	MenuCharOut_PrintLFCRandAdjustOffsetForStartOfLine
+	jcxz	.NothingToMove
+	call	MovePartialWordFromPreviousLineInESSItoNewLineInESDIwithSizeInCX
+.NothingToMove:
+	pop		ax
+	pop		cx
+	pop		si
+	ret
+
+
+;--------------------------------------------------------------------
+; GetOffsetToPartialWordToSIandSizeToCX
+;	Parameters:
+;		ES:DI:	Ptr to space before border character
+;	Returns:
+;		CX:		Number of bytes that needs to be moved
+;		ES:SI:	Ptr to beginning of partial word that needs to be moved to new line
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+GetOffsetToPartialWordToSIandSizeToCX:
+	xor		cx, cx
+	mov		si, di
+ALIGN JUMP_ALIGN
+.ScanNextCharacter:		; Space will always be found since one comes after border
+	dec		si
+	dec		si
+	cmp		BYTE [es:si], ' '
+	je		SHORT .PartialWordFound
+	inc		cx
+	jmp		SHORT .ScanNextCharacter
+ALIGN JUMP_ALIGN
+.PartialWordFound:
+	inc		si
+	inc		si			; SI now points one past space
+	shl		cx, 1		; Characters to bytes
+	ret
+
+
+;--------------------------------------------------------------------
+; MovePartialWordFromPreviousLineInESSItoNewLineInESDIwithSizeInCX
+;	Parameters:
+;		CX:		Number of BYTEs in partial word
+;		DS:		BDA segment (zero)
+;		ES:SI:	Ptr to partial word on previous line
+;		ES:DI:	Ptr to new empty line
+;	Returns:
+;		ES:DI:	Ptr where to store next character
+;	Corrupts registers:
+;		AX, CX, DX, SI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+MovePartialWordFromPreviousLineInESSItoNewLineInESDIwithSizeInCX:
+	push	si
+	push	cx
+	WAIT_RETRACE_IF_NECESSARY_THEN rep movsb
+	pop		cx
+	pop		si
+
+	xchg	di, si
+	shr		cx, 1		; Bytes to characters
+	mov		al, ' '
+	call	DisplayPrint_RepeatCharacterFromALwithCountInCX
+	mov		di, si
+	ret
Index: trunk/Assembly_Library/Src/Menu/Dialog/Dialog.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/Dialog.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/Dialog/Dialog.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	6.8.2010
-; Last update	:	9.10.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Common functions for many dialogs.
@@ -38,5 +38,5 @@
 	call	Keyboard_RemoveAllKeystrokesFromBuffer
 
-	mov		ax, [bp+MENU.wHighlightedItem]
+	mov		ax, [bp+MENUINIT.wHighlightedItem]
 	eLEAVE_STRUCT DIALOG_size
 	pop		ds
@@ -78,6 +78,7 @@
 
 ;--------------------------------------------------------------------
-; Dialog_EventInitializeMenuinitFromDSSIforSingleItem
-;	Parameters:
+; Dialog_EventInitializeMenuinitFromDSSIforSingleItemWithHighlightedItemInAX
+;	Parameters:
+;		AX:			Index of highlighted item
 ;		DS:SI:		Ptr to MENUINIT struct to initialize
 ;		SS:BP:		Ptr to DIALOG
@@ -87,13 +88,14 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-Dialog_EventInitializeMenuinitFromDSSIforSingleItem:
+Dialog_EventInitializeMenuinitFromDSSIforSingleItemWithHighlightedItemInAX:
 	les		di, [bp+DIALOG.fpDialogIO]
 	mov		WORD [es:di+DIALOG_INPUT.fszItems], g_szSingleItem
 	mov		[es:di+DIALOG_INPUT.fszItems+2], cs
-	; Fall to Dialog_EventInitializeMenuinitFromDSSI
-
-;--------------------------------------------------------------------
-; Dialog_EventInitializeMenuinitFromDSSI
-;	Parameters:
+	; Fall to Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX
+
+;--------------------------------------------------------------------
+; Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX
+;	Parameters:
+;		AX:			Index of highlighted item
 ;		DS:SI:		Ptr to MENUINIT struct to initialize
 ;		SS:BP:		Ptr to DIALOG
@@ -103,23 +105,20 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-Dialog_EventInitializeMenuinitFromDSSI:
+Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX:
+	mov		[bp+MENUINIT.wHighlightedItem], ax
 	les		di, [bp+DIALOG.fpDialogIO]
 	call	.GetWidthBasedOnParentMenuToAL
 	mov		[bp+MENUINIT.bWidth], al
 
-	call	MenuLocation_GetMaxTextLineLengthToAX
-	mov		bx, ax
 	lds		si, [es:di+DIALOG_INPUT.fszTitle]
-	call	LineSplitter_SplitStringFromDSSIwithMaxLineLengthInAXandGetLineCountToAX
+	call	ItemLineSplitter_GetLinesToAXforStringInDSSI
 	mov		[bp+MENUINIT.bTitleLines], al
 
-	mov		ax, bx
 	lds		si, [es:di+DIALOG_INPUT.fszItems]
-	call	LineSplitter_SplitStringFromDSSIwithMaxLineLengthInAXandGetLineCountToAX
+	call	ItemLineSplitter_GetLinesToAXforStringInDSSI
 	mov		[bp+MENUINIT.wItems], ax
 
-	xchg	ax, bx
 	lds		si, [es:di+DIALOG_INPUT.fszInfo]
-	call	LineSplitter_SplitStringFromDSSIwithMaxLineLengthInAXandGetLineCountToAX
+	call	ItemLineSplitter_GetLinesToAXforStringInDSSI
 	mov		[bp+MENUINIT.bInfoLines], al
 
@@ -178,29 +177,18 @@
 ALIGN JUMP_ALIGN
 Dialog_EventRefreshTitle:
-	mov		dl, [bp+MENUINIT.bTitleLines]
 	lds		si, [bp+DIALOG.fpDialogIO]
-	les		di, [si+DIALOG_INPUT.fszTitle]
-	jmp		SHORT PrintDLlinesFromESDI
+	lds		si, [si+DIALOG_INPUT.fszTitle]
+	jmp		SHORT PrintTitleOrInfoLine
 
 ALIGN JUMP_ALIGN
 Dialog_EventRefreshInformation:
-	mov		dl, [bp+MENUINIT.bInfoLines]
 	lds		si, [bp+DIALOG.fpDialogIO]
-	les		di, [si+DIALOG_INPUT.fszInfo]
-	; Fall to PrintDLlinesFromESDI
-
-ALIGN JUMP_ALIGN
-PrintDLlinesFromESDI:
-	xor		cx, cx				; Start from line zero
-	mov		dh, cl				; Line count now in DX
-ALIGN JUMP_ALIGN
-.PrintNextLine:
-	call	LineSplitter_PrintLineInCXfromStringInESDI
-	push	di
-	CALL_DISPLAY_LIBRARY PrintNewlineCharacters
-	pop		di
-	inc		cx
-	dec		dx
-	jnz		SHORT .PrintNextLine
+	lds		si, [si+DIALOG_INPUT.fszInfo]
+	; Fall to PrintTitleOrInfoLine
+
+ALIGN JUMP_ALIGN
+PrintTitleOrInfoLine:
+	mov		bx, ds
+	CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromBXSI
 	stc
 	ret
@@ -218,6 +206,11 @@
 Dialog_EventRefreshItemFromCX:
 	lds		si, [bp+DIALOG.fpDialogIO]
-	les		di, [si+DIALOG_INPUT.fszItems]
-	call	LineSplitter_PrintLineInCXfromStringInESDI
+	lds		si, [si+DIALOG_INPUT.fszItems]
+	call	ItemLineSplitter_GetLineToDSSIandLengthToCXfromStringInDSSIwithIndexInCX
+	jnc		SHORT .LineNotFound
+
+	mov		bx, ds
+	CALL_DISPLAY_LIBRARY PrintCharBufferFromBXSIwithLengthInCX
+.LineNotFound:
 	stc
 	ret
Index: trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	6.9.2010
-; Last update	:	10.10.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Displays file dialog.
@@ -49,7 +49,6 @@
 .ItemSelectedFromCX:
 	call	LoadItemStringBufferToESDI
-	call	LineSplitter_GetOffsetToSIforLineCXfromStringInESDI
-	push	es
-	pop		ds
+	call	Memory_CopyESDItoDSSI
+	call	ItemLineSplitter_GetLineToDSSIandLengthToCXfromStringInDSSIwithIndexInCX
 	jmp		ParseSelectionFromItemLineInDSSI
 
@@ -115,12 +114,11 @@
 	call	SortDirectoryContentsStringFromESDIwithCountInCX
 	call	Memory_CopySSBPtoDSSI
-	call	Dialog_EventInitializeMenuinitFromDSSI
+	xor		ax, ax
+	call	Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX
 	call	GetInfoLinesToCXandDialogFlagsToAX
 	mov		[bp+MENUINIT.bInfoLines], cl
 	CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH
 	mov		[bp+MENUINIT.bHeight], ah				; Always max height
-	xor		ax, ax
-	mov		[bp+MENU.wHighlightedItem], ax
-	mov		[bp+MENU.wFirstVisibleItem], ax
+	mov		WORD [bp+MENU.wFirstVisibleItem], 0
 	ret
 
@@ -256,5 +254,6 @@
 	mov		bx, di
 	CALL_DISPLAY_LIBRARY PushDisplayContext
-	CALL_DISPLAY_LIBRARY PrepareOffScreenBufferInESBXtoESDI
+	mov		cx, -1
+	CALL_DISPLAY_LIBRARY PrepareOffScreenBufferInESBXwithLengthInCX
 
 	call	.FormatFileOrDirectoryToBufferFromDTAinDSSI
@@ -299,8 +298,11 @@
 ;--------------------------------------------------------------------
 .FormatFile:
+	; Convert file name to lower case
+	xchg	si, ax
+	mov		dx, StringProcess_ConvertToLowerCase
+	call	StringProcess_DSSIwithFunctionInDX
+	xchg	ax, si
+
 	; Push parameters for file name
-	xchg	si, ax
-	call	String_ConvertDSSItoLowerCase
-	xchg	ax, si
 	push	ax				; Push directory name offset
 	push	ds				; Push directory name segment
Index: trunk/Assembly_Library/Src/Menu/Dialog/DialogMessage.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/DialogMessage.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/Dialog/DialogMessage.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	6.8.2010
-; Last update	:	6.9.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Displays message dialog.
@@ -44,6 +44,6 @@
 .InitializeMenuinitFromDSSI:
 	or		BYTE [bp+MENU.bFlags], FLG_MENU_USER_HANDLES_SCROLLING | FLG_MENU_NOHIGHLIGHT
-	mov		WORD [bp+MENU.wHighlightedItem], 0
-	jmp		Dialog_EventInitializeMenuinitFromDSSI
+	xor		ax, ax		; Cannot be NO_ITEM_HIGHLIGHTED because of scrolling
+	jmp		Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX
 
 
@@ -91,9 +91,9 @@
 ALIGN JUMP_ALIGN
 .DecrementLines:
-	cmp		WORD [bp+MENU.wHighlightedItem], BYTE 0
+	cmp		WORD [bp+MENUINIT.wHighlightedItem], BYTE 0
 	je		SHORT .AlreadyAtTheTopOrBottom
 
 	mov		ax, [bp+MENU.wFirstVisibleItem]
-	mov		[bp+MENU.wHighlightedItem], ax
+	mov		[bp+MENUINIT.wHighlightedItem], ax
 	mov		ah, MENU_KEY_UP
 	jmp		MenuLoop_ProcessScrollingKeysFromAX
@@ -103,9 +103,9 @@
 	mov		ax, [bp+MENUINIT.wItems]
 	dec		ax						; Last possible item to highlight
-	cmp		[bp+MENU.wHighlightedItem], ax
+	cmp		[bp+MENUINIT.wHighlightedItem], ax
 	jae		SHORT .AlreadyAtTheTopOrBottom
 
 	call	MenuScrollbars_GetLastVisibleItemOnPageToAX
-	mov		[bp+MENU.wHighlightedItem], ax
+	mov		[bp+MENUINIT.wHighlightedItem], ax
 	mov		ah, MENU_KEY_DOWN
 	jmp		MenuLoop_ProcessScrollingKeysFromAX
Index: trunk/Assembly_Library/Src/Menu/Dialog/DialogProgress.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/DialogProgress.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/Dialog/DialogProgress.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	15.8.2010
-; Last update	:	28.9.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Displays progress bar dialog and starts progress task.
@@ -78,5 +78,6 @@
 ALIGN JUMP_ALIGN
 .InitializeMenuinitFromDSSI:
-	call	Dialog_EventInitializeMenuinitFromDSSIforSingleItem
+	mov		ax, NO_ITEM_HIGHLIGHTED
+	call	Dialog_EventInitializeMenuinitFromDSSIforSingleItemWithHighlightedItemInAX
 	lds		si, [bp+DIALOG.fpDialogIO]
 	call	TimerTicks_ReadFromBdaToAX
Index: trunk/Assembly_Library/Src/Menu/Dialog/DialogSelection.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/DialogSelection.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/Dialog/DialogSelection.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	13.8.2010
-; Last update	:	13.8.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Displays selection dialog.
@@ -43,6 +43,6 @@
 ALIGN JUMP_ALIGN
 .InitializeMenuinitFromDSSI:
-	mov		WORD [bp+MENU.wHighlightedItem], 0
-	jmp		Dialog_EventInitializeMenuinitFromDSSI
+	xor		ax, ax
+	jmp		Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX
 
 
Index: trunk/Assembly_Library/Src/Menu/Dialog/DialogString.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/DialogString.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/Dialog/DialogString.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	12.8.2010
-; Last update	:	7.9.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Displays word input dialog.
@@ -43,7 +43,13 @@
 
 ALIGN JUMP_ALIGN
+.InitializeMenuinitFromDSSI:
+	xor		ax, ax
+	jmp		Dialog_EventInitializeMenuinitFromDSSIforSingleItemWithHighlightedItemInAX
+
+
+ALIGN JUMP_ALIGN
 .IdleProcessing:
-	xor		ax, ax						; Item 0 is used as input line
-	call	MenuText_AdjustDisplayContextForDrawingItemFromAX
+	xor		cx, cx						; Item 0 is used as input line
+	call	MenuText_AdjustDisplayContextForDrawingItemFromCX
 	call	GetStringFromUser
 	call	MenuInit_CloseMenuWindow
@@ -55,5 +61,5 @@
 .rgfnEventHandlers:
 istruc MENUEVENT
-	at	MENUEVENT.InitializeMenuinitFromDSSI,	dw	Dialog_EventInitializeMenuinitFromDSSIforSingleItem
+	at	MENUEVENT.InitializeMenuinitFromDSSI,	dw	.InitializeMenuinitFromDSSI
 	at	MENUEVENT.ExitMenu,						dw	Dialog_EventNotHandled
 	at	MENUEVENT.IdleProcessing,				dw	.IdleProcessing
Index: trunk/Assembly_Library/Src/Menu/Dialog/DialogWord.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/DialogWord.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/Dialog/DialogWord.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	10.8.2010
-; Last update	:	7.9.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Displays word input dialog.
@@ -43,7 +43,13 @@
 
 ALIGN JUMP_ALIGN
+.InitializeMenuinitFromDSSI:
+	xor		ax, ax
+	jmp		Dialog_EventInitializeMenuinitFromDSSIforSingleItemWithHighlightedItemInAX
+
+
+ALIGN JUMP_ALIGN
 .IdleProcessing:
-	xor		ax, ax						; Item 0 is used as input line
-	call	MenuText_AdjustDisplayContextForDrawingItemFromAX
+	xor		cx, cx						; Item 0 is used as input line
+	call	MenuText_AdjustDisplayContextForDrawingItemFromCX
 	call	GetWordFromUser
 	call	MenuInit_CloseMenuWindow
@@ -55,5 +61,5 @@
 .rgfnEventHandlers:
 istruc MENUEVENT
-	at	MENUEVENT.InitializeMenuinitFromDSSI,	dw	Dialog_EventInitializeMenuinitFromDSSIforSingleItem
+	at	MENUEVENT.InitializeMenuinitFromDSSI,	dw	.InitializeMenuinitFromDSSI
 	at	MENUEVENT.ExitMenu,						dw	Dialog_EventNotHandled
 	at	MENUEVENT.IdleProcessing,				dw	.IdleProcessing
Index: trunk/Assembly_Library/Src/Menu/Dialog/ItemLineSplitter.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/ItemLineSplitter.asm	(revision 52)
+++ trunk/Assembly_Library/Src/Menu/Dialog/ItemLineSplitter.asm	(revision 52)
@@ -0,0 +1,149 @@
+; File name		:	ItemLineSplitter.asm
+; Project name	:	Assembly Library
+; Created date	:	12.10.2010
+; Last update	:	12.10.2010
+; Author		:	Tomi Tilli
+; Description	:	Functions for splitting strings to item lines.
+
+struc ITEM_LINE_SPLITTER
+	.wMaxTextLineLength	resb	2
+	.wLineToFind		resb	2
+	.wStartOfLine		resb	2
+endstruc
+
+; Section containing code
+SECTION .text
+
+;--------------------------------------------------------------------
+; ItemLineSplitter_GetLinesToAXforStringInDSSI
+;	Parameters:
+;		DS:SI:	Ptr to string
+;		SS:BP:	Ptr to MENU
+;	Returns:
+;		AX:		Number of lines on string
+;	Corrupts registers:
+;		BX, CX, DX, SI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+ItemLineSplitter_GetLinesToAXforStringInDSSI:
+	push	di
+
+	call	MenuLocation_GetMaxTextLineLengthToAX
+	eENTER_STRUCT	ITEM_LINE_SPLITTER_size
+	mov		[bp+ITEM_LINE_SPLITTER.wMaxTextLineLength], ax
+	mov		WORD [bp+ITEM_LINE_SPLITTER.wLineToFind], -1
+
+	xor		bx, bx		; Line index
+	mov		di, si		; Start of first word
+	mov		dx, ProcessCharacterFromStringToSplit
+	call	StringProcess_DSSIwithFunctionInDX
+
+	lea		ax, [bx+1]
+	eLEAVE_STRUCT	ITEM_LINE_SPLITTER_size
+	pop		di
+	ret
+
+
+;--------------------------------------------------------------------
+; ItemLineSplitter_GetLineToDSSIandLengthToCXfromStringInDSSIwithIndexInCX
+;	Parameters:
+;		CX:		Index of line to search for
+;		DS:SI:	Ptr to string
+;		SS:BP:	Ptr to MENU
+;	Returns:
+;		CX:		Line length
+;		DS:SI:	Ptr to beginning of line
+;		CF:		Set if wanted line was found
+;	Corrupts registers:
+;		AX, BX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+ItemLineSplitter_GetLineToDSSIandLengthToCXfromStringInDSSIwithIndexInCX:
+	push	di
+
+	call	MenuLocation_GetMaxTextLineLengthToAX
+	eENTER_STRUCT	ITEM_LINE_SPLITTER_size
+	mov		[bp+ITEM_LINE_SPLITTER.wMaxTextLineLength], ax
+	mov		[bp+ITEM_LINE_SPLITTER.wLineToFind], cx
+	mov		[bp+ITEM_LINE_SPLITTER.wStartOfLine], si
+
+	xor		bx, bx		; Line index
+	mov		di, si		; Start of first word
+	mov		dx, ProcessCharacterFromStringToSplit
+	call	StringProcess_DSSIwithFunctionInDX
+
+	mov		si, [bp+ITEM_LINE_SPLITTER.wStartOfLine]
+	jc		SHORT .ReturnLineInDSSIandLengthInCX
+	call	String_GetLengthFromDSSItoCX	; Last or invalid line. Just return last line.
+
+ALIGN JUMP_ALIGN
+.ReturnLineInDSSIandLengthInCX:
+	eLEAVE_STRUCT	ITEM_LINE_SPLITTER_size
+	pop		di
+	stc
+	ret
+
+
+;--------------------------------------------------------------------
+; Character processing callback function prototype for StringProcess_DSSIwithFunctionInBX.
+; ProcessCharacterFromStringToSplit
+;	Parameters:
+;		AL:			Character to process
+;		BX:			Line index
+;		CX:			Number of characters processed (Characters on line so far)
+;		DS:SI:		Ptr to next character
+;		DS:DI:		Start of current word
+;		SS:BP:		Ptr to ITEM_LINE_SPLITTER
+;	Returns:
+;		CF:			Clear to continue with next character
+;					Set to stop processing
+;		BX:			Line index
+;		CX:			Characters on line so far
+;		DS:DI:		Start of current word
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+ProcessCharacterFromStringToSplit:
+	cmp		al, ' '
+	ja		SHORT .CheckLineLength
+	mov		di, si				; DS:DI now points start of new word
+	je		SHORT .CheckLineLength
+
+	cmp		al, LF
+	je		SHORT .ChangeToNextLine
+	cmp		al, CR
+	jne		SHORT .IgnoreUnsupportedControlCharacter
+	xor		cx, cx				; Carriage return so reset line length so far
+
+ALIGN JUMP_ALIGN
+.CheckLineLength:
+	cmp		cx, [bp+ITEM_LINE_SPLITTER.wMaxTextLineLength]
+	ja		SHORT .ChangeToNextLine
+	clc
+	ret
+
+ALIGN JUMP_ALIGN
+.ChangeToNextLine:
+	cmp		bx, [bp+ITEM_LINE_SPLITTER.wLineToFind]
+	je		SHORT .WantedLineFound
+
+	inc		bx					; Increment line
+	xor		cx, cx				; Zero character counter
+	mov		si, di				; Start from complete word
+	mov		[bp+ITEM_LINE_SPLITTER.wStartOfLine], di
+	clc
+	ret
+
+ALIGN JUMP_ALIGN
+.IgnoreUnsupportedControlCharacter:
+	dec		cx
+	clc
+	ret
+
+ALIGN JUMP_ALIGN
+.WantedLineFound:
+	lea		cx, [di-1]
+	sub		cx, [bp+ITEM_LINE_SPLITTER.wStartOfLine]
+	stc
+	ret
Index: trunk/Assembly_Library/Src/Menu/Dialog/LineSplitter.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/LineSplitter.asm	(revision 51)
+++ 	(revision )
@@ -1,225 +1,0 @@
-; File name		:	Line Splitter.asm
-; Project name	:	Assembly Library
-; Created date	:	8.8.2010
-; Last update	:	1.10.2010
-; Author		:	Tomi Tilli
-; Description	:	Splits long strings to multiple lines.
-
-struc LINE_SPLITTER
-	.pLastWord			resb	2
-	.wMaxLineLength		resb	2
-	.wLines				resb	2
-endstruc
-
-
-; Section containing code
-SECTION .text
-
-;--------------------------------------------------------------------
-; LineSplitter_SplitStringFromDSSIwithMaxLineLengthInAXandGetLineCountToAX
-;	Parameters:
-;		AX:		Maximum allowed length for a line
-;		DS:SI:	Ptr to string to split
-;	Returns:
-;		AX:		Number of lines
-;	Corrupts registers:
-;		CX, SI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-LineSplitter_SplitStringFromDSSIwithMaxLineLengthInAXandGetLineCountToAX:
-	xor		cx, cx
-	cmp		[si], cl						; String length zero?
-	jne		SHORT .PrepareToSplit
-	xchg	ax, cx
-	ret
-
-ALIGN JUMP_ALIGN
-.PrepareToSplit:
-	eENTER_STRUCT LINE_SPLITTER_size		; SS:BP now points to LINE_SPLITTER
-
-	mov		[bp+LINE_SPLITTER.wLines], cx
-	call	Memory_SetZFifNullPointerInDSSI
-	jz		SHORT .ReturnNumberOfLinesInAX
-	call	SplitStringFromDSSIusingLineSplitterInSSBP
-
-.ReturnNumberOfLinesInAX:
-	mov		ax, [bp+LINE_SPLITTER.wLines]
-	eLEAVE_STRUCT LINE_SPLITTER_size
-	ret
-
-;--------------------------------------------------------------------
-; SplitStringFromDSSIusingLineSplitterInSSBP
-;	Parameters:
-;		AX:		Maximum allowed length for a line
-;		DS:SI:	Ptr to string to split
-;		SS:BP:	Ptr to LINE_SPLITTER
-;	Returns:
-;		SS:BP:	Ptr to LINE_SPLITTER with number of lines
-;	Corrupts registers:
-;		AX, CX, SI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-SplitStringFromDSSIusingLineSplitterInSSBP:
-	mov		[bp+LINE_SPLITTER.pLastWord], si
-	mov		[bp+LINE_SPLITTER.wMaxLineLength], ax
-	inc		WORD [bp+LINE_SPLITTER.wLines]		; Always at least one line
-	xor		cx, cx								; Length of current line
-	cld
-ALIGN JUMP_ALIGN
-.ScanNextCharacter:
-	lodsb					; Load from [DS:SI] to AL, increment SI
-	cmp		al, ' '			; Control character or space?
-	je		SHORT .ProcessSpace
-	jb		SHORT .ProcessControlCharacter
-.IncrementCharacterCount:
-	inc		cx				; Increment character count
-	cmp		cx, [bp+LINE_SPLITTER.wMaxLineLength]
-	jbe		SHORT .ScanNextCharacter
-
-	mov		si, [bp+LINE_SPLITTER.pLastWord]	; Resume to beginning of last word
-	mov		BYTE [si-1], STX					; STX marks start or new line
-	; Fall to .StartNewLine
-
-;--------------------------------------------------------------------
-; .StartNewLine
-;	Parameters:
-;		CX:		Line length so far
-;		DS:SI:	Ptr character that begins new line
-;		SS:BP:	Ptr to LINE_SPLITTER
-;	Returns:
-;		CX:		Zero
-;		SS:BP:	LINE_SPLITTER updated for number of lines
-;		Jumps to .ScanNextCharacter
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-.StartNewLine:
-	inc		WORD [bp+LINE_SPLITTER.wLines]		; Increment number of lines
-	xor		cx, cx								; Zero line length
-	jmp		SHORT .ScanNextCharacter
-
-;--------------------------------------------------------------------
-; .ProcessSpace
-;	Parameters:
-;		CX:		Line length so far
-;		DS:SI:	Ptr first character after space
-;		SS:BP:	Ptr to LINE_SPLITTER
-;	Returns:
-;		SS:BP:	LINE_SPLITTER updated to beginning of next word
-;		Jumps to .IncrementCharacterCount
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.ProcessSpace:
-	mov		[bp+LINE_SPLITTER.pLastWord], si
-	jmp		SHORT .IncrementCharacterCount
-
-;--------------------------------------------------------------------
-; .ProcessControlCharacter
-;	Parameters:
-;		AL:		Control character
-;		CX:		Line length so far
-;		DS:SI:	Ptr inside string to split
-;		SS:BP:	Ptr to LINE_SPLITTER
-;	Returns:
-;		SS:BP:	LINE_SPLITTER updated to beginning of next line (LF control character)
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.ProcessControlCharacter:
-	cmp		al, NULL			; End of string?
-	je		SHORT .RemoveEmptyLinesAtTheEndIfAnyExists
-	cmp		al, LF				; Line feed?
-	je		SHORT .NewlineCharacter
-	cmp		al, SOH				; Previous newline character?
-	je		SHORT .NewlineCharacter
-
-	mov		BYTE [si-1], ' '	; Replace unhandled control characters with space
-	jmp		SHORT .ProcessSpace
-
-ALIGN JUMP_ALIGN
-.NewlineCharacter:
-	mov		BYTE [si-1], SOH	; SOH marks previous newline character
-	mov		[bp+LINE_SPLITTER.pLastWord], si
-	jmp		SHORT .StartNewLine
-
-ALIGN JUMP_ALIGN
-.RemoveEmptyLinesAtTheEndIfAnyExists:
-	cmp		BYTE [si-2], SOH	; Character before NULL
-	je		SHORT .RemoveEmptyLineAtTheEndOfString
-	ret
-ALIGN JUMP_ALIGN
-.RemoveEmptyLineAtTheEndOfString:
-	dec		si
-	dec		WORD [bp+LINE_SPLITTER.wLines]
-	mov		BYTE [si-1], NULL
-	jmp		SHORT .RemoveEmptyLinesAtTheEndIfAnyExists
-
-
-;--------------------------------------------------------------------
-; LineSplitter_PrintLineInCXfromStringInESDI
-;	Parameters:
-;		CX:		Index of line to print
-;		ES:DI:	Ptr to string containing the line
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, BX, SI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-LineSplitter_PrintLineInCXfromStringInESDI:
-	push	di
-	push	cx
-
-	call	LineSplitter_GetOffsetToSIforLineCXfromStringInESDI
-	jnc		SHORT .LineNotFound
-	mov		bx, es
-	CALL_DISPLAY_LIBRARY PrintCharBufferFromBXSIwithLengthInCX
-.LineNotFound:
-	pop		cx
-	pop		di
-	ret
-
-
-;--------------------------------------------------------------------
-; LineSplitter_GetOffsetToSIforLineCXfromStringInESDI
-;	Parameters:
-;		CX:		Index of line to search for
-;		ES:DI:	Ptr to string
-;	Returns:
-;		CX:		Line length
-;		ES:SI:	Ptr to beginning of line
-;		CF:		Set if wanted line was found
-;	Corrupts registers:
-;		AX, DI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-LineSplitter_GetOffsetToSIforLineCXfromStringInESDI:
-	mov		si, di				; SI points to start of first line
-	mov		al, STX				; Last control character to scan for
-	inc		cx					; Increment CX to line count
-	cld
-ALIGN JUMP_ALIGN
-.LineScanLoop:
-	scasb						; cmp al, [es:di]. Increment DI
-	jb		SHORT .LineScanLoop	; Ignore all above STX
-
-	; NULL, SOH or STX
-	dec		cx					; Decrement lines to scan through
-	jz		SHORT .WantedLineFound
-	cmp		BYTE [es:di-1], NULL
-	je		SHORT .EndOfString	; Jump with CF cleared
-	mov		si, di				; SI points to start of new line
-	jmp		SHORT .LineScanLoop
-
-ALIGN JUMP_ALIGN
-.WantedLineFound:
-	stc							; Set CF since wanted line was found
-.EndOfString:
-	lahf						; Load FLAGS low to AH
-	lea		cx, [di-1]			; CX = offset to NULL, SOH or STX
-	sub		cx, si				; CX = string length
-	sahf						; Store AH to FLAGS low
-	ret
Index: trunk/Assembly_Library/Src/Menu/MenuAttributes.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuAttributes.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/MenuAttributes.asm	(revision 52)
@@ -24,5 +24,5 @@
 
 ;--------------------------------------------------------------------
-; MenuAttribute_GetToALfromTypeInSI
+; MenuAttribute_SetToDisplayContextFromTypeInSI
 ;	Parameters
 ;		SI:		Attribute type (from ATTRIBUTE_CHARS)
Index: trunk/Assembly_Library/Src/Menu/MenuBorders.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuBorders.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/MenuBorders.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	14.7.2010
-; Last update	:	28.9.2010
+; Last update	:	11.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for drawing menu borders.
@@ -50,8 +50,8 @@
 MenuBorders_AdjustDisplayContextForDrawingBorders:
 	mov		bl, ATTRIBUTES_ARE_USED
-	mov		ax, MenuCharOut_MenuBorderTeletypeOutputWithAttribute
+	mov		ax, MenuCharOut_MenuTeletypeOutput
 	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL
 
-	mov		ax, bp
+	call	CharOutLineSplitter_GetFirstBorderLineColumnOffsetToAX
 	CALL_DISPLAY_LIBRARY SetCharacterOutputParameterFromAX
 
Index: trunk/Assembly_Library/Src/Menu/MenuCharOut.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuCharOut.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/MenuCharOut.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	15.7.2010
-; Last update	:	10.10.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Character out function for printing withing menu window.
@@ -10,5 +10,6 @@
 
 ;--------------------------------------------------------------------
-; MenuCharOut_MenuBorderTeletypeOutputWithAttribute
+; MenuCharOut_MenuTeletypeOutputWithAutomaticLineChange
+; MenuCharOut_MenuTeletypeOutput
 ;	Parameters:
 ;		AL:		Character to output
@@ -16,4 +17,7 @@
 ;		DS:		BDA segment (zero)
 ;		ES:DI:	Ptr to video memory where to output
+;		[DISPLAY_CONTEXT.wCharOutParam]:
+;				Low byte  = First column offset (after CR)
+;				High byte = Last column offset (when using automatic line change)
 ;	Returns:
 ;		DI:		Incremented for next character
@@ -22,138 +26,28 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-MenuCharOut_MenuBorderTeletypeOutputWithAttribute:
-	cmp		al, CR					; Carriage return?
-	je		SHORT .PrintCRandAdjustColumnToMenuBorders
-	jmp		DisplayCharOut_TeletypeOutputWithAttribute
-
-ALIGN JUMP_ALIGN
-.PrintCRandAdjustColumnToMenuBorders:
-	call	DisplayCharOut_BiosTeletypeOutput
-	xor		ax, ax					; No offset, cursor to start of border
-	jmp		SHORT SetCursorToNextMenuLine
-
-
-;--------------------------------------------------------------------
-; MenuCharOut_MenuTextTeletypeOutputWithAttributeAndAutomaticLineChange
-; MenuCharOut_MenuTextTeletypeOutputWithAttribute
-;	Parameters:
-;		AL:		Character to output
-;		AH:		Attribute to output
-;		DS:		BDA segment (zero)
-;		ES:DI:	Ptr to video memory where to output
-;	Returns:
-;		DI:		Incremented for next character
-;	Corrupts registers:
-;		AX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-MenuCharOut_MenuTextTeletypeOutputWithAttributeAndAutomaticLineChange:
-	push	di
-	push	ax
-	mov		al, DOUBLE_VERTICAL
-	add		di, BYTE MENU_TEXT_COLUMN_OFFSET	; Border char comes after space
-	WAIT_RETRACE_IF_NECESSARY_THEN scasb
-	pop		ax
-	pop		di
-	je		SHORT MovePartialWordToNewTextLineAndPrintCharacterFromAX
+MenuCharOut_MenuTeletypeOutputWithAutomaticLineChange:
+	call	CharOutLineSplitter_IsCursorAtTheEndOfTextLine
+	jnc		SHORT MenuCharOut_MenuTeletypeOutput
+	cmp		al, ' '
+	jb		SHORT ReturnSinceNoNeedToStartLineWithControlCharacter
+	call	CharOutLineSplitter_MovePartialWordToNewTextLine
 	; Fall to MenuCharOut_MenuTextTeletypeOutputWithAttribute
 
 ALIGN JUMP_ALIGN
-MenuCharOut_MenuTextTeletypeOutputWithAttribute:
-	cmp		al, CR						; Carriage return?
-	je		SHORT PrintCRfromALandAdjustColumnToMenuText
+MenuCharOut_MenuTeletypeOutput:
+	cmp		al, CR
+	je		SHORT PrintCRandAdjustOffsetForStartOfLine
 	jmp		DisplayCharOut_TeletypeOutputWithAttribute
 
 
 ;--------------------------------------------------------------------
-; MovePartialWordToNewTextLineAndPrintCharacterFromAX
-;	Parameters:
-;		AL:		Character to output
-;		AH:		Attribute to output
-;		DS:		BDA segment (zero)
-;		ES:DI:	Ptr to end of text line in video memory
-;	Returns:
-;		DI:		Incremented for next character
-;	Corrupts registers:
-;		AX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-MovePartialWordToNewTextLineAndPrintCharacterFromAX:
-	cmp		al, ' '		; Space or any control character
-	jb		SHORT .MoveCursorInDItoBeginningOfNextLine
-	push	si
-	push	cx
-	push	ax
-
-	call	.GetOffsetToPartialWordToSIandSizeToCX
-	call	.MoveCursorInDItoBeginningOfNextLine
-	jcxz	.NothingToMove
-	call	.MovePartialWordFromPreviousLineInESSItoNewLineInESDIwithSizeInCX
-.NothingToMove:
-	pop		ax
-	pop		cx
-	pop		si
-	jmp		DisplayCharOut_TeletypeOutputWithAttribute
-
-;--------------------------------------------------------------------
-; .GetOffsetToPartialWordToSIandSizeToCX
-;	Parameters:
-;		ES:DI:	Ptr to space before border character
-;	Returns:
-;		CX:		Number of bytes that needs to be moved
-;		ES:SI:	Ptr to beginning of partial word that needs to be moved to new line
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.GetOffsetToPartialWordToSIandSizeToCX:
-	xor		cx, cx
-	mov		si, di
-ALIGN JUMP_ALIGN
-.ScanNextCharacter:		; Space will always be found since one comes after border
-	dec		si
-	dec		si
-	cmp		BYTE [es:si], ' '
-	je		SHORT .PartialWordFound
-	inc		cx
-	jmp		SHORT .ScanNextCharacter
-ALIGN JUMP_ALIGN
-.PartialWordFound:
-	inc		si
-	inc		si			; SI now points one past space
-	shl		cx, 1		; Characters to bytes
-	ret
-
-;--------------------------------------------------------------------
-; .MovePartialWordFromPreviousLineInESSItoNewLineInESDIwithSizeInCX
-;	Parameters:
-;		CX:		Number of bytes in partial word
-;		DS:		BDA segment (zero)
-;		ES:SI:	Ptr to partial word on previous line
-;		ES:DI:	Ptr to new empty line
-;	Returns:
-;		ES:DI:	Ptr where to store next character
-;	Corrupts registers:
-;		AX, CX, DX, SI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.MovePartialWordFromPreviousLineInESSItoNewLineInESDIwithSizeInCX:
-	push	si
-	push	cx
-	WAIT_RETRACE_IF_NECESSARY_THEN rep movsb
-	pop		cx
-	pop		si
-	xchg	di, si
-	shr		cx, 1		; Bytes to characters
-	mov		al, ' '
-	call	DisplayPrint_RepeatCharacterFromALwithCountInCX
-	mov		di, si
-	ret
-
-;--------------------------------------------------------------------
-; .MoveCursorInDItoBeginningOfNextLine
+; MenuCharOut_PrintLFCRandAdjustOffsetForStartOfLine
+; PrintCRandAdjustOffsetForStartOfLine
 ;	Parameters:
 ;		DS:		BDA segment (zero)
 ;		ES:DI:	Ptr to cursor location
+;		[DISPLAY_CONTEXT.wCharOutParam]:
+;				Low byte  = First column offset (after CR)
+;				High byte = Last column offset (when using automatic line change)
 ;	Returns:
 ;		ES:DI:	Ptr to beginning of new line
@@ -162,67 +56,15 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-.MoveCursorInDItoBeginningOfNextLine:
+MenuCharOut_PrintLFCRandAdjustOffsetForStartOfLine:
 	mov		al, LF
 	call	DisplayCharOut_BiosTeletypeOutput
+	; Fall to PrintCRandAdjustOffsetForStartOfLine
+
+ALIGN JUMP_ALIGN
+PrintCRandAdjustOffsetForStartOfLine:
 	mov		al, CR
-	; Fall to PrintCRfromALandAdjustColumnToMenuText
-
-
-;--------------------------------------------------------------------
-; PrintCRfromALandAdjustColumnToMenuText
-;	Parameters:
-;		AL:		Character to output (CR)
-;		DS:		BDA segment (zero)
-;		ES:DI:	Ptr to video memory where to output
-;	Returns:
-;		DI:		Incremented for next text line
-;	Corrupts registers:
-;		AX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-PrintCRfromALandAdjustColumnToMenuText:
 	call	DisplayCharOut_BiosTeletypeOutput
-	mov		al, MENU_TEXT_COLUMN_OFFSET	; Offset to start of text
-	; Fall to SetCursorToNextMenuLine
-
-;--------------------------------------------------------------------
-; SetCursorToNextMenuLine
-;	Parameters:
-;		AL:		Column offset from start of borders
-;		DS:		BDA segment (zero)
-;		ES:DI:	Ptr to video memory where to output
-;	Returns:
-;		DI:		Adjusted for next line
-;	Corrupts registers:
-;		AX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-SetCursorToNextMenuLine:
-	push	bp
-
-	mov		bp, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
-	call	.AddCoordinatesForNewBorderLineToAX
-	call	DisplayCursor_SetCoordinatesFromAX	; Updates DI
-
-	pop		bp
+	eMOVZX	ax, BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
+	add		di, ax
+ReturnSinceNoNeedToStartLineWithControlCharacter:
 	ret
-
-;--------------------------------------------------------------------
-; .AddCoordinatesForNewBorderLineToAX
-;	Parameters:
-;		AL:		Column offset from start of borders
-;		DS:		BDA segment (zero)
-;		SS:BP:	Ptr to MENU
-;	Returns:
-;		AX:		Coordinates for new line
-;	Corrupts registers:
-;		DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.AddCoordinatesForNewBorderLineToAX:
-	call	MenuLocation_AddTitleBordersTopLeftCoordinatesToAX
-	push	ax
-	call	DisplayCursor_GetSoftwareCoordinatesToAX
-	pop		dx
-	mov		al, dl					; Adjust column to borders
-	ret
Index: trunk/Assembly_Library/Src/Menu/MenuEvent.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuEvent.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/MenuEvent.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	13.7.2010
-; Last update	:	5.10.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for initializing menu system.
@@ -82,5 +82,5 @@
 	mov		bx, MENUEVENT.RefreshInformation
 LoadHighlightedItemToCXandSendMessageFromBX:
-	mov		cx, [bp+MENU.wHighlightedItem]
+	mov		cx, [bp+MENUINIT.wHighlightedItem]
 	jmp		SHORT MenuEvent_SendFromBX
 
@@ -117,5 +117,5 @@
 MenuEvent_HighlightItemFromCX:
 	mov		dx, cx
-	xchg	dx, [bp+MENU.wHighlightedItem]
+	xchg	dx, [bp+MENUINIT.wHighlightedItem]
 	push	dx
 
@@ -125,5 +125,5 @@
 	pop		ax
 	call	MenuText_RefreshItemFromAX
-	mov		ax, [bp+MENU.wHighlightedItem]
+	mov		ax, [bp+MENUINIT.wHighlightedItem]
 	jmp		MenuText_RefreshItemFromAX
 
Index: trunk/Assembly_Library/Src/Menu/MenuInit.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuInit.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/MenuInit.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	13.7.2010
-; Last update	:	5.10.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for initializing menu system.
@@ -30,5 +30,5 @@
 	call	Memory_ZeroSSBPwithSizeInCX
 	call	MenuInit_EnterMenuWithHandlerInBXandUserDataInDXAX
-	mov		ax, [bp+MENU.wHighlightedItem]
+	mov		ax, [bp+MENUINIT.wHighlightedItem]
 
 	eLEAVE_STRUCT MENU_size
@@ -56,5 +56,4 @@
 	mov		[bp+MENU.dwUserData], ax
 	mov		[bp+MENU.dwUserData+2], dx
-	mov		WORD [bp+MENU.wHighlightedItem], NO_ITEM_HIGHLIGHTED
 
 	mov		ax, CURSOR_HIDDEN
@@ -110,5 +109,5 @@
 ALIGN JUMP_ALIGN
 MenuInit_HighlightItemFromAX:
-	sub		ax, [bp+MENU.wHighlightedItem]
+	sub		ax, [bp+MENUINIT.wHighlightedItem]
 	jmp		MenuScrollbars_MoveHighlightedItemByAX
 
@@ -124,5 +123,5 @@
 ALIGN JUMP_ALIGN
 MenuInit_GetHighlightedItemToAX:
-	mov		ax, [bp+MENU.wHighlightedItem]
+	mov		ax, [bp+MENUINIT.wHighlightedItem]
 	ret
 
Index: trunk/Assembly_Library/Src/Menu/MenuLoop.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuLoop.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/MenuLoop.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	22.7.2010
-; Last update	:	16.9.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Menu loop for waiting keystrokes.
@@ -102,5 +102,5 @@
 .LeaveMenuWithoutSelectingItem:
 	call	MenuInit_CloseMenuWindow
-	mov		WORD [bp+MENU.wHighlightedItem], NO_ITEM_HIGHLIGHTED
+	mov		WORD [bp+MENUINIT.wHighlightedItem], NO_ITEM_HIGHLIGHTED
 	stc
 	ret
@@ -108,5 +108,5 @@
 ALIGN JUMP_ALIGN
 .SelectItem:
-	mov		cx, [bp+MENU.wHighlightedItem]
+	mov		cx, [bp+MENUINIT.wHighlightedItem]
 	call	MenuEvent_ItemSelectedFromCX
 	stc
@@ -151,5 +151,5 @@
 	xchg	ax, cx
 	neg		ax
-	mov		cx, [bp+MENU.wHighlightedItem]
+	mov		cx, [bp+MENUINIT.wHighlightedItem]
 	add		cx, ax
 	jge		SHORT .MoveHighlightedItemByAX	; No rotation for PgUp
@@ -157,5 +157,5 @@
 ALIGN JUMP_ALIGN
 .SelectFirstItem:
-	mov		ax, [bp+MENU.wHighlightedItem]
+	mov		ax, [bp+MENUINIT.wHighlightedItem]
 	neg		ax
 	jmp		SHORT .MoveHighlightedItemByAX
@@ -165,5 +165,5 @@
 	call	MenuScrollbars_GetMaxVisibleItemsOnPageToCX
 	xchg	ax, cx
-	mov		cx, [bp+MENU.wHighlightedItem]
+	mov		cx, [bp+MENUINIT.wHighlightedItem]
 	add		cx, ax
 	cmp		cx, [bp+MENUINIT.wItems]
@@ -173,5 +173,5 @@
 .SelectLastItem:
 	mov		ax, [bp+MENUINIT.wItems]
-	sub		ax, [bp+MENU.wHighlightedItem]
+	sub		ax, [bp+MENUINIT.wHighlightedItem]
 	dec		ax
 	jmp		SHORT .MoveHighlightedItemByAX
Index: trunk/Assembly_Library/Src/Menu/MenuScrollbars.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuScrollbars.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/MenuScrollbars.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	20.7.2010
-; Last update	:	9.8.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for drawing scroll bars over menu borders.
@@ -98,5 +98,5 @@
 ALIGN JUMP_ALIGN
 MenuScrollbars_MoveHighlightedItemByAX:
-	mov		cx, [bp+MENU.wHighlightedItem]
+	mov		cx, [bp+MENUINIT.wHighlightedItem]
 	add		cx, ax
 	call	.RotateItemInCX
@@ -118,5 +118,5 @@
 
 	mov		dx, [bp+MENU.wFirstVisibleItem]
-	sub		dx, [bp+MENU.wHighlightedItem]
+	sub		dx, [bp+MENUINIT.wHighlightedItem]
 	add		dx, cx
 	MAX_S	dx, 0
Index: trunk/Assembly_Library/Src/Menu/MenuText.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuText.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Menu/MenuText.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	21.7.2010
-; Last update	:	7.10.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for drawing menu texts by the user.
@@ -76,18 +76,14 @@
 PrepareToDrawTitleArea:
 	mov		si, ATTRIBUTE_CHARS.cTitle
-	mov		ax, MenuCharOut_MenuTextTeletypeOutputWithAttributeAndAutomaticLineChange
-	call	AdjustDisplayContextForDrawingTextsWithCharOutFunctionFromAX
 	call	MenuLocation_GetTitleTextTopLeftCoordinatesToAX
-	CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
-	ret
+	jmp		SHORT FinishPreparationsToDrawTitleOrInformationArea
 
 ALIGN JUMP_ALIGN
 PrepareToDrawInformationArea:
 	mov		si, ATTRIBUTE_CHARS.cInformation
-	mov		ax, MenuCharOut_MenuTextTeletypeOutputWithAttributeAndAutomaticLineChange
-	call	AdjustDisplayContextForDrawingTextsWithCharOutFunctionFromAX
 	call	MenuLocation_GetInformationTextTopLeftCoordinatesToAX
-	CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
-	ret
+FinishPreparationsToDrawTitleOrInformationArea:
+	mov		dx, MenuCharOut_MenuTeletypeOutputWithAutomaticLineChange
+	jmp		SHORT AdjustDisplayContextForDrawingTextsAtCoordsInAXwithAttrTypeInSIandCharOutFunctionInDX
 
 
@@ -134,6 +130,5 @@
 	call	MenuScrollbars_IsItemInCXonVisiblePage
 	jnc		SHORT .InvalidItem
-	mov		ax, cx
-	call	MenuText_AdjustDisplayContextForDrawingItemFromAX
+	call	MenuText_AdjustDisplayContextForDrawingItemFromCX
 	call	MenuEvent_RefreshItemFromCX
 	call	DrawScrollbarIfNecessary
@@ -144,24 +139,47 @@
 
 ;--------------------------------------------------------------------
-; MenuText_AdjustDisplayContextForDrawingItemFromAX
-;	Parameters
-;		AX:		Item to refresh
-;		SS:BP:	Ptr to MENU
-;	Returns:
-;		CX:		Item to refresh
-;	Corrupts registers:
-;		AX, SI, DI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-MenuText_AdjustDisplayContextForDrawingItemFromAX:
-	mov		cx, ax
+; MenuText_AdjustDisplayContextForDrawingItemFromCX
+;	Parameters
+;		CX:		Item to refresh
+;		SS:BP:	Ptr to MENU
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, DX, SI, DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+MenuText_AdjustDisplayContextForDrawingItemFromCX:
+	mov		ax, cx
+	call	GetItemTextAttributeTypeToSIforItemInCX
 	call	MenuLocation_GetTextCoordinatesToAXforItemInAX
+	mov		dx, MenuCharOut_MenuTeletypeOutput
+	; Fall to AdjustDisplayContextForDrawingTextsAtCoordinatesInAXwithAttributeTypeInSI
+
+;--------------------------------------------------------------------
+; AdjustDisplayContextForDrawingTextsAtCoordsInAXwithAttrTypeInSIandCharOutFunctionInDX
+;	Parameters
+;		AX:		Cursor coordinates to set
+;		DX:		Character output function
+;		SI:		Attribute type (from ATTRIBUTE_CHARS)
+;		SS:BP:	Ptr to MENU
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, DX, SI, DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+AdjustDisplayContextForDrawingTextsAtCoordsInAXwithAttrTypeInSIandCharOutFunctionInDX:
 	CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
-	call	.GetItemTextAttributeTypeToSIforItemInCX
-	mov		ax, MenuCharOut_MenuTextTeletypeOutputWithAttribute
-	jmp		SHORT AdjustDisplayContextForDrawingTextsWithCharOutFunctionFromAX
-
-;--------------------------------------------------------------------
-; .GetItemTextAttributeTypeToSIforItemInCX
+
+	xchg	ax, dx
+	mov		bl, ATTRIBUTES_ARE_USED
+	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL
+
+	call	CharOutLineSplitter_PrepareForPrintingTextLines
+	jmp		MenuAttribute_SetToDisplayContextFromTypeInSI
+
+
+;--------------------------------------------------------------------
+; GetItemTextAttributeTypeToSIforItemInCX
 ;	Parameters
 ;		CX:		Item to refresh
@@ -173,9 +191,10 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-.GetItemTextAttributeTypeToSIforItemInCX:
+GetItemTextAttributeTypeToSIforItemInCX:
 	mov		si, ATTRIBUTE_CHARS.cItem
 	test	BYTE [bp+MENU.bFlags], FLG_MENU_NOHIGHLIGHT
 	jnz		SHORT .ReturnAttributeTypeInSI
-	cmp		cx, [bp+MENU.wHighlightedItem]
+
+	cmp		cx, [bp+MENUINIT.wHighlightedItem]
 	jne		SHORT .ReturnAttributeTypeInSI
 	sub		si, BYTE ATTRIBUTE_CHARS.cItem - ATTRIBUTE_CHARS.cHighlightedItem
@@ -258,24 +277,2 @@
 	pop		cx
 	ret
-
-
-;--------------------------------------------------------------------
-; AdjustDisplayContextForDrawingTextsWithCharOutFunctionFromAX
-;	Parameters
-;		AX:		Character output function
-;		SI:		Attribute type (from ATTRIBUTE_CHARS)
-;		SS:BP:	Ptr to MENU
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, BX, SI, DI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-AdjustDisplayContextForDrawingTextsWithCharOutFunctionFromAX:
-	mov		bl, ATTRIBUTES_ARE_USED
-	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL
-
-	mov		ax, bp
-	CALL_DISPLAY_LIBRARY SetCharacterOutputParameterFromAX
-
-	jmp		MenuAttribute_SetToDisplayContextFromTypeInSI
Index: trunk/Assembly_Library/Src/String/String.asm
===================================================================
--- trunk/Assembly_Library/Src/String/String.asm	(revision 51)
+++ trunk/Assembly_Library/Src/String/String.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	12.7.2010
-; Last update	:	1.10.2010
+; Last update	:	12.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for handling characters.
@@ -16,37 +16,27 @@
 ;	Returns:
 ;		AX:		Word converted from string
-;		DI:		Offset to NULL or first invalid character
-;		CF:		Set if conversion successfull
-;				Cleared if invalid string
+;		SI:		Updated
+;		CF:		Cleared if successfull
+;				Set if error during conversion
 ;	Corrupts registers:
-;		DX
+;		Nothing
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 String_ConvertWordToAXfromStringInDSSIwithBaseInBX:
-	xor		dx, dx
-	cld
+	push	di
+	push	dx
 
-ALIGN JUMP_ALIGN
-.ConvertWordToAXfromStringInDSSIwithBaseInBX:
-	lodsb						; Load character from DS:SI to AL
-	call	Char_ConvertIntegerToALfromDigitInALwithBaseInBX
-	jnc		SHORT .InvalidCharacter
-	xor		ah, ah
-	push	ax					; Push integer
-	xchg	ax, dx				; Copy WORD to AX
-	mul		bx					; DX:AX = word in AX * base in BX
-	pop		dx					; Pop integer
-	add		dx, ax				; WORD back to DX
-	jmp		SHORT .ConvertWordToAXfromStringInDSSIwithBaseInBX
+	xor		di, di
+	mov		dx, StringProcess_ConvertToWordInDIWithBaseInBX
+	call	StringProcess_DSSIwithFunctionInDX
+	xchg	ax, di
 
-ALIGN JUMP_ALIGN
-.InvalidCharacter:
-	sub		al, 1				; Set CF if NULL character, clear CF otherwise
-	xchg	ax, dx				; Return WORD in AX
+	pop		dx
+	pop		di
 	ret
 
 
 ;--------------------------------------------------------------------
-; String_CopyToESDIfromDSSIwithoutTerminatingESDI
+; String_CopyDSSItoESDIandGetSizeToCX
 ;	Parameters:
 ;		DS:SI:	Ptr to source NULL terminated string
@@ -59,10 +49,10 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-String_CopyToESDIfromDSSIwithoutTerminatingESDI:
+String_CopyDSSItoESDIandGetSizeToCX:
 	push	ax
+
 	xor		cx, cx
-
 ALIGN JUMP_ALIGN
-.GetAndStoreNewCharacter:
+.CopyNextCharacter:
 	lodsb						; Load from DS:SI to AL
 	test	al, al				; NULL to end string?
@@ -70,5 +60,5 @@
 	stosb						; Store from AL to ES:DI
 	inc		cx					; Increment number of characters written
-	jmp		SHORT .GetAndStoreNewCharacter
+	jmp		SHORT .CopyNextCharacter
 
 ALIGN JUMP_ALIGN
@@ -79,29 +69,27 @@
 
 ;--------------------------------------------------------------------
-; String_ConvertDSSItoLowerCase
+; String_GetLengthFromDSSItoCX
 ;	Parameters:
-;		DS:SI:	Ptr to NULL terminated string to convert
+;		DS:SI:	Ptr to NULL terminated string
 ;	Returns:
-;		Nothing
+;		CX:		String length in characters
 ;	Corrupts registers:
 ;		Nothing
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-String_ConvertDSSItoLowerCase:
+String_GetLengthFromDSSItoCX:
+	push	ax
 	push	si
-	push	ax
 
-ALIGN JUMP_ALIGN
-.ConvertNextCharacter:
-	lodsb
-	test	al, al				; NULL to end string?
-	jz		SHORT .EndOfString
-	call	Char_ALtoLowerCaseLetter
-	mov		[si-1], al
-	jmp		SHORT .ConvertNextCharacter
+	call	Memory_ExchangeDSSIwithESDI
+	xor		ax, ax		; Find NULL
+	mov		cx, -1		; Full segment if necessary
+	repne scasb
+	mov		cx, di
+	call	Memory_ExchangeDSSIwithESDI
 
-ALIGN JUMP_ALIGN
-.EndOfString:
+	pop		si
+	stc
+	sbb		cx, si		; Subtract NULL
 	pop		ax
-	pop		si
 	ret
Index: trunk/Assembly_Library/Src/String/StringProcess.asm
===================================================================
--- trunk/Assembly_Library/Src/String/StringProcess.asm	(revision 52)
+++ trunk/Assembly_Library/Src/String/StringProcess.asm	(revision 52)
@@ -0,0 +1,109 @@
+; File name		:	StringProcess.asm
+; Project name	:	Assembly Library
+; Created date	:	12.10.2010
+; Last update	:	12.10.2010
+; Author		:	Tomi Tilli
+; Description	:	Functions for processing characters in a string.
+
+; Section containing code
+SECTION .text
+
+;--------------------------------------------------------------------
+; Character processing callback function prototype for StringProcess_DSSIwithFunctionInBX.
+;	Parameters:
+;		AL:			Character to process
+;		CX:			Number of characters processed
+;		DS:SI:		Ptr to next character
+;		BX,DI,ES:	Free to use by processing function
+;	Returns:
+;		CF:			Clear to continue with next character
+;					Set to stop processing
+;		BX,DI,ES:	Free to use by processing function
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+
+
+;--------------------------------------------------------------------
+; StringProcess_DSSIwithFunctionInDX
+;	Parameters:
+;		DX:		Character processing function
+;		DS:SI:	Ptr to NULL terminated string to convert
+;	Returns:
+;		CX:		Number of characters processed
+;		CF:		Clear if all characters processed
+;				Set if terminated by processing function				
+;	Corrupts registers:
+;		Nothing (processing function can corrupt BX,DI,ES)
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+StringProcess_DSSIwithFunctionInDX:
+	push	si
+	push	ax
+
+	xor		cx, cx
+ALIGN JUMP_ALIGN
+.ProcessNextCharacter:
+	lodsb
+	test	al, al				; NULL to end string
+	jz		SHORT .EndOfString	; Return with CF cleared
+	inc		cx
+	call	dx
+	jnc		SHORT .ProcessNextCharacter
+
+ALIGN JUMP_ALIGN
+.EndOfString:
+	pop		ax
+	pop		si
+	ret
+
+
+;--------------------------------------------------------------------
+; StringProcess_ConvertToLowerCase (callback function for StringProcess_DSSIwithFunctionInDX)
+;	Parameters:
+;		AL:		Character to convert to lower case
+;		DS:SI:	Ptr to next character
+;	Returns:
+;		CF:		Clear to continue processing
+;	Corrupts registers:
+;		AL
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+StringProcess_ConvertToLowerCase:
+	call	Char_ALtoLowerCaseLetter
+	mov		[si-1], al
+	clc
+	ret
+
+
+;--------------------------------------------------------------------
+; StringProcess_ConvertToWordInDIWithBaseInBX (callback function for StringProcess_DSSIwithFunctionInDX)
+;	Parameters:
+;		AL:		Character to convert to lower case
+;		BX:		Numeric base (2, 10 or 16)
+;	Returns:
+;		CF:		Clear to continue processing
+;				Set if error
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+StringProcess_ConvertToWordInDIWithBaseInBX:
+	call	Char_ConvertIntegerToALfromDigitInALwithBaseInBX
+	jnc		SHORT .InvalidCharacter
+	push	dx
+
+	xor		ah, ah		; Digit converted to integer now in AX
+	xchg	ax, di
+	mul		bx			; Old WORD *= base
+	jc		SHORT .Overflow
+	add		di, ax		; Add old WORD to new integer
+	jc		SHORT .Overflow
+
+	pop		dx
+	ret
+.Overflow:
+	pop		dx
+.InvalidCharacter:
+	stc					; Set CF to stop processing
+	ret
Index: trunk/Assembly_Library/Src/Util/Memory.asm
===================================================================
--- trunk/Assembly_Library/Src/Util/Memory.asm	(revision 51)
+++ trunk/Assembly_Library/Src/Util/Memory.asm	(revision 52)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	14.7.2010
-; Last update	:	9.10.2010
+; Last update	:	11.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for memory access.
@@ -131,4 +131,5 @@
 ; Memory_CopySSBPtoESDI
 ; Memory_CopySSBPtoDSSI
+; Memory_CopyDSSItoESDI
 ; Memory_CopyESDItoDSSI
 ;	Parameters
@@ -151,4 +152,11 @@
 	pop		ds
 	mov		si, bp
+	ret
+
+ALIGN JUMP_ALIGN
+Memory_CopyDSSItoESDI:
+	push	ds
+	pop		es
+	mov		di, si
 	ret
 
