Compare commits

...

2 Commits

Author SHA1 Message Date
Yourtion
5bc0adee61 变得更像真正的操作系统(2) 2016-05-13 11:54:11 +08:00
Yourtion
95542da7f7 变得更像真正的操作系统(1) 2016-05-13 11:47:29 +08:00
2 changed files with 24 additions and 94 deletions

View File

@@ -5,8 +5,8 @@
#define KEYCMD_LED 0xed
int keywin_off(struct SHEET *key_win, struct SHEET *sht_win, int cur_c, int cur_x);
int keywin_on(struct SHEET *key_win, struct SHEET *sht_win, int cur_c);
void keywin_off(struct SHEET *key_win);
void keywin_on(struct SHEET *key_win);
void HariMain(void)
{
@@ -14,15 +14,14 @@ void HariMain(void)
struct SHTCTL *shtctl;
char s[40];
struct FIFO32 fifo, keycmd;
int fifobuf[128], keycmd_buf[32];
int mx, my, i, cursor_x, cursor_c;
int fifobuf[128], keycmd_buf[32], *cons_fifo[2];
int mx, my, i;
unsigned int memtotal;
struct MOUSE_DEC mdec;
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_cons[2];
unsigned char *buf_back, buf_mouse[256], *buf_cons[2];
struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_cons[2];
struct TASK *task_a, *task_cons[2], *task;
struct TIMER *timer;
static char keytable0[0x80] = {
0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0,
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S',
@@ -98,20 +97,10 @@ void HariMain(void)
task_run(task_cons[i], 2, 2); /* level=2, priority=2 */
sht_cons[i]->task = task_cons[i];
sht_cons[i]->flags |= 0x20; /*有光标*/
cons_fifo[i] = (int *) memman_alloc_4k(memman, 128 * 4);
fifo32_init(&task_cons[i]->fifo, 128, cons_fifo[i], task_cons[i]);
}
/* sht_win */
sht_win = sheet_alloc(shtctl);
buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52);
sheet_setbuf(sht_win, buf_win, 144, 52, -1); /* 无透明色 */
make_window8(buf_win, 144, 52, "task_a", 1);
make_textbox8(sht_win, 8, 28, 128, 16, COL8_FFFFFF);
cursor_x = 8;
cursor_c = COL8_FFFFFF;
timer = timer_alloc();
timer_init(timer, &fifo, 1);
timer_settime(timer, 50);
/* sht_mouse */
sht_mouse = sheet_alloc(shtctl);
sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99);
@@ -127,9 +116,8 @@ void HariMain(void)
sheet_updown(sht_back, 0);
sheet_updown(sht_cons[1], 1);
sheet_updown(sht_cons[0], 2);
sheet_updown(sht_win, 3);
sheet_updown(sht_mouse, 4);
key_win = sht_win;
sheet_updown(sht_mouse, 3);
key_win = sht_cons[0];
/*为了避免和键盘当前状态冲突,在一开始先进行设置*/
fifo32_put(&keycmd, KEYCMD_LED);
@@ -151,7 +139,6 @@ void HariMain(void)
io_sti();
if (key_win->flags == 0) { /*输入窗口被关闭*/
key_win = shtctl->sheets[shtctl->top - 1];
cursor_c = keywin_on(key_win, sht_win, cursor_c);
}
if (256 <= i && i <= 511) { /* 键盘数据*/
if (i < 0x80 + 256) { /*将按键编码转换为字符编码*/
@@ -168,42 +155,17 @@ void HariMain(void)
s[0] += 0x20; /*将大写字母转换为小写字母*/
}
}
if (s[0] != 0) { /*一般字符*/
if (key_win == sht_win) { /*发送给任务A */
if (cursor_x < 128) {
/*显示一个字符之后将光标后移一位*/
s[1] = 0;
putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1);
cursor_x += 8;
}
} else { /*发送给命令行窗口*/
fifo32_put(&key_win->task->fifo, s[0] + 256);
}
}
if (i == 256 + 0x0e) { /* 退格键 */
if (key_win == sht_win) { /*发送给任务A */
if (cursor_x > 8) {
/*用空白擦除光标后将光标前移一位*/
putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1);
cursor_x -= 8;
}
} else { /*发送给命令行窗口*/
fifo32_put(&key_win->task->fifo, 8 + 256);
}
}
if (i == 256 + 0x1c) { /*回车键*/
if (key_win != sht_win) { /*发送至命令行窗口*/
fifo32_put(&key_win->task->fifo, 10 + 256);
}
if (s[0] != 0) { /*一般字符、退格键、回车键*/
fifo32_put(&key_win->task->fifo, s[0] + 256);
}
if (i == 256 + 0x0f) { /* Tab键 */
cursor_c = keywin_off(key_win, sht_win, cursor_c, cursor_x);
keywin_off(key_win);
j = key_win->height - 1;
if (j == 0) {
j = shtctl->top - 1;
}
key_win = shtctl->sheets[j];
cursor_c = keywin_on(key_win, sht_win, cursor_c);
keywin_on(key_win);
}
if (i == 256 + 0x2a) { /*左Shift ON */
key_shift |= 1;
@@ -252,11 +214,6 @@ void HariMain(void)
wait_KBC_sendready();
io_out8(PORT_KEYDAT, keycmd_wait);
}
/*重新显示光标*/
if (cursor_c >= 0) {
boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43);
}
sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44);
} else if (512 <= i && i <= 767) { /* 鼠标数据*/
if (mouse_decode(&mdec, i - 512) != 0) {
/* 已经收集了3字节的数据移动光标 */
@@ -289,9 +246,9 @@ void HariMain(void)
if (sht->buf[y * sht->bxsize + x] != sht->col_inv) {
sheet_updown(sht, shtctl->top - 1);
if (sht != key_win) {
cursor_c = keywin_off(key_win, sht_win, cursor_c, cursor_x);
keywin_off(key_win);
key_win = sht;
cursor_c = keywin_on(key_win, sht_win, cursor_c);/*到此结束*/
keywin_on(key_win);
}
if (3 <= x && x < sht->bxsize - 3 && 3 <= y && y < 21) {
mmx = mx; /*进入窗口移动模式*/
@@ -326,51 +283,25 @@ void HariMain(void)
}
}
} else if (i <= 1) { /* 光标用定时器*/
if (i != 0) {
timer_init(timer, &fifo, 0); /* 下面设定0 */
if (cursor_c >= 0) {
cursor_c = COL8_000000;
}
} else {
timer_init(timer, &fifo, 1); /* 下面设定1 */
if (cursor_c >= 0) {
cursor_c = COL8_FFFFFF;
}
}
timer_settime(timer, 50);
if (cursor_c >= 0) {
boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43);
sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44);
}
}
}
}
}
int keywin_off(struct SHEET *key_win, struct SHEET *sht_win, int cur_c, int cur_x)
void keywin_off(struct SHEET *key_win)
{
change_wtitle8(key_win, 0);
if (key_win == sht_win) {
cur_c = -1; /*删除光标*/
boxfill8(sht_win->buf, sht_win->bxsize, COL8_FFFFFF, cur_x, 28, cur_x + 7, 43);
} else {
if ((key_win->flags & 0x20) != 0) {
fifo32_put(&key_win->task->fifo, 3); /*命令行窗口光标OFF */
}
if ((key_win->flags & 0x20) != 0) {
fifo32_put(&key_win->task->fifo, 3); /*命令行窗口光标OFF */
}
return cur_c;
return;
}
int keywin_on(struct SHEET *key_win, struct SHEET *sht_win, int cur_c)
void keywin_on(struct SHEET *key_win)
{
change_wtitle8(key_win, 1);
if (key_win == sht_win) {
cur_c = COL8_000000; /*显示光标*/
} else {
if ((key_win->flags & 0x20) != 0) {
fifo32_put(&key_win->task->fifo, 2); /*命令行窗口光标ON */
}
if ((key_win->flags & 0x20) != 0) {
fifo32_put(&key_win->task->fifo, 2); /*命令行窗口光标ON */
}
return cur_c;
return;
}

View File

@@ -9,7 +9,7 @@ void console_task(struct SHEET *sheet, unsigned int memtotal)
struct TIMER *timer;
struct TASK *task = task_now();
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
int i, fifobuf[128], *fat = (int *) memman_alloc_4k(memman, 4 * 2880);
int i, *fat = (int *) memman_alloc_4k(memman, 4 * 2880);
struct CONSOLE cons;
char cmdline[30];
cons.sht = sheet;
@@ -18,7 +18,6 @@ void console_task(struct SHEET *sheet, unsigned int memtotal)
cons.cur_c = -1;
task->cons = &cons;
fifo32_init(&task->fifo, 128, fifobuf, task);
timer = timer_alloc();
timer_init(timer, &task->fifo, 1);
timer_settime(timer, 50);