Index: trunk/Assembly_Library/Inc/AssemblyLibrary.inc
===================================================================
--- trunk/Assembly_Library/Inc/AssemblyLibrary.inc	(revision 49)
+++ trunk/Assembly_Library/Inc/AssemblyLibrary.inc	(revision 50)
@@ -15,4 +15,5 @@
 %include "Debug.inc"
 %include "DosFunctions.inc"
+%include "File.inc"
 %include "Math.inc"
 
Index: trunk/Assembly_Library/Inc/Display.inc
===================================================================
--- trunk/Assembly_Library/Inc/Display.inc	(revision 49)
+++ trunk/Assembly_Library/Inc/Display.inc	(revision 50)
@@ -2,5 +2,5 @@
 ; Project name	:	AssemblyLibrary
 ; Created date	:	25.6.2010
-; Last update	:	6.10.2010
+; Last update	:	9.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Defines for display library.
@@ -110,4 +110,5 @@
 ; Display context flags
 FLG_CONTEXT_ATTRIBUTES		EQU		(1<<0)	; Character output function uses attributes
+FLG_CONTEXT_CGA				EQU		(1<<1)	; CGA detected so prevent CGA snow
 
 
Index: trunk/Assembly_Library/Inc/DosFunctions.inc
===================================================================
--- trunk/Assembly_Library/Inc/DosFunctions.inc	(revision 49)
+++ trunk/Assembly_Library/Inc/DosFunctions.inc	(revision 50)
@@ -2,5 +2,5 @@
 ; Project name	:	AssemblyLibrary
 ; Created date	:	1.9.2010
-; Last update	:	3.9.2010
+; Last update	:	8.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Defines for MS-DOS functions.
@@ -30,13 +30,4 @@
 ; DOS errors
 ERR_DOS_DRIVE_NOT_READY								EQU		15h
-
-
-; File attribute flags
-FLG_FILEATTR_READ_ONLY			EQU		(1<<0)
-FLG_FILEATTR_HIDDEN				EQU		(1<<1)
-FLG_FILEATTR_SYSTEM				EQU		(1<<2)
-FLG_FILEATTR_VOLUME_LABEL		EQU		(1<<3)
-FLG_FILEATTR_DIRECTORY			EQU		(1<<4)
-FLG_FILEATTR_ARCHIVE			EQU		(1<<5)
 
 
Index: trunk/Assembly_Library/Inc/Emulate.inc
===================================================================
--- trunk/Assembly_Library/Inc/Emulate.inc	(revision 49)
+++ trunk/Assembly_Library/Inc/Emulate.inc	(revision 50)
@@ -2,5 +2,5 @@
 ; Project name	:	Emulation library
 ; Created date	:	21.10.2009
-; Last update	:	29.7.2010
+; Last update	:	9.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Macros for emulating later x86 instruction with older
@@ -318,6 +318,4 @@
 	sub		sp, %1
 	mov		bp, sp
-	;eENTER	%1, 0
-	;sub		bp, %1			; SS:BP now points to struct
 %endmacro
 
@@ -334,6 +332,4 @@
 	add		sp, %1
 	pop		bp
-	;add		bp, %1			; Restore BP to what it was after eENTER
-	;eLEAVE
 %endmacro
 
Index: trunk/Assembly_Library/Inc/File.inc
===================================================================
--- trunk/Assembly_Library/Inc/File.inc	(revision 50)
+++ trunk/Assembly_Library/Inc/File.inc	(revision 50)
@@ -0,0 +1,33 @@
+; File name		:	File.inc
+; Project name	:	Assembly Library
+; Created date	:	8.10.2010
+; Last update	:	8.10.2010
+; Author		:	Tomi Tilli
+; Description	:	File library defines.
+%ifndef FILE_INC
+%define FILE_INC
+
+; File access and sharing modes
+struc FILE_ACCESS
+	.ReadOnly		resb	1
+	.WriteOnly		resb	1
+	.ReadAndWrite	resb	1
+endstruc
+
+; Origin of file seek
+struc SEEK_FROM
+	.startOfFile			resb	1
+	.currentFilePosition	resb	1
+	.endOfFile				resb	1
+endstruc
+
+; File attribute flags
+FLG_FILEATTR_READ_ONLY			EQU		(1<<0)
+FLG_FILEATTR_HIDDEN				EQU		(1<<1)
+FLG_FILEATTR_SYSTEM				EQU		(1<<2)
+FLG_FILEATTR_VOLUME_LABEL		EQU		(1<<3)
+FLG_FILEATTR_DIRECTORY			EQU		(1<<4)
+FLG_FILEATTR_ARCHIVE			EQU		(1<<5)
+
+
+%endif ; FILE_INC
Index: trunk/Assembly_Library/Src/Display/CgaSnow.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/CgaSnow.asm	(revision 49)
+++ trunk/Assembly_Library/Src/Display/CgaSnow.asm	(revision 50)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	8.10.2010
-; Last update	:	8.10.2010
+; Last update	:	9.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for preventing CGA snow.
@@ -8,4 +8,28 @@
 ; Section containing code
 SECTION .text
+
+;--------------------------------------------------------------------
+; CgaSnow_IsCgaPresent
+;	Parameters:
+;		DS:		BDA segment (zero)
+;	Returns:
+;		CF:		Set if CGA detected
+;				Cleared if CGA not detected
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+CgaSnow_IsCgaPresent:
+	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
+	stc
+	ret
+ALIGN JUMP_ALIGN
+.CgaNotFound:
+	clc
+	ret
 
 
@@ -29,6 +53,6 @@
 ALIGN JUMP_ALIGN
 CgaSnow_Stosb:
-	call	LoadAndVerifyStatusRegisterFromBDA
-	jne		SHORT .StosbWithoutWaitSinceUnknownPort
+	call	LoadCgaStatusRegisterAddressToDXifCgaPresent
+	jz		SHORT .StosbWithoutWaitSinceUnknownPort
 
 	mov		ah, al
@@ -44,6 +68,6 @@
 CgaSnow_Stosw:
 	push	bx
-	call	LoadAndVerifyStatusRegisterFromBDA
-	jne		SHORT .StoswWithoutWaitSinceUnknownPort
+	call	LoadCgaStatusRegisterAddressToDXifCgaPresent
+	jz		SHORT .StoswWithoutWaitSinceUnknownPort
 
 	xchg	bx, ax
@@ -71,6 +95,6 @@
 ALIGN JUMP_ALIGN
 CgaSnow_Scasb:
-	call	LoadAndVerifyStatusRegisterFromBDA
-	jne		SHORT .ScasbWithoutWaitSinceUnknownPort
+	call	LoadCgaStatusRegisterAddressToDXifCgaPresent
+	jz		SHORT .ScasbWithoutWaitSinceUnknownPort
 
 	mov		ah, al
@@ -98,6 +122,6 @@
 ALIGN JUMP_ALIGN
 CgaSnow_RepMovsb:
-	call	LoadAndVerifyStatusRegisterFromBDA
-	jne		SHORT .RepMovsbWithoutWaitSinceUnknownPort
+	call	LoadCgaStatusRegisterAddressToDXifCgaPresent
+	jz		SHORT .RepMovsbWithoutWaitSinceUnknownPort
 
 .MovsbNextByte:
@@ -115,30 +139,21 @@
 
 ;--------------------------------------------------------------------
-; LoadAndVerifyStatusRegisterFromBDA
+; LoadCgaStatusRegisterAddressToDXifCgaPresent
 ;	Parameters:
 ;		DS:		BDA segment (zero)
 ;	Returns:
 ;		DX:		CGA Status Register Address
-;		ZF:		Set if CGA Base Port found in BDA
+;		ZF:		Set if CGA not present
+;				Cleared if CGA present
 ;	Corrupts registers:
 ;		Nothing
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-LoadAndVerifyStatusRegisterFromBDA:
-	mov		dx, [BDA.wVidPort]
-	add		dl, OFFSET_TO_CGA_STATUS_REGISTER
-	cmp		dx, CGA_STATUS_REGISTER
-	je		SHORT .CheckIfEgaOrLater
-	ret
-
-ALIGN JUMP_ALIGN
-.CheckIfEgaOrLater:
-	push	ax
-	call	DisplayPage_GetColumnsToALandRowsToAH
-	cmp		ah, [BDA.bVidRows]		; Video rows stored only by EGA and later
-	lahf
-	xor		ah, 1<<6				; Invert ZF
-	sahf
-	pop		ax
+LoadCgaStatusRegisterAddressToDXifCgaPresent:
+	test	BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_CGA
+	jz		SHORT .NoCgaDetected
+	mov		dx, CGA_STATUS_REGISTER
+ALIGN JUMP_ALIGN, ret
+.NoCgaDetected:
 	ret
 
Index: trunk/Assembly_Library/Src/Display/DisplayContext.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayContext.asm	(revision 49)
+++ trunk/Assembly_Library/Src/Display/DisplayContext.asm	(revision 50)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	25.6.2010
-; Last update	:	5.10.2010
+; Last update	:	9.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for managing display context.
@@ -20,13 +20,11 @@
 ALIGN JUMP_ALIGN
 DisplayContext_Initialize:
-	call	.DetectAndSetDisplaySegment
+	call	.DetectAndSetDisplaySegment	; and .InitializeFlags
 	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], SCREEN_BACKGROUND_ATTRIBUTE
-	mov		BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
-
 	xor		ax, ax
 	call	DisplayCursor_SetCoordinatesFromAX
-	jmp		SHORT DisplayContext_SynchronizeToHardware
+	jmp		DisplayContext_SynchronizeToHardware
 
 ;--------------------------------------------------------------------
@@ -37,12 +35,31 @@
 ;		Nothing
 ;	Corrupts registers:
-;		Nothing
+;		AX, DX
 ;--------------------------------------------------------------------
 .DetectAndSetDisplaySegment:
-	mov		WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], COLOR_TEXT_SEGMENT
+	mov		ax, COLOR_TEXT_SEGMENT
 	cmp		BYTE [VIDEO_BDA.bMode], MDA_TEXT_MODE
-	jne		SHORT .Return
-	sub		WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], COLOR_TEXT_SEGMENT - MONO_TEXT_SEGMENT
-.Return:
+	jne		SHORT .StoreSegmentToDisplayContext
+	mov		ax, MONO_TEXT_SEGMENT
+.StoreSegmentToDisplayContext:
+	mov		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], ax
+	; Fall to InitializeFlags
+
+;--------------------------------------------------------------------
+; .InitializeFlags
+;	Parameters:
+;		DS:		BDA segment (zero)
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, DX
+;--------------------------------------------------------------------
+.InitializeFlags:
+	mov		dl, FLG_CONTEXT_ATTRIBUTES
+	call	CgaSnow_IsCgaPresent
+	jnc		SHORT .DoNotSetCgaFlag
+	or		dl, FLG_CONTEXT_CGA
+.DoNotSetCgaFlag:
+	mov		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], dl
 	ret
 
@@ -188,10 +205,12 @@
 ;		Nothing
 ;	Corrupts registers:
-;		Nothing
+;		BL
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
+	and		bl, FLG_CONTEXT_ATTRIBUTES
+	and		BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES
+	or		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
 	mov		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
-	mov		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
 	ret
 
Index: trunk/Assembly_Library/Src/File/FileIO.asm
===================================================================
--- trunk/Assembly_Library/Src/File/FileIO.asm	(revision 49)
+++ trunk/Assembly_Library/Src/File/FileIO.asm	(revision 50)
@@ -2,23 +2,7 @@
 ; Project name	:	Assembly Library
 ; Created date	:	1.9.2010
-; Last update	:	3.9.2010
+; Last update	:	8.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for file access.
-
-
-; File access and sharing modes
-struc FILE_ACCESS
-	.ReadOnly		resb	1
-	.WriteOnly		resb	1
-	.ReadAndWrite	resb	1
-endstruc
-
-; Origin of file seek
-struc SEEK_FROM
-	.startOfFile			resb	1
-	.currentFilePosition	resb	1
-	.endOfFile				resb	1
-endstruc
-
 
 ; Section containing code
Index: trunk/Assembly_Library/Src/LibraryTests.asm
===================================================================
--- trunk/Assembly_Library/Src/LibraryTests.asm	(revision 49)
+++ trunk/Assembly_Library/Src/LibraryTests.asm	(revision 50)
@@ -224,10 +224,9 @@
 .AskFileFromUser:
 	mov		si, g_dialogInputOutput
-	mov		WORD [si+DIALOG_INPUT.fszItems], g_szBuffer
+	mov		WORD [si+FILE_DIALOG_IO.fszItemBuffer], g_szBuffer
 	mov		BYTE [si+FILE_DIALOG_IO.bDialogFlags], FLG_FILEDIALOG_DIRECTORY | FLG_FILEDIALOG_NEW | FLG_FILEDIALOG_DRIVES
 	mov		BYTE [si+FILE_DIALOG_IO.bFileAttributes], FLG_FILEATTR_DIRECTORY | FLG_FILEATTR_ARCHIVE
 	mov		WORD [si+FILE_DIALOG_IO.fpFileFilterString], .szAllFiles
 	mov		[si+FILE_DIALOG_IO.fpFileFilterString+2], cs
-	mov		[si+STRING_DIALOG_IO.fpReturnBuffer+2], cs
 	CALL_MENU_LIBRARY GetFileNameWithIoInDSSI
 	cmp		BYTE [g_dialogInputOutput+FILE_DIALOG_IO.bUserCancellation], TRUE
Index: trunk/Assembly_Library/Src/Menu/Dialog/Dialog.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/Dialog.asm	(revision 49)
+++ trunk/Assembly_Library/Src/Menu/Dialog/Dialog.asm	(revision 50)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	6.8.2010
-; Last update	:	7.10.2010
+; Last update	:	9.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Common functions for many dialogs.
@@ -26,7 +26,7 @@
 	push	ds
 	mov		di, bp								; Backup parent MENU
-	eENTER_STRUCT DIALOG_size
-
 	mov		cx, DIALOG_size
+	eENTER_STRUCT cx
+
 	call	Memory_ZeroSSBPwithSizeInCX
 	mov		[bp+DIALOG.fpDialogIO], si
Index: trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 49)
+++ trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 50)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	6.9.2010
-; Last update	:	4.10.2010
+; Last update	:	9.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Displays file dialog.
@@ -114,7 +114,5 @@
 	call	LoadItemStringBufferToESDI
 	call	SortDirectoryContentsStringFromESDIwithCountInCX
-	push	ss
-	pop		ds
-	mov		si, bp
+	call	Memory_CopySSBPtoDSSI
 	call	Dialog_EventInitializeMenuinitFromDSSI
 	call	GetInfoLinesToCXandDialogFlagsToAX
@@ -199,7 +197,5 @@
 ALIGN JUMP_ALIGN
 .ClearDLifInRootDirectory:
-	push	es
-	pop		ds
-	mov		si, di
+	call	Memory_CopyESDItoDSSI
 	call	Directory_WriteCurrentPathToDSSI
 	mov		dl, [si]
@@ -511,9 +507,8 @@
 	add		di, BYTE FILE_DIALOG_IO.szFile
 	mov		cx, FILENAME_BUFFER_SIZE-1
-	cld
-	rep movsb
+	call	Memory_CopyCXbytesFromDSSItoESDI
 	xor		ax, ax
 	stosb						; Terminate with NULL
-	jmp		CloseFileDialogAfterSuccessfullSelection
+	jmp		SHORT CloseFileDialogAfterSuccessfullSelection
 
 ;--------------------------------------------------------------------
Index: trunk/Assembly_Library/Src/Util/Memory.asm
===================================================================
--- trunk/Assembly_Library/Src/Util/Memory.asm	(revision 49)
+++ trunk/Assembly_Library/Src/Util/Memory.asm	(revision 50)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	14.7.2010
-; Last update	:	1.10.2010
+; Last update	:	9.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for memory access.
@@ -67,11 +67,12 @@
 ALIGN JUMP_ALIGN
 Memory_ZeroSSBPwithSizeInCX:
+	push	es
+	push	di
 	push	ax
-
-	call	Memory_ExchangeSSBPwithESDI
+	call	Memory_CopySSBPtoESDI
 	call	Memory_ZeroESDIwithSizeInCX
-	call	Memory_ExchangeSSBPwithESDI
-
 	pop		ax
+	pop		di
+	pop		es
 	ret
 
@@ -82,5 +83,5 @@
 ;		ES:DI:	Ptr to destination buffer
 ;	Returns:
-;		Nothing
+;		DI:		Updated by number of BYTEs stored
 ;	Corrupts registers:
 ;		AX
@@ -98,5 +99,5 @@
 ;		ES:DI:	Ptr to destination buffer
 ;	Returns:
-;		Nothing
+;		DI:		Updated by number of BYTEs stored
 ;	Corrupts registers:
 ;		Nothing
@@ -105,34 +106,23 @@
 Memory_StoreCXbytesFromAccumToESDI:
 	OPTIMIZE_STRING_OPERATION rep, stos
-	sub		di, cx
 	ret
 
 
 ;--------------------------------------------------------------------
-; Memory_ExchangeSSBPwithESDI
 ; Memory_ExchangeDSSIwithESDI
 ;	Parameters
 ;		Nothing
 ;	Returns:
-;		SS:BP/DS:SI and ES:DI are exchanged.
+;		DS:SI and ES:DI are exchanged.
 ;	Corrupts registers:
 ;		Nothing
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-Memory_ExchangeSSBPwithESDI:
-	xchg	bp, di
-	push	ss
-	push	es
-	pop		ss
-	pop		es
-	ret
-
-ALIGN JUMP_ALIGN
 Memory_ExchangeDSSIwithESDI:
-	xchg	si, di
 	push	ds
 	push	es
 	pop		ds
 	pop		es
+	xchg	si, di
 	ret
 
@@ -140,8 +130,10 @@
 ;--------------------------------------------------------------------
 ; Memory_CopySSBPtoESDI
+; Memory_CopySSBPtoDSSI
+; Memory_CopyESDItoDSSI
 ;	Parameters
 ;		Nothing
 ;	Returns:
-;		ES:DI:		Same as SS:BP
+;		Copies farm pointer to different segment/pointer register pair
 ;	Corrupts registers:
 ;		Nothing
@@ -152,4 +144,18 @@
 	pop		es
 	mov		di, bp
+	ret
+
+ALIGN JUMP_ALIGN
+Memory_CopySSBPtoDSSI:
+	push	ss
+	pop		ds
+	mov		si, bp
+	ret
+
+ALIGN JUMP_ALIGN
+Memory_CopyESDItoDSSI:
+	push	es
+	pop		ds
+	mov		si, di
 	ret
 
