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

📄 m6845vga.c

📁 cpc-1631的BSP包for VxWorks操作系统
💻 C
📖 第 1 页 / 共 4 页
字号:
/* m6845Vga.c - motorola 6845 vga console driver routines */

/* Copyright 1993-1993 Wind River System, Inc. */
#include "copyright_wrs.h"

/*
modification history
--------------------
01e,12feb97,hdn  fixed the bug causes workQ panic. (SPR#7923)
01d,03aug95,myz  fixed the warning message
01c,14jun95,hdn  removed function declarations defined in sysLib.h.
01b,30mar94,hdn  changed CONSOLE_TTY to PC_CONSOLE.
01a,20oct93,vin  created
*/

/*
DESCRIPTION
This is the driver fo Video Contoroller Chip (6845) normally  used in the
386/486 personal computers.

USER CALLABLE ROUTINES
The routines in this driver are accessed from a generic console
driver through the hook routine, the pointer to which is initialized
in the VGA_CON_DEV structure at the time of initialization.
This makes the access to these routines more generic without declaring
these functions as external. 

The routines in this driver which are accessed from an external module
are vgaWriteString() and vgaHrdInit(). vgaWriteString() is installed
as a device transmit start-up routine in tyDevInit(). vgaHrdInit() is
called to initialize the device descriptors and the vga console.

All virtual consoles are mapped to the same screen buffer. This is a 
very basic implementation of virtual consoles. Multiple screen
buffers are not used to switch between consoles. This implementation
is left for the future. Mutual exclusion for the screen buffer is 
guaranteed within the same console but it is not implemented across multiple
virtual consoles because all virtual consoles use the same screen buffer. If
multiple screen buffers are implemented then the mutual exclusion between
virtual consoles can be implemented.

Before using the driver, it must be initialized by calling vgaHrdInit(). 
This routine should be called exactly once. Normally, it is called from 
a generic driver for eg. from tyCoDrv() which is called before tyCoDevCreate.


SEE ALSO
tyLib

NOTES
The macro N_VIRTUAL_CONSOLES should be defined in config.h file.
This refers to the number of virtual consoles which the user wishes to have.
The user should define INCLUDE_ANSI_ESC_SEQUENCE in <target>.h file if
the ansi escape sequences are required. Special processing in the vga
driver is done if an escape sequence exists.
*/

/* includes */

#include "vxWorks.h"
#include "iv.h"
#include "ioLib.h"
#include "iosLib.h"
#include "memLib.h"
#include "rngLib.h"
#include "tyLib.h"
#include "private/funcBindP.h"
#include "intLib.h"
#include "taskLib.h"
#include "errnoLib.h"
#include "stdio.h"
#include "string.h"
#include "config.h"
#include "pcConsole.h"
#include "pc.h"


/* externals */

IMPORT PC_CON_DEV	pcConDv [N_VIRTUAL_CONSOLES] ;


/* locals */

LOCAL VGA_CON_DEV	vgaConDv [N_VIRTUAL_CONSOLES];
LOCAL UCHAR		curSt,curEd;		/* current cursor mode */
LOCAL int 		tyWrtThreshold  = 20;	/* min bytes free in output 
						 * buffer before the next 
						 * writer will be enabled */
LOCAL int 		jobaddThreshold = 20;	/* bytes processed in int lvl */
LOCAL UCHAR * vgaCharTable [] = 
    {
    /* 8-bit Latin-1 mapped to the PC charater set: '\0' means non-printable */
    (unsigned char *)
    "\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"
    " !\"#$%&'()*+,-./0123456789:;<=>?"
    "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
    "`abcdefghijklmnopqrstuvwxyz{|}~\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"
    "\040\255\233\234\376\235\174\025\376\376\246\256\252\055\376\376"
    "\370\361\375\376\376\346\024\371\376\376\247\257\254\253\376\250"
    "\376\376\376\376\216\217\222\200\376\220\376\376\376\376\376\376"
    "\376\245\376\376\376\376\231\376\235\376\376\376\232\376\376\341"
    "\205\240\203\376\204\206\221\207\212\202\210\211\215\241\214\213"
    "\376\244\225\242\223\376\224\366\233\227\243\226\201\376\376\230",
    /* vt100 graphics */
    (unsigned char *)
    "\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"
    " !\"#$%&'()*+,-./0123456789:;<=>?"
    "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ "
    "\004\261\007\007\007\007\370\361\040\007\331\277\332\300\305\007"
    "\007\304\007\007\303\264\301\302\263\007\007\007\007\007\234\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"
    "\040\255\233\234\376\235\174\025\376\376\246\256\252\055\376\376"
    "\370\361\375\376\376\346\024\371\376\376\247\257\254\253\376\250"
    "\376\376\376\376\216\217\222\200\376\220\376\376\376\376\376\376"
    "\376\245\376\376\376\376\231\376\376\376\376\376\232\376\376\341"
    "\205\240\203\376\204\206\221\207\212\202\210\211\215\241\214\213"
    "\376\244\225\242\223\376\224\366\376\227\243\226\201\376\376\230",
    /* IBM graphics: minimal translations (CR, LF, LL, SO, SI and ESC) */
    (unsigned char *)
    "\000\001\002\003\004\005\006\007\010\011\000\013\000\000\000\000"
    "\020\021\022\023\024\025\026\027\030\031\032\000\034\035\036\037"
    "\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057"
    "\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077"
    "\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117"
    "\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137"
    "\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157"
    "\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177"
    "\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217"
    "\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237"
    "\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257"
    "\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277"
    "\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317"
    "\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337"
    "\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357"
    "\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377"
    };


/* forward declarations */

LOCAL void	vgaStatInit (void);
LOCAL void	vgaHook (FAST VGA_CON_DEV *  pVgaConDv, int arg, int opCode);
LOCAL void	vgaClear (FAST VGA_CON_DEV *  pVgaConDv, int position, 
			  UCHAR eraseChar);
LOCAL void	vgaScroll (FAST VGA_CON_DEV *  pVgaConDv, int pos, int line, 
			   BOOL upDn, FAST UCHAR atr);
LOCAL void	vgaInsertChar (FAST VGA_CON_DEV *  pVgaConDv, 
			       FAST int nInsChar);
LOCAL void 	vgaCursorOn (void);
LOCAL void	vgaCursorOff (void);
LOCAL void	vgaCursorPos (FAST UINT16 pos);
LOCAL void	vgaScreenRev (FAST VGA_CON_DEV * pVgaConDv);
LOCAL void	vgaDelLeftChar (FAST VGA_CON_DEV *  pVgaConDv);
LOCAL void	vgaCarriageReturn (FAST VGA_CON_DEV *  pVgaConDv);
LOCAL void	vgaBackSpace (FAST VGA_CON_DEV *  pVgaConDv);
LOCAL void	vgaLineFeed (FAST VGA_CON_DEV *  pVgaConDv);
LOCAL void	vgaTab (FAST VGA_CON_DEV *  pVgaConDv);
LOCAL void	vgaConBeep (BOOL mode);

#ifdef INCLUDE_ANSI_ESC_SEQUENCE

LOCAL UCHAR vgaColorTable [] = 
    {
    /* black, red, green, brown, blue, magenta, cyan, light grey */
           0,   4,     2,     6,    1,       5,    3,          7
    };
LOCAL void	vgaEscResponse (FAST PC_CON_DEV * pPcCoDv, int  responseId );
LOCAL void	vgaPutCursor (FAST VGA_CON_DEV *  pVgaConDv);
LOCAL void	vgaSaveCurAttrib (FAST VGA_CON_DEV *  pVgaConDv);
LOCAL void	vgaRestAttrib (FAST VGA_CON_DEV *  pVgaConDv);
LOCAL void	vgaSetMode (FAST  PC_CON_DEV *  pPcCoDv, BOOL onOff);
LOCAL void	vgaClearLine (FAST VGA_CON_DEV *  pVgaConDv);
LOCAL void	vgaInsertLine (FAST VGA_CON_DEV *  pVgaConDv);
LOCAL void	vgaSetAttrib (FAST VGA_CON_DEV *  pVgaConDv);
LOCAL void	vgaDelLines (FAST VGA_CON_DEV *  pVgaConDv);
LOCAL void	vgaDelRightChars (FAST VGA_CON_DEV *  pVgaConDv, int nDelChar);

#endif /* INCLUDE_ANSI_ESC_SEQUENCE */

/*******************************************************************************
*
* vgaConBeep - sound beep function (using timer 2 for tone)
* 
* This function is responsible for producing the beep 
*
* RETURNS: N/A
*
* NOMANUAL
*/

LOCAL void vgaConBeep 
    (
    BOOL	mode	/* TRUE:long beep  FALSE:short beep */
    )
    {
    int		beepTime;
    int		beepPitch;
    FAST int 	oldlevel;

    if (mode)
        { 
        beepPitch = BEEP_PITCH_L;
        beepTime  = BEEP_TIME_L;	/* long beep */
        }
    else
        { 
        beepPitch = BEEP_PITCH_S;
        beepTime  = BEEP_TIME_S;	/* short beep */
        }

    oldlevel = intLock ();

    /* set command for counter 2, 2 byte write */

    sysOutByte (PIT_BASE_ADR + 3, 0xb6);	
    sysOutByte (PIT_BASE_ADR + 2, (beepPitch & 0xff));
    sysOutByte (PIT_BASE_ADR + 2, (beepPitch >> 8));

    /* enable counter 2 */
    sysOutByte (DIAG_CTRL, sysInByte (DIAG_CTRL) | 0x03);	

    taskDelay (beepTime);

    /* desable counter 2 */
    sysOutByte (DIAG_CTRL, sysInByte (DIAG_CTRL) & ~0x03);

    intUnlock (oldlevel);
    return;
    }

/******************************************************************************
*
* vgaHrdInit - initialize the VGA Display
*
* This function is called externally to initialize the vga display
*
* RETURNS: N/A
*
* NOMANUAL
*/

void vgaHrdInit (void)
    {

    /* get cursor shape and mode */

    sysOutByte ((int) CTRL_SEL_REG, 0x0a);
    curSt = sysInByte ((int) CTRL_VAL_REG);
    sysOutByte ((int) CTRL_SEL_REG, 0x0b);
    curEd = sysInByte ((int) CTRL_VAL_REG);

    vgaStatInit ();

    /* clear screen and position cursor at 0,0 */

    vgaClear (pcConDv [PC_CONSOLE].vs, 2,' ');

    vgaCursorOn ();
    return;
    } 

/*******************************************************************************
*
* vgaStatInit - initialize the VGA Display state
*
* RETURNS: N/A
*/

LOCAL void vgaStatInit (void)
    {
    int		ix;			/* to hold the index */
    FAST VGA_CON_DEV * pVgaConDv;	/* pointer to hold vga descriptor */

    for (ix = 0; ix < N_VIRTUAL_CONSOLES; ix++)
	{
	pcConDv [ix].vs	= pVgaConDv = &vgaConDv [ix];

	/* (VGA) Display status initialization */
	pVgaConDv->memBase	 = CTRL_MEM_BASE;
	pVgaConDv->colorMode     = COLOR_MODE;      /* color mode */   
	pVgaConDv->sv_col        = pVgaConDv->col   = 0;
	pVgaConDv->sv_row        = pVgaConDv->row   = 0;
	pVgaConDv->sv_curAttrib  = pVgaConDv->curAttrib = DEFAULT_ATR;
	pVgaConDv->defAttrib     = DEFAULT_ATR;
	pVgaConDv->curChrPos     = pVgaConDv->memBase;  /* current  position */
	pVgaConDv->sv_rev        = pVgaConDv->rev   = FALSE;
	pVgaConDv->ncol          = 80;                /* Number of columns */
	pVgaConDv->nrow          = 25;                /* Number of text rows */
	pVgaConDv->scst          = 0;                 /* scroll start */
	pVgaConDv->sced          = 24;                /* scroll end */
	pVgaConDv->autoWrap      = TRUE;              /* auto Wrap mode */
	pVgaConDv->scrollCheck   = FALSE;             /* scroll  flag off */
	pVgaConDv->charSet       = vgaCharTable [TEXT_SET]; /* character set */
	pVgaConDv->vgaMode       = TEXT_MODE;         /* video mode  */
	pVgaConDv->insMode       = INSERT_MODE_OFF;   /* insert mode */
	pVgaConDv->escFlags      = ESC_NORMAL;        /* normal character */
	pVgaConDv->escParaCount  = 0;                 /* zero parameters */
	pVgaConDv->escQuestion   = FALSE;             /* ? flag set to false */
	bzero ((char *)pVgaConDv->escPara, sizeof(pVgaConDv->escPara));
	bzero (pVgaConDv->tab_stop, sizeof(pVgaConDv->tab_stop));
	pVgaConDv->tab_stop [ 0] = 1;
	pVgaConDv->tab_stop [ 8] = 1;
	pVgaConDv->tab_stop [16] = 1;
	pVgaConDv->tab_stop [24] = 1;
	pVgaConDv->tab_stop [32] = 1;
	pVgaConDv->tab_stop [40] = 1;
	pVgaConDv->tab_stop [48] = 1;
	pVgaConDv->tab_stop [56] = 1;
	pVgaConDv->tab_stop [64] = 1;
	pVgaConDv->tab_stop [72] = 1;
	pVgaConDv->vgaHook	 = (FUNCPTR) vgaHook;	/* install the hook */
	}
    return;
    } 

/******************************************************************************
*
* vgaHook - hook called from an external module
* 
* This function performs various functions depending on the opCode.
* Typically this hook is to facilitate the user to add any additional
* routines which can be accessed externally through the vga console
* descriptor.
*
* RETURNS: N/A
*/

LOCAL void vgaHook 
    (
    FAST VGA_CON_DEV *  pVgaConDv,      /* pointer to the vga descriptor */
    int			arg,		/* argument */
    int			opCode		/* operation to perform */
    )
    {
    switch (opCode)
	{
	case 0:
	      vgaScreenRev (pVgaConDv); /* reverse screen */
	      break;
	case 1:
	      vgaConBeep (arg);		/* produce beep */
	      break;
	case 2:
	      vgaCursorOn ();		/* turn the cursor on */
	      break;
	case 3:
	      vgaCursorOff ();		/* turn the cursor Off */
	      break;
	case 4:				/* position the cursor */
	      pVgaConDv->row = (arg >> 8) & 0xff;
	      pVgaConDv->col = arg & 0xff;
	      if (pVgaConDv->row >= pVgaConDv->nrow)
	      pVgaConDv->row = pVgaConDv->nrow - 1;
	      if (pVgaConDv->col >= pVgaConDv->ncol)
	      pVgaConDv->col = pVgaConDv->ncol - 1;
	      vgaCursorPos ((UINT16) (pVgaConDv->row * pVgaConDv->ncol 
				      + pVgaConDv->col));
	      break;
	default:
	      break;
	}
    }

/******************************************************************************
*
* vgaClear - Clear Screen
*
* This routine clears the screen depending on the value of position.
* If position is 2 then it clears the whole screen and moves the cursor to 
* location 0,0. If position is 1 then the screen is erased from the cursor to
* until the end of display. If position is equal to any other value then 
* the screen is erased until the cursor.
*
* RETURNS: N/A
*/

LOCAL void vgaClear 
    (
    FAST VGA_CON_DEV *	pVgaConDv,	/* pointer to the vga descriptor */
    int			position,	/* cursor position  0 or 1 or 2 */
    UCHAR		eraseChar	/* erase character eg space is  0x20 */
    )
    {
    FAST UINT16 *	cp;	/* hold the beginning position */
    FAST UINT16 *	end;	/* hold the end position */
    FAST UINT16 	erase;	/* erase character with attribute */

    erase = (pVgaConDv->defAttrib << 8) + eraseChar;
    if ( position == 2 )
	{ 
	cp  = (UINT16 *) pVgaConDv->memBase;
	end = (UINT16 *) (pVgaConDv->memBase + 2048 * CHR);
	pVgaConDv->col = pVgaConDv->row = 0;
	pVgaConDv->curChrPos = (UCHAR *) pVgaConDv->memBase;
	}
    else if ( position == 0 )
	{ 
	cp  = (UINT16 *)pVgaConDv->curChrPos;
	end = (UINT16 *)(pVgaConDv->memBase + 2048 * CHR);
	}
    else  
	{
	cp  = (UINT16 *) pVgaConDv->memBase;
	end = (UINT16 *) (pVgaConDv->curChrPos + CHR);
	}
    for (; cp < end; cp++ )
        {
        *cp     = erase;  
        }
    }

⌨️ 快捷键说明

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