//------------------------------------------------------------------- // gpmslide.cpp // // programmer: ALLAN CRUSE // written on: 21 AUG 2003 // revised on: 22 OCT 2003 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for close() #include // for tcgetattr(), tcsetattr() #include // for mmap() #include // for iopl() #include // for Gpm_Open() #define VRAM_BASE_ADDRESS 0xA0000000 #define VGA_MEMORY_LENGTH ( 4 << 20) #define ESCAPE_KEY 0x1B unsigned char *vram = (unsigned char*)VRAM_BASE_ADDRESS; const int display_mode = 0x4101, hres = 640, vres = 480; // global variables (for control of the slider) int minx = 100, maxx = 340, locy = 236; int wide = 200, high = 8, bgcolor = 0; int curr = 220, prev = 220, fgcolor = 10; void draw_rectangle( int x, int y, int h, int v, int color ) { int minx = 0, miny = 0, maxx = hres-1, maxy = vres-1; 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 ); } void fill_rectangle( int x, int y, int h, int v, int color ) { int minx = x, maxx = x+h-1, miny = y, maxy = y+v-1; for (y = miny; y <= maxy; y++) for (x = minx; x <= maxx; x++) vram[ y*hres + x ] = color; } int map_system_memory( int base, int size ) { int fd = open( "/dev/vram", O_RDWR ); if ( fd < 0 ) { perror( "/dev/vram" ); return -1; } int prot = PROT_READ | PROT_WRITE; int flag = MAP_FIXED | MAP_SHARED; void *mm = (void*)base; if ( mmap( mm, size, prot, flag, fd, 0 ) == MAP_FAILED ) { perror( "mmap" ); return -1; } close( fd ); } int my_handler( Gpm_Event *evt, void *data ) { if ( evt->type != GPM_MOVE ) return 0; prev = curr; curr += 2*evt->dx; if ( curr < minx ) curr = minx; if ( curr > maxx ) curr = maxx; if ( curr != prev ) { fill_rectangle( prev, locy, wide, high, bgcolor ); fill_rectangle( curr, locy, wide, high, fgcolor ); } return 0; } int main( void ) { if ( iopl( 3 ) ) { perror( "iopl" ); exit(1); } system( "/sbin/insmod vram.o" ); map_system_memory( VRAM_BASE_ADDRESS, VGA_MEMORY_LENGTH ); 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 ); char command[ 40 ]; sprintf( command, " clear ; mode3 %d ", display_mode ); system( command ); int bordercolor = 15; draw_rectangle( 0, 0, hres, vres, bordercolor ); fill_rectangle( curr, locy, wide, high, fgcolor ); Gpm_Connect conn; conn.eventMask = ~0; conn.defaultMask = 0; conn.minMod = 0; conn.maxMod = ~0; if ( Gpm_Open( &conn, 0 ) != -1 ) { int c; gpm_handler = my_handler; while ( ( c = Gpm_Getc( stdin ) ) != ESCAPE_KEY ); Gpm_Close(); } system( " mode3 3 " ); tcsetattr( 0, TCSAFLUSH, &otty ); }