[41] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Functions for system timer related operations.
|
---|
| 3 |
|
---|
| 4 | ; System timer ticks 18.2 times per second = 54.9 ms / tick
|
---|
| 5 | TICKS_PER_HOUR EQU 65520
|
---|
| 6 | TICKS_PER_MINUTE EQU 1092
|
---|
| 7 | TICKS_PER_SECOND EQU 18
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | ; Section containing code
|
---|
| 11 | SECTION .text
|
---|
| 12 |
|
---|
| 13 | ;--------------------------------------------------------------------
|
---|
| 14 | ; TimerTicks_GetHoursToAXfromTicksInDXAX
|
---|
| 15 | ; TimerTicks_GetMinutesToAXfromTicksInDX
|
---|
| 16 | ; TimerTicks_GetSecondsToAXfromTicksInDX
|
---|
| 17 | ; Parameters
|
---|
| 18 | ; DX(:AX): Timer ticks to convert
|
---|
| 19 | ; Returns:
|
---|
| 20 | ; AX: Hours, minutes or seconds
|
---|
| 21 | ; DX: Remainder ticks
|
---|
| 22 | ; Corrupts registers:
|
---|
| 23 | ; CX
|
---|
| 24 | ;--------------------------------------------------------------------
|
---|
[131] | 25 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[370] | 26 | %ifndef EXCLUDE_FROM_XTIDECFG
|
---|
[41] | 27 | ALIGN JUMP_ALIGN
|
---|
| 28 | TimerTicks_GetHoursToAXfromTicksInDXAX:
|
---|
| 29 | mov cx, TICKS_PER_HOUR
|
---|
| 30 | div cx ; Divide DX:AX by CX, Hours to AX, remainder ticks to DX
|
---|
| 31 | ret
|
---|
[370] | 32 | %endif ; EXCLUDE_FROM_XTIDECFG
|
---|
[41] | 33 |
|
---|
| 34 | ALIGN JUMP_ALIGN
|
---|
| 35 | TimerTicks_GetMinutesToAXfromTicksInDX:
|
---|
| 36 | xor ax, ax
|
---|
| 37 | xchg ax, dx ; Ticks now in DX:AX
|
---|
| 38 | mov cx, TICKS_PER_MINUTE
|
---|
| 39 | div cx ; Divide DX:AX by CX, Minutes to AX, remainder ticks to DX
|
---|
| 40 | ret
|
---|
[370] | 41 | %endif ; EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[106] | 42 |
|
---|
[41] | 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
|
---|
[119] | 71 | add [bx], ax ; [bx] now contains end time for timeout
|
---|
[41] | 72 | ret
|
---|
| 73 |
|
---|
[60] | 74 |
|
---|
[41] | 75 | ;--------------------------------------------------------------------
|
---|
[60] | 76 | ; TimerTicks_GetTimeoutTicksLeftToAXfromDSBX
|
---|
[41] | 77 | ; Parameters:
|
---|
| 78 | ; DS:BX: Ptr to timeout variable WORD
|
---|
| 79 | ; Returns:
|
---|
[85] | 80 | ; AX: Number of ticks left before timeout
|
---|
[41] | 81 | ; CF: Set if timeout
|
---|
| 82 | ; Cleared if time left
|
---|
| 83 | ; Corrupts registers:
|
---|
| 84 | ; Nothing
|
---|
| 85 | ;--------------------------------------------------------------------
|
---|
| 86 | ALIGN JUMP_ALIGN
|
---|
[60] | 87 | TimerTicks_GetTimeoutTicksLeftToAXfromDSBX:
|
---|
| 88 | push dx
|
---|
| 89 | mov dx, [bx]
|
---|
[41] | 90 | call TimerTicks_ReadFromBdaToAX
|
---|
[60] | 91 | xchg ax, dx
|
---|
| 92 | sub ax, dx ; AX = End time - current time
|
---|
| 93 | pop dx
|
---|
[41] | 94 | ret
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | ;--------------------------------------------------------------------
|
---|
| 98 | ; TimerTicks_GetElapsedToAXandResetDSBX
|
---|
| 99 | ; Parameters
|
---|
| 100 | ; DS:BX: Ptr to WORD containing previous reset time
|
---|
| 101 | ; Returns:
|
---|
| 102 | ; AX: 54.9 ms ticks elapsed since last reset
|
---|
| 103 | ; [DS:BX]: Reset to latest time
|
---|
| 104 | ; Corrupts registers:
|
---|
| 105 | ; Nothing
|
---|
| 106 | ;--------------------------------------------------------------------
|
---|
[131] | 107 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[41] | 108 | ALIGN JUMP_ALIGN
|
---|
| 109 | TimerTicks_GetElapsedToAXandResetDSBX:
|
---|
| 110 | call TimerTicks_ReadFromBdaToAX
|
---|
| 111 | push ax
|
---|
| 112 | sub ax, [bx]
|
---|
| 113 | pop WORD [bx] ; Latest time to [DS:BX]
|
---|
| 114 | ret
|
---|
[131] | 115 | %endif
|
---|
[41] | 116 |
|
---|
| 117 | ;--------------------------------------------------------------------
|
---|
| 118 | ; TimerTicks_GetElapsedToAXfromDSBX
|
---|
| 119 | ; Parameters
|
---|
| 120 | ; DS:BX: Ptr to WORD containing previous update time
|
---|
| 121 | ; Returns:
|
---|
| 122 | ; AX: 54.9 ms ticks elapsed since initializing [DS:BX]
|
---|
| 123 | ; Corrupts registers:
|
---|
| 124 | ; Nothing
|
---|
| 125 | ;--------------------------------------------------------------------
|
---|
[131] | 126 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[41] | 127 | ALIGN JUMP_ALIGN
|
---|
| 128 | TimerTicks_GetElapsedToAXfromDSBX:
|
---|
| 129 | call TimerTicks_ReadFromBdaToAX
|
---|
| 130 | sub ax, [bx]
|
---|
| 131 | ret
|
---|
[131] | 132 | %endif
|
---|
[41] | 133 |
|
---|
| 134 |
|
---|
| 135 | ;--------------------------------------------------------------------
|
---|
| 136 | ; TimerTicks_ReadFromBdaToAX
|
---|
| 137 | ; Parameters
|
---|
| 138 | ; Nothing
|
---|
| 139 | ; Returns:
|
---|
| 140 | ; AX: System time in 54.9 ms ticks
|
---|
| 141 | ; Corrupts registers:
|
---|
| 142 | ; Nothing
|
---|
| 143 | ;--------------------------------------------------------------------
|
---|
| 144 | ALIGN JUMP_ALIGN
|
---|
| 145 | TimerTicks_ReadFromBdaToAX:
|
---|
| 146 | push ds
|
---|
| 147 |
|
---|
| 148 | LOAD_BDA_SEGMENT_TO ds, ax
|
---|
| 149 | mov ax, [BDA.dwTimerTicks] ; Read low WORD only
|
---|
| 150 |
|
---|
| 151 | pop ds
|
---|
| 152 | ret
|
---|