UNIT COOLUTIL;
INTERFACE
procedure loadhm5(name:string;sgm,ofs,size:word);
procedure seekret;
procedure moved(source,dest:pointer;size:word);
procedure setpal(pal:pointer);

IMPLEMENTATION
procedure loadhm5(name:string;sgm,ofs,size:word);
var f:file;
begin
  assign(f,name);
  reset(f,1);
  blockread(f,mem[sgm:ofs],1000);{1000 byte mll}
  blockread(f,mem[sgm:ofs],size);
  close(f);
end;

procedure seekret;assembler;
asm
  @retracefind:
    mov dx,3dah   {bit3:1-retrace}
    in al,dx
    and al,00001000b
  jz @retracefind  {retracestart}
  @retracewait:
    in al,dx
    and al,00001000b
  jnz @retracewait
end;

procedure moved(source,dest:pointer;size:word);
begin             {Beide asm-Routinen sind Ersatz fr MOVE}
  asm
    push ds
    les di,dest
    lds si,source
    mov cx,size
    shr cx,2

   @repmovsd:
    {  db $f3   {rep}
      db $66
      db $a5 {rep movsd:17sec; rep movsw:25sec; rep movsb:46sec}
      dec cx        {rep movsd+seekret:23sec; original:59sec !!}
    jnz @repmovsd          {=> effektiv 3.47 mal so schnell    }

    pop ds
  end;
end;

procedure setpal(pal:pointer);
var i:word;
begin
  for i:=0 to 255 do begin
    port[$3c8]:=i;
    port[$3c9]:=mem[seg(pal^):ofs(pal^)+i*3+0];
    port[$3c9]:=mem[seg(pal^):ofs(pal^)+i*3+1];
    port[$3c9]:=mem[seg(pal^):ofs(pal^)+i*3+2];
  end;
end;

begin
end.