//------------------------------------------------------------------- // brickpat.cpp // // This program uses an 8-by-8 pattern-glyph to fill the screen // with a red-and-white brick-wall pattern. It executes in VGA // graphics mode 19 (320-by-200, 256-colors). Can you adapt it // to execute in a 16-color graphics mode (e.g., VGA mode 18)? // // compile using: g++ brickpat.cpp int86.cpp -o brickpat // // programmer: ALLAN CRUSE // written on: 13 SEP 2003 // revised on: 04 SEP 2005 -- replaced svgalib with 'int86()' //------------------------------------------------------------------- #include // for printf() #include "int86.h" // for init8086(), int86() #define VRAM_BASE_FOR_VGA 0x000A0000 unsigned char *vram = (unsigned char *)VRAM_BASE_FOR_VGA; struct vm86plus_struct vm; int vga_mode = 19, hres = 320, vres = 200; char brickpat[ 8 ] = { 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x08, 0x08, 0x08 }; void tile_area( int x, int y, int h, int v, int fg, int bg, char *pat ); int main( int argc, char **argv ) { // setup 1-MB memory-map and I/O permission for BIOS routines printf( "\e[H\n" ); // avoid getchar jerk init8086(); // allows BIOS access // enter graphics mode vm.regs.eax = vga_mode; int86( 0x10, vm ); // draw white screen border int minx = 0, maxx = hres-1, miny = 0, maxy = vres-1; int x = 0, y = 0, color = 15; do { vram[ y*hres + x ] = color; ++x; } while ( x < maxx ); do { vram[ y*hres + x ] = color; ++y; } while ( y < maxy ); do { vram[ y*hres + x ] = color; --x; } while ( x > minx ); do { vram[ y*hres + x ] = color; --y; } while ( y > miny ); getchar(); // fill a screen region with our 2-color brick pattern int red = 4, white = 15; tile_area( 1, 1, hres-2, vres-2, white, red, brickpat ); getchar(); // restore standard text mode vm.regs.eax = 0x0003; int86( 0x10, vm ); printf( "\n" ); } void tile_area( int x, int y, int h, int v, int fg, int bg, char *pat ) { int minx = x, maxx = x+h-1, miny = y, maxy = y+v-1; for (y = miny; y <= maxy; y++) for (x = minx; x <= maxx; x++) { int r = y % 8; int k = x % 8; int color = ( pat[ r ] & (0x80>>k) ) ? fg : bg; vram[ y*hres + x ] = color; } }