add csi_hide and csi_reverse
This commit is contained in:
parent
a389dcf93a
commit
ceeb34cf78
BIN
hd/test.vmdk
Normal file
BIN
hd/test.vmdk
Normal file
Binary file not shown.
@ -34,6 +34,7 @@ typedef struct s_console
|
||||
#define SCR_BUFSIZE (2 * SCR_SIZE)
|
||||
#define SCR_MAXLINE (SCR_BUFSIZE / SCR_WIDTH)
|
||||
|
||||
#define FLASH_CHAR 0x8000
|
||||
#define DEFAULT_CHAR_COLOR ((MAKE_COLOR(BLACK, WHITE | BRIGHT)) << 8)
|
||||
#define GRAY_CHAR (MAKE_COLOR(BLACK, BLACK) | BRIGHT)
|
||||
#define RED_CHAR (MAKE_COLOR(BLUE, RED) | BRIGHT)
|
||||
|
||||
@ -166,14 +166,16 @@
|
||||
|
||||
/* VGA */
|
||||
// added by mingxuan 2019-5-19
|
||||
#define CRTC_ADDR_REG 0x3D4 /* CRT Controller Registers - Addr Register */
|
||||
#define CRTC_DATA_REG 0x3D5 /* CRT Controller Registers - Data Register */
|
||||
#define START_ADDR_H 0xC /* reg index of video mem start addr (MSB) */
|
||||
#define START_ADDR_L 0xD /* reg index of video mem start addr (LSB) */
|
||||
#define CURSOR_H 0xE /* reg index of cursor position (MSB) */
|
||||
#define CURSOR_L 0xF /* reg index of cursor position (LSB) */
|
||||
#define V_MEM_BASE 0xB8000 /* base of color video memory */
|
||||
#define V_MEM_SIZE 0x8000 /* 32K: B8000H -> BFFFFH */
|
||||
#define CRTC_ADDR_REG 0x3D4 /* CRT Controller Registers - Addr Register */
|
||||
#define CRTC_DATA_REG 0x3D5 /* CRT Controller Registers - Data Register */
|
||||
#define START_ADDR_H 0xC /* reg index of video mem start addr (MSB) */
|
||||
#define START_ADDR_L 0xD /* reg index of video mem start addr (LSB) */
|
||||
#define CURSOR_H 0xE /* reg index of cursor position (MSB) */
|
||||
#define CURSOR_L 0xF /* reg index of cursor position (LSB) */
|
||||
#define UNDERLINE_REG 0x14 /* reg index of underline */
|
||||
#define ModeControl_Reg 0x10 /* reg index of Attribute Mode Control Register */
|
||||
#define V_MEM_BASE 0xB8000 /* base of color video memory */
|
||||
#define V_MEM_SIZE 0x8000 /* 32K: B8000H -> BFFFFH */
|
||||
|
||||
#define STD_IN 0
|
||||
#define STD_OUT 1
|
||||
|
||||
21
include/csi.h
Normal file
21
include/csi.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef FS_H
|
||||
#define FS_H
|
||||
|
||||
void enable_blink();
|
||||
void disable_blink();
|
||||
|
||||
void set_underline(u32 addr);
|
||||
void enable_blink();
|
||||
|
||||
void csi_scroll(vga_buf *vgabuf, i16 scroll_num);
|
||||
void cursor_locate(i16 row, i16 col, vga_buf *vgabuf);
|
||||
|
||||
void cursor_move(i16 move_row, i16 move_col, vga_buf *vgabuf);
|
||||
void clear_screen(vga_buf *vgabuf, i16 src_row, i16 src_col, i16 dst_row, i16 dst_col);
|
||||
|
||||
void set_color(vga_buf *vgabuf);
|
||||
|
||||
void CSI_Erase_handler(vga_buf *vgabuf, int n);
|
||||
|
||||
void CSI_handler(u8 terminator, vga_buf *vgabuf);
|
||||
#endif /* FS_H */
|
||||
@ -75,10 +75,15 @@ typedef struct vga_buf
|
||||
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
|
||||
|
||||
@ -32,6 +32,7 @@ KERN_SRCFILES :=kernel/kernel.asm \
|
||||
kernel/protect.c \
|
||||
kernel/serialport.c \
|
||||
kernel/vga.c \
|
||||
kernel/csi.c \
|
||||
lib/klib.c \
|
||||
|
||||
|
||||
|
||||
495
kernel/csi.c
Normal file
495
kernel/csi.c
Normal file
@ -0,0 +1,495 @@
|
||||
#include "tty.h"
|
||||
#include "x86.h"
|
||||
#include "console.h"
|
||||
#include "const.h"
|
||||
#include "assert.h"
|
||||
|
||||
#define INDEX(row, col) ((row)*SCR_WIDTH + (col))
|
||||
#define NEXTLINE(row) NEXT(row, SCR_MAXLINE)
|
||||
#define LASTLINE(row) LAST(row, SCR_MAXLINE)
|
||||
#define ADDLINE(row, add_num) (((row) + add_num) % SCR_MAXLINE)
|
||||
|
||||
void enable_blink()
|
||||
{
|
||||
disable_int();
|
||||
inb(0x3DA);
|
||||
outb(0x3C0, 0x30);
|
||||
u8 temp = inb(0x3C1);
|
||||
outb(0x3C0, temp | 0x08);
|
||||
enable_int();
|
||||
}
|
||||
|
||||
void disable_blink()
|
||||
{
|
||||
disable_int();
|
||||
inb(0x3DA);
|
||||
outb(0x3C0, 0x30);
|
||||
u8 temp = inb(0x3C1);
|
||||
outb(0x3C0, temp & 0xF7);
|
||||
enable_int();
|
||||
}
|
||||
|
||||
void set_underline(u32 addr)
|
||||
{
|
||||
disable_int();
|
||||
inb(0x3DA);
|
||||
outb(0x3C0, 0x30);
|
||||
u8 temp = inb(0x3C1);
|
||||
outb(0x3C0, temp | 0x01);
|
||||
outb(CRTC_ADDR_REG, UNDERLINE_REG);
|
||||
outb(CRTC_DATA_REG, addr & 0xFF);
|
||||
enable_int();
|
||||
}
|
||||
|
||||
// called by csi
|
||||
void csi_scroll(vga_buf *vgabuf, i16 scroll_num)
|
||||
{
|
||||
while (scroll_num > 0) // down
|
||||
{
|
||||
scroll_num--;
|
||||
for (int i = SCR_HEIGHT - 1; i > 0; i--)
|
||||
{
|
||||
int line_dst = ADDLINE(vgabuf->scr_top_line, i);
|
||||
int line_src = ADDLINE(vgabuf->scr_top_line, i - 1);
|
||||
u32 *ptr_buf_dst = (u32 *)(vgabuf->buf + sizeof(u16) * line_dst * SCR_WIDTH);
|
||||
u32 *ptr_buf_src = (u32 *)(vgabuf->buf + sizeof(u16) * line_src * SCR_WIDTH);
|
||||
for (int p = 0; p < SCR_WIDTH * sizeof(u16) / sizeof(u32); ++p)
|
||||
{
|
||||
*ptr_buf_dst++ = *ptr_buf_src++;
|
||||
}
|
||||
}
|
||||
u32 *ptr_buf_start = (u32 *)(vgabuf->buf + sizeof(u16) * (vgabuf->scr_top_line) * SCR_WIDTH);
|
||||
for (int i = 0; i < SCR_WIDTH * sizeof(u16) / sizeof(u32); ++i)
|
||||
{
|
||||
*ptr_buf_start++ = (BLANK << 16) | BLANK;
|
||||
}
|
||||
}
|
||||
while (scroll_num < 0) // up
|
||||
{
|
||||
scroll_num++;
|
||||
|
||||
for (int i = 0; i < SCR_HEIGHT - 1; i++)
|
||||
{
|
||||
int line_dst = ADDLINE(vgabuf->scr_top_line, i);
|
||||
int line_src = ADDLINE(vgabuf->scr_top_line, i + 1);
|
||||
u32 *ptr_buf_dst = (u32 *)(vgabuf->buf + sizeof(u16) * line_dst * SCR_WIDTH);
|
||||
u32 *ptr_buf_src = (u32 *)(vgabuf->buf + sizeof(u16) * line_src * SCR_WIDTH);
|
||||
for (int p = 0; p < SCR_WIDTH * sizeof(u16) / sizeof(u32); ++p)
|
||||
{
|
||||
*ptr_buf_dst++ = *ptr_buf_src++;
|
||||
}
|
||||
}
|
||||
int line_end = ADDLINE(vgabuf->scr_top_line, SCR_HEIGHT - 1);
|
||||
u32 *ptr_buf_end = (u32 *)(vgabuf->buf + sizeof(u16) * line_end * SCR_WIDTH);
|
||||
for (int i = 0; i < SCR_WIDTH * sizeof(u16) / sizeof(u32); ++i)
|
||||
{
|
||||
*ptr_buf_end++ = (BLANK << 16) | BLANK; // bg-black, fg-white, ascii-space
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cursor_locate(i16 row, i16 col, vga_buf *vgabuf)
|
||||
{
|
||||
|
||||
vgabuf->scr_cur_line = vgabuf->scr_top_line;
|
||||
while (row > 0 && row < SCR_HEIGHT)
|
||||
{
|
||||
row--;
|
||||
vgabuf->scr_cur_line = NEXTLINE(vgabuf->scr_cur_line);
|
||||
if (vgabuf->scr_cur_line == vgabuf->scr_bot_line)
|
||||
break;
|
||||
}
|
||||
if (col >= 0 && col <= SCR_WIDTH - 1)
|
||||
{
|
||||
vgabuf->cur_col = col;
|
||||
}
|
||||
}
|
||||
|
||||
void cursor_move(i16 move_row, i16 move_col, vga_buf *vgabuf)
|
||||
{
|
||||
// kprintf("%d,%d", move_row, move_col);
|
||||
while (move_row > 0) // down
|
||||
{
|
||||
move_row--;
|
||||
if (vgabuf->scr_cur_line == vgabuf->scr_bot_line)
|
||||
break;
|
||||
vgabuf->scr_cur_line = NEXTLINE(vgabuf->scr_cur_line);
|
||||
vgabuf->cur_row = CYCLE_SUB(vgabuf->scr_top_line, vgabuf->scr_cur_line, SCR_MAXLINE);
|
||||
if (vgabuf->cur_row == SCR_HEIGHT)
|
||||
{
|
||||
// auto scroll
|
||||
vgabuf->scr_top_line = NEXTLINE(vgabuf->scr_top_line);
|
||||
}
|
||||
}
|
||||
while (move_row < 0) // up
|
||||
{
|
||||
move_row++;
|
||||
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->scr_bot_line = LASTLINE(vgabuf->scr_bot_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;
|
||||
else if (vgabuf->cur_col >= SCR_WIDTH)
|
||||
vgabuf->cur_col = SCR_WIDTH - 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
inline static void
|
||||
param12vga_color(i16 *param)
|
||||
{
|
||||
u8 tmp = *param & 1;
|
||||
*param &= 0b0110;
|
||||
*param |= *param >> 2;
|
||||
*param &= 0b0011;
|
||||
*param |= tmp << 2;
|
||||
}
|
||||
|
||||
inline static void
|
||||
enable_reverse(vga_buf *vgabuf)
|
||||
{
|
||||
vgabuf->last_color = vgabuf->color;
|
||||
vgabuf->color = ((vgabuf->color & 0xf000) >> 4) | ((vgabuf->color & 0x0f00) << 4);
|
||||
vgabuf->IsColorReverse = true;
|
||||
}
|
||||
|
||||
inline static void
|
||||
disable_reverse(vga_buf *vgabuf)
|
||||
{
|
||||
if (vgabuf->IsColorReverse == true)
|
||||
{
|
||||
vgabuf->color = vgabuf->last_color;
|
||||
vgabuf->IsColorReverse = false;
|
||||
}
|
||||
}
|
||||
|
||||
inline static void
|
||||
enable_hide(vga_buf *vgabuf)
|
||||
{
|
||||
vgabuf->last_color = vgabuf->color;
|
||||
u16 back_clolor = ((vgabuf->color & 0xF000) >> 4);
|
||||
vgabuf->color &= 0xf000;
|
||||
vgabuf->color |= back_clolor;
|
||||
vgabuf->IsHide = true;
|
||||
}
|
||||
|
||||
inline static void
|
||||
disable_hide(vga_buf *vgabuf)
|
||||
{
|
||||
if (vgabuf->IsHide == true)
|
||||
{
|
||||
vgabuf->color = vgabuf->last_color;
|
||||
vgabuf->IsHide = false;
|
||||
}
|
||||
}
|
||||
|
||||
void set_color(vga_buf *vgabuf)
|
||||
{
|
||||
if (vgabuf->param1 == 0)
|
||||
{
|
||||
vgabuf->color = DEFAULT_CHAR_COLOR;
|
||||
disable_reverse(vgabuf);
|
||||
disable_hide(vgabuf);
|
||||
}
|
||||
// else if (vgabuf->param1 == 5 || vgabuf->param1 == 6)
|
||||
// {
|
||||
// enable_blink();
|
||||
// vgabuf->color |= FLASH_CHAR;
|
||||
// }
|
||||
else if (vgabuf->param1 == 7)
|
||||
{
|
||||
enable_reverse(vgabuf);
|
||||
}
|
||||
else if (vgabuf->param1 == 8)
|
||||
{
|
||||
enable_hide(vgabuf);
|
||||
}
|
||||
else if (vgabuf->param1 == 25)
|
||||
{
|
||||
disable_blink();
|
||||
vgabuf->color &= (~FLASH_CHAR);
|
||||
}
|
||||
else if (vgabuf->param1 == 27)
|
||||
{
|
||||
disable_reverse(vgabuf);
|
||||
}
|
||||
else if (vgabuf->param1 == 28)
|
||||
{
|
||||
disable_hide(vgabuf);
|
||||
}
|
||||
else if (30 <= vgabuf->param1 && vgabuf->param1 <= 37)
|
||||
{
|
||||
vgabuf->param1 -= 30;
|
||||
param12vga_color(&(vgabuf->param1));
|
||||
vgabuf->color = (vgabuf->color & 0xf8ff) | FOREGROUND(vgabuf->param1);
|
||||
}
|
||||
else if (vgabuf->param1 == 39)
|
||||
{
|
||||
u16 default_foreground = DEFAULT_CHAR_COLOR & 0x0f00;
|
||||
vgabuf->color = (vgabuf->color & 0xf0ff) | default_foreground;
|
||||
}
|
||||
else if (40 <= vgabuf->param1 && vgabuf->param1 <= 47)
|
||||
{
|
||||
vgabuf->param1 -= 40;
|
||||
param12vga_color(&(vgabuf->param1));
|
||||
vgabuf->color = (vgabuf->color & 0x8fff) | BACKGROUND(vgabuf->param1);
|
||||
}
|
||||
else if (vgabuf->param1 == 49)
|
||||
{
|
||||
u16 default_background = DEFAULT_CHAR_COLOR & 0xf000;
|
||||
vgabuf->color = (vgabuf->color & 0x0fff) | default_background;
|
||||
}
|
||||
else if (90 <= vgabuf->param1 && vgabuf->param1 <= 97)
|
||||
{
|
||||
vgabuf->param1 -= 90;
|
||||
param12vga_color(&(vgabuf->param1));
|
||||
vgabuf->param1 |= 0x8;
|
||||
vgabuf->color = (vgabuf->color & 0xf0ff) | FOREGROUND(vgabuf->param1);
|
||||
}
|
||||
else if (100 <= vgabuf->param1 && vgabuf->param1 <= 107)
|
||||
{
|
||||
vgabuf->param1 -= 100;
|
||||
param12vga_color(&(vgabuf->param1));
|
||||
vgabuf->param1 |= 0x8;
|
||||
vgabuf->color = (vgabuf->color & 0x0fff) | BACKGROUND(vgabuf->param1);
|
||||
}
|
||||
else
|
||||
{
|
||||
warn("unsupport CSI: color");
|
||||
}
|
||||
if (vgabuf->Is2param == true)
|
||||
{
|
||||
if (vgabuf->param2 == 0)
|
||||
{
|
||||
vgabuf->color = DEFAULT_CHAR_COLOR;
|
||||
disable_reverse(vgabuf);
|
||||
disable_hide(vgabuf);
|
||||
}
|
||||
// else if (vgabuf->param2 == 5 || vgabuf->param2 == 6)
|
||||
// {
|
||||
// enable_blink();
|
||||
// vgabuf->color |= FLASH_CHAR;
|
||||
// }
|
||||
else if (vgabuf->param2 == 7)
|
||||
{
|
||||
enable_reverse(vgabuf);
|
||||
}
|
||||
else if (vgabuf->param2 == 8)
|
||||
{
|
||||
enable_hide(vgabuf);
|
||||
}
|
||||
else if (vgabuf->param2 == 25)
|
||||
{
|
||||
disable_blink();
|
||||
vgabuf->color &= (~FLASH_CHAR);
|
||||
}
|
||||
else if (vgabuf->param2 == 27)
|
||||
{
|
||||
disable_reverse(vgabuf);
|
||||
}
|
||||
else if (vgabuf->param2 == 28)
|
||||
{
|
||||
disable_hide(vgabuf);
|
||||
}
|
||||
else if (30 <= vgabuf->param2 && vgabuf->param2 <= 37)
|
||||
{
|
||||
vgabuf->param2 -= 30;
|
||||
param12vga_color(&(vgabuf->param2));
|
||||
vgabuf->color = (vgabuf->color & 0xf8ff) | FOREGROUND(vgabuf->param2);
|
||||
}
|
||||
else if (vgabuf->param2 == 39)
|
||||
{
|
||||
u16 default_foreground = DEFAULT_CHAR_COLOR & 0x0f00;
|
||||
vgabuf->color = (vgabuf->color & 0xf0ff) | default_foreground;
|
||||
}
|
||||
else if (40 <= vgabuf->param2 && vgabuf->param2 <= 47)
|
||||
{
|
||||
vgabuf->param2 -= 40;
|
||||
param12vga_color(&(vgabuf->param2));
|
||||
vgabuf->color = (vgabuf->color & 0x8fff) | BACKGROUND(vgabuf->param2);
|
||||
}
|
||||
else if (vgabuf->param2 == 49)
|
||||
{
|
||||
u16 default_background = DEFAULT_CHAR_COLOR & 0xf000;
|
||||
vgabuf->color = (vgabuf->color & 0x0fff) | default_background;
|
||||
}
|
||||
else if (90 <= vgabuf->param2 && vgabuf->param2 <= 97)
|
||||
{
|
||||
vgabuf->param2 -= 90;
|
||||
param12vga_color(&(vgabuf->param2));
|
||||
vgabuf->param2 |= 0x8;
|
||||
vgabuf->color = (vgabuf->color & 0xf0ff) | FOREGROUND(vgabuf->param2);
|
||||
}
|
||||
else if (100 <= vgabuf->param2 && vgabuf->param2 <= 107)
|
||||
{
|
||||
vgabuf->param2 -= 100;
|
||||
param12vga_color(&(vgabuf->param2));
|
||||
vgabuf->param2 |= 0x8;
|
||||
vgabuf->color = (vgabuf->color & 0x0fff) | BACKGROUND(vgabuf->param2);
|
||||
}
|
||||
else
|
||||
{
|
||||
warn("unsupport CSI: color");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSI_Erase_handler(vga_buf *vgabuf, int n)
|
||||
{
|
||||
if (n == 2)
|
||||
{
|
||||
vgabuf->scr_bot_line = ADDLINE(vgabuf->scr_top_line, SCR_HEIGHT - 1);
|
||||
for (int i = 0; i < SCR_HEIGHT; i++)
|
||||
{
|
||||
vgabuf->scr_cur_line = NEXTLINE(vgabuf->scr_cur_line);
|
||||
vgabuf->scr_bot_line = NEXTLINE(vgabuf->scr_bot_line);
|
||||
// kprintf("af %x\n", vgabuf->scr_cur_line);
|
||||
vgabuf->cur_row = CYCLE_SUB(vgabuf->scr_top_line, vgabuf->scr_bot_line, SCR_MAXLINE);
|
||||
if (vgabuf->cur_row == SCR_HEIGHT)
|
||||
{
|
||||
// auto scroll
|
||||
vgabuf->scr_top_line = NEXTLINE(vgabuf->scr_top_line);
|
||||
}
|
||||
if (vgabuf->scr_bot_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->scr_bot_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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (n == 3)
|
||||
{
|
||||
int line = vgabuf->head_line;
|
||||
while (line != vgabuf->scr_top_line)
|
||||
{
|
||||
u32 *ptr_buf = (u32 *)(vgabuf->buf + sizeof(u16) * 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
|
||||
}
|
||||
line = NEXTLINE(line);
|
||||
}
|
||||
vgabuf->head_line = vgabuf->scr_top_line;
|
||||
}
|
||||
}
|
||||
|
||||
void CSI_handler(u8 terminator, vga_buf *vgabuf)
|
||||
{
|
||||
vgabuf->CSI = CSI_ESC;
|
||||
switch (terminator)
|
||||
{
|
||||
case 'A': // Cursor Up
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
cursor_move(-vgabuf->param1, 0, vgabuf);
|
||||
break;
|
||||
case 'B': // Cursor Down
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
cursor_move(+vgabuf->param1, 0, vgabuf);
|
||||
break;
|
||||
case 'C': // Cursor Forward
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
cursor_move(0, +vgabuf->param1, vgabuf);
|
||||
break;
|
||||
case 'D': // Cursor Back
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
cursor_move(0, -vgabuf->param1, vgabuf); // nothing
|
||||
break;
|
||||
case 'E': // Cursor Next Line
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
cursor_move(+vgabuf->param1, -vgabuf->cur_col, vgabuf);
|
||||
break;
|
||||
case 'F': // Cursor Previous Line
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
cursor_move(-vgabuf->param1, -vgabuf->cur_col, vgabuf);
|
||||
break;
|
||||
case 'G': // Cursor Horizontal Absolute
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
cursor_locate(CYCLE_SUB(vgabuf->scr_top_line, vgabuf->scr_cur_line, SCR_MAXLINE), vgabuf->param1 - 1, vgabuf);
|
||||
break;
|
||||
case 'H': // Cursor Position
|
||||
case 'f':
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
if (vgabuf->param2 == 0)
|
||||
vgabuf->param2 == 1;
|
||||
cursor_locate(vgabuf->param1 - 1, vgabuf->param2 - 1, vgabuf);
|
||||
break;
|
||||
case 'J': // Erase in Display
|
||||
if (vgabuf->param1 == 0)
|
||||
// from Cursor Position to the end of the screen
|
||||
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)
|
||||
// from Cursor Position to the start of the screen
|
||||
clear_screen(vgabuf, vgabuf->scr_top_line, 0, vgabuf->scr_cur_line, vgabuf->cur_col);
|
||||
else if (vgabuf->param1 == 2)
|
||||
// The whole screen
|
||||
CSI_Erase_handler(vgabuf, 2);
|
||||
else if (vgabuf->param1 == 3)
|
||||
// The whole screen and the buffer
|
||||
CSI_Erase_handler(vgabuf, 3);
|
||||
break;
|
||||
case 'K': // Erase in Line
|
||||
if (vgabuf->param1 == 0)
|
||||
// from Cursor Position to the end of the line
|
||||
clear_screen(vgabuf, vgabuf->scr_cur_line, vgabuf->cur_col, vgabuf->scr_cur_line, SCR_WIDTH - 1);
|
||||
else if (vgabuf->param1 == 1)
|
||||
// from Cursor Position to the start of the line
|
||||
clear_screen(vgabuf, vgabuf->scr_cur_line, 0, vgabuf->scr_cur_line, vgabuf->cur_col);
|
||||
else if (vgabuf->param1 == 2)
|
||||
// The whole line
|
||||
clear_screen(vgabuf, vgabuf->scr_cur_line, 0, vgabuf->scr_cur_line, SCR_WIDTH - 1);
|
||||
break;
|
||||
case 'S': // Scroll Up
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 = 1;
|
||||
csi_scroll(vgabuf, -vgabuf->param1);
|
||||
break;
|
||||
case 'T': // Scroll Down
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 = 1;
|
||||
csi_scroll(vgabuf, +vgabuf->param1);
|
||||
break;
|
||||
case 'm': // Select Graphic Rendition
|
||||
set_color(vgabuf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -132,7 +132,8 @@ void initial()
|
||||
do_vclose(stdout);
|
||||
do_vclose(stderr);
|
||||
|
||||
exec("orange/shell_1.bin");
|
||||
// exec("orange/shell_1.bin");
|
||||
exec("orange/test.bin");
|
||||
|
||||
while (1)
|
||||
;
|
||||
|
||||
@ -32,7 +32,7 @@ _NR_unlink equ 20 ; //added by xw, 18/6/18
|
||||
|
||||
_NR_create equ 21 ; //added by mingxuan 2019-5-17
|
||||
_NR_delete equ 22 ; //added by mingxuan 2019-5-17
|
||||
_NR_opendir equ 22 ; //added by mingxuan 2019-5-17
|
||||
_NR_opendir equ 23 ; //added by mingxuan 2019-5-17
|
||||
_NR_createdir equ 24 ; //added by mingxuan 2019-5-17
|
||||
_NR_deletedir equ 25 ; //added by mingxuan 2019-5-17
|
||||
|
||||
|
||||
38
kernel/tty.c
38
kernel/tty.c
@ -13,7 +13,6 @@
|
||||
#include "stdio.h"
|
||||
#include "serialport.h"
|
||||
|
||||
|
||||
int current_console; // 当前显示在屏幕上的console
|
||||
int tty_ok = 0;
|
||||
void tty_write(NTTY *tty, char *buf, int len);
|
||||
@ -24,11 +23,11 @@ static void tty_dev_read(TTY *tty);
|
||||
static void tty_dev_write(TTY *tty);
|
||||
static void put_key(TTY *tty, u32 key);
|
||||
|
||||
NTTY *cur_ntty;
|
||||
NTTY *ntty_table[NR_CONSOLES];
|
||||
|
||||
NTTY* cur_ntty;
|
||||
NTTY* ntty_table[NR_CONSOLES];
|
||||
|
||||
inline NTTY* get_tty(const int nr_tty) {
|
||||
inline NTTY *get_tty(const int nr_tty)
|
||||
{
|
||||
return ntty_table[nr_tty];
|
||||
}
|
||||
|
||||
@ -38,20 +37,20 @@ void init_tty_main()
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
// tty = &ntty_table[i];
|
||||
tty = (NTTY*)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
|
||||
tty = (NTTY *)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
|
||||
tty->driver_type = 1; // vga
|
||||
// tty->input_buf = (void*)do_kmalloc(sizeof(keyboard_buf));
|
||||
// tty->output_buf = (void*)do_kmalloc(sizeof(vga_buf));
|
||||
tty->input_buf = (keyboard_buf*)K_PHY2LIN(do_kmalloc(sizeof(keyboard_buf)));
|
||||
tty->output_buf = (vga_buf*)K_PHY2LIN(do_kmalloc(sizeof(vga_buf)));
|
||||
tty->input_buf = (keyboard_buf *)K_PHY2LIN(do_kmalloc(sizeof(keyboard_buf)));
|
||||
tty->output_buf = (vga_buf *)K_PHY2LIN(do_kmalloc(sizeof(vga_buf)));
|
||||
vga_tty_init(tty);
|
||||
ps2_tty_init(tty);
|
||||
ntty_table[i] = tty;
|
||||
// kprintf("tty: %p, outbuf: %p\n", tty, tty->output_buf);
|
||||
}
|
||||
tty = (NTTY*)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
|
||||
tty = (NTTY *)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
|
||||
tty->driver_type = 2;
|
||||
tty->input_buf = (serial_buf*)K_PHY2LIN(do_kmalloc(sizeof(serial_buf)));
|
||||
tty->input_buf = (serial_buf *)K_PHY2LIN(do_kmalloc(sizeof(serial_buf)));
|
||||
// kprintf("tty: %p, outbuf: %p\n", tty, tty->input_buf);
|
||||
tty->output_buf = NULL;
|
||||
serial_tty_init_i(tty);
|
||||
@ -59,10 +58,10 @@ void init_tty_main()
|
||||
ntty_table[2] = tty;
|
||||
cur_ntty = ntty_table[0];
|
||||
tty_ok = 1;
|
||||
|
||||
kprintf("TTY initialized\n");
|
||||
}
|
||||
|
||||
|
||||
void task_tty()
|
||||
{
|
||||
// NTTY* p_tty;
|
||||
@ -78,10 +77,8 @@ void task_tty()
|
||||
// vga_tty_write(get_tty(2), serial_input);
|
||||
// kprintf("%c", serial_input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* tty_write
|
||||
****************************************************************************
|
||||
@ -90,22 +87,27 @@ void task_tty()
|
||||
*****************************************************************************/
|
||||
void tty_write(NTTY *tty, char *buf, int len)
|
||||
{
|
||||
if (!tty_ok) {
|
||||
if (!tty_ok)
|
||||
{
|
||||
while (--len >= 0)
|
||||
{
|
||||
write_serial(*buf++);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (tty->driver_type == 1) {
|
||||
else if (tty->driver_type == 1)
|
||||
{
|
||||
while (--len >= 0)
|
||||
{
|
||||
vga_tty_write(tty, *buf++);
|
||||
}
|
||||
if (cur_ntty == tty) vga_tty_flush(tty);
|
||||
if (cur_ntty == tty)
|
||||
vga_tty_flush(tty);
|
||||
}
|
||||
else if (tty->driver_type == 2) {
|
||||
while(--len >= 0) {
|
||||
else if (tty->driver_type == 2)
|
||||
{
|
||||
while (--len >= 0)
|
||||
{
|
||||
serial_tty_write(tty, *buf++);
|
||||
}
|
||||
}
|
||||
|
||||
372
kernel/vga.c
372
kernel/vga.c
@ -12,7 +12,7 @@
|
||||
#include "x86.h"
|
||||
#include "memman.h"
|
||||
#include "assert.h"
|
||||
|
||||
#include "csi.h"
|
||||
/*****************************************************************************
|
||||
* Low level vga driver
|
||||
*****************************************************************************/
|
||||
@ -133,6 +133,10 @@ void vga_tty_init(NTTY *tty)
|
||||
// buf->max_line = SCR_BUFSIZE / SCR_WIDTH;
|
||||
vga->scr_top_line = vga->scr_cur_line = vga->scr_bot_line = 0;
|
||||
vga->head_line = 0;
|
||||
vga->Is2param = false;
|
||||
vga->IsColorReverse = false;
|
||||
vga->IsHide = false;
|
||||
vga->color = DEFAULT_CHAR_COLOR;
|
||||
u32 *ptr_buf = (u32 *)vga->buf;
|
||||
for (int i = 0; i < SCR_BUFSIZE * sizeof(u16) / sizeof(u32); ++i)
|
||||
{
|
||||
@ -146,60 +150,11 @@ void vga_tty_init(NTTY *tty)
|
||||
#define LASTLINE(row) LAST(row, SCR_MAXLINE)
|
||||
#define ADDLINE(row, add_num) (((row) + add_num) % SCR_MAXLINE)
|
||||
|
||||
// called by csi
|
||||
static void csi_scroll(vga_buf *vgabuf, i16 scroll_num)
|
||||
{
|
||||
while (scroll_num > 0) // down
|
||||
{
|
||||
scroll_num--;
|
||||
for (int i = SCR_HEIGHT - 1; i > 0; i--)
|
||||
{
|
||||
int line_dst = ADDLINE(vgabuf->scr_top_line, i);
|
||||
int line_src = ADDLINE(vgabuf->scr_top_line, i - 1);
|
||||
u32 *ptr_buf_dst = (u32 *)(vgabuf->buf + sizeof(u16) * line_dst * SCR_WIDTH);
|
||||
u32 *ptr_buf_src = (u32 *)(vgabuf->buf + sizeof(u16) * line_src * SCR_WIDTH);
|
||||
for (int p = 0; p < SCR_WIDTH * sizeof(u16) / sizeof(u32); ++p)
|
||||
{
|
||||
*ptr_buf_dst++ = *ptr_buf_src++;
|
||||
}
|
||||
}
|
||||
u32 *ptr_buf_start = (u32 *)(vgabuf->buf + sizeof(u16) * (vgabuf->scr_top_line) * SCR_WIDTH);
|
||||
for (int i = 0; i < SCR_WIDTH * sizeof(u16) / sizeof(u32); ++i)
|
||||
{
|
||||
*ptr_buf_start++ = (BLANK << 16) | BLANK; // bg-black, fg-white, ascii-space
|
||||
}
|
||||
}
|
||||
while (scroll_num < 0) // up
|
||||
{
|
||||
scroll_num++;
|
||||
|
||||
for (int i = 0; i < SCR_HEIGHT - 1; i++)
|
||||
{
|
||||
int line_dst = ADDLINE(vgabuf->scr_top_line, i);
|
||||
int line_src = ADDLINE(vgabuf->scr_top_line, i + 1);
|
||||
u32 *ptr_buf_dst = (u32 *)(vgabuf->buf + sizeof(u16) * line_dst * SCR_WIDTH);
|
||||
u32 *ptr_buf_src = (u32 *)(vgabuf->buf + sizeof(u16) * line_src * SCR_WIDTH);
|
||||
for (int p = 0; p < SCR_WIDTH * sizeof(u16) / sizeof(u32); ++p)
|
||||
{
|
||||
*ptr_buf_dst++ = *ptr_buf_src++;
|
||||
}
|
||||
}
|
||||
int line_end = ADDLINE(vgabuf->scr_top_line, SCR_HEIGHT - 1);
|
||||
u32 *ptr_buf_end = (u32 *)(vgabuf->buf + sizeof(u16) * line_end * SCR_WIDTH);
|
||||
for (int i = 0; i < SCR_WIDTH * sizeof(u16) / sizeof(u32); ++i)
|
||||
{
|
||||
*ptr_buf_end++ = (BLANK << 16) | BLANK; // bg-black, fg-white, ascii-space
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void newline(vga_buf *vga)
|
||||
{
|
||||
u16 *buf = vga->buf;
|
||||
vga->cur_col = 0;
|
||||
// kprintf("bf %x\n", vgabuf->scr_cur_line);
|
||||
vga->scr_cur_line = NEXTLINE(vga->scr_cur_line);
|
||||
// kprintf("af %x\n", vgabuf->scr_cur_line);
|
||||
vga->cur_row = CYCLE_SUB(vga->scr_top_line, vga->scr_cur_line, SCR_MAXLINE);
|
||||
if (vga->cur_row == SCR_HEIGHT)
|
||||
{
|
||||
@ -215,9 +170,6 @@ static void newline(vga_buf *vga)
|
||||
{
|
||||
*ptr_buf++ = (BLANK << 16) | BLANK; // bg-black, fg-white, ascii-space
|
||||
}
|
||||
// for (int i = 0; i < SCR_WIDTH; ++ i) {
|
||||
// buf[INDEX(vga->scr_cur_line, i)] = BLANK;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,304 +182,6 @@ static void nextcol(vga_buf *vgabuf)
|
||||
}
|
||||
}
|
||||
|
||||
static void cursor_locate(i16 row, i16 col, vga_buf *vgabuf)
|
||||
{
|
||||
|
||||
vgabuf->scr_cur_line = vgabuf->scr_top_line;
|
||||
while (row > 0 && row < SCR_HEIGHT)
|
||||
{
|
||||
row--;
|
||||
vgabuf->scr_cur_line = NEXTLINE(vgabuf->scr_cur_line);
|
||||
if (vgabuf->scr_cur_line == vgabuf->scr_bot_line)
|
||||
break;
|
||||
}
|
||||
if (col >= 0 && col <= SCR_WIDTH - 1)
|
||||
{
|
||||
vgabuf->cur_col = col;
|
||||
}
|
||||
}
|
||||
static void cursor_move(i16 move_row, i16 move_col, vga_buf *vgabuf)
|
||||
{
|
||||
// kprintf("%d,%d", move_row, move_col);
|
||||
while (move_row > 0) // down
|
||||
{
|
||||
move_row--;
|
||||
if (vgabuf->scr_cur_line == vgabuf->scr_bot_line)
|
||||
break;
|
||||
vgabuf->scr_cur_line = NEXTLINE(vgabuf->scr_cur_line);
|
||||
vgabuf->cur_row = CYCLE_SUB(vgabuf->scr_top_line, vgabuf->scr_cur_line, SCR_MAXLINE);
|
||||
if (vgabuf->cur_row == SCR_HEIGHT)
|
||||
{
|
||||
// auto scroll
|
||||
vgabuf->scr_top_line = NEXTLINE(vgabuf->scr_top_line);
|
||||
}
|
||||
}
|
||||
while (move_row < 0) // up
|
||||
{
|
||||
move_row++;
|
||||
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->scr_bot_line = LASTLINE(vgabuf->scr_bot_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;
|
||||
else if (vgabuf->cur_col >= SCR_WIDTH)
|
||||
vgabuf->cur_col = SCR_WIDTH - 1;
|
||||
}
|
||||
|
||||
inline static void
|
||||
param12vga_color(i16 *param)
|
||||
{
|
||||
u8 tmp = *param & 1;
|
||||
*param &= 0b0110;
|
||||
*param |= *param >> 2;
|
||||
*param &= 0b0011;
|
||||
*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)
|
||||
{
|
||||
vgabuf->color = DEFAULT_CHAR_COLOR;
|
||||
}
|
||||
else if (vgabuf->param1 == 1)
|
||||
{
|
||||
vgabuf->color |= 0x8800;
|
||||
}
|
||||
else if (vgabuf->param1 == 2)
|
||||
{
|
||||
vgabuf->color &= 0x7700;
|
||||
}
|
||||
else if (30 <= vgabuf->param1 && vgabuf->param1 <= 37)
|
||||
{
|
||||
vgabuf->param1 -= 30;
|
||||
param12vga_color(&(vgabuf->param1));
|
||||
vgabuf->color = (vgabuf->color & 0xf8ff) | FOREGROUND(vgabuf->param1);
|
||||
}
|
||||
else if (40 <= vgabuf->param1 && vgabuf->param1 <= 47)
|
||||
{
|
||||
vgabuf->param1 -= 40;
|
||||
param12vga_color(&(vgabuf->param1));
|
||||
vgabuf->color = (vgabuf->color & 0x8fff) | BACKGROUND(vgabuf->param1);
|
||||
}
|
||||
else if (90 <= vgabuf->param1 && vgabuf->param1 <= 97)
|
||||
{
|
||||
vgabuf->param1 -= 90;
|
||||
param12vga_color(&(vgabuf->param1));
|
||||
vgabuf->param1 |= 0x8;
|
||||
vgabuf->color = (vgabuf->color & 0xf0ff) | FOREGROUND(vgabuf->param1);
|
||||
}
|
||||
else if (100 <= vgabuf->param1 && vgabuf->param1 <= 107)
|
||||
{
|
||||
vgabuf->param1 -= 100;
|
||||
param12vga_color(&(vgabuf->param1));
|
||||
vgabuf->param1 |= 0x8;
|
||||
vgabuf->color = (vgabuf->color & 0x0fff) | BACKGROUND(vgabuf->param1);
|
||||
}
|
||||
else
|
||||
{
|
||||
warn("unsupport CSI: color");
|
||||
}
|
||||
if (vgabuf->Is2param == true)
|
||||
{
|
||||
if (vgabuf->param2 == 0 && vgabuf->param1 == 0)
|
||||
{
|
||||
vgabuf->color = DEFAULT_CHAR_COLOR;
|
||||
}
|
||||
else if (vgabuf->param2 == 1)
|
||||
{
|
||||
vgabuf->color |= 0x8800;
|
||||
}
|
||||
else if (vgabuf->param2 == 2)
|
||||
{
|
||||
vgabuf->color &= 0x7700;
|
||||
}
|
||||
else if (30 <= vgabuf->param2 && vgabuf->param2 <= 37)
|
||||
{
|
||||
vgabuf->param2 -= 30;
|
||||
param12vga_color(&(vgabuf->param2));
|
||||
vgabuf->color = (vgabuf->color & 0xf8ff) | FOREGROUND(vgabuf->param2);
|
||||
}
|
||||
else if (40 <= vgabuf->param2 && vgabuf->param2 <= 47)
|
||||
{
|
||||
vgabuf->param2 -= 40;
|
||||
param12vga_color(&(vgabuf->param2));
|
||||
vgabuf->color = (vgabuf->color & 0x8fff) | BACKGROUND(vgabuf->param2);
|
||||
}
|
||||
else if (90 <= vgabuf->param2 && vgabuf->param2 <= 97)
|
||||
{
|
||||
vgabuf->param2 -= 90;
|
||||
param12vga_color(&(vgabuf->param2));
|
||||
vgabuf->param2 |= 0x8;
|
||||
vgabuf->color = (vgabuf->color & 0xf0ff) | FOREGROUND(vgabuf->param2);
|
||||
}
|
||||
else if (100 <= vgabuf->param2 && vgabuf->param2 <= 107)
|
||||
{
|
||||
vgabuf->param2 -= 100;
|
||||
param12vga_color(&(vgabuf->param2));
|
||||
vgabuf->param2 |= 0x8;
|
||||
vgabuf->color = (vgabuf->color & 0x0fff) | BACKGROUND(vgabuf->param2);
|
||||
}
|
||||
else
|
||||
{
|
||||
warn("unsupport CSI: color");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void CSI_Erase_handler(vga_buf *vgabuf, int n)
|
||||
{
|
||||
if (n == 2)
|
||||
{
|
||||
vgabuf->scr_bot_line = ADDLINE(vgabuf->scr_top_line, SCR_HEIGHT - 1);
|
||||
for (int i = 0; i < SCR_HEIGHT; i++)
|
||||
{
|
||||
vgabuf->scr_cur_line = NEXTLINE(vgabuf->scr_cur_line);
|
||||
vgabuf->scr_bot_line = NEXTLINE(vgabuf->scr_bot_line);
|
||||
// kprintf("af %x\n", vgabuf->scr_cur_line);
|
||||
vgabuf->cur_row = CYCLE_SUB(vgabuf->scr_top_line, vgabuf->scr_bot_line, SCR_MAXLINE);
|
||||
if (vgabuf->cur_row == SCR_HEIGHT)
|
||||
{
|
||||
// auto scroll
|
||||
vgabuf->scr_top_line = NEXTLINE(vgabuf->scr_top_line);
|
||||
}
|
||||
if (vgabuf->scr_bot_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->scr_bot_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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (n == 3)
|
||||
{
|
||||
int line = vgabuf->head_line;
|
||||
while (line != vgabuf->scr_top_line)
|
||||
{
|
||||
u32 *ptr_buf = (u32 *)(vgabuf->buf + sizeof(u16) * 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
|
||||
}
|
||||
line = NEXTLINE(line);
|
||||
}
|
||||
vgabuf->head_line = vgabuf->scr_top_line;
|
||||
}
|
||||
}
|
||||
static void CSI_handler(u8 terminator, vga_buf *vgabuf)
|
||||
{
|
||||
vgabuf->CSI = CSI_ESC;
|
||||
switch (terminator)
|
||||
{
|
||||
case 'A':
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
cursor_move(-vgabuf->param1, 0, vgabuf);
|
||||
break;
|
||||
case 'B':
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
cursor_move(+vgabuf->param1, 0, vgabuf);
|
||||
break;
|
||||
case 'C':
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
cursor_move(0, +vgabuf->param1, vgabuf);
|
||||
break;
|
||||
case 'D':
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
cursor_move(0, -vgabuf->param1, vgabuf); // nothing
|
||||
break;
|
||||
case 'E':
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
cursor_move(+vgabuf->param1, -vgabuf->cur_col, vgabuf);
|
||||
break;
|
||||
case 'F':
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
cursor_move(-vgabuf->param1, -vgabuf->cur_col, vgabuf);
|
||||
break;
|
||||
case 'G': // added
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
cursor_locate(CYCLE_SUB(vgabuf->scr_top_line, vgabuf->scr_cur_line, SCR_MAXLINE), vgabuf->param1 - 1, vgabuf);
|
||||
break;
|
||||
case 'H':
|
||||
case 'f':
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 == 1;
|
||||
if (vgabuf->param2 == 0)
|
||||
vgabuf->param2 == 1;
|
||||
cursor_locate(vgabuf->param1 - 1, vgabuf->param2 - 1, 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)
|
||||
CSI_Erase_handler(vgabuf, 2);
|
||||
else if (vgabuf->param1 == 3)
|
||||
CSI_Erase_handler(vgabuf, 3);
|
||||
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': // Scroll Up
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 = 1;
|
||||
csi_scroll(vgabuf, -vgabuf->param1);
|
||||
break;
|
||||
case 'T': // Scroll Down
|
||||
if (vgabuf->param1 == 0)
|
||||
vgabuf->param1 = 1;
|
||||
csi_scroll(vgabuf, +vgabuf->param1);
|
||||
break;
|
||||
case 'm':
|
||||
set_color(vgabuf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void vga_tty_write(NTTY *tty, char ch)
|
||||
{
|
||||
// assert(tty->driver_type == 1);
|
||||
@ -566,14 +220,7 @@ void vga_tty_write(NTTY *tty, char ch)
|
||||
vga->Is2param = false;
|
||||
break;
|
||||
default:
|
||||
if (vga->color == 0)
|
||||
{
|
||||
buf[INDEX(vga->scr_cur_line, vga->cur_col)] = MAKE_CELL(DEFAULT_CHAR_COLOR, ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
buf[INDEX(vga->scr_cur_line, vga->cur_col)] = MAKE_CELL(vga->color, ch);
|
||||
}
|
||||
buf[INDEX(vga->scr_cur_line, vga->cur_col)] = MAKE_CELL(vga->color, ch);
|
||||
// buf[INDEX(vga->scr_cur_line, vga->cur_col)] = MAKE_CELL(DEFAULT_CHAR_COLOR, ch);
|
||||
nextcol(vga);
|
||||
break;
|
||||
@ -614,8 +261,11 @@ void vga_tty_write(NTTY *tty, char ch)
|
||||
; // do nothing
|
||||
break;
|
||||
case ';':
|
||||
vga->CSI = CSI_PARAM2;
|
||||
vga->Is2param = true;
|
||||
if (vga->CSI == CSI_PARAM1)
|
||||
{
|
||||
vga->CSI = CSI_PARAM2;
|
||||
vga->Is2param = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (!(0x20 <= ch && ch <= 0x7e))
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
#include "tty.h"
|
||||
#include "serialport.h"
|
||||
|
||||
static void serialputch(int ch, void *cnt)
|
||||
static void kprintfputch(int ch, void *cnt)
|
||||
{
|
||||
// write_serial(ch);
|
||||
char _ch = ch;
|
||||
@ -16,8 +16,7 @@ static void serialputch(int ch, void *cnt)
|
||||
int vkprintf(const char *fmt, va_list ap)
|
||||
{
|
||||
|
||||
// vprintfmt((void*)kprintfputch, NULL, fmt, ap);
|
||||
vprintfmt((void *)serialputch, NULL, fmt, ap);
|
||||
vprintfmt((void *)kprintfputch, NULL, fmt, ap);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
10
user/test.c
10
user/test.c
@ -34,14 +34,16 @@ int main(int arg, char *argv[])
|
||||
// printf("8888888888");
|
||||
// printf("9999999999\r\b\b\n");
|
||||
// }
|
||||
printf("\x1b[33m");
|
||||
|
||||
for (int i = 0; i < 40; i++)
|
||||
// printf("\x1b[33m");
|
||||
// printf("\x1b[1m");
|
||||
for (int i = 0; i < 14; i++)
|
||||
{
|
||||
printf("%d", i);
|
||||
printf("\x1b[m");
|
||||
|
||||
printf("11111111111111111\n");
|
||||
}
|
||||
printf("\x1b[31;47m555555555555\x1b[m");
|
||||
printf("\x1b[6T11111111111111111\n");
|
||||
|
||||
// Cursor Up
|
||||
// printf("\x1b[2A");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user