Index: trunk/Assembly_Library/Src/Menu/MenuCharOut.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuCharOut.asm	(revision 41)
+++ trunk/Assembly_Library/Src/Menu/MenuCharOut.asm	(revision 48)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	15.7.2010
-; Last update	:	4.8.2010
+; Last update	:	8.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Character out function for printing withing menu window.
@@ -29,5 +29,5 @@
 ALIGN JUMP_ALIGN
 .PrintCRandAdjustColumnToMenuBorders:
-	call	DisplayCharOut_TeletypeOutputWithAttribute
+	call	DisplayCharOut_BiosTeletypeOutput
 	xor		ax, ax					; No offset, cursor to start of border
 	jmp		SHORT SetCursorToNextMenuLine
@@ -35,4 +35,5 @@
 
 ;--------------------------------------------------------------------
+; MenuCharOut_MenuTextTeletypeOutputWithAttributeAndAutomaticLineChange
 ; MenuCharOut_MenuTextTeletypeOutputWithAttribute
 ;	Parameters:
@@ -47,12 +48,139 @@
 ;--------------------------------------------------------------------
 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
+	; Fall to MenuCharOut_MenuTextTeletypeOutputWithAttribute
+
+ALIGN JUMP_ALIGN
 MenuCharOut_MenuTextTeletypeOutputWithAttribute:
 	cmp		al, CR						; Carriage return?
-	je		SHORT .PrintCRandAdjustColumnToMenuText
+	je		SHORT PrintCRfromALandAdjustColumnToMenuText
 	jmp		DisplayCharOut_TeletypeOutputWithAttribute
 
-ALIGN JUMP_ALIGN
-.PrintCRandAdjustColumnToMenuText:
-	call	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, ' '
+	je		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
+;	Parameters:
+;		DS:		BDA segment (zero)
+;		ES:DI:	Ptr to cursor location
+;	Returns:
+;		ES:DI:	Ptr to beginning of new line
+;	Corrupts registers:
+;		AX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.MoveCursorInDItoBeginningOfNextLine:
+	mov		al, LF
+	call	DisplayCharOut_BiosTeletypeOutput
+	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
