📄 m6845vga.c
字号:
#ifdef INCLUDE_ANSI_ESC_SEQUENCE
/*****************************************************************************
*
* vgaEscResponse - This function gives back a response to an escape sequence.
* The valid response Ids are
* 0 for cursor position, 1 for terminal status,
* 2 for terminal device attributes.
*
* RETURNS: N/A
*/
LOCAL void vgaEscResponse
(
FAST PC_CON_DEV * pPcCoDv, /* pointer to the console descriptor */
int responseId /* response Id */
)
{
FAST VGA_CON_DEV * pVgaConDv; /* pointer to the vga descriptor */
pVgaConDv = pPcCoDv->vs;
tyIoctl (&pPcCoDv->tyDev, FIORFLUSH, 0);
if ( responseId == 0)
{
sprintf (pVgaConDv->escResp, "\033[%d;%dR",pVgaConDv->row,
pVgaConDv->col );
}
else if ( responseId == 1)
{
sprintf (pVgaConDv->escResp, "\033[0n");
}
else if ( responseId == 2)
{
sprintf (pVgaConDv->escResp, "\033[?1;0c");
}
else
{
pVgaConDv->escResp[0] = '\0';
}
rngBufPut (pPcCoDv->tyDev.rdBuf, pVgaConDv->escResp,
strlen (pVgaConDv->escResp) );
semGive (&pPcCoDv->tyDev.rdSyncSem);
selWakeupAll (&pPcCoDv->tyDev.selWakeupList, SELREAD);
}
/*****************************************************************************
*
* vgaSaveCurAttrib - saves all the current attributes, cursor position
* screen reverse mode.
*
* RETURNS: N/A
*/
LOCAL void vgaSaveCurAttrib
(
FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
)
{
pVgaConDv->sv_rev = pVgaConDv->rev;
pVgaConDv->sv_col = pVgaConDv->col;
pVgaConDv->sv_row = pVgaConDv->row;
pVgaConDv->sv_curAttrib = pVgaConDv->curAttrib;
}
/*****************************************************************************
*
* vgaRestAttrib - restores all the saved attributes, cursor position
* screen reverse mode.
*
* RETURNS: N/A
*/
LOCAL void vgaRestAttrib
(
FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
)
{
pVgaConDv->rev = pVgaConDv->sv_rev;
pVgaConDv->col = pVgaConDv->sv_col;
pVgaConDv->row = pVgaConDv->sv_row;
pVgaConDv->curAttrib = pVgaConDv->sv_curAttrib;
}
/*****************************************************************************
*
* vgaSetAttrib - sets various attributes
*
* RETURNS: N/A
*/
LOCAL void vgaSetAttrib
(
FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
)
{
FAST int ix; /* register to hold the index */
FAST UCHAR attr; /* register to hold the current attribute */
attr = pVgaConDv->curAttrib;
for (ix = 0 ; ix <= pVgaConDv->escParaCount; ix++)
{
switch (pVgaConDv->escPara [ix])
{
case 0:
attr = DEFAULT_ATR;
break;
case 1:
attr |= ATRB_BRIGHT; /* set intensity */
break;
case 4:
if (!pVgaConDv->colorMode)
{
attr |= UNDERLINE;
}
break;
case 5:
attr |= ATRB_BLINK; /* toggle blinking */
break;
case 7:
pVgaConDv->rev = TRUE; /* set reverse mode */
attr = (attr & 0x88) | (((attr >> 4) | ((attr << 4) & 0x7)));
break;
case 21:
case 22:
attr &= ~ATRB_BRIGHT; /* reset brightness */
break;
case 24:
if (!pVgaConDv->colorMode)
{
attr &= ~UNDERLINE; /* reset underline mode */
}
break;
case 25:
attr &= ~ATRB_BLINK;
break;
case 27:
pVgaConDv->rev = FALSE; /* reset reverse mode */
break;
default:
/* set foreground and background attribute */
if ((pVgaConDv->escPara [ix] >= 30) &&
(pVgaConDv->escPara [ix] <= 37) )
{
attr = (attr & 0xf8) |
(vgaColorTable [pVgaConDv->escPara [ix] - 30]) ;
}
else if ((pVgaConDv->escPara [ix] >= 40) &&
(pVgaConDv->escPara [ix] <= 47))
{
attr = (attr & 0x8f) |
vgaColorTable [pVgaConDv->escPara [ix] - 40] << 4;
}
break;
}
}
pVgaConDv->curAttrib = attr; /* set the current attribute */
}
/*****************************************************************************
*
* vgaSetMode - set various special modes according to the input onOff
*
* RETURNS: N/A
*/
LOCAL void vgaSetMode
(
FAST PC_CON_DEV * pPcCoDv, /* pointer to the vga descriptor */
BOOL onOff /* on or off */
)
{
FAST int ix;
FAST VGA_CON_DEV * pVgaConDv; /* pointer to the vga descriptor */
pVgaConDv = pPcCoDv->vs;
for ( ix =0; ix <= pVgaConDv->escParaCount; ix++ )
{
if ( pVgaConDv->escQuestion )
{
switch (pVgaConDv->escPara [ix])
{ /* modes set reset */
case 1:
pPcCoDv->ks->curMode = (onOff) ? FALSE : TRUE;
break;
case 3: /* 80/132 mode switch unimplemented */
vgaClear (pVgaConDv, 2, ' ');
break;
case 5:
pVgaConDv->rev = (pVgaConDv->rev) ? FALSE : TRUE;
vgaScreenRev (pVgaConDv);
break;
case 7:
pVgaConDv->autoWrap = onOff;
break;
case 25:
(onOff) ? vgaCursorOn() : vgaCursorOff() ;
break;
}
}
else if ( pVgaConDv->escPara [ix] == 4)
{
pVgaConDv->insMode = onOff;
}
}
}
/*****************************************************************************
*
* vgaPutCursor - place the cursor in the specified location
*
* RETURNS: N/A
*/
LOCAL void vgaPutCursor
(
FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
)
{
if ( pVgaConDv->col < 0)
pVgaConDv->col = 0;
else if (pVgaConDv->col >= pVgaConDv->ncol)
pVgaConDv->col = pVgaConDv->ncol - 1;
if ( pVgaConDv->row < pVgaConDv->scst)
pVgaConDv->row = pVgaConDv->scst;
else if ( pVgaConDv->row >= pVgaConDv->sced )
pVgaConDv->row = pVgaConDv->sced;
pVgaConDv->curChrPos = (pVgaConDv->memBase + pVgaConDv->row *
pVgaConDv->ncol * CHR + pVgaConDv->col * CHR );
}
/*****************************************************************************
*
* vgaClearLine - clear the line according to the position passed.
*
* RETURNS: N/A
*/
LOCAL void vgaClearLine
(
FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
)
{
FAST UINT16 * cp; /* hold the beginning value */
FAST UINT16 * end; /* hold the end value */
FAST UINT16 erase; /* hold the erase character */
erase = (pVgaConDv->defAttrib << 8 ) + ' ';
if (pVgaConDv->escPara [0] == 0 )
{
cp = (UINT16 *) (pVgaConDv->curChrPos + CHR );
end = (UINT16 *) (pVgaConDv->memBase + pVgaConDv->row *
pVgaConDv->ncol * CHR + (pVgaConDv->ncol - 1) * CHR);
}
else if (pVgaConDv->escPara [0] == 1)
{
cp = (UINT16 *) (pVgaConDv->memBase + pVgaConDv->row *
pVgaConDv->ncol * CHR);
end = (UINT16 *) (pVgaConDv->curChrPos);
}
else
{
cp = (UINT16 *) (pVgaConDv->memBase + pVgaConDv->row *
pVgaConDv->ncol * CHR);
end = (UINT16 *) (cp + (pVgaConDv->ncol - 1) * CHR);
pVgaConDv->curChrPos = (UCHAR *) cp ;
pVgaConDv->col = 0;
}
for (; cp <= end; cp ++)
{
*cp = erase;
}
}
/******************************************************************************
*
* vgaInsertLine - inserts as many number of lines as passed in the escape
* parameter
*
* RETURNS: N/A
*/
LOCAL void vgaInsertLine
(
FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
)
{
int ix;
int start;
int end;
start = pVgaConDv->scst;
end = pVgaConDv->sced;
pVgaConDv->scst = pVgaConDv->row;
pVgaConDv->sced = pVgaConDv->nrow - 1 ;
ix = pVgaConDv->escPara [0];
if (pVgaConDv->escPara [0] == 0)
{
ix = 1;
}
if (pVgaConDv->row + ix >= pVgaConDv->nrow)
{
ix = pVgaConDv->nrow - pVgaConDv->row - 1;
}
vgaScroll (pVgaConDv, pVgaConDv->row, ix, BACKWARD, pVgaConDv->defAttrib);
pVgaConDv->curChrPos -= pVgaConDv->col * CHR;
pVgaConDv->col = 0;
pVgaConDv->scst = start;
pVgaConDv->sced = end ;
}
/******************************************************************************
*
* vgaDelLines - deletes as many as lines as passed in the escape
* parameter
*
* RETURNS: N/A
*/
LOCAL void vgaDelLines
(
FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
)
{
int ix;
int start;
int end;
start = pVgaConDv->scst;
end = pVgaConDv->sced;
pVgaConDv->scst = pVgaConDv->row;
pVgaConDv->sced = pVgaConDv->nrow - 1;
ix = pVgaConDv->escPara [0];
if (ix == 0)
{
ix = 1;
}
if (pVgaConDv->row + ix > pVgaConDv->nrow)
{
ix = pVgaConDv->row;
}
vgaScroll (pVgaConDv, pVgaConDv->sced, ix, FORWARD, pVgaConDv->defAttrib);
pVgaConDv->curChrPos -= pVgaConDv->col * CHR;
pVgaConDv->col = 0;
pVgaConDv->scst = start;
pVgaConDv->sced = end;
}
/******************************************************************************
*
* vgaDelRightChars - deletes character right of the cursor
*
* RETURNS: N/A
*/
LOCAL void vgaDelRightChars
(
FAST VGA_CON_DEV * pVgaConDv, /* pointer to the vga descriptor */
int nDelChar /* number of Deletes to do */
)
{
FAST int xPos; /* current position in columns */
FAST UINT16 * cp; /* current pointer */
FAST UINT16 erase; /* to hold erase character with Attribute */
erase = (pVgaConDv->defAttrib << 8 ) + ' ';
if (nDelChar + pVgaConDv->col >= pVgaConDv->ncol )
{
nDelChar = pVgaConDv->ncol - pVgaConDv->col - 1;
}
else if (nDelChar == 0)
{
nDelChar = 1;
}
while ( nDelChar-- )
{
xPos = pVgaConDv->col;
cp = (unsigned short *) pVgaConDv->curChrPos;
while (++xPos < pVgaConDv->ncol)
{
*cp = *(cp +1);
cp++;
}
*cp = erase; /* erase the last character */
}
}
#endif /* INCLUDE_ANSI_ESC_SEQUENCE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -