我的学习之旅(20)console.h和console.c

来源:互联网 发布:魔方大数据 编辑:程序博客网 时间:2024/06/16 00:42
void console_write(void *tty, char *buf ){    unsigned int number = 0;    unsigned char ch;    unsigned char *up;        if( !tty || !buf )        return;        /* 统计当前write_q队列中的字符数*/    number = ((((tty_struct_t *)tty)->write_q.head-((tty_struct_t *)tty)->write_q.tail)&(TTY_BUF_SIZE-1));    /* 读取并处理所有write_q中的字符*/    while( number-- ) {        ch =   get_char_from_queue( &((tty_struct_t *)tty)->write_q);           if( ch > 31 && ch < 127 ) { /*非控制字符*/            if( g_x >=  DISP_MAX_X) {                g_x  = g_x - DISP_MAX_X;//换行并进一行                g_position = g_position - BYTES_FOR_ONE_LINE;                add_a_line();            }            //刷新g_position以便后面刷新光标位置            up = (unsigned char *)g_position;            up[0] = ch; //字符            up[1] = g_color; //颜色            g_position += 2;            g_x++;        }        else if(ch == 10 || ch== 11 || ch== 12 || ch == 13) { /*换行'\n' 并重新调整坐标*/           add_a_line();           gotoxy(0, g_y);        }        else if ( ch == 177 ||ch==127 ) { /*删除符号*/            delete_char();        }        else {            /*不支持*/        }    }    /*刷新光标位置*/    (void)set_cursor(1);}

0 0