home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / CNFIG218.ZIP / ADAPTER.PAS next >
Encoding:
Pascal/Delphi Source File  |  1992-10-26  |  4.7 KB  |  120 lines

  1. unit adapter;
  2. {
  3. written by Michael D. McCall  ==>  M-McCall@bgu.edu
  4. }
  5. interface
  6.  
  7.     (******************************************************) function
  8. videoType : char;
  9.     {checks the active video adapter and returns:
  10.         U=Unknown
  11.         M=MCGA
  12.         V=VGA
  13.         E=EGA
  14.         C=CGA
  15.         H=Hercules
  16.         D=MDA
  17.      adapter type determined using techniques from
  18.      Programmer's Guide to PC & PS/2 VIDEO SYSTEMS by Richard Wilton
  19.     }
  20.  
  21.  
  22. implementation
  23.  
  24. var x : byte;
  25.     portAddress : word;
  26.  
  27.     (******************************************************) function
  28. is6845here : boolean;
  29.  
  30.     begin
  31.     inline (
  32.         $8B/$16/portAddress/ {mov DX, portAddress                           }
  33.         $B0/$0F/             {mov AL, 0F                                    }
  34.         $EE/                 {out DX, AL     select 6845 reg 0F (cursor low)}
  35.         $42/                 {inc DX                                        }
  36.         $EC/                 {in  AL, DX     current cursor low value       }
  37.         $88/$C4/             {mov AH, AL     preserve in AH                 }
  38.         $B0/$66/             {mov AL, 66     arbitrary value                }
  39.         $EE/                 {out DX, AL     try to write to 6845           }
  40.         $B9/$00/$01/         {mov CX, 100                                   }
  41. {here}  $E2/$FE/             {loop here      wait for 6845 to respond       }
  42.         $EC/                 {in  AL, DX                                    }
  43.         $86/$E0/             {xchg AH, AL    al=original, ah=returned       }
  44.         $EE/                 {out DX, AL     restore original value         }
  45.         $88/$26/x);          {mov turbo_variable_x, AH                      }
  46.     is6845here := x = $66;
  47.     end;
  48.  
  49.     (******************************************************) function
  50. isHERC : boolean;
  51.  
  52.     begin
  53.     portAddress := $3BA;   {CRT controller status port}
  54.     inline (
  55.         $8B/$16/portAddress/ {mov DX, portAddress                            }
  56.         $EC/                 {in  AL, DX                                     }
  57.         $24/$80/             {and AL, 80                                     }
  58.         $88/$C4/             {mov AH, AL           bit 7=vertical sync on HGC}
  59.         $B9/$00/$80/         {mov CX, 8000         do this 32768 times       }
  60. {here}  $EC/                 {in  AL, DX                                     }
  61.         $24/$80/             {and AL, 80                                     }
  62.         $38/$C4/             {cmp AH, AL           has bit 7 changed         }
  63.         $E1/$F9/             {loope here           wait for bit 7 to change  }
  64.         $A3/portAddress);    {mov portAddress, AX  bit 7 changes on a HERC   }
  65.     isHERC := hi (portAddress) <> lo (portAddress);
  66.     end;
  67.  
  68.     (******************************************************) function
  69. MDAvsHERC : char;
  70.  
  71.     begin
  72.     portAddress := $3B4;          { I/O port of MDA & HERC's CRT controller  }
  73.     if NOT is6845here then        { not Motorola 6845 means unknown adapter  }
  74.         MDAvsHERC := 'U'
  75.     else if isHERC then
  76.         MDAvsHERC := 'H'
  77.     else
  78.         MDAvsHERC := 'D';
  79.     end;
  80.  
  81.     (******************************************************) function
  82. videoType : char;
  83.  
  84.     begin
  85.     videoType := 'U';
  86.     {test for int $10 function $1A, found with VGAs and MCGAs}
  87.     inline (
  88.         $B8/$00/$1A/           {mov AX, 1A00}
  89.         $CD/$10/               {int 10}
  90.         $A2/x/                 {mov x, AL}
  91.         $88/$1E/portAddress);  {mov portAddress, BL}
  92.     if x = $1A then    { function $1A returns $1A in AL if supported  }
  93.         case lo (portAddress) of  { active adapter is returned in BL  }
  94.             1 : videoType := MDAvsHERC;
  95.             2 : videoType := 'C';
  96.          4, 5 : videoType := 'E';
  97.             6 : videoType := 'P';
  98.          7, 8 : videoType := 'V';
  99.          $A, $B, $C : videoType := 'M';
  100.         end
  101.     else              { function $1A is not supported  }
  102.         begin   { test for int $10 function $12, found with EGA's  }
  103.         inline (
  104.             $B3/$10/           {mov BL, 10       arbitrary value}
  105.             $B4/$12/           {mov AH, 12}
  106.             $CD/$10/           {int 10}
  107.             $88/$1E/x);        {mov x, BL}
  108.         if x <> $10 then   { if BL is changed by function 12, we have an EGA  }
  109.             videoType := 'E'
  110.         else
  111.             begin   {   test for CGA   }
  112.             portAddress := $3D4;   {I/O port of CGA CRT controller }
  113.             if is6845here then    {    is CGA    }
  114.                 videoType := 'C'
  115.             else
  116.                 videoType := MDAvsHERC;
  117.             end;
  118.         end;
  119.     end;
  120. end.