|Dͻ
|D |5The Happy Hacker |D
|Dͼ

^C|0
^C|0|E~0Bits 'N PC's ^0|0
^C|0|F~0      by     ^0|0 
^C|0|F~0Daniel Tobias^0|0
^C|0 

   A few months ago, we outlined some methods you can use in your programs to 
detect various sorts of video adapters.  This is important, since there are a 
number of incompatibilities between different display types, so it is useful 
for a program to be able to tell what is being used.

   Unfortunately, it turned out that the method for detecting an EGA (Enhanced 
Graphics Adapter) we gave does not always work reliably.  We've found systems 
which have an EGA but turn up negative on the test, and conversely, systems 
without an EGA which show positive.  Hence, we went back to the drawing board 
and came up with a new, more reliable test. 

   This new test involves checking a particular memory location that is 
modified when you have an EGA, as part of the "patch" it does to your BIOS.  
This location is segment 0, offset $43 (hexadecimal).  It holds the most 
significant byte (MSB) of the segment to which Interrupt 10 calls are vectored.
If an EGA is present, this byte is set to $C?, where ? is an arbitrary hex 
digit.  Hence, you can check for the presence of an EGA with the following code
in Turbo Pascal:

^1  if (mem[$0000:$0043] and $F0) = $C0 then EGA := true else EGA := false

   In BASIC, it works like:

^1  DEF SEG 0: IF (PEEK(&H43) AND &HF0) = &HC0 THEN EGA = -1 ELSE EGA = 0

   In each of these examples, the variable EGA is "true" (a boolean True in 
Pascal, and the value -1 representing true in BASIC) if an EGA board is present,
allowing statements like "IF EGA THEN <do something>".

   This test shows only that an EGA is present, not that it is actually being 
used.  You might have both an EGA and a monochrome board hooked up at once, and
switch back and forth with the MODE command.  In this case, you can tell which 
board is actually being used by peeking at the BIOS video mode, in segment $40,
offset $49.  This has the value of 7 (since this is a single-digit number, it's
the same whether you're in hex or decimal) when a monochrome display is in use,
and other values when a color board of some sort is being used.

   Hence, using the above tricks, as well as the PCjr indicator mentioned in 
the earlier article, the following Turbo Pascal code will tell you what board 
is in use: 

^1  if mem[$FFFF:$000E] = $FD then
^1     writeln('The PCjr''s built-in video adapter is in use.')
^1  else if mem[$0040:$0049] = 7 then
^1     writeln('An MDA (Monochrome Display Adapter) is in use.')
^1  else if (mem[$0000:$0043] and $F0) = $C0 then
^1     writeln('An EGA (Extended Graphics Adapter) is in use.')
^1  else writeln('A CGA (Color Graphics Adapter) is in use.')

  This covers just about everything except Hercules monochrome graphics cards 
(which register as MDA's in these tests) and the new VGA standard for the IBM 
PS/2 models.  As we research further into such things, we'll report the results.
