[41] | 1 | ; File name : TimerTicks.asm
|
---|
| 2 | ; Project name : Assembly Library
|
---|
| 3 | ; Created date : 24.7.2010
|
---|
| 4 | ; Last update : 3.8.2010
|
---|
| 5 | ; Author : Tomi Tilli
|
---|
| 6 | ; Description : Functions for system timer related operations.
|
---|
| 7 |
|
---|
| 8 | ; System timer ticks 18.2 times per second = 54.9 ms / tick
|
---|
| 9 | TICKS_PER_HOUR EQU 65520
|
---|
| 10 | TICKS_PER_MINUTE EQU 1092
|
---|
| 11 | TICKS_PER_SECOND EQU 18
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 | ; Section containing code
|
---|
| 15 | SECTION .text
|
---|
| 16 |
|
---|
| 17 | ;--------------------------------------------------------------------
|
---|
| 18 | ; TimerTicks_GetHoursToAXfromTicksInDXAX
|
---|
| 19 | ; TimerTicks_GetMinutesToAXfromTicksInDX
|
---|
| 20 | ; TimerTicks_GetSecondsToAXfromTicksInDX
|
---|
| 21 | ; Parameters
|
---|
| 22 | ; DX(:AX): Timer ticks to convert
|
---|
| 23 | ; Returns:
|
---|
| 24 | ; AX: Hours, minutes or seconds
|
---|
| 25 | ; DX: Remainder ticks
|
---|
| 26 | ; Corrupts registers:
|
---|
| 27 | ; CX
|
---|
| 28 | ;--------------------------------------------------------------------
|
---|
| 29 | ALIGN JUMP_ALIGN
|
---|
| 30 | TimerTicks_GetHoursToAXfromTicksInDXAX:
|
---|
| 31 | mov cx, TICKS_PER_HOUR
|
---|
| 32 | div cx ; Divide DX:AX by CX, Hours to AX, remainder ticks to DX
|
---|
| 33 | ret
|
---|
| 34 |
|
---|
| 35 | ALIGN JUMP_ALIGN
|
---|
| 36 | TimerTicks_GetMinutesToAXfromTicksInDX:
|
---|
| 37 | xor ax, ax
|
---|
| 38 | xchg ax, dx ; Ticks now in DX:AX
|
---|
| 39 | mov cx, TICKS_PER_MINUTE
|
---|
| 40 | div cx ; Divide DX:AX by CX, Minutes to AX, remainder ticks to DX
|
---|
| 41 | ret
|
---|
| 42 |
|
---|
| 43 | ALIGN JUMP_ALIGN
|
---|
| 44 | TimerTicks_GetSecondsToAXfromTicksInDX:
|
---|
| 45 | xchg ax, dx ; Ticks now in AX
|
---|
| 46 | mov cl, TICKS_PER_SECOND
|
---|
| 47 | div cl ; Divide AX by CL, Seconds to AL, remainder ticks to AH
|
---|
| 48 | xor dx, dx
|
---|
| 49 | xchg dl, ah ; Seconds in AX, remainder in DX
|
---|
| 50 | ret
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | ;--------------------------------------------------------------------
|
---|
| 54 | ; First tick might take 0...54.9 ms and remaining ticks
|
---|
| 55 | ; will occur at 54.9 ms intervals. Use delay of two (or more) ticks to
|
---|
| 56 | ; ensure at least 54.9 ms timeout.
|
---|
| 57 | ;
|
---|
| 58 | ; TimerTicks_InitializeTimeoutFromAX
|
---|
| 59 | ; Parameters:
|
---|
| 60 | ; AX: Timeout ticks (54.9 ms) before timeout
|
---|
| 61 | ; DS:BX: Ptr to timeout variable WORD
|
---|
| 62 | ; Returns:
|
---|
| 63 | ; [DS:BX]: Initialized for TimerTicks_SetCarryIfTimeoutFromDSBX
|
---|
| 64 | ; Corrupts registers:
|
---|
| 65 | ; AX
|
---|
| 66 | ;--------------------------------------------------------------------
|
---|
| 67 | ALIGN JUMP_ALIGN
|
---|
| 68 | TimerTicks_InitializeTimeoutFromAX:
|
---|
| 69 | mov [bx], ax ; Store timeout ticks
|
---|
| 70 | call TimerTicks_ReadFromBdaToAX
|
---|
| 71 | add [bx], ax ; Add latest time to timeout ticks
|
---|
| 72 | ret
|
---|
| 73 |
|
---|
| 74 | ;--------------------------------------------------------------------
|
---|
| 75 | ; Timeout counter can be initialized with TimerTicks_InitializeTimeoutFromAX.
|
---|
| 76 | ;
|
---|
| 77 | ; TimerTicks_SetCarryIfTimeoutFromDSBX
|
---|
| 78 | ; Parameters:
|
---|
| 79 | ; DS:BX: Ptr to timeout variable WORD
|
---|
| 80 | ; Returns:
|
---|
| 81 | ; CF: Set if timeout
|
---|
| 82 | ; Cleared if time left
|
---|
| 83 | ; Corrupts registers:
|
---|
| 84 | ; Nothing
|
---|
| 85 | ;--------------------------------------------------------------------
|
---|
| 86 | ALIGN JUMP_ALIGN
|
---|
| 87 | TimerTicks_SetCarryIfTimeoutFromDSBX:
|
---|
| 88 | push ax
|
---|
| 89 | call TimerTicks_ReadFromBdaToAX
|
---|
| 90 | cmp [bx], ax ; Set CF if timeout WORD is less than time
|
---|
| 91 | pop ax
|
---|
| 92 | ret
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | ;--------------------------------------------------------------------
|
---|
| 96 | ; TimerTicks_GetElapsedToAXandResetDSBX
|
---|
| 97 | ; Parameters
|
---|
| 98 | ; DS:BX: Ptr to WORD containing previous reset time
|
---|
| 99 | ; Returns:
|
---|
| 100 | ; AX: 54.9 ms ticks elapsed since last reset
|
---|
| 101 | ; [DS:BX]: Reset to latest time
|
---|
| 102 | ; Corrupts registers:
|
---|
| 103 | ; Nothing
|
---|
| 104 | ;--------------------------------------------------------------------
|
---|
| 105 | ALIGN JUMP_ALIGN
|
---|
| 106 | TimerTicks_GetElapsedToAXandResetDSBX:
|
---|
| 107 | call TimerTicks_ReadFromBdaToAX
|
---|
| 108 | push ax
|
---|
| 109 | sub ax, [bx]
|
---|
| 110 | pop WORD [bx] ; Latest time to [DS:BX]
|
---|
| 111 | ret
|
---|
| 112 |
|
---|
| 113 | ;--------------------------------------------------------------------
|
---|
| 114 | ; TimerTicks_GetElapsedToAXfromDSBX
|
---|
| 115 | ; Parameters
|
---|
| 116 | ; DS:BX: Ptr to WORD containing previous update time
|
---|
| 117 | ; Returns:
|
---|
| 118 | ; AX: 54.9 ms ticks elapsed since initializing [DS:BX]
|
---|
| 119 | ; Corrupts registers:
|
---|
| 120 | ; Nothing
|
---|
| 121 | ;--------------------------------------------------------------------
|
---|
| 122 | ALIGN JUMP_ALIGN
|
---|
| 123 | TimerTicks_GetElapsedToAXfromDSBX:
|
---|
| 124 | call TimerTicks_ReadFromBdaToAX
|
---|
| 125 | sub ax, [bx]
|
---|
| 126 | ret
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | ;--------------------------------------------------------------------
|
---|
| 130 | ; TimerTicks_ReadFromBdaToAX
|
---|
| 131 | ; Parameters
|
---|
| 132 | ; Nothing
|
---|
| 133 | ; Returns:
|
---|
| 134 | ; AX: System time in 54.9 ms ticks
|
---|
| 135 | ; Corrupts registers:
|
---|
| 136 | ; Nothing
|
---|
| 137 | ;--------------------------------------------------------------------
|
---|
| 138 | ALIGN JUMP_ALIGN
|
---|
| 139 | TimerTicks_ReadFromBdaToAX:
|
---|
| 140 | push ds
|
---|
| 141 |
|
---|
| 142 | LOAD_BDA_SEGMENT_TO ds, ax
|
---|
| 143 | mov ax, [BDA.dwTimerTicks] ; Read low WORD only
|
---|
| 144 |
|
---|
| 145 | pop ds
|
---|
| 146 | ret
|
---|