//------------------------------------------------------------------- // vgademo.cpp // // This example demonstrates 256-color PC graphics programming // as implemented by IBM's Video Graphics Array (VGA) adapter, // still supported by SVGA devices for backward compatibility. // Screen-resolution is 320-by-200, and pixel-depth is 8-bits. // This mode uses the DAC's 256 color-lookup registers, but it // disregards the Attribute Controller's 16 palette registers. // // compile using: $ g++ vgademo.cpp int86.cpp -o vgademo // // programmer: ALLAN CRUSE // written on: 01 SEP 2005 //------------------------------------------------------------------- #include // for printf() #include // for inb(), outw(), etc. #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 hres = 320, vres = 200; void set_pixel( int x, int y, int color ) { int posn = y*hres + x; vram[ posn ] = color; } void fill_rectangle( int x, int y, int h, int v, int color ) { int minx = x, maxx = x+h-1; int miny = y, maxy = y+v-1; for (y = miny; y <= maxy; y++) for (x = minx; x <= maxx; x++) set_pixel( x, y, color ); } int main( int argc, char **argv ) { int minx, midx, maxx, miny, midy, maxy; int x, y, color, radius_squared; printf( "\e[H\n" ); // avoids getchar jerk init8086(); // enable BIOS service //-------------------------------------------------- // Demonstrate VGA 256-color graphics (IBM mode 19) //-------------------------------------------------- vm.regs.eax = 0x0013; // Set Display Mode 19 int86( 0x10, vm ); // invoke BIOS service // draw a screen border color = 15; // white minx = 0, maxx = hres-1; miny = 0, maxy = vres-1; x = y = 0; do { set_pixel( x, y, color ); ++x; } while ( x < maxx ); do { set_pixel( x, y, color ); ++y; } while ( y < maxy ); do { set_pixel( x, y, color ); --x; } while ( x > minx ); do { set_pixel( x, y, color ); --y; } while ( y > miny ); getchar(); // fill circle (unrescaled) midx = hres/2; midy = 23*vres/32; radius_squared = 40*40; color = 6; for (y = 4; y <= maxy-4; y++) for (x = 4; x <= maxx-4; x++) { int dx = x - midx; int dy = y - midy; int dist_squared = dx*dx + dy*dy; color = ( dist_squared < radius_squared ) ? 6 : 150; set_pixel( x, y, color ); } getchar(); // show the palette of 256-colors int h = 5, v = 5, x0 = 32, y0 = 24; for (color = 0; color < 256; color++) { x = x0 + (color % 32)*8; y = y0 + (color / 32)*8; fill_rectangle( x, y, h, v, color ); } getchar(); // return the display to standard text-mode vm.regs.eax = 0x0003; // Set Display Mode 3 int86( 0x10, vm ); // invoke BIOS service printf( "VGA demo is finished\n" ); }