[41] | 1 | ; Project name : Assembly Library |
---|
| 2 | ; Description : Delay functions. |
---|
| 3 | |
---|
| 4 | ; Section containing code |
---|
| 5 | SECTION .text |
---|
| 6 | |
---|
| 7 | ;-------------------------------------------------------------------- |
---|
| 8 | ; Delay is always at least one millisecond since |
---|
| 9 | ; RTC resolution is 977 microsecs. |
---|
| 10 | ; |
---|
| 11 | ; Delay_MicrosecondsFromAX |
---|
| 12 | ; Parameters: |
---|
| 13 | ; AX: Number of microsecs to wait |
---|
| 14 | ; Returns: |
---|
| 15 | ; Nothing |
---|
| 16 | ; Corrupts registers: |
---|
| 17 | ; AX |
---|
| 18 | ;-------------------------------------------------------------------- |
---|
| 19 | ALIGN JUMP_ALIGN |
---|
| 20 | Delay_MicrosecondsFromAX: |
---|
| 21 | push dx |
---|
| 22 | push cx |
---|
| 23 | |
---|
| 24 | xor cx, cx |
---|
| 25 | xchg dx, ax ; Microsecs now in CX:DX |
---|
| 26 | mov ah, EVENT_WAIT ; Event Wait |
---|
| 27 | int BIOS_SYSTEM_INTERRUPT_15h |
---|
| 28 | sti ; XT BIOSes return with interrupt disabled |
---|
| 29 | |
---|
| 30 | pop cx |
---|
| 31 | pop dx |
---|
| 32 | mov ax, 1 ; Prepare to wait 1 timer tick |
---|
| 33 | jc SHORT Delay_TimerTicksFromAX ; Event Wait was unsupported or busy |
---|
| 34 | ret |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | ;-------------------------------------------------------------------- |
---|
| 38 | ; First tick might take 0...54.9 ms and remaining ticks |
---|
| 39 | ; will occur at 54.9 ms intervals. |
---|
| 40 | ; |
---|
| 41 | ; Delay_TimerTicksFromAX |
---|
| 42 | ; Parameters: |
---|
| 43 | ; AX: Number of timer ticks to wait |
---|
| 44 | ; Returns: |
---|
| 45 | ; Nothing |
---|
| 46 | ; Corrupts registers: |
---|
| 47 | ; AX |
---|
| 48 | ;-------------------------------------------------------------------- |
---|
| 49 | ALIGN JUMP_ALIGN |
---|
| 50 | Delay_TimerTicksFromAX: |
---|
| 51 | push dx |
---|
| 52 | |
---|
[42] | 53 | sti ; Make sure that interrupts are enabled |
---|
[41] | 54 | xchg dx, ax |
---|
| 55 | call TimerTicks_ReadFromBdaToAX |
---|
| 56 | add dx, ax ; DX = end time |
---|
| 57 | .WaitLoop: |
---|
| 58 | call TimerTicks_ReadFromBdaToAX |
---|
| 59 | cmp ax, dx |
---|
| 60 | jb SHORT .WaitLoop ; Loop until end time is reached |
---|
| 61 | |
---|
| 62 | pop dx |
---|
| 63 | ret |
---|