home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / imdisp79.zip / VESA.C < prev    next >
C/C++ Source or Header  |  1993-02-15  |  3KB  |  135 lines

  1. /***  IMDISP module VESA.C
  2.  
  3.         VESA contains the device dependent display routines for the
  4.     Color Graphics Adapter (CGA), the Enhanced Graphics Adapter (EGA),
  5.     the Professional Graphics Adapter (PGA) and the Video Graphics Array
  6.     (VGA).  The global variables that define the device are allocated
  7.     and initialized here.
  8.  
  9. ***/
  10.  
  11. #define __MSC
  12.  
  13. /* * * * INCLUDE files * * * */
  14.  
  15. #include <stdlib.h>
  16. #include <conio.h>
  17. #include <dos.h>
  18.  
  19. /* * * *  Defined Constants * * * */
  20.  
  21. #define VESA_Support                   0x4f
  22. #define VESA_Function_Supported        100
  23. #define VESA_Call_Successful             0
  24. #define VESA_Call_Failed                -1
  25. #define VESA_Function_Not_Supported    101
  26.  
  27. /* * * * External functions * * * */
  28.  
  29. /* * * * Function declarations * * * */
  30.  
  31. int    VESA_Get_Info(void);
  32. int    VESA_Set_Mode(int);
  33. int    VESA_Set_Page(unsigned int);
  34.  
  35. /* * * * Global Variables * * * */
  36.  
  37. typedef    unsigned int Word ;
  38. typedef    struct  VESA_Block
  39.     {
  40.        char    VESASignature[4];
  41.        Word    VESAVersion;
  42.        char    far *OEMStringPtr;
  43.        char    Capabilities[4];
  44.        int     far *VideoModePtr;
  45.        char    filler[238];        /* Pad to 256 */
  46.     } VESA_Block ;
  47.  
  48. static VESA_Block     *VESA_Info;
  49.  
  50. int VESA_Get_Info(void)
  51. {
  52.     union  REGS    inreg, outreg;
  53.     struct SREGS   segregs;
  54.     char           error;
  55.     char           status;
  56.  
  57.     segregs.es = FP_SEG( VESA_Info );
  58.     inreg.x.di = FP_OFF( VESA_Info );
  59.     inreg.x.ax = 0x4F00;
  60.     int86x (0x10, &inreg, &outreg, &segregs);
  61.  
  62.     error  = outreg.h.al;
  63.     status = outreg.h.ah;
  64.  
  65.     if (error != VESA_Support)
  66.        return (VESA_Function_Not_Supported);
  67.     else if (status != VESA_Call_Successful)
  68.        return (VESA_Call_Failed);
  69.     return(VESA_Call_Successful);
  70.  
  71. }
  72.  
  73. int    VESA_Set_Mode(int mode)
  74. {
  75.     int             error, status, scratch;
  76.     union  REGS     inreg, outreg;
  77.  
  78.     if (mode == -1)
  79.     {
  80.         status = VESA_Get_Info();
  81.         if (status == VESA_Call_Successful)
  82.         {
  83.             scratch = 0;
  84.             mode = 0;
  85.             while (scratch != 0x7fff)
  86.             {
  87.                scratch = *VESA_Info->VideoModePtr;
  88.                if (scratch > mode)
  89.                    mode = scratch ;
  90.                VESA_Info->VideoModePtr++;
  91.             }
  92.         }
  93.         else
  94.         {
  95.            exit(0);
  96.         }
  97.     }
  98.     inreg.x.ax = 0x4F02;  /* SVGA set video mode */
  99.     inreg.x.bx = mode;
  100.     int86 (0x10, &inreg, &outreg);
  101.  
  102.     if (error != VESA_Support)
  103.        return (VESA_Function_Not_Supported);
  104.     else if (status != VESA_Call_Successful)
  105.        return (VESA_Call_Failed);
  106.  
  107.     return(mode);
  108. }
  109.  
  110. int    VESA_Set_Page( unsigned int page )
  111. {
  112.  
  113.     union  REGS     inreg, outreg;
  114.     char   error;
  115.     char   status;
  116.  
  117.     inreg.x.ax = 0x4F05;    /* VESA Video memory window control */
  118.     inreg.x.bx = 0x0000;    /* select window 0 */
  119.     inreg.x.dx = page ;     /* set window position */
  120.     int86 (0x10, &inreg, &outreg);
  121.  
  122.     error  = outreg.h.al;
  123.     status = outreg.h.ah;
  124.  
  125.     if (error != VESA_Support)
  126.        return (VESA_Function_Not_Supported);
  127.     else if (status == VESA_Call_Successful)
  128.        return ( page );
  129.     else
  130.        return (VESA_Call_Failed);
  131.  
  132. }
  133.  
  134.  
  135.