unit LCD;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Open1: TMenuItem;
    Exit1: TMenuItem;
    OpenDialog1: TOpenDialog;
    Label1: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Image1: TImage;
    Label5: TLabel;
    Label6: TLabel;
    SaveDialog1: TSaveDialog;
    procedure Open1Click(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Open1Click(Sender: TObject);
var
   F:textfile;
   s:byte;
   i,j,k,counter,totaal,line_number:integer;
   LCDbyte,previous:byte;
begin
if opendialog1.execute then
begin
     image1.picture.loadfromfile(opendialog1.filename);
     label3.caption:=inttostr(image1.width);
     label4.caption:=inttostr(image1.height);
     label1.caption:=opendialog1.filename;
     counter:=1;
     totaal:=0;
     assignfile(f,'test.a51');
     append(f);
     writeln(f,'     ORG 200H');
     writeln(f,'block');

     for j:=0 to image1.height-1 do
     begin
          i:=0;
          while i<image1.width do
          begin
               LCDbyte:=0;
               for k:=0 to 7 do
               begin
                    if image1.canvas.pixels[i,j]=0 then
                       LCDbyte:=LCDbyte shl 1 +1
                    else
                        LCDbyte:=LCDbyte shl 1;
                    i:=i+1;
               end; {for k}
               if counter=1 then
               begin
                    write(f,'     DB ');
                    write(f,inttostr(LCDbyte));

                    counter:=2;
               end
               else
                   if counter=20 then
                   begin
                        writeln(f,','+inttostr(LCDbyte));
                        counter:=1;
                   end
                   else
                   begin
                      counter:=counter+1;
                      write(f,','+inttostr(LCDbyte));

               end;

          end; {while}
     end; {for j}
writeln(f);     
writeln(f,'enddata');
writeln(f,'stop     SJMP stop') ;
writeln(f,'     END');

closefile(f);
end;
end;
procedure TForm1.Exit1Click(Sender: TObject);
begin
application.terminate;
end;

end.
