📄 pal_library.c
字号:
0x00, 0x00, 0x44, 0x7D, 0x41, 0x00,
0x30, 0x48, 0x48, 0x4A, 0x32, 0x00,
0x38, 0x40, 0x40, 0x22, 0x7A, 0x00,
0x00, 0x7A, 0x0A, 0x0A, 0x72, 0x00,
0x7D, 0x0D, 0x19, 0x31, 0x7D, 0x00,
0x26, 0x29, 0x29, 0x2F, 0x28, 0x00,
0x26, 0x29, 0x29, 0x29, 0x26, 0x00,
0x30, 0x48, 0x4D, 0x40, 0x20, 0x00,
0x38, 0x08, 0x08, 0x08, 0x08, 0x00,
0x08, 0x08, 0x08, 0x08, 0x38, 0x00,
0x2F, 0x10, 0xC8, 0xAC, 0xBA, 0x00,
0x2F, 0x10, 0x28, 0x34, 0xFA, 0x00,
0x00, 0x00, 0x7B, 0x00, 0x00, 0x00,
0x08, 0x14, 0x2A, 0x14, 0x22, 0x00,
0x22, 0x14, 0x2A, 0x14, 0x08, 0x00,
0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00,
0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55,
0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00,
0x10, 0x10, 0x10, 0xFF, 0x00, 0x00,
0x14, 0x14, 0x14, 0xFF, 0x00, 0x00,
0x10, 0x10, 0xFF, 0x00, 0xFF, 0x00,
0x10, 0x10, 0xF0, 0x10, 0xF0, 0x00,
0x14, 0x14, 0x14, 0xFC, 0x00, 0x00,
0x14, 0x14, 0xF7, 0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00,
0x14, 0x14, 0xF4, 0x04, 0xFC, 0x00,
0x14, 0x14, 0x17, 0x10, 0x1F, 0x00,
0x10, 0x10, 0x1F, 0x10, 0x1F, 0x00,
0x14, 0x14, 0x14, 0x1F, 0x00, 0x00,
0x10, 0x10, 0x10, 0xF0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1F, 0x10, 0x10,
0x10, 0x10, 0x10, 0x1F, 0x10, 0x10,
0x10, 0x10, 0x10, 0xF0, 0x10, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x10, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0xFF, 0x10, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x14, 0x14,
0x00, 0x00, 0xFF, 0x00, 0xFF, 0x10,
0x00, 0x00, 0x1F, 0x10, 0x17, 0x14,
0x00, 0x00, 0xFC, 0x04, 0xF4, 0x14,
0x14, 0x14, 0x17, 0x10, 0x17, 0x14,
0x14, 0x14, 0xF4, 0x04, 0xF4, 0x14,
0x00, 0x00, 0xFF, 0x00, 0xF7, 0x14,
0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x14, 0xF7, 0x00, 0xF7, 0x14,
0x14, 0x14, 0x14, 0x17, 0x14, 0x14,
0x10, 0x10, 0x1F, 0x10, 0x1F, 0x10,
0x14, 0x14, 0x14, 0xF4, 0x14, 0x14,
0x10, 0x10, 0xF0, 0x10, 0xF0, 0x10,
0x00, 0x00, 0x1F, 0x10, 0x1F, 0x10,
0x00, 0x00, 0x00, 0x1F, 0x14, 0x14,
0x00, 0x00, 0x00, 0xFC, 0x14, 0x14,
0x00, 0x00, 0xF0, 0x10, 0xF0, 0x10,
0x10, 0x10, 0xFF, 0x10, 0xFF, 0x10,
0x14, 0x14, 0x14, 0xFF, 0x14, 0x14,
0x10, 0x10, 0x10, 0x1F, 0x00, 0x00,
0x00, 0x00, 0x00, 0xF0, 0x10, 0x10,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x38, 0x44, 0x44, 0x38, 0x44, 0x00,
0x7C, 0x2A, 0x2A, 0x3E, 0x14, 0x00,
0x7E, 0x02, 0x02, 0x06, 0x06, 0x00,
0x02, 0x7E, 0x02, 0x7E, 0x02, 0x00,
0x63, 0x55, 0x49, 0x41, 0x63, 0x00,
0x38, 0x44, 0x44, 0x3C, 0x04, 0x00,
0x40, 0x7E, 0x20, 0x1E, 0x20, 0x00,
0x06, 0x02, 0x7E, 0x02, 0x02, 0x00,
0x99, 0xA5, 0xE7, 0xA5, 0x99, 0x00,
0x1C, 0x2A, 0x49, 0x2A, 0x1C, 0x00,
0x4C, 0x72, 0x01, 0x72, 0x4C, 0x00,
0x30, 0x4A, 0x4D, 0x4D, 0x30, 0x00,
0x30, 0x48, 0x78, 0x48, 0x30, 0x00,
0xBC, 0x62, 0x5A, 0x46, 0x3D, 0x00,
0x3E, 0x49, 0x49, 0x49, 0x00, 0x00,
0x7E, 0x01, 0x01, 0x01, 0x7E, 0x00,
0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x00,
0x44, 0x44, 0x5F, 0x44, 0x44, 0x00,
0x40, 0x51, 0x4A, 0x44, 0x40, 0x00,
0x40, 0x44, 0x4A, 0x51, 0x40, 0x00,
0x00, 0x00, 0xFF, 0x01, 0x03, 0x00,
0xE0, 0x80, 0xFF, 0x00, 0x00, 0x00,
0x08, 0x08, 0x6B, 0x6B, 0x08, 0x08,
0x36, 0x12, 0x36, 0x24, 0x36, 0x00,
0x06, 0x0F, 0x09, 0x0F, 0x06, 0x00,
0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
0x00, 0x00, 0x10, 0x10, 0x00, 0x00,
0x30, 0x40, 0xFF, 0x01, 0x01, 0x00,
0x00, 0x1F, 0x01, 0x01, 0x1E, 0x00,
0x00, 0x19, 0x1D, 0x17, 0x12, 0x00,
0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
} ;
/*********************
* LIBRARY FUNCTIONS
*********************/
/************************************
* Interrupt service routine
* This function MUST be included by user in the interrupt() routine
* like this :
* void interrupt() { PAL_ISR() } ;
*
* All PAL video generation is done here
* one call is one video or vertical sync line of 64 祍
***********************************/
void PAL_ISR()
{
if(INTCON.TMR0IF)
{
unsigned char d ; // temporary register to save TABLAT
PAL_BVID = 0 ; // end of previous line
PAL_BSYNC = 0 ;
d = TABLAT ;
PAL_lineCode = *PAL_linePtr ; // get curret line code
if(PAL_lineCode == PAL_LVIDEO) // is it a visible video line ?
{
unsigned char *ptr ; // temporary pointer
volatile char dummy ; // dummy char to please compiler
/*
* start of video line
*/
PAL_HSYNC(3) ; // horizontal sync : low level
PAL_BSYNC = 1 ; // ultra black
/*
* during ultra black level :
*/
PAL_lineVideo++ ; // next line number
if(PAL_lineVideo == 287) // last line ?
{
// next step in line table
PAL_linePtr++ ;
PAL_lineIdx++ ;
}
/*
* points to the first 8 pixels of the line
*/
ptr = PAL_screen + (((PAL_lineVideo - PAL_shift_y) & 0b11111110) << 3) ;
/*
* make left border
*/
PAL_MAKE_BORDER ;
/*
* is rendering enabled and line number within limits ?
* if not, a border color line will be displayed
*/
if(PAL_render && ((PAL_lineVideo >= PAL_shift_y) && (PAL_lineVideo < PAL_max_y)))
{
/*
* yes, display one video line
* one line is 16 bytes ( x 8 = 128 pixels)
*/
dummy = *ptr ; // dummy assignement lo let the compiler know PAL_ISR_ptr
PAL_BLOCK_HEAD ; // header
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ; // shift bits, preload and load
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ;
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ;
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ;
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ;
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ;
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ;
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ;
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ;
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ;
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ;
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ;
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ;
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ;
PAL_BLOCK_SHIFT ; PAL_BLOCK_LOAD ;
PAL_BLOCK_SHIFT ;
PAL_MAKE_BORDER ; // make right border
}
}
else
{
/*
* vertical synchronization
* decode the PAL_lineCode and build the 4 parts of the sync line
*/
PAL_BSYNC = (PAL_lineCode & 1) ? 1 : 0 ; // first part
if(PAL_lineCode & 2) Delay_us(PAL_DELAY4) ; else Delay_us(PAL_DELAY28 - 6) ;
PAL_linePtr++ ;
PAL_lineIdx++ ;
PAL_lineVideo = 0 ;
/*
* points to the next line type
*/
if(PAL_lineIdx == sizeof(PAL_ltype)) // end of table ?
{
PAL_lineIdx = 0 ; // back to start
PAL_linePtr = PAL_ltype ;
PAL_frameCtr++ ;
}
PAL_BSYNC = (PAL_lineCode & 4) ? 1 : 0 ; // second part
if(PAL_lineCode != PAL_LINFO)
{
if(PAL_lineCode & 8) Delay_us(PAL_DELAY4) ; else Delay_us(PAL_DELAY28) ;
PAL_BSYNC = (PAL_lineCode & 16) ? 1 : 0 ; // third part
if(PAL_lineCode & 32) Delay_us(PAL_DELAY4) ; else Delay_us(PAL_DELAY28) ;
PAL_BSYNC = (PAL_lineCode & 64) ? 1 : 0 ; // fourth part (no delay is needed)
}
}
TABLAT = d ;
INTCON.TMR0IF = 0 ; // clear TIMER 0 interrupt flag
}
}
/************************************************************
* PAL_init : PAL initialization
* parameters :
* y : number of vertical lines in pixels
* the more vertical lines you have :
* - the less RAM you have
* - the less MCU time you have
* returns :
* nothing
* requires :
* the PIC MUST be clocked at 32 Mhz
* notes :
* this function must be called to prepare for PAL video generation
* this function takes control of TIMER 0 and associated interrupt
*/
void PAL_init(unsigned char y)
{
INTCON.T0IF = 0 ; // clear TIMER 0 overflow interrupt flag
INTCON.T0IE = 0 ; // disable TIMER 0 overflow interrupt
T0CON = 0b11000000 ; // TIMER 0 is 8 bits, prescaler = 2
PAL_y = y ; // save vertical definition
PAL_shift_y = 286 / 2 - y ; // compute vertical offset for centering
PAL_max_y = y * 2 + PAL_shift_y ; // compute last video line number
}
/**********************************************
* PAL_start : start PAL video generation
* parameters :
* st : start/stop PAL video generation, start = 1, stop = 0
* rd : start/stop rendering, start = 1, stop = 0
* returns :
* nothing
* requires :
* PAL_init must have been called
* notes :
* none
*/
void PAL_control(unsigned char st, unsigned char rd)
{
if(st)
{
INTCON.GIE = 1 ; // enable global interrupts
INTCON.T0IE = 1 ; // enable TIMER 0 overflow interrupt
}
else
{
INTCON.T0IE = 0 ; // dsable TIMER 0 overflow interrupt
}
PAL_render = rd ;
}
/************************************************
* PAL_fill : fill video screen with pattern
* parameters :
* c : filling pattern
* for example : 0 for black screen, 0xff for white screen
* returns :
* nothing
* requires :
* PAL_init must have been called
* notes :
* none
*/
void PAL_fill(unsigned char c)
{
memset(PAL_screen, c, PAL_X * PAL_y / 8) ;
}
/**********************************************
* PAL_setBorder : set video border color
* parameters :
* border : PAL_COLOR_WHITE or PAL_COLOR_BLACK
* returns :
* nothing
* requires :
* PAL_init must have been called
* notes :
* none
*/
void PAL_setBorder(unsigned char border)
{
PAL_border = border ;
}
/********************************************
* PAL_setPixel : direct access to pixel
* parameters :
* x : pixel row
* y : pixel column
* mode : PAL_COLOR_WHITE or PAL_COLOR_BLACK or PAL_COLOR_REVERSE
* returns :
* nothing
* requires :
* PAL_init must have been called
* notes :
* none
*/
void PAL_setPixel(char x, char y, unsigned char mode)
{
unsigned char *ptr ;
unsigned char mask ;
/*
* do nothing if pixel is out of bounds
*/
if(x < 0) return ;
if(y < 0) return ;
if(x >= PAL_X) return ;
if(y >= PAL_y) return ;
ptr = PAL_screen + (((y << 7) + x) >> 3) ; // points to byte in screen map
mask = 1 << (x & 7) ; // pixel bit mask
switch(mode)
{
case PAL_COLOR_BLACK:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -