source: xtideuniversalbios/trunk/Assembly_Library/Src/Time/Delay.asm@ 45

Last change on this file since 45 was 42, checked in by Tomi Tilli, 14 years ago

Display Library no more produces CGA snow.

File size: 2.3 KB
RevLine 
[41]1; File name : Delay.asm
2; Project name : Assembly Library
3; Created date : 24.7.2010
4; Last update : 16.9.2010
5; Author : Tomi Tilli
6; Description : Delay functions.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; Mimimun delays (without fetching) with some CPU architectures:
13; 8088/8086: 17 cycles for jump + 5 cycles for last comparison
14; 286: 10 cycles for jump + 4 cycles for last comparison
15; 386: 13 cycles for jump + ? cycles for last comparison
16; 486: 7 cycles for jump + 6 cycles for last comparison
17;
18; DELAY_WITH_LOOP_INSTRUCTION
19; Parameters
20; CX: Loop iterations (0 is maximum delay with 65536 iterations)
21; Returns:
22; Nothing
23; Corrupts registers:
24; CX
25;--------------------------------------------------------------------
26%macro DELAY_WITH_LOOP_INSTRUCTION 0
27%%StartOfLoop:
28 loop %%StartOfLoop
29%endmacro
30
31
32;--------------------------------------------------------------------
33; Delay is always at least one millisecond since
34; RTC resolution is 977 microsecs.
35;
36; Delay_MicrosecondsFromAX
37; Parameters:
38; AX: Number of microsecs to wait
39; Returns:
40; Nothing
41; Corrupts registers:
42; AX
43;--------------------------------------------------------------------
44ALIGN JUMP_ALIGN
45Delay_MicrosecondsFromAX:
46 push dx
47 push cx
48
49 xor cx, cx
50 xchg dx, ax ; Microsecs now in CX:DX
51 mov ah, EVENT_WAIT ; Event Wait
52 int BIOS_SYSTEM_INTERRUPT_15h
53 sti ; XT BIOSes return with interrupt disabled
54
55 pop cx
56 pop dx
57 mov ax, 1 ; Prepare to wait 1 timer tick
58 jc SHORT Delay_TimerTicksFromAX ; Event Wait was unsupported or busy
59 ret
60
61
62;--------------------------------------------------------------------
63; First tick might take 0...54.9 ms and remaining ticks
64; will occur at 54.9 ms intervals.
65;
66; Delay_TimerTicksFromAX
67; Parameters:
68; AX: Number of timer ticks to wait
69; Returns:
70; Nothing
71; Corrupts registers:
72; AX
73;--------------------------------------------------------------------
74ALIGN JUMP_ALIGN
75Delay_TimerTicksFromAX:
76 push dx
77
[42]78 sti ; Make sure that interrupts are enabled
[41]79 xchg dx, ax
80 call TimerTicks_ReadFromBdaToAX
81 add dx, ax ; DX = end time
82.WaitLoop:
83 call TimerTicks_ReadFromBdaToAX
84 cmp ax, dx
85 jb SHORT .WaitLoop ; Loop until end time is reached
86
87 pop dx
88 ret
Note: See TracBrowser for help on using the repository browser.