program batmenu;

{       this program is invoked from the command line:

             menu title item1 item2 .... itemN

        You can then choose one of the items.  The program will
        set the DOS variable ERRORLEVEL, so that you can then
        perform an action in a BATCH file with the statement:

             IF ERRORLEVEL=2 GOTO PROG2:

        returns 0 if escape is pressed, otherwise the item number

        the menu will be automatically centered on the screen.


        Written by BJ Gleason
        Copyright 1992, BJ Gleason

}

uses dos;

var
   menus : string;
   l,x,y : integer;
   regs : registers;

begin
     { read the parameters from the command line }
     { add them to the menu string }

     menus := '';
     l := 0;
     for x:=1 to paramcount do
       begin
         menus := menus + paramstr(x) + chr(0);
         if length(paramstr(x))>l then l:=length(paramstr(x));
       end;
     menus := menus + chr(0);

     for x:=1 to length(menus) do
       if menus[x]='_' then menus[x] := ' ';

     { now call the internal ROM BIOS Menu functions }

     regs.ah := $0f;
     regs.al := 65;
     regs.bh := 0;
     regs.cx := 0;
     if l<36 then x:=(40-(l+4)) div 2 else x:=0;
     if paramcount<6 then y:=(8-(paramcount+1)) div 2 else y:=0;
     regs.dh := y;
     regs.dl := x;
     regs.ds := seg(menus);
     regs.si := ofs(menus)+1;
     regs.di := $0ffff;
     intr($60, regs);
     inc(regs.ax);
     halt(regs.ax and $0ff);
end.

