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

Last change on this file since 314 was 181, checked in by krille_n_@…, 13 years ago

Changes to all parts of the project:

  • Size optimizations.
  • Added a define (EXCLUDE_FROM_XTIDECFG) to exclude unused library code from XTIDECFG.
  • Tried to minimize time spent with interrupts disabled.
  • Some minor attempts to improve speed (reordering instructions etc).
  • Tried to improve readability, did some cleanup and fixed some errors in comments.
File size: 3.2 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; Timer_InitializeTimeoutWithTicksInCL
9; Parameters:
10; CL: Timeout value in system timer ticks
11; DS: Segment to RAMVARS
12; Returns:
13; Nothing
14; Corrupts registers:
15; CX
16;--------------------------------------------------------------------
17ALIGN JUMP_ALIGN
18Timer_InitializeTimeoutWithTicksInCL:
19 mov [RAMVARS.bTimeoutTicksLeft], cl ; Ticks until timeout
20 call ReadTimeFromBdaToCX
21 mov [RAMVARS.bLastTimeoutUpdate], cl ; Start time
22 ret
23
24
25;--------------------------------------------------------------------
26; Timer_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
36Timer_SetCFifTimeout:
37 call ReadTimeFromBdaToCX
38 cmp cl, [RAMVARS.bLastTimeoutUpdate]
39 je SHORT .StillPollingTheSameTick
40 mov [RAMVARS.bLastTimeoutUpdate], cl
41 sub BYTE [RAMVARS.bTimeoutTicksLeft], 1 ; DEC does not update CF
42.StillPollingTheSameTick:
43 ret
44
45
46;--------------------------------------------------------------------
47; Delay is always at least one millisecond since
48; RTC resolution is 977 microsecs.
49;
50; Timer_DelayMicrosecondsFromAX
51; Parameters:
52; AX: Number of microsecs to wait
53; Returns:
54; Nothing
55; Corrupts registers:
56; AX
57;--------------------------------------------------------------------
58Timer_DelayMicrosecondsFromAX:
59%ifndef USE_AT
60 mov ax, 2
61 ; Fall to Timer_DelayTimerTicksFromAX
62%else
63 push dx
64 push cx
65
66 xor cx, cx
67 xchg dx, ax ; Microsecs now in CX:DX
68 mov ah, EVENT_WAIT
69 int BIOS_SYSTEM_INTERRUPT_15h
70 sti ; XT BIOSes return with interrupts disabled. TODO: Maybe we can remove this since it's in an AT-only block?
71
72 pop cx
73 pop dx
74 mov ax, 1 ; Prepare to wait 1 timer tick
75 jc SHORT Timer_DelayTimerTicksFromAX ; Event Wait was unsupported or busy
76 ret
77%endif
78
79
80;--------------------------------------------------------------------
81; First tick might take 0...54.9 ms and remaining ticks
82; will occur at 54.9 ms intervals.
83;
84; Timer_DelayTimerTicksFromAX
85; Parameters:
86; AX: Number of timer ticks to wait
87; Returns:
88; Nothing
89; Corrupts registers:
90; AX
91;--------------------------------------------------------------------
92Timer_DelayTimerTicksFromAX:
93 sti ; Make sure that interrupts are enabled
94 call ReadTimeFromBdaToCX
95 add ax, cx ; AX = end time
96.WaitLoop:
97 call ReadTimeFromBdaToCX
98 cmp cx, ax
99 jne SHORT .WaitLoop ; Loop until end time is reached
100 ret
101
102
103;--------------------------------------------------------------------
104; ReadTimeFromBdaToCX
105; Parameters
106; Nothing
107; Returns:
108; CX: System time in 54.9 ms ticks
109; Corrupts registers:
110; Nothing
111;--------------------------------------------------------------------
112ALIGN JUMP_ALIGN
113ReadTimeFromBdaToCX:
114 push ds
115 LOAD_BDA_SEGMENT_TO ds, cx
116 mov cx, [BDA.dwTimerTicks] ; Read low WORD only
117 pop ds
118 ret
Note: See TracBrowser for help on using the repository browser.