home *** CD-ROM | disk | FTP | other *** search
- /*** IMDISP module EVGAIO.C
-
- EVGAIO contains the device dependent display routines for
- the Everex EV-673 enhanced VGA board. The code is taken from
- demo routines in the Everex Software Developer's Kit. This
- module was adapted, coded and tested by:
-
- A. Warnock
- ST Systems Corp
- Mail Code 681
- NASA/Goddard Space Flight Center
- Greenbelt, MD.
-
- All bugs contained herein are mine and mine alone.
-
- ***/
-
- /* If you are compiling using Microsoft C 4.0, remove this line */
- /* and compile this using the /Zp option. */
- #pragma pack(1)
-
- /* * * * INCLUDE files * * * */
-
- #include <stdio.h>
- #include <dos.h>
- #include <memory.h>
- #include <string.h>
- #include "imdef.h"
- #include "dispio.h"
-
- #define rWDacWrteAddr 0x3C8
- #define rWDacData 0x3C9
- #define rWAttrAddr 0x3C0
- #define rWMiscOutp 0x3C2
- #define rRMiscOutp 0x3CC
- #define rWSequAddr 0x3C4
- #define rWGrfxAddr 0x3CE
-
- #define DACSIZE 0xFF
- #define TRUE 1
- #define PALETTESIZE 16
-
-
- typedef unsigned char byte;
- typedef unsigned int word;
-
- /* Function declarations for EVGAIO.C */
-
-
- /* * * * External functions * * * */
-
- /* * * * Function declarations * * * */
-
- void EVGAWritePixel256( int x, int y, int color);
- void EVGASetPage( byte page);
- void EVGAWritePixelEGA( int x, int y, byte color, int useBIOS);
- void EVGAClearDisplay( int DN);
-
- /* * * * Global Variables * * * */
-
-
-
-
- void EVGAWritePixel256( int x, int y, int color)
-
- /*--------------------------------------------------------------*/
- /* This function writes the specified color value to the pixel */
- /* specified by (x,y). It calculates the offset, sets the page */
- /* using EVGASetPage, and writes the pixel value directly. */
- /* */
- /*--------------------------------------------------------------*/
-
- {
- void EVGASetPage();
-
- word crtcolumns;
- word far *mSysCrtColumns;
- byte far *pixelptr;
- byte page;
- word offset;
- unsigned long pixelnum;
-
- mSysCrtColumns = (word far *) 0x44A;
- crtcolumns = (*mSysCrtColumns);
-
- pixelnum = (unsigned long) (8*(unsigned long) crtcolumns*y)+ x;
- page = pixelnum >> 0x10;
- offset = pixelnum & 0xFFFF;
- EVGASetPage(page);
- pixelptr = (byte far *) 0xA0000000 + offset;
- *pixelptr = (unsigned char)color;
- } /*EVGAWritePixel256*/
-
- /*--------------------------------------------------------------*/
- /* This function selects among the 4 segments in Everex Extended*/
- /* 256 color modes. Page should be in the range 0..3. Other */
- /* values will be treated modulo 4. */
- /*--------------------------------------------------------------*/
-
- void EVGASetPage( byte page)
-
- {
- byte reg;
-
- outp(rWSequAddr,0x8); /* Index Everex Control Register */
- reg = inp(rWSequAddr+1); /* Read its contents */
-
- if( (page & 0x1) == 0x1)
- {
- reg = reg | 0x80; /* Select between odd and even pages */
- } else
- { /* (0,2) and (1,3) */
- reg = reg & 0x7F;
- }
- outp(rWSequAddr+1,reg); /* Index should still be the same, */
- /* so write the new contents back */
-
- reg = inp(rRMiscOutp); /* Read Misc Outout register */
- if ( (page & 0x2) == 0x2)
- {
- reg = reg & 0xDF; /* Select between (0,1) and (2,3) */
- } else
- {
- reg = reg | 0x20;
- }
- outp(rWMiscOutp,reg);
- } /*EVGASetPage*/
-
-
- /*--------------------------------------------------------------*/
- /* This function writes the specified color value to the pixel */
- /* specified by (x,y). If useBIOS is TRUE, then WritePixelEGA */
- /* uses the BIOS Write Dot function to write the pixel, */
- /* otherwise it calculates the offset and writes the pixel value*/
- /* directly. Note that Graphics Write Mode 0 (EGA/VGA default) */
- /* and >64K of video memory is assumed. This routine does not */
- /* support the XOR function of the BIOS Write Dot function, but */
- /* this and other logical functions can be applied using the */
- /* Data Rotate Register (03h) of the Graphics Controller (3CEh).*/
- /*--------------------------------------------------------------*/
-
- void EVGAWritePixelEGA( int x, int y, byte color, int useBIOS)
-
- {
- union REGS inreg,outreg;
- int crtcolumns;
- int far *mSysCrtColumns;
- int regenstart;
- int far *mSysRegenStart;
- byte far *pixelptr;
- int offset;
- byte pixelnum;
- byte bitmask;
- byte tmp;
-
-
- if(useBIOS) {
- inreg.h.ah = 0x0C; /* BIOS Write Dot Function */
- inreg.h.al = color;
- inreg.h.bh = 0x00; /* Page 0 */
- inreg.x.cx = x;
- inreg.x.dx = y;
- int86(0x10,&inreg,&outreg);
- } else {
- mSysCrtColumns = (int far *) 0x44A;
- crtcolumns = (*mSysCrtColumns);
-
- mSysRegenStart = (int far *) 0x44E;
- regenstart = (*mSysRegenStart);
-
- offset = (y*crtcolumns) + (x/8);
- pixelnum = x & 0x7;
- bitmask = 0x80 >> pixelnum;
-
- pixelptr = (byte far *) 0xA0000000 + offset;
-
- outp(rWGrfxAddr ,0x08);
- outp(rWGrfxAddr+1,bitmask); /* Select which bit to modify */
-
- outp(rWSequAddr ,0x02);
- outp(rWSequAddr+1,0x0F); /* Select all 4 planes */
-
- tmp = *pixelptr; /* Latch 4 planes */
- *pixelptr = 0x00; /* Zero out current bits */
-
- outp(rWSequAddr ,0x02);
- outp(rWSequAddr+1,(color & 0x0F)); /* Select planes */
-
- tmp = *pixelptr; /* Latch 4 planes */
- *pixelptr = 0xFF; /* Write the latched data */
-
- outp(rWGrfxAddr ,0x08);
- outp(rWGrfxAddr+1,0xFF); /* Restore Bit Mask to default */
-
- outp(rWSequAddr ,0x02);
- outp(rWSequAddr+1,0x0F); /* Restore Map Mask to default */
- }
- } /*EVGAWritePixelEGA*/
-
-
-
-
- /*--------------------------------------------------------------*/
- /* This file demonstrates how to clear screen memory in Everex */
- /* Extended 256 color modes. */
- /*--------------------------------------------------------------*/
-
-
- void EVGAClearDisplay( int DN)
-
- {
- void EVGASetPage();
-
- byte far *pixelptr;
- byte page;
-
- for (page=0; page<4; page++)
- {
- EVGASetPage(page);
- pixelptr = (byte far *) 0xA0000000;
- memset( pixelptr, DN, 0x8000);
- memset( pixelptr+0x08000L, DN, 0x8000);
- }
- } /*EVGAClearDisplay*/
-