{to make a color bitmap from 640*480 graphics screen}
{declare  var  outFile:text; also assign filename , rewrite, and close file}
procedure writeBitmap;
var i,j:integer;
begin
write(outFile,'BM'); {bitmaps start with "BM"}
write(outFile,chr(54),chr(180),chr(4),chr(0)); {size of file = 54+(4*16)+(640*480)  }
write(outFile,chr(0),chr(0),chr(0),chr(0)); {identifies our application}
write(outFile,chr(118),chr(0),chr(0),chr(0)); {offset to start = 54 + 4*16}
write(outFile,chr(40),chr(0),chr(0),chr(0)); {header size}
write(outFile,chr(128),chr(2),chr(0),chr(0)); {width = 640}
write(outFile,chr(224),chr(1),chr(0),chr(0)); {height = 480}
write(outFile,chr(1),chr(0)); {color planes}
write(outFile,chr(4),chr(0)); {color depth in bits}
write(outFile,chr(0),chr(0),chr(0),chr(0)); {compression method = none}
write(outFile,chr(0),chr(88),chr(2),chr(0)); {image size = 640*480/2-pix/byte }
write(outFile,chr(194),chr(30),chr(0),chr(0));{horizontal resolution ???}
write(outFile,chr(194),chr(30),chr(0),chr(0)); {vertical res.???}
write(outFile,chr(16),chr(0),chr(0),chr(0)); {colors used = 16}
write(outFile,chr(0),chr(0),chr(0),chr(0)); {important colors}
{color palette}
write(outFile,chr(0),chr(0),chr(0),chr(0)); {color0 will be 0blue, 0green and 0red}
write(outFile,chr(128),chr(0),chr(0),chr(0));{color1 = blue}
write(outFile,chr(0),chr(128),chr(0),chr(0));{color2 = green}
write(outFile,chr(128),chr(128),chr(0),chr(0));{color3 = cyan}
write(outFile,chr(0),chr(0),chr(128),chr(0));{color4 = red}
write(outFile,chr(128),chr(0),chr(128),chr(0)); {color5 = magenta}
write(outFile,chr(0),chr(128),chr(128),chr(0)); {color6 = brown}
write(outFile,chr(192),chr(192),chr(192),chr(0)); {color7 = lightGray}
write(outFile,chr(128),chr(128),chr(128),chr(0)); {color8 = darkGray}
write(outFile,chr(255),chr(0),chr(0),chr(0)); {color9 = lightBlue}
write(outFile,chr(0),chr(255),chr(0),chr(0)); {color10 = lightGreen}
write(outFile,chr(255),chr(255),chr(0),chr(0)); {color11 = lightCyan}
write(outFile,chr(0),chr(0),chr(255),chr(0)); {color12 = lightRed}
write(outFile,chr(255),chr(0),chr(255),chr(0)); {color13 = lightMagenta}
write(outFile,chr(0),chr(255),chr(255),chr(0)); {color14 = yellow}
write(outFile,chr(255),chr(255),chr(255),chr(0)); {color15 = white}

for j:=479 downto 0 do for i:=0 to 639 div 2 do
    write(outFile,chr(16*getPixel(2*i,j)+ getPixel(2*i+1,j)));
end;