#include "type.h" #include "const.h" #include "protect.h" #include "string.h" #include "proc.h" #include "tty.h" #include "console.h" #include "global.h" #include "proto.h" #include "keyboard.h" #include "x86.h" #include "memman.h" #include "stdio.h" #include "serialport.h" int current_console; // 当前显示在屏幕上的console int tty_ok = 0; void tty_write(NTTY *tty, char *buf, int len); int tty_read(NTTY *tty, char *buf, int len); static void tty_mouse(TTY *tty); static void tty_dev_read(TTY *tty); static void tty_dev_write(TTY *tty); static void put_key(TTY *tty, u32 key); NTTY *cur_ntty; NTTY *ntty_table[NR_CONSOLES]; inline NTTY *get_tty(const int nr_tty) { return ntty_table[nr_tty]; } void init_tty_main() { NTTY *tty; for (int i = 0; i < 2; ++i) { // tty = &ntty_table[i]; tty = (NTTY *)K_PHY2LIN(do_kmalloc(sizeof(NTTY))); tty->driver_type = 1; // vga // tty->input_buf = (void*)do_kmalloc(sizeof(keyboard_buf)); // tty->output_buf = (void*)do_kmalloc(sizeof(vga_buf)); tty->input_buf = (keyboard_buf *)K_PHY2LIN(do_kmalloc(sizeof(keyboard_buf))); tty->output_buf = (vga_buf *)K_PHY2LIN(do_kmalloc(sizeof(vga_buf))); vga_tty_init(tty); ps2_tty_init(tty); ntty_table[i] = tty; // kprintf("tty: %p, outbuf: %p\n", tty, tty->output_buf); } tty = (NTTY *)K_PHY2LIN(do_kmalloc(sizeof(NTTY))); tty->driver_type = 2; tty->input_buf = (serial_buf *)K_PHY2LIN(do_kmalloc(sizeof(serial_buf))); // kprintf("tty: %p, outbuf: %p\n", tty, tty->input_buf); tty->output_buf = NULL; serial_tty_init_i(tty); serial_tty_init_o(tty); ntty_table[2] = tty; cur_ntty = ntty_table[0]; tty_ok = 1; kprintf("TTY initialized\n"); } void task_tty() { // NTTY* p_tty; // for (p_tty = ntty_table; p_tty < ntty_table + 3; ++ p_tty) { // init_ntty(p_tty); // } volatile char serial_input; while (1) { // sys_yield(); // vga_tty_flush(cur_ntty); // serial_input = read_serial(); // vga_tty_write(get_tty(2), serial_input); // kprintf("%c", serial_input); } } /***************************************************************************** * tty_write **************************************************************************** * 当fd=STD_OUT时,write()系统调用转发到此函数 *****************************************************************************/ void tty_write(NTTY *tty, char *buf, int len) { if (!tty_ok) { while (--len >= 0) { write_serial(*buf++); } return; } else if (tty->driver_type == 1) { while (--len >= 0) { vga_tty_write(tty, *buf++); } if (cur_ntty == tty) vga_tty_flush(tty); } else if (tty->driver_type == 2) { while (--len >= 0) { serial_tty_write(tty, *buf++); } } } /***************************************************************************** * tty_read **************************************************************************** * 当fd=STD_IN时,read()系统调用转发到此函数 *****************************************************************************/ int tty_read(NTTY *tty, char *buf, int len) { return ps2_tty_read(tty, buf, len); }