davidTrt83
10-12-2006, 12:03
Ciao a tutti, ho bisogno di un timer con risoluzione dell'ordine dei ms per un ambiente borland C++ v3.1, come lo posso ottenere?
grazie.
Ovviamente dipende dal sistema operativo...quindi riferendosi alle PAI di Windows devi puoi usare timeGetTime
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_timegettime.asp
davidTrt83
10-12-2006, 15:56
Ovviamente dipende dal sistema operativo...quindi riferendosi alle PAI di Windows devi puoi usare timeGetTime
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_timegettime.asp
Il compilatore č per dos... :( sto modificando un vecchio gioco.
Dr.Speed
11-12-2006, 00:23
mi inscrivo perche interessa anche a me :)
repne scasb
11-12-2006, 10:18
Ho disponibile delle routine in assembly x86 spero ti siano utili ugualmente:
Uso delle routine:
1) Chiamare una sola volta la routine Init_Timer (calcolo overhead del timer).
2) Per misurare un tempo utilizzare Timer_On per marcare l'inizio della misurazione.
3) Utilizzare Timer_Off per marcare la fine della misurazione.
4) Il tempo trascorso si trovera' nella variabile 'elapsed_time'.
5) La precisione del timer e' di 1193046.47111 -> (2^32)/3600. Ossia se in 'elapsed_time' si trovera' il valore di 1193046 sara' passato circa 1 secondo.
BIOS_SEGMENT EQU 40h
TIMER_OFFSET EQU 6Ch
Init_Timer proc near
pusha
call Timer_On
mov ds: dword ptr [overhead],0h
mov cx,10h
mov eax,ds: dword ptr [timer_start]
loop_overhead:
call Timer_On
call Timer_Off
loop loop_overhead
mov ds: dword ptr [timer_start],eax
call Timer_Off
mov eax,ds: dword ptr [elapsed_time]
shr eax,4h
mov ds: dword ptr [overhead],eax
popa
ret
Init_Timer endp
Timer_On proc near
push eax
push es
push BIOS_SEGMENT
pop es
pushf
mov al,34h
out 43h,al
call Delay
xor al,al
out 40h,al
call Delay
out 40h,al
pushf
sti
call Delay
call Delay
call Delay
popf
mov eax,es: dword ptr [TIMER_OFFSET]
mov ds: dword ptr [timer_start],eax
mov al,34h
out 43h,al
call Delay
xor al,al
out 40h,al
call Delay
out 40h,al
popf
pop es
pop eax
ret
Timer_On endp
Timer_Off proc near
pushf
push es
push BIOS_SEGMENT
pop es
push eax
sti
call Delay
call Delay
call Delay
mov al,34h
out 43h,al
call Delay
xor al,al
out 43h,al
cli
mov eax,es: dword ptr [TIMER_OFFSET]
sub eax,ds: dword ptr [timer_start]
shl eax,10h
in al,40h
call Delay
mov ah,al
in al,40h
xchg al,ah
neg ax
sti
sub eax,ds: dword ptr [overhead]
mov ds: dword ptr [elapsed_time],eax
mov al,36h
out 43h,al
call Delay
xor al,al
out 40h,al
call Delay
out 40h,al
pop eax
pop es
popf
ret
Timer_Off endp
Delay proc near
jmp $+2h
jmp $+2h
jmp $+2h
jmp $+2h
jmp $+2h
jmp $+2h
jmp $+2h
jmp $+2h
ret
Delay endp
data segment byte 'DATA'
overhead:
DD ?
timer_start:
DD ?
elapsed_time:
DD ?
data ends
davidTrt83
11-12-2006, 10:44
Ho disponibile delle routine in assembly x86 spero ti siano utili ugualmente:
Uso delle routine:
1) Chiamare una sola volta la routine Init_Timer (calcolo overhead del timer).
2) Per misurare un tempo utilizzare Timer_On per marcare l'inizio della misurazione.
3) Utilizzare Timer_Off per marcare la fine della misurazione.
4) Il tempo trascorso si trovera' nella variabile 'elapsed_time'.
5) La precisione del timer e' di 1193046.47111 -> (2^32)/3600. Ossia se in 'elapsed_time' si trovera' il valore di 1193046 sara' passato circa 1 secondo.
FiGo :) , perņ non ho mai usato l'assembly quindi avrei bisogno di un minimo di aiuto, sempre che la cosa non č lunga e ti prenda troppo tempo.
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.