BigOS/include/tty.h
2023-01-13 20:24:21 +08:00

122 lines
3.3 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_
#include "type.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*/
typedef struct n_tty
{
int driver_type; // 1-vga&kbd; 2-serial
void *input_buf;
void *output_buf;
void (*write)(struct n_tty *tty, char ch);
int (*read)(struct n_tty *tty, char* buf, int nr);
void (*recvbuf)(struct n_tty *tty, u32 ch);
int (*ioctl)(struct n_tty *tty, u32 cmd, long arg);
} 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 scr_bot_line; // the index in buf of the most-bottom printed line
int head_line; // for circular buffer use
int cur_row;
int cur_col; // cursor position, on screen
bool Is2param;
bool IsColorReverse;
bool IsHide;
enum CSI_state CSI;
i16 param1; // the first param of CSI
i16 param2; // the second of CSI
u16 color;
u16 last_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;
typedef struct serial_buf
{
void *buf;
int tail;
int head;
int len;
int readable;
} serial_buf;
#include "console.h"
NTTY *get_tty(const int nr_tty);
void vga_tty_init(NTTY *tty);
void vga_tty_write(NTTY *tty, char ch);
void vga_tty_flush(NTTY *tty);
void vga_tty_scroll(NTTY *tty, int direction);
void vga_tty_select(NTTY *tty);
void ps2_tty_init(NTTY *tty);
int ps2_tty_read(NTTY *tty, char *buf, int nr);
void ps2_tty_recvbuf(NTTY *tty, u32 key);
#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 FOREGROUND(color) ((u16)(color & 0xf) << 8)
#define BACKGROUND(color) ((u16)(color & 0xf) << 12)
// extern int cur_ntty;
extern NTTY *cur_ntty;
// extern NTTY ntty_table[3];
#define IOCTL_CMD_TTY_SCROLL 1
#define IOCTL_CMD_TTY_SELECTCON 2
#define IOCTL_CMD_TTY_FLUSH 3
#define TTY_SCROLL_UP 1
#define TTY_SCROLL_DOWN 2
#define TTY_SCROLL_TOCUR 3
#endif /* _ORANGES_TTY_H_ */