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