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
|
---|
21 | TICKS_PER_HOUR EQU 65520
|
---|
22 | TICKS_PER_MINUTE EQU 1092
|
---|
23 | TICKS_PER_SECOND EQU 18
|
---|
24 |
|
---|
25 |
|
---|
26 | ; Section containing code
|
---|
27 | SECTION .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
|
---|
43 | ALIGN JUMP_ALIGN
|
---|
44 | TimerTicks_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 |
|
---|
50 | ALIGN JUMP_ALIGN
|
---|
51 | TimerTicks_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 |
|
---|
59 | %ifdef INCLUDE_MENU_LIBRARY
|
---|
60 | ALIGN JUMP_ALIGN
|
---|
61 | TimerTicks_GetSecondsToAXfromTicksInDX:
|
---|
62 | xchg ax, dx ; Ticks now in AX
|
---|
63 | mov cl, TICKS_PER_SECOND
|
---|
64 | div cl ; Divide AX by CL, Seconds to AL, remainder ticks to AH
|
---|
65 | xor dx, dx
|
---|
66 | xchg dl, ah ; Seconds in AX, remainder in DX
|
---|
67 | ret
|
---|
68 | %endif
|
---|
69 |
|
---|
70 | ;--------------------------------------------------------------------
|
---|
71 | ; First tick might take 0...54.9 ms and remaining ticks
|
---|
72 | ; will occur at 54.9 ms intervals. Use delay of two (or more) ticks to
|
---|
73 | ; ensure at least 54.9 ms timeout.
|
---|
74 | ;
|
---|
75 | ; TimerTicks_InitializeTimeoutFromAX
|
---|
76 | ; Parameters:
|
---|
77 | ; AX: Timeout ticks (54.9 ms) before timeout
|
---|
78 | ; DS:BX: Ptr to timeout variable WORD
|
---|
79 | ; Returns:
|
---|
80 | ; [DS:BX]: Initialized for TimerTicks_SetCarryIfTimeoutFromDSBX
|
---|
81 | ; Corrupts registers:
|
---|
82 | ; AX
|
---|
83 | ;--------------------------------------------------------------------
|
---|
84 | %ifdef INCLUDE_MENU_LIBRARY
|
---|
85 | ALIGN JUMP_ALIGN
|
---|
86 | TimerTicks_InitializeTimeoutFromAX:
|
---|
87 | mov [bx], ax ; Store timeout ticks
|
---|
88 | call TimerTicks_ReadFromBdaToAX
|
---|
89 | add [bx], ax ; [bx] now contains end time for timeout
|
---|
90 | ret
|
---|
91 | %endif
|
---|
92 |
|
---|
93 | ;--------------------------------------------------------------------
|
---|
94 | ; TimerTicks_GetTimeoutTicksLeftToAXfromDSBX
|
---|
95 | ; Parameters:
|
---|
96 | ; DS:BX: Ptr to timeout variable WORD
|
---|
97 | ; Returns:
|
---|
98 | ; AX: Number of ticks left before timeout
|
---|
99 | ; CF: Set if timeout
|
---|
100 | ; Cleared if time left
|
---|
101 | ; Corrupts registers:
|
---|
102 | ; Nothing
|
---|
103 | ;--------------------------------------------------------------------
|
---|
104 | %ifdef INCLUDE_MENU_LIBRARY
|
---|
105 | ALIGN JUMP_ALIGN
|
---|
106 | TimerTicks_GetTimeoutTicksLeftToAXfromDSBX:
|
---|
107 | push dx
|
---|
108 | mov dx, [bx]
|
---|
109 | call TimerTicks_ReadFromBdaToAX
|
---|
110 | xchg ax, dx
|
---|
111 | sub ax, dx ; AX = End time - current time
|
---|
112 | pop dx
|
---|
113 | ret
|
---|
114 | %endif
|
---|
115 |
|
---|
116 | ;--------------------------------------------------------------------
|
---|
117 | ; TimerTicks_GetElapsedToAXandResetDSBX
|
---|
118 | ; Parameters
|
---|
119 | ; DS:BX: Ptr to WORD containing previous reset time
|
---|
120 | ; Returns:
|
---|
121 | ; AX: 54.9 ms ticks elapsed since last reset
|
---|
122 | ; [DS:BX]: Reset to latest time
|
---|
123 | ; Corrupts registers:
|
---|
124 | ; Nothing
|
---|
125 | ;--------------------------------------------------------------------
|
---|
126 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
127 | ALIGN JUMP_ALIGN
|
---|
128 | TimerTicks_GetElapsedToAXandResetDSBX:
|
---|
129 | call TimerTicks_ReadFromBdaToAX
|
---|
130 | push ax
|
---|
131 | sub ax, [bx]
|
---|
132 | pop WORD [bx] ; Latest time to [DS:BX]
|
---|
133 | ret
|
---|
134 | %endif
|
---|
135 |
|
---|
136 | ;--------------------------------------------------------------------
|
---|
137 | ; TimerTicks_GetElapsedToAXfromDSBX
|
---|
138 | ; Parameters
|
---|
139 | ; DS:BX: Ptr to WORD containing previous update time
|
---|
140 | ; Returns:
|
---|
141 | ; AX: 54.9 ms ticks elapsed since initializing [DS:BX]
|
---|
142 | ; Corrupts registers:
|
---|
143 | ; Nothing
|
---|
144 | ;--------------------------------------------------------------------
|
---|
145 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
146 | ALIGN JUMP_ALIGN
|
---|
147 | TimerTicks_GetElapsedToAXfromDSBX:
|
---|
148 | call TimerTicks_ReadFromBdaToAX
|
---|
149 | sub ax, [bx]
|
---|
150 | ret
|
---|
151 | %endif
|
---|
152 |
|
---|
153 |
|
---|
154 | ;--------------------------------------------------------------------
|
---|
155 | ; TimerTicks_ReadFromBdaToAX
|
---|
156 | ; Parameters
|
---|
157 | ; Nothing
|
---|
158 | ; Returns:
|
---|
159 | ; AX: System time in 54.9 ms ticks
|
---|
160 | ; Corrupts registers:
|
---|
161 | ; Nothing
|
---|
162 | ;--------------------------------------------------------------------
|
---|
163 | ALIGN JUMP_ALIGN
|
---|
164 | TimerTicks_ReadFromBdaToAX:
|
---|
165 | push ds
|
---|
166 |
|
---|
167 | LOAD_BDA_SEGMENT_TO ds, ax
|
---|
168 | mov ax, [BDA.dwTimerTicks] ; Read low WORD only
|
---|
169 |
|
---|
170 | pop ds
|
---|
171 | ret
|
---|