| #include "glcd.h" |
| //#include "timer.h" |
| #include "../nec_hardware.h" |
| #include "gb2312_16.h" |
| #include "string.h" |
| #include "stdio.h" |
| |
| uint8_t gb2312_16x16_draw_char(uint8_t x, uint8_t y, uint8_t buf[32]) |
| { |
| uint8_t i,j; |
| |
| for(i=0;i<16;i++) |
| { |
| for(j=0;j<2;j++) |
| { |
| uint8_t dat,bit; |
| |
| dat = buf[2*i+j]; |
| |
| if(glcd_get_reverse_sta()) |
| dat = ~dat; |
| |
| for(bit=0;bit<8;bit++) |
| { |
| if (dat & (0x80>>bit)) |
| { |
| glcd_set_pixel(x+j*8+bit, y+i, BLACK); |
| } |
| else |
| { |
| glcd_set_pixel(x+j*8+bit, y+i,WHITE); |
| } |
| } |
| } |
| } |
| |
| return 16; |
| } |
| |
| void gb2312_16x16_get_data(uint8_t xy[2], uint8_t buf[32]) |
| { |
| uint32_t offset; |
| |
| if((xy[0]<0xa1) || (xy[1])<0xa1) |
| return; |
| |
| offset = (94*(xy[0] - 0xa1) + (xy[1] - 0xa1))*32ul; |
| |
| HW_Flash_Read(offset+256, 32, buf); |
| } |
| |
| uint8_t gb2312_16x8_draw_char(uint8_t x, uint8_t y, uint8_t buf[16]) |
| { |
| uint8_t i; |
| |
| for(i=0;i<16;i++) |
| { |
| uint8_t dat,bit; |
| |
| dat = buf[i]; |
| |
| if(glcd_get_reverse_sta()) |
| dat = ~dat; |
| for(bit=0;bit<8;bit++) |
| { |
| if (dat & (0x80>>bit)) |
| { |
| glcd_set_pixel(x+bit, y+i, BLACK); |
| } |
| else |
| { |
| glcd_set_pixel(x+bit, y+i,WHITE); |
| } |
| } |
| } |
| |
| return 8; |
| } |
| |
| void gb2312_16x8_get_data(uint8_t c, uint8_t buf[16]) |
| { |
| uint32_t offset; |
| |
| offset = c*16ul + 0x43000; |
| |
| HW_Flash_Read(offset, 16, buf); |
| } |
| |
| void gb2312_16x16_test(void) |
| { |
| uint32_t i,j; |
| |
| HW_Flash_Init(); |
| glcd_init(); |
| glcd_clear(); |
| |
| for(i=0xa1;i<0xfe;i++) |
| { |
| uint8_t xy[2]; |
| |
| xy[0] = i; |
| for(j=0xa1;j<0xfe;j++) |
| { |
| uint8_t buf[32]; |
| |
| xy[1] = j; |
| |
| gb2312_16x16_get_data(xy, buf); |
| gb2312_16x16_draw_char(0, 0, buf); |
| glcd_write(); |
| delay_ms(100); |
| } |
| } |
| } |
| |
| |
| void gb2312_16x8_test(void) |
| { |
| uint32_t i; |
| |
| HW_Flash_Init(); |
| glcd_init(); |
| glcd_clear(); |
| |
| for(i=0;i<256;i++) |
| { |
| uint8_t buf[32]; |
| |
| gb2312_16x8_get_data(i, buf); |
| gb2312_16x8_draw_char(0, 0, buf); |
| glcd_write(); |
| delay_ms(50); |
| } |
| } |
| |
| uint8_t gb2312_16_get_ver(uint8_t ver[3]) |
| { |
| uint8_t temp_buff[20]; |
| |
| if(HW_Flash_Read(0, sizeof(temp_buff), temp_buff)) |
| return 1; |
| |
| if(memcmp(temp_buff, sk_font_id, 9)) |
| return 2; |
| |
| memcpy(ver, temp_buff+9, 3); |
| ver[0] -= '0'; |
| ver[1] -= '0'; |
| |
| return 0; |
| } |
| |
| void gb2312_16_draw_str(uint8_t x, uint8_t y, char* s) |
| { |
| uint8_t i=0,j=0; |
| |
| while(*s) |
| { |
| uint8_t buf[32]; |
| |
| #if 1 |
| if(x>=GLCD_LCD_WIDTH || y>=GLCD_LCD_HEIGHT) |
| return ; |
| #else |
| if(x+i >= GLCD_LCD_WIDTH) |
| { |
| j += 16; //»»ÐÐ |
| i = 0; //»Ø³µ |
| } |
| if(y+j >= GLCD_LCD_HEIGHT) |
| { |
| j = 0; |
| i = 0; |
| } |
| #endif |
| if((uint8_t)(*s)<128) |
| { |
| gb2312_16x8_get_data((uint8_t)*s, buf); |
| i += gb2312_16x8_draw_char(x+i, y+j, buf); |
| } |
| else |
| { |
| gb2312_16x16_get_data((uint8_t *)s, buf); |
| i += gb2312_16x16_draw_char(x+i, y+j, buf); |
| s ++; |
| } |
| s ++; |
| } |
| } |
| |
| uint8_t gb2312_16_verify(void) |
| { |
| const uint8_t font_01[32] = |
| { |
| 0x01, 0x00, 0x01, 0x00, 0x01, 0x08, 0x01, 0x10, 0x7D, 0x20, 0x05, 0xC0, 0x05, 0x40, 0x09, 0x20, |
| 0x09, 0x20, 0x11, 0x10, 0x11, 0x18, 0x21, 0x0E, 0xC1, 0x04, 0x01, 0x00, 0x05, 0x00, 0x02, 0x00 |
| }; |
| const uint8_t font_02[32] = |
| { |
| 0x10, 0x00, 0x10, 0x20, 0x10, 0x10, 0xFD, 0xFE, 0x11, 0x04, 0x10, 0x50, 0x14, 0x8C, 0x19, 0x04, |
| 0x30, 0x00, 0xD1, 0xFC, 0x10, 0x20, 0x10, 0x20, 0x10, 0x20, 0x10, 0x20, 0x53, 0xFE, 0x20, 0x00 |
| }; |
| const uint8_t font_03[16] = |
| { |
| 0x00, 0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00 |
| }; |
| const uint8_t font_04[16] = |
| { |
| 0x00, 0x00, 0xFC, 0x66, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x66, 0x66, 0xFC, 0x00, 0x00, 0x00, 0x00 |
| }; |
| uint8_t buf[32]; |
| |
| gb2312_16x16_get_data("Ë®", buf); |
| if(memcmp(buf, font_01, sizeof(font_01))) |
| return 1; |
| gb2312_16x16_get_data("¿Ø", buf); |
| if(memcmp(buf, font_02, sizeof(font_02))) |
| return 2; |
| gb2312_16x8_get_data('A', buf); |
| if(memcmp(buf, font_03, sizeof(font_03))) |
| return 3; |
| gb2312_16x8_get_data('B', buf); |
| if(memcmp(buf, font_04, sizeof(font_04))) |
| return 4; |
| |
| return 0; |
| } |