示例#1
0
// 屏幕输出一个字符(带颜色)
static void console_putc_color(char c, real_color_t back, real_color_t fore)
{
        uint8_t back_color = (uint8_t)back;
        uint8_t fore_color = (uint8_t)fore;

        uint8_t attribute_byte = (back_color << 4) | (fore_color & 0x0F);
        uint16_t attribute = attribute_byte << 8;

        // 0x08 是 退格键 的 ASCII 码
        // 0x09 是 tab 键 的 ASCII 码
        if (c == 0x08 && buffer_x) {
              buffer_x--;
        } else if (c == 0x09) {
              buffer_x = (buffer_x+8) & ~(8-1);
        } else if (c == '\r') {
              buffer_x = 0;
        } else if (c == '\n') {
                buffer_x = 0;
                buffer_y++;
        } else if (c >= ' ') {
                video_buffer[buffer_y * BUFF_WIDTH + buffer_x] = c | attribute;
                buffer_x++;
        }

        // 每 80 个字符一行,满80就必须换行了
        if (buffer_x == BUFF_WIDTH) {
                buffer_x = 0;
                buffer_y ++;
        }

        // 滚动缓冲区
        scroll_buffer();
}
示例#2
0
static void append_char(char c)
{
	if(!bb->lines) {bb->lines++; cursor_pos=0;}
	if(bb->text[bb->lines - 1]==NULL)
	{
		bb->text[bb->lines - 1]=malloc(CC_MAX_LINE_LENGTH);
		memset(bb->text[bb->lines - 1],0,CC_MAX_LINE_LENGTH);
		cursor_pos=0;
	}

	if(c=='\n')
	{
		if(cursor_pos>0 && bb->lines < SUB_MAX_TEXT)
		{
			bb->lines++;cursor_pos=0;
			if(cc_mode==CC_ROLLUP){ //Carriage return - scroll buffer one line up
				bb->text[bb->lines - 1]=calloc(1, CC_MAX_LINE_LENGTH);
				scroll_buffer(bb);
			}
		}
	}
	else
	{
		if(cursor_pos==CC_MAX_LINE_LENGTH-1)
		{
			fprintf(stderr,"CC: append_char() reached CC_MAX_LINE_LENGTH!\n");
			return;
		}
		bb->text[bb->lines - 1][cursor_pos++]=c;
	}
	//In CC roll-up mode data should be shown immediately
	if(cc_mode==CC_ROLLUP) display_buffer(bb);
}