I didn't clue in to it to send the 64 bit version because i wrote the 32 bit program in about within an hour and did not want to continue working on it and also i knew already they would find the clock cycle 64 bit macro code on the forum when you google it i was tired and just got back to checking the replies............... I sent this code because its exact frame rate (down to clock cycles used per frame) and saw the forum lacked an exact frame rate post and added it in a jiffy....... Here is the fastest conversion to 64 bit of the source code i can do from copy and paste and edit:
Also thought of something of a calculation of exact frame rate calculation down to the decimal point available......... let's see..... answer (possibly ) is fps*((1000/fps-calc1)*100/(1000/fps)/100) put that where it prints the frames per second with out the int() might give you whole number with decimal fraction exact frame rate or not, something like that :) i don't have 64 bit version of freebasic on my computer because i copied it over to 32bit and am working on a fmodex software Crazy Machine on sourceforge.net that won't work yet with the latest fmod library available until i sit down and convert it over (unless someone else reading this feels like posting such a thing)...... in the include file......... I gotta take a look at any function name changes in the new version of fmod before converting it over for example......
below is the new calculation for fps in 64 bit code:
Code: Select all
#include once "windows.bi"
screenres 1024,768,32
dim shared as longint counter_cycles
dim shared as integer _process_priority_class_, _thread_priority_
dim shared as longint total_cycles
dim shared totalcycles as longint
dim shared as integer _loop_count_, _loop_counter_
#macro COUNTER_BEGIN( loop_count, process_priority, thread_priority )
_loop_count_ = loop_count
_process_priority_class_ = GetPriorityClass(GetCurrentProcess())
_thread_priority_ = GetThreadPriority(GetCurrentThread())
SetPriorityClass(GetCurrentProcess(), process_priority)
SetThreadPriority(GetCurrentThread(), thread_priority)
_loop_counter_ = _loop_count_
asm
xor eax, eax
cpuid
rdtsc
push rdx
push rax
xor eax, eax
cpuid
.balign 16
0:
sub DWORD PTR _loop_counter_, 1
jnz 0b
xor eax, eax
cpuid
rdtsc
pop rcx
sub eax, ecx
pop rcx
sbb edx, ecx
push rdx
push rax
xor eax, eax
cpuid
rdtsc
push rdx
push rax
mov eax, _loop_count_
mov _loop_counter_, eax
xor eax, eax
cpuid
.balign 16
1:
end asm
#endmacro
#macro COUNTER_END()
asm
sub DWORD PTR _loop_counter_, 1
jnz 1b
xor eax, eax
cpuid
rdtsc
pop rcx
sub eax, ecx
pop rcx
sbb edx, ecx
pop rcx
sub eax, ecx
pop rcx
sbb edx, ecx
mov DWORD PTR [counter_cycles], eax
mov DWORD PTR [counter_cycles+4], edx
end asm
SetPriorityClass(GetCurrentProcess(),_process_priority_class_)
SetThreadPriority(GetCurrentThread(),_thread_priority_)
counter_cycles /= _loop_count_
#endmacro
dim fps as double
dim flag as byte
dim calc1 as double
dim key as string
dim lx as integer
dim ly as integer
fps=33
print"Calculating clock cycles per second on this machine............"
counter_begin(1,HIGH_PRIORITY_CLASS,2)
sleep (1000,1)
counter_end()
total_cycles=counter_cycles
print"Calculated: ";total_cycles;"Hz"
sleep (2000,1)
screenset 1,0
cls
screencopy
do
counter_begin(1,HIGH_PRIORITY_CLASS,2)
color rgb(int(rnd(1)*255)+1,int(rnd(1)*215)+1,0),rgb(int(rnd(1)*255)+1,int(rnd(1)*215)+1,0)
print".........Don't forsake love, love is your momma from above........"
lx=pos
ly=csrlin
color rgb(255,215,0),rgb(0,0,0)
locate 1,1:print"fps: ";fps*((1000/fps-calc1)*100/(1000/fps)/100);".......Let brotherly love continue......."
locate ly,lx
if fps<33 then flag=0
if flag=0 then fps=fps+.333
if flag=1 then fps=fps-.333
screencopy
key=inkey
if key=chr(27) then end
counter_end()
calc1=1000*(counter_cycles*100/total_cycles/100)
if (1000/fps-calc1)<0 then
flag=1
else
sleep (1000/fps-calc1,1)
end if
screencopy
loop
and 32 bit code version......
Code: Select all
#include once "windows.bi"
screenres 1024,768,32
dim shared as longint counter_cycles
dim shared as integer _process_priority_class_, _thread_priority_
dim shared as longint total_cycles
dim shared totalcycles as longint
dim shared as integer _loop_count_, _loop_counter_
#macro COUNTER_BEGIN( loop_count, process_priority, thread_priority )
_loop_count_ = loop_count
_process_priority_class_ = GetPriorityClass(GetCurrentProcess())
_thread_priority_ = GetThreadPriority(GetCurrentThread())
SetPriorityClass(GetCurrentProcess(), process_priority)
SetThreadPriority(GetCurrentThread(), thread_priority)
_loop_counter_ = _loop_count_
asm
xor eax, eax
cpuid
rdtsc
push edx
push eax
xor eax, eax
cpuid
.balign 16
0:
sub DWORD PTR _loop_counter_, 1
jnz 0b
xor eax, eax
cpuid
rdtsc
pop ecx
sub eax, ecx
pop ecx
sbb edx, ecx
push edx
push eax
xor eax, eax
cpuid
rdtsc
push edx
push eax
mov eax, _loop_count_
mov _loop_counter_, eax
xor eax, eax
cpuid
.balign 16
1:
end asm
#endmacro
#macro COUNTER_END()
asm
sub DWORD PTR _loop_counter_, 1
jnz 1b
xor eax, eax
cpuid
rdtsc
pop ecx
sub eax, ecx
pop ecx
sbb edx, ecx
pop ecx
sub eax, ecx
pop ecx
sbb edx, ecx
mov DWORD PTR [counter_cycles], eax
mov DWORD PTR [counter_cycles+4], edx
end asm
SetPriorityClass(GetCurrentProcess(),_process_priority_class_)
SetThreadPriority(GetCurrentThread(),_thread_priority_)
counter_cycles /= _loop_count_
#endmacro
dim fps as double
dim flag as byte
dim calc1 as double
dim key as string
dim lx as integer
dim ly as integer
fps=33
print"Calculating clock cycles per second on this machine............"
counter_begin(1,HIGH_PRIORITY_CLASS,2)
sleep (1000,1)
counter_end()
total_cycles=counter_cycles
print"Calculated: ";total_cycles;"Hz"
sleep (2000,1)
screenset 1,0
cls
screencopy
do
counter_begin(1,HIGH_PRIORITY_CLASS,2)
color rgb(int(rnd(1)*255)+1,int(rnd(1)*215)+1,0),rgb(int(rnd(1)*255)+1,int(rnd(1)*215)+1,0)
print".........Don't forsake love, love is your momma from above........"
lx=pos
ly=csrlin
color rgb(255,215,0),rgb(0,0,0)
locate 1,1:print"fps: ";fps*((1000/fps-calc1)*100/(1000/fps)/100);".......Let brotherly love continue......."
locate ly,lx
if fps<33 then flag=0
if flag=0 then fps=fps+.333
if flag=1 then fps=fps-.333
screencopy
key=inkey
if key=chr(27) then end
counter_end()
calc1=1000*(counter_cycles*100/total_cycles/100)
if (1000/fps-calc1)<0 then
flag=1
else
sleep (1000/fps-calc1,1)
end if
screencopy
loop