source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HTimer.asm@ 154

Last change on this file since 154 was 150, checked in by Tomi Tilli, 13 years ago

Changes to XTIDE Universal BIOS:

  • Redesigned Disk Parameter Tables.
  • Code generalizations for supporting non-IDE devices in the future.
File size: 2.9 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Timeout and delay functions for INT 13h services.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; HTimer_InitializeTimeoutWithTicksInCX
9; Parameters:
10; CX: Timeout value in system timer ticks
11; DS: Segment to RAMVARS
12; Returns:
13; Nothing
14; Corrupts registers:
15; CX
16;--------------------------------------------------------------------
17ALIGN JUMP_ALIGN
18HTimer_InitializeTimeoutWithTicksInCX:
19 mov [RAMVARS.wTimeoutCounter], cx ; Store timeout ticks
20 call ReadTimeFromBdaToCX
21 add [RAMVARS.wTimeoutCounter], cx ; End time for timeout
22 ret
23
24
25;--------------------------------------------------------------------
26; HTimer_SetCFifTimeout
27; Parameters:
28; DS: Segment to RAMVARS
29; Returns:
30; CF: Set if timeout
31; Cleared if time left
32; Corrupts registers:
33; CX
34;--------------------------------------------------------------------
35ALIGN JUMP_ALIGN
36HTimer_SetCFifTimeout:
37 call ReadTimeFromBdaToCX
38 cmp [RAMVARS.wTimeoutCounter], cx
39 ret
40
41
42;--------------------------------------------------------------------
43; Delay is always at least one millisecond since
44; RTC resolution is 977 microsecs.
45;
46; HTimer_DelayMicrosecondsFromAX
47; Parameters:
48; AX: Number of microsecs to wait
49; Returns:
50; Nothing
51; Corrupts registers:
52; AX
53;--------------------------------------------------------------------
54HTimer_DelayMicrosecondsFromAX:
55%ifndef USE_AT
56 mov ax, 2
57 ; Fall to Delay_TimerTicksFromAX
58%else
59 push dx
60 push cx
61
62 xor cx, cx
63 xchg dx, ax ; Microsecs now in CX:DX
64 mov ah, EVENT_WAIT
65 int BIOS_SYSTEM_INTERRUPT_15h
66 sti ; XT BIOSes return with interrupt disabled
67
68 pop cx
69 pop dx
70 mov ax, 1 ; Prepare to wait 1 timer tick
71 jc SHORT HTimer_DelayTimerTicksFromAX ; Event Wait was unsupported or busy
72 ret
73%endif
74
75
76;--------------------------------------------------------------------
77; First tick might take 0...54.9 ms and remaining ticks
78; will occur at 54.9 ms intervals.
79;
80; HTimer_DelayTimerTicksFromAX
81; Parameters:
82; AX: Number of timer ticks to wait
83; Returns:
84; Nothing
85; Corrupts registers:
86; AX
87;--------------------------------------------------------------------
88HTimer_DelayTimerTicksFromAX:
89 sti ; Make sure that interrupts are enabled
90 call ReadTimeFromBdaToCX
91 add ax, cx ; AX = end time
92.WaitLoop:
93 call ReadTimeFromBdaToCX
94 cmp cx, ax
95 jb SHORT .WaitLoop ; Loop until end time is reached
96 ret
97
98
99;--------------------------------------------------------------------
100; ReadTimeFromBdaToCX
101; Parameters
102; Nothing
103; Returns:
104; CX: System time in 54.9 ms ticks
105; Corrupts registers:
106; Nothing
107;--------------------------------------------------------------------
108ALIGN JUMP_ALIGN
109ReadTimeFromBdaToCX:
110 push ds
111 LOAD_BDA_SEGMENT_TO ds, cx
112 mov cx, [BDA.dwTimerTicks] ; Read low WORD only
113 pop ds
114 ret
Note: See TracBrowser for help on using the repository browser.