99 lines
2.5 KiB
C
99 lines
2.5 KiB
C
/*************************************************************************//**
|
|
*****************************************************************************
|
|
* @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;
|
|
|
|
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
|
|
} vga_buf;
|
|
|
|
typedef struct keyboard_buf {
|
|
void* buf; // 1d array, buffer input virtual line, works as a ldisc
|
|
int max_buf;
|
|
int tail;
|
|
} 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);
|
|
|
|
#endif /* _ORANGES_TTY_H_ */ |