//------------------------------------------------------------------- // dacproto.cpp // // This testbed lets us see the effect of modifying the values // that are programmed into the 256 DAC color-table registers. // // compile using: $ dacproto.cpp int86.cpp -o dacproto // // programmer: ALLAN CRUSE // written on: 20 NOV 2005 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for lseek() #include // for tcgetattr(), tcsetattr() #include // for mmap() #include // for outb() #include "int86.h" // for init8086(), int86() unsigned char *vram = (unsigned char*)0xA0000000; int vesa_mode = 0x4101, hres = 640, vres = 480; struct vm86plus_struct vm; struct rgb_struct { unsigned char r, g, b; }; void reprogram_color_registers( struct rgb_struct *table ) { for (int color = 0; color < 256; color++) { outb( color, 0x3C8 ); outb( table[ color ].r, 0x3C9 ); outb( table[ color ].g, 0x3C9 ); outb( table[ color ].b, 0x3C9 ); } } void draw_color_grid( void ) { int wide = hres/16, high = vres/16; for (int color = 0; color < 256; color++) { int horiz = color % 16; int vertl = color / 16; int x_start = wide * horiz; int y_start = high * vertl; int screen_offset = y_start * hres + x_start; int box_margin = 5; unsigned char *destn = vram + screen_offset; for (int y = box_margin; y < high-box_margin; y++) for (int x = box_margin; x < wide-box_margin; x++) destn[ y*hres + x ] = color; } } int main( int argc, char **argv ) { int fd = open( "/dev/vram", O_RDWR ); if ( fd < 0 ) { perror( "/dev/vram" ); return -1; } int size = lseek( fd, 0, SEEK_END ); int prot = PROT_READ | PROT_WRITE; int flag = MAP_FIXED | MAP_SHARED; if ( mmap( (void*)vram, size, prot, flag, fd, 0 ) == MAP_FAILED ) { perror( "mmap" ); return -1; } struct termios otty; tcgetattr( 0, &otty ); struct termios tty = otty; tty.c_lflag &= ~( ICANON | ECHO | ISIG ); tty.c_cc[ VMIN ] = 1; tty.c_cc[ VTIME ] = 0; tcsetattr( 0, TCSAFLUSH, &tty ); init8086(); vm.regs.eax = 0x4F02; vm.regs.ebx = vesa_mode; int86( 0x10, vm ); int minx = 0, miny = 0, maxx = hres-1, maxy = vres-1; int x = minx, y = miny, 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 ); draw_color_grid(); getchar(); // design a new array of color values int b = 0, g = 64, r = 128, w = 192; struct rgb_struct color_table[ 256 ] = { 0 }; for (int i = 0; i < 64; i++) { color_table[ r + i ].r = i; color_table[ g + i ].g = i; color_table[ b + i ].b = i; color_table[ w + i ].r = i; color_table[ w + i ].g = i; color_table[ w + i ].b = i; } reprogram_color_registers( color_table ); getchar(); vm.regs.eax = 0x4F02; vm.regs.ebx = 0x0003; int86( 0x10, vm ); tcsetattr( 0, TCSAFLUSH, &otty ); }