Index: trunk/Assembly_Library/Src/Menu/MenuTime.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuTime.asm	(revision 47)
+++ trunk/Assembly_Library/Src/Menu/MenuTime.asm	(revision 60)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	25.7.2010
-; Last update	:	4.10.2010
+; Last update	:	25.11.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Menu timeouts other time related functions.
@@ -10,22 +10,7 @@
 
 ;--------------------------------------------------------------------
-; MenuTime_SetSelectionTimeoutValueFromAX
+; MenuTime_StartSelectionTimeoutWithTicksInAX
 ;	Parameters
-;		AX:		Selection timeout in system timer ticks
-;		SS:BP:	Ptr to MENU
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-MenuTime_SetSelectionTimeoutValueFromAX:
-	mov		[bp+MENUINIT.wTimeoutTicks], ax
-	ret
-
-
-;--------------------------------------------------------------------
-; MenuTime_RestartSelectionTimeout
-;	Parameters
+;		AX:		Timeout ticks
 ;		SS:BP:	Ptr to MENU
 ;	Returns:
@@ -35,10 +20,30 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-MenuTime_RestartSelectionTimeout:
+MenuTime_StartSelectionTimeoutWithTicksInAX:
 	push	ds
 	call	PointDSBXtoTimeoutCounter
-	mov		ax, [bp+MENUINIT.wTimeoutTicks]
-	call	TimerTicks_InitializeTimeoutFromAX	; End time to [DS:BX]
+	call	TimerTicks_InitializeTimeoutFromAX
+	or		BYTE [bp+MENU.bFlags], FLG_MENU_TIMEOUT_COUNTDOWN
 	pop		ds
+	ret
+
+
+;--------------------------------------------------------------------
+; MenuTime_StopSelectionTimeout
+;	Parameters
+;		SS:BP:	Ptr to MENU
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, DX, SI, DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+MenuTime_StopSelectionTimeout:
+	test	BYTE [bp+MENU.bFlags], FLG_MENU_TIMEOUT_COUNTDOWN
+	jz		SHORT .TimeoutAlreadyStopped
+	and		BYTE [bp+MENU.bFlags], ~FLG_MENU_TIMEOUT_COUNTDOWN
+	jmp		MenuBorders_RedrawBottomBorderLine
+ALIGN JUMP_ALIGN
+.TimeoutAlreadyStopped:
 	ret
 
@@ -52,41 +57,25 @@
 ;				Cleared if time left
 ;	Corrupts registers:
-;		AX, BX, CX, DX, SI, DI
+;		AX, BX, SI, DI
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 MenuTime_UpdateSelectionTimeout:
+	test	BYTE [bp+MENU.bFlags], FLG_MENU_TIMEOUT_COUNTDOWN
+	jz		SHORT .ReturnSinceTimeoutDisabled
+
 	push	ds
-
-	call	MenuTime_DrawWithoutUpdating
-	jnc		SHORT .TimeoutDisabled
 	call	PointDSBXtoTimeoutCounter
-	call	TimerTicks_SetCarryIfTimeoutFromDSBX
+	call	TimerTicks_GetTimeoutTicksLeftToAXfromDSBX
+	pop		ds
+	jnc		SHORT .RedrawSinceNoTimeout
+	and		BYTE [bp+MENU.bFlags], ~FLG_MENU_TIMEOUT_COUNTDOWN
+	stc
+	ret
 
 ALIGN JUMP_ALIGN
-.TimeoutDisabled:
-	pop		ds
-	ret
-
-;--------------------------------------------------------------------
-; MenuTime_DrawWithoutUpdating
-;	Parameters
-;		SS:BP:	Ptr to MENU
-;	Returns:
-;		CF:		Set if timeout enabled
-;				Cleared if timeout disabled
-;	Corrupts registers:
-;		AX, BX, CX, DX, SI, DI
-;--------------------------------------------------------------------
+.RedrawSinceNoTimeout:
+	call	MenuBorders_RedrawTimeoutValue
+	clc
 ALIGN JUMP_ALIGN
-MenuTime_DrawWithoutUpdating:
-	cmp		WORD [bp+MENUINIT.wTimeoutTicks], BYTE 0
-	je		SHORT .ReturnSinceTimeoutDisabled	; Clear CF
-
-	push	ds
-	call	GetSecondsLeftUntilTimeoutToAXandCounterToDSBX
-	call	DrawTimeoutInAXoverMenuBorders
-	pop		ds
-	stc
-ALIGN JUMP_ALIGN, ret
 .ReturnSinceTimeoutDisabled:
 	ret
@@ -94,21 +83,36 @@
 
 ;--------------------------------------------------------------------
-; GetSecondsLeftUntilTimeoutToAXandCounterToDSBX
+; MenuTime_GetTimeoutSecondsLeftToAX
 ;	Parameters
 ;		SS:BP:	Ptr to MENU
 ;	Returns:
 ;		AX:		Seconds until timeout
-;		DS:BX:	Ptr to timeout counter
 ;	Corrupts registers:
-;		AX, CX, DX
+;		AX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-GetSecondsLeftUntilTimeoutToAXandCounterToDSBX:
+MenuTime_GetTimeoutSecondsLeftToAX:
+	push	ds
+	push	dx
+	push	cx
+	push	bx
+
 	call	PointDSBXtoTimeoutCounter
-	call	TimerTicks_GetElapsedToAXfromDSBX
-	neg		ax			; Negate since DS:BX points to end time
-	MAX_S	ax, 0		; Set to zero if overflow
+	call	TimerTicks_GetTimeoutTicksLeftToAXfromDSBX
+	jc		SHORT .TimeoutHasOccurred
+
 	xchg	dx, ax
-	jmp		TimerTicks_GetSecondsToAXfromTicksInDX
+	call	TimerTicks_GetSecondsToAXfromTicksInDX
+	clc
+	jmp		SHORT .PopRegistersAndReturn
+.TimeoutHasOccurred:
+	xor		ax, ax
+	stc
+.PopRegistersAndReturn:
+	pop		bx
+	pop		cx
+	pop		dx
+	pop		ds
+	ret
 
 
@@ -128,71 +132,2 @@
 	lea		bx, [bp+MENU.wTimeoutCounter]
 	ret
-
-
-;--------------------------------------------------------------------
-; DrawTimeoutInAXoverMenuBorders
-;	Parameters
-;		AX:		Seconds to draw
-;		SS:BP:	Ptr to MENU
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, CX, DX, SI, DI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-DrawTimeoutInAXoverMenuBorders:
-	xchg	cx, ax
-	call	MenuBorders_AdjustDisplayContextForDrawingBorders
-	call	MenuLocation_GetBottomBordersTopLeftCoordinatesToAX
-	CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
-	; Fall to .PrintTimeoutStringWithSecondsInDX
-
-;--------------------------------------------------------------------
-; .PrintTimeoutStringWithSecondsInDX
-;	Parameters
-;		CX:		Seconds to print
-;		SS:BP:	Ptr to MENU
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, DX, SI, DI
-;--------------------------------------------------------------------
-;ALIGN JUMP_ALIGN
-.PrintTimeoutStringWithSecondsInDX:
-	push	bp
-
-	mov		bp, sp
-	call	.GetTimeoutAttributeToAXfromSecondsInCX
-	mov		si, .szSelectionTimeout
-	push	ax			; Push attribute
-	push	cx			; Push seconds
-	CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
-	pop		bp
-
-	; Draw right border with normal border color
-	mov		al, DOUBLE_RIGHT_HORIZONTAL_TO_SINGLE_VERTICAL
-	jmp		MenuBorders_PrintSingleBorderCharacterFromAL
-.szSelectionTimeout:
-	db		DOUBLE_BOTTOM_LEFT_CORNER
-	db		DOUBLE_LEFT_HORIZONTAL_TO_SINGLE_VERTICAL
-	db		"%AAutoselection in %2u s",NULL
-
-;--------------------------------------------------------------------
-; .GetTimeoutAttributeToAXfromSecondsInCX
-;	Parameters
-;		CX:		Seconds to print
-;	Returns:
-;		AX:		Attribute byte for seconds
-;		CX:		Seconds to print
-;	Corrupts registers:
-;		SI, DI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.GetTimeoutAttributeToAXfromSecondsInCX:
-	mov		si, ATTRIBUTE_CHARS.cNormalTimeout
-	cmp		cx, BYTE 3
-	ja		SHORT .GetAttributeToAX
-	add		si, BYTE ATTRIBUTE_CHARS.cHurryTimeout - ATTRIBUTE_CHARS.cNormalTimeout
-ALIGN JUMP_ALIGN
-.GetAttributeToAX:
-	jmp		MenuAttribute_GetToAXfromTypeInSI
