uses screen, memory, crt, dos, palette;
CONST
pattern: array[0..4*4-1] of byte =
(0,8,2,10, 12,4,14,6, 3,11,1,9, 15,7,13,5);


var
c, i, x,y,n,m,yy,xx:word;
fw1:text;
col, r,g,b:byte;
size:word;

begin
SetUpVirtual(scr,vaddr);
SetUpVirtual(scr2, vaddr2);
SetUpVirtual(scr3, vaddr3);
{
asm
mov ax, 13h
int 10h
end;
setonecolor(16, 15,30,60);{}

Assign(fw1, 'chunki.txt');
Rewrite(fw1);


for n:=0 to 15 do begin
WriteLn(fw1,'@n',n,':');
WriteLn(fw1,'mov ch, dh');
WriteLn(fw1,'@y',n,':');
WriteLn(fw1,'mov cl, dl');
WriteLn(fw1,'@x',n,':');
for y:=0 to 3 do begin
   for x:=0 to 3 do
   begin
      {if pattern[(x and 3)+(y and 3)*4]>=n then
      mem[vga:word(x+y*320+(n*4)*320   +150+320*50)]:= (n+1);}

      if pattern[(x and 3)+(y and 3)*4]>=n then
      WriteLn(fw1,'mov es:[di+', x+y*320 ,'], al');{}
   end;
end;
WriteLn(fw1,'add di, 4');
WriteLn(fw1,'dec cl');
WriteLn(fw1,'jnz @x',n);

WriteLn(fw1,'add di, bx');
WriteLn(fw1,'dec ch');
WriteLn(fw1,'jnz @y',n);
WriteLn(fw1,'jmp @next');
end;

WriteLn(fw1,'@next:');

Close(fw1);

readkey;

asm
mov ax, 3h
int 10h
end;

end.