//------------------------------------------------------------------- // setreset.cpp // // This program demonstrates the operation of the VGA Graphics // Controller's SET/RESET and ENABLE SET/RESET registers while // the video display mode is setup for 16 simultaneous colors; // default values are used for Write Mode and Function Select. // // compile using: $ g++ setreset.cpp int86.cpp -o setreset // // programmer: ALLAN CRUSE // written on: 04 SEP 2005 //------------------------------------------------------------------- #include // for printf() #include // for inb(), outb() #include "int86.h" // for init8086(), int86() #define VRAM_BASE_FOR_VGA 0x000A0000 #define GRFX_INDEX_PORT 0x3CE typedef unsigned char u8; u8 *vram = (u8*)VRAM_BASE_FOR_VGA; struct vm86plus_struct vm; int vga_mode = 18, hres = 640, vres = 480; u8 glyph[ ] = { 0xFF, 0xFF, 0xFF, 0xC0, 0x00, 0x03, 0xC0, 0x00, 0x03, 0xC0, 0x00, 0x03, 0xC0, 0x00, 0x03, 0xC0, 0x00, 0x03, 0xC0, 0x00, 0x03, 0xC0, 0x00, 0x03, 0xC0, 0x00, 0x03, 0xC0, 0x00, 0x03, 0xC0, 0x00, 0x03, 0xC0, 0x00, 0x03, 0xC0, 0x00, 0x03, 0xC0, 0x00, 0x03, 0xC0, 0x00, 0x03, 0xFF, 0xFF, 0xFF }; void draw_glyph( int row, int col, int reg0, int reg1 ) { u8 *dst = vram + row * 640 + col; outw( (reg0<<8) | 0, GRFX_INDEX_PORT ); // Set/Reset outw( (reg1<<8) | 1, GRFX_INDEX_PORT ); // Enable Set/Reset for (int i = 0; i < 48; i++) dst[ (i / 3) * 80 + (i % 3) ] = glyph[ i ]; } void write_string( int row, int col, int color, char *msg ) { // restore default-values to Graphics Controller registers outw( 0x0000, GRFX_INDEX_PORT ); // Set/Reset outw( 0x0001, GRFX_INDEX_PORT ); // Enable Set/Reset // copy string to conventional memory and determine length char *mem = (char*)0x00018000; int length = 0; while ( mem[ length ] = msg[ length ] ) ++length; // invoke the Video ROM-BIOS 'write_string' service vm.regs.ecx = length; vm.regs.ebx = color & 0xF; vm.regs.edx = (row << 8) | (col & 0xFF); vm.regs.ebp = 0; vm.regs.es = ((int)mem >> 4); vm.regs.eax = 0x1300; int86( 0x10, vm ); } int main( int argc, char **argv ) { // setup the display for 16-color graphics (640-by-480) printf( "\e[H\n" ); // avoids getchar jerk init8086(); // allows I/O and BIOS vm.regs.eax = vga_mode; // Set Display Mode 18 int86( 0x10, vm ); // invoke BIOS service // draw our glyph using every possible combination of values // for Set/Reset (by rows) and Enable Set/Reset (by columns) for (int reg0 = 0; reg0 < 16; reg0++) for (int reg1 = 0; reg1 < 16; reg1++) draw_glyph( 3*(reg0+3), 4*(reg1+3), reg0, reg1 ); // draw the title and explanatory legend write_string( 1, 27, 15, "A Study of VGA Write Mode 0" ); write_string( 3, 0, 7, "Enable Set/Reset \032" ); write_string( 4, 0, 7, "Set/Reset \031" ); getchar(); // awaits -key // restore the display to standard 80-by-25 text-mode vm.regs.eax = 0x0003; // Set Display Mode 3 int86( 0x10, vm ); // invoke BIOS service }