modern timers in DOS (32bit) (Developers)
Absolutely true!
> If you only want to measure time in a very fine-grained way, use the TSC.
> Every Intel CPU since at least Pentium had a time stamp counter and most
> other brands introduced one not much later. The time stamps typically have
> a very high resolution, for example CPU clock cycles, and processors may
> even compensate the counts for you when changing clock speeds in power
> saving modes.
If you need a resolution of 0.1 to 1 ms, just use the normal, unmodified int 8 timer and read the values of the timer at the events you are interested in. Here's my standard code:
;--- this returns timer value in ms
GetTimerValue proc uses es bx
mov es, [_0000H]
tryagain:
mov edx,es:[46ch]
mov al,0C2h ;read timer 0 status + value low/high
out 43h, al
xchg edx, edx
in al,40h
mov cl,al ;CL = status
xchg edx, edx
in al,40h
mov ah, al ;AH = value low
xchg edx, edx
in al,40h ;AL = value high
test cl,40h ;was latch valid?
jnz tryagain
cmp edx,es:[46ch] ;did an interrupt occur in the meantime?
jnz tryagain ;then do it again!
xchg al,ah
;--- usually (counter mode 3) the timer is set to count down *twice*!
;--- however, sometimes counter mode 2 is set!
mov ch,cl
and ch,0110B ;bit 1+2 relevant
cmp ch,0110B ;counter mode 3?
jnz @F
;--- in mode 3, PIN status of OUT0 will become bit 15
shr ax,1
and cl,80h
or ah, cl
@@:
;--- now the counter is in AX (counts from FFFF to 0000)
neg ax
;--- now the count is from 0 to FFFF
ret
GetTimerValue endp
;--- get timer value in ms in eax
gettimer proc
call GetTimerValue
;--- the timer ticks are in EDX:AX, timer counts down
;--- a 16bit value with 1,193,180 Hz -> 1193180/65536 = 18.20648 Hz
;--- which are 54.83 ms
;--- to convert in ms:
;--- 1. subticks in ms: AX / 1193
;--- 2. ticks in ms: EDX * 55
;--- 3. total 1+2
push edx
movzx eax,ax ;step 1
cdq
mov ecx, 1193
div ecx
mov ecx, eax
pop eax ;step 2
mov edx, 55
mul edx
add eax, ecx ;step 3
ret
gettimer endp
---
MS-DOS forever!
Complete thread:
- modern timers in DOS (32bit) - LowLevel, 05.05.2022, 11:11 (Developers)
- modern timers in DOS (32bit) - bretjohn, 05.05.2022, 19:05
- modern timers in DOS (32bit) - mceric, 05.05.2022, 20:53
- modern timers in DOS (32bit) - Japheth, 06.05.2022, 08:06
- modern timers in DOS (32bit) - LowLevel, 06.05.2022, 08:37
- modern timers in DOS (32bit) - LowLevel, 06.05.2022, 08:29
- modern timers in DOS (32bit) - RayeR, 18.05.2022, 22:40
- modern timers in DOS (32bit) - Japheth, 06.05.2022, 08:06
- modern timers in DOS (32bit) - LowLevel, 06.05.2022, 08:08
- modern timers in DOS (32bit) - bretjohn, 06.05.2022, 20:01
- modern timers in DOS (32bit) - tkchia, 08.05.2022, 17:57
- modern timers in DOS (32bit) - bretjohn, 06.05.2022, 20:01
- modern timers in DOS (32bit) - mceric, 05.05.2022, 20:53
- modern timers in DOS (32bit) - Laaca, 05.05.2022, 20:56
- modern timers in DOS (32bit) - LowLevel, 06.05.2022, 08:30
- modern timers in DOS (32bit) - bretjohn, 05.05.2022, 19:05