
uses crt,gfx3,makes,tptimer;

{$i mem.pas}

var
image,i,back2,backpage : word;
q,peek: byte;
t1,t2 : longint;


Begin
asm
mov ax,13h
int 10h
end;

backpage:=malloc(64000);
back2:=malloc (64000);
image:=malloc (64000);
lpcx ('image4.pcx',image);

for i:=0 to 319 do mem[image:i]:=0;
for i:=0 to 319 do mem[image:199*320+i]:=0;

lpcx ('bw.pcx',backpage);
makesurf1 (backpage,256-64);

q:=0;
t1:=readtimer;
repeat
inc (q);

{for i:=0 to 64000-1 do Begin
peek:=mem[backpage:i];
if peek>q+30 then mem[back2:i]:=mem[image:i];
end;}

asm
mov es,backpage
mov di,i
mov al,es:[di]
mov peek,al
mov cx,64000
xor di,di

@loopa:
       mov es,backpage
       mov al,es:[di]
       add al,30
       cmp al,q
jb @skip                                {if peek>q+30 then}
       mov es,image
       mov al,es:[di]
       mov es,back2
       mov es:[di],al
@skip:
      inc di
loop @loopa
end;

for i:=1 to 99 do Begin
                    firelineupLEFT    (back2,i*320,160);
                    firelineupRIGHT   (back2,i*320+160,160);
                    firelinedownLEFT  (back2,i*320+31680,160);
                    firelinedownRIGHT
                     (back2,i*320+31680+160,160);
                   End;
{fire (back2);}

waitretrace;
flip32 (back2,sega000);
flip32 (back2,sega000);

until q>254;
t2:=readtimer;

textmode (co80);

writeln (1000000/(t2-t1)*q:0:4,' fps');

end.


