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