📄 ui_svga.c
字号:
getc (stdin); }#else if (nthreads != 1) { printf ("WARNING WARNING WARNING WARNING\n" "You are trying to start SVGAlib XaoS with multiple threads. In case\n" "you use linux-thread based thread library (like one in glibc) your system\n" "is going to CRASH! So if you are not sure stop XaoS now. Otherwise press 'y'\n" "to continue\n"); if (getc (stdin) != 'y') exit (1); }#endif vga_setmode (mode); seteuid (getuid ()); /* Don't need supervisor rights anymore. */ setegid (getgid ()); if (mode == G320x240x256 || mode == G320x400x256 || mode == G360x480x256) svga_driver.textheight = 8 * 4; else svga_driver.textheight = 8; gl_setcontextvga (mode);#ifdef HAVE_PTHREAD_SIGHANDLER if (nthreads != 1) {#warning With linux thread SVGAlib driver is just partially functional. See comment bellow this line. /* bad luck...bots SVGAlib and linuxthreads abuses SIGUSR1/2 * for their own purposes. It is better to keep pthread code- * it disables console switching but don't crashes XaoS. * SIGUSR2 is not mapped, since linuxthreads don't export * handler. It is used for canceling threads wich is not * used by current XaoS thread implementation so everything * works (almost) well */ struct sigaction sa; sa.sa_handler = pthread_sighandler; sigemptyset (&sa.sa_mask); sa.sa_flags = SA_RESTART; /* does not matter for regular threads, but better for the thread manager */ sigaction (SIGUSR1, &sa, NULL); sa.sa_handler = shutdown; /* Well shutdown isn't exactly what pthread implementation does, but it works:) */ sigaction (SIGUSR2, &sa, NULL); vga_lockvc (); }#endif gl_getcontext (&screen); keyboard_init (); keyboard_translatekeys (0);#ifdef VGA_KEYEVENT keyboard_seteventhandler (handler);#endif gl_setpalettecolor (255, 63, 63, 63); gl_setpalettecolor (0, 0, 0, 0); if (colors == 256) { if (grayscale) svga_setgrayscale (), svga_driver.imagetype = UI_GRAYSCALE, whitecolor = 255; else svga_driver.imagetype = UI_C256, whitecolor = 1; } if (colors == 65536) { svga_driver.imagetype = UI_TRUECOLOR16; svga_driver.rmask = 31 * 64 * 32; svga_driver.gmask = 63 * 32; svga_driver.bmask = 31; whitecolor = colors - 1; } if (colors == 32768) { svga_driver.imagetype = UI_TRUECOLOR16; svga_driver.rmask = 31 * 32 * 32; svga_driver.gmask = 31 * 32; svga_driver.bmask = 31; whitecolor = colors - 1; } if (colors == 16777216) { if (bbytesperpixel == 4) { svga_driver.imagetype = UI_TRUECOLOR; svga_driver.rmask = 0xff0000; svga_driver.gmask = 0x00ff00; svga_driver.bmask = 0x0000ff; if (info->flags & RGB_MISORDERED) { svga_driver.rmask = 0x000000ff; svga_driver.gmask = 0x0000ff00; svga_driver.bmask = 0x00ff0000; } whitecolor = 0xffffffffU; } else { svga_driver.rmask = 0xff0000; svga_driver.gmask = 0x00ff00; svga_driver.bmask = 0x0000ff; svga_driver.imagetype = UI_TRUECOLOR24; if (info->flags & RGB_MISORDERED) { svga_driver.rmask = 0x0000ff; svga_driver.gmask = 0x00ff00; svga_driver.bmask = 0xff0000; } whitecolor = 0xffffffU; } } if (font != NULL) free (font), font = NULL; font = (char *) malloc (256 * 8 * 8 * bbytesperpixel * 2); gl_expandfont (8, 8, whitecolor, gl_font8x8, font); gl_setfont (8, 8, font); draw_mouse (mouse_getx (), mouse_gety (), 0);}static voidsvga_uninitialise (void){ keyboard_close (); vga_setmode (TEXT); if (font != NULL) free (font), font = NULL;}static intsvga_init (void){ int i; int fd; struct stat chkbuf; seteuid (euid); /* We need supervisor rights to open mouse. */ setegid (egid); if ((fd = open ("/dev/console", O_RDONLY)) < 0) { seteuid (getuid ()); /* Don't need supervisor rights anymore. */ setegid (getgid ()); return (0); } close (fd); fstat (2, &chkbuf); if (chkbuf.st_rdev >> 8 != 4 || (chkbuf.st_rdev & 0xff) >= 64) { seteuid (getuid ()); /* Don't need supervisor rights anymore. */ setegid (getgid ()); return (0); } if ((fd = open ("/dev/mem", O_RDWR)) < 0) { seteuid (getuid ()); /* Don't need supervisor rights anymore. */ setegid (getgid ()); return (0); } close (fd); if (!initialised) { vga_setmousesupport (1); vga_init (); initialised = 1; } for (i = 1; i <= GLASTMODE; i++) if (vga_hasmode (i)) { info = vga_getmodeinfo (i); if (info->colors == 256 || info->colors == 32768 || info->colors == 65536 || info->colors == 16777216) break; } if (i == GLASTMODE + 1) // No valid mode was found. { svga_uninitialise (); return 0; } seteuid (getuid ()); /* Don't need supervisor rights anymore. */ setegid (getgid ()); return (1);}static voidsvga_get_size (int *x, int *y){ int m = 0; if (mode != -1) { m = 1; svga_uninitialise (); mode = -1; } init_mode (); *x = width; *y = height;}static voidsvga_getmouse (int *x, int *y, int *buttons){ mouse_update (); *x = mouse_getx (); *y = mouse_gety (); *buttons = 0; if (mouse_getbutton () == MOUSE_LEFTBUTTON) *buttons |= BUTTON1; if (mouse_getbutton () == MOUSE_RIGHTBUTTON) *buttons |= BUTTON3; if (mouse_getbutton () & MOUSE_MIDDLEBUTTON) *buttons |= BUTTON2; draw_mouse (mouse_getx (), mouse_gety (), 1);}static voidsvga_processevents (int wait, int *x, int *y, int *buttons, int *k){ if (wait) {#ifdef VGA_KEYEVENT struct timeval timeout; fd_set inputs; fd_set outputs; fd_set except; FD_ZERO (&inputs); FD_ZERO (&outputs); FD_ZERO (&except); timeout.tv_sec = 999999; timeout.tv_usec = 999999; mouse_update (); keyboard_update (); vga_waitevent (VGA_KEYEVENT | VGA_MOUSEEVENT, &inputs, &outputs, &except, &timeout);#else#warning Your SVGALIB is old. Please update to latest one to get better XaoS mouse_update (); keyboard_update ();#endif } else { mouse_update (); keyboard_update (); }#ifndef VGA_KEYEVENT { int i; for (i = 0; i < 128; i++) if (keys[i] && !keyboard_keypressed (i)) handler (i, 0); else { if (!keys[i] && keyboard_keypressed (i)) handler (i, 1); } }#endif *x = mouse_getx (); *y = mouse_gety (); *buttons = 0; if (mouse_getbutton () & MOUSE_LEFTBUTTON) *buttons |= BUTTON1; if (mouse_getbutton () & MOUSE_RIGHTBUTTON) *buttons |= BUTTON3; if (mouse_getbutton () & MOUSE_MIDDLEBUTTON) *buttons |= BUTTON2; *k = (keys[SCANCODE_CURSORBLOCKLEFT] != 0) + 2 * (keys[SCANCODE_CURSORBLOCKRIGHT] != 0) + 4 * (keys[SCANCODE_CURSORBLOCKUP] != 0) + 8 * (keys[SCANCODE_CURSORBLOCKDOWN] != 0); draw_mouse (mouse_getx (), mouse_gety (), 1);}static intsvga_alloc_buffers (char **buffer1, char **buffer2){ svga_currentbuff = 0; gl_setcontextvgavirtual (mode); gl_getcontext (&buffers[0]); gl_setcontextvgavirtual (mode); gl_getcontext (&buffers[1]); *buffer1 = buffers[0].vbuf; *buffer2 = buffers[1].vbuf; return (info->linewidth >= width ? info->linewidth : width * bbytesperpixel);}static voidsvga_free_buffers (char *buffer1, char *buffer2){ gl_freecontext (&buffers[0]); gl_freecontext (&buffers[1]);}static CONST struct params params[] = { {"", P_HELP, NULL, "SVGA driver options:"}, {"-mode", P_NUMBER, &defmode, "Select graphics mode(same number as in interactive menu)"}, {"-retrace", P_SWITCH, &retrace, "Wait for retrace before displaying"}, {"-grayscale", P_SWITCH, &grayscale, "Use grayscale mode instead of palette"}, {NULL, 0, NULL, NULL}};struct ui_driver svga_driver = { "SVGAlib", svga_init, svga_get_size, svga_processevents, svga_getmouse, svga_uninitialise, NULL, svga_setpalette, svga_print, svga_display, svga_alloc_buffers, svga_free_buffers, svga_flip_buffers, svga_mousetype, NULL, 8, 8, params, FULLSCREEN | UPDATE_AFTER_RESIZE | PALETTE_ROTATION | ROTATE_INSIDE_CALCULATION | RESIZE_COMMAND, 0.0, 0.0, 0, 0, UI_C256, 0, 256, 255};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -