better api (ioctl decoupled)

This commit is contained in:
catfood 2023-01-08 11:40:07 +08:00
parent bb51f9775a
commit 000c2a4b7c
4 changed files with 57 additions and 17 deletions

View File

@ -37,8 +37,8 @@ extern irq_handler irq_table[];
#include "console.h"
// extern TTY tty_table[];
extern CONSOLE console_table[];
extern int current_console;
// extern CONSOLE console_table[];
// extern int current_console;
// u32 PageTblNum; //页表数量 add by visual 2016.4.5
extern u32 cr3_ready; //当前进程的页目录 add by visual 2016.4.5

View File

@ -128,4 +128,13 @@ void ps2_tty_recvbuf(NTTY *tty, u32 key);
// 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_ */

View File

@ -438,12 +438,12 @@ void ps2_tty_recvbuf(NTTY *tty, u32 key)
if (key & MOUSESCR_UP)
{
// kprintf("scroll up\n");
vga_tty_scroll(tty, MOUSESCR_UP);
tty->ioctl(tty, 1, TTY_SCROLL_UP);
}
else
{
// kprintf("scroll down\n");
vga_tty_scroll(tty, MOUSESCR_DOWN);
tty->ioctl(tty, 1, TTY_SCROLL_DOWN);
}
}
else if (key & MOUSEBTN)
@ -451,7 +451,7 @@ void ps2_tty_recvbuf(NTTY *tty, u32 key)
if ((key & MOUSEBTN_CLICK) && (key & MOUSEBTN_M))
{
// kprintf("middle btn click %x\n", key);
vga_tty_scroll(tty, 3);
tty->ioctl(tty, 1, TTY_SCROLL_TOCUR);
}
}
}
@ -466,8 +466,7 @@ void ps2_tty_recvbuf(NTTY *tty, u32 key)
if (conno < NR_CONSOLES)
{
// kprintf("select console %d\n", conno);
if (get_tty(conno)->driver_type == 1)
vga_tty_select(get_tty(conno));
tty->ioctl(tty, 2, conno);
}
break;
}
@ -514,7 +513,7 @@ void ps2_tty_recvbuf(NTTY *tty, u32 key)
// kprintf("len=%d, h=%d, t=%d, rd=%d\n", kbd->len, kbd->head, kbd->tail, kbd->readable);
break;
}
vga_tty_flush(tty);
tty->ioctl(tty, IOCTL_CMD_TTY_FLUSH, 0);
}
enable_int();
}

View File

@ -14,7 +14,6 @@
#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);
@ -27,9 +26,33 @@ static void write_default_tty(char ch) {
}
inline NTTY* get_tty(const int nr_tty) {
if (nr_tty >= NR_CONSOLES || nr_tty < 0) return NULL;
return ntty_table[nr_tty];
}
static int ps2_vga_ioctl(NTTY* tty, u32 cmd, long arg)
{
int retval = 0;
switch (cmd)
{
case IOCTL_CMD_TTY_SCROLL:
vga_tty_scroll(tty, arg);
break;
case IOCTL_CMD_TTY_SELECTCON:
if (get_tty(arg) == NULL || get_tty(arg)->driver_type != 1) retval = -1;
else vga_tty_select(get_tty(arg));
break;
case IOCTL_CMD_TTY_FLUSH:
if (tty == cur_ntty) vga_tty_flush(tty);
break;
default:
break;
}
return retval;
}
static int dummy_ioctl(NTTY* tty, u32 cmd, long arg) {return 0;}
void init_tty_main()
{
NTTY *tty;
@ -47,6 +70,7 @@ void init_tty_main()
tty->write = vga_tty_write;
tty->read = ps2_tty_read;
tty->recvbuf = ps2_tty_recvbuf;
tty->ioctl = ps2_vga_ioctl;
ntty_table[i] = tty;
}
for (int i = 2; i < 3; ++ i) {
@ -59,6 +83,7 @@ void init_tty_main()
tty->write = serial_tty_write;
tty->read = serial_tty_read;
tty->recvbuf = serial_tty_recvbuf;
tty->ioctl = dummy_ioctl;
ntty_table[2] = tty;
}
cur_ntty = ntty_table[0];
@ -100,18 +125,25 @@ void tty_write(NTTY *tty, char *buf, int len)
// while (--len >= 0) write_serial(*buf++);
return;
}
else if (tty->driver_type == 1) {
else {
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->write(tty, *buf++);
}
tty->ioctl(tty, IOCTL_CMD_TTY_FLUSH, 0);
}
// 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++);
// }
// }
}
/*****************************************************************************