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

Last change on this file since 420 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: 3.9 KB
RevLine 
[140]1; Project name : XTIDE Universal BIOS
2; Description : Timeout and delay functions for INT 13h services.
3
[376]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
[140]20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
[155]24; Timer_InitializeTimeoutWithTicksInCL
[140]25; Parameters:
[155]26; CL: Timeout value in system timer ticks
[140]27; DS: Segment to RAMVARS
28; Returns:
29; Nothing
30; Corrupts registers:
31; CX
32;--------------------------------------------------------------------
33ALIGN JUMP_ALIGN
[155]34Timer_InitializeTimeoutWithTicksInCL:
35 mov [RAMVARS.bTimeoutTicksLeft], cl ; Ticks until timeout
[140]36 call ReadTimeFromBdaToCX
[155]37 mov [RAMVARS.bLastTimeoutUpdate], cl ; Start time
[140]38 ret
39
40
41;--------------------------------------------------------------------
[155]42; Timer_SetCFifTimeout
[140]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
[155]52Timer_SetCFifTimeout:
[140]53 call ReadTimeFromBdaToCX
[155]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:
[140]59 ret
60
61
62;--------------------------------------------------------------------
63; Delay is always at least one millisecond since
64; RTC resolution is 977 microsecs.
65;
[155]66; Timer_DelayMicrosecondsFromAX
[140]67; Parameters:
68; AX: Number of microsecs to wait
69; Returns:
70; Nothing
71; Corrupts registers:
72; AX
73;--------------------------------------------------------------------
[155]74Timer_DelayMicrosecondsFromAX:
[140]75%ifndef USE_AT
[150]76 mov ax, 2
[181]77 ; Fall to Timer_DelayTimerTicksFromAX
[140]78%else
79 push dx
80 push cx
81
82 xor cx, cx
[148]83 xchg dx, ax ; Microsecs now in CX:DX
[140]84 mov ah, EVENT_WAIT
85 int BIOS_SYSTEM_INTERRUPT_15h
[181]86 sti ; XT BIOSes return with interrupts disabled. TODO: Maybe we can remove this since it's in an AT-only block?
[140]87
88 pop cx
89 pop dx
[148]90 mov ax, 1 ; Prepare to wait 1 timer tick
[155]91 jc SHORT Timer_DelayTimerTicksFromAX ; Event Wait was unsupported or busy
[140]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;
[155]100; Timer_DelayTimerTicksFromAX
[140]101; Parameters:
102; AX: Number of timer ticks to wait
103; Returns:
104; Nothing
105; Corrupts registers:
106; AX
107;--------------------------------------------------------------------
[155]108Timer_DelayTimerTicksFromAX:
[140]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
[155]115 jne SHORT .WaitLoop ; Loop until end time is reached
[140]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.