Index: trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 52)
+++ trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 53)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	6.9.2010
-; Last update	:	12.10.2010
+; Last update	:	13.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Displays file dialog.
@@ -74,4 +74,19 @@
 	loop	.InfoLineLoop
 	stc						; Event processed
+	ret
+
+
+ALIGN JUMP_ALIGN
+.RefreshItemFromCX:
+	call	LoadItemStringBufferToESDI
+	mov		ax, FILE_STRING_LENGTH
+	xchg	ax, cx
+	mul		cx
+	add		di, ax
+	mov		si, di
+	mov		bx, es
+	dec		cx				; Do not print LF at the end of file string
+	CALL_DISPLAY_LIBRARY PrintCharBufferFromBXSIwithLengthInCX
+	stc
 	ret
 
@@ -93,5 +108,5 @@
 	at	MENUEVENT.RefreshTitle,					dw	Dialog_EventRefreshTitle
 	at	MENUEVENT.RefreshInformation,			dw	.RefreshInformation
-	at	MENUEVENT.RefreshItemFromCX,			dw	Dialog_EventRefreshItemFromCX
+	at	MENUEVENT.RefreshItemFromCX,			dw	.RefreshItemFromCX
 iend
 
@@ -113,4 +128,5 @@
 	call	LoadItemStringBufferToESDI
 	call	SortDirectoryContentsStringFromESDIwithCountInCX
+	call	RemoveLastLFandTerminateESDIwithNull
 	call	Memory_CopySSBPtoDSSI
 	xor		ax, ax
@@ -148,37 +164,25 @@
 ;		CX:		Number of files or directories found
 ;	Corrupts registers:
-;		AX, DX, SI, DI, DS, ES
+;		AX, BX, DX, SI, DI, DS
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 CreateStringFromCurrentDirectoryContentsToESDI:
+	mov		bx, di
+	CALL_DISPLAY_LIBRARY PushDisplayContext
+	mov		cx, -1
+	CALL_DISPLAY_LIBRARY PrepareOffScreenBufferInESBXwithLengthInCX	; ES:DI now points to buffer
+
 	lds		si, [bp+DIALOG.fpDialogIO]
 	eMOVZX	cx, BYTE [si+FILE_DIALOG_IO.bFileAttributes]
 	lds		si, [si+FILE_DIALOG_IO.fpFileFilterString]
 	call	Directory_UpdateDTAForFirstMatchForDSSIwithAttributesInCX
-	rcr		cx, 1			; Store CF
+
 	call	.ClearDLifInRootDirectory
 	call	Directory_GetDiskTransferAreaAddressToDSSI
-	rcl		cx, 1			; Restore CF
 	xor		cx, cx			; Clear file/directory count
-	; Fall to .FindMatchingFilesAndWriteThemToESDI
-
-;--------------------------------------------------------------------
-; .FindMatchingFilesAndWriteThemToESDI
-;	Parameters:
-;		CX:		Initial directory count
-;		DL:		Zero if root directory selected
-;		DS:SI:	Ptr to DTA with first matching file
-;		ES:DI:	Ptr to destination string buffer
-;	Returns:
-;		CX:		Incremented by number of files/directories found
-;	Corrupts registers:
-;		AX, DX, DI
-;--------------------------------------------------------------------
-;ALIGN JUMP_ALIGN
-.FindMatchingFilesAndWriteThemToESDI:
-	jc		SHORT TerminateESDIwithNull
-	call	AppendFileToBufferInESDIfromDtaInDSSI
-	call	Directory_UpdateDTAForNextMatchUsingPreviousParameters
-	jmp		SHORT .FindMatchingFilesAndWriteThemToESDI
+	call	.FindMatchingFilesAndPrintThemToOffScreenBuffer
+
+	CALL_DISPLAY_LIBRARY PopDisplayContext
+	ret
 
 ;--------------------------------------------------------------------
@@ -200,70 +204,79 @@
 	ret
 
-
-;--------------------------------------------------------------------
-; TerminateESDIwithNull
-;	Parameters:
-;		ES:DI:	Ptr to destination string buffer
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-TerminateESDIwithNull:
-	xor		ax, ax
-	stosb
-	ret
-
-
-;--------------------------------------------------------------------
-; AppendFileToBufferInESDIfromDtaInDSSI
+;--------------------------------------------------------------------
+; .FindMatchingFilesAndPrintThemToOffScreenBuffer
+;	Parameters:
+;		CX:		Initial directory count
+;		DL:		Zero if root directory selected
+;		DS:SI:	Ptr to DTA with first matching file
+;	Returns:
+;		CX:		Incremented by number of files/directories found
+;	Corrupts registers:
+;		AX, BX, DX, DI, DS
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.FindMatchingFilesAndPrintThemToOffScreenBuffer:
+	call	AppendFileFromDTAinDSSItoOffScreenBuffer
+	call	Directory_UpdateDTAForNextMatchUsingPreviousParameters
+	jnc		SHORT .FindMatchingFilesAndPrintThemToOffScreenBuffer
+	ret
+
+
+;--------------------------------------------------------------------
+; AppendFileFromDTAinDSSItoOffScreenBuffer
 ;	Parameters:
 ;		CX:		Files/directores found
 ;		DL:		Zero if root directory selected
 ;		DS:SI:	Ptr to DTA containing file information
-;		ES:DI:	Ptr to destination string buffer
 ;	Returns:
 ;		CX:		Incremented by number of files/directories found
-;		DI:		Updated for next file
-;	Corrupts registers:
-;		AX, BX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-AppendFileToBufferInESDIfromDtaInDSSI:
+;	Corrupts registers:
+;		AX, BX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+AppendFileFromDTAinDSSItoOffScreenBuffer:
 	call	.FilterCurrentDirectory			; We never want "."
 	call	.FilterUpDirectoryWhenInRoot	; No ".." when in root directory
 	inc		cx								; Nothing filtered so increment files/directories
-	; Fall to .PrepareBufferFormattingAndFormatFromDTAinDSSI
-
-;--------------------------------------------------------------------
-; .PrepareBufferFormattingAndFormatFromDTAinDSSI
-;	Parameters:
-;		DS:SI:	Ptr to DTA containing file information
-;		ES:DI:	Ptr to destination string buffer
-;	Returns:
-;		DI:		Updated for next file
-;	Corrupts registers:
-;		AX, BX, DX
-;--------------------------------------------------------------------
-;ALIGN JUMP_ALIGN
-.PrepareBufferFormattingAndFormatFromDTAinDSSI:
+
 	push	bp
 	push	si
+	push	dx
 	push	cx
-	mov		bx, di
-	CALL_DISPLAY_LIBRARY PushDisplayContext
-	mov		cx, -1
-	CALL_DISPLAY_LIBRARY PrepareOffScreenBufferInESBXwithLengthInCX
-
 	call	.FormatFileOrDirectoryToBufferFromDTAinDSSI
-
-	CALL_DISPLAY_LIBRARY GetCharacterPointerToBXAX
-	xchg	bx, ax
-	CALL_DISPLAY_LIBRARY PopDisplayContext
-	mov		di, bx
 	pop		cx
+	pop		dx
 	pop		si
 	pop		bp
+	ret
+
+;--------------------------------------------------------------------
+; .FilterCurrentDirectory
+; .FilterUpDirectoryWhenInRoot
+;	Parameters:
+;		DL:		Zero if root directory selected
+;		DS:SI:	Ptr to DTA containing file information
+;	Returns:
+;		Nothing
+;		Returns from AppendFileToBufferInESDIfromDtaInDSSI when filtering
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.FilterCurrentDirectory:
+	cmp		WORD [si+DTA.szFile], CURRENTDIR_CHARACTERS
+	jne		SHORT .ReturnWithoutFiltering
+	add		sp, BYTE 2		; Remove return address from stack
+	ret
+
+ALIGN JUMP_ALIGN
+.FilterUpDirectoryWhenInRoot:
+	test	dl, dl			; Set ZF if root directory selected
+	jnz		SHORT .ReturnWithoutFiltering
+	cmp		WORD [si+DTA.szFile], UPDIR_CHARACTERS
+	jne		SHORT .ReturnWithoutFiltering
+	add		sp, BYTE 2		; Remove return address from stack
+ALIGN JUMP_ALIGN, ret
+.ReturnWithoutFiltering:
 	ret
 
@@ -295,16 +308,14 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, BX, CX, DX, SI, DI, BP
+;		AX, BX, CX, DX, SI, DI
 ;--------------------------------------------------------------------
 .FormatFile:
-	; Convert file name to lower case
 	xchg	si, ax
-	mov		dx, StringProcess_ConvertToLowerCase
-	call	StringProcess_DSSIwithFunctionInDX
+	call	String_ConvertDSSItoLowerCase
 	xchg	ax, si
 
 	; Push parameters for file name
-	push	ax				; Push directory name offset
-	push	ds				; Push directory name segment
+	push	ax				; Push file name offset
+	push	ds				; Push file name segment
 
 	; Push parameters for file size
@@ -334,5 +345,5 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, BX, CX, DX, SI, DI, BP
+;		AX, SI, DI
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -350,34 +361,4 @@
 	ret
 
-;--------------------------------------------------------------------
-; .FilterCurrentDirectory
-; .FilterUpDirectoryWhenInRoot
-;	Parameters:
-;		DL:		Zero if root directory selected
-;		DS:SI:	Ptr to DTA containing file information
-;	Returns:
-;		Nothing
-;		Returns from AppendFileToBufferInESDIfromDtaInDSSI when filtering
-;	Corrupts registers:
-;		AX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.FilterCurrentDirectory:
-	cmp		WORD [si+DTA.szFile], CURRENTDIR_CHARACTERS
-	jne		SHORT .ReturnWithoutFiltering
-	add		sp, BYTE 2		; Remove return address from stack
-	ret
-
-ALIGN JUMP_ALIGN
-.FilterUpDirectoryWhenInRoot:
-	test	dl, dl			; Set ZF if root directory selected
-	jnz		SHORT .ReturnWithoutFiltering
-	cmp		WORD [si+DTA.szFile], UPDIR_CHARACTERS
-	jne		SHORT .ReturnWithoutFiltering
-	add		sp, BYTE 2		; Remove return address from stack
-ALIGN JUMP_ALIGN, ret
-.ReturnWithoutFiltering:
-	ret
-
 
 ;--------------------------------------------------------------------
@@ -388,15 +369,23 @@
 ;		SS:BP:	Ptr to DIALOG
 ;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, BX, CX, DX, SI, DI, DS, ES
+;		ES:DI:	Ptr to end of directory contents string
+;	Corrupts registers:
+;		AX, BX, CX, DX, SI, DS
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 SortDirectoryContentsStringFromESDIwithCountInCX:
-	call	Memory_ExchangeDSSIwithESDI
+	call	Memory_CopyESDItoDSSI
+	call	.AddDirectoryContentsStringLengthToDI
 	mov		bx, .FileStringComparator
 	xchg	dx, cx
 	mov		cx, FILE_STRING_LENGTH
 	jmp		Sort_ItemsFromDSSIwithCountInDXsizeInCXandComparatorInBX
+
+ALIGN JUMP_ALIGN
+.AddDirectoryContentsStringLengthToDI:
+	mov		ax, FILE_STRING_LENGTH
+	mul		cx
+	add		di, ax
+	ret
 
 ;--------------------------------------------------------------------
@@ -739,5 +728,5 @@
 	or		bx, cx
 	jnz		SHORT .BitShiftLoop
-	jmp		TerminateESDIwithNull
+	jmp		SHORT TerminateESDIwithNull
 
 ;--------------------------------------------------------------------
@@ -769,4 +758,24 @@
 
 ;--------------------------------------------------------------------
+; RemoveLastLFandTerminateESDIwithNull
+; TerminateESDIwithNull
+;	Parameters:
+;		ES:DI:	Ptr to end of buffer to terminate
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+RemoveLastLFandTerminateESDIwithNull:
+	dec		di
+ALIGN JUMP_ALIGN
+TerminateESDIwithNull:
+	xor		ax, ax
+	stosb
+	ret
+
+
+;--------------------------------------------------------------------
 ; InitializeNullStringsToDialogInputInDSSI
 ;	Parameters:
Index: trunk/Assembly_Library/Src/String/String.asm
===================================================================
--- trunk/Assembly_Library/Src/String/String.asm	(revision 52)
+++ trunk/Assembly_Library/Src/String/String.asm	(revision 53)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	12.7.2010
-; Last update	:	12.10.2010
+; Last update	:	13.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for handling characters.
@@ -8,4 +8,27 @@
 ; Section containing code
 SECTION .text
+
+;--------------------------------------------------------------------
+; String_ConvertDSSItoLowerCase
+;	Parameters:
+;		DS:SI:	Ptr to string to convert
+;	Returns:
+;		CX:		Number of characters processed
+;		SI:		Updated
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+String_ConvertDSSItoLowerCase:
+	push	dx
+	push	ax
+
+	mov		dx, StringProcess_ConvertToLowerCase
+	call	StringProcess_DSSIwithFunctionInDX
+
+	pop		ax
+	pop		dx
+	ret
+
 
 ;--------------------------------------------------------------------
@@ -16,4 +39,5 @@
 ;	Returns:
 ;		AX:		Word converted from string
+;		CX:		Number of characters processed
 ;		SI:		Updated
 ;		CF:		Cleared if successfull
@@ -38,5 +62,5 @@
 
 ;--------------------------------------------------------------------
-; String_CopyDSSItoESDIandGetSizeToCX
+; String_CopyDSSItoESDIandGetLengthToCX
 ;	Parameters:
 ;		DS:SI:	Ptr to source NULL terminated string
@@ -49,5 +73,5 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-String_CopyDSSItoESDIandGetSizeToCX:
+String_CopyDSSItoESDIandGetLengthToCX:
 	push	ax
 
