uses screen, memory, crt, dos;

const
VGA=$a000;

procedure Fblur(where:word); assembler;
 asm
  mov es, where
  mov di, 0
  mov cx, 65535
  @here:
    xor dx, dx
    xor ax, ax
    mov dl, es:[di+1]
    mov al, es:[di-1]
    add dx, ax
    mov al, es:[di+320]
    add dx, ax
    mov al, es:[di-320]
    add dx, ax

    shr dx, 2
    mov es:[di], dl
    add di, 1
    dec cx
  jnz @here
 end;


Procedure CreateNoice(where:word);
var i,j:word;
begin
   RandSeed:=0;
   for i := 0 to 204 do for j := 0 to 319
   do mem[where:word(j+i*320)]:=byte(random(255));
end;

Procedure CreateBumpmap(from,  where,where2:word);
var  i,j:integer;
     nx,ny:shortint;
begin
for j := 0 to 199 do
for i := 0 to 319 do begin
  nx:=shortint(mem[from:word(i-2+j*320+640)]-mem[from:word(i+2+j*320+640)]);
  ny:=shortint(mem[from:word(i+(j-2)*320+640)]-mem[from:word(i+(j+2)*320+640)]);
  if j<100 then begin
    mem[where:word((i+j*320) shl 1)]:=byte(nx) and 254;
    mem[where:word((i+j*320) shl 1+1)]:=byte(ny);
    end
    else begin
    mem[where2:word((i+(j-100)*320) shl 1)]:=byte(nx) and 254;
    mem[where2:word((i+(j-100)*320) shl 1+1)]:=byte(ny);
    end;
 end;
end;


procedure save_data(name:string; size:longint; from:word);
var fw1:file;
i:word;
begin
Assign(fw1, name);
Rewrite(fw1,1);
Reset(fw1, 1);
for i:=0 to size-1 do BlockWrite(fw1, mem[from:i], 1);
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);

CreateNoice(vaddr3);{}
for i:=0 to 6 do Fblur(vaddr3);
CreateBumpMap(vaddr3, vaddr,vaddr2);


save_data('bump1.bin', 65536, vaddr);
save_data('bump2.bin', 65536, vaddr2);

   WriteLn('Done');

readkey;


end.