diff --git a/kernel/chr_drv/console.c b/kernel/chr_drv/console.c index 3f6c592da23c178d7254fbd106c15d296aa44c62..749aa726f0629086fce14fe2a2de26a6a35590cb 100644 --- a/kernel/chr_drv/console.c +++ b/kernel/chr_drv/console.c @@ -27,6 +27,7 @@ static unsigned long video_size_row; /* Bytes per row */ static unsigned char video_page; /* Initial video page */ static unsigned short video_port_reg; /* Video register select port */ static unsigned short video_port_val; /* Video register value port */ +static unsigned short video_erase_char; static unsigned long origin; static unsigned long scr_end; @@ -47,6 +48,15 @@ static inline void gotoxy(int new_x,unsigned int new_y) { pos = origin + y*video_size_row + (x << 1); } +static inline void set_origin() { + cli(); + outb_p(12, video_port_reg); + outb_p(0xff & ((origin - video_mem_base) >> 9), video_port_val); + outb_p(13, video_port_reg); + outb_p(0xff & ((origin - video_mem_base) >> 1), video_port_val); + sti(); +} + static inline void set_cursor() { cli(); outb_p(14, video_port_reg); @@ -56,6 +66,43 @@ static inline void set_cursor() { sti(); } +static void scrup() { + if (video_type == VIDEO_TYPE_EGAC || video_type == VIDEO_TYPE_EGAM) { + if (!top && bottom == video_num_lines) { + origin += video_size_row; + pos += video_size_row; + scr_end += video_size_row; + + if (scr_end > video_mem_term) { + + } + + } + } +} + +static void lf() { + if (y + 1 < bottom) { + y++; + pos += video_size_row; + return; + } + scrup(); +} + +static void cr() { + pos -= x << 1; + x = 0; +} + +static void del() { + if (x) { + pos -= 2; + x--; + *(unsigned short*)pos = video_erase_char; + } +} + void con_init() { char * display_desc = "????"; char * display_ptr; @@ -64,6 +111,7 @@ void con_init() { video_size_row = video_num_columns * 2; video_num_lines = ORIG_VIDEO_LINES; video_page = ORIG_VIDEO_PAGE; + video_erase_char = 0x0720; /* Is this a monochrome display? */ if (ORIG_VIDEO_MODE == 7) { @@ -114,17 +162,38 @@ void con_init() { } void con_write(const char* buf, int nr) { - char* t = (char*)pos; char* s = buf; int i = 0; - for (i = 0; i < nr; i++) { - *t++ = *(s++); - *t++ = 0xf; - x++; + while(nr--) { + char c = *s++; + if (c > 31 && c < 127) { + if (x >= video_num_columns) { + x -= video_num_columns; + pos -= video_size_row; + lf(); + } + + *(char *)pos = c; + *(((char*)pos) + 1) = attr; + pos += 2; + x++; + } + else if (c == 10 || c == 11 || c == 12) + lf(); + else if (c == 13) + cr(); + else if (c == 127) { + del(); + } + else if (c == 8) { + if (x) { + x--; + pos -= 2; + } + } } - pos = t; gotoxy(x, y); set_cursor(); } diff --git a/kernel/main.c b/kernel/main.c index c563dcc8308f98594ebaecb114ba9df33d386676..6caab5f07ddfb2867a1a023dfc41d03462795da3 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -40,7 +40,7 @@ void main(void) sched_init(); tty_init(); - printk("memory start: %d, end: %d\n\r" , main_memory_start, memory_end); + printk("%d %d\n\r", 12, 34); __asm__ __volatile__( "int $0x80\n\r"