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

📄 vga.c

📁 基于组件方式开发操作系统的OSKIT源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* 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. *//* 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>#ifndef OSKIT#include <sys/kd.h>#include <sys/ioctl.h>#include <sys/vt.h>#endif#include <sys/wait.h>#include <errno.h>#include <ctype.h>#ifdef USEGLIBC#include <sys/io.h>#endif#include "vga.h"#include "libvga.h"#include "driver.h"#ifndef OSKIT#include "mouse/vgamouse.h"#include "keyboard/vgakeyboard.h"#endif#ifdef BACKGROUND#include "vgabg.h"#endif/* 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/* 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 */int color_text;		/* true if color text emulation *//* 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},    {0, 0, 0, 0, 0},		/* 16 user definable modes */    {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))unsigned long __svgalib_graph_base = GRAPH_BASE;unsigned char __svgalib_novga = 0;     /* Does not have VGA circuitry on board */unsigned char __svgalib_secondary = 0; /* this is not the main card with VC'S (not yet supported) *//* 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};unsigned char text_regs[MAX_REGS];	/* VGA registers for saved text mode *//* saved text mode palette values */unsigned char text_red[256];unsigned char text_green[256];unsigned char text_blue[256];#ifndef OSKIT/* saved graphics mode palette values */static unsigned char graph_red[256];static unsigned char graph_green[256];static unsigned char graph_blue[256];#endifint prv_mode = TEXT;	/* previous video mode      */#ifndef OSKITstatic int flip_mode = TEXT;	/* flipped video mode       */#endifint CM = TEXT;			/* current video mode       */struct info CI;			/* current video parameters */int COL;			/* current color            */extern int initialized;		/* 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_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 */unsigned __svgalib_maxhsync[] ={    31500, 35100, 35500, 37900, 48300, 56000, 60000};static int lastmodenumber = __GLASTMODE;	/* Last defined mode */#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;#ifndef OSKITstatic int mouse_support = 0;static int mouse_mode = 0;static int mouse_type = -1;static int mouse_modem_ctl = 0;static char *mouse_device = "/dev/mouse";#endif /* !OSKIT */#ifndef BACKGROUNDstatic int __svgalib_oktowrite = 1;#endifint modeinfo_mask = ~0;#ifndef OSKITint __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;#endif /* !OSKIT */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;/* 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 BACKGROUNDstatic 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_linear_memory_size;int __svgalib_oktowrite=1;/* __svgalib_oktowrite tells if it is safe to write registers. */int __svgalib_currentpage;static int __svgalib_virtual_mem_fd=-1;static int __svgalib_processnumber=-1;#endif#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 */unsigned char *font_buf1;	/* saved font data - plane 2 */unsigned char *font_buf2;	/* saved font data - plane 3 */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);	/* gives little faster vga_setpage() */void (*__svgalib_setrdpage) (int);void (*__svgalib_setwrpage) (int);#endifDriverSpecs *__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};/*#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);#ifndef OSKIT    sync();#endif /* !OSKIT */}#else#define _DEBUG(d)#endifvoid __svgalib_delay(void){    int i;    for (i = 0; i < 10; i++);}/* The Xfree server uses a slow copy, may help us too ... */#if defined(CONFIG_ALPHA_JENSEN)extern unsigned long vga_readl(unsigned long base, unsigned long off);extern void vga_writel(unsigned long b, unsigned long base, unsigned long off);void slowcpy_from_sm(unsigned char *dest, unsigned char *src, unsigned bytes){    long i;    if (((long) dest & 7) || ((long) src & 7) || bytes & 7) {	printf("svgalib: unaligned slowcpy()!\n");	exit(1);    }    for (i = 0; i < bytes; i++) {	*(dest + i) = (*(unsigned long *) (src + (i << 7)) >> ((i & 0x03) * 8))	    & 0xffUL;    }}void slowcpy_to_sm(unsigned char *dest, unsigned char *src, unsigned bytes){    long i;    if (((long) dest & 7) || ((long) src & 7) || bytes & 7) {	printf("svgalib: unaligned slowcpy()!\n");	exit(1);    }    for (i = 0; i < bytes; i++) {	*(unsigned long *) (dest + (i << 7)) =	    (*(unsigned char *) (src + i)) * 0x01010101UL;    }}#elsevoid slowcpy(unsigned char *dest, unsigned char *src, unsigned bytes){#ifdef __alpha__    if (((long) dest & 7) || ((long) src & 7) || bytes & 7) {	printf("svgalib: unaligned slowcpy()!\n");	exit(1);    }    while (bytes > 0) {	*(long *) dest = *(long *) src;	dest += 8;	src += 8;	bytes -= 8;    }#else    while (bytes-- > 0)	*(dest++) = *(src++);#endif}#endifint __svgalib_saveregs(unsigned char *regs){    int i;    if (__svgalib_chipset == EGA || __svgalib_novga) {	/* Special case: Don't save standard VGA registers. */	return chipset_saveregs(regs);    }    /* save VGA registers */    for (i = 0; i < CRT_C; i++) {	port_out(i, __svgalib_CRT_I);	regs[CRT + i] = port_in(__svgalib_CRT_D);    }    for (i = 0; i < ATT_C; i++) {	port_in(__svgalib_IS1_R);	__svgalib_delay();	port_out(i, ATT_IW);	__svgalib_delay();	regs[ATT + i] = port_in(ATT_R);	__svgalib_delay();    }    for (i = 0; i < GRA_C; i++) {	port_out(i, GRA_I);	regs[GRA + i] = port_in(GRA_D);    }    for (i = 0; i < SEQ_C; i++) {	port_out(i, SEQ_I);	regs[SEQ + i] = port_in(SEQ_D);    }    regs[MIS] = port_in(MIS_R);    i = chipset_saveregs(regs);	/* save chipset-specific registers */    /* i : additional registers */    if (!SCREENON) {		/* We turned off the screen */	port_in(__svgalib_IS1_R);	__svgalib_delay();	port_out(0x20, ATT_IW);    }    return CRT_C + ATT_C + GRA_C + SEQ_C + 1 + i;}int __svgalib_setregs(const unsigned char *regs){    int i;

⌨️ 快捷键说明

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