⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vga.c

📁 linux 下svgalib编的一个界面程序示例
💻 C
📖 第 1 页 / 共 5 页
字号:
/* VGAlib version 1.2 - (c) 1993 Tommy Frandsen                    *//*                                                                 *//* This library is free software; you can redistribute it and/or   *//* modify it without any restrictions. This library is distributed *//* in the hope that it will be useful, but without any warranty.   *//* Multi-chipset support Copyright (C) 1993 Harm Hanemaayer *//* partially copyrighted (C) 1993 by Hartmut Schirmer *//* Changes by Michael Weller. *//* Modified by Don Secrest to include Tseng ET6000 handling *//* Changes around the config things by 101 (Attila Lendvai) *//* The code is a bit of a mess; also note that the drawing functions *//* are not speed optimized (the gl functions are much faster). */#define _GNU_SOURCE#include <stdlib.h>#include <stdio.h>#include <fcntl.h>#include <signal.h>#include <termios.h>#include <string.h>#include <unistd.h>#include <stdarg.h>#include <sys/mman.h>#include <sys/kd.h>#include <sys/ioctl.h>#include <sys/stat.h>#include <sys/vt.h>#include <sys/wait.h>#include <errno.h>#include <ctype.h>#include "vga.h"#include "libvga.h"#include "driver.h"#include "vgapci.h"#include "mouse/vgamouse.h"#include "keyboard/vgakeyboard.h"#include "vgaregs.h"#include "vgaversion.h"#ifdef BACKGROUND#include "vgabg.h"/* ugly check to prevent usage on kernel versions < 2.0.36 and < 2.1.123 * should this also be runtime checked? * * Why not earlier kernels? * The following sequence of mmap() calls is deadly in these versions * due to a kernel bug: * #define MAP_ADDR 0xfd000000  // high mem area, eg. framebuf * #define MAP_SIZE 0x200000 * map_a=mmap(0,MAP_SIZE,PROT_READ|PROT_WRITE, *            MAP_PRIVATE|MAP_ANONYMOUS,-1,0); * map_b=mmap(0,MAP_SIZE,PROT_READ | PROT_WRITE, *            MAP_SHARED,dev_mem_fd,MAP_ADDR); * map_c=mmap(map_a,MAP_SIZE,PROT_READ | PROT_WRITE, *           MAP_SHARED | MAP_FIXED,proc_self_mem_fd, *           map_b); * The map_c mmapping will destroy random kernel data. A similar * mmap sequence is done when calling __svgalib_map_virtual_screen() * to map the linear framebuffer virtual address to the final * virtual address (which then can mapped to backing storage on VC switch, * transparently for the application). */#include <linux/version.h>#define LNX_MAJ_VER ((LINUX_VERSION_CODE >> 16) & 255)#define LNX_MED_VER ((LINUX_VERSION_CODE >> 8) & 255)#define LNX_MIN_VER (LINUX_VERSION_CODE & 255)#if (LNX_MAJ_VER < 2) || \    ( (LNX_MAJ_VER == 2) && (LNX_MED_VER == 0) && (LNX_MIN_VER < 36) ) || \    ( (LNX_MAJ_VER == 2) && (LNX_MED_VER == 1) && (LNX_MIN_VER < 123) ) || \    ( (LNX_MAJ_VER == 2) && (LNX_MED_VER == 3) && (LNX_MIN_VER > 26) )#warning BACKGROUND *not* supported on kernel versions < 2.0.36 or < 2.1.123,#warning or version>2.3.26. Compile without BACKGROUND.#endif#endif /* #ifdef BACKGROUND *//* Delay in microseconds after a mode is set (screen is blanked during this *//* time), allows video signals to stabilize */#define MODESWITCHDELAY 150000/* Define this to disable video output during mode switches, in addition to *//* 'turning off the screen', which is always done. *//* Doesn't look very nice on my Cirrus. *//* #define DISABLE_VIDEO_OUTPUT *//* #define DONT_WAIT_VC_ACTIVE *//* Use /dev/tty instead of /dev/tty0 (the previous behaviour may have been * silly). */#define USE_DEVTTY#define SETSIG(sa, sig, fun) {\	sa.sa_handler = fun; \	sa.sa_flags = SA_RESTART; \	zero_sa_mask(&(sa.sa_mask)); \	sigaction(sig, &sa, NULL); \}#ifdef INCLUDE_VESA_DRIVERextern int __svgalib_lrmi_cpu_type;#endif/* variables used to shift between monchrome and color emulation */int __svgalib_CRT_I;			/* current CRT index register address */int __svgalib_CRT_D;			/* current CRT data register address */int __svgalib_IS1_R;			/* current input status register address */static int color_text;		/* true if color text emulation */unsigned char * BANKED_MEM_POINTER=NULL, * LINEAR_MEM_POINTER, *MMIO_POINTER;unsigned char * B8000_MEM_POINTER=NULL;unsigned long int __svgalib_banked_mem_base, __svgalib_banked_mem_size;unsigned long int __svgalib_mmio_base, __svgalib_mmio_size=0;unsigned long int __svgalib_linear_mem_base=0, __svgalib_linear_mem_size=0;/* If == 0 then nothing is defined by the user... */int __svgalib_default_mode = 0;struct info infotable[] ={    {80, 25, 16, 160, 0},	/* VGAlib VGA modes */    {320, 200, 16, 40, 0},    {640, 200, 16, 80, 0},    {640, 350, 16, 80, 0},    {640, 480, 16, 80, 0},    {320, 200, 256, 320, 1},    {320, 240, 256, 80, 0},    {320, 400, 256, 80, 0},    {360, 480, 256, 90, 0},    {640, 480, 2, 80, 0},    {640, 480, 256, 640, 1},	/* VGAlib SVGA modes */    {800, 600, 256, 800, 1},    {1024, 768, 256, 1024, 1},    {1280, 1024, 256, 1280, 1},    {320, 200, 1 << 15, 640, 2},	/* Hicolor/truecolor modes */    {320, 200, 1 << 16, 640, 2},    {320, 200, 1 << 24, 320 * 3, 3},    {640, 480, 1 << 15, 640 * 2, 2},    {640, 480, 1 << 16, 640 * 2, 2},    {640, 480, 1 << 24, 640 * 3, 3},    {800, 600, 1 << 15, 800 * 2, 2},    {800, 600, 1 << 16, 800 * 2, 2},    {800, 600, 1 << 24, 800 * 3, 3},    {1024, 768, 1 << 15, 1024 * 2, 2},    {1024, 768, 1 << 16, 1024 * 2, 2},    {1024, 768, 1 << 24, 1024 * 3, 3},    {1280, 1024, 1 << 15, 1280 * 2, 2},    {1280, 1024, 1 << 16, 1280 * 2, 2},    {1280, 1024, 1 << 24, 1280 * 3, 3},    {800, 600, 16, 100, 0},	/* SVGA 16-color modes */    {1024, 768, 16, 128, 0},    {1280, 1024, 16, 160, 0},    {720, 348, 2, 90, 0},	/* Hercules emulation mode */    {320, 200, 1 << 24, 320 * 4, 4},    {640, 480, 1 << 24, 640 * 4, 4},    {800, 600, 1 << 24, 800 * 4, 4},    {1024, 768, 1 << 24, 1024 * 4, 4},    {1280, 1024, 1 << 24, 1280 * 4, 4},    {1152, 864, 16, 144, 0},    {1152, 864, 256, 1152, 1},    {1152, 864, 1 << 15, 1152 * 2, 2},    {1152, 864, 1 << 16, 1152 * 2, 2},    {1152, 864, 1 << 24, 1152 * 3, 3},    {1152, 864, 1 << 24, 1152 * 4, 4},    {1600, 1200, 16, 200, 0},    {1600, 1200, 256, 1600, 1},    {1600, 1200, 1 << 15, 1600 * 2, 2},    {1600, 1200, 1 << 16, 1600 * 2, 2},    {1600, 1200, 1 << 24, 1600 * 3, 3},    {1600, 1200, 1 << 24, 1600 * 4, 4},    {320, 240, 256, 320, 1},	    {320, 240, 1<<15, 320*2, 2},    {320, 240, 1<<16, 320*2, 2},    {320, 240, 1<<24, 320*3, 3},    {320, 240, 1<<24, 320*4, 4},         {400, 300, 256, 400, 1},    {400, 300, 1<<15, 400*2, 2},    {400, 300, 1<<16, 400*2, 2},    {400, 300, 1<<24, 400*3, 3},    {400, 300, 1<<24, 400*4, 4},         {512, 384, 256, 512, 1},		    {512, 384, 1<<15, 512*2, 2},    {512, 384, 1<<16, 512*2, 2},    {512, 384, 1<<24, 512*3, 3},    {512, 384, 1<<24, 512*4, 4},    {960, 720, 256, 960, 1},		    {960, 720, 1<<15, 960*2, 2},    {960, 720, 1<<16, 960*2, 2},    {960, 720, 1<<24, 960*3, 3},    {960, 720, 1<<24, 960*4, 4},    {1920, 1440, 256, 1920, 1},		    {1920, 1440, 1<<15, 1920*2, 2},    {1920, 1440, 1<<16, 1920*2, 2},    {1920, 1440, 1<<24, 1920*3, 3},    {1920, 1440, 1<<24, 1920*4, 4},    {320, 400, 1<<8,  320,   1},    {320, 400, 1<<15, 320*2, 2},    {320, 400, 1<<16, 320*2, 2},    {320, 400, 1<<24, 320*3, 3},    {320, 400, 1<<24, 320*4, 4},    {640, 400, 256, 640, 1},    {640, 400, 1<<15, 640*2, 2},    {640, 400, 1<<16, 640*2, 2},    {640, 400, 1<<24, 640*3, 3},    {640, 400, 1<<24, 640*4, 4},    {320, 480, 256, 320, 1},    {320, 480, 1<<15, 320*2, 2},    {320, 480, 1<<16, 320*2, 2},    {320, 480, 1<<24, 320*3, 3},    {320, 480, 1<<24, 320*4, 4},    {720, 540, 256, 720, 1},    {720, 540, 1<<15, 720*2, 2},    {720, 540, 1<<16, 720*2, 2},    {720, 540, 1<<24, 720*3, 3},    {720, 540, 1<<24, 720*4, 4},    {848, 480, 256, 848, 1},    {848, 480, 1<<15, 848*2, 2},    {848, 480, 1<<16, 848*2, 2},    {848, 480, 1<<24, 848*3, 3},    {848, 480, 1<<24, 848*4, 4},    {1072, 600, 256, 1072, 1},    {1072, 600, 1<<15, 1072*2, 2},    {1072, 600, 1<<16, 1072*2, 2},    {1072, 600, 1<<24, 1072*3, 3},    {1072, 600, 1<<24, 1072*4, 4},    {1280, 720, 256, 1280, 1},    {1280, 720, 1<<15, 1280*2, 2},    {1280, 720, 1<<16, 1280*2, 2},    {1280, 720, 1<<24, 1280*3, 3},    {1280, 720, 1<<24, 1280*4, 4},    {1360, 768, 256, 1360, 1},    {1360, 768, 1<<15, 1360*2, 2},    {1360, 768, 1<<16, 1360*2, 2},    {1360, 768, 1<<24, 1360*3, 3},    {1360, 768, 1<<24, 1360*4, 4},    {1800, 1012, 256, 1800, 1},    {1800, 1012, 1<<15, 1800*2, 2},    {1800, 1012, 1<<16, 1800*2, 2},    {1800, 1012, 1<<24, 1800*3, 3},    {1800, 1012, 1<<24, 1800*4, 4},    {1920, 1080, 256, 1920, 1},    {1920, 1080, 1<<15, 1920*2, 2},    {1920, 1080, 1<<16, 1920*2, 2},    {1920, 1080, 1<<24, 1920*3, 3},    {1920, 1080, 1<<24, 1920*4, 4},    {2048, 1152, 256, 2048, 1},    {2048, 1152, 1<<15, 2048*2, 2},    {2048, 1152, 1<<16, 2048*2, 2},    {2048, 1152, 1<<24, 2048*3, 3},    {2048, 1152, 1<<24, 2048*4, 4},    {2048, 1536, 256, 2048, 1},    {2048, 1536, 1<<15, 2048*2, 2},    {2048, 1536, 1<<16, 2048*2, 2},    {2048, 1536, 1<<24, 2048*3, 3},    {2048, 1536, 1<<24, 2048*4, 4},    {512, 480, 256, 512, 1},		    {512, 480, 1<<15, 512*2, 2},    {512, 480, 1<<16, 512*2, 2},    {512, 480, 1<<24, 512*3, 3},    {512, 480, 1<<24, 512*4, 4},    {400, 600, 256, 400, 1},    {400, 600, 1<<15, 400*2, 2},    {400, 600, 1<<16, 400*2, 2},    {400, 600, 1<<24, 400*3, 3},    {400, 600, 1<<24, 400*4, 4},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0},    {0, 0, 0, 0, 0}};#define MAX_MODES (sizeof(infotable) / sizeof(struct info))#ifndef BACKGROUNDvoid (*__svgalib_go_to_background) (void) = 0;void (*__svgalib_come_from_background) (void) = 0;static int release_acquire=0;#endif /* BACKGROUND */unsigned long __svgalib_graph_base = GRAPH_BASE;unsigned char __svgalib_novga = 0;     /* Does not have VGA circuitry on board */unsigned char __svgalib_vesatext = 0;unsigned char __svgalib_textprog = 0;  /* run a program when returning to text mode */unsigned char __svgalib_secondary = 0; /* this is not the main card with VC'S (not yet supported) */unsigned char __svgalib_novccontrol = 0; /* this is not the main card with VC'S (not yet supported) */unsigned char __svgalib_simple = 0;unsigned char __svgalib_ragedoubleclock = 0;/* default palette values */static const unsigned char default_red[256]={0, 0, 0, 0, 42, 42, 42, 42, 21, 21, 21, 21, 63, 63, 63, 63, 0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63, 0, 16, 31, 47, 63, 63, 63, 63, 63, 63, 63, 63, 63, 47, 31, 16, 0, 0, 0, 0, 0, 0, 0, 0, 31, 39, 47, 55, 63, 63, 63, 63, 63, 63, 63, 63, 63, 55, 47, 39, 31, 31, 31, 31, 31, 31, 31, 31, 45, 49, 54, 58, 63, 63, 63, 63, 63, 63, 63, 63, 63, 58, 54, 49, 45, 45, 45, 45, 45, 45, 45, 45, 0, 7, 14, 21, 28, 28, 28, 28, 28, 28, 28, 28, 28, 21, 14, 7, 0, 0, 0, 0, 0, 0, 0, 0, 14, 17, 21, 24, 28, 28, 28, 28, 28, 28, 28, 28, 28, 24, 21, 17, 14, 14, 14, 14, 14, 14, 14, 14, 20, 22, 24, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 26, 24, 22, 20, 20, 20, 20, 20, 20, 20, 20, 0, 4, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 12, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10, 8, 8, 8, 8, 8, 8, 8, 8, 11, 12, 13, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 13, 12, 11, 11, 11, 11, 11, 11, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0};static const unsigned char default_green[256]={0, 0, 42, 42, 0, 0, 21, 42, 21, 21, 63, 63, 21, 21, 63, 63, 0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 31, 47, 63, 63, 63, 63, 63, 63, 63, 63, 63, 47, 31, 16, 31, 31, 31, 31, 31, 31, 31, 31, 31, 39, 47, 55, 63, 63, 63, 63, 63, 63, 63, 63, 63, 55, 47, 39, 45, 45, 45, 45, 45, 45, 45, 45, 45, 49, 54, 58, 63, 63, 63, 63, 63, 63, 63, 63, 63, 58, 54, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 14, 21, 29, 28, 28, 28, 28, 28, 28, 28, 28, 21, 14, 7, 14, 14, 14, 14, 14, 14, 14, 14, 14, 17, 21, 24, 28, 28, 28, 28, 28, 28, 28, 28, 28, 24, 21, 17, 20, 20, 20, 20, 20, 20, 20, 20, 20, 22, 24, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 26, 24, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, 8, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 12, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 13, 12, 0, 0, 0, 0, 0, 0, 0, 0};static const unsigned char default_blue[256]={0, 42, 0, 42, 0, 42, 0, 42, 21, 63, 21, 63, 21, 63, 21, 63, 0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63, 63, 63, 63, 63, 63, 47, 31, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 31, 47, 63, 63, 63, 63, 63, 63, 63, 63, 63, 55, 47, 39, 31, 31, 31, 31, 31, 31, 31, 31, 31, 39, 47, 55, 63, 63, 63, 63, 63, 63, 63, 63, 63, 58, 54, 49, 45, 45, 45, 45, 45, 45, 45, 45, 45, 49, 54, 58, 63, 63, 63, 63, 28, 28, 28, 28, 28, 21, 14, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 14, 21, 28, 28, 28, 28, 28, 28, 28, 28, 28, 24, 21, 17, 14, 14, 14, 14, 14, 14, 14, 14, 14, 17, 21, 24, 28, 28, 28, 28, 28, 28, 28, 28, 28, 26, 24, 22, 20, 20, 20, 20, 20, 20, 20, 20, 20, 22, 24, 26, 28, 28, 28, 28, 16, 16, 16, 16, 16, 12, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 12, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 13, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 15, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0};static unsigned char text_regs[MAX_REGS];	/* VGA registers for saved text mode */static unsigned char graph_regs[MAX_REGS];	/* VGA registers for svgalib mode */char *__svgalib_TextProg_argv[16]; /* should be enough */char *__svgalib_TextProg;/* saved text mode palette values */static unsigned char text_red[256];static unsigned char text_green[256];static unsigned char text_blue[256];/* saved graphics mode palette values */static unsigned char graph_red[256];static unsigned char graph_green[256];static unsigned char graph_blue[256];static int prv_mode = TEXT;	/* previous video mode      */static int flip_mode = TEXT;	/* flipped video mode       */int CM = TEXT;			/* current video mode       */struct info CI;			/* current video parameters */int COL;			/* current color            */static int initialized = 0;	/* flag: initialize() called ?  */static int flip = 0;		/* flag: executing vga_flip() ? *//* svgalib additions: */int __svgalib_chipset = UNDEFINED;int __svgalib_driver_report = 1;	/* report driver used after chipset detection */int __svgalib_videomemoryused = -1;int __svgalib_modeX = 0;	/* true after vga_setmodeX() */int __svgalib_modeflags = 0;	/* copy of flags for current mode */int __svgalib_critical = 0;	/* indicates blitter is busy */int __svgalib_screenon = 1;	/* screen visible if != 0 */RefreshRange __svgalib_horizsync ={31500U, 0U};			/* horz. refresh (Hz) min, max */RefreshRange __svgalib_vertrefresh ={50U, 70U};			/* vert. refresh (Hz) min, max */int __svgalib_bandwidth=50000;  /* monitor maximum bandwidth (kHz) */int __svgalib_grayscale = 0;	/* grayscale vs. color mode */int __svgalib_modeinfo_linearset = 0;	/* IS_LINEAR handled via extended vga_modeinfo */const int __svgalib_max_modes = MAX_MODES;	/* Needed for dynamical allocated tables in mach32.c */static unsigned __svgalib_maxhsync[] ={    31500, 35100, 35500, 37900, 48300, 56000, 60000};static int lastmodenumber = __GLASTMODE;	/* Last defined mode */static int my_pid = 0;		/* process PID, used with atexit() */#ifndef BACKGROUNDstatic int __svgalib_currentpage;#endifstatic int vga_page_offset;	/* offset to add to all vga_set*page() calls */static int currentlogicalwidth;static int currentdisplaystart;static int mouse_support = 0;int mouse_open = 0;static int mouse_mode = 0;static int mouse_type = -1;static int mouse_modem_ctl = 0;static char *mouse_device = "/dev/mouse";#ifndef BACKGROUNDstatic int __svgalib_oktowrite = 1;#endifstatic int modeinfo_mask = ~0;int __svgalib_mem_fd = -1;	/* /dev/mem file descriptor  */int __svgalib_tty_fd = -1;	/* /dev/tty file descriptor */int __svgalib_nosigint = 0;	/* Don't generate SIGINT in graphics mode */int __svgalib_runinbackground = 0;static int svgalib_vc = -1, startup_vc = -1;static int __svgalib_security_revokeallprivs = 1;static unsigned fontbufsize = 8192; /* compatibility *//* Dummy buffer for mmapping grahics memory; points to 64K VGA framebuffer. */unsigned char *__svgalib_graph_mem;/* Exported variable (read-only) is shadowed from internal variable, for *//* better shared library performance. */unsigned char *graph_mem;/* static unsigned char saved_text[32768]; *//* Some new organisation for backgrund running. *//* Alpha do not have ability to run in background (yet). *//* Bg runnin has two different methods 1 and (2). */       #ifdef BACKGROUND

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -