//------------------------------------------------------------------- // redband.cpp // // This code will illustrate the role of the graphics display // memory in controlling the color of screen picture-elements // (pixels) if programmed for the so-called 'truecolor' mode. // // to compile: $ g++ redband.cpp -o redband // to execute: $ ./redband // // NOTE: This program is designed for execution solely on our // Gateway NV53A laptop computer (in 1024-by-768 resolution), // and requires installing our customized device-driver named // 'gateway.c' to allow access to the graphics display memory // plus the Radeon graphics engine's memory-mapped registers. // // programmer: ALLAN CRUSE // written on: 22 MAR 2011 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for lseek() #include // for mmap() #include // for ioctl() #define VRAM_BASE 0x80000000 #define GET_CRTC_START_ADDRESS 0 const unsigned int hpitch = 1024; unsigned int *fb; int main( int argc, char **argv ) { // map the graphics display memory into user's address-space int fd = open( "/dev/vram", O_RDWR ); if ( fd < 0 ) { perror( "/dev/vram" ); exit(1); } int size = lseek( fd, 0, SEEK_END ); int prot = PROT_READ | PROT_WRITE; int flag = MAP_FIXED | MAP_SHARED; void *mm = (void *)VRAM_BASE; if ( mmap( mm, size, prot, flag, fd, 0 ) == MAP_FAILED ) { perror( "mmap" ); exit(1); } // determine the current address of the GPU's frame-buffer unsigned int crtc_start_address = 0; if ( ioctl( fd, GET_CRTC_START_ADDRESS, &crtc_start_address ) < 0 ) { perror( "ioctl" ); exit(1); } unsigned int fb_offset = crtc_start_address & 0x3FFFFFFF; printf( " FRAME BUFFER OFFSET = 0x%08X \n", fb_offset ); fb = (unsigned int *)( VRAM_BASE + fb_offset ); // fill the upper 40 scanlines with blue-colored pixels unsigned int color = 0x00FF0000; // red for (int i = 0; i < 40 * hpitch; i++) fb[i] = color; }