printk.c主要实现字符和字符串的打印包括x和y坐标以及字符的颜色。具体功能是:
printk_char()在指定坐标打印字符;console初始化前调试打印使用。
printk_string()在指定坐标处开始打印字符串;console初始化前调试打印使用。
printk()在当前坐标(g_x,g_y)处开始打印字符串;
snprintf()格式化字符串
具体代码:
#include <printk.h>
#include <stdarg.h>
#include <mem.h>
#include <console.h>
#include <tty.h>
static char *g_print_buf = (char *)MEM_PRINTK_BUF;
/*console初始化前的调试打印调用函数。在x ,y坐标处打印带颜色的一个字符*/
void printk_char(unsigned char x, unsigned char y, unsigned char c, unsigned char color)
{
unsigned short offset;
unsigned char *p;
offset = (unsigned short)y * DISP_MAX_X *2 + (unsigned short)x * 2;
p = (unsigned char *) (DISP_BASE_ADDR + offset);
*p++ = c;
*p++ = color;
return;
}
/*console初始化前的调试打印调用函数。在x ,y坐标起始处打印带颜色的一串字符*/
void printk_string(unsigned char x, unsigned char y, unsigned char *s, unsigned char color)
{
unsigned short offset;
unsigned char *p;
if( !s)
return;
offset = (unsigned short)y*DISP_MAX_X*2 + (unsigned short)x*2;
p = (unsigned char *)(DISP_BASE_ADDR+offset);
while(*s) {
*p++=*s++;
*p++= color;
}
return;
}