 {~ Setting video modes of VESA-obeying SVGA cards ~}

program VModV; {by Jan Hollan, when learning video cards switching;
               Sets or shows video mode by using VESA standard services}
uses Dos,hdconv;
const cl=#13#10;
var
  reg : registers; j:integer;
  i, L: byte;
  Deci : longint;
  HexS : string[3];
  HexB : array [0..3] of byte absolute HexS;
  Pow : longint;

begin
if ParamCount=1 then
 begin
  if pos('?',paramstr(1))>0 then
   begin
    writeln(cl,
'vmodv [#]',cl,
cl,
'says or sets the VESA videomode. # is to be hexadecimal.',cl,
cl,
'(source code available at http://astro.sci.muni.cz/pub/hollan/programmes)'
);
    halt;
   end;
     Deci:= 0; Pow:=1;
     HexS:=ParamStr(1);
     L:= HexB[0]+1;  
     for  i:= 1 to HexB[0] do 
      begin
       if (HexB[L-i]<59) and (HexB[L-i]>47) then
          inc(Deci,(HexB[L-i]-48)*Pow)
       else
          if (HexB[L-i]<71) and (HexB[L-i]>64)  then
           inc(Deci,(HexB[L-i]-55)*Pow)
          else
           if (HexB[L-i]>96) and (HexB[L-i]<103) then
            inc(Deci,(HexB[L-i]-87)*Pow)
           else
            begin
             writeln(
'A hexadecimal number of video mode to be set (VGA or VESA) was wanted -- '+cl,
      HexS,' is no such number.');
             writeln(
'VModV (without any parameter) displays the current video mode'+cl+
'     (its VESA number).');
             halt
            end;
       Pow:=Pow*16
      end;
  reg.ax := $4f02;
  reg.bx := Deci;
  intr ($10, reg);
  if reg.ax=$004f then
   begin
    write(cl,cl,cl,cl,cl,cl,cl);
    Writeln('VESA video mode $',HexS,' = ',Deci:3,' has been chosen.');
    halt(1)
   end
  else
   begin
    writeln('VESA video mode $',HexS,' = ',Deci:3,' is not available.');
    halt(2)
   end
 end
else
 begin
  reg.ax := $4f03;
  intr ($10, reg);
  if reg.ax=$004f then
    writeln(' Current video mode (VGA or VESA) is: $ ',DecToHexP(reg.bx))
  else
    writeln(' The video card does not support VESA standard')
 end;
end.
