void VGLEnd(void) { struct vt_mode smode; if (!VGLInitDone) return; VGLInitDone = 0; VGLSwitchPending = 0; VGLAbortPending = 0; signal(SIGUSR1, SIG_IGN); if (VGLMem != MAP_FAILED) { VGLClear(VGLDisplay, 0); munmap(VGLMem, VGLAdpInfo.va_window_size); } if (VGLOldMode >= M_VESA_BASE) { /* ugly, but necessary */ ioctl(0, _IO('V', VGLOldMode - M_VESA_BASE), 0); if (VGLOldMode == M_VESA_800x600) { int size[3]; size[0] = VGLOldWSize.ws_col; size[1] = VGLOldWSize.ws_row; size[2] = 16; ioctl(0, KDRASTER, size); } } else { ioctl(0, _IO('S', VGLOldMode), 0); } ioctl(0, KDDISABIO, 0); ioctl(0, KDSETMODE, KD_TEXT); smode.mode = VT_AUTO; ioctl(0, VT_SETMODE, &smode); if (VGLBuf) free(VGLBuf); VGLBuf = NULL; free(VGLDisplay); VGLDisplay = NULL; VGLKeyboardEnd(); }
void vgainit(void) { {int b=0; while (b);} if (geteuid() != 0) { fprintf(stderr, "The current graphics console architecture only permits " \ "super-user to access it, therefore you either have to obtain such permissions" \ "or ask your sysadmin to put set-user-id on digger executable.\n"); exit(1); } if (VGLInit(SW_VESA_CG640x400) != 0) { fprintf(stderr, "WARNING! Could not initialise VESA mode. " \ "Trying to fallback to the VGA 640x480 mode\n"); if (VGLInit(SW_CG640x480) == 0) yoffset = 40; /* Center the image */ else { fprintf(stderr, "WARNING! Could not initialise VGA mode either. " \ "Please check your kernel.\n"); exit(1); } } vgl_inited = 1; sVGLDisplay = VGLBitmapCreate(MEMBUF, 640, 400, NULL); VGLBitmapAllocateBits(sVGLDisplay); VGLClear(sVGLDisplay, 0); /* * Since the VGL library doesn't provide a default way to restore console * and keyboard after uncatched by the program signal, we should try to * catch at least what we could catch and pray to God that he would not * send SIGKILL to us. */ signal(SIGHUP, catcher); signal(SIGINT, catcher); signal(SIGQUIT, catcher); signal(SIGABRT, catcher); signal(SIGTERM, catcher); signal(SIGSEGV, catcher); signal(SIGBUS, catcher); signal(SIGILL, catcher); }
int main(int argc, char **argv) { int y, xsize, ysize, i,j; VGLBitmap *tmp; // set graphics mode, here 320x240 256 colors // supported modes are (from <sys/consio.h>): // SW_VGA_CG320: std VGA 320x200 256 colors // SW_VGA_MODEX: Modex VGA 320x240 256 colors // SW_VGA_VG640: std VGA 640x480 16 colors VGLInit(SW_VGA_MODEX); // initialize mouse and show pointer VGLMouseInit(VGL_MOUSESHOW); // VGLDisplay is a ptr to a struct Bitmap defined and initialized by // libvgl. The Bitmap points directly to screen memory etc. xsize=VGLDisplay->Xsize; ysize=VGLDisplay->Ysize; // alloc a new bitmap tmp = VGLBitmapCreate(MEMBUF, 256, 256, NULL); VGLBitmapAllocateBits(tmp); VGLClear(tmp, 0); // fill the screen with colored lines for (y=0; y<ysize; y++) VGLLine(VGLDisplay, 0, y, xsize-1, y, y/2 % 256); // draw some lines and circles just to show off VGLLine(VGLDisplay, 0, 0, xsize-1, ysize-1, 63); VGLLine(VGLDisplay, 0, ysize-1, xsize-1, 0, 63); VGLLine(VGLDisplay, 0, 0, 0, ysize-1, 63); VGLLine(VGLDisplay, xsize-1, 0, xsize-1, ysize-1, 63); VGLEllipse(VGLDisplay, 256, 0, 256, 256, 63); VGLEllipse(VGLDisplay, 0, 256, 256, 256, 0); // some text is also useful VGLBitmapString(VGLDisplay, 100,100, "This is text", 63, 0, 0, VGL_DIR_RIGHT); sleep(2); VGLBitmapString(VGLDisplay, 100,100, "This is text", 63, 0, 0, VGL_DIR_UP); sleep(2); VGLBitmapString(VGLDisplay, 100,100, "This is text", 63, 0, 0, VGL_DIR_LEFT); sleep(2); VGLBitmapString(VGLDisplay, 100,100, "This is text", 63, 0, 0, VGL_DIR_DOWN); sleep(2); // now show some simple bitblit for (i=0; i<256; i++) for (j=0; j<256; j++) tmp->Bitmap[i+256*j] = i%16; VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 0, 0, 128, 128); for (i=0; i<256; i++) for (j=0; j<256; j++) tmp->Bitmap[i+256*j] = j%16; VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 3, 128, 128, 128); sleep(2); VGLBitmapCopy(VGLDisplay, 237, 311, tmp, 64, 64, 128, 128); VGLBitmapCopy(tmp, 32, 32, VGLDisplay, 400, 128, 128, 128); sleep(2); VGLBitmapCopy(VGLDisplay, 300, 300, VGLDisplay, 500, 128, 128, 128); sleep(5); i=0; // loop around drawing and copying while (++i) { VGLBitmapCopy(VGLDisplay, rand()%xsize, rand()%ysize, VGLDisplay, rand()%xsize, rand()%ysize, rand()%xsize, rand()%ysize); VGLLine(VGLDisplay, rand()%xsize, rand()%ysize, rand()%xsize, rand()%ysize, rand()%256); VGLEllipse(VGLDisplay, rand()%xsize, rand()%ysize, rand()%xsize/2, rand()%ysize/2, rand()%256); rand(); if (i > 1000) break; } // restore screen to its original mode VGLEnd(); return 0; }
int VGLInit(int mode) { struct vt_mode smode; int adptype; if (VGLInitDone) return -1; signal(SIGUSR1, VGLSwitch); signal(SIGINT, VGLAbort); signal(SIGTERM, VGLAbort); signal(SIGSEGV, VGLAbort); signal(SIGBUS, VGLAbort); signal(SIGUSR2, SIG_IGN); VGLOnDisplay = 1; VGLSwitchPending = 0; VGLAbortPending = 0; if (ioctl(0, CONS_GET, &VGLOldMode) || ioctl(0, CONS_CURRENT, &adptype)) return -1; VGLModeInfo.vi_mode = mode; if (ioctl(0, CONS_MODEINFO, &VGLModeInfo)) /* FBIO_MODEINFO */ return -1; /* If current mode is VESA_800x600 then save its geometry to restore later */ if ((VGLOldMode >= M_VESA_BASE) && (VGLOldMode == M_VESA_800x600)) if (ioctl(0, TIOCGWINSZ, &VGLOldWSize)) return -1; VGLDisplay = (VGLBitmap *)malloc(sizeof(VGLBitmap)); if (VGLDisplay == NULL) return -2; if (ioctl(0, KDENABIO, 0)) { free(VGLDisplay); return -3; } VGLInitDone = 1; /* * vi_mem_model specifies the memory model of the current video mode * in -CURRENT. */ switch (VGLModeInfo.vi_mem_model) { case V_INFO_MM_PLANAR: /* we can handle EGA/VGA planner modes only */ if (VGLModeInfo.vi_depth != 4 || VGLModeInfo.vi_planes != 4 || (adptype != KD_EGA && adptype != KD_VGA)) { VGLEnd(); return -4; } VGLDisplay->Type = VIDBUF4; break; case V_INFO_MM_PACKED: /* we can do only 256 color packed modes */ if (VGLModeInfo.vi_depth != 8) { VGLEnd(); return -4; } VGLDisplay->Type = VIDBUF8; break; case V_INFO_MM_VGAX: VGLDisplay->Type = VIDBUF8X; break; default: VGLEnd(); return -4; } ioctl(0, VT_WAITACTIVE, 0); ioctl(0, KDSETMODE, KD_GRAPHICS); if (ioctl(0, CONS_SET, &mode)) { VGLEnd(); return -5; } if (ioctl(0, CONS_ADPINFO, &VGLAdpInfo)) { /* FBIO_ADPINFO */ VGLEnd(); return -6; } /* * Calculate the shadow screen buffer size. In -CURRENT, va_buffer_size * always holds the entire frame buffer size, wheather it's in the linear * mode or windowed mode. * VGLBufSize = VGLAdpInfo.va_buffer_size; * In -STABLE, va_buffer_size holds the frame buffer size, only if * the linear frame buffer mode is supported. Otherwise the field is zero. * We shall calculate the minimal size in this case: * VGLAdpInfo.va_line_width*VGLModeInfo.vi_height*VGLModeInfo.vi_planes * or * VGLAdpInfo.va_window_size*VGLModeInfo.vi_planes; * Use whichever is larger. */ if (VGLAdpInfo.va_buffer_size != 0) VGLBufSize = VGLAdpInfo.va_buffer_size; else VGLBufSize = max(VGLAdpInfo.va_line_width*VGLModeInfo.vi_height, VGLAdpInfo.va_window_size)*VGLModeInfo.vi_planes; VGLBuf = malloc(VGLBufSize); if (VGLBuf == NULL) { VGLEnd(); return -7; } #ifdef LIBVGL_DEBUG fprintf(stderr, "VGLBufSize:0x%x\n", VGLBufSize); #endif /* see if we are in the windowed buffer mode or in the linear buffer mode */ if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size) { if (VGLDisplay->Type == VIDBUF4) VGLDisplay->Type = VIDBUF4S; else if (VGLDisplay->Type == VIDBUF8) VGLDisplay->Type = VIDBUF8S; } VGLMode = mode; VGLCurWindow = 0; VGLDisplay->Xsize = VGLModeInfo.vi_width; VGLDisplay->Ysize = VGLModeInfo.vi_height; VGLDisplay->VXsize = VGLAdpInfo.va_line_width *8/(VGLModeInfo.vi_depth/VGLModeInfo.vi_planes); VGLDisplay->VYsize = VGLBufSize/VGLModeInfo.vi_planes/VGLAdpInfo.va_line_width; VGLDisplay->Xorigin = 0; VGLDisplay->Yorigin = 0; VGLMem = (byte*)mmap(0, VGLAdpInfo.va_window_size, PROT_READ|PROT_WRITE, MAP_FILE, 0, 0); if (VGLMem == MAP_FAILED) { VGLEnd(); return -7; } VGLDisplay->Bitmap = VGLMem; VGLSavePalette(); #ifdef LIBVGL_DEBUG fprintf(stderr, "va_line_width:%d\n", VGLAdpInfo.va_line_width); fprintf(stderr, "VGLXsize:%d, Ysize:%d, VXsize:%d, VYsize:%d\n", VGLDisplay->Xsize, VGLDisplay->Ysize, VGLDisplay->VXsize, VGLDisplay->VYsize); #endif smode.mode = VT_PROCESS; smode.waitv = 0; smode.relsig = SIGUSR1; smode.acqsig = SIGUSR1; smode.frsig = SIGINT; if (ioctl(0, VT_SETMODE, &smode)) { VGLEnd(); return -9; } VGLTextSetFontFile(NULL); VGLClear(VGLDisplay, 0); return 0; }
void vgaclear(void) { VGLClear(sVGLDisplay, 0); VGLClear(VGLDisplay, 0); }