Index: trunk/Assembly_Library/Src/Time/TimerTicks.asm
===================================================================
--- trunk/Assembly_Library/Src/Time/TimerTicks.asm	(revision 489)
+++ trunk/Assembly_Library/Src/Time/TimerTicks.asm	(revision 491)
@@ -3,5 +3,5 @@
 
 ;
-; XTIDE Universal BIOS and Associated Tools 
+; XTIDE Universal BIOS and Associated Tools
 ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
 ;
@@ -10,14 +10,23 @@
 ; the Free Software Foundation; either version 2 of the License, or
 ; (at your option) any later version.
-; 
+;
 ; This program is distributed in the hope that it will be useful,
 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-; GNU General Public License for more details.		
+; GNU General Public License for more details.
 ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
-;		
-
-; System timer ticks 18.2 times per second = 54.9 ms / tick
-TICKS_PER_HOUR			EQU		65520
+;
+
+; With a PIT input clock of 1193181.6666... Hz and a maximum
+; 16 bit divisor of 65536 (if PIT programmed with 0) we get:
+;
+; Clock / Divisor = ~18.2065 ticks per second
+; Clock * SecondsPerMinute / Divisor = ~1092 ticks per minute
+; Clock * SecondsPerHour / Divisor = ~65543 ticks per hour
+;
+; Since 65543 can't fit in a 16 bit register we use the
+; maximum possible instead and disregard the last ~8 ticks.
+
+TICKS_PER_HOUR			EQU		65535
 TICKS_PER_MINUTE		EQU		1092
 TICKS_PER_SECOND		EQU		18
@@ -28,7 +37,7 @@
 
 ;--------------------------------------------------------------------
-; TimerTicks_GetHoursToAXfromTicksInDXAX
-; TimerTicks_GetMinutesToAXfromTicksInDX
-; TimerTicks_GetSecondsToAXfromTicksInDX
+; TimerTicks_GetHoursToAXandRemainderTicksToDXfromTicksInDXAX
+; TimerTicks_GetMinutesToAXandRemainderTicksToDXfromTicksInDX
+; TimerTicks_GetSecondsToAXandRemainderTicksToDXfromTicksInDX
 ;	Parameters
 ;		DX(:AX):	Timer ticks to convert
@@ -42,5 +51,5 @@
 %ifndef EXCLUDE_FROM_XTIDECFG
 ALIGN JUMP_ALIGN
-TimerTicks_GetHoursToAXfromTicksInDXAX:
+TimerTicks_GetHoursToAXandRemainderTicksToDXfromTicksInDXAX:
 	mov		cx, TICKS_PER_HOUR
 	div		cx		; Divide DX:AX by CX, Hours to AX, remainder ticks to DX
@@ -49,5 +58,5 @@
 
 ALIGN JUMP_ALIGN
-TimerTicks_GetMinutesToAXfromTicksInDX:
+TimerTicks_GetMinutesToAXandRemainderTicksToDXfromTicksInDX:
 	xor		ax, ax
 	xchg	ax, dx	; Ticks now in DX:AX
@@ -57,7 +66,9 @@
 %endif ; EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
 
-%ifdef INCLUDE_MENU_LIBRARY
-ALIGN JUMP_ALIGN
-TimerTicks_GetSecondsToAXfromTicksInDX:
+%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS OR EXCLUDE_FROM_XTIDECFG
+ALIGN JUMP_ALIGN
+TimerTicks_GetSecondsToAXandRemainderTicksToDXfromTicksInDX:
+	; This procedure can handle at most 4607 ticks in DX (almost 256 seconds)
+	; More than 4607 ticks will generate a divide overflow exception!
 	xchg	ax, dx	; Ticks now in AX
 	mov		cl, TICKS_PER_SECOND
@@ -68,4 +79,29 @@
 %endif
 
+
+%ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
+	%ifndef MODULE_BOOT_MENU
+		%define EXCLUDE
+	%endif
+%endif
+;--------------------------------------------------------------------
+; TimerTicks_GetSecondsToAXfromTicksInDX
+;	Parameters
+;		DX:			Timer ticks to convert
+;	Returns:
+;		AX:			Seconds
+;	Corrupts registers:
+;		DX
+;--------------------------------------------------------------------
+%ifndef EXCLUDE	; 1 of 3
+ALIGN JUMP_ALIGN
+TimerTicks_GetSecondsToAXfromTicksInDX:
+	mov		ax, 3600	; Approximately 65536 / (Clock / Divisor)
+	mul		dx
+	xchg	dx, ax
+	ret
+%endif
+
+
 ;--------------------------------------------------------------------
 ; First tick might take 0...54.9 ms and remaining ticks
@@ -82,5 +118,5 @@
 ;		AX
 ;--------------------------------------------------------------------
-%ifdef INCLUDE_MENU_LIBRARY		
+%ifndef EXCLUDE	; 2 of 3
 ALIGN JUMP_ALIGN
 TimerTicks_InitializeTimeoutFromAX:
@@ -90,4 +126,5 @@
 	ret
 %endif
+
 
 ;--------------------------------------------------------------------
@@ -102,5 +139,5 @@
 ;		Nothing
 ;--------------------------------------------------------------------
-%ifdef INCLUDE_MENU_LIBRARY		
+%ifndef EXCLUDE	; 3 of 3
 ALIGN JUMP_ALIGN
 TimerTicks_GetTimeoutTicksLeftToAXfromDSBX:
@@ -114,4 +151,7 @@
 %endif
 
+%undef EXCLUDE
+
+
 ;--------------------------------------------------------------------
 ; TimerTicks_GetElapsedToAXandResetDSBX
@@ -134,4 +174,5 @@
 %endif
 
+
 ;--------------------------------------------------------------------
 ; TimerTicks_GetElapsedToAXfromDSBX
@@ -161,4 +202,11 @@
 ;		Nothing
 ;--------------------------------------------------------------------
+%ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
+	%ifndef MODULE_BOOT_MENU OR MODULE_HOTKEYS
+		%define EXCLUDE
+	%endif
+%endif
+
+%ifndef EXCLUDE
 ALIGN JUMP_ALIGN
 TimerTicks_ReadFromBdaToAX:
@@ -170,2 +218,4 @@
 	pop		ds
 	ret
+%endif
+%undef EXCLUDE
