[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 | ;--------------------------------------------------------------------
|
---|
[155] | 8 | ; Timer_InitializeTimeoutWithTicksInCL
|
---|
[140] | 9 | ; Parameters:
|
---|
[155] | 10 | ; CL: Timeout value in system timer ticks
|
---|
[140] | 11 | ; DS: Segment to RAMVARS
|
---|
| 12 | ; Returns:
|
---|
| 13 | ; Nothing
|
---|
| 14 | ; Corrupts registers:
|
---|
| 15 | ; CX
|
---|
| 16 | ;--------------------------------------------------------------------
|
---|
| 17 | ALIGN JUMP_ALIGN
|
---|
[155] | 18 | Timer_InitializeTimeoutWithTicksInCL:
|
---|
| 19 | mov [RAMVARS.bTimeoutTicksLeft], cl ; Ticks until timeout
|
---|
[140] | 20 | call ReadTimeFromBdaToCX
|
---|
[155] | 21 | mov [RAMVARS.bLastTimeoutUpdate], cl ; Start time
|
---|
[140] | 22 | ret
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 | ;--------------------------------------------------------------------
|
---|
[155] | 26 | ; Timer_SetCFifTimeout
|
---|
[140] | 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 | ;--------------------------------------------------------------------
|
---|
| 35 | ALIGN JUMP_ALIGN
|
---|
[155] | 36 | Timer_SetCFifTimeout:
|
---|
[140] | 37 | call ReadTimeFromBdaToCX
|
---|
[155] | 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:
|
---|
[140] | 43 | ret
|
---|
| 44 |
|
---|
| 45 |
|
---|
| 46 | ;--------------------------------------------------------------------
|
---|
| 47 | ; Delay is always at least one millisecond since
|
---|
| 48 | ; RTC resolution is 977 microsecs.
|
---|
| 49 | ;
|
---|
[155] | 50 | ; Timer_DelayMicrosecondsFromAX
|
---|
[140] | 51 | ; Parameters:
|
---|
| 52 | ; AX: Number of microsecs to wait
|
---|
| 53 | ; Returns:
|
---|
| 54 | ; Nothing
|
---|
| 55 | ; Corrupts registers:
|
---|
| 56 | ; AX
|
---|
| 57 | ;--------------------------------------------------------------------
|
---|
[155] | 58 | Timer_DelayMicrosecondsFromAX:
|
---|
[140] | 59 | %ifndef USE_AT
|
---|
[150] | 60 | mov ax, 2
|
---|
[181] | 61 | ; Fall to Timer_DelayTimerTicksFromAX
|
---|
[140] | 62 | %else
|
---|
| 63 | push dx
|
---|
| 64 | push cx
|
---|
| 65 |
|
---|
| 66 | xor cx, cx
|
---|
[148] | 67 | xchg dx, ax ; Microsecs now in CX:DX
|
---|
[140] | 68 | mov ah, EVENT_WAIT
|
---|
| 69 | int BIOS_SYSTEM_INTERRUPT_15h
|
---|
[181] | 70 | sti ; XT BIOSes return with interrupts disabled. TODO: Maybe we can remove this since it's in an AT-only block?
|
---|
[140] | 71 |
|
---|
| 72 | pop cx
|
---|
| 73 | pop dx
|
---|
[148] | 74 | mov ax, 1 ; Prepare to wait 1 timer tick
|
---|
[155] | 75 | jc SHORT Timer_DelayTimerTicksFromAX ; Event Wait was unsupported or busy
|
---|
[140] | 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 | ;
|
---|
[155] | 84 | ; Timer_DelayTimerTicksFromAX
|
---|
[140] | 85 | ; Parameters:
|
---|
| 86 | ; AX: Number of timer ticks to wait
|
---|
| 87 | ; Returns:
|
---|
| 88 | ; Nothing
|
---|
| 89 | ; Corrupts registers:
|
---|
| 90 | ; AX
|
---|
| 91 | ;--------------------------------------------------------------------
|
---|
[155] | 92 | Timer_DelayTimerTicksFromAX:
|
---|
[140] | 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
|
---|
[155] | 99 | jne SHORT .WaitLoop ; Loop until end time is reached
|
---|
[140] | 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 | ;--------------------------------------------------------------------
|
---|
| 112 | ALIGN JUMP_ALIGN
|
---|
| 113 | ReadTimeFromBdaToCX:
|
---|
| 114 | push ds
|
---|
| 115 | LOAD_BDA_SEGMENT_TO ds, cx
|
---|
| 116 | mov cx, [BDA.dwTimerTicks] ; Read low WORD only
|
---|
| 117 | pop ds
|
---|
| 118 | ret
|
---|