source: xtideuniversalbios/trunk/Assembly_Library/Src/Time/TimerTicks.asm@ 436

Last change on this file since 436 was 376, checked in by gregli@…, 13 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 5.0 KB
Line 
1; Project name : Assembly Library
2; Description : Functions for system timer related operations.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
12;
13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
20; System timer ticks 18.2 times per second = 54.9 ms / tick
21TICKS_PER_HOUR EQU 65520
22TICKS_PER_MINUTE EQU 1092
23TICKS_PER_SECOND EQU 18
24
25
26; Section containing code
27SECTION .text
28
29;--------------------------------------------------------------------
30; TimerTicks_GetHoursToAXfromTicksInDXAX
31; TimerTicks_GetMinutesToAXfromTicksInDX
32; TimerTicks_GetSecondsToAXfromTicksInDX
33; Parameters
34; DX(:AX): Timer ticks to convert
35; Returns:
36; AX: Hours, minutes or seconds
37; DX: Remainder ticks
38; Corrupts registers:
39; CX
40;--------------------------------------------------------------------
41%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
42%ifndef EXCLUDE_FROM_XTIDECFG
43ALIGN JUMP_ALIGN
44TimerTicks_GetHoursToAXfromTicksInDXAX:
45 mov cx, TICKS_PER_HOUR
46 div cx ; Divide DX:AX by CX, Hours to AX, remainder ticks to DX
47 ret
48%endif ; EXCLUDE_FROM_XTIDECFG
49
50ALIGN JUMP_ALIGN
51TimerTicks_GetMinutesToAXfromTicksInDX:
52 xor ax, ax
53 xchg ax, dx ; Ticks now in DX:AX
54 mov cx, TICKS_PER_MINUTE
55 div cx ; Divide DX:AX by CX, Minutes to AX, remainder ticks to DX
56 ret
57%endif ; EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
58
59ALIGN JUMP_ALIGN
60TimerTicks_GetSecondsToAXfromTicksInDX:
61 xchg ax, dx ; Ticks now in AX
62 mov cl, TICKS_PER_SECOND
63 div cl ; Divide AX by CL, Seconds to AL, remainder ticks to AH
64 xor dx, dx
65 xchg dl, ah ; Seconds in AX, remainder in DX
66 ret
67
68
69;--------------------------------------------------------------------
70; First tick might take 0...54.9 ms and remaining ticks
71; will occur at 54.9 ms intervals. Use delay of two (or more) ticks to
72; ensure at least 54.9 ms timeout.
73;
74; TimerTicks_InitializeTimeoutFromAX
75; Parameters:
76; AX: Timeout ticks (54.9 ms) before timeout
77; DS:BX: Ptr to timeout variable WORD
78; Returns:
79; [DS:BX]: Initialized for TimerTicks_SetCarryIfTimeoutFromDSBX
80; Corrupts registers:
81; AX
82;--------------------------------------------------------------------
83ALIGN JUMP_ALIGN
84TimerTicks_InitializeTimeoutFromAX:
85 mov [bx], ax ; Store timeout ticks
86 call TimerTicks_ReadFromBdaToAX
87 add [bx], ax ; [bx] now contains end time for timeout
88 ret
89
90
91;--------------------------------------------------------------------
92; TimerTicks_GetTimeoutTicksLeftToAXfromDSBX
93; Parameters:
94; DS:BX: Ptr to timeout variable WORD
95; Returns:
96; AX: Number of ticks left before timeout
97; CF: Set if timeout
98; Cleared if time left
99; Corrupts registers:
100; Nothing
101;--------------------------------------------------------------------
102ALIGN JUMP_ALIGN
103TimerTicks_GetTimeoutTicksLeftToAXfromDSBX:
104 push dx
105 mov dx, [bx]
106 call TimerTicks_ReadFromBdaToAX
107 xchg ax, dx
108 sub ax, dx ; AX = End time - current time
109 pop dx
110 ret
111
112
113;--------------------------------------------------------------------
114; TimerTicks_GetElapsedToAXandResetDSBX
115; Parameters
116; DS:BX: Ptr to WORD containing previous reset time
117; Returns:
118; AX: 54.9 ms ticks elapsed since last reset
119; [DS:BX]: Reset to latest time
120; Corrupts registers:
121; Nothing
122;--------------------------------------------------------------------
123%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
124ALIGN JUMP_ALIGN
125TimerTicks_GetElapsedToAXandResetDSBX:
126 call TimerTicks_ReadFromBdaToAX
127 push ax
128 sub ax, [bx]
129 pop WORD [bx] ; Latest time to [DS:BX]
130 ret
131%endif
132
133;--------------------------------------------------------------------
134; TimerTicks_GetElapsedToAXfromDSBX
135; Parameters
136; DS:BX: Ptr to WORD containing previous update time
137; Returns:
138; AX: 54.9 ms ticks elapsed since initializing [DS:BX]
139; Corrupts registers:
140; Nothing
141;--------------------------------------------------------------------
142%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
143ALIGN JUMP_ALIGN
144TimerTicks_GetElapsedToAXfromDSBX:
145 call TimerTicks_ReadFromBdaToAX
146 sub ax, [bx]
147 ret
148%endif
149
150
151;--------------------------------------------------------------------
152; TimerTicks_ReadFromBdaToAX
153; Parameters
154; Nothing
155; Returns:
156; AX: System time in 54.9 ms ticks
157; Corrupts registers:
158; Nothing
159;--------------------------------------------------------------------
160ALIGN JUMP_ALIGN
161TimerTicks_ReadFromBdaToAX:
162 push ds
163
164 LOAD_BDA_SEGMENT_TO ds, ax
165 mov ax, [BDA.dwTimerTicks] ; Read low WORD only
166
167 pop ds
168 ret
Note: See TracBrowser for help on using the repository browser.