//------------------------------------------------------------------- // randpats.cpp // // This program uses the standard 'rand()' library-function to // generate some pattern-bitmaps and select their colors; then // it fills some rectangular screen-areas using these pattern. // // compile using: $ g++ randpats.cpp int86.cpp -o randpats // // programmer: ALLAN CRUSE // written on: 15 SEP 2005 //------------------------------------------------------------------- #include // for getchar(), printf() #include // for rand() #include "int86.h" // for init8086(), int86() #define VRAM_BASE_FOR_VGA 0x000A0000 typedef unsigned char u8; u8 *vram = (u8*)VRAM_BASE_FOR_VGA; struct vm86plus_struct vm; int vga_mode = 19, hres = 320, vres = 200; char pat[ 8 ]; int main( int argc, char **argv ) { // enter graphics mode init8086(); vm.regs.eax = vga_mode; int86( 0x10, vm ); // draw screen border int x = 0, y = 0, color = 15; do { vram[ y * hres + x ] = color; ++x; } while ( x < hres-1 ); do { vram[ y * hres + x ] = color; ++y; } while ( y < vres-1 ); do { vram[ y * hres + x ] = color; --x; } while ( x > 0 ); do { vram[ y * hres + x ] = color; --y; } while ( y > 0 ); getchar(); // setup the subdivisions of the screen to be tiled int wide = hres/2, high = vres/2; for (int area = 0; area < 4; area++) { // create the bitmap for an 8-by-8 2-color pattern for (int i = 0; i < 8; i++) pat[ i ] = rand(); // choose the pattern's foreground/background colors int fgcolor = 32 + rand() % 72; int bgcolor = 104 + rand() % 72; // setup coordinates for the area's starting location int x = (area % 2)*wide; int y = (area / 2)*high; u8 *dstn = vram + y * hres + x; // tile the screen-area with the pattern for (int row = 0; row < high; row++) { u8 bits = pat[ row % 8 ]; for (int col = 0; col < wide; col++) { u8 which = ( bits >>( col % 8 ) )&1; int where = row * hres + col; dstn[ where ] = ( which ) ? fgcolor : bgcolor; } } } getchar(); // leave graphics mode vm.regs.eax = 0x0003; int86( 0x10, vm ); printf( "\n" ); }