📄 vga.c
字号:
static unsigned char *__svgalib_graph_mem_orginal;static unsigned char *__svgalib_graph_mem_check;unsigned char *__svgalib_graph_mem_linear_orginal;unsigned char *__svgalib_graph_mem_linear_check;static int __svgalib_linear_is_background=0;int __svgalib_oktowrite=1;/* __svgalib_oktowrite tells if it is safe to write registers. */int __svgalib_currentpage;int __svgalib_virtual_mem_fd=-1;static int __svgalib_processnumber=-1;static unsigned char *graph_buf2 = NULL; /* saves linear graphics data during flip */#endifvoid *__svgalib_physaddr;int __svgalib_linear_memory_size;#ifdef __alpha__/* same as graph mem, but mapped through sparse memory: */unsigned char *__svgalib_sparse_mem;#endifstatic unsigned char *graph_buf = NULL; /* saves graphics data during flip */static unsigned char *font_buf1; /* saved font data - plane 2 */static unsigned char *font_buf2; /* saved font data - plane 3 */static unsigned char *text_buf1; /* saved text data - plane 0 */static unsigned char *text_buf2; /* saved text data - plane 1 */static struct termios text_termio; /* text mode termio parameters */static struct termios graph_termio; /* graphics mode termio parameters */int __svgalib_flipchar = '\x1b'; /* flip character - initially ESCAPE *//* Chipset specific functions */DriverSpecs *__svgalib_driverspecs = &__svgalib_vga_driverspecs;#ifndef BACKGROUNDstatic void (*__svgalib_setpage) (int); /* gives little faster vga_setpage() */static void (*__svgalib_setrdpage) (int);static void (*__svgalib_setwrpage) (int);#endif#ifdef BACKGROUNDvoid (*__svgalib_setpage) (int); void (*__svgalib_setrdpage) (int);void (*__svgalib_setwrpage) (int);#endifstatic void readconfigfile(void);DriverSpecs *__svgalib_driverspecslist[] ={ NULL, /* chipset undefined */ &__svgalib_vga_driverspecs,#ifdef INCLUDE_ET4000_DRIVER &__svgalib_et4000_driverspecs,#else NULL,#endif#ifdef INCLUDE_CIRRUS_DRIVER &__svgalib_cirrus_driverspecs,#else NULL,#endif#ifdef INCLUDE_TVGA_DRIVER &__svgalib_tvga8900_driverspecs,#else NULL,#endif#ifdef INCLUDE_OAK_DRIVER &__svgalib_oak_driverspecs,#else NULL,#endif#ifdef INCLUDE_EGA_DRIVER &__svgalib_ega_driverspecs,#else NULL,#endif#ifdef INCLUDE_S3_DRIVER &__svgalib_s3_driverspecs,#else NULL,#endif#ifdef INCLUDE_ET3000_DRIVER &__svgalib_et3000_driverspecs,#else NULL,#endif#ifdef INCLUDE_MACH32_DRIVER &__svgalib_mach32_driverspecs,#else NULL,#endif#ifdef INCLUDE_GVGA6400_DRIVER &__svgalib_gvga6400_driverspecs,#else NULL,#endif#ifdef INCLUDE_ARK_DRIVER &__svgalib_ark_driverspecs,#else NULL,#endif#ifdef INCLUDE_ATI_DRIVER &__svgalib_ati_driverspecs,#else NULL,#endif#ifdef INCLUDE_ALI_DRIVER &__svgalib_ali_driverspecs,#else NULL,#endif#ifdef INCLUDE_MACH64_DRIVER &__svgalib_mach64_driverspecs,#else NULL,#endif#ifdef INCLUDE_CHIPS_DRIVER &__svgalib_chips_driverspecs,#else NULL,#endif#ifdef INCLUDE_APM_DRIVER &__svgalib_apm_driverspecs,#else NULL,#endif#ifdef INCLUDE_NV3_DRIVER &__svgalib_nv3_driverspecs,#else NULL,#endif#ifdef INCLUDE_ET6000_DRIVER &__svgalib_et6000_driverspecs,#else NULL,#endif#ifdef INCLUDE_VESA_DRIVER &__svgalib_vesa_driverspecs,#else NULL,#endif#ifdef INCLUDE_MX_DRIVER &__svgalib_mx_driverspecs,#else NULL,#endif#ifdef INCLUDE_PARADISE_DRIVER &__svgalib_paradise_driverspecs,#else NULL,#endif#ifdef INCLUDE_RAGE_DRIVER &__svgalib_rage_driverspecs,#else NULL,#endif#ifdef INCLUDE_BANSHEE_DRIVER &__svgalib_banshee_driverspecs,#else NULL,#endif#ifdef INCLUDE_SIS_DRIVER &__svgalib_sis_driverspecs,#else NULL,#endif#ifdef INCLUDE_I740_DRIVER &__svgalib_i740_driverspecs,#else NULL,#endif#ifdef INCLUDE_NEO_DRIVER &__svgalib_neo_driverspecs,#else NULL,#endif#ifdef INCLUDE_LAGUNA_DRIVER &__svgalib_laguna_driverspecs,#else NULL,#endif#ifdef INCLUDE_FBDEV_DRIVER &__svgalib_fbdev_driverspecs,#else NULL,#endif#ifdef INCLUDE_G400_DRIVER &__svgalib_g400_driverspecs,#else NULL,#endif#ifdef INCLUDE_R128_DRIVER &__svgalib_r128_driverspecs,#else NULL,#endif#ifdef INCLUDE_SAVAGE_DRIVER &__svgalib_savage_driverspecs,#else NULL,#endif};static char *driver_names[] ={"", "VGA", "ET4000", "Cirrus", "TVGA", "Oak", "EGA", "S3","ET3000", "Mach32", "GVGA6400","ARK","ATI","ALI","Mach64", "C&T","APM","NV3","ET6000","VESA","MX","PARADISE","RAGE","BANSHEE", "SIS","I740","NEOMAGIC","LAGUNA","FBDev","G400","R128","Savage", NULL};/* Chipset drivers *//* vgadrv Standard VGA (also used by drivers below) *//* et4000 Tseng ET4000 (from original vgalib) *//* cirrus Cirrus Logic GD542x *//* tvga8900 Trident TVGA 8900/9000 (derived from tvgalib) *//* oak Oak Technologies 037/067/077 *//* egadrv IBM EGA (subset of VGA) *//* s3 S3 911 *//* mach32 ATI MACH32 *//* ark ARK Logic *//* gvga6400 Genoa 6400 (old SVGA) *//* ati ATI *//* ali ALI2301 *//* mach64 ATI MACH64 *//* chips chips & technologies*//* et6000 Tseng ET6000 */ /* DS *//*#define DEBUG *//* Debug config file parsing.. *//*#define DEBUG_CONF */#ifdef DEBUGstatic void _DEBUG(int dnr){ static int first = 1; FILE *dfile; dfile = fopen("svgalib.debug", (first ? "w" : "a")); first = 0; if (dfile == NULL) exit(1); fprintf(dfile, "debug #%d\n", dnr); fclose(dfile); sync();}#else#define _DEBUG(d)#endifstatic void set_graphtermio(void){ /* Leave keyboard alone when rawkeyboard is enabled! */ if (__svgalib_kbd_fd < 0) { /* set graphics mode termio parameters */ ioctl(0, TCSETSW, &graph_termio); }}static void set_texttermio(void){ /* Leave keyboard alone when rawkeyboard is enabled! */ if (__svgalib_kbd_fd < 0) { /* restore text mode termio parameters */ ioctl(0, TCSETSW, &text_termio); }}static void disable_interrupt(void){ struct termios cur_termio; /* Well, one could argue that sigint is not enabled at all when in __svgalib_nosigint but sometimes they *still* are enabled b4 graph_termio is set.. */ ioctl(0, TCGETS, &cur_termio); cur_termio.c_lflag &= ~ISIG; ioctl(0, TCSETSW, &cur_termio);}static void enable_interrupt(void){ struct termios cur_termio; if (__svgalib_nosigint) /* do not reenable, they are often reenabled by text_termio */ return; ioctl(0, TCGETS, &cur_termio); cur_termio.c_lflag |= ISIG; ioctl(0, TCSETSW, &cur_termio);}/* The following is rather messy and inelegant. The only solution I can *//* see is getting a extra free VT for graphics like XFree86 does. */void __svgalib_waitvtactive(void){ if (__svgalib_tty_fd < 0) return; /* Not yet initialized */ while (ioctl(__svgalib_tty_fd, VT_WAITACTIVE, svgalib_vc) < 0) { if ((errno != EAGAIN) && (errno != EINTR)) { perror("ioctl(VT_WAITACTIVE)"); exit(1); } usleep(150000); }}/* open /dev/mem */static void open_mem(void){#ifdef BACKGROUND#if BACKGROUND == 1 char tmp[40];#endif#endif if (CHIPSET == FBDEV) return; /* Ensure that the open will get a file descriptor greater * than 2, else problems can occur with stdio functions * under certain strange conditions: */ if (fcntl(0,F_GETFD) < 0) open("/dev/null", O_RDONLY); if (fcntl(1,F_GETFD) < 0) open("/dev/null", O_WRONLY); if (fcntl(2,F_GETFD) < 0) open("/dev/null", O_WRONLY); if (__svgalib_mem_fd < 0) if ((__svgalib_mem_fd = open("/dev/mem", O_RDWR)) < 0) { printf("svgalib: Cannot open /dev/mem.\n"); exit(1); }#ifdef BACKGROUND#if BACKGROUND == 1 /* Needs proc-fs. */ /* printf("procc\n"); */ /* char tmp[40];*/ if (__svgalib_virtual_mem_fd<0) { __svgalib_processnumber=getpid(); sprintf(tmp,"/proc/%d/mem",__svgalib_processnumber); if ((__svgalib_virtual_mem_fd = open(tmp,O_RDWR)) < 0) { printf("svgalib: Cannot open /proc/%d/mem.\n", __svgalib_processnumber); exit(-1); } }#endif#endif}static int check_owner(int vc){ struct stat sbuf; char fname[30];#ifdef ROOT_VC_SHORTCUT if (!getuid()) return 1; /* root can do it always */#endif sprintf(fname, "/dev/tty%d", vc); if ((stat(fname, &sbuf) >= 0) && (getuid() == sbuf.st_uid)) { return 1; } printf("You must be the owner of the current console to use svgalib.\n"); return 0;}void __svgalib_open_devconsole(void){ struct vt_mode vtm; struct vt_stat vts; struct stat sbuf; char fname[30]; if(__svgalib_novccontrol)return; if (__svgalib_tty_fd >= 0) return; /* The code below assumes file descriptors 0, 1, and 2 * are already open; make sure that's true. */ if (fcntl(0,F_GETFD) < 0) open("/dev/null", O_RDONLY); if (fcntl(1,F_GETFD) < 0) open("/dev/null", O_WRONLY); if (fcntl(2,F_GETFD) < 0) open("/dev/null", O_WRONLY); /* * Now, it would be great if we could use /dev/tty and see what it is connected to. * Alas, we cannot find out reliably what VC /dev/tty is bound to. Thus we parse * stdin through stderr for a reliable VC */ for (__svgalib_tty_fd = 0; __svgalib_tty_fd < 3; __svgalib_tty_fd++) { if (fstat(__svgalib_tty_fd, &sbuf) < 0) continue; if (ioctl(__svgalib_tty_fd, VT_GETMODE, &vtm) < 0) continue; if ((sbuf.st_rdev & 0xff00) != 0x400) continue; if (!(sbuf.st_rdev & 0xff)) continue; svgalib_vc = sbuf.st_rdev & 0xff; return; /* perfect */ } if ((__svgalib_tty_fd = open("/dev/console", O_RDWR)) < 0) { printf("svgalib: can't open /dev/console \n"); exit(1); } if (ioctl(__svgalib_tty_fd, VT_OPENQRY, &svgalib_vc) < 0) goto error; if (svgalib_vc <= 0) goto error; sprintf(fname, "/dev/tty%d", svgalib_vc); close(__svgalib_tty_fd); /* change our control terminal: */ setpgid(0,getppid()); setsid(); /* We must use RDWR to allow for output... */ if (((__svgalib_tty_fd = open(fname, O_RDWR)) >= 0) && (ioctl(__svgalib_tty_fd, VT_GETSTATE, &vts) >= 0)) { if (!check_owner(vts.v_active)) goto error; /* success, redirect all stdios */ if (DREP) printf("[svgalib: allocated virtual console #%d]\n", svgalib_vc); fflush(stdin); fflush(stdout); fflush(stderr); close(0); close(1); close(2); dup(__svgalib_tty_fd); dup(__svgalib_tty_fd); dup(__svgalib_tty_fd);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -