/*************************************************************************/ /** ***************************************************************************** * @file tty.h * @brief * @author Forrest Y. Yu * @date 2005 ***************************************************************************** *****************************************************************************/ /********************************************************** * tty.h //added by mingxuan 2019-5-17 ***********************************************************/ #ifndef _ORANGES_TTY_H_ #define _ORANGES_TTY_H_ #define TTY_IN_BYTES 256 /* tty input queue size */ #define TTY_OUT_BUF_LEN 2 /* tty output buffer size */ /* TTY state (3bit) wait_enter wait_space display 1/0 1/0 1/0 */ #define TTY_STATE_WAIT_ENTER 4 /*100*/ #define TTY_STATE_WAIT_SPACE 2 /*010*/ #define TTY_STATE_DISPLAY 1 /*001*/ struct s_tty; struct s_console; /* TTY */ typedef struct s_tty { u32 ibuf[TTY_IN_BYTES]; /* TTY input buffer */ u32 *ibuf_head; /* the next free slot */ u32 *ibuf_tail; /* 缓冲区显示位置指针 */ u32 *ibuf_read; int ibuf_cnt; /* how many */ int ibuf_read_cnt; int status; int mouse_left_button; int mouse_mid_button; int mouse_X; int mouse_Y; struct s_console *console; } TTY; typedef struct MouseState { u8 mouse_lb; u8 mouse_mb; u8 mouse_rb; signed char mouse_scroll; int mouse_x; int mouse_y; } MouseState; typedef struct n_tty { int driver_type; // 1-vga&kbd; 2-serial MouseState mouse; void *input_buf; void *output_buf; } NTTY; enum CSI_state { CSI_ESC, CSI_BRACKET, CSI_PARAM1, CSI_PARAM2 }; typedef struct vga_buf { void *buf; // 2d array, screen size, for text mode it's [maxline][80] int max_line; // to support scroll, max line should be a lot more than screen int scr_top_line; // the index in buf of top line on screen; int scr_cur_line; // the index in buf of the cursor's line int head_line; // for circular buffer use int cur_row; int cur_col; // cursor position, on screen enum CSI_state CSI; i16 param1; // the first param of CSI i16 param2; // the second of CSI u16 color; } vga_buf; typedef struct keyboard_buf { void* buf; // 1d array, buffer input virtual line, works as a ldisc int tail; int head; int len; int readable; } keyboard_buf; #include "console.h" void select_console(int nr_console); void init_screen(TTY *tty); void out_char(CONSOLE *con, char ch); int is_current_console(CONSOLE *con); int init_serial(); char read_serial(); void write_serial(char a); void vga_tty_init(NTTY* tty); void vga_tty_write(NTTY* tty, char ch); void vga_tty_flush(NTTY* tty); void vga_tty_backspace(NTTY* tty); void ps2_tty_init(NTTY* tty); int ps2_tty_read(NTTY* tty, u8* buf, int nr); #define CYCLE_SUB(head, tail, _max) ((head) < (tail) ? (tail)-(head) : (tail) + (_max) - (head)) #define NEXT(x, _max) (((x) + 1) % (_max)) #define LAST(x, _max) (((x) - 1) >= 0 ? ((x) - 1) % (_max) : (_max) - 1) #define DEBUGNEW #define FOREGROUND(color) ((u16)(color & 0xf) << 8) #define BACKGROUND(color) ((u16)(color & 0xf) << 12) extern int cur_ntty; extern NTTY ntty_table[3]; #endif /* _ORANGES_TTY_H_ */