📄 pal_library.c
字号:
*ptr &= ~mask ; // clear bit
break ;
case PAL_COLOR_WHITE: // set bit
*ptr |= mask ;
break ;
default:
*ptr ^= mask ; // toggle bit
break ;
}
}
/******************************
* PAL_line : draw a line
* parameters :
* x0, y0 : pixel start coordinates
* x1, y1 : pixel end coordinates
* pcolor : PAL_COLOR_WHITE or PAL_COLOR_BLACK or PAL_COLOR_REVERSE
* returns :
* nothing
* requires :
* PAL_init must have been called
* notes :
* uses Bresenham's line drawing algorithm
*/
void PAL_line(char x0, char y0, char x1, char y1, unsigned char pcolor)
{
int dy ;
int dx ;
int stepx, stepy ;
dy = y1 - y0 ;
dx = x1 - x0 ;
if(dy < 0)
{
dy = -dy ;
stepy = -1 ;
}
else
{
stepy = 1 ;
}
if(dx < 0)
{
dx = -dx ;
stepx = -1 ;
}
else
{
stepx = 1 ;
}
dy <<= 1 ;
dx <<= 1 ;
PAL_setPixel(x0, y0, pcolor) ;
if(dx > dy)
{
int fraction = dy - (dx >> 1) ;
while(x0 != x1)
{
if(fraction >= 0)
{
y0 += stepy ;
fraction -= dx ;
}
x0 += stepx ;
fraction += dy ;
PAL_setPixel(x0, y0, pcolor) ;
}
}
else
{
int fraction = dx - (dy >> 1) ;
while(y0 != y1)
{
if(fraction >= 0)
{
x0 += stepx ;
fraction -= dy ;
}
y0 += stepy ;
fraction += dx ;
PAL_setPixel(x0, y0, pcolor) ;
}
}
}
/**********************************
* PAL_circle : draw a circle
* parameters :
* x, y : row and column of the center
* r : radius
* pcolor : PAL_COLOR_WHITE or PAL_COLOR_BLACK or PAL_COLOR_REVERSE
* returns :
* nothing
* requires :
* PAL_init must have been called
* notes :
* none
*/
void PAL_circle(char x, char y, char r, unsigned char pcolor)
{
long px, py, opx, opy ;
int a ;
for(a = 0 ; a <= 360 ; a += 15) // for each angle from 0 to 360
{
/*
* pixel row
*/
px = (long)sinE3(a) * r ;
px /= 1000 ;
px += x ;
/*
* pixel column
*/
py = (long)cosE3(a) * r ;
py /= 1000 ;
py += y ;
/*
* if not first step
*/
if(a > 0)
{
PAL_line(opx, opy, px, py, pcolor) ; // draw the line from old to new coordinates
}
opx = px ; // save previous coordinates
opy = py ;
}
}
/**********************************
* PAL_box : draw a solid box
* parameters :
* x0, y0 : top left coordinates
* x1, y1 : bottom right coordinates
* pcolor : PAL_COLOR_WHITE or PAL_COLOR_BLACK or PAL_COLOR_REVERSE
* returns :
* nothing
* requires :
* PAL_init must have been called
* notes :
* none
*/
void PAL_box(char x0, char y0, char x1, char y1, unsigned char pcolor)
{
/*
* just draw lines from left to right
*/
while(x0 != x1)
{
PAL_line(x0, y0, x0, y1, pcolor) ;
x0++ ;
}
}
/************************************
* PAL_rectangle : draw a solid rectangle
* parameters :
* x0, y0 : top left coordinates
* x1, y1 : bottom right coordinates
* pcolor : PAL_COLOR_WHITE or PAL_COLOR_BLACK or PAL_COLOR_REVERSE
* returns :
* nothing
* requires :
* PAL_init must have been called
* notes :
* none
*/
void PAL_rectangle(char x0, char y0, char x1, char y1, unsigned char pcolor)
{
/*
* just draw the four lines of the border
*/
PAL_line(x0, y0, x1, y0, pcolor) ;
PAL_line(x1, y0, x1, y1, pcolor) ;
PAL_line(x1, y1, x0, y1, pcolor) ;
PAL_line(x0, y1, x0, y0, pcolor) ;
}
/********************************
* PAL_char : draw a character
* parameters :
* x, y : top left coordinates where to draw
* c : PAL_COLOR_WHITE or PAL_COLOR_BLACK or PAL_COLOR_REVERSE
* size : high nibble is height multiplier, low nibble is width multiplier
* returns :
* nothing
* requires :
* PAL_init must have been called
* notes :
* char is white on black background, please use PAL_box to reverse after PAL_char if you want to reverse video.
*/
void PAL_char(unsigned char x, unsigned char y, unsigned char c, unsigned char size)
{
unsigned char i, j ;
unsigned char px, py ;
unsigned char sx, sy ;
unsigned char mx, my ;
const char *ptr ;
/*
* get height and width size
*/
mx = size & 0x0f ;
my = size >> 4 ;
/*
* pointer to pattern in character table
*/
ptr = PAL_charTable + c * 6 ;
/*
* char is 6 pixels large
*/
for(i = 0 ; i < 6 ; i++)
{
px = x + i * mx ;
c = *ptr++ ; // get byte pattern
py = y ;
/*
* char is 8 pixels high
*/
for(j = 0 ; j < 8 ; j++)
{
for(sx = 0 ; sx < mx ; sx++)
{
for(sy = 0 ; sy < my ; sy++)
{
PAL_setPixel(px + sx, py + sy, c & 1) ; // paint pixel
}
}
c >>= 1 ; // next one
py += my ;
}
}
}
/*******************************
* PAL_write : write a string
* parameters :
* lig, col : line and column of the first char
* s : string to write
* size : high nibble is height multiplier, low nibble is width multiplier
* returns :
* nothing
* requires :
* PAL_init must have been called
* notes :
* no cursor, no automatic carriage return at end of line.
* string is painted white on black, use PAL_box to reverse video after writing if you need.
*/
void PAL_write(unsigned char lig, unsigned char col, unsigned char *s, unsigned char size)
{
unsigned char c ;
/*
* coordinates calculations
*/
lig <<= 3 ; // a char is 8 pixels high
col *= 6 ; // and 6 pixel large
while(c = *s++) // parse all string
{
PAL_char(col, lig, c, size) ; // print char
col += 6 *(size & 0x0f) ; // next row
}
}
/***************************************
* PAL_write : write a constant string
* parameters :
* lig, col : line and column of the first char
* s : string to write
* size : high nibble is height multiplier, low nibble is width multiplier
* returns :
* nothing
* requires :
* PAL_init must have been called
* notes :
* no cursor, no automatic carriage return at end of line.
* string is displayed white on black, use PAL_box to reverse video after writing if you need.
*/
void PAL_constWrite(unsigned char lig, unsigned char col, const unsigned char *s, unsigned char size)
{
unsigned char c ;
lig <<= 3 ;
col *= 6 ;
while(c = *s++)
{
PAL_char(col, lig, c, size) ;
col += 6 *(size & 0x0f) ; // next row
}
}
/***************************************
* PAL_picture : draw a bitmap picture
* parameters :
* x, y : coordinates of the top left location
* bm : pointer to picture bitmap
* sx, sy : size of the picture (in pixels)
* returns :
* nothing
* requires :
* PAL_init must have been called
* notes :
* data is arranged as a monochrome bitmap
* mikroElektronika GLCD bitmap editor tool does it very well :
* select T6963 and 128x128 for example.
*/
void PAL_picture(unsigned char x, unsigned char y, const unsigned char *bm, unsigned char sx, unsigned char sy)
{
unsigned char i, j, k ;
unsigned char px ;
unsigned int py ;
unsigned char c ;
sx /= 8 ;
x /= 8 ;
for(j = 0 ; j < sy ; j++)
{
py = (y + j) << 4 ;
for(i = 0 ; i < sx ; i++)
{
unsigned char rc ;
px = x + i ;
c = *bm++ ;
for(k = 0 ; k < 8 ; k++)
{
rc <<= 1 ;
rc |= c & 1 ;
c >>= 1 ;
}
PAL_screen[px + py] = rc ;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -