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

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

Changes to Assembly Library:

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