{$N+,A+,G+,F+,D-,E-,L-,R-,S-,Q-,Y-,I-}
unit memory;

interface
TYPE
  Virtualscreen = Array[1..65535] of byte;
  Virscr = ^VirtualScreen;

  Virtual4096 = Array[1..5096] of byte;
  Vir4096 = ^Virtual4096;

  Font_fps = Array[1..1200] of byte;
  VirFont_fps = ^Font_fps;

var
 scr, scr2, scr3: virscr;
 pale: vir4096;
 fonte: virFont_fps;


PROCEDURE SetUpVirtual(VAR screenname:virscr;VAR add : word);
PROCEDURE SetUpVirtualPalette(VAR screenname:vir4096; VAR segpal:word; VAR ofspal:word);
PROCEDURE SetUpVirtualFont6x6_d(VAR screenname:virFont_fps; VAR segfont:word; VAR ofsfont:word);
procedure mem2mem(src_seg,src_ofs,  dst_seg,dst_ofs:word; len:longint);


implementation

PROCEDURE SetUpVirtual(VAR screenname:virscr;VAR add : word);
var n:word;
BEGIN
  GetMem (Screenname,65535);
  add := seg (Screenname^);
  for n:=0 to 65535 do mem[add:n]:=0;
END;

PROCEDURE SetUpVirtualPalette(VAR screenname:vir4096; VAR segpal:word; VAR ofspal:word);
var n:word;
BEGIN
  GetMem (Screenname,5096);
  segpal := seg (Screenname^);
  ofspal := ofs (Screenname^);
  for n:=0 to 5095 do mem[segpal:ofspal+n]:=0;
END;

PROCEDURE SetUpVirtualFont6x6_d(VAR screenname:virFont_fps; VAR segfont:word; VAR ofsfont:word);
var n:word;
BEGIN
  GetMem (Screenname, 1200);
  segfont := seg (Screenname^);
  ofsfont := ofs (Screenname^);
  for n:=0 to 1199 do mem[segfont:ofsfont+n]:=0;
END;



procedure mem2mem(src_seg,src_ofs,  dst_seg,dst_ofs:word; len:longint);
var lastbyte:word;
begin
if len>65535 then begin len:=65535; lastbyte:=1; end else lastbyte:=0;
asm
   push ds
   mov es, dst_seg
   mov di, dst_ofs
   mov si, src_ofs
   mov cx, word ptr len
   mov dx, cx
   and dx, 3
   add dx, lastbyte
   shr cx, 2
   mov ds, src_seg
   db $66; rep movsw
   mov cx, dx
   rep movsb
   pop ds
end;
end;


end.