home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer 9 / 1995-08_Disc_9.iso / vesa / samples / vesalist.pas < prev    next >
Pascal/Delphi Source File  |  1990-04-17  |  15KB  |  474 lines

  1. {-----------------------------------------------------------------------}
  2. {VESALIST                        GL:12/18/89    }
  3. {-----------------------------------------------------------------------}
  4. {-----------------------------------------------------------------------}
  5. {The following program is written to loosely conform to the VESA     }
  6. {Super VGA BIOS Extension document VS891001.  The program is intended    }
  7. {as a demonstration and is not intended to be an example of a         }
  8. {high-performance implementations of the VESA standard.            }
  9. {If you find any omissions or errors, please report them to me on the     }
  10. {Everex Systems BBS at (415) 683-2984.                    }
  11. {                        Gary Lorensen        }
  12. {                        Everex Systems, Inc.    }
  13. {                        48571 Milmont Dr. B3    }
  14. {                        Fremont, CA   94538    }
  15. {-----------------------------------------------------------------------}
  16.  
  17. uses
  18.     dos;
  19.  
  20. {-----------------------------------------------------------------------}
  21. {-----------------------------------------------------------------------}
  22.  
  23. type
  24.     s80 = string[80];
  25.     s8  = string[8];
  26.  
  27.     CharString = array [$00..$03] of char;
  28.  
  29.     ModeListType = array [$00..$00] of word;
  30.  
  31.     PageFuncPtrType = pointer;
  32.  
  33.     VgaInfoBlockType = record
  34.         VESASignature    : CharString;
  35.     VESAVersion     : word;
  36.     OEMStringPtr    : ^CharString;
  37.     Capabilities    : array [$00..$03] of byte;
  38.     VideoModePtr    : ^ModeListType;
  39.     reserved    : array [$00..$ED] of byte;    {Pad to 256}
  40.     end;
  41.  
  42.     ModeInfoBlockType = record
  43.                      {mandatory information}
  44.     ModeAttributes    : word;
  45.     WinAAttributes    : byte;
  46.     WinBAttributes    : byte;
  47.     WinGranularity    : word;
  48.     WinSize        : word;
  49.     WinASegment    : word;
  50.     WinBSegment    : word;
  51.     WinFuncPtr    : PageFuncPtrType;
  52.     BytesPerScanLine : word;
  53.  
  54.                     {optional information}
  55.     XResolution    : word;
  56.     YResolution    : word;
  57.     XCharSize    : byte;
  58.     YCharSize    : byte;
  59.     NumberOfPlanes    : byte;
  60.     BitsPerPixel    : byte;
  61.     NumberOfBanks    : byte;
  62.     MemoryModel    : byte;
  63.     BankSize    : byte;
  64.     reserved    : array [$00..$E2] of byte;    {Pad to 256}
  65.     end;
  66.  
  67. {-----------------------------------------------------------------------}
  68. {-----------------------------------------------------------------------}
  69.  
  70. var
  71.     reg : Registers;
  72.     VesaVgaInfo : VgaInfoBlockType;
  73.     VesaModeInfo : ModeInfoBlockType;
  74.     i,j : word;
  75.     displayall : boolean;
  76.     verbose    : boolean;
  77.     skipmode   : boolean;
  78.  
  79. {-----------------------------------------------------------------------}
  80. {-----------------------------------------------------------------------}
  81.  
  82. function decval(ch : char) : byte;
  83.  
  84. begin
  85.     decval := 0;
  86.     if ((ch>='0') and (ch<='9')) then
  87.         decval := ord(ch)-ord('0');
  88.     if ((ch>='A') and (ch<='F')) then
  89.         decval := ord(ch)-ord('A')+$0A;
  90.     if ((ch>='a') and (ch<='f')) then
  91.         decval := ord(ch)-ord('a')+$0A;
  92. end;
  93.  
  94. function hex2dec(s : s80) : word;
  95.  
  96. var
  97.     i     : byte;
  98.     tmp   : word;
  99.     place : word;
  100.  
  101. begin
  102.     i := ord(s[0]);
  103.     place := 1;
  104.     tmp := 0;
  105.     while (i>0) do begin
  106.         tmp := tmp+place*decval(s[i]);
  107.     i:=i-1;
  108.     place := place*$10;
  109.     end;
  110.     hex2dec := tmp;
  111. {    writeln('hex2dec(',s,') = ',tmp);}
  112. end;
  113.  
  114. {-----------------------------------------------------------------------}
  115.  
  116. function hexval(x : byte) : char;
  117.  
  118. begin
  119.     hexval := '0';
  120.     if ((x>=0) and (x<=9)) then
  121.         hexval := chr(x+ord('0'));
  122.     if ((x>=10) and (x<=15)) then
  123.         hexval := chr(x-10+ord('A'));
  124. end;
  125.  
  126. function dec2hex(x : word) : s8;
  127.  
  128. var
  129.     tmp   : s8;
  130.     place : word;
  131.  
  132. begin
  133. {    tmp   := '0';}
  134.     tmp := ' ';
  135.     if (x>=$100) then
  136.         place := $1000
  137.     else
  138.         place := $10;
  139.  
  140.     repeat
  141.         tmp := tmp+hexval(x div place);
  142.     x := x mod place;
  143.     place := place div $10;
  144.     until (place=$0000);
  145.  
  146.     dec2hex := tmp+'h';
  147. end;
  148.  
  149.  
  150. function hex(x : word) : s8;
  151.  
  152. var
  153.     tmp   : s8;
  154.     place : word;
  155.  
  156. begin
  157.     tmp := '0';
  158.     if (x>=$100) then
  159.         place := $1000
  160.     else
  161.         place := $10;
  162.  
  163.     repeat
  164.         tmp := tmp+hexval(x div place);
  165.     x := x mod place;
  166.     place := place div $10;
  167.     until (place=$0000);
  168.  
  169.     hex := tmp+'h';
  170. end;
  171.  
  172. function addrhex(x : word) : s8;
  173.  
  174. var
  175.     tmp   : s8;
  176.     place : word;
  177.  
  178. begin
  179.     tmp := '';
  180.     place := $1000;
  181.  
  182.     repeat
  183.         tmp := tmp+hexval(x div place);
  184.     x := x mod place;
  185.     place := place div $10;
  186.     until (place=$0000);
  187.  
  188.     addrhex := tmp;
  189. end;
  190.  
  191. {-----------------------------------------------------------------------}
  192. {-----------------------------------------------------------------------}
  193.  
  194. begin
  195.     writeln;
  196.     writeln('VESALIST -- List modes supported by VESA BIOS Extension');
  197.     writeln;
  198.  
  199.     displayall := false;
  200.     verbose    := false;
  201.     if (ParamCount>0) then begin
  202.         displayall := ((ParamStr(1)='ALL') or (ParamStr(1)='all'));
  203.         verbose    := ((ParamStr(1)='VERBOSE') or (ParamStr(1)='verbose'));
  204.         if (ParamCount>1) then begin
  205.             displayall := displayall or ((ParamStr(2)='ALL') or (ParamStr(2)='all'));
  206.             verbose    := verbose or ((ParamStr(2)='VERBOSE') or (ParamStr(2)='verbose'));
  207.     end;
  208.     end;
  209.  
  210.     reg.AX := $4F00;
  211.     reg.ES := Seg(VesaVgaInfo);
  212.     reg.DI := Ofs(VesaVgaInfo);
  213.     intr($10,reg);
  214.  
  215.     if (reg.AL<>$4F) then begin
  216.         writeln('ERROR: VESA Function 00h: Return Super VGA Information not supported.');
  217.     halt(1);
  218.     end;
  219.  
  220.     if (reg.AH<>$00) then begin
  221.         writeln('ERROR: VESA Function 00h: Return Super VGA Information failed.');
  222.     halt(2);
  223.     end;
  224.  
  225.     writeln('---------------------------------------');
  226.     writeln;
  227.  
  228.     writeln('VESA VGA Information:');
  229.  
  230.     write('    VESA Signature: ');
  231.     writeln(VesaVgaInfo.VesaSignature);
  232.  
  233.     write('    VESA Version  : v');
  234.     write(VesaVgaInfo.VesaVersion div $100);
  235.     write('.');
  236.     write(VesaVgaInfo.VesaVersion mod $100);
  237.     writeln;
  238.  
  239.     write('    OEM String    : ');
  240.     i := $00;
  241.     while (VesaVgaInfo.OEMStringPtr^[i]<>#00) do begin
  242.         write(VesaVgaInfo.OEMStringPtr^[i]);
  243.     i:=i+1;
  244.     end;
  245.     writeln;
  246.  
  247.     if (verbose) then begin
  248.         write('    Capabilities  : ');
  249.         for j := $00 to $03 do
  250.             for i := $00 to $07 do
  251.             if ((VesaVgaInfo.Capabilities[j] and ($80 shr i))=$00) then
  252.                 write('0')
  253.             else
  254.                 write('1');
  255.         writeln;
  256.  
  257.         write  ('    Modes         : ');
  258.         i := $00;
  259.         while (VesaVgaInfo.VideoModePtr^[i]<>$FFFF) do begin
  260.             if ((i mod 8)=0) then begin
  261.             writeln;
  262.             write('        ');
  263.         end;
  264.             write(addrhex(VesaVgaInfo.VideoModePtr^[i]),'h ');
  265.         i:=i+1;
  266.         end;
  267.         writeln;
  268.     end; {verbose}
  269.  
  270.     writeln('---------------------------------------');
  271.     writeln;
  272.  
  273.     writeln('Mode Information:');
  274.  
  275.     i := $00;
  276.     while (VesaVgaInfo.VideoModePtr^[i]<>$FFFF) do begin
  277.  
  278.         skipmode := true;
  279.  
  280.         reg.AX := $4F01;
  281.     reg.CX := VesaVgaInfo.VideoModePtr^[i];
  282.         reg.ES := Seg(VesaModeInfo);
  283.         reg.DI := Ofs(VesaModeInfo);
  284.         intr($10,reg);
  285.  
  286.         if (reg.AL<>$4F) then begin
  287.             write('    ',addrhex(VesaVgaInfo.VideoModePtr^[i]),'h  ');
  288.             writeln('WARNING: Return Super VGA Mode Information not supported.');
  289.     end else if (reg.AH<>$00) then begin
  290.             write('    ',addrhex(VesaVgaInfo.VideoModePtr^[i]),'h  ');
  291.             writeln('WARNING: Return Super VGA Mode Information failed.');
  292.     end else begin
  293.  
  294.         if ((VesaModeInfo.ModeAttributes and $02)=$00) then begin
  295.  
  296.                 VesaModeInfo.XCharSize := $00;
  297.                 VesaModeInfo.YCharSize := $00;
  298.  
  299.             if ((VesaVgaInfo.VideoModePtr^[i] = $100)
  300.             or (VesaVgaInfo.VideoModePtr^[i] = $101)
  301.             or (VesaVgaInfo.VideoModePtr^[i] = $103)
  302.             or (VesaVgaInfo.VideoModePtr^[i] = $105)
  303.             or (VesaVgaInfo.VideoModePtr^[i] = $107)) then begin
  304.  
  305.                     VesaModeInfo.NumberOfPlanes := $01;
  306.                     VesaModeInfo.BitsPerPixel   := $08;
  307.                     VesaModeInfo.NumberOfBanks  := $01;
  308.                     VesaModeInfo.BankSize       := $00;
  309.                     VesaModeInfo.MemoryModel    := $04;
  310.         end else if ((VesaVgaInfo.VideoModePtr^[i] = $102)
  311.             or (VesaVgaInfo.VideoModePtr^[i] = $104)
  312.             or (VesaVgaInfo.VideoModePtr^[i] = $106)) then begin
  313.  
  314.                     VesaModeInfo.NumberOfPlanes := $04;
  315.                     VesaModeInfo.BitsPerPixel   := $04;
  316.                     VesaModeInfo.NumberOfBanks  := $01;
  317.                     VesaModeInfo.BankSize       := $00;
  318.                     VesaModeInfo.MemoryModel    := $03;
  319.         end else begin
  320.  
  321.                     VesaModeInfo.NumberOfPlanes := $00;
  322.                     VesaModeInfo.BitsPerPixel   := $00;
  323.                     VesaModeInfo.NumberOfBanks  := $00;
  324.                     VesaModeInfo.BankSize       := $00;
  325.                     VesaModeInfo.MemoryModel    := $FF;
  326.         end;
  327.  
  328.             case VesaVgaInfo.VideoModePtr^[i] of
  329.             $100 : begin
  330.                         VesaModeInfo.XResolution := 640;
  331.                         VesaModeInfo.YResolution := 400;
  332.             end;
  333.             $101 : begin
  334.                         VesaModeInfo.XResolution := 640;
  335.                         VesaModeInfo.YResolution := 480;
  336.             end;
  337.             $102,$103 : begin
  338.                         VesaModeInfo.XResolution := 800;
  339.                         VesaModeInfo.YResolution := 600;
  340.             end;
  341.             $104,$105 : begin
  342.                         VesaModeInfo.XResolution := 1024;
  343.                         VesaModeInfo.YResolution := 768;
  344.             end;
  345.             $106,$107 : begin
  346.                         VesaModeInfo.XResolution := 1280;
  347.                         VesaModeInfo.YResolution := 1024;
  348.             end;
  349.         end;
  350.         end;
  351.  
  352.         if ((displayall) or ((VesaModeInfo.ModeAttributes and $01)=$01)) then begin
  353.  
  354.             if ((VesaModeInfo.MemoryModel=$04)
  355.                 and (VesaModeInfo.NumberOfPlanes=1)
  356.                 and (VesaModeInfo.BitsPerPixel=8)
  357.                 and (VesaModeInfo.NumberOfBanks<=1)
  358.                 and (VesaModeInfo.BankSize=0)
  359.             ) then begin
  360.                     write('VESA256-> ',addrhex(VesaVgaInfo.VideoModePtr^[i]),'h  ');
  361.             skipmode := false;
  362.             end else if ((VesaModeInfo.MemoryModel=$05)
  363.                 and (VesaModeInfo.NumberOfPlanes=1)
  364.                 and (VesaModeInfo.BitsPerPixel=8)
  365.                 and (VesaModeInfo.NumberOfBanks<=1)
  366.                 and (VesaModeInfo.BankSize=0)
  367.             ) then begin
  368.                     write('SEQU256->',addrhex(VesaVgaInfo.VideoModePtr^[i]),'h  ');
  369.             skipmode := false;
  370.             end else if ((VesaModeInfo.MemoryModel=$03)
  371.                 and (VesaModeInfo.NumberOfPlanes=4)
  372.                 and (VesaModeInfo.BitsPerPixel=4)
  373.                 and (VesaModeInfo.NumberOfBanks<=1)
  374.                 and (VesaModeInfo.BankSize=0)
  375.             ) then begin
  376.                     write('VESA16 -> ',addrhex(VesaVgaInfo.VideoModePtr^[i]),'h  ');
  377.             skipmode := false;
  378.             end else begin
  379.                 if (displayall) then
  380.                         write('          ',addrhex(VesaVgaInfo.VideoModePtr^[i]),'h  ');
  381.             end;
  382.  
  383.             if (displayall) or not(skipmode) then begin
  384.                 write(VesaModeInfo.XResolution:4,'x',VesaModeInfo.YResolution:3);
  385.                 if ((VesaModeInfo.ModeAttributes and $10)=$10) then
  386.                     write('x',VesaModeInfo.NumberOfPlanes:1)
  387.                 else
  388.                     write('  ');
  389.                 write(' ',VesaModeInfo.BitsPerPixel:1,'bpp');
  390.                 write(VesaModeInfo.XCharSize:2,'x',VesaModeInfo.YCharSize:2);
  391.                 write(' ');
  392.  
  393.                 if ((VesaModeInfo.ModeAttributes and $08)=$08) then
  394.                     write('Color ')
  395.                 else
  396.                     write('Mono  ');
  397.  
  398.             if (verbose) then begin
  399.                     if (VesaModeInfo.BankSize>0) then 
  400.                         write(' ',VesaModeInfo.BankSize:2,'Kx',VesaModeInfo.NumberOfBanks:1);
  401.  
  402.                     if ((VesaModeInfo.WinAAttributes and $01)=$01) then begin
  403.                         write('A:',addrhex(VesaModeInfo.WinASegment),' ');
  404.                     if ((VesaModeInfo.WinAAttributes and $02)=$02) then
  405.                         write('R')
  406.                     else 
  407.                         write(' ');
  408.                     if ((VesaModeInfo.WinAAttributes and $04)=$04) then
  409.                         write('W')
  410.                     else 
  411.                         write(' ');
  412.                     end else
  413.                         write('         ');
  414.  
  415.                     if ((VesaModeInfo.WinBAttributes and $01)=$01) then begin
  416.                         write('B:',addrhex(VesaModeInfo.WinBSegment),' ');
  417.                     if ((VesaModeInfo.WinBAttributes and $02)=$02) then
  418.                         write('R')
  419.                     else 
  420.                         write(' ');
  421.                     if ((VesaModeInfo.WinBAttributes and $04)=$04) then
  422.                         write('W')
  423.                     else 
  424.                         write(' ');
  425.                     end else
  426.                         write('         ');
  427.             end; {verbose}
  428.  
  429.                 case (VesaModeInfo.MemoryModel) of
  430.                     $00 : write('Text');
  431.                     $01 : write('CGA Grfx');
  432.                     $02 : write('HGC Grfx');
  433.                     $03 : write('16 Grfx');
  434.                     $04 : write('Packed Pixel Grfx');
  435.                     $05 : write('Sequ 256 Grfx');
  436.                     $06,$07,$08,$09,$0A,$0B,$0C,$0D,$0E,$0F
  437.                     : write('reserved for VESA');
  438.                 else
  439.                 write('OEM memory model');
  440.                 end;
  441.                 writeln;
  442.  
  443.             if (verbose) then begin
  444.                     write('          ');
  445.                     if ((VesaModeInfo.ModeAttributes and $01)=$01) then
  446.                         write('Present.     ')
  447.                     else
  448.                         write('Not present. ');
  449.  
  450.                     if ((VesaModeInfo.ModeAttributes and $04)=$04) then
  451.                         write('BIOS.')
  452.                     else
  453.                         write('     ');
  454.  
  455.                     write(' ',VesaModeInfo.BytesPerScanLine:3,' raster. ');
  456.  
  457.                     write('Win:');
  458.                     write(VesaModeInfo.WinSize:2,'Kx');
  459.                     write(VesaModeInfo.WinSize:2,'K  ');
  460.                     write('WinFunc: ',addrhex(Seg(VesaModeInfo.WinFuncPtr^)));
  461.                     write(':',addrhex(Ofs(VesaModeInfo.WinFuncPtr^)));
  462.  
  463.                     writeln;
  464.             end; {verbose}
  465.             end; {displayall}
  466.         end; {displayall}
  467.     end;
  468.     i:=i+1;
  469.     end;
  470. end.
  471.  
  472. {-----------------------------------------------------------------------}
  473. {-----------------------------------------------------------------------}
  474.