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

  1. /***  IMDISP module EVGAIO.C
  2.  
  3.         EVGAIO contains the device dependent display routines for
  4.     the Everex EV-673 enhanced VGA board.  The code is taken from
  5.     demo routines in the Everex Software Developer's Kit.  This
  6.     module was adapted, coded and tested by:
  7.  
  8.           A. Warnock
  9.           ST Systems Corp
  10.           Mail Code 681
  11.           NASA/Goddard Space Flight Center
  12.           Greenbelt, MD.
  13.  
  14.      All bugs contained herein are mine and mine alone.
  15.  
  16. ***/
  17.  
  18. #define __MSC
  19.  
  20. /* If you are compiling using Microsoft C 4.0, remove this line  */
  21. /* and compile this using the /Zp option.                        */
  22.  
  23. #pragma pack(1)
  24.  
  25. /* * * * INCLUDE files * * * */
  26.  
  27. #include        <conio.h>
  28. #include        <dos.h>
  29. #include        <string.h>
  30. /*
  31. #include        "imdef.h"
  32. #include        "dispio.h"
  33. */
  34. #define         rWDacWrteAddr   0x3C8
  35. #define         rWDacData       0x3C9
  36. #define         rWAttrAddr      0x3C0
  37. #define         rWMiscOutp      0x3C2
  38. #define         rRMiscOutp      0x3CC
  39. #define         rWSequAddr      0x3C4
  40. #define         rWGrfxAddr      0x3CE
  41.  
  42. #define         DACSIZE         0xFF
  43. #define         TRUE            1
  44. #define         PALETTESIZE     16
  45.  
  46.  
  47. typedef unsigned char   byte;
  48. typedef unsigned int    word;
  49.  
  50. /* Function declarations for EVGAIO.C */
  51.  
  52.  
  53. /* * * * External functions * * * */
  54.  
  55. /* * * * Function declarations * * * */
  56.  
  57. void EVGAWritePixel256( int x, int y, int color);
  58. void EVGASetPage( byte page);
  59. void EVGAWritePixelEGA( int x, int y, byte color, int useBIOS);
  60. void EVGAClearDisplay( int DN);
  61.  
  62. /* * * * Global Variables * * * */
  63.  
  64.  
  65.  
  66.  
  67. void EVGAWritePixel256( int x, int y, int color)
  68.  
  69. /*--------------------------------------------------------------*/
  70. /* This function writes the specified color value to the pixel  */
  71. /* specified by (x,y).  It calculates the offset, sets the page */
  72. /* using EVGASetPage, and writes the pixel value directly.      */
  73. /*                                                              */
  74. /*--------------------------------------------------------------*/
  75.  
  76. {
  77.     void                EVGASetPage();
  78.  
  79.     word                crtcolumns;
  80.     word                far *mSysCrtColumns;
  81.     byte                far *pixelptr;
  82.     byte                page;
  83.     word                offset;
  84.     unsigned long       pixelnum;
  85.  
  86.         mSysCrtColumns = (word far *) 0x44A;
  87.         crtcolumns = (*mSysCrtColumns);
  88.  
  89.         pixelnum = (unsigned long) (8*(unsigned long) crtcolumns*y)+ x;
  90.         page     = pixelnum >> 0x10;
  91.         offset   = pixelnum & 0xFFFF;
  92.         EVGASetPage(page);
  93.         pixelptr = (byte far *) 0xA0000000 + offset;
  94.         *pixelptr = (unsigned char)color;
  95. } /*EVGAWritePixel256*/
  96.  
  97. /*--------------------------------------------------------------*/
  98. /* This function selects among the 4 segments in Everex Extended*/
  99. /* 256 color modes.  Page should be in the range 0..3.  Other   */
  100. /* values will be treated modulo 4.                             */
  101. /*--------------------------------------------------------------*/
  102.  
  103. void EVGASetPage( byte page)
  104.  
  105. {
  106.     byte        reg;
  107.  
  108.     outp(rWSequAddr,0x8);               /* Index Everex Control Register */
  109.     reg = inp(rWSequAddr+1);            /* Read its contents            */
  110.  
  111.     if( (page & 0x1) == 0x1)
  112.     {
  113.         reg = reg | 0x80;               /* Select between odd and even pages */
  114.     } else
  115.     {                                   /* (0,2) and (1,3) */
  116.         reg = reg & 0x7F;
  117.     }
  118.     outp(rWSequAddr+1,reg);             /* Index should still be the same, */
  119.                                         /* so write the new contents back  */
  120.  
  121.     reg = inp(rRMiscOutp);              /* Read Misc Outout register       */
  122.     if ( (page & 0x2) == 0x2)
  123.     {
  124.         reg = reg & 0xDF;               /* Select between (0,1) and (2,3) */
  125.     } else
  126.     {
  127.         reg = reg | 0x20;
  128.     }    
  129.     outp(rWMiscOutp,reg);
  130. } /*EVGASetPage*/
  131.  
  132.  
  133. /*--------------------------------------------------------------*/
  134. /* This function writes the specified color value to the pixel  */
  135. /* specified by (x,y).  If useBIOS is TRUE, then WritePixelEGA  */
  136. /* uses the BIOS Write Dot function to write the pixel,         */
  137. /* otherwise it calculates the offset and writes the pixel value*/
  138. /* directly.  Note that Graphics Write Mode 0 (EGA/VGA default) */
  139. /* and >64K of video memory is assumed.  This routine does not  */
  140. /* support the XOR function of the BIOS Write Dot function, but */
  141. /* this and other logical functions can be applied using the    */
  142. /* Data Rotate Register (03h) of the Graphics Controller (3CEh).*/
  143. /*--------------------------------------------------------------*/
  144.  
  145. void EVGAWritePixelEGA( int x, int y, byte color, int useBIOS)
  146.  
  147. {
  148.     union REGS          inreg,outreg;
  149.     int                 crtcolumns;
  150.     int                 far *mSysCrtColumns;
  151.     int                 regenstart;
  152.     int                 far *mSysRegenStart;
  153.     byte                far *pixelptr;
  154.     int                 offset;
  155.     byte                pixelnum;
  156.     byte                bitmask;
  157.     byte                tmp;
  158.  
  159.  
  160.     if(useBIOS) {
  161.         inreg.h.ah = 0x0C;              /* BIOS Write Dot Function */
  162.         inreg.h.al = color;
  163.              inreg.h.bh = 0x00;              /* Page 0 */
  164.         inreg.x.cx = x;
  165.         inreg.x.dx = y;
  166.         int86(0x10,&inreg,&outreg);
  167.     } else {
  168.         mSysCrtColumns = (int far *) 0x44A;
  169.         crtcolumns = (*mSysCrtColumns);
  170.  
  171.         mSysRegenStart = (int far *) 0x44E;
  172.         regenstart = (*mSysRegenStart);
  173.  
  174.         offset   = (y*crtcolumns) + (x/8);
  175.         pixelnum = x & 0x7;
  176.         bitmask  = 0x80 >> pixelnum;
  177.  
  178.         pixelptr = (byte far *) 0xA0000000 + offset;
  179.  
  180.         outp(rWGrfxAddr  ,0x08);
  181.         outp(rWGrfxAddr+1,bitmask);             /* Select which bit to modify */
  182.  
  183.         outp(rWSequAddr  ,0x02);
  184.         outp(rWSequAddr+1,0x0F);                /* Select all 4 planes */
  185.  
  186.         tmp = *pixelptr;                        /* Latch 4 planes */
  187.         *pixelptr = 0x00;                       /* Zero out current bits */
  188.  
  189.         outp(rWSequAddr  ,0x02);
  190.         outp(rWSequAddr+1,(color & 0x0F));      /* Select planes */
  191.  
  192.         tmp = *pixelptr;                        /* Latch 4 planes */
  193.         *pixelptr = 0xFF;                       /* Write the latched data */
  194.  
  195.         outp(rWGrfxAddr  ,0x08);
  196.         outp(rWGrfxAddr+1,0xFF);                /* Restore Bit Mask to default */
  197.  
  198.         outp(rWSequAddr  ,0x02);
  199.         outp(rWSequAddr+1,0x0F);                /* Restore Map Mask to default */
  200.     }
  201. } /*EVGAWritePixelEGA*/
  202.  
  203.  
  204.  
  205.  
  206. /*--------------------------------------------------------------*/
  207. /* This file demonstrates how to clear screen memory in Everex  */
  208. /* Extended 256 color modes.                                    */
  209. /*--------------------------------------------------------------*/
  210.  
  211.  
  212. void EVGAClearDisplay( int DN)
  213.  
  214. {
  215.     void                EVGASetPage();
  216.  
  217.     byte                far *pixelptr;
  218.     byte                page;
  219.  
  220.     for (page=0; page<4; page++)
  221.     {
  222.        EVGASetPage(page);
  223.        pixelptr = (byte far *) 0xA0000000;
  224.        memset( pixelptr, DN, 0x8000);
  225.        memset( pixelptr+0x08000L, DN, 0x8000);
  226.     }
  227. } /*EVGAClearDisplay*/
  228.