Program Cyber_fps2;
uses exec, sysutils, utility, intuition,agraphics,cybergraphics,timer,math;
var
win:PWindow;
done:Boolean=False;
Msg:PMessage;
pix_array:ARRAY[0..307199] of ULONG;
x,y:Integer;
color_part1,color_part2,color_part3:ULONG;
tr:PTimerequest;
tp:PMsgPort;
start_sec,end_sec:ULONG;
start_micro,end_micro:ULONG;
ptm:PTimeval;
test_time:float;
n:LongInt;
fps:float;
err:LongInt;
r,dir:UBYTE;
begin
tp:=createport(nil,0);
if tp=nil then
halt()
else
begin
tr:=PTimerequest(CreateExtIO(tp,Sizeof(TTimerequest)));
if tr=nil then
begin
deleteport(tp);
halt();
end
else
begin
err:=OpenDevice(TIMERNAME,UNIT_MICROHZ,PIORequest(tr),0);
if err<>0 then
begin
DeleteExtIO(PIORequest(tr));
DeletePort(tp);
halt();
end;
end;
end;
tr^.tr_Node.io_Command:=TR_GETSYSTIME;
win:=OpenWindowTags(nil,
[WA_InnerWidth,AsTag(640),
WA_InnerHeight,AsTag(480),
WA_MinWidth,AsTag(100),
WA_MinHeight,AsTag(100),
WA_Left,AsTag(300),
WA_Top,AsTag(50),
WA_Title,AsTag('My Window'),
WA_DepthGadget,AsTag(True),
WA_SizeGadget,AsTag(True),
WA_DragBar,AsTag(True),
WA_Flags,WFLG_Closegadget or WFLG_GIMMEZEROZERO,
WA_IDCMP,IDCMP_CLOSEWINDOW or IDCMP_REFRESHWINDOW,
TAG_END]);
randomize;
n:=0;
test_time:=0;
r:=0;
dir:=1;
DoIO(PIORequest(tr));
ptm:=@tr^.tr_time;
start_sec:=ptm^.tv_secs;
start_micro:=ptm^.tv_micro;
repeat
for y:=0 to 479 do
begin
for x:=0 to 639 do
begin
color_part1:=x+system.random(r);
color_part2:=y+system.random(r);
color_part3:=(x+y)+system.random(r);
pix_array[y*640+x]:=(color_part1 or color_part2 or color_part3) and $00FFFFFF;
end;
end;
if dir=1 then
begin
r:=r+1;
if r=50 then dir:=2;
end
else
begin
r:=r-1;
if r=0 then dir:=1;
end;
WritePixelArray(@pix_array,0,0,640*SizeOf(ULONG),win^.RPort,0,0,640,480,RECTFMT_ARGB);
DoIO(PIORequest(tr));
ptm:=@tr^.tr_time;
end_sec:=ptm^.tv_secs;
end_micro:=ptm^.tv_micro;
test_time:=end_sec-start_sec+(end_micro-start_micro)/1000000;
n:=n+1;
until test_time>50;
fps:=n/test_time;
writeln('start sec= ',start_sec,' start micro= ',start_micro);
writeln('end sec= ',end_sec,' end micro= ',end_micro);
writeln('test time= ',test_time:10:5);
writeln('fps= ',fps:10:5);
repeat
WaitPort(Win^.UserPort);
Msg:=GetMsg(Win^.UserPort);
case PIntuiMessage(Msg)^.IClass of
IDCMP_CloseWindow:
done:=True;
end;
ReplyMsg(Msg);
Until done;
CloseDevice(PIORequest(tr));
DeleteExtIO(PIORequest(tr));
DeletePort(tp);
CloseWindow(Win);
end.