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

Last change on this file since 145 was 131, checked in by Tomi Tilli, 14 years ago

Changes to Assembly Library:

  • Some functions are now excluded from XTIDE Universal BIOS with EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS define.
File size: 4.2 KB
RevLine 
[41]1; Project name : Assembly Library
2; Description : Functions for system timer related operations.
3
4; System timer ticks 18.2 times per second = 54.9 ms / tick
5TICKS_PER_HOUR EQU 65520
6TICKS_PER_MINUTE EQU 1092
7TICKS_PER_SECOND EQU 18
8
9
10; Section containing code
11SECTION .text
12
13;--------------------------------------------------------------------
14; TimerTicks_GetHoursToAXfromTicksInDXAX
15; TimerTicks_GetMinutesToAXfromTicksInDX
16; TimerTicks_GetSecondsToAXfromTicksInDX
17; Parameters
18; DX(:AX): Timer ticks to convert
19; Returns:
20; AX: Hours, minutes or seconds
21; DX: Remainder ticks
22; Corrupts registers:
23; CX
24;--------------------------------------------------------------------
[131]25%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]26ALIGN JUMP_ALIGN
27TimerTicks_GetHoursToAXfromTicksInDXAX:
28 mov cx, TICKS_PER_HOUR
29 div cx ; Divide DX:AX by CX, Hours to AX, remainder ticks to DX
30 ret
31
32ALIGN JUMP_ALIGN
33TimerTicks_GetMinutesToAXfromTicksInDX:
34 xor ax, ax
35 xchg ax, dx ; Ticks now in DX:AX
36 mov cx, TICKS_PER_MINUTE
37 div cx ; Divide DX:AX by CX, Minutes to AX, remainder ticks to DX
38 ret
[106]39%endif
40
[41]41ALIGN JUMP_ALIGN
42TimerTicks_GetSecondsToAXfromTicksInDX:
43 xchg ax, dx ; Ticks now in AX
44 mov cl, TICKS_PER_SECOND
45 div cl ; Divide AX by CL, Seconds to AL, remainder ticks to AH
46 xor dx, dx
47 xchg dl, ah ; Seconds in AX, remainder in DX
48 ret
49
50
51;--------------------------------------------------------------------
52; First tick might take 0...54.9 ms and remaining ticks
53; will occur at 54.9 ms intervals. Use delay of two (or more) ticks to
54; ensure at least 54.9 ms timeout.
55;
56; TimerTicks_InitializeTimeoutFromAX
57; Parameters:
58; AX: Timeout ticks (54.9 ms) before timeout
59; DS:BX: Ptr to timeout variable WORD
60; Returns:
61; [DS:BX]: Initialized for TimerTicks_SetCarryIfTimeoutFromDSBX
62; Corrupts registers:
63; AX
64;--------------------------------------------------------------------
65ALIGN JUMP_ALIGN
66TimerTicks_InitializeTimeoutFromAX:
67 mov [bx], ax ; Store timeout ticks
68 call TimerTicks_ReadFromBdaToAX
[119]69 add [bx], ax ; [bx] now contains end time for timeout
[41]70 ret
71
[60]72
[41]73;--------------------------------------------------------------------
[60]74; TimerTicks_GetTimeoutTicksLeftToAXfromDSBX
[41]75; Parameters:
76; DS:BX: Ptr to timeout variable WORD
77; Returns:
[85]78; AX: Number of ticks left before timeout
[41]79; CF: Set if timeout
80; Cleared if time left
81; Corrupts registers:
82; Nothing
83;--------------------------------------------------------------------
84ALIGN JUMP_ALIGN
[60]85TimerTicks_GetTimeoutTicksLeftToAXfromDSBX:
86 push dx
87 mov dx, [bx]
[41]88 call TimerTicks_ReadFromBdaToAX
[60]89 xchg ax, dx
90 sub ax, dx ; AX = End time - current time
91 pop dx
[41]92 ret
93
94
95;--------------------------------------------------------------------
96; TimerTicks_GetElapsedToAXandResetDSBX
97; Parameters
98; DS:BX: Ptr to WORD containing previous reset time
99; Returns:
100; AX: 54.9 ms ticks elapsed since last reset
101; [DS:BX]: Reset to latest time
102; Corrupts registers:
103; Nothing
104;--------------------------------------------------------------------
[131]105%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]106ALIGN JUMP_ALIGN
107TimerTicks_GetElapsedToAXandResetDSBX:
108 call TimerTicks_ReadFromBdaToAX
109 push ax
110 sub ax, [bx]
111 pop WORD [bx] ; Latest time to [DS:BX]
112 ret
[131]113%endif
[41]114
115;--------------------------------------------------------------------
116; TimerTicks_GetElapsedToAXfromDSBX
117; Parameters
118; DS:BX: Ptr to WORD containing previous update time
119; Returns:
120; AX: 54.9 ms ticks elapsed since initializing [DS:BX]
121; Corrupts registers:
122; Nothing
123;--------------------------------------------------------------------
[131]124%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]125ALIGN JUMP_ALIGN
126TimerTicks_GetElapsedToAXfromDSBX:
127 call TimerTicks_ReadFromBdaToAX
128 sub ax, [bx]
129 ret
[131]130%endif
[41]131
132
133;--------------------------------------------------------------------
134; TimerTicks_ReadFromBdaToAX
135; Parameters
136; Nothing
137; Returns:
138; AX: System time in 54.9 ms ticks
139; Corrupts registers:
140; Nothing
141;--------------------------------------------------------------------
142ALIGN JUMP_ALIGN
143TimerTicks_ReadFromBdaToAX:
144 push ds
145
146 LOAD_BDA_SEGMENT_TO ds, ax
147 mov ax, [BDA.dwTimerTicks] ; Read low WORD only
148
149 pop ds
150 ret
Note: See TracBrowser for help on using the repository browser.