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

📄 gpcdrv.c

📁 使用键盘上的上、下、左、右四个按键
💻 C
📖 第 1 页 / 共 2 页
字号:
///////////////////////////////////////////////////////////////////////////////////
//
//      Copyright (C) 1999 SEIKO EPSON Corp.
//      All Rights Reserved
//
//      File name :gpcdrv.c
//      Function  :
//          This is a device driver(HAL) program
//      Revision history
//          Ver 0.10 1999/09/10  SungYoung Shin       Start        
//          Ver 0.11 2001/05/11  Catherine Ni	      Add that initialize TCM-A1263 
//          Ver 0.20 2000/04/13  SungYoung Shin       Update For Alpha2
//          Ver 1.90 2001/06/01  CYu                  customize to plus version
//
///////////////////////////////////////////////////////////////////////////////////

//#include "gpcdrv.h"
#include <cDevice.h>
#include <gpc.h>
//#include "c33208.h"
//#include <memory.h>
#include<Ar320240.h>
static void seSetMonoImageLine( PPHYIMAGEINFO ppii );

void vDisableInterrupt( void );
void vEnableInterrupt( void );

#define LCD_Command        0x0400000
#define LCD_Data	   0x0400002	


void vDisableInterrupt( void )
{
   asm("ld.w %r9, %psr");
   asm("xand %r9, 0x0ef");
   asm("ld.w %psr, %r9");
}

void vEnableInterrupt( void )
{
   asm("ld.w %r10, %psr\nor %r9, 0x10\nld.w %psr, %r9");
}

void	_DrawDiagonalLine( S16 x1, S16 y1, S16 x2, S16 y2, U16 ColorIndex)
{
	unsigned short usXInterval, usYInterval;
	unsigned char bX1LessthanX2 = true, bY1LessthanY2 = true, bXIntervalEqualYInterval = false;
	unsigned short i,ushTmpX,uchTmpY,ushCount;
	short  shScale = 0;
	unsigned short *uspTmpDispMem = uspMemBaseAddr ;

	if( x1 < x2 )
	{
		usXInterval = x2 - x1;
	}
	else
	{
		usXInterval = x1 - x2;
		bX1LessthanX2 = false ;
	}
	
	if( y1 < y2 )
		usYInterval = y2 - y1 ;
	else
	{
		usYInterval = y1 - y2 ;
		bY1LessthanY2 = false ;
	}

	if( usXInterval == usYInterval )
		bXIntervalEqualYInterval = true;

	ushCount = usXInterval + usYInterval;
	ushTmpX  = x1;
	uchTmpY  = y1;

	if( bX1LessthanX2 &&  bY1LessthanY2 )
	{
		if( bXIntervalEqualYInterval )
			for( i = 0; i <= y2 - y1; i++ )
				seSetPixel( x1 + i, y1 + i, ColorIndex );
		else
		{
			seSetPixel( x1, y1, ColorIndex);
			for( i = 0; i < ushCount; i++ )
			{
				if( shScale >= 0 )
				{
					ushTmpX++;
					shScale -= usYInterval;
				}
				else
				{
					uchTmpY++;
					shScale += usXInterval;
			    }
			    seSetPixel( ushTmpX, uchTmpY, ColorIndex );
			}
		}
		return ;
	}
	if( bX1LessthanX2 &&  !bY1LessthanY2 )
	{
		if( bXIntervalEqualYInterval )
			for( i = 0; i <= x2 - x1; i++ )
				 seSetPixel( x1 + i, x2 - i, ColorIndex );
		else
		{
		    seSetPixel( x1, x2, ColorIndex);
			for( i = 0; i < ushCount; i++ )
			{
				if( shScale >= 0 )
				{
					ushTmpX++;
					shScale -= usYInterval;
				}
				else
				{
					uchTmpY--;
					shScale += usXInterval;
				}
				seSetPixel( ushTmpX, uchTmpY, ColorIndex );
			}
		}
		return ;
	}
	if( !bX1LessthanX2 &&  bY1LessthanY2 )
	{
		if( bXIntervalEqualYInterval )
			for( i = 0; i <= x1 - x2; i++ )
				seSetPixel( x1 - i, y1 + i, ColorIndex );
		else
		{
			seSetPixel( x1, y1, ColorIndex );
			for( i = 0; i < ushCount; i++ )
			{
			 	if( shScale >= 0 )
			 	{
					ushTmpX--;
					shScale -= usYInterval;
				}
			   	else
				{
					uchTmpY++;
					shScale += usXInterval;
				}
				seSetPixel( ushTmpX, uchTmpY, ColorIndex );
			}
		}
		return ;
	}
	if( !bX1LessthanX2 &&  !bY1LessthanY2 )
	{
		if( bXIntervalEqualYInterval )
			for( i = 0; i <= x1-x2; i++ )
				seSetPixel( x1 - i, y1 - i, ColorIndex );
		else
		{
			seSetPixel( x1, y1, ColorIndex );
			for( i = 0; i < ushCount; i++ )
			{
				if( shScale >= 0 )
				{
					ushTmpX--;
					shScale -= usYInterval;
				}
				else
				{
					uchTmpY--;
					shScale += usXInterval;
				}
				seSetPixel( ushTmpX, uchTmpY, ColorIndex );
			}
		}
	}
}
//-------------------------------------------------------------------------
//    seGetScreenSize()
//
//  alculates and returns the width and height, in pixels, and returns the
//  the value in 'width' and 'height'.
//
//  Parameters:
//      width        - pointer to an integer to receive the width of the display
//      height       - pointer to an integer to receive the height of the display.
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
U16 seGetScreenSize( S16 *width, S16 *height )
{

    *width  = SCREEN_WIDTH;
    *height = SCREEN_HEIGHT;

    return GPC_ERR_OK;
}


//-------------------------------------------------------------------------
//    seInit()
//
//This program Initial lcd:
//
//	Text & Graphic mode:
//	Total pages:		240 	(   page 00: up side 	to     page 240:    down side)
//	Columns in each page:	320	( Column 0: left side 	to  Column 319: right side)
//	Bits in each column:	8 bits 	(   R:D7~D5	G:D4~D2	    B:D1~D0)
//	Dot Matrix mode:
//	Total resolution:
//	X:	320 dots;	Y:	240 dots
//	 (0,0) left-up corner to (3199,239) right-down corner
//
//
//  Parameters: unsigned long para
//
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------

U16 seInit( U32 para )
{

    return GPC_ERR_OK;
}


//-------------------------------------------------------------------------
//    seSetPixel()
//
//      This function sets the pixel at the specified coordinates to specified color.
//	ColorIndex is interrupted by HAL.GPC can use function seRGBtoIndex to convert a RGB value to a color index
//
//  Parameters:
//     X: the x-coordinate , in pixel , of the point to be painted
//     Y: the y-coordinate , in pixel , of the point to be painted
//     ColorIndex : the color to be use to paint the pixel
//
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
void seSetPixel( S16 x, S16 y, U16 ColorIndex )
{   
	if( x >= SCREEN_WIDTH || y >= SCREEN_HEIGHT )
		 return ;

    *( ucpMemBaseAddr + y * S1D_ONE_LINE_BYTES_NUMBER + x ) = ColorIndex;
}


//-------------------------------------------------------------------------
//    seGetPixel()
//
//      This function retrives the color value of the pixel at the specified coordinates 
//
//  Parameters:
//     X: the x-coordinate , in pixel , of the point to be examined
//     Y: the y-coordinate , in pixel , of the point to be examined
//     ColorIndex : the color of the pixel
//
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
void seGetPixel( S16 x, S16 y, U16 *ColorIndex )
{
	if( x >= SCREEN_WIDTH || y >= SCREEN_HEIGHT )
		 return ;
	*ColorIndex=*(ucpMemBaseAddr + y * S1D_ONE_LINE_BYTES_NUMBER + x);

}


//-------------------------------------------------------------------------
//    seDrawLine()
//
//  draws a line
//
//  Parameters:
//      x1,y1:specified the coordinate of the lines start point in pixel
//      x2,y2:specified the coordinate of the lines end point in pixel
//	ColorIndex:the color of the pixel
//	mask:line style mask
//
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
void seDrawLine( S16 x1, S16 y1, S16 x2, S16 y2, U16 ColorIndex, U16 mask )
{
    unsigned char *ucpTmpDispMem = ucpMemBaseAddr;
	S16  usMin, usMax;
	int     i;

    if(mask!=GPC_SOLID_LINE)
       mask==GPC_SOLID_LINE;
	if( y1 == y2 )  // horizonal line
	{
	  if(x1 < x2)
		{
		   usMin =x1;
		   usMax =x2;
		}
	  else
		{
		   usMin =x2;
		   usMax =x1;
		}
	 for(i=0;i<=(usMax-usMin);i++)
     seSetPixel( x1+i, y1, ColorIndex );
	}
    else if(x1 == x2)	// vertical line
	{
	   	if(y1 < y2)
			{
			  usMin = y1;
		      usMax = y2;
			}
		    else
			{
			  usMin = y2;
			  usMax = y1;
			}
		
		 for(i=0;i<=(usMax-usMin);i++)
		 seSetPixel( x1, y1 + i, ColorIndex);
	}
    else	// diagonal line ,here use relative accurate algorithem
	    _DrawDiagonalLine( x1, y1 ,x2, y2, ColorIndex);

			
}

//-------------------------------------------------------------------------
//    seInvertLine()
//
//  Invert a line
//
//  Parameters:
//      x1,y1:specified the coordinate of the lines start point in pixel
//      x2,y2:specified the coordinate of the lines end point in pixel
//	mask:line style mask
//
//    Returns:
//      GPC_ERR_OK
//-------------------------------------------------------------------------
void seInvertLine( S16 x1, S16 y1, S16 x2, S16 y2, U16 mask )
{
	S16 dx,dy,incrE,incrNE,d,x,y;
	S16 x0, y0;
	unsigned short invertcolor;


	if (x2==x1)
	{//*write stright line*//
		if (y1<y2)
		{
			for (y=y1;y<=y2;y++)
				if( ( mask&0x8000 ) == 0x8000 )
		 		{
		 			seGetPixel(x1,y, &invertcolor);
		 			invertcolor = ~invertcolor;
		 			seSetPixel(x1,y,invertcolor);
			 		mask=( mask<<1 )|0x0001 ;
				}
				else
					mask=mask<<1;
		}						
		else 
		{
            for (y=y2;y<=y1;y++)
				if( ( mask&0x8000 ) == 0x8000 )
		 		{
					seGetPixel(x1,y, &invertcolor);
		 			invertcolor = ~invertcolor;
		 			seSetPixel(x1,y,invertcolor);
		 			mask=( mask<<1 )|0x0001 ;
				}
			    else
				    mask=mask<<1;
		}
	}			
			
	else if (y2==y1)
	{//*write horizental line*//
		if (x1<x2)
		{
			for (x=x1;x<=x2;x++)
				if( ( mask&0x8000 ) == 0x8000 )
		 		{
					seGetPixel(x,y1, &invertcolor);
		 			seSetPixel(x,y1,~invertcolor);;
		 			mask=( mask<<1 )|0x0001 ;
				}
				else
					mask=mask<<1;
		}						
		else 
		{
			for (x=x2;x<=x1;x++)
				if( ( mask&0x8000 ) == 0x8000 )
		 		{
					seGetPixel(x,y1, &invertcolor);
		 			seSetPixel(x,y1,~invertcolor);
		 			mask=( mask<<1 )|0x0001 ;
				}
				else
					mask=mask<<1;
		}
	}										
	
	else
	{// * start point definition*//
		if (x1<x2)
		{	x0=x1;
			y0=y1;
			x1=x2;
			y1=y2;
		}
		else
		{	x0=x2;
			y0=y2;
		}
	
		dx=x1-x0;
		if (y0<y1)
		{
			dy=y1-y0;
		    if (dy<dx)
		    {	d=-(2*dy-dx);		/*初始化判别式d*/
		    	incrE=-2*dy;		/*取像素E时判别式的增量*/
		    	incrNE=-2*(dy-dx);	/*取像素NE时判别式的增量*/
		    	x=x0,y=y0;
		    	while (x<=x1)
				{ 
					if( ( mask&0x8000 ) == 0x8000 )
		 			{
						seGetPixel(x,y, &invertcolor);
		 				seSetPixel(x,y,~invertcolor);
		 				mask=( mask<<1 )|0x0001 ;
					}
					else
						mask=mask<<1;
					if (d>=0)	/*取像素E*/
					{
						d+=incrE;
						x++;
					}
					else	/*取像素NE*/
					{
						d+=incrNE;
						x++;
						y++;
					}
				}
		    }			
		    else 
		    {	d=-(2*dx-dy);		/*初始化判别式d*/
		    	incrE=-2*dx;		/*取像素E时判别式的增量*/
		    	incrNE=-2*(dx-dy);	/*取像素NE时判别式的增量*/
		    	x=x0,y=y0;
		    	while (y<=y1)
		    	{
                    if( ( mask&0x8000 ) == 0x8000 )
		 			{
						seGetPixel(x,y, &invertcolor);
		 				seSetPixel(x,y,~invertcolor);
		 				mask=( mask<<1 )|0x0001 ;
					}

⌨️ 快捷键说明

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