📄 gpcdrv.c
字号:
/***************************************************************************************\
*
* Copyright (c) 2001 National ASIC Center, All Rights Reserved
*
* File Name: gpcdrv.c
* Programmer: Julias
*
* Date of Creation: 2001/10/23
*
* Description: This is an application file for operating VRAM.
*
* Local Function List:
*
* seSetPixel(GC *gc, SHORT x,SHORT y,PIXEL ColorIndex, WORD style);
* seGetPixel(GC *gc, SHORT x, SHORT y, PIXEL *ColorIndex);
* seDrawHorzLine(GC *gc, SHORT x,SHORT y,SHORT width,PIXEL ColorIndex,WORD mask, WORD style);
* seDrawVertLine(GC *gc, SHORT x,SHORT y,SHORT height,PIXEL ColorIndex,WORD mask, WORD style);
* seDrawLine(GC *gc, SHORT x1,SHORT y1,SHORT x2, SHORT y2,PIXEL ColorIndex,WORD mask, WORD style);
* seSetMonoImageLine( GC *gc, PPHYIMAGEINFO ppii );
* seSetMonoImage( GC *gc, PPHYIMAGEINFO ppii );
* sePutChar( GC *gc, PPHYIMAGEINFO ppii );
* seSetImage(GC *gc, SHORT x, SHORT y, SHORT width, SHORT height , VRAM *buffer, WORD style);
* seGetImage(GC *gc, SHORT x, SHORT y, SHORT width , SHORT height , VRAM *buffer);
* seEllipse (GC *gc, SHORT x, SHORT y, SHORT a, SHORT b, PIXEL ColorIndex, WORD style);
* seRGBtoIndex(DWORD rgb , PIXEL *index);
* seClearRec(GC *gc, SHORT x, SHORT y, SHORT width, SHORT height, PIXEL ColorIndex, WORD style);
* seInvRec(GC *gc, SHORT x, SHORT y, SHORT width, SHORT height);
* seWrite2LCD( SHORT x1, SHORT x2, SHORT y1, SHORT y2, PWORD initAd, WORD Lwidth );
* seDrawImage(GC *gc, SHORT x, SHORT y, SHORT width, SHORT height , VRAM *buffer, WORD style, WORD trColor );
* seDrawCircle( GC *gc, SHORT xCenter, SHORT yCenter, SHORT radius, PIXEL ColorIndex, WORD style );
* seDisplayBMP( GC *gc, WORD x, WORD y, WORD width, WORD height, BITMAP *bmp );
* seDisplayBMPEx( GC *gc, WORD x, WORD y, WORD width, WORD height, BITMAP *bmp, WORD style, PIXEL trIndex );
*
***************************************************************************************
*
* Modification History
*
* 2002/04/25 by longn_qi create file.
* 2002/05/7 by Julias add function TurnOffLCD to every function
*
\***************************************************************************************/
#include <string.h>
#include <math.h>
#include <sys\gpc.h>
#include <sys\systsk.h>
// simulator header
//#include <simdrv\export\driver.h>
#include <sys\vramop.h>
#include <hardware\drball\lcd68k.h>
//void vDisableInterrupt( void );
//void vEnableInterrupt( void );
#define LCD_Command 0x0100000
#define LCD_Data 0x0100002
/*
void vDisableInterrupt( void )
{
asm("ld.w %r9, %psr\nand %r9, 0xef\nld.w %psr, %r9");
}
void vEnableInterrupt( void )
{
asm("ld.w %r10, %psr\nor %r9, 0x10\nld.w %psr, %r9");
}
*/
//画粗点的模板 以[(n-1)/2][(n-1)/2]为中心点
const char dot2[2][2] = {{2,1},{1,1}};
const char dot3[3][3] = {{0,1,0},{1,2,1},{0,1,0}};
const char dot4[4][4] = {{0,1,1,0}, {1,2,1,1}, {1,1,1,1}, {0,1,1,0}};
const char dot5[5][5] = {{0,0,1,0,0}, {0,1,1,1,0}, {1,1,2,1,1}, {0,1,1,1,0}, {0,0,1,0,0}};
const char dot6[6][6] = {{0,0,1,1,0,0}, {0,1,1,1,1,0}, {1,1,2,1,1,1}, {1,1,1,1,1,1}, {0,1,1,1,1,0},\
{0,0,1,1,0,0}};
const char dot7[7][7] = {{0,0,1,1,1,0,0},\
{0,1,1,1,1,1,0},\
{0,1,1,1,1,1,0},\
{1,1,1,2,1,1,1},\
{0,1,1,1,1,1,0},\
{0,1,1,1,1,1,0},\
{0,0,1,1,1,0,0}};
const char dot8[8][8] = {{0,0,1,1,1,1,0,0},\
{0,1,1,1,1,1,1,0},\
{0,1,1,1,1,1,1,0},\
{1,1,1,2,1,1,1,1},\
{1,1,1,1,1,1,1,1},\
{0,1,1,1,1,1,1,0},\
{0,1,1,1,1,1,1,0},\
{0,0,1,1,1,1,0,0}};
const char dot9[9][9] = {{0,0,1,1,1,1,1,0,0},\
{0,0,1,1,1,1,1,0,0},\
{0,1,1,1,1,1,1,1,0},\
{0,1,1,1,1,1,1,1,0},\
{1,1,1,1,2,1,1,1,1},\
{0,1,1,1,1,1,1,1,0},\
{0,1,1,1,1,1,1,1,0},\
{0,0,1,1,1,1,1,0,0},\
{0,0,1,1,1,1,1,0,0}};
const char dot1[10][10] = {{0,0,1,1,1,1,1,1,0,0},\
{0,0,1,1,1,1,1,1,0,0},\
{0,1,1,1,1,1,1,1,1,0},\
{0,1,1,1,1,1,1,1,1,0},\
{1,1,1,1,2,1,1,1,1,1},\
{1,1,1,1,2,1,1,1,1,1},\
{0,1,1,1,1,1,1,1,1,0},\
{0,1,1,1,1,1,1,1,1,0},\
{0,0,1,1,1,1,1,1,0,0},\
{0,0,1,1,1,1,1,1,0,0}};
const BYTE mask[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
/*
const BYTE solid = 0xffff;
const BYTE dash = 0xf0f0;
const BYTE dot = 0xaaaa;
const BYTE dashdot = 0xe4e4;
*/
/*add by DSA 2004.07.02*/
void VertLineUnicolorOp( PIXEL *desLinePos, CHAR desBitOffset, WORD len, PIXEL srcValue, WORD mask, WORD op, VRAM *vram )
{
#ifdef BIG_ENDIAN_ORDER
PIXEL srcMask = PixelMask << ( PIXEL_UNIT - BITS_PER_PIXEL - desBitOffset );
#else
PIXEL srcMask = PixelMask << desBitOffset;
#endif
WORD lw = vram->widthInUnit;
WORD i;
WORD enBit = 0;
#ifdef BIG_ENDIAN_ORDER
srcValue = srcValue << ( PIXEL_UNIT - desBitOffset - BITS_PER_PIXEL );
#else
srcValue = srcValue << desBitOffset;
#endif
switch( op )
{
case GPC_REPLACE_STYLE:
case GPC_COPY_STYLE:
for( i = 0; i < len; i++, desLinePos += lw )
{
if( enBit == 0 )
enBit = 0x8000;
if( enBit & mask )
(*desLinePos) = ( (*desLinePos) & ~srcMask ) | ( srcValue & srcMask );
enBit = enBit >> 1;
}
break;
case GPC_XOR_STYLE:
for( i = 0; i < len; i++, desLinePos += lw )
{
if( enBit == 0 )
enBit = 0x8000;
if( enBit & mask )
(*desLinePos) = (*desLinePos) ^ ( srcValue & srcMask );
enBit = enBit >> 1;
}
break;
case GPC_AND_STYLE:
for( i = 0; i < len; i++, desLinePos += lw )
{
if( enBit == 0 )
enBit = 0x8000;
if( enBit & mask )
(*desLinePos) = (*desLinePos) & ( ( ~srcMask ) | ( srcValue & srcMask ) );
enBit = enBit >> 1;
}
break;
case GPC_OR_STYLE:
for( i = 0; i < len; i++, desLinePos += lw )
{
if( enBit == 0 )
enBit = 0x8000;
if( enBit & mask )
(*desLinePos) = (*desLinePos) | ( srcValue & srcMask );
enBit = enBit >> 1;
}
break;
default:
break;
}
return;
}
/*end add*/
//-------------------------------------------------------------------------
// Function name :seSetPixel()
//
// Description :sets the pixel at the specified coordinates to specified color
// with specified style.
// ColorIndex is interrupted by HAL.GPC can use function seRGBtoIndex to convert
// a RGB value to a color index
//
// Parameters:
// gc: the point that points the current task's gc
// 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
// style : the style to be use to paint the pixel. consisted of:GPC_REPLACE_STYLE,
// GPC_AND_STYLE,GPC_OR_STYLE,GPC_XOR_STYLE,GPC_COPY_STYLE,GPC_NOT_STYLE
//
// No return value
//-------------------------------------------------------------------------
void seSetPixel( GC *gc, SHORT x, SHORT y, PIXEL ColorIndex, WORD style)
{
PIXEL *pixelPos;
CHAR bitOffset;
// TurnOffLCD(); //Julias 2002/5/7
GetPixelPosition( &pixelPos, &bitOffset, gc->vram, x, y );
PixelOp( pixelPos, bitOffset, ColorIndex, style );
}
//-------------------------------------------------------------------------
// Function name :seGetPixel()
//
// Description :retrives the color value of the pixel at the specified coordinates
//
// Parameters:
// gc: the point that points the current task's gc
// 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
//
// No return value
//-------------------------------------------------------------------------
void seGetPixel(GC *gc, SHORT x, SHORT y, PIXEL *ColorIndex)
{
PIXEL *pixelPos;
CHAR bitOffset;
// TurnOffLCD(); //Julias 2002/5/7
GetPixelPosition( &pixelPos, &bitOffset, gc->vram, x, y );
newGetPixel( ColorIndex, pixelPos, bitOffset );
}
//-------------------------------------------------------------------------
// Function name :seDrawHorzLine()
//
// Description :draws a horzontal line
//
// Parameters:
// gc: the point that points the current task's gc
// x,y :specified the coordinate of the lines start point in pixel
// width :specified the width of the lines
// ColorIndex:the color of the pixel
// mask:line style mask,such as GPC_SOLID_LINE,GPC_DASH_LINE,GPC_DOT_LINE,GPC_DASHDOT_LINE
// style : the style to be use to paint the pixel. consisted of:GPC_REPLACE_STYLE,
// GPC_AND_STYLE,GPC_OR_STYLE,GPC_XOR_STYLE,GPC_COPY_STYLE,GPC_NOT_STYLE
//
// No return value
//-------------------------------------------------------------------------
void seDrawHorzLine(GC *gc, SHORT x, SHORT y, SHORT width, PIXEL ColorIndex, WORD mask, WORD style)
{
SHORT topx, topy;
PIXEL *lineAd;
CHAR bitOffset;
topx = x;
topy = y - ( (gc->dotwidth - 1) >> 1 );
GetPixelPosition( &lineAd, &bitOffset, gc->vram, topx, topy );
// TurnOffLCD(); //Julias 2002/5/7
if ( (gc->dotwidth != 1 && width < gc->dotwidth) || width == 0 ) //画点或粗点
{
if( mask == GPC_SOLID_LINE )
BlockUnicolorOp( lineAd, bitOffset, width, gc->dotwidth, ColorIndex, style, gc->vram );
else
BlockUnicolorMaskOp( lineAd, bitOffset, width, gc->dotwidth, ColorIndex, mask, style, gc->vram );
}
else
{
if( mask == GPC_SOLID_LINE )
LineUnicolorOp( lineAd, bitOffset, width, ColorIndex, style );
else
LineUnicolorMaskOp( lineAd, bitOffset, width, ColorIndex, mask, style );
}
}
//-------------------------------------------------------------------------
// Function name :seDrawVertLine()
//
// Description :draws a vertical line
//
// Parameters:
// gc: the point that points the current task's gc
// x,y :specified the coordinate of the lines start point in pixel
// height :specified the height of the lines
// ColorIndex:the color of the pixel
// mask:line style mask,such as GPC_SOLID_LINE,GPC_DASH_LINE,GPC_DOT_LINE,GPC_DASHDOT_LINE
// style : the style to be use to paint the pixel. consisted of:GPC_REPLACE_STYLE,
// GPC_AND_STYLE,GPC_OR_STYLE,GPC_XOR_STYLE,GPC_COPY_STYLE,GPC_NOT_STYLE
//
// No return value
//-------------------------------------------------------------------------
//void seDrawVertLine(GC *gc, SHORT x, SHORT y, WORD height, WORD ColorIndex, WORD mask, WORD style)
void seDrawVertLine(GC *gc, SHORT x, SHORT y, SHORT height, PIXEL ColorIndex, WORD mask, WORD style)
{
SHORT j; // x1, x2, y1, y2, topx, topy; //i控制x轴,j控制y轴的变化(j在画点和画粗线中用到)
SHORT topx, topy;
PIXEL *lineAd, *nextLineAd;
CHAR bitOffset, nextBitOffset;
WORD enBit = 0;
topx = x - ( (gc->dotwidth - 1) >> 1 );
topy = y;
GetPixelPosition( &lineAd, &bitOffset, gc->vram, topx, topy );
// TurnOffLCD(); //Julias 2002/5/7
if ( (gc->dotwidth != 1 && height < gc->dotwidth) || height == 0 ) //画点或粗点
{
nextLineAd = lineAd;
nextBitOffset = bitOffset;
for ( j = 0; j < height; j++ )
{
if( enBit == 0 )
enBit = 0x8000;
if( enBit & mask )
LineUnicolorOp( nextLineAd, nextBitOffset, gc->dotwidth, ColorIndex, style );
enBit = enBit >> 1;
GetNextLine( &nextLineAd, &nextBitOffset, nextLineAd, nextBitOffset, gc->vram );
}
}
else
{
/* nextLineAd = lineAd;
nextBitOffset = bitOffset;
for ( j = 0; j < height; j++ )
{
if( enBit == 0 )
enBit = 0x8000;
if( enBit & mask )
PixelOp( nextLineAd, nextBitOffset, ColorIndex, style );
enBit = enBit >> 1;
GetNextLine( &nextLineAd, &nextBitOffset, nextLineAd, nextBitOffset, gc->vram );
}
*/ VertLineUnicolorOp( lineAd, bitOffset, height, ColorIndex, mask, style, gc->vram );
}
}
//-------------------------------------------------------------------------
// Function name :seDrawLine()
//
// Description :draws a line
//
// Parameters:
// gc: the point that points the current task's gc
// x1,y1:specified the coordinate of the lines start point in pixel
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -