Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e9e43cd8e | ||
|
|
27c1d3c033 | ||
|
|
f9a75fa1e4 | ||
|
|
44e2862131 | ||
|
|
fdaff54b21 | ||
|
|
0eb609914b | ||
|
|
7febffdda1 | ||
|
|
306a3a1eac | ||
|
|
4b58073f12 | ||
|
|
ceeb34cf78 | ||
|
|
f9e7459bbb |
@ -24,10 +24,6 @@ typedef struct s_console
|
|||||||
char *buf;
|
char *buf;
|
||||||
} s_console;
|
} s_console;
|
||||||
|
|
||||||
typedef struct fb_console {
|
|
||||||
|
|
||||||
} fb_console;
|
|
||||||
|
|
||||||
typedef struct ringbuf {
|
typedef struct ringbuf {
|
||||||
unsigned int head;
|
unsigned int head;
|
||||||
unsigned int tail;
|
unsigned int tail;
|
||||||
@ -54,6 +50,7 @@ void fbcon_screen_setup();
|
|||||||
#define SCR_BUFSIZE (2 * SCR_SIZE)
|
#define SCR_BUFSIZE (2 * SCR_SIZE)
|
||||||
#define SCR_MAXLINE (SCR_BUFSIZE / SCR_WIDTH)
|
#define SCR_MAXLINE (SCR_BUFSIZE / SCR_WIDTH)
|
||||||
|
|
||||||
|
#define FLASH_CHAR 0x8000
|
||||||
#define DEFAULT_CHAR_COLOR ((MAKE_COLOR(BLACK, WHITE | BRIGHT)) << 8)
|
#define DEFAULT_CHAR_COLOR ((MAKE_COLOR(BLACK, WHITE | BRIGHT)) << 8)
|
||||||
#define GRAY_CHAR (MAKE_COLOR(BLACK, BLACK) | BRIGHT)
|
#define GRAY_CHAR (MAKE_COLOR(BLACK, BLACK) | BRIGHT)
|
||||||
#define RED_CHAR (MAKE_COLOR(BLUE, RED) | BRIGHT)
|
#define RED_CHAR (MAKE_COLOR(BLUE, RED) | BRIGHT)
|
||||||
|
|||||||
@ -166,14 +166,16 @@
|
|||||||
|
|
||||||
/* VGA */
|
/* VGA */
|
||||||
// added by mingxuan 2019-5-19
|
// added by mingxuan 2019-5-19
|
||||||
#define CRTC_ADDR_REG 0x3D4 /* CRT Controller Registers - Addr Register */
|
#define CRTC_ADDR_REG 0x3D4 /* CRT Controller Registers - Addr Register */
|
||||||
#define CRTC_DATA_REG 0x3D5 /* CRT Controller Registers - Data 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_H 0xC /* reg index of video mem start addr (MSB) */
|
||||||
#define START_ADDR_L 0xD /* reg index of video mem start addr (LSB) */
|
#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_H 0xE /* reg index of cursor position (MSB) */
|
||||||
#define CURSOR_L 0xF /* reg index of cursor position (LSB) */
|
#define CURSOR_L 0xF /* reg index of cursor position (LSB) */
|
||||||
#define V_MEM_BASE 0xB8000 /* base of color video memory */
|
#define UNDERLINE_REG 0x14 /* reg index of underline */
|
||||||
#define V_MEM_SIZE 0x8000 /* 32K: B8000H -> BFFFFH */
|
#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_IN 0
|
||||||
#define STD_OUT 1
|
#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 */
|
||||||
@ -44,7 +44,6 @@ void keyboard_read();
|
|||||||
|
|
||||||
/* tty.c */
|
/* tty.c */
|
||||||
// added by mingxuan 2019-5-19
|
// added by mingxuan 2019-5-19
|
||||||
void in_process(TTY *p_tty, u32 key);
|
|
||||||
void task_tty();
|
void task_tty();
|
||||||
void tty_write(NTTY *tty, char *buf, int len);
|
void tty_write(NTTY *tty, char *buf, int len);
|
||||||
int tty_read(NTTY *tty, char *buf, int len);
|
int tty_read(NTTY *tty, char *buf, int len);
|
||||||
|
|||||||
@ -27,27 +27,8 @@
|
|||||||
#define TTY_STATE_WAIT_SPACE 2 /*010*/
|
#define TTY_STATE_WAIT_SPACE 2 /*010*/
|
||||||
#define TTY_STATE_DISPLAY 1 /*001*/
|
#define TTY_STATE_DISPLAY 1 /*001*/
|
||||||
|
|
||||||
struct s_tty;
|
#define MAXNUM_PARAM 16
|
||||||
struct s_console;
|
#define MAXNUM_PARAM_CH 100
|
||||||
|
|
||||||
/* 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 n_tty
|
typedef struct n_tty
|
||||||
{
|
{
|
||||||
@ -55,7 +36,7 @@ typedef struct n_tty
|
|||||||
void *input_buf;
|
void *input_buf;
|
||||||
void *output_buf;
|
void *output_buf;
|
||||||
void (*write)(struct n_tty *tty, char ch);
|
void (*write)(struct n_tty *tty, char ch);
|
||||||
int (*read)(struct n_tty *tty, char* buf, int nr);
|
int (*read)(struct n_tty *tty, char *buf, int nr);
|
||||||
void (*recvbuf)(struct n_tty *tty, u32 ch);
|
void (*recvbuf)(struct n_tty *tty, u32 ch);
|
||||||
int (*ioctl)(struct n_tty *tty, u32 cmd, long arg);
|
int (*ioctl)(struct n_tty *tty, u32 cmd, long arg);
|
||||||
} NTTY;
|
} NTTY;
|
||||||
@ -64,8 +45,7 @@ enum CSI_state
|
|||||||
{
|
{
|
||||||
CSI_ESC,
|
CSI_ESC,
|
||||||
CSI_BRACKET,
|
CSI_BRACKET,
|
||||||
CSI_PARAM1,
|
CSI_PARAM
|
||||||
CSI_PARAM2
|
|
||||||
};
|
};
|
||||||
typedef struct vga_buf
|
typedef struct vga_buf
|
||||||
{
|
{
|
||||||
@ -78,11 +58,15 @@ typedef struct vga_buf
|
|||||||
int cur_row;
|
int cur_row;
|
||||||
int cur_col; // cursor position, on screen
|
int cur_col; // cursor position, on screen
|
||||||
|
|
||||||
bool Is2param;
|
bool IsColorReverse;
|
||||||
|
bool IsHide;
|
||||||
|
|
||||||
enum CSI_state CSI;
|
enum CSI_state CSI;
|
||||||
i16 param1; // the first param of CSI
|
|
||||||
i16 param2; // the second of CSI
|
char param_c[MAXNUM_PARAM_CH]; // the params of CSI
|
||||||
|
u16 param_num;
|
||||||
u16 color;
|
u16 color;
|
||||||
|
u16 last_color; // 为了某些功能关闭后,恢复原属性
|
||||||
} vga_buf;
|
} vga_buf;
|
||||||
|
|
||||||
typedef struct keyboard_buf
|
typedef struct keyboard_buf
|
||||||
@ -110,7 +94,6 @@ NTTY *get_tty(const int nr_tty);
|
|||||||
void vga_tty_init(NTTY *tty);
|
void vga_tty_init(NTTY *tty);
|
||||||
void vga_tty_write(NTTY *tty, char ch);
|
void vga_tty_write(NTTY *tty, char ch);
|
||||||
void vga_tty_flush(NTTY *tty);
|
void vga_tty_flush(NTTY *tty);
|
||||||
void vga_tty_backspace(NTTY *tty);
|
|
||||||
void vga_tty_scroll(NTTY *tty, int direction);
|
void vga_tty_scroll(NTTY *tty, int direction);
|
||||||
void vga_tty_select(NTTY *tty);
|
void vga_tty_select(NTTY *tty);
|
||||||
|
|
||||||
@ -133,8 +116,8 @@ extern NTTY *cur_ntty;
|
|||||||
#define IOCTL_CMD_TTY_SELECTCON 2
|
#define IOCTL_CMD_TTY_SELECTCON 2
|
||||||
#define IOCTL_CMD_TTY_FLUSH 3
|
#define IOCTL_CMD_TTY_FLUSH 3
|
||||||
|
|
||||||
#define TTY_SCROLL_UP 1
|
#define TTY_SCROLL_UP 1
|
||||||
#define TTY_SCROLL_DOWN 2
|
#define TTY_SCROLL_DOWN 2
|
||||||
#define TTY_SCROLL_TOCUR 3
|
#define TTY_SCROLL_TOCUR 3
|
||||||
|
|
||||||
#endif /* _ORANGES_TTY_H_ */
|
#endif /* _ORANGES_TTY_H_ */
|
||||||
@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "x86.h"
|
|
||||||
#include "proto.h"
|
|
||||||
static inline void acquire_y(volatile u32* lock) {
|
|
||||||
while (xchg(lock, 1) == 1){
|
|
||||||
sys_yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void release_y(volatile u32* lock) {
|
|
||||||
xchg(lock, 0);
|
|
||||||
}
|
|
||||||
@ -32,6 +32,7 @@ KERN_SRCFILES :=kernel/kernel.asm \
|
|||||||
kernel/protect.c \
|
kernel/protect.c \
|
||||||
kernel/serialport.c \
|
kernel/serialport.c \
|
||||||
kernel/vga.c \
|
kernel/vga.c \
|
||||||
|
kernel/csi.c \
|
||||||
kernel/pci.c \
|
kernel/pci.c \
|
||||||
kernel/bga.c \
|
kernel/bga.c \
|
||||||
kernel/fbcon.c \
|
kernel/fbcon.c \
|
||||||
|
|||||||
431
kernel/csi.c
Normal file
431
kernel/csi.c
Normal file
@ -0,0 +1,431 @@
|
|||||||
|
#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 disable_blink()
|
||||||
|
{
|
||||||
|
disable_int();
|
||||||
|
inb(0x3DA);
|
||||||
|
outb(0x3C0, 0x30);
|
||||||
|
u8 temp = inb(0x3C1);
|
||||||
|
outb(0x3C0, temp & 0xF7);
|
||||||
|
enable_int();
|
||||||
|
}
|
||||||
|
|
||||||
|
void enable_blink()
|
||||||
|
{
|
||||||
|
disable_int();
|
||||||
|
inb(0x3DA);
|
||||||
|
outb(0x3C0, 0x30);
|
||||||
|
u8 temp = inb(0x3C1);
|
||||||
|
outb(0x3C0, temp | 0x08);
|
||||||
|
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++;
|
||||||
|
if (vgabuf->scr_cur_line == vgabuf->scr_top_line)
|
||||||
|
break;
|
||||||
|
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(i16 param_cnt, i16 param[], vga_buf *vgabuf)
|
||||||
|
{
|
||||||
|
for (int i = 0; i <= param_cnt; i++)
|
||||||
|
{
|
||||||
|
if (param[i] == 0)
|
||||||
|
{
|
||||||
|
disable_reverse(vgabuf);
|
||||||
|
disable_hide(vgabuf);
|
||||||
|
vgabuf->color = DEFAULT_CHAR_COLOR;
|
||||||
|
}
|
||||||
|
else if (param[i] == 7)
|
||||||
|
{
|
||||||
|
enable_reverse(vgabuf);
|
||||||
|
}
|
||||||
|
else if (param[i] == 8)
|
||||||
|
{
|
||||||
|
enable_hide(vgabuf);
|
||||||
|
}
|
||||||
|
else if (param[i] == 27)
|
||||||
|
{
|
||||||
|
disable_reverse(vgabuf);
|
||||||
|
}
|
||||||
|
else if (param[i] == 28)
|
||||||
|
{
|
||||||
|
disable_hide(vgabuf);
|
||||||
|
}
|
||||||
|
else if (30 <= param[i] && param[i] <= 37)
|
||||||
|
{
|
||||||
|
param[i] -= 30;
|
||||||
|
param12vga_color(&(param[i]));
|
||||||
|
vgabuf->color = (vgabuf->color & 0xf8ff) | FOREGROUND(param[i]);
|
||||||
|
}
|
||||||
|
else if (param[i] == 39)
|
||||||
|
{
|
||||||
|
u16 default_foreground = DEFAULT_CHAR_COLOR & 0x0f00;
|
||||||
|
vgabuf->color = (vgabuf->color & 0xf0ff) | default_foreground;
|
||||||
|
}
|
||||||
|
else if (40 <= param[i] && param[i] <= 47)
|
||||||
|
{
|
||||||
|
param[i] -= 40;
|
||||||
|
param12vga_color(&(param[i]));
|
||||||
|
vgabuf->color = (vgabuf->color & 0x8fff) | BACKGROUND(param[i]);
|
||||||
|
}
|
||||||
|
else if (param[i] == 49)
|
||||||
|
{
|
||||||
|
u16 default_background = DEFAULT_CHAR_COLOR & 0xf000;
|
||||||
|
vgabuf->color = (vgabuf->color & 0x0fff) | default_background;
|
||||||
|
}
|
||||||
|
else if (90 <= param[i] && param[i] <= 97)
|
||||||
|
{
|
||||||
|
param[i] -= 90;
|
||||||
|
param12vga_color(&(param[i]));
|
||||||
|
param[i] |= 0x8;
|
||||||
|
vgabuf->color = (vgabuf->color & 0xf0ff) | FOREGROUND(param[i]);
|
||||||
|
}
|
||||||
|
else if (100 <= param[i] && param[i] <= 107)
|
||||||
|
{
|
||||||
|
param[i] -= 100;
|
||||||
|
param12vga_color(&(param[i]));
|
||||||
|
param[i] |= 0x8;
|
||||||
|
vgabuf->color = (vgabuf->color & 0x0fff) | BACKGROUND(param[i]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
warn("\x1b[47;93munsupport CSI: sgr param[%d]:%d\x1b[m\n", i, param[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
|
i16 param[MAXNUM_PARAM] = {0};
|
||||||
|
i16 param_cnt = 0;
|
||||||
|
for (int i = 0; i < vgabuf->param_num && param_cnt < MAXNUM_PARAM; i++)
|
||||||
|
{
|
||||||
|
u8 ch = vgabuf->param_c[i];
|
||||||
|
if (ch != ';')
|
||||||
|
{
|
||||||
|
param[param_cnt] = param[param_cnt] * 10 + ch - '0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
param_cnt++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (terminator)
|
||||||
|
{
|
||||||
|
case 'A': // Cursor Up
|
||||||
|
if (param[0] == 0)
|
||||||
|
param[0] = 1;
|
||||||
|
cursor_move(-param[0], 0, vgabuf);
|
||||||
|
break;
|
||||||
|
case 'B': // Cursor Down
|
||||||
|
if (param[0] == 0)
|
||||||
|
param[0] = 1;
|
||||||
|
cursor_move(+param[0], 0, vgabuf);
|
||||||
|
break;
|
||||||
|
case 'C': // Cursor Forward
|
||||||
|
if (param[0] == 0)
|
||||||
|
param[0] = 1;
|
||||||
|
cursor_move(0, +param[0], vgabuf);
|
||||||
|
break;
|
||||||
|
case 'D': // Cursor Back
|
||||||
|
if (param[0] == 0)
|
||||||
|
param[0] = 1;
|
||||||
|
cursor_move(0, -param[0], vgabuf); // nothing
|
||||||
|
break;
|
||||||
|
case 'E': // Cursor Next Line
|
||||||
|
if (param[0] == 0)
|
||||||
|
param[0] = 1;
|
||||||
|
cursor_move(+param[0], -vgabuf->cur_col, vgabuf);
|
||||||
|
break;
|
||||||
|
case 'F': // Cursor Previous Line
|
||||||
|
if (param[0] == 0)
|
||||||
|
param[0] = 1;
|
||||||
|
cursor_move(-param[0], -vgabuf->cur_col, vgabuf);
|
||||||
|
break;
|
||||||
|
case 'G': // Cursor Horizontal Absolute
|
||||||
|
if (param[0] == 0)
|
||||||
|
param[0] = 1;
|
||||||
|
cursor_locate(CYCLE_SUB(vgabuf->scr_top_line, vgabuf->scr_cur_line, SCR_MAXLINE), param[0] - 1, vgabuf);
|
||||||
|
break;
|
||||||
|
case 'H': // Cursor Position
|
||||||
|
case 'f':
|
||||||
|
if (param[0] == 0)
|
||||||
|
param[0] = 1;
|
||||||
|
if (param[1] == 0)
|
||||||
|
param[1] = 1;
|
||||||
|
cursor_locate(param[0] - 1, param[1] - 1, vgabuf);
|
||||||
|
break;
|
||||||
|
case 'J': // Erase in Display
|
||||||
|
if (param[0] == 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 (param[0] == 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 (param[0] == 2)
|
||||||
|
// The whole screen
|
||||||
|
CSI_Erase_handler(vgabuf, 2);
|
||||||
|
else if (param[0] == 3)
|
||||||
|
// The whole screen and the buffer
|
||||||
|
CSI_Erase_handler(vgabuf, 3);
|
||||||
|
break;
|
||||||
|
case 'K': // Erase in Line
|
||||||
|
if (param[0] == 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 (param[0] == 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 (param[0] == 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 (param[0] == 0)
|
||||||
|
param[0] = 1;
|
||||||
|
csi_scroll(vgabuf, -param[0]);
|
||||||
|
break;
|
||||||
|
case 'T': // Scroll Down
|
||||||
|
if (param[0] == 0)
|
||||||
|
param[0] = 1;
|
||||||
|
csi_scroll(vgabuf, +param[0]);
|
||||||
|
break;
|
||||||
|
case 'm': // Select Graphic Rendition
|
||||||
|
set_color(param_cnt, param, vgabuf);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -141,7 +141,7 @@ static u32 exec_elfcpy(u32 fd, Elf32_Phdr Echo_Phdr, u32 attribute) // 这部分
|
|||||||
// 已初始化数据段拷贝完毕,剩下的是未初始化的数据段,在内存中填0
|
// 已初始化数据段拷贝完毕,剩下的是未初始化的数据段,在内存中填0
|
||||||
*((u8 *)lin_addr) = 0; // memset((void*)lin_addr,0,1);
|
*((u8 *)lin_addr) = 0; // memset((void*)lin_addr,0,1);
|
||||||
}
|
}
|
||||||
if (!(lin_addr & 0x3f)) kprintf(".");
|
// if (!(lin_addr & 0x3f)) kprintf(".");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ static u32 exec_load(u32 fd, const Elf32_Ehdr *Echo_Ehdr, const Elf32_Phdr Echo_
|
|||||||
kprintf("\x1b[31;47mexec_load: elf ERROR!\x1b[m", 0x74);
|
kprintf("\x1b[31;47mexec_load: elf ERROR!\x1b[m", 0x74);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
kprintf("loading elf from file");
|
// kprintf("loading elf from file");
|
||||||
|
|
||||||
// 我们还不能确定elf中一共能有几个program,但就目前我们查看过的elf文件中,只出现过两中program,一种.text(R-E)和一种.data(RW-)
|
// 我们还不能确定elf中一共能有几个program,但就目前我们查看过的elf文件中,只出现过两中program,一种.text(R-E)和一种.data(RW-)
|
||||||
for (ph_num = 0; ph_num < Echo_Ehdr->e_phnum; ph_num++)
|
for (ph_num = 0; ph_num < Echo_Ehdr->e_phnum; ph_num++)
|
||||||
@ -188,7 +188,7 @@ static u32 exec_load(u32 fd, const Elf32_Ehdr *Echo_Ehdr, const Elf32_Phdr Echo_
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kprintf("[\x1b[32mok\x1b[0m]\n");
|
// kprintf("[\x1b[32mok\x1b[0m]\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
#include "type.h"
|
#include "type.h"
|
||||||
#include "x86.h"
|
#include "x86.h"
|
||||||
#include "yieldlock.h"
|
|
||||||
#include "fs.h" //added by mingxuan 2019-5-19
|
#include "fs.h" //added by mingxuan 2019-5-19
|
||||||
#include "vfs.h"
|
#include "vfs.h"
|
||||||
|
|
||||||
@ -67,7 +66,7 @@ static void fbcon_draw_raw(int row, int col, char ch) {
|
|||||||
static void fbcon_draw_hzk(int row, int col, u16 ch) {
|
static void fbcon_draw_hzk(int row, int col, u16 ch) {
|
||||||
u8 code0 = ((ch >> 8) & 0xff);
|
u8 code0 = ((ch >> 8) & 0xff);
|
||||||
u8 code1 = (ch & 0xff);
|
u8 code1 = (ch & 0xff);
|
||||||
if (code0 == 0) {fbcon_draw_raw(row, col, code1); return; }
|
if (code0 < 0xa0) {fbcon_draw_raw(row, col, code1); return; }
|
||||||
else { code0 -= 0xa0; code1 -= 0xa0; }
|
else { code0 -= 0xa0; code1 -= 0xa0; }
|
||||||
u32 offset = (94 * (code0 - 1) + (code1 - 1)) * 32;
|
u32 offset = (94 * (code0 - 1) + (code1 - 1)) * 32;
|
||||||
u16* hzk16h = (u16*)&hzk16h_buf[offset];
|
u16* hzk16h = (u16*)&hzk16h_buf[offset];
|
||||||
@ -79,6 +78,9 @@ static void fbcon_draw_hzk(int row, int col, u16 ch) {
|
|||||||
if (bigend & (1 << (x))) {
|
if (bigend & (1 << (x))) {
|
||||||
clr ^= 0xffffffff;
|
clr ^= 0xffffffff;
|
||||||
}
|
}
|
||||||
|
// if ((u32)cur_fb + ind * 4 == 0xfd600000) {
|
||||||
|
// kprintf("%x %d %d %d %d\n", ch, col, row, x, y);
|
||||||
|
// }
|
||||||
cur_fb[ind] = clr;
|
cur_fb[ind] = clr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -80,5 +80,3 @@ system_call sys_call_table[NR_SYS_CALL] = {
|
|||||||
sys_mmap,
|
sys_mmap,
|
||||||
};
|
};
|
||||||
|
|
||||||
TTY tty_table[NR_CONSOLES]; // added by mingxuan 2019-5-19
|
|
||||||
s_console console_table[NR_CONSOLES]; // added by mingxuan 2019-5-19
|
|
||||||
@ -15,7 +15,6 @@
|
|||||||
#include "minix_keymap.h"
|
#include "minix_keymap.h"
|
||||||
#include "serialport.h"
|
#include "serialport.h"
|
||||||
#include "memman.h"
|
#include "memman.h"
|
||||||
#include "yieldlock.h"
|
|
||||||
|
|
||||||
static int code_with_E0;
|
static int code_with_E0;
|
||||||
static int shift_l; /* l shift state */
|
static int shift_l; /* l shift state */
|
||||||
@ -361,11 +360,12 @@ static void kbd_process(unsigned char scode)
|
|||||||
set_leds();
|
set_leds();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
if (press)
|
||||||
|
cur_ntty->recvbuf(cur_ntty, map_key(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
// inputdriver_send_event(FALSE /*mouse*/, page, code, press, 0);
|
// inputdriver_send_event(FALSE /*mouse*/, page, code, press, 0);
|
||||||
if (press)
|
|
||||||
cur_ntty->recvbuf(cur_ntty, map_key(code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kbd_state = 0;
|
kbd_state = 0;
|
||||||
@ -405,7 +405,7 @@ int ps2_tty_read(NTTY *tty, char *buf, int nr)
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
release_y(&kbdlock);
|
xchg(&kbdlock, 0);
|
||||||
sys_yield();
|
sys_yield();
|
||||||
}
|
}
|
||||||
assert(kbd->buf);
|
assert(kbd->buf);
|
||||||
@ -418,7 +418,7 @@ int ps2_tty_read(NTTY *tty, char *buf, int nr)
|
|||||||
}
|
}
|
||||||
kbd->readable -= i;
|
kbd->readable -= i;
|
||||||
kbd->len -= i;
|
kbd->len -= i;
|
||||||
release_y(&kbdlock);
|
xchg(&kbdlock, 0);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,7 +495,7 @@ void ps2_tty_recvbuf(NTTY *tty, u32 key)
|
|||||||
kbd->len++;
|
kbd->len++;
|
||||||
kbd->tail = NEXTKEY(kbd->tail);
|
kbd->tail = NEXTKEY(kbd->tail);
|
||||||
kbd->readable = CYCLE_SUB(kbd->head, kbd->tail, TTY_IN_BYTES);
|
kbd->readable = CYCLE_SUB(kbd->head, kbd->tail, TTY_IN_BYTES);
|
||||||
release_y(&kbdlock);
|
xchg(&kbdlock, 0);
|
||||||
// kprintf("len=%d, h=%d, t=%d, rd=%d\n", kbd->len, kbd->head, kbd->tail, kbd->readable);
|
// kprintf("len=%d, h=%d, t=%d, rd=%d\n", kbd->len, kbd->head, kbd->tail, kbd->readable);
|
||||||
break;
|
break;
|
||||||
case '\b':
|
case '\b':
|
||||||
@ -510,11 +510,12 @@ void ps2_tty_recvbuf(NTTY *tty, u32 key)
|
|||||||
kbd->len--;
|
kbd->len--;
|
||||||
kbd->tail = LASTKEY(kbd->tail);
|
kbd->tail = LASTKEY(kbd->tail);
|
||||||
}
|
}
|
||||||
release_y(&kbdlock);
|
xchg(&kbdlock, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
while (xchg(&kbdlock, 1) == 1);
|
while (xchg(&kbdlock, 1) == 1)
|
||||||
|
sys_yield();
|
||||||
if ((key & 0xff) == 0)
|
if ((key & 0xff) == 0)
|
||||||
return;
|
return;
|
||||||
if (kbd->len == TTY_IN_BYTES - 1)
|
if (kbd->len == TTY_IN_BYTES - 1)
|
||||||
@ -523,7 +524,7 @@ void ps2_tty_recvbuf(NTTY *tty, u32 key)
|
|||||||
// kprintf("%d %d %d", key & 0xff, kbd->tail, buf[kbd->tail]);
|
// kprintf("%d %d %d", key & 0xff, kbd->tail, buf[kbd->tail]);
|
||||||
kbd->len++;
|
kbd->len++;
|
||||||
kbd->tail = NEXTKEY(kbd->tail);
|
kbd->tail = NEXTKEY(kbd->tail);
|
||||||
release_y(&kbdlock);
|
xchg(&kbdlock, 0);
|
||||||
tty->write(tty, key);
|
tty->write(tty, key);
|
||||||
// kprintf("len=%d, h=%d, t=%d, rd=%d\n", kbd->len, kbd->head, kbd->tail, kbd->readable);
|
// kprintf("len=%d, h=%d, t=%d, rd=%d\n", kbd->len, kbd->head, kbd->tail, kbd->readable);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -153,7 +153,7 @@ void initial()
|
|||||||
#ifdef USE_FBCON
|
#ifdef USE_FBCON
|
||||||
exec("orange/shell_chn.bin");
|
exec("orange/shell_chn.bin");
|
||||||
#else
|
#else
|
||||||
exec("orange/shell_mix.bin");
|
exec("orange/shell_1.bin");
|
||||||
#endif
|
#endif
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
void schedule()
|
void schedule()
|
||||||
{
|
{
|
||||||
PROCESS* p;
|
PROCESS* p;
|
||||||
|
#ifdef USE_FBCON
|
||||||
for (int i = NEXT(p_proc_current->task.pid, NR_PCBS); i != p_proc_current->task.pid; i = NEXT(i, NR_PCBS)) {
|
for (int i = NEXT(p_proc_current->task.pid, NR_PCBS); i != p_proc_current->task.pid; i = NEXT(i, NR_PCBS)) {
|
||||||
if (proc_table[i].task.stat == READY) {
|
if (proc_table[i].task.stat == READY) {
|
||||||
p_proc_next = &proc_table[i];
|
p_proc_next = &proc_table[i];
|
||||||
@ -27,36 +28,37 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
p_proc_next = p_proc_current;
|
p_proc_next = p_proc_current;
|
||||||
// kprintf("shit\n");
|
#else
|
||||||
|
|
||||||
// int greatest_ticks = 0;
|
int greatest_ticks = 0;
|
||||||
// //Added by xw, 18/4/21
|
//Added by xw, 18/4/21
|
||||||
// if (p_proc_current->task.stat == READY && p_proc_current->task.ticks > 0) {
|
if (p_proc_current->task.stat == READY && p_proc_current->task.ticks > 0) {
|
||||||
// p_proc_next = p_proc_current; //added by xw, 18/4/26
|
p_proc_next = p_proc_current; //added by xw, 18/4/26
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// while (!greatest_ticks)
|
while (!greatest_ticks)
|
||||||
// {
|
{
|
||||||
// for (p = proc_table; p < proc_table+NR_PCBS; p++) //edit by visual 2016.4.5
|
for (p = proc_table; p < proc_table+NR_PCBS; p++) //edit by visual 2016.4.5
|
||||||
// {
|
{
|
||||||
// if (p->task.stat == READY && p->task.ticks > greatest_ticks) //edit by visual 2016.4.5
|
if (p->task.stat == READY && p->task.ticks > greatest_ticks) //edit by visual 2016.4.5
|
||||||
// {
|
{
|
||||||
// greatest_ticks = p->task.ticks;
|
greatest_ticks = p->task.ticks;
|
||||||
// // p_proc_current = p;
|
// p_proc_current = p;
|
||||||
// p_proc_next = p; //modified by xw, 18/4/26
|
p_proc_next = p; //modified by xw, 18/4/26
|
||||||
// }
|
}
|
||||||
|
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (!greatest_ticks)
|
if (!greatest_ticks)
|
||||||
// {
|
{
|
||||||
// for (p = proc_table; p < proc_table+NR_PCBS; p++) //edit by visual 2016.4.5
|
for (p = proc_table; p < proc_table+NR_PCBS; p++) //edit by visual 2016.4.5
|
||||||
// {
|
{
|
||||||
// p->task.ticks = p->task.priority;
|
p->task.ticks = p->task.priority;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*======================================================================*
|
/*======================================================================*
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
start.c
|
start.c
|
||||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
Forrest Yu, 2005
|
Forrest Yu, 2005
|
||||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
@ -17,8 +17,7 @@
|
|||||||
/*
|
/*
|
||||||
* 当发生不可挽回的错误时就打印错误信息并使CPU核休眠
|
* 当发生不可挽回的错误时就打印错误信息并使CPU核休眠
|
||||||
*/
|
*/
|
||||||
void
|
void _panic(const char *file, int line, const char *fmt, ...)
|
||||||
_panic(const char *file, int line, const char *fmt,...)
|
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@ -32,49 +31,47 @@ _panic(const char *file, int line, const char *fmt,...)
|
|||||||
kprintf("\n");
|
kprintf("\n");
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
// 休眠CPU核,直接罢工
|
// 休眠CPU核,直接罢工
|
||||||
while(1)
|
while (1)
|
||||||
asm volatile("hlt");
|
asm volatile("hlt");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 很像panic,但是不会休眠CPU核,就是正常打印信息
|
* 很像panic,但是不会休眠CPU核,就是正常打印信息
|
||||||
*/
|
*/
|
||||||
void
|
void _warn(const char *file, int line, const char *fmt, ...)
|
||||||
_warn(const char *file, int line, const char *fmt,...)
|
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
kprintf("kernel warning at %s:%d: ", file, line);
|
kprintf("\x1b[47;93mkernel warning at %s:%d: \x1b[m", file, line);
|
||||||
vkprintf(fmt, ap);
|
vkprintf(fmt, ap);
|
||||||
kprintf("\n");
|
kprintf("\n");
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*
|
/*======================================================================*
|
||||||
cstart
|
cstart
|
||||||
*======================================================================*/
|
*======================================================================*/
|
||||||
void cstart()
|
void cstart()
|
||||||
{
|
{
|
||||||
kprintf("-----\"cstart\" begins-----\n");
|
kprintf("-----\"cstart\" begins-----\n");
|
||||||
|
|
||||||
// 将 LOADER 中的 GDT 复制到新的 GDT 中
|
// 将 LOADER 中的 GDT 复制到新的 GDT 中
|
||||||
memcpy( &gdt, // New GDT
|
memcpy(&gdt, // New GDT
|
||||||
(void*)(*((u32*)(&gdt_ptr[2]))), // Base of Old GDT
|
(void *)(*((u32 *)(&gdt_ptr[2]))), // Base of Old GDT
|
||||||
*((u16*)(&gdt_ptr[0])) + 1 // Limit of Old GDT
|
*((u16 *)(&gdt_ptr[0])) + 1 // Limit of Old GDT
|
||||||
);
|
);
|
||||||
// gdt_ptr[6] 共 6 个字节:0~15:Limit 16~47:Base。用作 sgdt 以及 lgdt 的参数。
|
// gdt_ptr[6] 共 6 个字节:0~15:Limit 16~47:Base。用作 sgdt 以及 lgdt 的参数。
|
||||||
u16* p_gdt_limit = (u16*)(&gdt_ptr[0]);
|
u16 *p_gdt_limit = (u16 *)(&gdt_ptr[0]);
|
||||||
u32* p_gdt_base = (u32*)(&gdt_ptr[2]);
|
u32 *p_gdt_base = (u32 *)(&gdt_ptr[2]);
|
||||||
*p_gdt_limit = GDT_SIZE * sizeof(DESCRIPTOR) - 1;
|
*p_gdt_limit = GDT_SIZE * sizeof(DESCRIPTOR) - 1;
|
||||||
*p_gdt_base = (u32)&gdt;
|
*p_gdt_base = (u32)&gdt;
|
||||||
|
|
||||||
// idt_ptr[6] 共 6 个字节:0~15:Limit 16~47:Base。用作 sidt 以及 lidt 的参数。
|
// idt_ptr[6] 共 6 个字节:0~15:Limit 16~47:Base。用作 sidt 以及 lidt 的参数。
|
||||||
u16* p_idt_limit = (u16*)(&idt_ptr[0]);
|
u16 *p_idt_limit = (u16 *)(&idt_ptr[0]);
|
||||||
u32* p_idt_base = (u32*)(&idt_ptr[2]);
|
u32 *p_idt_base = (u32 *)(&idt_ptr[2]);
|
||||||
*p_idt_limit = IDT_SIZE * sizeof(GATE) - 1;
|
*p_idt_limit = IDT_SIZE * sizeof(GATE) - 1;
|
||||||
*p_idt_base = (u32)&idt;
|
*p_idt_base = (u32)&idt;
|
||||||
|
|
||||||
init_prot();
|
init_prot();
|
||||||
|
|
||||||
|
|||||||
47
kernel/tty.c
47
kernel/tty.c
@ -14,24 +14,26 @@
|
|||||||
#include "serialport.h"
|
#include "serialport.h"
|
||||||
#include "bga.h"
|
#include "bga.h"
|
||||||
|
|
||||||
|
|
||||||
int tty_ok = 0;
|
int tty_ok = 0;
|
||||||
void tty_write(NTTY *tty, char *buf, int len);
|
void tty_write(NTTY *tty, char *buf, int len);
|
||||||
int tty_read(NTTY *tty, char *buf, int len);
|
int tty_read(NTTY *tty, char *buf, int len);
|
||||||
|
|
||||||
NTTY* cur_ntty;
|
NTTY *cur_ntty;
|
||||||
NTTY* ntty_table[NR_CONSOLES];
|
NTTY *ntty_table[NR_CONSOLES];
|
||||||
|
|
||||||
static void write_default_tty(char ch) {
|
static void write_default_tty(char ch)
|
||||||
|
{
|
||||||
cur_ntty->write(cur_ntty, ch);
|
cur_ntty->write(cur_ntty, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline NTTY* get_tty(const int nr_tty) {
|
inline NTTY *get_tty(const int nr_tty)
|
||||||
if (nr_tty >= NR_CONSOLES || nr_tty < 0) return NULL;
|
{
|
||||||
|
if (nr_tty >= NR_CONSOLES || nr_tty < 0)
|
||||||
|
return NULL;
|
||||||
return ntty_table[nr_tty];
|
return ntty_table[nr_tty];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ps2_vga_ioctl(NTTY* tty, u32 cmd, long arg)
|
static int ps2_vga_ioctl(NTTY *tty, u32 cmd, long arg)
|
||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
@ -40,11 +42,14 @@ static int ps2_vga_ioctl(NTTY* tty, u32 cmd, long arg)
|
|||||||
vga_tty_scroll(tty, arg);
|
vga_tty_scroll(tty, arg);
|
||||||
break;
|
break;
|
||||||
case IOCTL_CMD_TTY_SELECTCON:
|
case IOCTL_CMD_TTY_SELECTCON:
|
||||||
if (get_tty(arg) == NULL || get_tty(arg)->driver_type != 1) retval = -1;
|
if (get_tty(arg) == NULL || get_tty(arg)->driver_type != 1)
|
||||||
else vga_tty_select(get_tty(arg));
|
retval = -1;
|
||||||
|
else
|
||||||
|
vga_tty_select(get_tty(arg));
|
||||||
break;
|
break;
|
||||||
case IOCTL_CMD_TTY_FLUSH:
|
case IOCTL_CMD_TTY_FLUSH:
|
||||||
if (tty == cur_ntty) vga_tty_flush(tty);
|
if (tty == cur_ntty)
|
||||||
|
vga_tty_flush(tty);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -52,7 +57,7 @@ static int ps2_vga_ioctl(NTTY* tty, u32 cmd, long arg)
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dummy_ioctl(NTTY* tty, u32 cmd, long arg) {return 0;}
|
static int dummy_ioctl(NTTY *tty, u32 cmd, long arg) { return 0; }
|
||||||
|
|
||||||
void init_tty_main()
|
void init_tty_main()
|
||||||
{
|
{
|
||||||
@ -87,12 +92,12 @@ void init_tty_main()
|
|||||||
for (int i = 1; i < 2; ++i)
|
for (int i = 1; i < 2; ++i)
|
||||||
{
|
{
|
||||||
// tty = &ntty_table[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->driver_type = 1; // vga
|
||||||
// tty->input_buf = (void*)do_kmalloc(sizeof(keyboard_buf));
|
// tty->input_buf = (void*)do_kmalloc(sizeof(keyboard_buf));
|
||||||
// tty->output_buf = (void*)do_kmalloc(sizeof(vga_buf));
|
// tty->output_buf = (void*)do_kmalloc(sizeof(vga_buf));
|
||||||
tty->input_buf = (keyboard_buf*)K_PHY2LIN(do_kmalloc(sizeof(keyboard_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->output_buf = (vga_buf *)K_PHY2LIN(do_kmalloc(sizeof(vga_buf)));
|
||||||
vga_tty_init(tty);
|
vga_tty_init(tty);
|
||||||
ps2_tty_init(tty);
|
ps2_tty_init(tty);
|
||||||
tty->write = vga_tty_write;
|
tty->write = vga_tty_write;
|
||||||
@ -101,10 +106,11 @@ void init_tty_main()
|
|||||||
tty->ioctl = ps2_vga_ioctl;
|
tty->ioctl = ps2_vga_ioctl;
|
||||||
ntty_table[i] = tty;
|
ntty_table[i] = tty;
|
||||||
}
|
}
|
||||||
for (int i = 2; i < 3; ++ i) {
|
for (int i = 2; i < 3; ++i)
|
||||||
tty = (NTTY*)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
|
{
|
||||||
|
tty = (NTTY *)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
|
||||||
tty->driver_type = 2;
|
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)));
|
||||||
tty->output_buf = NULL;
|
tty->output_buf = NULL;
|
||||||
serial_tty_init_i(tty);
|
serial_tty_init_i(tty);
|
||||||
serial_tty_init_o(tty);
|
serial_tty_init_o(tty);
|
||||||
@ -121,7 +127,6 @@ void init_tty_main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* tty_write
|
* tty_write
|
||||||
****************************************************************************
|
****************************************************************************
|
||||||
@ -130,12 +135,14 @@ void init_tty_main()
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void tty_write(NTTY *tty, char *buf, int len)
|
void tty_write(NTTY *tty, char *buf, int len)
|
||||||
{
|
{
|
||||||
if (!tty_ok) {
|
if (!tty_ok)
|
||||||
|
{
|
||||||
simpleconsole_write(buf, len);
|
simpleconsole_write(buf, len);
|
||||||
// while (--len >= 0) write_serial(*buf++);
|
// while (--len >= 0) write_serial(*buf++);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
while (--len >= 0)
|
while (--len >= 0)
|
||||||
{
|
{
|
||||||
tty->write(tty, *buf++);
|
tty->write(tty, *buf++);
|
||||||
|
|||||||
409
kernel/vga.c
409
kernel/vga.c
@ -12,7 +12,7 @@
|
|||||||
#include "x86.h"
|
#include "x86.h"
|
||||||
#include "memman.h"
|
#include "memman.h"
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
|
#include "csi.h"
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Low level vga driver
|
* Low level vga driver
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
@ -133,6 +133,10 @@ void vga_tty_init(NTTY *tty)
|
|||||||
// buf->max_line = SCR_BUFSIZE / SCR_WIDTH;
|
// buf->max_line = SCR_BUFSIZE / SCR_WIDTH;
|
||||||
vga->scr_top_line = vga->scr_cur_line = vga->scr_bot_line = 0;
|
vga->scr_top_line = vga->scr_cur_line = vga->scr_bot_line = 0;
|
||||||
vga->head_line = 0;
|
vga->head_line = 0;
|
||||||
|
vga->IsColorReverse = false;
|
||||||
|
vga->IsHide = false;
|
||||||
|
vga->color = DEFAULT_CHAR_COLOR;
|
||||||
|
vga->CSI = CSI_ESC;
|
||||||
u32 *ptr_buf = (u32 *)vga->buf;
|
u32 *ptr_buf = (u32 *)vga->buf;
|
||||||
for (int i = 0; i < SCR_BUFSIZE * sizeof(u16) / sizeof(u32); ++i)
|
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 LASTLINE(row) LAST(row, SCR_MAXLINE)
|
||||||
#define ADDLINE(row, add_num) (((row) + add_num) % 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)
|
static void newline(vga_buf *vga)
|
||||||
{
|
{
|
||||||
u16 *buf = vga->buf;
|
u16 *buf = vga->buf;
|
||||||
vga->cur_col = 0;
|
vga->cur_col = 0;
|
||||||
// kprintf("bf %x\n", vgabuf->scr_cur_line);
|
|
||||||
vga->scr_cur_line = NEXTLINE(vga->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);
|
vga->cur_row = CYCLE_SUB(vga->scr_top_line, vga->scr_cur_line, SCR_MAXLINE);
|
||||||
if (vga->cur_row == SCR_HEIGHT)
|
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
|
*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)
|
void vga_tty_write(NTTY *tty, char ch)
|
||||||
{
|
{
|
||||||
// assert(tty->driver_type == 1);
|
// assert(tty->driver_type == 1);
|
||||||
@ -563,17 +217,9 @@ void vga_tty_write(NTTY *tty, char ch)
|
|||||||
break;
|
break;
|
||||||
case '\x1b':
|
case '\x1b':
|
||||||
vga->CSI = CSI_BRACKET;
|
vga->CSI = CSI_BRACKET;
|
||||||
vga->Is2param = false;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (vga->color == 0)
|
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);
|
|
||||||
}
|
|
||||||
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(DEFAULT_CHAR_COLOR, ch);
|
// buf[INDEX(vga->scr_cur_line, vga->cur_col)] = MAKE_CELL(DEFAULT_CHAR_COLOR, ch);
|
||||||
nextcol(vga);
|
nextcol(vga);
|
||||||
break;
|
break;
|
||||||
@ -584,8 +230,13 @@ void vga_tty_write(NTTY *tty, char ch)
|
|||||||
switch (ch)
|
switch (ch)
|
||||||
{
|
{
|
||||||
case '[':
|
case '[':
|
||||||
vga->CSI = CSI_PARAM1;
|
vga->CSI = CSI_PARAM;
|
||||||
vga->param1 = vga->param2 = 0;
|
// init
|
||||||
|
for (int i = 0; i < MAXNUM_PARAM_CH; i++)
|
||||||
|
{
|
||||||
|
vga->param_c[i] = 0;
|
||||||
|
}
|
||||||
|
vga->param_num = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
vga->CSI = CSI_ESC;
|
vga->CSI = CSI_ESC;
|
||||||
@ -606,20 +257,15 @@ void vga_tty_write(NTTY *tty, char ch)
|
|||||||
case '7':
|
case '7':
|
||||||
case '8':
|
case '8':
|
||||||
case '9':
|
case '9':
|
||||||
if (vga->CSI == CSI_PARAM1)
|
|
||||||
vga->param1 = vga->param1 * 10 + ch - '0';
|
|
||||||
else if (vga->CSI == CSI_PARAM2)
|
|
||||||
vga->param2 = vga->param2 * 10 + ch - '0';
|
|
||||||
else
|
|
||||||
; // do nothing
|
|
||||||
break;
|
|
||||||
case ';':
|
case ';':
|
||||||
vga->CSI = CSI_PARAM2;
|
if (vga->param_num < MAXNUM_PARAM_CH)
|
||||||
vga->Is2param = true;
|
{
|
||||||
|
vga->param_c[vga->param_num] = ch;
|
||||||
|
vga->param_num++;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!(0x20 <= ch && ch <= 0x7e))
|
vga->CSI = CSI_ESC;
|
||||||
vga->CSI = CSI_ESC;
|
|
||||||
if (0x40 <= ch && ch <= 0x7e)
|
if (0x40 <= ch && ch <= 0x7e)
|
||||||
CSI_handler(ch, vga);
|
CSI_handler(ch, vga);
|
||||||
break;
|
break;
|
||||||
@ -633,23 +279,6 @@ void vga_tty_write(NTTY *tty, char ch)
|
|||||||
// kprintf("row: %d; ", vga->cur_row);
|
// kprintf("row: %d; ", vga->cur_row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vga_tty_backspace(NTTY *tty)
|
|
||||||
{
|
|
||||||
vga_buf *vga = tty->output_buf;
|
|
||||||
u16 *buf = vga->buf;
|
|
||||||
if (vga->cur_col == 0)
|
|
||||||
{
|
|
||||||
vga->cur_col = SCR_WIDTH - 1;
|
|
||||||
vga->scr_cur_line = LASTLINE(vga->scr_cur_line);
|
|
||||||
}
|
|
||||||
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;
|
vga_buf *vga = tty->output_buf;
|
||||||
|
|||||||
@ -8,10 +8,10 @@
|
|||||||
|
|
||||||
static void kprintfputch(int ch, int *cnt)
|
static void kprintfputch(int ch, int *cnt)
|
||||||
{
|
{
|
||||||
write_serial(ch);
|
// write_serial(ch);
|
||||||
#ifndef USE_FBCON
|
#ifndef USE_FBCON
|
||||||
// char _ch = ch;
|
char _ch = ch;
|
||||||
//tty_write(cur_ntty, &_ch, 1);
|
tty_write(cur_ntty, &_ch, 1);
|
||||||
#endif
|
#endif
|
||||||
(*cnt)++;
|
(*cnt)++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,13 +6,19 @@ USERLIB_OBJS := $(patsubst %.c, $(OBJDIR)/%.o, $(USERLIB_SRCS))
|
|||||||
USERLIB_OBJS := $(patsubst %.asm, $(OBJDIR)/%.o, $(USERLIB_OBJS))
|
USERLIB_OBJS := $(patsubst %.asm, $(OBJDIR)/%.o, $(USERLIB_OBJS))
|
||||||
|
|
||||||
# 这里给我整不会了,文件名只能长度为16位,否则会寄,原因还挺难找
|
# 这里给我整不会了,文件名只能长度为16位,否则会寄,原因还挺难找
|
||||||
USER_SRCS := user/shell_2con.c \
|
USER_SRCS := user/shell_1.c \
|
||||||
user/shell_chn.c \
|
user/shell_0.c \
|
||||||
user/shell_mix.c \
|
user/test.c \
|
||||||
user/shell_uart.c \
|
user/test2.c \
|
||||||
user/test2con.c \
|
user/sgr_test.c \
|
||||||
user/testchn.c \
|
user/cur_test.c \
|
||||||
user/testscr.c \
|
user/shell_2con.c \
|
||||||
|
user/shell_chn.c \
|
||||||
|
user/shell_mix.c \
|
||||||
|
user/shell_uart.c \
|
||||||
|
user/test2con.c \
|
||||||
|
user/testchn.c \
|
||||||
|
user/testscr.c \
|
||||||
|
|
||||||
USER_BINS := $(patsubst %.c, $(OBJDIR)/%.bin, $(USER_SRCS))
|
USER_BINS := $(patsubst %.c, $(OBJDIR)/%.bin, $(USER_SRCS))
|
||||||
USER_BASENAMES := $(patsubst $(OBJDIR)/user/%, %, $(USER_BINS))
|
USER_BASENAMES := $(patsubst $(OBJDIR)/user/%, %, $(USER_BINS))
|
||||||
|
|||||||
99
user/cur_test.c
Normal file
99
user/cur_test.c
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
#include "type.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "protect.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "proc.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include "proto.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
void delay(int time)
|
||||||
|
{
|
||||||
|
int i, j, k;
|
||||||
|
for (k = 0; k < time; k++)
|
||||||
|
{
|
||||||
|
for (i = 0; i < 10000; i++)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 10000; j++)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int main(int arg, char *argv[])
|
||||||
|
{
|
||||||
|
int stdin = open("dev_tty0", O_RDWR);
|
||||||
|
int stdout = open("dev_tty0", O_RDWR);
|
||||||
|
int stderr = open("dev_tty0", O_RDWR);
|
||||||
|
|
||||||
|
for (int i = 0; i < 30; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 10; j++)
|
||||||
|
printf("%d*", i);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
delay(2);
|
||||||
|
|
||||||
|
// clear line and cursor to the start of line
|
||||||
|
printf("\x1b[2K\x1b[1G");
|
||||||
|
printf("\x1b[31mCursor Up and Cursor Forward\x1b[m");
|
||||||
|
delay(2);
|
||||||
|
for (int i = 1; i < 90; i++)
|
||||||
|
{
|
||||||
|
printf("\x1b[%dA\x1b[%dC", i, i);
|
||||||
|
i += i;
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(3);
|
||||||
|
printf("\x1b[2K\x1b[1G");
|
||||||
|
printf("\x1b[32mCursor Down and Cursor Back\x1b[m");
|
||||||
|
delay(2);
|
||||||
|
for (int i = 1; i < 90; i++)
|
||||||
|
{
|
||||||
|
printf("\x1b[%dB\x1b[%dD", i, i);
|
||||||
|
i += i;
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(3);
|
||||||
|
printf("\x1b[2K\x1b[G");
|
||||||
|
printf("\x1b[33mCursor Previous Line\x1b[m");
|
||||||
|
delay(2);
|
||||||
|
for (int i = 1; i < 90; i++)
|
||||||
|
{
|
||||||
|
printf("\x1b[%dF", i, i);
|
||||||
|
i += i;
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
// Scroll Up:5 lines
|
||||||
|
delay(1);
|
||||||
|
printf("\x1b[2K\x1b[G");
|
||||||
|
printf("\x1b[34mScroll Up:5 lines\x1b[m");
|
||||||
|
delay(6);
|
||||||
|
printf("\x1b[5S");
|
||||||
|
delay(10);
|
||||||
|
|
||||||
|
// Scroll Up:27 lines
|
||||||
|
printf("\x1b[2K\x1b[G");
|
||||||
|
printf("\x1b[34mScroll Up:27 lines\x1b[m");
|
||||||
|
delay(6);
|
||||||
|
printf("\x1b[27S");
|
||||||
|
delay(10);
|
||||||
|
|
||||||
|
// Erase in Display n=3
|
||||||
|
printf("\x1b[2K\x1b[G");
|
||||||
|
printf("\x1b[35mErase in Display n=3 \x1b[m");
|
||||||
|
delay(6);
|
||||||
|
printf("\x1b[3J");
|
||||||
|
delay(10);
|
||||||
|
|
||||||
|
// Erase in Display n=0
|
||||||
|
printf("\x1b[2K\x1b[G");
|
||||||
|
printf("\x1b[36mErase in Display n=1 \x1b[m");
|
||||||
|
delay(6);
|
||||||
|
printf("\x1b[1J");
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
42
user/sgr_test.c
Normal file
42
user/sgr_test.c
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#include "type.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "protect.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "proc.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include "proto.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
int main(int arg, char *argv[])
|
||||||
|
{
|
||||||
|
int stdin = open("dev_tty0", O_RDWR);
|
||||||
|
int stdout = open("dev_tty0", O_RDWR);
|
||||||
|
int stderr = open("dev_tty0", O_RDWR);
|
||||||
|
|
||||||
|
printf("set color:\n");
|
||||||
|
for (int i = 30; i <= 37; i++)
|
||||||
|
{
|
||||||
|
printf(" \x1b[%d;%dm Hello minios!! \x1b[m\n", i, 47 - (i - 30));
|
||||||
|
}
|
||||||
|
for (int i = 90; i <= 97; i++)
|
||||||
|
{
|
||||||
|
printf(" \x1b[%d;%dm Hello minios!! \x1b[m\n", i, 107 - (i - 90));
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("reverse:\n");
|
||||||
|
printf(" \x1b[32;47m Hello minios!! \n");
|
||||||
|
printf(" \x1b[7m Hello minios!! \x1b[m\n");
|
||||||
|
|
||||||
|
printf("hide:\n");
|
||||||
|
printf(" \x1b[32;47;m Hello minios!! \n");
|
||||||
|
printf(" \x1b[8m Hello minios!! \x1b[m\n");
|
||||||
|
|
||||||
|
printf("reset:\n");
|
||||||
|
printf(" \x1b[m Hello minios!! \n");
|
||||||
|
|
||||||
|
printf("\n\n");
|
||||||
|
printf(" \x1b[5m Hello minios!!\n \x1b[29m \n\x1b[61;67m\n");
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
31
user/shell_0.c
Normal file
31
user/shell_0.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "type.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "protect.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "proc.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include "proto.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
int main(int arg, char *argv[])
|
||||||
|
{
|
||||||
|
int stdin = open("dev_tty2", O_RDWR);
|
||||||
|
int stdout = open("dev_tty2", O_RDWR);
|
||||||
|
int stderr = open("dev_tty2", O_RDWR);
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
int pid;
|
||||||
|
int times = 0;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
printf("\nminiOS:/ $ ");
|
||||||
|
if (gets(buf) && strlen(buf) != 0)
|
||||||
|
{
|
||||||
|
if (exec(buf) != 0)
|
||||||
|
{
|
||||||
|
printf("exec failed: file not found!\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
55
user/shell_1.c
Normal file
55
user/shell_1.c
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#include "type.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "protect.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "proc.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include "proto.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
int main(int arg, char *argv[])
|
||||||
|
{
|
||||||
|
if (0 == fork()) {
|
||||||
|
int stdin = open("dev_tty0", O_RDWR);
|
||||||
|
int stdout = open("dev_tty0", O_RDWR);
|
||||||
|
int stderr = open("dev_tty0", O_RDWR);
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
int pid;
|
||||||
|
int times = 0;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
printf("\nminiOS:/ $ ");
|
||||||
|
if (gets(buf) && strlen(buf) != 0)
|
||||||
|
{
|
||||||
|
if (exec(buf) != 0)
|
||||||
|
{
|
||||||
|
printf("exec failed: file not found!\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int stdin = open("dev_tty1", O_RDWR);
|
||||||
|
int stdout = open("dev_tty1", O_RDWR);
|
||||||
|
int stderr = open("dev_tty1", O_RDWR);
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
int pid;
|
||||||
|
int times = 0;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
printf("\nminiOS:/ $ ");
|
||||||
|
if (gets(buf) && strlen(buf) != 0)
|
||||||
|
{
|
||||||
|
printf("received\n");
|
||||||
|
if (exec(buf) != 0)
|
||||||
|
{
|
||||||
|
printf("exec failed: file not found!\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
87
user/test.c
Normal file
87
user/test.c
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#include "type.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "protect.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "proc.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include "proto.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
int main(int arg, char *argv[])
|
||||||
|
{
|
||||||
|
int stdin = open("dev_tty0", O_RDWR);
|
||||||
|
int stdout = open("dev_tty0", O_RDWR);
|
||||||
|
int stderr = open("dev_tty0", O_RDWR);
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
int pid;
|
||||||
|
int times = 0;
|
||||||
|
// for (int i = 0; i < 20; ++i)
|
||||||
|
// {
|
||||||
|
// printf("test %d\n", i);
|
||||||
|
// }
|
||||||
|
// for (int i = 0; i < 2; ++i)
|
||||||
|
// {
|
||||||
|
// printf("\x1b[42;31m1111111111");
|
||||||
|
// // printf("\x1b[m1111111111");
|
||||||
|
// printf("2222222222");
|
||||||
|
// printf("3333333333");
|
||||||
|
// printf("4444444444");
|
||||||
|
// printf("5555555555");
|
||||||
|
// printf("6666666666");
|
||||||
|
// printf("7777777777");
|
||||||
|
// // printf("\x1b[5F");
|
||||||
|
// printf("8888888888");
|
||||||
|
// printf("9999999999\r\b\b\n");
|
||||||
|
// }
|
||||||
|
// printf("\x1b[33m");
|
||||||
|
// printf("\x1b[1m");
|
||||||
|
for (int i = 0; i < 14; i++)
|
||||||
|
{
|
||||||
|
printf("%d", i);
|
||||||
|
printf("\x1b[m");
|
||||||
|
|
||||||
|
printf("11111111111111111\n");
|
||||||
|
}
|
||||||
|
printf("\x1b[6T11111111111111111\n");
|
||||||
|
|
||||||
|
// Cursor Up
|
||||||
|
// printf("\x1b[2A");
|
||||||
|
|
||||||
|
// Cursor down
|
||||||
|
// printf("\x1b[2B");
|
||||||
|
|
||||||
|
// Cursor Forward
|
||||||
|
// printf("\x1b[20C");
|
||||||
|
|
||||||
|
// Cursor Back
|
||||||
|
// printf("\x1b[2D");
|
||||||
|
|
||||||
|
// Cursor Next Line
|
||||||
|
// printf("\x1b[3E");
|
||||||
|
|
||||||
|
// Cursor Previous Line
|
||||||
|
// printf("\x1b[3F");
|
||||||
|
|
||||||
|
// Cursor Horizontal Absolute
|
||||||
|
// printf("\x1b[2G");
|
||||||
|
|
||||||
|
// Cursor Position ; H or f
|
||||||
|
// printf("\x1b[3;5H");
|
||||||
|
|
||||||
|
// Erase in Display
|
||||||
|
// printf("\x1b[3J");
|
||||||
|
|
||||||
|
// Erase in Line
|
||||||
|
// printf("\x1b[K");
|
||||||
|
|
||||||
|
// Scroll Up
|
||||||
|
// printf("\x1b[13S");
|
||||||
|
|
||||||
|
// Scroll Down
|
||||||
|
// printf("\x1b[13T");
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
40
user/test2.c
Normal file
40
user/test2.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include "type.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "protect.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "proc.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include "proto.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
int main(int arg, char *argv[])
|
||||||
|
{
|
||||||
|
int pid = fork();
|
||||||
|
volatile int i;
|
||||||
|
if (pid == 0) {
|
||||||
|
int stdin = open("dev_tty0", O_RDWR);
|
||||||
|
int stdout = open("dev_tty0", O_RDWR);
|
||||||
|
int stderr = open("dev_tty0", O_RDWR);
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
printf("\x1b[32;40mAAA ");
|
||||||
|
i=100000000;
|
||||||
|
while(--i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int stdin = open("dev_tty1", O_RDWR);
|
||||||
|
int stdout = open("dev_tty1", O_RDWR);
|
||||||
|
int stderr = open("dev_tty1", O_RDWR);
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
char* s = "\x1b[33;40mBBB ";
|
||||||
|
for (char* p = s; *p != 0; p++ ){
|
||||||
|
write(stdout, p, 1);
|
||||||
|
}
|
||||||
|
i=100000000;
|
||||||
|
while(--i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user