add CSI JKST
This commit is contained in:
parent
4bd7c1e46d
commit
618be86f31
@ -58,9 +58,11 @@ static void untar(const char * filename)
|
||||
int chunk = sizeof(buf);
|
||||
int i = 0;
|
||||
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
do_vread(fd, buf, 512); // modified by mingxuan 2019-5-21
|
||||
if (buf[0] == 0) {
|
||||
if (buf[0] == 0)
|
||||
{
|
||||
if (i == 0)
|
||||
printf(" need not unpack the file.\n");
|
||||
break;
|
||||
@ -79,14 +81,16 @@ static void untar(const char * filename)
|
||||
char full_name[30] = "orange/";
|
||||
strcat(full_name, phdr->name);
|
||||
int fdout = do_vopen(full_name, O_CREAT | O_RDWR); // modified by mingxuan 2019-5-20
|
||||
if (fdout == -1) {
|
||||
if (fdout == -1)
|
||||
{
|
||||
printf(" failed to extract file: %s\n", phdr->name);
|
||||
printf(" aborted]\n");
|
||||
do_vclose(fd); // modified by mingxuan 2019-5-20
|
||||
return;
|
||||
}
|
||||
printf(" %s \n", phdr->name); // deleted by mingxuan 2019-5-22
|
||||
while (bytes_left) {
|
||||
while (bytes_left)
|
||||
{
|
||||
int iobytes = min(chunk, bytes_left);
|
||||
|
||||
do_vread(fd, buf, ((iobytes - 1) / 512 + 1) * 512); // modified by mingxuan 2019-5-21
|
||||
@ -97,7 +101,8 @@ static void untar(const char * filename)
|
||||
do_vclose(fdout); // modified by mingxuan 2019-5-20
|
||||
}
|
||||
|
||||
if (i) {
|
||||
if (i)
|
||||
{
|
||||
do_vlseek(fd, 0, SEEK_SET); // modified by mingxuan 2019-5-20
|
||||
buf[0] = 0;
|
||||
do_vwrite(fd, buf, 1); // modified by mingxuan 2019-5-20
|
||||
@ -108,7 +113,6 @@ static void untar(const char * filename)
|
||||
printf(" done, %d files extracted]\n", i);
|
||||
}
|
||||
|
||||
|
||||
void initial()
|
||||
{
|
||||
|
||||
@ -118,7 +122,8 @@ void initial()
|
||||
|
||||
// untar(INSTALL_FILENAME);
|
||||
// modified by mingxuan 2019-5-21
|
||||
char full_name[30]="orange/";;
|
||||
char full_name[30] = "orange/";
|
||||
;
|
||||
printf("untar:%s\n", full_name);
|
||||
strcat(full_name, INSTALL_FILENAME);
|
||||
untar(full_name);
|
||||
@ -127,7 +132,9 @@ void initial()
|
||||
do_vclose(stdout);
|
||||
do_vclose(stderr);
|
||||
|
||||
exec("orange/shell_0.bin");
|
||||
// exec("orange/shell_0.bin");
|
||||
exec("orange/test.bin");
|
||||
|
||||
while(1);
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
197
kernel/vga.c
197
kernel/vga.c
@ -121,7 +121,8 @@ static inline void vga_flush_blankline(int line_no)
|
||||
*****************************************************************************/
|
||||
static u16 pagebuf[3][SCR_BUFSIZE];
|
||||
|
||||
void vga_tty_init(NTTY* tty) {
|
||||
void vga_tty_init(NTTY *tty)
|
||||
{
|
||||
static int _cnt = 0;
|
||||
assert(tty->driver_type == 1);
|
||||
assert(tty->output_buf);
|
||||
@ -144,6 +145,37 @@ void vga_tty_init(NTTY* tty) {
|
||||
#define INDEX(row, col) ((row)*SCR_WIDTH + (col))
|
||||
#define NEXTLINE(row) (((row) + 1) % SCR_MAXLINE)
|
||||
#define LASTLINE(row) (((row)-1) >= 0 ? ((row)-1) % SCR_MAXLINE : SCR_MAXLINE)
|
||||
#define ADDLINE(row, add_num) (((row) + add_num) % SCR_MAXLINE)
|
||||
|
||||
// called by csi
|
||||
void vga_tty_scroll(vga_buf *vgabuf, i16 scroll_num)
|
||||
{
|
||||
u16 *buf = vgabuf->buf;
|
||||
while (scroll_num > 0)
|
||||
{
|
||||
// down
|
||||
scroll_num--;
|
||||
if (vgabuf->scr_top_line == vgabuf->scr_cur_line)
|
||||
return;
|
||||
vgabuf->scr_top_line = NEXTLINE(vgabuf->scr_top_line);
|
||||
}
|
||||
while (scroll_num < 0)
|
||||
{
|
||||
scroll_num++;
|
||||
if (vgabuf->scr_top_line == vgabuf->head_line)
|
||||
return;
|
||||
vgabuf->scr_top_line = LASTLINE(vgabuf->scr_top_line);
|
||||
}
|
||||
vgabuf->cur_row = abs(vgabuf->scr_cur_line - vgabuf->scr_top_line);
|
||||
if (vgabuf->cur_row >= SCR_HEIGHT)
|
||||
{
|
||||
vga_disable_cursor();
|
||||
}
|
||||
else
|
||||
{
|
||||
vga_enable_cursor(0, 15);
|
||||
}
|
||||
}
|
||||
|
||||
static void newline(vga_buf *vgabuf)
|
||||
{
|
||||
@ -180,12 +212,40 @@ static void nextcol(vga_buf *vgabuf)
|
||||
|
||||
static void cursor_move(i16 move_row, i16 move_col, vga_buf *vgabuf)
|
||||
{
|
||||
vgabuf->scr_cur_line += move_row;
|
||||
if (vgabuf->scr_cur_line < 0)
|
||||
vgabuf->scr_cur_line = 0;
|
||||
else if (vgabuf->scr_cur_line >= SCR_MAXLINE)
|
||||
vgabuf->scr_cur_line = SCR_MAXLINE - 1;
|
||||
|
||||
while (move_row > 0) // down
|
||||
{
|
||||
move_col--;
|
||||
vgabuf->scr_cur_line = NEXTLINE(vgabuf->scr_cur_line);
|
||||
vgabuf->cur_row = abs(vgabuf->scr_cur_line - vgabuf->scr_top_line);
|
||||
if (vgabuf->cur_row == SCR_HEIGHT)
|
||||
{
|
||||
// auto scroll
|
||||
vgabuf->scr_top_line = NEXTLINE(vgabuf->scr_top_line);
|
||||
if (vgabuf->scr_cur_line == vgabuf->head_line)
|
||||
{
|
||||
vgabuf->head_line = NEXTLINE(vgabuf->head_line);
|
||||
// remember to fill blank the old line
|
||||
u32 *ptr_buf = (u32 *)(vgabuf->buf + sizeof(u16) * vgabuf->head_line * SCR_WIDTH);
|
||||
for (int i = 0; i < SCR_WIDTH * sizeof(u16) / sizeof(u32); ++i)
|
||||
{
|
||||
*ptr_buf++ = (BLANK << 16) | BLANK; // bg-black, fg-white, ascii-space
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (move_row < 0) // up
|
||||
{
|
||||
move_col++;
|
||||
// vgabuf->scr_cur_line = LASTLINE(vgabuf->scr_cur_line);
|
||||
if (vgabuf->scr_cur_line == vgabuf->scr_top_line)
|
||||
{
|
||||
if (vgabuf->scr_top_line == vgabuf->head_line)
|
||||
break;
|
||||
vgabuf->scr_cur_line = LASTLINE(vgabuf->scr_cur_line);
|
||||
vgabuf->scr_top_line = LASTLINE(vgabuf->scr_top_line);
|
||||
}
|
||||
}
|
||||
vgabuf->cur_row = CYCLE_SUB(vgabuf->scr_top_line, vgabuf->scr_cur_line, SCR_MAXLINE);
|
||||
vgabuf->cur_col += move_col;
|
||||
if (vgabuf->cur_col < 0)
|
||||
vgabuf->cur_col = 0;
|
||||
@ -203,6 +263,25 @@ param12vga_color(i16 *param)
|
||||
*param |= tmp << 2;
|
||||
}
|
||||
|
||||
static void clear_screen(vga_buf *vgabuf, i16 src_row, i16 src_col, i16 dst_row, i16 dst_col)
|
||||
{
|
||||
u16 *buf = vgabuf->buf;
|
||||
int src_index = INDEX(src_row, src_col);
|
||||
int dst_index = INDEX(dst_row, dst_col);
|
||||
if (src_index <= dst_index)
|
||||
for (int i = src_index; i <= dst_index; i++)
|
||||
{
|
||||
buf[i] = BLANK;
|
||||
}
|
||||
else // scr>dst
|
||||
{
|
||||
for (int i = 0; i <= dst_index; i++)
|
||||
buf[i] = BLANK;
|
||||
int index_end = INDEX(SCR_MAXLINE - 1, SCR_WIDTH - 1);
|
||||
for (int i = 0; i <= index_end; i++)
|
||||
buf[i] = BLANK;
|
||||
}
|
||||
}
|
||||
static void set_color(vga_buf *vgabuf)
|
||||
{
|
||||
if (vgabuf->param1 == 0)
|
||||
@ -334,12 +413,41 @@ static void CSI_handler(u8 terminator, vga_buf *vgabuf)
|
||||
cursor_move(vgabuf->param1 - vgabuf->scr_cur_line, vgabuf->param1 - vgabuf->cur_col, vgabuf);
|
||||
break;
|
||||
case 'J':
|
||||
if (vgabuf->param1 == 0)
|
||||
clear_screen(vgabuf, vgabuf->scr_cur_line, vgabuf->cur_col, ADDLINE(vgabuf->scr_top_line, SCR_HEIGHT - 1), SCR_WIDTH - 1);
|
||||
else if (vgabuf->param1 == 1)
|
||||
clear_screen(vgabuf, vgabuf->scr_top_line, 0, vgabuf->scr_cur_line, vgabuf->cur_col);
|
||||
else if (vgabuf->param1 == 2)
|
||||
{
|
||||
clear_screen(vgabuf, vgabuf->scr_top_line, 0, ADDLINE(vgabuf->scr_top_line, SCR_HEIGHT - 1), SCR_WIDTH - 1);
|
||||
vgabuf->cur_col = 0;
|
||||
vgabuf->scr_cur_line = vgabuf->scr_top_line;
|
||||
}
|
||||
else if (vgabuf->param1 == 3)
|
||||
{
|
||||
clear_screen(vgabuf, 0, 0, SCR_MAXLINE - 1, SCR_WIDTH - 1);
|
||||
vgabuf->cur_col = vgabuf->cur_row = 0;
|
||||
vgabuf->scr_top_line = vgabuf->scr_cur_line = 0;
|
||||
vgabuf->head_line = 0;
|
||||
}
|
||||
break;
|
||||
case 'K':
|
||||
if (vgabuf->param1 == 0)
|
||||
clear_screen(vgabuf, vgabuf->scr_cur_line, vgabuf->cur_col, vgabuf->scr_cur_line, SCR_WIDTH - 1);
|
||||
else if (vgabuf->param1 == 1)
|
||||
clear_screen(vgabuf, vgabuf->scr_cur_line, 0, vgabuf->scr_cur_line, vgabuf->cur_col);
|
||||
else if (vgabuf->param1 == 2)
|
||||
clear_screen(vgabuf, vgabuf->scr_cur_line, 0, vgabuf->scr_cur_line, SCR_WIDTH - 1);
|
||||
break;
|
||||
case 'S':
|
||||
case 'S': // Scroll Up
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 = 1;
|
||||
vga_tty_scroll(vgabuf, -vgabuf->param1);
|
||||
break;
|
||||
case 'T':
|
||||
case 'T': // Scroll Down
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 = 1;
|
||||
vga_tty_scroll(vgabuf, +vgabuf->param1);
|
||||
break;
|
||||
case 'm':
|
||||
set_color(vgabuf);
|
||||
@ -446,25 +554,30 @@ void vga_tty_write(NTTY *tty, char ch)
|
||||
// kprintf("row: %d; ", vga->cur_row);
|
||||
}
|
||||
|
||||
void vga_tty_backspace(NTTY* tty) {
|
||||
void vga_tty_backspace(NTTY *tty)
|
||||
{
|
||||
vga_buf *vga = tty->output_buf;
|
||||
u16 *buf = vga->buf;
|
||||
if (vga->cur_col == 0) {
|
||||
if (vga->cur_col == 0)
|
||||
{
|
||||
vga->cur_col = SCR_WIDTH - 1;
|
||||
vga->scr_cur_line = LASTLINE(vga->scr_cur_line);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
vga->cur_col--;
|
||||
}
|
||||
buf[INDEX(vga->scr_cur_line, vga->cur_col)] = BLANK;
|
||||
vga->cur_row = CYCLE_SUB(vga->scr_top_line, vga->scr_cur_line, SCR_MAXLINE);
|
||||
}
|
||||
|
||||
void vga_tty_flush(NTTY* tty) {
|
||||
void vga_tty_flush(NTTY *tty)
|
||||
{
|
||||
vga_buf *vga = tty->output_buf;
|
||||
u16 *buf = vga->buf;
|
||||
int i, cur_line;
|
||||
vga_set_cursor(INDEX(vga->cur_row, vga->cur_col));
|
||||
if (vga->cur_row == SCR_WIDTH - 1)
|
||||
if (vga->cur_row == SCR_HEIGHT - 1) ///////////????????????????
|
||||
{
|
||||
vga_flush_screen(&buf[INDEX(vga->scr_top_line, 0)]);
|
||||
}
|
||||
@ -476,7 +589,7 @@ void vga_tty_flush(NTTY* tty) {
|
||||
vga_flush_line(&buf[INDEX(cur_line, 0)], i);
|
||||
cur_line = NEXTLINE(cur_line);
|
||||
}
|
||||
for (; i < SCR_WIDTH; ++i)
|
||||
for (; i < SCR_HEIGHT; ++i)
|
||||
{
|
||||
vga_flush_blankline(i);
|
||||
}
|
||||
@ -484,33 +597,33 @@ void vga_tty_flush(NTTY* tty) {
|
||||
// kprintf("flush: row=%d, top=%d, cur=%d\n", vga->cur_row, vga->scr_top_line, vga->scr_cur_line);
|
||||
}
|
||||
|
||||
void vga_tty_scroll(NTTY *tty, int direction)
|
||||
{
|
||||
vga_buf *vga = tty->output_buf;
|
||||
u16 *buf = vga->buf;
|
||||
if (direction > 0)
|
||||
{
|
||||
// down
|
||||
if (vga->scr_top_line == vga->scr_cur_line)
|
||||
return;
|
||||
vga->scr_top_line = NEXTLINE(vga->scr_top_line);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vga->scr_top_line == vga->head_line)
|
||||
return;
|
||||
vga->scr_top_line = LASTLINE(vga->scr_top_line);
|
||||
}
|
||||
vga->cur_row = abs(vga->scr_cur_line - vga->scr_top_line);
|
||||
if (vga->cur_row >= SCR_HEIGHT)
|
||||
{
|
||||
vga_disable_cursor();
|
||||
}
|
||||
else
|
||||
{
|
||||
vga_enable_cursor(0, 15);
|
||||
}
|
||||
}
|
||||
// void vga_tty_scroll(NTTY *tty, int direction)
|
||||
// {
|
||||
// vga_buf *vga = tty->output_buf;
|
||||
// u16 *buf = vga->buf;
|
||||
// if (direction > 0)
|
||||
// {
|
||||
// // down
|
||||
// if (vga->scr_top_line == vga->scr_cur_line)
|
||||
// return;
|
||||
// vga->scr_top_line = NEXTLINE(vga->scr_top_line);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (vga->scr_top_line == vga->head_line)
|
||||
// return;
|
||||
// vga->scr_top_line = LASTLINE(vga->scr_top_line);
|
||||
// }
|
||||
// vga->cur_row = abs(vga->scr_cur_line - vga->scr_top_line);
|
||||
// if (vga->cur_row >= SCR_HEIGHT)
|
||||
// {
|
||||
// vga_disable_cursor();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// vga_enable_cursor(0, 15);
|
||||
// }
|
||||
// }
|
||||
|
||||
void vga_scroll_to_cur(NTTY *tty)
|
||||
{
|
||||
|
||||
@ -30,8 +30,9 @@ int main(int arg, char *argv[])
|
||||
printf("5555555555");
|
||||
printf("6666666666");
|
||||
printf("7777777777");
|
||||
printf("8888888888");
|
||||
printf("9999999999\r\b\b\n");
|
||||
printf("\x1b[5F");
|
||||
// printf("8888888888");
|
||||
// printf("9999999999\r\b\b\n");
|
||||
}
|
||||
|
||||
while (1)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user