//------------------------------------------------------------------- // vramdraw.cpp // // This application exercises services of our 'vram.c' driver. // // programmer: ALLAN CRUSE // written on: 19 NOV 2004 // revised on: 13 DEC 2004 -- correction to draw_pixel() bounds //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for read(), write(), close() char devname[] = "/dev/vram"; int hmax = 1280; int vmax = 1024; int fd; void draw_pixel( int r, int c, int color ) { if (( r < 0 )||( r >= vmax )) return; if (( c < 0 )||( c >= hmax )) return; int pos = ( hmax * r + c ) << 2; lseek( fd, pos, SEEK_SET ); write( fd, &color, 4 ); } int main( int argc, char **argv ) { // install our driver module system( "/sbin/insmod vram.o" ); // open the device-file fd = open( devname, O_RDWR ); if ( fd < 0 ) { perror( devname ); exit(1); } getchar(); // draw white border around edge of screen long pel = 0x00FFFFFF; int row = 0, col = 0; do { draw_pixel( row, col, pel ); } while ( ++col < hmax-1 ); do { draw_pixel( row, col, pel ); } while ( ++row < vmax-1 ); do { draw_pixel( row, col, pel ); } while ( --col > 0 ); do { draw_pixel( row, col, pel ); } while ( --row > 0 ); getchar(); // fill screen with green color pel = 0x0000FF00; int nbytes = hmax * vmax; for (int i = 0; i < nbytes; i++) write( fd, &pel, sizeof( pel ) ); getchar(); // close the device-file and remove the driver-module close( fd ); system( "/sbin/rmmod vram" ); }