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

📄 scvidctl.c

📁 基于组件方式开发操作系统的OSKIT源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*- * Copyright (c) 1998 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer as *    the first lines of this file unmodified. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $Id: scvidctl.c,v 1.7.2.1 1999/02/07 03:03:26 yokota Exp $ */#include "sc.h"#include "opt_syscons.h"#if NSC > 0#include <sys/param.h>#include <sys/systm.h>#include <sys/signalvar.h>#include <sys/tty.h>#include <sys/kernel.h>#ifdef __i386__#include <machine/apm_bios.h>#endif#include <machine/console.h>#include <dev/fb/fbreg.h>#include <dev/syscons/syscons.h>/* for compatibility with previous versions */typedef struct old_video_adapter {    int			va_index;    int			va_type;    int			va_flags;#define V_ADP_COLOR	(1<<0)#define V_ADP_MODECHANGE (1<<1)#define V_ADP_STATESAVE	(1<<2)#define V_ADP_STATELOAD	(1<<3)#define V_ADP_FONT	(1<<4)#define V_ADP_PALETTE	(1<<5)#define V_ADP_BORDER	(1<<6)#define V_ADP_VESA	(1<<7)    int			va_crtc_addr;    u_int		va_window;	/* virtual address */    size_t		va_window_size;    size_t		va_window_gran;    u_int		va_buffer;	/* virtual address */    size_t		va_buffer_size;    int			va_initial_mode;    int			va_initial_bios_mode;    int			va_mode;} old_video_adapter_t;#define OLD_CONS_ADPINFO _IOWR('c', 101, old_video_adapter_t)/* variables */extern scr_stat *cur_console;extern int fonts_loaded;extern int sc_history_size;extern u_char palette[];intsc_set_text_mode(scr_stat *scp, struct tty *tp, int mode, int xsize, int ysize,		 int fontsize){    video_info_t info;    int error;    int s;    int i;    if ((*vidsw[scp->ad]->get_info)(scp->adp, mode, &info))	return ENODEV;     /* adjust argument values */    if (fontsize <= 0)	fontsize = info.vi_cheight;    if (fontsize < 14) {	fontsize = 8;	if (!(fonts_loaded & FONT_8))	    return EINVAL;    } else if (fontsize >= 16) {	fontsize = 16;	if (!(fonts_loaded & FONT_16))	    return EINVAL;    } else {	fontsize = 14;	if (!(fonts_loaded & FONT_14))	    return EINVAL;    }    if ((xsize <= 0) || (xsize > info.vi_width))	xsize = info.vi_width;    if ((ysize <= 0) || (ysize > info.vi_height))	ysize = info.vi_height;    /* stop screen saver, etc */    s = spltty();    if ((error = sc_clean_up(scp))) {	splx(s);	return error;    }    /* set up scp */    if (scp->history != NULL)	i = imax(scp->history_size / scp->xsize 		 - imax(sc_history_size, scp->ysize), 0);    else	i = 0;    /*     * This is a kludge to fend off scrn_update() while we     * muck around with scp. XXX     */    scp->status |= UNKNOWN_MODE;    scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);    scp->mode = mode;    scp->font_size = fontsize;    scp->xsize = xsize;    scp->ysize = ysize;    scp->xoff = 0;    scp->yoff = 0;    scp->xpixel = scp->xsize*8;    scp->ypixel = scp->ysize*fontsize;    /* allocate buffers */    sc_alloc_scr_buffer(scp, TRUE, TRUE);    if (ISMOUSEAVAIL(scp->adp->va_flags))	sc_alloc_cut_buffer(scp, FALSE);    sc_alloc_history_buffer(scp, sc_history_size, i, FALSE);    splx(s);    if (scp == cur_console)	set_mode(scp);    scp->status &= ~UNKNOWN_MODE;    if (tp == NULL)	return 0;    if (tp->t_winsize.ws_col != scp->xsize	|| tp->t_winsize.ws_row != scp->ysize) {	tp->t_winsize.ws_col = scp->xsize;	tp->t_winsize.ws_row = scp->ysize;	pgsignal(tp->t_pgrp, SIGWINCH, 1);    }    return 0;}intsc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode){    video_info_t info;    int error;    int s;    if ((*vidsw[scp->ad]->get_info)(scp->adp, mode, &info))	return ENODEV;    /* stop screen saver, etc */    s = spltty();    if ((error = sc_clean_up(scp))) {	splx(s);	return error;    }    /* set up scp */    scp->status |= (UNKNOWN_MODE | GRAPHICS_MODE);    scp->status &= ~PIXEL_MODE;    scp->mode = mode;    scp->xoff = 0;    scp->yoff = 0;    scp->xpixel = info.vi_width;    scp->ypixel = info.vi_height;    scp->xsize = info.vi_width/8;    scp->ysize = info.vi_height/info.vi_cheight;    scp->font_size = FONT_NONE;    /* move the mouse cursor at the center of the screen */    sc_move_mouse(scp, scp->xpixel / 2, scp->ypixel / 2);    splx(s);    if (scp == cur_console)	set_mode(scp);    /* clear_graphics();*/    scp->status &= ~UNKNOWN_MODE;    if (tp == NULL)	return 0;    if (tp->t_winsize.ws_xpixel != scp->xpixel	|| tp->t_winsize.ws_ypixel != scp->ypixel) {	tp->t_winsize.ws_xpixel = scp->xpixel;	tp->t_winsize.ws_ypixel = scp->ypixel;	pgsignal(tp->t_pgrp, SIGWINCH, 1);    }    return 0;}intsc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize, int ysize, 		  int fontsize){    video_info_t info;    int error;    int s;    int i;    if ((*vidsw[scp->ad]->get_info)(scp->adp, scp->mode, &info))	return ENODEV;		/* this shouldn't happen */#ifdef SC_VIDEO_DEBUG    if (scp->scr_buf != NULL) {	printf("set_pixel_mode(): mode:%x, col:%d, row:%d, font:%d\n",	       scp->mode, xsize, ysize, fontsize);    }#endif    /* adjust argument values */    if ((fontsize <= 0) || (fontsize == FONT_NONE))	fontsize = info.vi_cheight;    if (fontsize < 14) {	fontsize = 8;	if (!(fonts_loaded & FONT_8))	    return EINVAL;    } else if (fontsize >= 16) {	fontsize = 16;	if (!(fonts_loaded & FONT_16))	    return EINVAL;    } else {	fontsize = 14;	if (!(fonts_loaded & FONT_14))	    return EINVAL;    }    if (xsize <= 0)	xsize = info.vi_width/8;    if (ysize <= 0)	ysize = info.vi_height/fontsize;#ifdef SC_VIDEO_DEBUG    if (scp->scr_buf != NULL) {	printf("set_pixel_mode(): mode:%x, col:%d, row:%d, font:%d\n",	       scp->mode, xsize, ysize, fontsize);	printf("set_pixel_mode(): window:%x, %dx%d, xoff:%d, yoff:%d\n",	       scp->adp->va_window, info.vi_width, info.vi_height, 	       (info.vi_width/8 - xsize)/2,	       (info.vi_height/fontsize - ysize)/2);    }#endif    if ((info.vi_width < xsize*8) || (info.vi_height < ysize*fontsize))	return EINVAL;    /* only 16 color, 4 plane modes are supported XXX */    if ((info.vi_depth != 4) || (info.vi_planes != 4))	return ENODEV;    /*     * set_pixel_mode() currently does not support video modes whose     * memory size is larger than 64K. Because such modes require     * bank switching to access the entire screen. XXX     */    if (info.vi_width*info.vi_height/8 > info.vi_window_size)	return ENODEV;    /* stop screen saver, etc */    s = spltty();    if ((error = sc_clean_up(scp))) {	splx(s);	return error;    }    /* set up scp */    if (scp->history != NULL)	i = imax(scp->history_size / scp->xsize 		 - imax(sc_history_size, scp->ysize), 0);    else	i = 0;    scp->status |= (UNKNOWN_MODE | PIXEL_MODE);

⌨️ 快捷键说明

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