Index: trunk/Assembly_Library/Inc/Display.inc
===================================================================
--- trunk/Assembly_Library/Inc/Display.inc	(revision 43)
+++ trunk/Assembly_Library/Inc/Display.inc	(revision 44)
@@ -2,5 +2,5 @@
 ; Project name	:	AssemblyLibrary
 ; Created date	:	25.6.2010
-; Last update	:	15.9.2010
+; Last update	:	27.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Defines for display library.
@@ -37,33 +37,37 @@
 	.PushDisplayContext:
 	.PopDisplayContext:
-	.InitializeDisplayContext					resb	2
-
-	.SetCharacterPointerFromBXAX				resb	2
-	.SetCharacterOutputFunctionFromAX			resb	2
-	.SetCharacterOutputParameterFromAX			resb	2
-	.SetCharacterAttributeFromAL				resb	2
-	.SetCursorShapeFromAX						resb	2
-	.SetCursorCoordinatesFromAX					resb	2
-	.SetNewPageFromAL							resb	2
-	.SynchronizeDisplayContextToHardware		resb	2
-
-	.GetCharacterPointerToBXAX					resb	2
-	.GetSoftwareCoordinatesToAX					resb	2
-	.GetColumnsToALandRowsToAH					resb	2
-
-	.FormatNullTerminatedStringFromCSSI			resb	2
-	.PrintSignedDecimalIntegerFromAX			resb	2
-	.PrintWordFromAXwithBaseInBX				resb	2
-	.PrintCharBufferFromBXSIwithLengthInCX		resb	2
-	.PrintNullTerminatedStringFromBXSI			resb	2
-	.PrintNullTerminatedStringFromCSSI			resb	2
-	.PrintRepeatedCharacterFromALwithCountInCX	resb	2
-	.PrintCharacterFromAL						resb	2
-	.PrintNewlineCharacters						resb	2
-	.ClearAreaWithHeightInAHandWidthInAL		resb	2
-	.ClearScreen								resb	2
+	.InitializeDisplayContext						resb	2
+
+	.SetCharacterPointerFromBXAX					resb	2
+	.SetCharOutputFunctionFromAXwithAttribFlagInDL	resb	2
+	.SetCharacterOutputParameterFromAX				resb	2
+	.SetCharacterAttributeFromAL					resb	2
+	.SetCursorShapeFromAX							resb	2
+	.SetCursorCoordinatesFromAX						resb	2
+	.SetNewPageFromAL								resb	2
+	.SynchronizeDisplayContextToHardware			resb	2
+
+	.GetCharacterPointerToBXAX						resb	2
+	.GetSoftwareCoordinatesToAX						resb	2
+	.GetColumnsToALandRowsToAH						resb	2
+
+	.FormatNullTerminatedStringFromCSSI				resb	2
+	.PrintSignedWordFromAXWithBaseInBX				resb	2
+	.PrintWordFromAXwithBaseInBX					resb	2
+	.PrintCharBufferFromBXSIwithLengthInCX			resb	2
+	.PrintNullTerminatedStringFromBXSI				resb	2
+	.PrintNullTerminatedStringFromCSSI				resb	2
+	.PrintRepeatedCharacterFromALwithCountInCX		resb	2
+	.PrintCharacterFromAL							resb	2
+	.PrintNewlineCharacters							resb	2
+	.ClearAreaWithHeightInAHandWidthInAL			resb	2
+	.ClearScreen									resb	2
 endstruc
 
-; Character output functions for DISPLAY_LIB.SetCharacterOutputFunctionFromAX
+; Attribute flags for DISPLAY_LIB.SetCharacterOutputFunctionFromAXwithAttributeFlagInDL
+ATTRIBUTES_NOT_USED							EQU		0
+ATTRIBUTES_ARE_USED							EQU		FLG_CONTEXT_ATTRIBUTES
+
+; Character output functions for DISPLAY_LIB.SetCharacterOutputFunctionFromAXwithAttributeFlagInDL
 TELETYPE_OUTPUT_WITH_ATTRIBUTE				EQU		DisplayCharOut_TeletypeOutputWithAttribute
 TELETYPE_OUTPUT_WITHOUT_ATTRIBUTE			EQU		DisplayCharOut_TeletypeOutput
@@ -98,6 +102,9 @@
 	.wCursorShape		resb	2	; Current cursor shape
 	.bAttribute			resb	1	; Selected character attribute
-						resb	1
+	.bFlags				resb	1	; Display context flags
 endstruc
+
+; Display context flags
+FLG_CONTEXT_ATTRIBUTES		EQU		(1<<0)	; Character output function uses attributes
 
 
@@ -203,5 +210,17 @@
 ANGLE_QUOTE_LEFT							EQU		174
 ANGLE_QUOTE_RIGHT							EQU		175
-
+BLOCK_MOSTLY_BACKGROUND						EQU		176
+BLOCK_EVEN_BACKGROUND_AND_FOREGROUND		EQU		177
+BLOCK_MOSTLY_FOREGROUND						EQU		178
+BLOCK_FULL_FOREGROUND						EQU		219
+
+
+; Background character for clearing screen
+%ifndef SCREEN_BACKGROUND_CHARACTER
+	%define	SCREEN_BACKGROUND_CHARACTER		BLOCK_MOSTLY_BACKGROUND
+%endif
+%ifndef SCREEN_BACKGROUND_ATTRIBUTE
+	%define	SCREEN_BACKGROUND_ATTRIBUTE		MONO_NORMAL
+%endif
 
 %endif ; DISPLAY_INC
Index: trunk/Assembly_Library/Inc/Menu.inc
===================================================================
--- trunk/Assembly_Library/Inc/Menu.inc	(revision 43)
+++ trunk/Assembly_Library/Inc/Menu.inc	(revision 44)
@@ -125,6 +125,6 @@
 MENU_TEXT_COLUMN_OFFSET				EQU		2
 
-SCROLL_TRACK_CHARACTER				EQU		176
-SCROLL_THUMB_CHARACTER				EQU		219
+SCROLL_TRACK_CHARACTER				EQU		BLOCK_EVEN_BACKGROUND_AND_FOREGROUND
+SCROLL_THUMB_CHARACTER				EQU		BLOCK_FULL_FOREGROUND
 
 NO_ITEM_SELECTED					EQU		-1
Index: trunk/Assembly_Library/Src/Display/Display.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/Display.asm	(revision 43)
+++ trunk/Assembly_Library/Src/Display/Display.asm	(revision 44)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	2.7.2010
-; Last update	:	13.8.2010
+; Last update	:	27.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Display Library functions for CALL_DISPLAY_LIBRARY macro
@@ -65,29 +65,29 @@
 .rgfnDisplayLibraryFunctions:
 istruc DISPLAY_LIB
-	at	DISPLAY_LIB.InitializeDisplayContext,					dw	DisplayContext_Initialize
+	at	DISPLAY_LIB.InitializeDisplayContext,						dw	DisplayContext_Initialize
 
-	at	DISPLAY_LIB.SetCharacterPointerFromBXAX,				dw	DisplayContext_SetCharacterPointerFromBXAX
-	at	DISPLAY_LIB.SetCharacterOutputFunctionFromAX,			dw	DisplayContext_SetCharacterOutputFunctionFromAX
-	at	DISPLAY_LIB.SetCharacterOutputParameterFromAX,			dw	DisplayContext_SetCharacterOutputParameterFromAX
-	at	DISPLAY_LIB.SetCharacterAttributeFromAL,				dw	DisplayContext_SetCharacterAttributeFromAL
-	at	DISPLAY_LIB.SetCursorShapeFromAX,						dw	DisplayCursor_SetShapeFromAX
-	at	DISPLAY_LIB.SetCursorCoordinatesFromAX,					dw	DisplayCursor_SetCoordinatesFromAX
-	at	DISPLAY_LIB.SetNewPageFromAL,							dw	DisplayPage_SetFromAL
-	at	DISPLAY_LIB.SynchronizeDisplayContextToHardware,		dw	DisplayContext_SynchronizeToHardware
+	at	DISPLAY_LIB.SetCharacterPointerFromBXAX,					dw	DisplayContext_SetCharacterPointerFromBXAX
+	at	DISPLAY_LIB.SetCharOutputFunctionFromAXwithAttribFlagInDL,	dw	DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInDL
+	at	DISPLAY_LIB.SetCharacterOutputParameterFromAX,				dw	DisplayContext_SetCharacterOutputParameterFromAX
+	at	DISPLAY_LIB.SetCharacterAttributeFromAL,					dw	DisplayContext_SetCharacterAttributeFromAL
+	at	DISPLAY_LIB.SetCursorShapeFromAX,							dw	DisplayCursor_SetShapeFromAX
+	at	DISPLAY_LIB.SetCursorCoordinatesFromAX,						dw	DisplayCursor_SetCoordinatesFromAX
+	at	DISPLAY_LIB.SetNewPageFromAL,								dw	DisplayPage_SetFromAL
+	at	DISPLAY_LIB.SynchronizeDisplayContextToHardware,			dw	DisplayContext_SynchronizeToHardware
 
-	at	DISPLAY_LIB.GetCharacterPointerToBXAX,					dw	DisplayContext_GetCharacterPointerToBXAX
-	at	DISPLAY_LIB.GetSoftwareCoordinatesToAX,					dw	DisplayCursor_GetSoftwareCoordinatesToAX
-	at	DISPLAY_LIB.GetColumnsToALandRowsToAH,					dw	DisplayPage_GetColumnsToALandRowsToAH
+	at	DISPLAY_LIB.GetCharacterPointerToBXAX,						dw	DisplayContext_GetCharacterPointerToBXAX
+	at	DISPLAY_LIB.GetSoftwareCoordinatesToAX,						dw	DisplayCursor_GetSoftwareCoordinatesToAX
+	at	DISPLAY_LIB.GetColumnsToALandRowsToAH,						dw	DisplayPage_GetColumnsToALandRowsToAH
 
-	at	DISPLAY_LIB.FormatNullTerminatedStringFromCSSI,			dw	.FormatNullTerminatedStringFromCSSI
-	at	DISPLAY_LIB.PrintSignedDecimalIntegerFromAX,			dw	DisplayPrint_SignedDecimalIntegerFromAX
-	at	DISPLAY_LIB.PrintWordFromAXwithBaseInBX,				dw	DisplayPrint_WordFromAXWithBaseInBX
-	at	DISPLAY_LIB.PrintCharBufferFromBXSIwithLengthInCX,		dw	DisplayPrint_CharacterBufferFromBXSIwithLengthInCX
-	at	DISPLAY_LIB.PrintNullTerminatedStringFromBXSI,			dw	DisplayPrint_NullTerminatedStringFromBXSI
-	at	DISPLAY_LIB.PrintNullTerminatedStringFromCSSI,			dw	DisplayPrint_NullTerminatedStringFromCSSI
-	at	DISPLAY_LIB.PrintRepeatedCharacterFromALwithCountInCX,	dw	DisplayPrint_RepeatCharacterFromALwithCountInCX
-	at	DISPLAY_LIB.PrintCharacterFromAL,						dw	DisplayPrint_CharacterFromAL
-	at	DISPLAY_LIB.PrintNewlineCharacters,						dw	DisplayPrint_Newline
-	at	DISPLAY_LIB.ClearAreaWithHeightInAHandWidthInAL,		dw	DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
-	at	DISPLAY_LIB.ClearScreen,								dw	DisplayPrint_ClearScreen
+	at	DISPLAY_LIB.FormatNullTerminatedStringFromCSSI,				dw	.FormatNullTerminatedStringFromCSSI
+	at	DISPLAY_LIB.PrintSignedWordFromAXWithBaseInBX,				dw	DisplayPrint_SignedWordFromAXWithBaseInBX
+	at	DISPLAY_LIB.PrintWordFromAXwithBaseInBX,					dw	DisplayPrint_WordFromAXWithBaseInBX
+	at	DISPLAY_LIB.PrintCharBufferFromBXSIwithLengthInCX,			dw	DisplayPrint_CharacterBufferFromBXSIwithLengthInCX
+	at	DISPLAY_LIB.PrintNullTerminatedStringFromBXSI,				dw	DisplayPrint_NullTerminatedStringFromBXSI
+	at	DISPLAY_LIB.PrintNullTerminatedStringFromCSSI,				dw	DisplayPrint_NullTerminatedStringFromCSSI
+	at	DISPLAY_LIB.PrintRepeatedCharacterFromALwithCountInCX,		dw	DisplayPrint_RepeatCharacterFromALwithCountInCX
+	at	DISPLAY_LIB.PrintCharacterFromAL,							dw	DisplayPrint_CharacterFromAL
+	at	DISPLAY_LIB.PrintNewlineCharacters,							dw	DisplayPrint_Newline
+	at	DISPLAY_LIB.ClearAreaWithHeightInAHandWidthInAL,			dw	DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
+	at	DISPLAY_LIB.ClearScreen,									dw	DisplayPrint_ClearScreen
 iend
Index: trunk/Assembly_Library/Src/Display/DisplayCharOut.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayCharOut.asm	(revision 43)
+++ trunk/Assembly_Library/Src/Display/DisplayCharOut.asm	(revision 44)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	26.6.2010
-; Last update	:	18.9.2010
+; Last update	:	22.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for outputting characters to video memory.
@@ -180,7 +180,4 @@
 					; made without interfering with the display. (H or V retrace)
 	jc		SHORT %%WaitUntilNotInRetrace
-	sti
-	nop				; Should have time to serve IRQ here
-	cli
 %%WaitUntilNextRetraceStarts:
 	in		al, dx
Index: trunk/Assembly_Library/Src/Display/DisplayContext.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayContext.asm	(revision 43)
+++ trunk/Assembly_Library/Src/Display/DisplayContext.asm	(revision 44)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	25.6.2010
-; Last update	:	13.8.2010
+; Last update	:	27.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for managing display context.
@@ -23,5 +23,6 @@
 	mov		WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], DEFAULT_CHARACTER_OUTPUT
 	mov		WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCursorShape], CURSOR_NORMAL
-	mov		BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], MONO_NORMAL
+	mov		BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], SCREEN_BACKGROUND_ATTRIBUTE
+	mov		BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
 
 	xor		ax, ax
@@ -152,16 +153,21 @@
 
 ;--------------------------------------------------------------------
-; DisplayContext_SetCharacterOutputFunctionFromAX
+; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInDL
 ;	Parameters:
 ;		AX:		Offset to character output function
-;		DS:		BDA segment (zero)
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-DisplayContext_SetCharacterOutputFunctionFromAX:
+;		DL:		Attribute Flag
+;		DS:		BDA segment (zero)
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInDL:
 	mov		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
+	and		BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES
+	mov		al, dl
+	and		al, FLG_CONTEXT_ATTRIBUTES
+	or		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], al
 	ret
 
@@ -211,2 +217,39 @@
 	mov		dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
 	ret
+
+
+;--------------------------------------------------------------------
+; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
+;	Parameters:
+;		AX:		Offset in bytes from some character to another
+;		DS:		BDA segment (zero)
+;	Returns:
+;		AX:		Offset in characters from some character to another
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------	
+ALIGN JUMP_ALIGN
+DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX:
+	test	BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
+	jz		SHORT ReturnOffsetInAX
+	sar		ax, 1		; BYTE count to WORD count
+	ret
+
+;--------------------------------------------------------------------
+; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
+;	Parameters:
+;		AX:		Offset in characters from some character to another
+;		DS:		BDA segment (zero)
+;	Returns:
+;		AX:		Offset in bytes from some character to another
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------	
+ALIGN JUMP_ALIGN
+DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX:
+	test	BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
+	jz		SHORT ReturnOffsetInAX
+	sal		ax, 1		; WORD count to BYTE count
+ALIGN JUMP_ALIGN, ret
+ReturnOffsetInAX:
+	ret
Index: trunk/Assembly_Library/Src/Display/DisplayFormat.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayFormat.asm	(revision 43)
+++ trunk/Assembly_Library/Src/Display/DisplayFormat.asm	(revision 44)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	29.6.2010
-; Last update	:	10.8.2010
+; Last update	:	26.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for displaying formatted strings.
@@ -13,281 +13,326 @@
 ;	Parameters:
 ;		DS:		BDA segment (zero)
+;		SS:BP:	Pointer to first format parameter (-=2 updates to next parameter)
+;		CS:SI:	Pointer to string to format
+;		ES:DI:	Ptr to cursor location in video RAM
+;	Returns:
+;		CS:SI:	Ptr to end of format string (ptr to one past NULL)
+;		DI:		Updated offset to video RAM
+;	Corrupts registers:
+;		AX, BX, CX, DX, BP
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+DisplayFormat_ParseCharacters:
+	call	ReadCharacterAndTestForNull
+	jz		SHORT .QuitCharacterParsing
+
+	ePUSH_T	cx, DisplayFormat_ParseCharacters	; Return address
+	xor		cx, cx								; Initial placeholder size
+	cmp		al, '%'								; Format specifier?
+	je		SHORT ParseFormatSpecifier
+	jmp		DisplayPrint_CharacterFromAL
+
+ALIGN JUMP_ALIGN
+.QuitCharacterParsing:
+	ret
+
+
+;--------------------------------------------------------------------
+; ParseFormatSpecifier
+;	Parameters:
+;		CX:		Placeholder size
+;		DS:		BDA segment (zero)
 ;		SS:BP:	Pointer to first format parameter (-=2 for next parameter)
 ;		CS:SI:	Pointer to string to format
 ;		ES:DI:	Ptr to cursor location in video RAM
 ;	Returns:
+;		SI:		Updated to first unparsed character
 ;		DI:		Updated offset to video RAM
-;	Corrupts registers:
-;		AX, BX, CX, DX, SI, BP
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-DisplayFormat_ParseCharacters:
-	call	.ReadCharacterAndTestForNull
-	jz		SHORT .Return
-	xor		cx, cx							; Zero CX for parsing number parameter
-	cmp		al, '%'
-	je		SHORT .FormatParameterEncountered
-	call	DisplayPrint_CharacterFromAL	; Control or printable character
-	jmp		SHORT DisplayFormat_ParseCharacters
-ALIGN JUMP_ALIGN
-.Return:
-	ret
-
-;--------------------------------------------------------------------
-; .ReadCharacterAndTestForNull
-;	Parameters:
-;		CS:SI:	Pointer next character from string
-;	Returns:
-;		AL:		Character from string
-;		SI:		Incremented to next character
-;		ZF:		Set if NULL, cleared if valid character
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.ReadCharacterAndTestForNull:
-	eSEG	cs
-	lodsb									; Load from CS:SI to AL
-	test	al, al							; NULL to end string?
-	ret
-
-
-;--------------------------------------------------------------------
-; .FormatParameterEncountered
-;	Parameters:
-;		CX:		Zero or previous number parameter
-;		DS:		BDA segment (zero)
-;		SS:BP:	Pointer to next format parameter
-;		CS:SI:	Pointer to next format string character
-;		ES:DI:	Ptr to cursor location in video RAM
-;	Returns:
-;		SI:		Incremented to next character
-;		BP:		Offset to next format parameter
-;		Eventually jumps to DisplayFormat_ParseCharacters
+;		BP:		Updated to next format parameter
 ;	Corrupts registers:
 ;		AX, BX, CX, DX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-.FormatParameterEncountered:
-	call	.ReadCharacterAndTestForNull
-	jz		SHORT .Return
+ParseFormatSpecifier:
+	call	ReadCharacterAndTestForNull
 	call	Char_IsDecimalDigitInAL
-	jnc		SHORT .FormatWithCorrectFormatFunction
-	; Fall to .ParseNumberParameterToCX
-
-;--------------------------------------------------------------------
-; .ParseNumberParameterToCX
-;	Parameters:
-;		AL:		Number digit from format string
-;		CX:		Zero or previous number parameter
-;	Returns:
-;		CX:		Updated number parameter
-;		Jumps to .FormatParameterEncountered
+	jc		SHORT .ParsePlaceholderSizeDigitFromALtoCX
+	call	GetFormatSpecifierParserToAX
+	call	ax				; Parser function
+	dec		bp
+	dec		bp				; SS:BP now points to next parameter
+	test	cx, cx
+	jnz		SHORT PrependOrAppendSpaces
+	ret
+
+;--------------------------------------------------------------------
+; .ParsePlaceholderSizeDigitFromALtoCX
+;	Parameters:
+;		AL:		Digit character from format string
+;		CX:		Current placeholder size
+;		DS:		BDA segment (zero)
+;	Returns:
+;		CX:		Current placeholder size
+;		Jumps back to ParseFormatSpecifier
 ;	Corrupts registers:
 ;		AX
 ;--------------------------------------------------------------------
-.ParseNumberParameterToCX:
+ALIGN JUMP_ALIGN
+.ParsePlaceholderSizeDigitFromALtoCX:
+	mov		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di
 	sub		al, '0'				; Digit '0'...'9' to integer 0...9
 	mov		ah, cl				; Previous number parameter to AH
 	aad							; AL += (AH * 10)
 	mov		cl, al				; Updated number parameter now in CX
-	jmp		SHORT .FormatParameterEncountered
-
-;--------------------------------------------------------------------
-; .FormatWithCorrectFormatFunction
-;	Parameters:
-;		AL:		Format placeholder character (non digit character after '%')
-;		CX:		Number parameter (zero if no number parameter present)
-;		DS:		BDA segment (zero)
-;		SS:BP:	Pointer to format parameter
-;		CS:SI:	Pointer to next format string character
-;		ES:DI:	Ptr to cursor location in video RAM
-;	Returns:
-;		Eventually jumps to DisplayFormat_ParseCharacters
+	jmp		SHORT ParseFormatSpecifier
+
+
+;--------------------------------------------------------------------
+; ReadCharacterAndTestForNull
+;	Parameters:
+;		CS:SI:	Pointer next character from string
+;	Returns:
+;		AL:		Character from string
+;		SI:		Incremented to next character
+;		ZF:		Set if NULL, cleared if valid character
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+ReadCharacterAndTestForNull:
+	eSEG	cs
+	lodsb									; Load from CS:SI to AL
+	test	al, al							; NULL to end string?
+	ret
+
+
+;--------------------------------------------------------------------
+; GetFormatSpecifierParserToAX
+;	Parameters:
+;		AL:		Format specifier character
+;	Returns:
+;		AX:		Offset to parser function
+;	Corrupts registers:
+;		AX, BX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+GetFormatSpecifierParserToAX:
+	mov		bx, .rgcFormatCharToLookupIndex
+ALIGN JUMP_ALIGN
+.CheckForNextSpecifierParser:
+	cmp		al, [cs:bx]
+	je		SHORT .ConvertIndexToFunctionOffset
+	inc		bx
+	cmp		bx, .rgcFormatCharToLookupIndexEnd
+	jb		SHORT .CheckForNextSpecifierParser
+	mov		ax, c_FormatCharacter
+	ret
+ALIGN JUMP_ALIGN
+.ConvertIndexToFunctionOffset:
+	sub		bx, .rgcFormatCharToLookupIndex
+	shl		bx, 1				; Shift for WORD lookup
+	mov		ax, [cs:bx+.rgfnFormatSpecifierParser]
+	ret
+
+.rgcFormatCharToLookupIndex:
+	db		"aAduxsSct-+%"
+.rgcFormatCharToLookupIndexEnd:
+ALIGN WORD_ALIGN
+.rgfnFormatSpecifierParser:
+	dw		a_FormatAttributeForNextCharacter
+	dw		A_FormatAttributeForRemainingString
+	dw		d_FormatSignedDecimalWord
+	dw		u_FormatUnsignedDecimalWord
+	dw		x_FormatHexadecimalWord
+	dw		s_FormatStringFromSegmentCS
+	dw		S_FormatStringFromFarPointer
+	dw		c_FormatCharacter
+	dw		t_FormatRepeatCharacter
+	dw		PrepareToPrependParameterWithSpaces
+	dw		PrepareToAppendSpacesAfterParameter
+	dw		percent_FormatPercent
+
+
+;--------------------------------------------------------------------
+; PrependOrAppendSpaces
+;	Parameters:
+;		CX:		Minimum length for format specifier in characters
+;		DS:		BDA segment (zero)
+;		ES:DI:	Ptr to cursor location in video RAM
+;	Returns:
+;		Nothing
 ;	Corrupts registers:
 ;		AX, BX, CX, DX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-.FormatWithCorrectFormatFunction:
-	xor		bx, bx								; Zero lookup index
-ALIGN JUMP_ALIGN
-.PlaceholderComparisonLoop:
-	cmp		al, [cs:bx+.rgcFormatCharToLookupIndex]
-	je		SHORT .JumpToFormatPlaceholder
-	inc		bx
-	cmp		bl, .EndOFrgcFormatCharToLookupIndex - .rgcFormatCharToLookupIndex
-	jb		SHORT .PlaceholderComparisonLoop	; Loop
-	call	DisplayPrint_CharacterFromAL		; Display unsupported format character
-	; Fall to .UpdateSpacesToAppendAfterPrintingSingleCharacter
-
-;--------------------------------------------------------------------
-; .UpdateSpacesToAppendAfterPrintingSingleCharacter
-; .UpdateSpacesToAppend
-;	Parameters:
-;		BX:		Number of characters printed (.UpdateSpacesToAppend only)
-;		CX:		Number parameter (zero if no number parameter present)
-;		DS:		BDA segment (zero)
-;		SS:BP:	Pointer to format parameter
-;		CS:SI:	Pointer to next format string character
-;		ES:DI:	Ptr to cursor location in video RAM
-;	Returns:
-;		CX:		Number of spaces to append
-;		Jumps to .PrepareToFormatNextParameter
+PrependOrAppendSpaces:
+	mov		ax, di
+	sub		ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
+	test	cx, cx
+	js		SHORT .PrependWithSpaces
+	; Fall to .AppendSpaces
+
+;--------------------------------------------------------------------
+; .AppendSpaces
+;	Parameters:
+;		AX:		Number of format parameter BYTEs printed
+;		CX:		Minimum length for format specifier in characters
+;		DS:		BDA segment (zero)
+;		ES:DI:	Ptr to cursor location in video RAM
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, CX, DX
+;--------------------------------------------------------------------
+.AppendSpaces:
+	call	DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
+	sub		cx, ax
+	jle		SHORT .NothingToAppendOrPrepend
+	mov		al, ' '
+	jmp		DisplayPrint_RepeatCharacterFromALwithCountInCX
+
+;--------------------------------------------------------------------
+; .PrependWithSpaces
+;	Parameters:
+;		AX:		Number of format parameter BYTEs printed
+;		CX:		Negative minimum length for format specifier in characters
+;		DS:		BDA segment (zero)
+;		ES:DI:	Ptr to cursor location in video RAM
+;	Returns:
+;		Nothing
 ;	Corrupts registers:
 ;		AX, BX, CX, DX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-.UpdateSpacesToAppendAfterPrintingSingleCharacter:
-	mov		bx, 1
-ALIGN JUMP_ALIGN
-.UpdateSpacesToAppend:
-	jcxz	.PrepareToFormatNextParameter
-	sub		cx, bx				; Number of spaces to append
-	jle		SHORT .PrepareToFormatNextParameter
+.PrependWithSpaces:
+	xchg	ax, cx
+	neg		ax
+	call	DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
+	sub		ax, cx				; AX = BYTEs to prepend, CX = BYTEs to move
+	jle		SHORT .NothingToAppendOrPrepend
+
+	mov		bx, di
+	add		bx, ax				; BX = DI after prepending
+
+	push	si
+	dec		di					; DI = Offset to last byte formatted
+	mov		si, di
+	add		di, ax				; DI = Offset to new location for last byte
+	std
+	eSEG_STR rep, es, movsb
+
+	mov		dl, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags]
+	and		dx, BYTE FLG_CONTEXT_ATTRIBUTES
+	not		dx
+	and		di, dx				; WORD alignment when using attributes
+
+	call	DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
+	xchg	cx, ax				; CX = Spaces to prepend
 	mov		al, ' '
 	call	DisplayPrint_RepeatCharacterFromALwithCountInCX
-	; Fall to .PrepareToFormatNextParameter
-
-;--------------------------------------------------------------------
-; .PrepareToFormatNextParameter
-;	Parameters:
-;		DS:		BDA segment (zero)
-;		SS:BP:	Pointer to format parameter
-;		CS:SI:	Pointer to next format string character
-;		ES:DI:	Ptr to cursor location in video RAM
-;	Returns:
-;		BP:		Adjusted to point next stack parameter
-;		Jumps to DisplayFormat_ParseCharacters
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.PrepareToFormatNextParameter:
-	dec		bp
-	dec		bp
-	jmp		SHORT DisplayFormat_ParseCharacters
-
-
-;--------------------------------------------------------------------
-; .JumpToFormatPlaceholder
-;	Parameters:
-;		BX:		Lookup index for format function
-;		CX:		Number parameter (zero if no number parameter present)
-;		DS:		BDA segment (zero)
-;		SS:BP:	Pointer to next format parameter
-;		CS:SI:	Pointer to next format string character
-;		ES:DI:	Ptr to cursor location in video RAM
-;	Returns:
-;		Eventually jumps to DisplayFormat_ParseCharacters
+	cld							; Restore DF
+
+	mov		di, bx
+	pop		si
+.NothingToAppendOrPrepend:
+	ret
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Formatting functions
+;	Parameters:
+;		DS:		BDA segment (zero)
+;		SS:BP:	Pointer to next format parameter (-=2 updates to next parameter)
+;		ES:DI:	Ptr to cursor location in video RAM
+;	Returns:
+;		SS:BP:	Points to last WORD parameter used
 ;	Corrupts registers:
 ;		AX, BX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.JumpToFormatPlaceholder:
-	shl		bx, 1					; Shift for WORD lookup
-	jmp		[cs:bx+.rgfnFormatParameter]
-
-ALIGN JUMP_ALIGN
-.a_FormatAttributeForNextCharacter:
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ALIGN JUMP_ALIGN
+a_FormatAttributeForNextCharacter:
 	mov		bl, [bp]
 	xchg	bl, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
-	call	.ReadCharacterAndTestForNull
-	jz		SHORT .Return
-	call	DisplayPrint_CharacterFromAL
+	push	bx
+	push	cx
+	push	di
+	call	DisplayFormat_ParseCharacters	; Recursive call
+	pop		WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
+	pop		cx
+	pop		bx
 	mov		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], bl
-	jmp		SHORT .UpdateSpacesToAppendAfterPrintingSingleCharacter
-
-ALIGN JUMP_ALIGN
-.A_FormatAttributeForRemainingString:
+	ret
+
+ALIGN JUMP_ALIGN
+A_FormatAttributeForRemainingString:
 	mov		al, [bp]
 	mov		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
-	jmp		SHORT .PrepareToFormatNextParameter
-
-ALIGN JUMP_ALIGN
-.d_FormatSignedDecimalWord:
-	mov		ax, [bp]
-	call	DisplayPrint_SignedDecimalIntegerFromAX
-	jmp		SHORT .UpdateSpacesToAppend
-
-ALIGN JUMP_ALIGN
-.u_FormatUnsignedDecimalWord:
+	ret
+
+ALIGN JUMP_ALIGN
+d_FormatSignedDecimalWord:
 	mov		ax, [bp]
 	mov		bx, 10
-	call	DisplayPrint_WordFromAXWithBaseInBX
-	jmp		SHORT .UpdateSpacesToAppend
-
-ALIGN JUMP_ALIGN
-.x_FormatHexadecimalWord:
+	jmp		DisplayPrint_SignedWordFromAXWithBaseInBX
+
+ALIGN JUMP_ALIGN
+u_FormatUnsignedDecimalWord:
+	mov		ax, [bp]
+	mov		bx, 10
+	jmp		DisplayPrint_WordFromAXWithBaseInBX
+
+ALIGN JUMP_ALIGN
+x_FormatHexadecimalWord:
 	mov		ax, [bp]
 	mov		bx, 16
 	call	DisplayPrint_WordFromAXWithBaseInBX
-	inc		bx					; Increment character count for 'h'
 	mov		al, 'h'
-	call	DisplayPrint_CharacterFromAL
-	jmp		SHORT .UpdateSpacesToAppend
-
-ALIGN JUMP_ALIGN
-.s_FormatStringFromSegmentCS:
+	jmp		DisplayPrint_CharacterFromAL
+
+ALIGN JUMP_ALIGN
+s_FormatStringFromSegmentCS:
 	xchg	si, [bp]
 	call	DisplayPrint_NullTerminatedStringFromCSSI
-	mov		si, [bp]			; Restore SI
-	jmp		SHORT .UpdateSpacesToAppend
-
-ALIGN JUMP_ALIGN
-.S_FormatStringFromFarPointer:
+	mov		si, [bp]
+	ret
+
+ALIGN JUMP_ALIGN
+S_FormatStringFromFarPointer:
+	mov		bx, [bp-2]
 	xchg	si, [bp]
-	mov		bx, [bp-2]
 	call	DisplayPrint_NullTerminatedStringFromBXSI
-	mov		si, [bp]			; Restore SI
-	jmp		SHORT .UpdateSpacesToAppendWithDWordParameter
-
-ALIGN JUMP_ALIGN
-.c_FormatCharacter:
+	mov		si, [bp]
+	dec		bp
+	dec		bp
+	ret
+
+ALIGN JUMP_ALIGN
+c_FormatCharacter:
 	mov		al, [bp]
-	jmp		SHORT .FormatSingleCharacterFromAL
-
-ALIGN JUMP_ALIGN
-.t_FormatRepeatCharacter:
+	jmp		DisplayPrint_CharacterFromAL
+
+ALIGN JUMP_ALIGN
+t_FormatRepeatCharacter:
+	push	cx
 	mov		cx, [bp-2]
-	mov		bx, cx
 	mov		al, [bp]
 	call	DisplayPrint_RepeatCharacterFromALwithCountInCX
-	jmp		SHORT .UpdateSpacesToAppendWithDWordParameter
-
-ALIGN JUMP_ALIGN
-.percent_FormatPercent:
+	pop		cx
+	dec		bp
+	dec		bp
+	ret
+
+ALIGN JUMP_ALIGN
+percent_FormatPercent:
 	mov		al, '%'
-	inc		bp					; Adjust here since...
-	inc		bp					; ...no parameter on stack
-	; Fall to .FormatSingleCharacterFromAL
-
-ALIGN JUMP_ALIGN
-.FormatSingleCharacterFromAL:
-	call	DisplayPrint_CharacterFromAL
-	jmp		.UpdateSpacesToAppendAfterPrintingSingleCharacter
-
-ALIGN JUMP_ALIGN
-.UpdateSpacesToAppendWithDWordParameter:
-	dec		bp
-	dec		bp
-	jmp		.UpdateSpacesToAppend
-
-
-; Table for converting format character to jump table index
-.rgcFormatCharToLookupIndex:
-	db		"aAduxsSct%"
-.EndOFrgcFormatCharToLookupIndex:
-
-; Jump table
-ALIGN WORD_ALIGN
-.rgfnFormatParameter:
-	dw		.a_FormatAttributeForNextCharacter
-	dw		.A_FormatAttributeForRemainingString
-	dw		.d_FormatSignedDecimalWord
-	dw		.u_FormatUnsignedDecimalWord
-	dw		.x_FormatHexadecimalWord
-	dw		.s_FormatStringFromSegmentCS
-	dw		.S_FormatStringFromFarPointer
-	dw		.c_FormatCharacter
-	dw		.t_FormatRepeatCharacter
-	dw		.percent_FormatPercent
+	jmp		DisplayPrint_CharacterFromAL
+
+ALIGN JUMP_ALIGN
+PrepareToPrependParameterWithSpaces:
+	neg		cx
+	; Fall to PrepareToAppendSpacesAfterParameter
+
+ALIGN JUMP_ALIGN
+PrepareToAppendSpacesAfterParameter:
+	add		sp, BYTE 2				; Remove return offset
+	jmp		ParseFormatSpecifier
Index: trunk/Assembly_Library/Src/Display/DisplayPrint.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayPrint.asm	(revision 43)
+++ trunk/Assembly_Library/Src/Display/DisplayPrint.asm	(revision 44)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	26.6.2010
-; Last update	:	18.9.2010
+; Last update	:	27.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for display output.
@@ -65,20 +65,19 @@
 
 ;--------------------------------------------------------------------
-; DisplayPrint_SignedDecimalIntegerFromAX
+; DisplayPrint_SignedWordFromAXWithBaseInBX
 ;	Parameters:
 ;		AX:		Word to display
-;		DS:		BDA segment (zero)
-;		ES:DI:	Ptr to cursor location in video RAM
-;	Returns:
-;		BX:		Number of characters printed
-;		DI:		Updated offset to video RAM
-;	Corrupts registers:
-;		AX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-DisplayPrint_SignedDecimalIntegerFromAX:
-	mov		bx, 10
-	test	ah, 1<<7			; Sign bit set?
-	jz		SHORT DisplayPrint_WordFromAXWithBaseInBX
+;		BX:		Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
+;		DS:		BDA segment (zero)
+;		ES:DI:	Ptr to cursor location in video RAM
+;	Returns:
+;		DI:		Updated offset to video RAM
+;	Corrupts registers:
+;		AX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+DisplayPrint_SignedWordFromAXWithBaseInBX:
+	test	ax, ax
+	jns		SHORT DisplayPrint_WordFromAXWithBaseInBX
 
 	push	ax
@@ -87,8 +86,5 @@
 	pop		ax
 	neg		ax
-	call	DisplayPrint_WordFromAXWithBaseInBX
-	inc		bx					; Increment character count for '-'
-	ret
-
+	; Fall to DisplayPrint_WordFromAXWithBaseInBX
 
 ;--------------------------------------------------------------------
@@ -100,5 +96,4 @@
 ;		ES:DI:	Ptr to cursor location in video RAM
 ;	Returns:
-;		BX:		Number of characters printed
 ;		DI:		Updated offset to video RAM
 ;	Corrupts registers:
@@ -108,4 +103,5 @@
 DisplayPrint_WordFromAXWithBaseInBX:
 	push	cx
+	push	bx
 
 	xor		cx, cx
@@ -118,13 +114,15 @@
 	test	ax, ax				; All divided?
 	jnz		SHORT .DivideLoop	;  If not, loop
-	mov		dx, cx				; Character count to DX
-ALIGN JUMP_ALIGN
-.PrintLoop:
-	pop		bx					; Pop digit
-	mov		al, [cs:bx+.rgcDigitToCharacter]
-	call	DisplayPrint_CharacterFromAL
-	loop	.PrintLoop
-	mov		bx, dx				; Return characters printed
-
+
+	mov		bx, .rgcDigitToCharacter
+ALIGN JUMP_ALIGN
+.PrintNextDigit:
+	pop		ax					; Pop digit
+	eSEG	cs
+	xlatb
+	call	DisplayPrint_CharacterFromAL
+	loop	.PrintNextDigit
+
+	pop		bx
 	pop		cx
 	ret
@@ -140,5 +138,4 @@
 ;		ES:DI:	Ptr to cursor location in video RAM
 ;	Returns:
-;		BX:		Number of characters printed
 ;		DI:		Updated offset to video RAM
 ;	Corrupts registers:
@@ -147,18 +144,20 @@
 ALIGN JUMP_ALIGN
 DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
-	push	cx
-
-	mov		es, bx					; Buffer now in ES:SI
-	xor		bx, bx					; Zero character counter
-	jcxz	.BufferPrinted
-ALIGN JUMP_ALIGN
-.CharacterOutputLoop:
-	mov		al, [es:bx+si]
-	inc		bx
-	call	LoadDisplaySegmentAndPrintCharacterFromAL
-	loop	.CharacterOutputLoop
-.BufferPrinted:
-	mov		es, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
-	pop		cx
+	jcxz	.NothingToPrintSinceZeroLength
+	push	si
+	push	cx
+
+ALIGN JUMP_ALIGN
+.PrintNextCharacter:
+	mov		ds, bx
+	lodsb
+	LOAD_BDA_SEGMENT_TO	ds, dx
+	call	DisplayPrint_CharacterFromAL
+	loop	.PrintNextCharacter
+
+	LOAD_BDA_SEGMENT_TO	ds, dx
+	pop		cx
+	pop		si
+.NothingToPrintSinceZeroLength:
 	ret
 
@@ -171,5 +170,4 @@
 ;		ES:DI:	Ptr to cursor location in video RAM
 ;	Returns:
-;		BX:		Number of characters printed
 ;		DI:		Updated offset to video RAM
 ;	Corrupts registers:
@@ -178,6 +176,10 @@
 ALIGN JUMP_ALIGN
 DisplayPrint_NullTerminatedStringFromCSSI:
+	push	bx
 	mov		bx, cs
-	; Fall to DisplayPrint_NullTerminatedStringFromBXSI
+	call	DisplayPrint_NullTerminatedStringFromBXSI
+	pop		bx
+	ret
+
 
 ;--------------------------------------------------------------------
@@ -188,5 +190,4 @@
 ;		ES:DI:	Ptr to cursor location in video RAM
 ;	Returns:
-;		BX:		Number of characters printed
 ;		DI:		Updated offset to video RAM
 ;	Corrupts registers:
@@ -195,56 +196,23 @@
 ALIGN JUMP_ALIGN
 DisplayPrint_NullTerminatedStringFromBXSI:
-	mov		es, bx					; String now in ES:SI
-	xor		bx, bx					; Zero character counter
-ALIGN JUMP_ALIGN
-.CharacterOutputLoop:
-	mov		al, [es:bx+si]
-	test	al, al
-	jz		SHORT .AllCharacterPrinted
-	inc		bx
-
-	call	LoadDisplaySegmentAndPrintCharacterFromAL
-	jmp		SHORT .CharacterOutputLoop
-ALIGN JUMP_ALIGN
-.AllCharacterPrinted:
-	mov		es, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
-	ret
-
-;--------------------------------------------------------------------
-; LoadDisplaySegmentAndPrintCharacterFromAL
-;	Parameters:
-;		AL:		Character to print
-;		DI:		Offset to cursor location in video RAM
-;		DS:		BDA segment (zero)
-;	Returns:
-;		DI:		Updated offset to video RAM
-;	Corrupts registers:
-;		AX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-LoadDisplaySegmentAndPrintCharacterFromAL:
-	push	es
-	mov		es, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
-	call	DisplayPrint_CharacterFromAL
-	pop		es
-	ret
-
-
-;--------------------------------------------------------------------
-; DisplayPrint_Newline
-;	Parameters:
-;		DS:		BDA segment (zero)
-;		ES:DI:	Ptr to cursor location in video RAM
-;	Returns:
-;		DI:		Updated offset to video RAM
-;	Corrupts registers:
-;		AX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-DisplayPrint_Newline:
-	mov		al, CR
-	call	DisplayPrint_CharacterFromAL
-	mov		al, LF
-	jmp		SHORT DisplayPrint_CharacterFromAL
+	push	si
+	push	cx
+
+	xor		cx, cx
+ALIGN JUMP_ALIGN
+.PrintNextCharacter:
+	mov		ds, bx				; String segment to DS
+	lodsb
+	mov		ds, cx				; BDA segment to DS
+	test	al, al				; NULL?
+	jz		SHORT .EndOfString
+	call	DisplayPrint_CharacterFromAL
+	jmp		SHORT .PrintNextCharacter
+
+ALIGN JUMP_ALIGN
+.EndOfString:
+	pop		cx
+	pop		si
+	ret
 
 
@@ -297,5 +265,5 @@
 .ClearRowLoop:
 	mov		cl, bl							; Area width now in CX
-	mov		al, ' '							; Clear with space
+	mov		al, SCREEN_BACKGROUND_CHARACTER
 	call	DisplayPrint_RepeatCharacterFromALwithCountInCX
 
@@ -327,9 +295,35 @@
 ALIGN JUMP_ALIGN
 DisplayPrint_RepeatCharacterFromALwithCountInCX:
+	jcxz	.NothingToRepeat
+	push	cx
+
+ALIGN JUMP_ALIGN
+.RepeatCharacter:
 	push	ax
 	call	DisplayPrint_CharacterFromAL
 	pop		ax
-	loop	DisplayPrint_RepeatCharacterFromALwithCountInCX
-	ret
+	loop	.RepeatCharacter
+
+	pop		cx
+.NothingToRepeat:
+	ret
+
+
+;--------------------------------------------------------------------
+; DisplayPrint_Newline
+;	Parameters:
+;		DS:		BDA segment (zero)
+;		ES:DI:	Ptr to cursor location in video RAM
+;	Returns:
+;		DI:		Updated offset to video RAM
+;	Corrupts registers:
+;		AX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+DisplayPrint_Newline:
+	mov		al, CR
+	call	DisplayPrint_CharacterFromAL
+	mov		al, LF
+	; Fall to DisplayPrint_CharacterFromAL
 
 
Index: trunk/Assembly_Library/Src/LibraryTests.asm
===================================================================
--- trunk/Assembly_Library/Src/LibraryTests.asm	(revision 43)
+++ trunk/Assembly_Library/Src/LibraryTests.asm	(revision 44)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	27.6.2010
-; Last update	:	15.9.2010
+; Last update	:	27.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Tests for Assembly Library.
@@ -254,6 +254,7 @@
 	mov		ax, si
 	CALL_DISPLAY_LIBRARY SetCharacterPointerFromBXAX
+	mov		dl, ATTRIBUTES_NOT_USED
 	mov		ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
-	CALL_DISPLAY_LIBRARY SetCharacterOutputFunctionFromAX
+	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInDL
 	lea		ax, [si+STRING_BUFFER_SIZE]
 	CALL_DISPLAY_LIBRARY SetCharacterOutputParameterFromAX
@@ -408,9 +409,10 @@
 	call	PrintHorizontalRuler
 	call	PrintVerticalRuler
+	
+	mov		al, COLOR_ATTRIBUTE(COLOR_BRIGHT_WHITE, COLOR_BLACK)
+	CALL_DISPLAY_LIBRARY SetCharacterAttributeFromAL
 
 	mov		ax, CURSOR_XY(0, 1)
 	CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
-	mov		al, COLOR_ATTRIBUTE(COLOR_BRIGHT_WHITE, COLOR_BLACK)
-	CALL_DISPLAY_LIBRARY SetCharacterAttributeFromAL
 	call	PrintFormattedStrings
 
@@ -494,5 +496,5 @@
 	ret
 .szIntegers:
-	db	"Integers -32768, -1, 0, 1, 65535:          %A|%6d|%6d|%6d|%6d|%6u|",LF,CR,NULL
+	db	"Integers -32768, -1, 0, 1, 65535:          %A|%6-d|%6-d|%6-d|%6-d|%6-u|",LF,CR,NULL
 
 .PrintHexadecimals:
@@ -508,5 +510,5 @@
 	ret
 .szHexadecimals:
-	db	"Hexadecimals CACAh, FFFFh, 0, 5A5Ah, A5A5h:%A|%6x|%6x|%6x|%6x|%6x|",LF,CR,NULL
+	db	"Hexadecimals CACAh, FFFFh, 0, 5A5Ah, A5A5h:%A|%6-x|%6-x|%6-x|%6-x|%6-x|",LF,CR,NULL
 
 .PrintCharacters:
Index: trunk/Assembly_Library/Src/Menu/Dialog/Dialog.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/Dialog.asm	(revision 43)
+++ trunk/Assembly_Library/Src/Menu/Dialog/Dialog.asm	(revision 44)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	6.8.2010
-; Last update	:	16.9.2010
+; Last update	:	27.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Common functions for many dialogs.
@@ -291,5 +291,5 @@
 ALIGN JUMP_ALIGN
 .RedrawDialogAreaAndWholeParentWindow:
-	mov		al, MONO_NORMAL
+	mov		al, SCREEN_BACKGROUND_ATTRIBUTE
 	CALL_DISPLAY_LIBRARY SetCharacterAttributeFromAL
 	call	MenuLocation_GetTitleBordersTopLeftCoordinatesToAX
Index: trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 43)
+++ trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 44)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	6.9.2010
-; Last update	:	16.9.2010
+; Last update	:	27.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Displays file dialog.
@@ -148,5 +148,5 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, CX, SI, DI, DS, ES
+;		AX, CX, DX, SI, DI, DS, ES
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -171,5 +171,5 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, CX, DI
+;		AX, CX, DX, DI
 ;--------------------------------------------------------------------
 ;ALIGN JUMP_ALIGN
@@ -225,5 +225,5 @@
 ;		DI:		Updated for next file
 ;	Corrupts registers:
-;		AX, BX, CX
+;		AX, BX, CX, DX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -241,5 +241,5 @@
 ;		DI:		Updated for next file
 ;	Corrupts registers:
-;		AX, BX, CX
+;		AX, BX, CX, DX
 ;--------------------------------------------------------------------
 ;ALIGN JUMP_ALIGN
@@ -253,6 +253,7 @@
 	xchg	ax, cx
 	CALL_DISPLAY_LIBRARY SetCharacterPointerFromBXAX
+	mov		dl, ATTRIBUTES_NOT_USED
 	mov		ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
-	CALL_DISPLAY_LIBRARY SetCharacterOutputFunctionFromAX
+	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInDL
 
 	call	.FormatFileOrDirectoryToBufferFromDTAinDSSI
Index: trunk/Assembly_Library/Src/Menu/Dialog/StringsForDialogs.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/StringsForDialogs.asm	(revision 43)
+++ trunk/Assembly_Library/Src/Menu/Dialog/StringsForDialogs.asm	(revision 44)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	14.9.2010
-; Last update	:	16.9.2010
+; Last update	:	27.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Strings used by dialogs.
@@ -9,5 +9,5 @@
 g_szTimeElapsed:		db	"Time elapsed  :",NULL
 g_szTimeLeft:			db	"Estimated left:",NULL
-g_szTimeFormat:			db	" %2u min %2u sec",LF,CR,NULL
+g_szTimeFormat:			db	" %2-u min %2-u sec",LF,CR,NULL
 
 ; Strings for File Dialog
@@ -23,5 +23,5 @@
 
 g_szFileFormat:
-	db		"%14S  %4u %c%cB",LF,NULL
+	db		"%14S  %4-u %c%cB",LF,NULL
 g_szDirectoryFormat:
 	db		"[%12S]  %s-DIR",LF,NULL
Index: trunk/Assembly_Library/Src/Menu/MenuBorders.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuBorders.asm	(revision 43)
+++ trunk/Assembly_Library/Src/Menu/MenuBorders.asm	(revision 44)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	14.7.2010
-; Last update	:	7.9.2010
+; Last update	:	27.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for drawing menu borders.
@@ -45,10 +45,11 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, SI, DI
+;		AX, DX, SI, DI
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 MenuBorders_AdjustDisplayContextForDrawingBorders:
+	mov		dl, ATTRIBUTES_ARE_USED
 	mov		ax, MenuCharOut_MenuBorderTeletypeOutputWithAttribute
-	CALL_DISPLAY_LIBRARY SetCharacterOutputFunctionFromAX
+	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInDL
 
 	mov		ax, bp
@@ -268,6 +269,9 @@
 	call	MenuAttribute_SetToDisplayContextFromTypeInSI
 
+	push	dx
+	mov		dl, ATTRIBUTES_ARE_USED
 	mov		ax, FAST_OUTPUT_WITH_ATTRIBUTE_ONLY
-	CALL_DISPLAY_LIBRARY SetCharacterOutputFunctionFromAX
+	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInDL
+	pop		dx
 
 	call	PrintMultipleBorderCharactersFromAL	; AL does not matter
Index: trunk/Assembly_Library/Src/Menu/MenuText.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuText.asm	(revision 43)
+++ trunk/Assembly_Library/Src/Menu/MenuText.asm	(revision 44)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	21.7.2010
-; Last update	:	11.8.2010
+; Last update	:	27.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for drawing menu texts by the user.
@@ -218,10 +218,11 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, SI, DI
+;		AX, DX, SI, DI
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 AdjustDisplayContextForDrawingTexts:
+	mov		dl, ATTRIBUTES_ARE_USED
 	mov		ax, MenuCharOut_MenuTextTeletypeOutputWithAttribute
-	CALL_DISPLAY_LIBRARY SetCharacterOutputFunctionFromAX
+	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInDL
 
 	mov		ax, bp
Index: trunk/Assembly_Library/Src/Menu/MenuTime.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuTime.asm	(revision 43)
+++ trunk/Assembly_Library/Src/Menu/MenuTime.asm	(revision 44)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	25.7.2010
-; Last update	:	13.8.2010
+; Last update	:	27.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Menu timeouts other time related functions.
@@ -141,9 +141,9 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, DX, SI, DI
+;		AX, CX, DX, SI, DI
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 DrawTimeoutInAXoverMenuBorders:
-	xchg	dx, ax
+	xchg	cx, ax
 	call	MenuBorders_AdjustDisplayContextForDrawingBorders
 	call	MenuLocation_GetBottomBordersTopLeftCoordinatesToAX
@@ -154,5 +154,5 @@
 ; .PrintTimeoutStringWithSecondsInDX
 ;	Parameters
-;		DX:		Seconds to print
+;		CX:		Seconds to print
 ;		SS:BP:	Ptr to MENU
 ;	Returns:
@@ -166,8 +166,8 @@
 
 	mov		bp, sp
-	call	.GetTimeoutAttributeToAXfromSecondsInDX
+	call	.GetTimeoutAttributeToAXfromSecondsInCX
 	mov		si, .szSelectionTimeout
 	push	ax			; Push attribute
-	push	dx			; Push seconds
+	push	cx			; Push seconds
 	CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
 	pop		bp
@@ -178,20 +178,20 @@
 	db		DOUBLE_BOTTOM_LEFT_CORNER
 	db		DOUBLE_LEFT_HORIZONTAL_TO_SINGLE_VERTICAL
-	db		"%AAutoselection in %2ds",NULL
-
-;--------------------------------------------------------------------
-; .GetTimeoutAttributeToAXfromSecondsInDX
-;	Parameters
-;		DX:		Seconds to print
+	db		"%AAutoselection in %2-ds",NULL
+
+;--------------------------------------------------------------------
+; .GetTimeoutAttributeToAXfromSecondsInCX
+;	Parameters
+;		CX:		Seconds to print
 ;	Returns:
 ;		AX:		Attribute byte for seconds
-;		DX:		Seconds to print
+;		CX:		Seconds to print
 ;	Corrupts registers:
 ;		SI, DI
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-.GetTimeoutAttributeToAXfromSecondsInDX:
+.GetTimeoutAttributeToAXfromSecondsInCX:
 	mov		si, ATTRIBUTE_CHARS.cNormalTimeout
-	cmp		dx, BYTE 3
+	cmp		cx, BYTE 3
 	ja		SHORT .GetAttributeToAX
 	add		si, BYTE ATTRIBUTE_CHARS.cHurryTimeout - ATTRIBUTE_CHARS.cNormalTimeout
