www.pudn.com > cwin.rar > CURSOR.C
/*-----------------------------------------------------------
程序模块 Cursor.c : 实现闪烁光标的函数模块
-----------------------------------------------------------*/
#include
/*-- 局部静态变量定义 : 光标的参数及工作变量 --------------*/
static int _CursorStatus = 0; /* 光标状态:1 = 显示 */
static int _CursorWidth = 1; /* 光标宽度(字节) */
static int _CursorHigh = 18; /* 光标整体高度(象素) */
static int _CursorLine = 2; /* 光标线数 */
static int _CursorSpeed = 1; /* 光标速度:1=最快 */
static int _CursorColor = 15; /* 光标颜色 */
static int _LastCol = 0; /* 光标原来列(字节) */
static int _LastLine = 0; /* 光标原来行(象素) */
/*-----------------------------------------------------------
内部函数 _Cursor : 显示光标
-----------------------------------------------------------*/
static void _Cdecl _Cursor(int col,int line)
{
int i,j;
char far *addr;
unsigned char old03,old05;
/*-- 置显示寄存器标志为"忙" -----------*/
_VideoBusy = YES;
/*-- 计算光标的显示位置 ---------------*/
addr = MK_FP(0xa000,(line+_CursorHigh-1+_ScreenTop)*_ScreenWidth+col);
/*-- 设置显示寄存器组 -----------------*/
outportb(0x3ce,0x05);
old05 = inportb(0x3cf);
outportb(0x3ce,0x03);
old03 = inportb(0x3cf);
outportb(0x3ce,0x05);
outportb(0x3cf,old05&0xfc);
outportb(0x3ce,0x03);
outportb(0x3cf,0x18);
outportb(0x3ce,0x00);
outportb(0x3cf,_CursorColor);
outportb(0x3ce,0x01);
outportb(0x3cf,0x0f);
outportb(0x3ce,0x08);
outportb(0x3cf,0xff);
/*-- 显示光标 -------------------------*/
for(i=0;i<_CursorLine;i++)
{
for(j=0;j<_CursorWidth;j++)
*(addr+j) &= 0xff;
addr -= _ScreenWidth;
}
/*-- 恢复显示寄存器组的省缺值 ---------*/
outportb(0x3ce,0x03);
outportb(0x3cf,old03);
outportb(0x3ce,8); /* 恢复位屏蔽寄存器 */
outportb(0x3cf,0xff); /* 恢复位屏蔽寄存器 */
outportb(0x3ce,1); /* 恢复允许置位/复位寄存器 */
outportb(0x3cf,0); /* 恢复允许置位/复位寄存器 */
outportb(0x3ce,0); /* 恢复置位/复位寄存器 */
outportb(0x3cf,0x0f); /* 恢复置位/复位寄存器 */
outportb(0x3ce,0x05);
outportb(0x3cf,old05);
/*-- 翻转光标状态 ---------------------*/
_CursorStatus = !_CursorStatus;
/*-- 置显示寄存器标志为"闲" -----------*/
_VideoBusy = NO;
}
/*-----------------------------------------------------------
内部函数 _CursorFun : 实现光标的闪烁功能
-----------------------------------------------------------*/
void far _CursorFun(void)
{
static count = 0;
count++;
if(count>_CursorSpeed && !_VideoBusy)
{
disable();
/*-- 如果光标位置有变动则移动光标 -*/
if(_TextCol !=_LastCol || _TextLine!=_LastLine)
{
if(_CursorStatus)
_Cursor(_LastCol,_LastLine);
_LastCol = _TextCol;
_LastLine = _TextLine;
}
count = 0;
_Cursor(_TextCol,_TextLine);
enable();
}
}
/*-----------------------------------------------------------
函数 lightcursor : 打开光标显示开关
-----------------------------------------------------------*/
void _Cdecl lightcursor(void)
{
_Int1CHfun[1] = _CursorFun;
}
/*-----------------------------------------------------------
函数 delightcursor : 关闭光标显示开关
-----------------------------------------------------------*/
void _Cdecl delightcursor(void)
{
_Int1CHfun[1] = 0;
if(_CursorStatus)
_Cursor(_TextCol,_TextLine);
}
/*-----------------------------------------------------------
函数 setcursor : 设置光标的形状、颜色和大小等参数
-----------------------------------------------------------*/
void _Cdecl setcursor(width,high,line,speed,color)
int width; /* 光标宽度(字节) */
int high; /* 光标整体高度(象素) */
int line; /* 光标线数 */
int speed; /* 光标速度:1=最快 */
int color; /* 光标颜色 */
{
_CursorWidth = width;
_CursorHigh = high;
_CursorLine = line;
_CursorSpeed = speed;
_CursorColor = color;
}