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

📄 core_vga.c

📁 嵌入式开发 嵌入式开发 嵌入式开发
💻 C
📖 第 1 页 / 共 5 页
字号:
    }
}

/***
 Func: PutHorzLineImg to Screen from XMS
 Parameters:
    -x,y; start point position
    -imgLineBytes; bytes of one imageline.
    -h_xms; handle of xms block
    -xms_off; offset of xms block
 Returns:
    NULL
***/
void PutHLine_xms(int x, int y, int imgLineBytes, unsigned h_xms, long xms_off)
{
    unsigned long addr=((unsigned long)y<<12)+((unsigned long)x<<2);
    unsigned long off=(addr&0xffffL);
    unsigned long left=(0x10000L-off);
    int bank=(int)(addr>>16);
    unsigned char far *ptr;
    if( left>=(unsigned long)imgLineBytes )
    {
        SetBANK(bank);
        ptr=LocalScrPtr+off;
        CopyXMSMem(h_xms,xms_off,imgLineBytes,0,(DWORD)ptr);
    }
    else
    {
        SetBANK(bank++);
        ptr=LocalScrPtr+off;
        CopyXMSMem(h_xms, xms_off,left, 0, (DWORD)(ptr));
        SetBANK(bank);
        CopyXMSMem(h_xms, xms_off + left, imgLineBytes - left, 0, (DWORD)LocalScrPtr);
    }
}

/***
 Func: GetHorzLineImg to XMS from Screen
 Parameters:
    -x,y; start point position
    -imgLineBytes; bytes of one imageline.
    -hXms; handle of xms block
    -XmsOffset; offset of xms block
 Returns:
    NULL
***/
void GetHLine_xms(int x, int y, int imgLineBytes, unsigned int h_xms, long xms_off)
{
    unsigned long addr=((unsigned long)y<<12)+((unsigned long)x<<2);
    unsigned long off=(addr&0xffffL);
    unsigned long left=(0x10000L-off);
    int bank=(int)(addr>>16);
    unsigned char far *ptr;
    if(left >= (long)imgLineBytes)
    {
        SetBANK(bank);
        ptr=LocalScrPtr + (unsigned)off;
        CopyXMSMem(0,(DWORD)ptr,imgLineBytes,h_xms,xms_off);
    }
    else
    {
        SetBANK(bank++);
        ptr=LocalScrPtr + (unsigned)off;
        CopyXMSMem(0, (DWORD)(ptr),left, h_xms, xms_off);
        SetBANK(bank);
        CopyXMSMem(0, (DWORD)LocalScrPtr, imgLineBytes - left, h_xms, xms_off + left);
    }
}

/***
 Func: frame of box
 Parameters:
    -x1,y1; position of startpoint
    -x2,y2; position of endpoint
 Returns:
    NULL
***/
void box_frame(int x1, int y1, int x2, int y2)
{
    MoveTo(x1,y2);
    LineTo(x1,y1,255,255,255);
    LineTo(x2,y1,255,255,255);
    LineTo(x2,y2,0,0,0);
    LineTo(x1,y2,0,0,0);
    MoveTo(x1+3,y2-3);
    LineTo(x1+3,y1+3,0,0,0);
    LineTo(x2-3,y1+3,0,0,0);
    LineTo(x2-3,y2-3,255,255,255);
    LineTo(x1+3,y2-3,255,255,255);
}

/***
 Func: GetImageData to Xms
 Parameters:
    -x,y, startpoint position
    -w,h; sizeof image area.
    -h_xms; handle of xms block
    -xms_off; offset of xms block
 Returns:
    NULL
***/
void GetImage_xms(int x, int y, int w, int h, unsigned h_xms, long xms_off)
{
    int i,imgLineBytes=((int)w<<2);
    long off=xms_off;
    for(i=y; i<=(y+h); i++)
    {
        GetHLine_xms(x, i, imgLineBytes, h_xms, off);
        off+=imgLineBytes;
    }
}

/***
 Func: put imagedata from xms
 Parameters:
    -x,y, startpoint position
    -w,h; sizeof image area.
    -h_xms; handle of xms block
    -xms_off; offset of xms block
 Returns:
    NULL
***/
void PutImage_xms(int x, int y, int w, int h, unsigned int h_xms, long xms_off)
{
    int i,imgLineBytes=((int)w<<2);
    long addr=((long)y<<12)+((long)x<<2);
    long off_1=xms_off;
    long off=(addr&0xFFFFL);
    long left=(0x10000L-off); //64K剩余的部分是否够写一行
    int bank=(int)(addr>>16);
    unsigned char far	*ptr;
    SetBANK(bank);
    for(i=y; i<=(y+h); i++)
    {
        if(left >= (long)imgLineBytes)
        {
            ptr=LocalScrPtr+(unsigned)off;
            CopyXMSMem(h_xms, off_1, imgLineBytes, 0, (DWORD)ptr);
            left-=g_graphatt.nBytesPerLine;
            off +=g_graphatt.nBytesPerLine;
        }
        else
        {
            PutHLine_xms(x, i, imgLineBytes, h_xms, off_1);
            addr=((long)(i+1)<<12)+((long)x<<2);
            off =(addr&0xFFFFL);
            left=(0x10000L-off); //64K剩余的部分是否够写一行
        }
        off_1+=imgLineBytes;
    }
    SetBANK(0);
}

/***
 Func: SquareBar of XP-Style.
 Parameters:
    x,y,w,h; startpoint of left-top & size of squarebar.
    style : 1=press-down; 0=press-up.
 Returns:
    NULL
***/
void xpbar(int x, int y, int w, int h, unsigned char style)
{
    int i,j,v,m=0;
    int r,g,b;
    for(i=y; i<=(y+h); i++,m++)
    {
        v=(int)(64.0*m/h);
        if(style)
        {   r=245-(v/4); g=245-(v/3); b=255-(v/2);}
        else
        {   r=235-(v/2); g=235-(v/3); b=235-(v/4);}
        for(j=x; j<=(x+w); j++)
        {   PutPixel(j, i, b, g, r);}
    }
}

/*
void ___MOUSEFUNCs___(void)
*/

/***
 Func: Mouse Cursor Drawing.
 Paramters:
    x,y : the cordiation on screen.
 Returns:
    NULL
***/
/*static unsigned mask[]={
    0x1800,0x2400,0x2400,0x2580,
    0x26B0,0x24D6,0x249a,0x2492,
    0x4492,0x4002,0x4002,0x2004,
    0x2004,0x1ff8,0x1008,0x1ff8, // black square border.
    0x0000,0x1800,0x1800,0x1800,
    0x1900,0x1B20,0x1B64,0x1B6C,
    0x3B6C,0x3FFC,0x3FFC,0x1FF8,
    0x1FF8,0x0000,0x0FF0,0x0000 // white square filled.
};*/
void PaintCursor(const int x, const int y)
{
	static BYTE M_mask[]={ // SIZE=256 
        0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x01, 0x0F, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x01, 0x0F, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x01, 0x0F, 0x0F, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x01, 0x0F, 0x0F, 0x01, 0x01, 0x0F, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x01, 0x0F, 0x0F, 0x01, 0x0F, 0x0F, 0x01, 0x01, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x01, 0x0F, 0x0F, 0x01, 0x0F, 0x0F, 0x01, 0x0F, 0x0F, 0x01, 0x01, 0x00, 0x01, 0x00,
        0x00, 0x00, 0x01, 0x0F, 0x0F, 0x01, 0x0F, 0x0F, 0x01, 0x0F, 0x0F, 0x01, 0x0F, 0x0F, 0x01, 0x00,
        0x00, 0x01, 0x0F, 0x0F, 0x0F, 0x01, 0x0F, 0x0F, 0x01, 0x0F, 0x0F, 0x01, 0x0F, 0x0F, 0x01, 0x00,
        0x00, 0x01, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x01, 0x00,
        0x00, 0x01, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x01, 0x00,
        0x00, 0x00, 0x01, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x01, 0x00, 0x00,
        0x00, 0x00, 0x01, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x01, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x01, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x01, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00
    };
    int t,k,m=0,xfrom=x-3;
    CursorDrawing=1;
    GetImage(xfrom, y, xfrom+16, y+16, MouseImageBuffer);
    for(t=0; t<16; t++)
    {
        for(k=0; k<16; k++)
        {
            if( M_mask[m]==0x01 )
            {   PutPixel(xfrom+k, y+t, 0, 0, 0);}
            else if( M_mask[m]==0x0F )
            {   PutPixel(xfrom+k, y+t, 255, 255, 255);}
            m++;
        }
    }
    CursorDrawing=0;
}

/***
 Func: ShowMouse Cursor.
 Parameters:
    NULL
 Returns:
    NULL
***/
void ShowMouse(void)
{
    disable();
    if( !MouseFlag )
    {
        MouseFlag=1;
        PaintCursor(OldMouseCol, OldMouseRow);
    }
    enable();
}

/***
 Func: HideMouse Cursor.
 Parameters:
    NULL
 Returns:
    NULL
***/
void HideMouse(void)
{
    disable();
    if( MouseFlag )
    {
        MouseFlag=0;
        PutImage(OldMouseCol-3, OldMouseRow, OldMouseCol+13, OldMouseRow+16, MouseImageBuffer);
    }
    enable();
}

/***************
 Description: 将鼠标点击的第一位置压栈
 ReferenceInfo:
    掩码位      中断的条件
    0           光标位置移动
    1           左按钮按下
    2           左按钮松开
    3           右按钮按下
    4           右按钮松开
 返回位:
    位0=1       左按键按下
    位1=1       右按键按下
***************/
void PutUsrClickEvtList(const int x, const int y)
{
    UsrClickEvtList[wUsrClickEvtList].x=x;
    UsrClickEvtList[wUsrClickEvtList].y=y;
    UsrClickEvtList[wUsrClickEvtList].flag=1;
    //MouseClickFlag=1;
    if( ++wUsrClickEvtList==MOUSE_CLICKEVT_LEN )
    {   wUsrClickEvtList=0;}
}
/***
 Func: Mouse Affair Routine of Interrupt-TSR
 Parameters:
    NULL
 Returns:
    NULL
***/
void MouseMaskProc(void)
{
    int col=_CX, row=_DX;
    disable();
    if( MouseFlag )
    {
        if( CursorDrawing )
    	{   goto Lex_MouseMaskProc;}
    	if( _BX&0x01 )
    	{   // 左按键按下
    	    if( !UsrLeftKeyTms )
    	    {   UsrLeftKeyTms=1; UsrLeftKeyX=col; UsrLeftKeyY=row;}
    	}
    	else
    	{   // 左按键松开
    	    if( UsrLeftKeyTms )
    	    {   UsrLeftKeyTms=0; PutUsrClickEvtList(UsrLeftKeyX, UsrLeftKeyY);}
    	}
        PutImage(OldMouseCol-3, OldMouseRow, OldMouseCol+13, OldMouseRow+16, MouseImageBuffer);
        PaintCursor(col, row);
        OldMouseCol=col; OldMouseRow=row;
    }
Lex_MouseMaskProc:
    enable();
}

/***
 Func: Mouse Click Test.
 Parameters:
    NULL
 Returns:
    1=MouseClicked; 0=MouseNotClicked.
***/
int MouseKeyClick(void)
{
    /*
    asm {
        push ax;
        push bx;
        push dx;
        push cx;
        mov ax,5;
        mov bx,0;
        int 33h;
        cmp ax,1;
        jnz exit_0;
        pop cx;
        pop dx;
        pop bx;
        pop ax;
    }
    return 0;
  exit_0:
    delay(1);
    asm {
        mov ax,5;
        mov bx,0;
        int 33h;
        cmp ax,1;
        jz exit_1;
        pop cx;
        pop dx;
        pop bx;
        pop ax;
    }
    return 0;
  exit_1:
    if( !MouseClickFlag )
    {   ClickCol=_CX; ClickRow=_DX; MouseClickFlag=1;}
    asm {
        pop cx;
        pop dx;
        pop bx;
        pop ax;
    }
    return 1;
    
    if((VarST3000.MenuIDSEL==1) && VarST3000.AppAlive)
    {
    	union REGS rHit;
    	rHit.x.ax=5;
    	rHit.x.bx=0;
    	int86(0x33, &rHit, &rHit);
    	if( rHit.x.ax!=0x01 ) {   return 0;}
    	delay(1);
    	rHit.x.ax=5;
    	rHit.x.bx=0;
    	int86(0x33, &rHit, &rHit);
    	if( rHit.x.ax!=0x00 ) {   return 0;}
    	if( !MouseClickFlag )
    	{   ClickCol=_CX; ClickRow=_DX; MouseClickFlag=1;}
    	return 1;
    }*/
    /***************
 	Description: 查询用户所有的点击点
 	DataTime: 2007-4-5 9:38:33
 	Returns:
    [0]=无按键. [1]=有按键
	***************/
	MouseClickFlag=UsrClickEvtList[rUsrClickEvtList].flag;
	if(MouseClickFlag)
	{
	    ClickCol=UsrClickEvtList[rUsrClickEvtList].x;
	    ClickRow=UsrClickEvtList[rUsrClickEvtList].y;
	    UsrClickEvtList[rUsrClickEvtList].flag=0;
	    //MouseClickFlag=0;
	    if( ++rUsrClickEvtList==MOUSE_CLICKEVT_LEN )
	    {   rUsrClickEvtList=0;}
	    return 1;
	}
	return 0;
}


/***
 Func: Initialize Mouse & Install TSR of Mouse.
 Parameters:
    NULL
 Returns:
    NULL
***/
void InitialMouse(void)
{
    union REGS regs;
    struct SREGS sregs;
    MouseImageBuffer=(unsigned char far*)farmalloc(1024L);
    if(MouseImageBuffer==NULL) 
    {   exit(0);}
    regs.x.ax=0;
    int86(0x33, &regs, &regs);
    if( !regs.x.ax ) return;
    // 设置鼠标水平边界
    regs.x.ax=0x07;
    regs.x.cx=8; // 最小水平位置
    regs.x.dx=1005; // 最大水平位置
    int86(0x33, &regs, &regs);
    // 设置鼠标垂直边界
    regs.x.ax=0x08;
    regs.x.cx=0; // 最小垂直边界
    regs.x.dx=750; // 最大垂直边界
    int86(0x33, &regs, &regs);
    // 设置鼠标指针位置
    regs.x.ax=0x04;
    regs.x.cx=512; // 水平居中
    regs.x.dx=384; // 垂直居中
    int86(0x33, &regs, &regs);
    // 读取鼠标位置及按钮状态
    regs.x.ax=0x03;
    int86(0x33, &regs, &regs);
    OldMouseCol=regs.x.cx;
    OldMouseRow=regs.x.dx;

⌨️ 快捷键说明

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