mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-03 01:53:24 +08:00
关闭命令行窗口(1)
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
void keywin_off(struct SHEET *key_win);
|
||||
void keywin_on(struct SHEET *key_win);
|
||||
struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal);
|
||||
void close_console(struct SHEET *sht);
|
||||
void close_constask(struct TASK *task);
|
||||
|
||||
void HariMain(void)
|
||||
{
|
||||
@@ -51,6 +53,7 @@ void HariMain(void)
|
||||
init_pic();
|
||||
io_sti(); /* IDT/PIC的初始化已经完成,于是开放CPU的中断 */
|
||||
fifo32_init(&fifo, 128, fifobuf, 0);
|
||||
*((int *) 0x0fec) = (int) &fifo;
|
||||
init_pit();
|
||||
init_keyboard(&fifo, 256);
|
||||
enable_mouse(&fifo, 512, &mdec);
|
||||
@@ -123,9 +126,13 @@ void HariMain(void)
|
||||
} else {
|
||||
i = fifo32_get(&fifo);
|
||||
io_sti();
|
||||
if (key_win->flags == 0) { /*输入窗口被关闭*/
|
||||
key_win = shtctl->sheets[shtctl->top - 1];
|
||||
keywin_on(key_win);
|
||||
if (key_win != 0 && key_win->flags == 0) { /*窗口被关闭*/
|
||||
if (shtctl->top == 1) { /*当画面上只剩鼠标和背景时*/
|
||||
key_win = 0;
|
||||
} else {
|
||||
key_win = shtctl->sheets[shtctl->top - 1];
|
||||
keywin_on(key_win);
|
||||
}
|
||||
}
|
||||
if (256 <= i && i <= 511) { /* 键盘数据*/
|
||||
if (i < 0x80 + 256) { /*将按键编码转换为字符编码*/
|
||||
@@ -143,10 +150,10 @@ void HariMain(void)
|
||||
s[0] += 0x20; /*将大写字母转换为小写字母*/
|
||||
}
|
||||
}
|
||||
if (s[0] != 0) { /*一般字符、退格键、回车键*/
|
||||
if (s[0] != 0 && key_win != 0) { /*一般字符、退格键、回车键*/
|
||||
fifo32_put(&key_win->task->fifo, s[0] + 256);
|
||||
}
|
||||
if (i == 256 + 0x0f) { /* Tab键 */
|
||||
if (i == 256 + 0x0f && key_win != 0) { /* Tab键 */
|
||||
keywin_off(key_win);
|
||||
j = key_win->height - 1;
|
||||
if (j == 0) {
|
||||
@@ -182,7 +189,7 @@ void HariMain(void)
|
||||
fifo32_put(&keycmd, KEYCMD_LED);
|
||||
fifo32_put(&keycmd, key_leds);
|
||||
}
|
||||
if (i == 256 + 0x3b && key_shift != 0) {
|
||||
if (i == 256 + 0x3b && key_shift != 0 && key_win != 0) {
|
||||
task = key_win->task;
|
||||
if (task != 0 && task->tss.ss0 != 0) { /* Shift+F1 */
|
||||
cons_putstr0(task->cons, "\nBreak(key) :\n");
|
||||
@@ -192,8 +199,10 @@ void HariMain(void)
|
||||
io_sti();
|
||||
}
|
||||
}
|
||||
if (i == 256 + 0x3c && key_shift != 0 ) { /* Shift+F2 */
|
||||
keywin_off(key_win);
|
||||
if (i == 256 + 0x3c && key_shift != 0) { /* Shift+F2 */
|
||||
if (key_win != 0) {
|
||||
keywin_off(key_win);
|
||||
}
|
||||
key_win = open_console(shtctl, memtotal);
|
||||
sheet_slide(key_win, 32, 4);
|
||||
sheet_updown(key_win, shtctl->top);
|
||||
@@ -282,6 +291,8 @@ void HariMain(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (768 <= i && i <= 1023) { /*命令行窗口关闭处理*/
|
||||
close_console(shtctl->sheets0 + (i - 768));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -311,6 +322,8 @@ struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal)
|
||||
struct SHEET *sht = sheet_alloc(shtctl);
|
||||
unsigned char *buf = (unsigned char *) memman_alloc_4k(memman, 256 * 165);
|
||||
struct TASK *task = task_alloc();
|
||||
task->cons_stack = memman_alloc_4k(memman, 64 * 1024);
|
||||
task->tss.esp = task->cons_stack + 64 * 1024 - 12;
|
||||
int *cons_fifo = (int *) memman_alloc_4k(memman, 128 * 4);
|
||||
sheet_setbuf(sht, buf, 256, 165, -1); /*无透明色*/
|
||||
make_window8(buf, 256, 165, "console", 0);
|
||||
@@ -331,3 +344,23 @@ struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal)
|
||||
fifo32_init(&task->fifo, 128, cons_fifo, task);
|
||||
return sht;
|
||||
}
|
||||
|
||||
void close_constask(struct TASK *task)
|
||||
{
|
||||
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
|
||||
task_sleep(task);
|
||||
memman_free_4k(memman, task->cons_stack, 64 * 1024);
|
||||
memman_free_4k(memman, (int) task->fifo.buf, 128 * 4);
|
||||
task->flags = 0; /*用来替代task_free(task); */
|
||||
return;
|
||||
}
|
||||
|
||||
void close_console(struct SHEET *sht)
|
||||
{
|
||||
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
|
||||
struct TASK *task = sht->task;
|
||||
memman_free_4k(memman, (int) sht->buf, 256 * 165);
|
||||
sheet_free(sht);
|
||||
close_constask(task);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ struct TASK {
|
||||
struct FIFO32 fifo;
|
||||
struct TSS32 tss;
|
||||
struct CONSOLE *cons;
|
||||
int ds_base;
|
||||
int ds_base, cons_stack;
|
||||
};
|
||||
struct TASKLEVEL {
|
||||
int running; /*正在运行的任务数量*/
|
||||
@@ -255,6 +255,7 @@ void cmd_mem(struct CONSOLE *cons, int memtotal);
|
||||
void cmd_cls(struct CONSOLE *cons);
|
||||
void cmd_dir(struct CONSOLE *cons);
|
||||
void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline);
|
||||
void cmd_exit(struct CONSOLE *cons, int *fat);
|
||||
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline);
|
||||
int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax);
|
||||
int *inthandler0d(int *esp);
|
||||
|
||||
@@ -173,6 +173,8 @@ void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal)
|
||||
cmd_dir(cons);
|
||||
} else if (strncmp(cmdline, "type ", 5) == 0) {
|
||||
cmd_type(cons, fat, cmdline);
|
||||
} else if (strcmp(cmdline, "exit") == 0) {
|
||||
cmd_exit(cons, fat);
|
||||
} else if (cmdline[0] != 0) {
|
||||
if (cmd_app(cons, fat, cmdline) == 0) {
|
||||
/*不是命令,不是应用程序,也不是空行*/
|
||||
@@ -250,6 +252,22 @@ void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline)
|
||||
return;
|
||||
}
|
||||
|
||||
void cmd_exit(struct CONSOLE *cons, int *fat)
|
||||
{
|
||||
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
|
||||
struct TASK *task = task_now();
|
||||
struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
|
||||
struct FIFO32 *fifo = (struct FIFO32 *) *((int *) 0x0fec);
|
||||
timer_cancel(cons->timer);
|
||||
memman_free_4k(memman, (int) fat, 4 * 2880);
|
||||
io_cli();
|
||||
fifo32_put(fifo, cons->sht - shtctl->sheets0 + 768); /* 768〜1023 */
|
||||
io_sti();
|
||||
for (;;) {
|
||||
task_sleep(task);
|
||||
}
|
||||
}
|
||||
|
||||
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
|
||||
{
|
||||
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
|
||||
|
||||
Reference in New Issue
Block a user