uses screen, memory, crt, dos;

const
VGA=$a000;

procedure setonecolor(c,r,g,b:byte);assembler;
asm
  mov dx,3c8h
  mov al,c
  out dx,al
  inc dx
  mov al,r
  out dx,al
  mov al,g
  out dx,al
  mov al,b
  out dx,al
end;

procedure readonecolor(c:byte;var r,g,b:byte);assembler;
asm
  mov dx,3c7h
  mov al,c
  out dx,al
  add dx,2
  in  al,dx
  les di,r
  mov [es:di],al
  in  al,dx
  les di,g
  mov [es:di],al
  in  al,dx
  les di,b
  mov [es:di],al
end;


var palitra, palitra2:array[0..767] of byte;


procedure save_palitra(name:string);
var fw1:file;
i:word;
z:byte;
begin
Assign(fw1, name);
Rewrite(fw1,1);
Reset(fw1, 1);
z:=0;
for i:=0 to 767 do begin
   BlockWrite(fw1, z, 1);
   BlockWrite(fw1, palitra[i], 1);
end;
Close(fw1);
end;


var
fw1,fw2:file;

c, i, x,y,n,m,yy,xx:word;
fr:file;
col, r,g,b:byte;
size:word;

begin
SetUpVirtual(scr,vaddr);
SetUpVirtual(scr2, vaddr2);
SetUpVirtual(scr3, vaddr3);

asm
mov ax, 13h
int 10h
end;
{
for n:=0 to 255 do begin
r:=round(cos(n/20)*31+32);
g:=round(cos(n/25+1)*31+32);
b:=round(cos(n/30+2)*21+42);
SetOneColor(n,r,g,b);

   palitra[n*3    ]:=r;
   palitra[n*3 +1 ]:=g;
   palitra[n*3 +2 ]:=b;
end;{}

{for n:=254 downto 1 do begin
r:=round(cos(n/40)*31+32);
g:=round(cos(n/40+1)*31+32);
b:=round(cos(n/60+2)*31+32);
SetOneColor(n,r,g,b);

   palitra[n*3    ]:=r;
   palitra[n*3 +1 ]:=g;
   palitra[n*3 +2 ]:=b;
end;{}


for n:=0 to 255 do begin
r:=round(cos(n/21)*31+32);
g:=round(cos(n/25+1)*31+32);
b:=round(cos(n/28+2)*31+32);
SetOneColor(n,r,g,b);

   palitra[n*3    ]:=r;
   palitra[n*3 +1 ]:=g;
   palitra[n*3 +2 ]:=b;
end;{}


for y:=0 to 199 do for x:=0 to 255 do mem[vga:x+y*320]:=x;



save_palitra('iferens3.pal');



readkey;

asm
mov ax, 3h
int 10h
end;

end.