Index: trunk/Assembly_Library/Src/Display/CgaSnow.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/CgaSnow.asm	(revision 48)
+++ trunk/Assembly_Library/Src/Display/CgaSnow.asm	(revision 48)
@@ -0,0 +1,146 @@
+; File name		:	CgaSnow.asm
+; Project name	:	Assembly Library
+; Created date	:	8.10.2010
+; Last update	:	8.10.2010
+; Author		:	Tomi Tilli
+; Description	:	Functions for preventing CGA snow.
+
+; Section containing code
+SECTION .text
+
+
+; CGA snow preventing must be kept optional so unnecerrasy overhead
+; can be prevented when building program ment for non-CGA systems.
+%ifdef ELIMINATE_CGA_SNOW
+
+;--------------------------------------------------------------------
+; CgaSnow_StosbWithoutCgaSnow
+; CgaSnow_StoswWithoutCgaSnow
+;	Parameters:
+;		AL:		Character to output
+;		AH:		Attribute to output (CgaSnow_StoswWithoutCgaSnow only)
+;		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
+CgaSnow_StosbWithoutCgaSnow:
+	call	LoadAndVerifyStatusRegisterFromBDA
+	jne		SHORT .StosbWithoutWaitSinceUnknownPort
+
+	mov		ah, al
+	cli				; Interrupt request would mess up timing
+	WAIT_UNTIL_SAFE_CGA_WRITE
+	mov		al, ah
+.StosbWithoutWaitSinceUnknownPort:
+	stosb
+	sti
+	ret
+
+ALIGN JUMP_ALIGN
+CgaSnow_StoswWithoutCgaSnow:
+	push	bx
+	call	LoadAndVerifyStatusRegisterFromBDA
+	jne		SHORT .StoswWithoutWaitSinceUnknownPort
+
+	xchg	bx, ax
+	cli				; Interrupt request would mess up timing
+	WAIT_UNTIL_SAFE_CGA_WRITE
+	xchg	ax, bx
+.StoswWithoutWaitSinceUnknownPort:
+	stosw
+	pop		bx
+	sti
+	ret
+
+
+;--------------------------------------------------------------------
+; CgaSnow_ScasbWithoutCgaSnow
+;	Parameters:
+;		AL:		Byte for comparison
+;		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
+CgaSnow_ScasbWithoutCgaSnow:
+	call	LoadAndVerifyStatusRegisterFromBDA
+	jne		SHORT .ScasbWithoutWaitSinceUnknownPort
+
+	mov		ah, al
+	cli				; Interrupt request would mess up timing
+	WAIT_UNTIL_SAFE_CGA_WRITE
+.ScasbWithoutWaitSinceUnknownPort:
+	mov		al, ah
+	scasb
+	sti
+	ret
+
+
+;--------------------------------------------------------------------
+; CgaSnow_RepMovsbWithoutCgaSnow
+;	Parameters:
+;		CX:		Number of characters to copy
+;		DS:		BDA segment (zero)
+;		ES:SI:	Ptr to video memory where to read from
+;		ES:DI:	Ptr to video memory where to write to
+;	Returns:
+;		SI, DI:	Updated for next character
+;	Corrupts registers:
+;		AX, CX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+CgaSnow_RepMovsbWithoutCgaSnow:
+	call	LoadAndVerifyStatusRegisterFromBDA
+	jne		SHORT .RepMovsbWithoutWaitSinceUnknownPort
+
+.MovsbNextByte:
+	cli				; Interrupt request would mess up timing
+	WAIT_UNTIL_SAFE_CGA_WRITE
+	eSEG	es
+	movsb
+	sti
+	loop	.MovsbNextByte
+	ret
+.RepMovsbWithoutWaitSinceUnknownPort:
+	eSEG_STR rep, es, movsb
+	ret
+
+
+;--------------------------------------------------------------------
+; LoadAndVerifyStatusRegisterFromBDA
+;	Parameters:
+;		DS:		BDA segment (zero)
+;	Returns:
+;		DX:		CGA Status Register Address
+;		ZF:		Set if CGA Base Port found in BDA
+;	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
+	ret
+
+
+%endif ; ELIMINATE_CGA_SNOW
Index: trunk/Assembly_Library/Src/Display/DisplayCharOut.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayCharOut.asm	(revision 47)
+++ trunk/Assembly_Library/Src/Display/DisplayCharOut.asm	(revision 48)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	26.6.2010
-; Last update	:	4.10.2010
+; Last update	:	8.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for outputting characters to video memory.
@@ -11,29 +11,4 @@
 ; Section containing code
 SECTION .text
-
-;--------------------------------------------------------------------
-; WAIT_RETRACE_IF_NECESSARY_THEN
-;	Parameters:
-;		AL:		Character to output
-;		AH:		Attribute to output (stosw only)
-;		DS:		BDA segment (zero)
-;		ES:DI:	Ptr to video memory where to output
-;	Returns:
-;		DI:		Incremented for next character
-;	Corrupts registers:
-;		AX, DX
-;--------------------------------------------------------------------
-%macro WAIT_RETRACE_IF_NECESSARY_THEN 1
-%ifdef ELIMINATE_CGA_SNOW
-	%ifidn %1, stosb
-		call	StosbWithoutCgaSnow
-	%else
-		call	StoswWithoutCgaSnow
-	%endif
-%else
-	%1			; STOSB or STOSW
-%endif
-%endmacro
-
 
 ;--------------------------------------------------------------------
@@ -155,94 +130,2 @@
 .BufferFull:
 	ret
-
-
-; STOSB and STOSW replacement functions to prevent CGA snow. These will slow
-; drawing a lot so use them only if it is necessary to eliminate CGA snow.
-%ifdef ELIMINATE_CGA_SNOW
-
-OFFSET_TO_CGA_STATUS_REGISTER	EQU		6		; Base port 3D4h + 6 = 3DAh
-CGA_STATUS_REGISTER				EQU		3DAh
-
-;--------------------------------------------------------------------
-; WAIT_UNTIL_SAFE_CGA_WRITE
-;	Parameters:
-;		DX:		CGA Status Register Address (3DAh)
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AL
-;--------------------------------------------------------------------
-%macro WAIT_UNTIL_SAFE_CGA_WRITE 0
-%%WaitUntilNotInRetrace:
-	in		al, dx
-	shr		al, 1	; 1 = Bit 0: A 1 indicates that regen-buffer memory access can be
-					; made without interfering with the display. (H or V retrace)
-	jc		SHORT %%WaitUntilNotInRetrace
-%%WaitUntilNextRetraceStarts:
-	in		al, dx
-	shr		al, 1
-	jnc		SHORT %%WaitUntilNextRetraceStarts
-%endmacro
-
-;--------------------------------------------------------------------
-; StosbWithoutCgaSnow
-; StoswWithoutCgaSnow
-;	Parameters:
-;		AL:		Character to output
-;		AH:		Attribute to output (StoswWithoutCgaSnow only)
-;		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
-StosbWithoutCgaSnow:
-	call	DisplayCharOut_LoadAndVerifyStatusRegisterFromBDA
-	jne		SHORT .StosbWithoutWaitSinceUnknownPort
-
-	mov		ah, al
-	cli				; Interrupt request would mess up timing
-	WAIT_UNTIL_SAFE_CGA_WRITE
-	mov		al, ah
-.StosbWithoutWaitSinceUnknownPort:
-	stosb
-	sti
-	ret
-
-ALIGN JUMP_ALIGN
-StoswWithoutCgaSnow:
-	push	bx
-	call	DisplayCharOut_LoadAndVerifyStatusRegisterFromBDA
-	jne		SHORT .StoswWithoutWaitSinceUnknownPort
-
-	xchg	bx, ax
-	cli				; Interrupt request would mess up timing
-	WAIT_UNTIL_SAFE_CGA_WRITE
-	xchg	ax, bx
-.StoswWithoutWaitSinceUnknownPort:
-	stosw
-	pop		bx
-	sti
-	ret
-
-
-;--------------------------------------------------------------------
-; DisplayCharOut_LoadAndVerifyStatusRegisterFromBDA
-;	Parameters:
-;		DS:		BDA segment (zero)
-;	Returns:
-;		DX:		CGA Status Register Address
-;		ZF:		Set if CGA Base Port found in BDA
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-DisplayCharOut_LoadAndVerifyStatusRegisterFromBDA:
-	mov		dx, [BDA.wVidPort]
-	add		dl, OFFSET_TO_CGA_STATUS_REGISTER
-	cmp		dx, CGA_STATUS_REGISTER
-	ret
-
-%endif ; ELIMINATE_CGA_SNOW
Index: trunk/Assembly_Library/Src/Display/DisplayContext.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayContext.asm	(revision 47)
+++ trunk/Assembly_Library/Src/Display/DisplayContext.asm	(revision 48)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	25.6.2010
-; Last update	:	28.9.2010
+; Last update	:	5.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for managing display context.
@@ -102,4 +102,31 @@
 
 ;--------------------------------------------------------------------
+; DisplayContext_PrepareOffScreenBufferInESBXtoESDI
+;	Parameters:
+;		BX:AX:	Ptr to off screen buffer
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+DisplayContext_PrepareOffScreenBufferInESBXtoESDI:
+	push	ds
+
+	LOAD_BDA_SEGMENT_TO	ds, di
+	xchg	ax, bx
+	mov		bx, es
+	call	DisplayContext_SetCharacterPointerFromBXAX	; ES:DI now has the pointer
+
+	mov		bl, ATTRIBUTES_NOT_USED
+	mov		ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
+	call	DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
+
+	mov		bx, di
+	pop		ds
+	ret
+
+
+;--------------------------------------------------------------------
 ; DisplayContext_SynchronizeToHardware
 ;	Parameters:
@@ -123,5 +150,5 @@
 ;		DS:		BDA segment (zero)
 ;	Returns:
-;		ES:DI:	Pointer that was in DX:AX
+;		ES:DI:	Pointer that was in BX:AX
 ;	Corrupts registers:
 ;		AX
Index: trunk/Assembly_Library/Src/Display/DisplayFormat.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayFormat.asm	(revision 47)
+++ trunk/Assembly_Library/Src/Display/DisplayFormat.asm	(revision 48)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	29.6.2010
-; Last update	:	4.10.2010
+; Last update	:	8.10.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for displaying formatted strings.
@@ -220,5 +220,5 @@
 	dec		di					; DI = Offset where to move last byte formatted
 	xchg	bx, ax				; BX = BYTEs to prepend
-	call	.ReverseMoveCXbytesFromESSItoESDI
+	call	.ReverseCopyCXbytesFromESSItoESDI
 	xchg	ax, bx
 	call	.ReversePrintAXspacesStartingFromESDI
@@ -231,53 +231,26 @@
 
 ;--------------------------------------------------------------------
-; .ReverseMoveCXbytesFromESSItoESDI
-;	Parameters:
-;		CX:		Number of bytes to move
-;		DS:		BDA segment (zero)
-;		ES:SI:	Ptr to source in video RAM
-;		ES:DI:	Ptr to destination in video RAM
-;	Returns:
-;		DI:		Offset to character preceeding string just moved
+; .ReverseCopyCXbytesFromESSItoESDI
+;	Parameters:
+;		CX:		Number of bytes to copy
+;		DS:		BDA segment (zero)
+;		ES:SI:	Ptr to old location
+;		ES:DI:	Ptr to new location
+;	Returns:
+;		DI:		Updated to before last character copied
 ;	Corrupts registers:
 ;		AX, CX, DX, SI
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-.ReverseMoveCXbytesFromESSItoESDI:
-%ifdef ELIMINATE_CGA_SNOW
-	call	DisplayCharOut_LoadAndVerifyStatusRegisterFromBDA
-	je		SHORT .WaitUntilReadyToMoveNextByte
-%endif
-
+.ReverseCopyCXbytesFromESSItoESDI:
+	test	BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
+	jz		SHORT .CopyWithoutDisplayProcessing
+
+	WAIT_RETRACE_IF_NECESSARY_THEN rep movsb
+	dec		di					; Point to preceeding character instead of attribute
+	ret
+ALIGN JUMP_ALIGN
+.CopyWithoutDisplayProcessing:
 	eSEG_STR rep, es, movsb
-
-%ifdef ELIMINATE_CGA_SNOW
-	jmp		SHORT .AlignDIforFirstPreceedingSpace
-.WaitUntilReadyToMoveNextByte:
-	cli				; Interrupt request would mess up timing
-	WAIT_UNTIL_SAFE_CGA_WRITE
-.MovsbWithoutWaitSinceUnknownPort:
-	eSEG	es
-	movsb
-	sti
-	loop	.WaitUntilReadyToMoveNextByte
-%endif
-	; Fall to .AlignDIforFirstPreceedingSpace
-
-;--------------------------------------------------------------------
-; .AlignDIforFirstPreceedingSpace
-;	Parameters:
-;		DS:		BDA segment (zero)
-;		ES:DI:	Byte offset before last byte moved
-;	Returns:
-;		DI:		Offset to space preceeding moved string
-;	Corrupts registers:
-;		AX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.AlignDIforFirstPreceedingSpace:
-	mov		al, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags]
-	and		ax, BYTE FLG_CONTEXT_ATTRIBUTES
-	not		ax
-	and		di, ax
 	ret
 
Index: trunk/Assembly_Library/Src/Display/DisplayPrint.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayPrint.asm	(revision 47)
+++ trunk/Assembly_Library/Src/Display/DisplayPrint.asm	(revision 48)
@@ -25,4 +25,8 @@
 ;	minimum number of characters. For example %8d would append spaces
 ;	after integer so that at least 8 characters would be printed.
+;
+;	When placing '-' after number, then spaces will be used for prepending.
+;	For example %8-d would prepend integer with spaces so that at least
+;	8 characters would be printed.
 ; 
 ; DisplayPrint_FormattedNullTerminatedStringFromCSSI
