home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 January / pcwk_01_1999.iso / Tajnepp / MCLK093 / VGA.H < prev   
C/C++ Source or Header  |  1997-06-15  |  7KB  |  232 lines

  1. #ifndef    __vga_h
  2.     #define __vga_h
  3. #include<string.h>
  4. #include<strstrea.h>
  5. #include"pci.h"
  6. /*    CHIPS header file                v0.93ß    06/15/97
  7.  *
  8.  *    Some major changes since v0.84...
  9.  *    I removed most <stdio.h> functions (sprintf, fprintf, etc.), and
  10.  *    (finally) replaced them with the more appropriate C++ stream methods.
  11.  *    .............
  12.  *    This header contains the necessary class structure VGA for my MCLK
  13.  *    program to manipulate.  Chipset specific classes (S3, Cirrus, etc.)
  14.  *    are defined in other header files, and are not necessary for MCLK.CPP
  15.  *
  16.  *    (If you wish to recompile the chips.lib file, you must compile
  17.  *     chips.cpp with chips.h.)
  18.  */
  19.  
  20. #define INITMSG(x) ostrstream msgout( x, sizeof( x ) )
  21.     // macro to quickly setup "msgout" method, printing-to-string
  22.  
  23. #define     TRUE        1
  24. #define     FALSE    0
  25.  
  26. #define    _CRindex    0x3D4    //    CRindex port-io address, color
  27. #define    _CRIO    0x3D5    //    CRIO port-io address, color
  28. #define    _SRindex    0x3C4    //    SRindex port-io address, color
  29. #define    _SRIO    0x3C5    //    SRIO port-io address, color
  30. #define    _GRindex    0x3CE    //    GRindex port-io address, color
  31. #define    _GRIO    0x3CF    //    GRIO port-io address, color
  32. #define    _DACmask    0x3C6    //    RS[1:0]=10 RAMDAC MASK port-io address
  33. #define _DACindexR    0x3C7    //    RS=11 RAMDAC read-index
  34. #define _DACindexW    0x3C8    //    RS=00 RAMDAC write-index
  35. #define    _DACIO    0x3C9    //    RS=01 read/write data port of RAMDAC
  36. #define    _OSC        14.31818    //    Reference oscillator frequency
  37.  
  38. #define _MAXOPTIONS    5
  39.     //    Maximum # of user-selectable choices
  40.  
  41.  
  42. #ifndef uchar
  43. typedef unsigned char uchar;
  44. typedef unsigned long ulong;
  45. typedef unsigned short uint;
  46. #endif
  47.  
  48. //    A structure for exchanging information about video hardware
  49. //    between the program and the underlying data structures
  50. typedef struct {
  51.     char make[ 80 ];        //    Examples... S3, Cirrus Logic, etc.
  52.     char chipset[ 80 ];        //    Examples... Trio64, GD-5428, etc.
  53.     char revision[ 80 ];    //    Examples... 01, 0A, etc.
  54. } vga_info;
  55.  
  56. #define _TEXTLENGTH 512
  57.  
  58. typedef struct    {
  59.     char text[ _TEXTLENGTH ];
  60.     char temp[ _TEXTLENGTH ];    //temporary work space
  61. }    message;
  62.  
  63.  
  64. #define _SET        1
  65. #define _GET        2
  66. #define _HELP        3
  67. #define _QUERY        4
  68.     //    Query will cause xxx::_fxnX( _QUERY ) to put a text-line
  69.     //    describing its operation (eg. "2 IO RDY wait state control")
  70.     //    into msg.text
  71.  
  72. class vga        {
  73. protected:
  74.     int parse_param( int index, uchar *parsed ); // Acquire 1 parameter
  75.     uchar shift( uchar in );    //    remaps shift(2) -> 3, and shift(3) -> 2
  76.     vga_info id;            // Video chipset identification
  77.     virtual void _mclk( int cmd );    //    Allow MCLK reprogramming
  78.     virtual void _fxn1( int cmd );
  79.     virtual void _fxn2( int cmd );    //    cmd = _GET, _SET, _HELP
  80.     virtual void _fxn3( int cmd );
  81.     virtual void _fxn4( int cmd );
  82.     virtual void _fxn5( int cmd );
  83.     char * bitstat( uchar bit );    //    Returns "ENABLE or DISABLE"
  84.  
  85.     /* Quick function for printing hex-numbers in "XX" format */
  86.     void hexout( ostrstream &deststr, int value );
  87.  
  88. public:
  89.     int num_param;        //    Number of parameters in input list
  90.     char **param;        //    List of parameters
  91.  
  92.     virtual message _info( void );    //    return SVGA information
  93.     vga( vga_info info );    // Constructor prototype,
  94.         //    set-up identification "info" structure -> vga_info id;
  95.     virtual ~vga() { ; } ;    // Destructor
  96.     message get_settings( void );    //    List user-changeable settings
  97.     vga_info get_info( void )    //    Inquire information of video chipset
  98.         {    return( id );    };
  99.         //    Returns information, like VGA name, chipset, revision
  100.     message get_vgahelp( void );    //    Returns general help message
  101.     message msg;        //    Text-buffer for return messages
  102.  
  103.     int status;        //    EXIT_FAILURE or EXIT_SUCCESS
  104.     void go( int fxn, int cmd );    //    Execute command,
  105.         //    where cmd == _SET, _GET, _HELP
  106.     char * version( void )    //    Returns software_revision in text-string
  107.         {    return "v093ß 06/15/97" ;    };
  108.  
  109.     uchar read_SR( uchar index ); // Reads VGA _SR register index,
  110.     void write_SR ( uchar index, uchar data );    // Writes VGA _SR register
  111.     uchar read_CR( uchar index );    // Reads VGA _CR register index
  112.     void write_CR ( uchar index, uchar data );    // Writes VGA _CR register
  113.     uchar read_bit ( int port, uchar index, uchar bit );
  114.         // Read single bit, bit = #bits from RIGHT -> 7654 3210
  115.           // intended for VGA indirect indexed registers
  116.     void write_bit( int port, uchar index, uchar bit, uchar data );
  117.         // Write single bit, bit = #bits from RIGHT -> 7654 3210
  118.           // intended for VGA indirect indexed registers
  119.      uchar read_bit ( int port, uchar bit );
  120.          // Read single bit from any standard port-io
  121.      void write_bit( int port, uchar bit, uchar data );
  122.          // Write single bit to any standard port-io
  123. };
  124.  
  125. //    Force auto-detection to check only these graphics controllers
  126. #define _AUTO        -1
  127. #define _FCIRRUS    1
  128. #define _FS3        2
  129. #define _FTSENG    3
  130. #define _FTRIDENT    4
  131. #define _FMATROX    5
  132.     //    for forcing auto-detection of _W32P...
  133.      //    Note, _FMATROX does not do anything so far...
  134.  
  135. class detect    {
  136. protected:
  137.     vga_info id;
  138.     vga *hardware;
  139.  
  140.      //  Added PCI-stuff v0.93
  141.     pci_bios_type *pci_bios;
  142.     pci_device_handle_type pci_vga;
  143.  
  144.     message msg;    //    char buffer for returning messages to caller
  145. public:
  146.     detect( void )
  147.         { hardware = NULL;    };        //    Constructor
  148.     message _help( int mode = _AUTO );    //    Help menu lists chipsets
  149.     vga * _find( int chipset = _AUTO, int family = _AUTO );
  150.         //    Detection routine, default is auto-detection
  151.     vga * _debug( int mode = _AUTO );    //    DEBUGGING purposes only!
  152.     vga * detect_cirrus( int mode = _AUTO );
  153.     vga * detect_s3( int mode = _AUTO );
  154.     vga * detect_tseng( int mode = _AUTO );        //    v0.93 added ET6000
  155.     vga * detect_trident( int mode = _AUTO );
  156.  
  157.     vga * detect_pci( int mode = _AUTO );    // v0.93 added PCI-detection
  158.          // So far, only Tseng Labs ET6000 and Cirrus GD5462/64 chipsets
  159.           // autodetected
  160. };
  161.  
  162. // Added word & dword structures v0.93
  163. #endif
  164. #ifndef    __dword_struct
  165.     #define __dword_struct
  166. union dword
  167. {
  168. public:
  169.     ulong dw;
  170.     struct    {
  171.           word w0;
  172.           word w1;
  173.      } w;
  174.  
  175.      struct    {
  176.          uchar b0;
  177.           uchar b1;
  178.           uchar b2;
  179.           uchar b3;
  180.      } b;
  181.  
  182.      // Constructors
  183.      dword( void )
  184.             {    dw = 0;    };
  185.     dword( ulong init_value )
  186.          {    dw = init_value;    };
  187.      dword( long init_value )
  188.          {    dw = (ulong)init_value;    };
  189.      dword( dword &init_dword )
  190.          {    dw = init_dword.dw;    };
  191.  
  192.      dword&
  193.     operator =( ulong value )
  194.     {
  195.         dw = value;
  196.         return *this;
  197.     };
  198. };
  199.  
  200. #endif
  201.  
  202. #ifndef   __word_struct
  203.     #define    __word_struct
  204.  
  205. union word
  206. {
  207. public:
  208.     uint w;
  209.  
  210.      struct    {
  211.          uchar b0;
  212.           uchar b1;
  213.      } b;
  214.  
  215.      // Constructors
  216.      word( void )
  217.             {    w = 0;    };
  218.     word( uint init_value )
  219.          {    w = init_value;    };
  220.      word( unsigned init_value )
  221.          {    w = (uint)init_value;    };
  222.      word( word &init_word )
  223.          {    w = init_word.w;    };
  224.  
  225.      word&
  226.     operator =( uint value )
  227.     {
  228.         w = value;
  229.         return *this;
  230.     };
  231. };
  232. #endif