/* VGAINI.C */ #include "dos.h" #include "memory.h" /* Port addresses of control regs */ #define GRAPHICS 0x3ce /* Registers within controllers */ #define GRSETRESET 0 #define GRENABLESETRESET 1 #define GRROTATE 3 #define GRCONTROL 5 #define GRBITMASK 8 /* the funcion select modes */ #define FS_DIRECT 0 #define FS_AND 0x10 #define FS_OR 0x20 #define FS_XOR 0x30 typedef unsigned char BYTE; static BYTE far *graphicsbase = MK_FP(0xa000,0); /* Subroutine to write to a VGA controller port */ static void WriteVGA(int port, BYTE reg, BYTE value) { outportb(port,reg); outportb(port+1,value); } /* Put us in text mode */ void TextMode(void) { asm mov ax,3; asm int 0x10; } /* Put us in Graphics mode */ void GraphMode(void) { asm mov ax,0x12; asm int 0x10; } /* Draw a pixel on the screen */ void DrawPixel(int x, int y, BYTE color) { int offset=y*80 + x/8; int mask=0x80>>(x&7); int temp; /* set color */ WriteVGA(GRAPHICS,GRSETRESET,color); /* color = our color */ WriteVGA(GRAPHICS,GRENABLESETRESET,15); /* select bit mask to modify */ WriteVGA(GRAPHICS,GRBITMASK,mask); /* latch current data, this reads all four planes into internal latches */ temp = graphicsbase[offset]; /* write the bit by mixing the latched data with the bitmask and color regs*/ graphicsbase[offset] = 0xff; /* now reset things so the BIOS can function */ WriteVGA(GRAPHICS,GRBITMASK,0xff); WriteVGA(GRAPHICS,GRENABLESETRESET,0); } /* Clear the screen to a given color */ void ClearScreen(int color) { int i,j; for (i=0; i < 640; i++) for (j=0; j < 480; j++) DrawPixel(i,j,color); } void main(void) { unsigned i,j; GraphMode(); ClearScreen(1); for (i= 0; i < 400; i++) { DrawPixel(i,39,14); DrawPixel(i,40,14); } while (!kbhit()); getch(); TextMode(); }