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
