source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Device/Timer.asm@ 556

Last change on this file since 556 was 526, checked in by krille_n_@…, 12 years ago

Changes:

  • Update of the copyright notices to include the year 2013.
File size: 3.9 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Timeout and delay functions for INT 13h services.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 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; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Timer_InitializeTimeoutWithTicksInCL
25; Parameters:
26; CL: Timeout value in system timer ticks
27; DS: Segment to RAMVARS
28; Returns:
29; Nothing
30; Corrupts registers:
31; CX
32;--------------------------------------------------------------------
33ALIGN JUMP_ALIGN
34Timer_InitializeTimeoutWithTicksInCL:
35 mov [RAMVARS.bTimeoutTicksLeft], cl ; Ticks until timeout
36 call ReadTimeFromBdaToCX
37 mov [RAMVARS.bLastTimeoutUpdate], cl ; Start time
38 ret
39
40
41;--------------------------------------------------------------------
42; Timer_SetCFifTimeout
43; Parameters:
44; DS: Segment to RAMVARS
45; Returns:
46; CF: Set if timeout
47; Cleared if time left
48; Corrupts registers:
49; CX
50;--------------------------------------------------------------------
51ALIGN JUMP_ALIGN
52Timer_SetCFifTimeout:
53 call ReadTimeFromBdaToCX
54 cmp cl, [RAMVARS.bLastTimeoutUpdate]
55 je SHORT .StillPollingTheSameTick
56 mov [RAMVARS.bLastTimeoutUpdate], cl
57 sub BYTE [RAMVARS.bTimeoutTicksLeft], 1 ; DEC does not update CF
58.StillPollingTheSameTick:
59 ret
60
61
62;--------------------------------------------------------------------
63; Delay is always at least one millisecond since
64; RTC resolution is 977 microsecs.
65;
66; Timer_DelayMicrosecondsFromAX
67; Parameters:
68; AX: Number of microsecs to wait
69; Returns:
70; Nothing
71; Corrupts registers:
72; AX
73;--------------------------------------------------------------------
74Timer_DelayMicrosecondsFromAX:
75%ifndef USE_AT
76 mov ax, 2
77 ; Fall to Timer_DelayTimerTicksFromAX
78%else
79 push dx
80 push cx
81
82 xor cx, cx
83 xchg dx, ax ; Microsecs now in CX:DX
84 mov ah, EVENT_WAIT
85 int BIOS_SYSTEM_INTERRUPT_15h
86 sti ; XT BIOSes return with interrupts disabled. TODO: Maybe we can remove this since it's in an AT-only block?
87
88 pop cx
89 pop dx
90 mov ax, 1 ; Prepare to wait 1 timer tick
91 jc SHORT Timer_DelayTimerTicksFromAX ; Event Wait was unsupported or busy
92 ret
93%endif
94
95
96;--------------------------------------------------------------------
97; First tick might take 0...54.9 ms and remaining ticks
98; will occur at 54.9 ms intervals.
99;
100; Timer_DelayTimerTicksFromAX
101; Parameters:
102; AX: Number of timer ticks to wait
103; Returns:
104; Nothing
105; Corrupts registers:
106; AX
107;--------------------------------------------------------------------
108Timer_DelayTimerTicksFromAX:
109 sti ; Make sure that interrupts are enabled
110 call ReadTimeFromBdaToCX
111 add ax, cx ; AX = end time
112.WaitLoop:
113 call ReadTimeFromBdaToCX
114 cmp cx, ax
115 jne SHORT .WaitLoop ; Loop until end time is reached
116 ret
117
118
119;--------------------------------------------------------------------
120; ReadTimeFromBdaToCX
121; Parameters
122; Nothing
123; Returns:
124; CX: System time in 54.9 ms ticks
125; Corrupts registers:
126; Nothing
127;--------------------------------------------------------------------
128ALIGN JUMP_ALIGN
129ReadTimeFromBdaToCX:
130 push ds
131 LOAD_BDA_SEGMENT_TO ds, cx
132 mov cx, [BDA.dwTimerTicks] ; Read low WORD only
133 pop ds
134 ret
Note: See TracBrowser for help on using the repository browser.