#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" int current_console; // 当前显示在屏幕上的console 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); #ifdef DEBUGNEW NTTY* cur_ntty; NTTY* ntty_table[NR_CONSOLES]; // int cur_ntty = 0; static keyboard_buf keyboardbuf[NR_CONSOLES]; static vga_buf vgabuf[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 < 3; ++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 = &keyboardbuf[i]; tty->output_buf = &vgabuf[i]; vga_tty_init(tty); ps2_tty_init(tty); ntty_table[i] = tty; // kprintf("tty: %p, outbuf: %p\n", tty, tty->output_buf); } cur_ntty = ntty_table[0]; } #endif #ifndef DEBUGNEW void in_process(TTY *p_tty, u32 key) { int real_line = p_tty->console->orig / SCR_WIDTH; if (!(key & FLAG_EXT)) { put_key(p_tty, key); } else { int raw_code = key & MASK_RAW; switch (raw_code) { case ENTER: put_key(p_tty, '\n'); p_tty->status = p_tty->status & 3; //&3'b011 break; case BACKSPACE: put_key(p_tty, '\b'); break; case UP: if (p_tty->console->current_line < 43) { disable_int(); p_tty->console->current_line++; outb(CRTC_ADDR_REG, START_ADDR_H); outb(CRTC_DATA_REG, ((80 * (p_tty->console->current_line + real_line)) >> 8) & 0xFF); outb(CRTC_ADDR_REG, START_ADDR_L); outb(CRTC_DATA_REG, (80 * (p_tty->console->current_line + real_line)) & 0xFF); enable_int(); } break; case DOWN: if (p_tty->console->current_line > 0) { disable_int(); p_tty->console->current_line--; outb(CRTC_ADDR_REG, START_ADDR_H); outb(CRTC_DATA_REG, ((80 * (p_tty->console->current_line + real_line)) >> 8) & 0xFF); outb(CRTC_ADDR_REG, START_ADDR_L); outb(CRTC_DATA_REG, (80 * (p_tty->console->current_line + real_line)) & 0xFF); enable_int(); } break; case F1: case F2: case F3: case F4: case F5: case F6: case F7: case F8: case F9: case F10: case F11: case F12: select_console(raw_code - F1); break; } } } #endif void task_tty() { // NTTY* p_tty; // for (p_tty = ntty_table; p_tty < ntty_table + 3; ++ p_tty) { // init_ntty(p_tty); // } while (1) { // sys_yield(); // vga_tty_flush(cur_ntty); } } /***************************************************************************** * tty_write **************************************************************************** * 当fd=STD_OUT时,write()系统调用转发到此函数 *****************************************************************************/ void tty_write(NTTY *tty, char *buf, int len) { while (--len >= 0) { vga_tty_write(tty, *buf++); } if (cur_ntty == tty) vga_tty_flush(tty); } /***************************************************************************** * tty_read **************************************************************************** * 当fd=STD_IN时,read()系统调用转发到此函数 *****************************************************************************/ int tty_read(NTTY *tty, char *buf, int len) { return ps2_tty_read(tty, buf, len); }