Skip to content

Commit

Permalink
ncst命令
Browse files Browse the repository at this point in the history
  • Loading branch information
yourtion committed May 16, 2016
1 parent 87b1d40 commit 02e307e
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 49 deletions.
56 changes: 31 additions & 25 deletions 26_day/bootpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

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);

Expand All @@ -17,14 +16,14 @@ void HariMain(void)
struct SHTCTL *shtctl;
char s[40];
struct FIFO32 fifo, keycmd;
int fifobuf[128], keycmd_buf[32], *cons_fifo[2];
int fifobuf[128], keycmd_buf[32];
int mx, my, i, new_mx = -1, new_my = 0, new_wx = 0x7fffffff, new_wy = 0;
unsigned int memtotal;
struct MOUSE_DEC mdec;
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
unsigned char *buf_back, buf_mouse[256], *buf_cons[2];
unsigned char *buf_back, buf_mouse[256];
struct SHEET *sht_back, *sht_mouse;
struct TASK *task_a, *task_cons[2], *task;
struct TASK *task_a, *task;
static char keytable0[0x80] = {
0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0x08, 0,
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0x0a, 0, 'A', 'S',
Expand Down Expand Up @@ -89,11 +88,11 @@ void HariMain(void)
mx = (binfo->scrnx - 16) / 2; /* 计算坐标使其位于画面中央 */
my = (binfo->scrny - 28 - 16) / 2;

sheet_slide(sht_back, 0, 0);
sheet_slide(key_win, 32, 4);
sheet_slide(sht_back, 0, 0);
sheet_slide(key_win, 32, 4);
sheet_slide(sht_mouse, mx, my);
sheet_updown(sht_back, 0);
sheet_updown(key_win, 1);
sheet_updown(sht_back, 0);
sheet_updown(key_win, 1);
sheet_updown(sht_mouse, 2);
keywin_on(key_win);

Expand Down Expand Up @@ -189,17 +188,17 @@ void HariMain(void)
fifo32_put(&keycmd, KEYCMD_LED);
fifo32_put(&keycmd, key_leds);
}
if (i == 256 + 0x3b && key_shift != 0 && key_win != 0) {
if (i == 256 + 0x3b && key_shift != 0 && key_win != 0) { /* Shift+F1 */
task = key_win->task;
if (task != 0 && task->tss.ss0 != 0) { /* Shift+F1 */
if (task != 0 && task->tss.ss0 != 0) {
cons_putstr0(task->cons, "\nBreak(key) :\n");
io_cli(); /*强制结束处理时禁止任务切换*/
task->tss.eax = (int) &(task->tss.esp0);
task->tss.eip = (int) asm_end_app;
io_sti();
}
}
if (i == 256 + 0x3c && key_shift != 0) { /* Shift+F2 */
if (i == 256 + 0x3c && key_shift != 0) { /* Shift+F2 */
if (key_win != 0) {
keywin_off(key_win);
}
Expand Down Expand Up @@ -256,7 +255,7 @@ void HariMain(void)
if (3 <= x && x < sht->bxsize - 3 && 3 <= y && y < 21) {
mmx = mx; /*进入窗口移动模式*/
mmy = my;
mmx2 = sht->vx0;
mmx2 = sht->vx0;
new_wy = sht->vy0;
}
if (sht->bxsize - 21 <= x && x < sht->bxsize - 5 && 5 <= y && y < 19) {
Expand All @@ -274,7 +273,7 @@ void HariMain(void)
fifo32_put(&task->fifo, 4);
io_sti();
}
}
}
break;
}
}
Expand All @@ -284,7 +283,7 @@ void HariMain(void)
x = mx - mmx; /*计算鼠标指针移动量*/
y = my - mmy;
new_wx = (mmx2 + x + 2) & ~3;
new_wy = new_wy + y;
new_wy = new_wy + y;
mmy = my;
}
} else {
Expand All @@ -293,11 +292,13 @@ void HariMain(void)
if (new_wx != 0x7fffffff) {
sheet_slide(sht, new_wx, new_wy); /*固定图层位置*/
new_wx = 0x7fffffff;
}
}
}
}
} else if (768 <= i && i <= 1023) { /*命令行窗口关闭处理*/
close_console(shtctl->sheets0 + (i - 768));
} else if (1024 <= i && i <= 2023) {
close_constask(taskctl->tasks0 + (i - 1024));
}
}
}
Expand All @@ -321,19 +322,13 @@ void keywin_on(struct SHEET *key_win)
return;
}

struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal)
struct TASK *open_constask(struct SHEET *sht, unsigned int memtotal)
{
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
struct SHEET *sht = sheet_alloc(shtctl);
unsigned char *buf = (unsigned char *) memman_alloc_4k(memman, 256 * 165);
struct TASK *task = task_alloc();
int *cons_fifo = (int *) memman_alloc_4k(memman, 128 * 4);
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);
make_textbox8(sht, 8, 28, 240, 128, COL8_000000);
task->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 12;
task->tss.eip = (int) &console_task;
task->tss.es = 1 * 8;
task->tss.cs = 2 * 8;
Expand All @@ -344,9 +339,20 @@ struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal)
*((int *) (task->tss.esp + 4)) = (int) sht;
*((int *) (task->tss.esp + 8)) = memtotal;
task_run(task, 2, 2); /* level=2, priority=2 */
sht->task = task;
sht->flags |= 0x20; /*有光标*/
fifo32_init(&task->fifo, 128, cons_fifo, task);
return task;
}

struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal)
{
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
struct SHEET *sht = sheet_alloc(shtctl);
unsigned char *buf = (unsigned char *) memman_alloc_4k(memman, 256 * 165);
sheet_setbuf(sht, buf, 256, 165, -1); /*无透明色*/
make_window8(buf, 256, 165, "console", 0);
make_textbox8(sht, 8, 28, 240, 128, COL8_000000);
sht->task = open_constask(sht, memtotal);
sht->flags |= 0x20; /*有光标*/
return sht;
}

Expand Down
5 changes: 5 additions & 0 deletions 26_day/bootpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ struct TASKCTL {
struct TASKLEVEL level[MAX_TASKLEVELS];
struct TASK tasks0[MAX_TASKS];
};
extern struct TASKCTL *taskctl;
extern struct TIMER *task_timer;
struct TASK *task_now(void);
struct TASK *task_init(struct MEMMAN *memman);
Expand Down Expand Up @@ -257,6 +258,7 @@ void cmd_dir(struct CONSOLE *cons);
void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline);
void cmd_exit(struct CONSOLE *cons, int *fat);
void cmd_start(struct CONSOLE *cons, char *cmdline, int memtotal);
void cmd_ncst(struct CONSOLE *cons, char *cmdline, int memtotal);
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);
Expand All @@ -274,3 +276,6 @@ void file_readfat(int *fat, unsigned char *img);
void file_loadfile(int clustno, int size, char *buf, int *fat, char *img);
struct FILEINFO *file_search(char *name, struct FILEINFO *finfo, int max);

/* bootpack.c */
struct TASK *open_constask(struct SHEET *sht, unsigned int memtotal);
struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal);
84 changes: 60 additions & 24 deletions 26_day/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ void console_task(struct SHEET *sheet, int memtotal)
cons.cur_c = -1;
task->cons = &cons;

cons.timer = timer_alloc();
timer_init(cons.timer, &task->fifo, 1);
timer_settime(cons.timer, 50);
if (sheet != 0) {
cons.timer = timer_alloc();
timer_init(cons.timer, &task->fifo, 1);
timer_settime(cons.timer, 50);
}
file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200));

/*显示提示符*/
Expand Down Expand Up @@ -72,6 +74,9 @@ void console_task(struct SHEET *sheet, int memtotal)
cmdline[cons.cur_x / 8 - 2] = 0;
cons_newline(&cons);
cons_runcmd(cmdline, &cons, fat, memtotal); /*运行命令*/
if (sheet == 0) {
cmd_exit(&cons, fat);
}
/*显示提示符*/
cons_putchar(&cons, '>', 1);
} else {
Expand All @@ -84,10 +89,12 @@ void console_task(struct SHEET *sheet, int memtotal)
}
}
/*重新显示光标*/
if (cons.cur_c >= 0) {
boxfill8(sheet->buf, sheet->bxsize, cons.cur_c, cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15);
if (sheet != 0) {
if (cons.cur_c >= 0) {
boxfill8(sheet->buf, sheet->bxsize, cons.cur_c, cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15);
}
sheet_refresh(sheet, cons.cur_x, cons.cur_y, cons.cur_x + 8, cons.cur_y + 16);
}
sheet_refresh(sheet, cons.cur_x, cons.cur_y, cons.cur_x + 8, cons.cur_y + 16);
}
}
}
Expand All @@ -99,8 +106,10 @@ void cons_putchar(struct CONSOLE *cons, int chr, char move)
s[1] = 0;
if (s[0] == 0x09) { /*制表符*/
for (;;) {
putfonts8_asc_sht(cons->sht, cons->cur_x, cons->cur_y, COL8_FFFFFF, COL8_000000, " ", 1);
cons->cur_x += 8;
if (cons->sht != 0) {
putfonts8_asc_sht(cons->sht, cons->cur_x, cons->cur_y, COL8_FFFFFF, COL8_000000, " ", 1);
cons->cur_x += 8;
}
if (cons->cur_x == 8 + 240) {
cons_newline(cons);
}
Expand All @@ -113,7 +122,9 @@ void cons_putchar(struct CONSOLE *cons, int chr, char move)
} else if (s[0] == 0x0d) { /*回车*/
/*先不做任何操作*/
} else { /*一般字符*/
putfonts8_asc_sht(cons->sht, cons->cur_x, cons->cur_y, COL8_FFFFFF, COL8_000000, s, 1);
if (cons->sht != 0) {
putfonts8_asc_sht(cons->sht, cons->cur_x, cons->cur_y, COL8_FFFFFF, COL8_000000, s, 1);
}
if (move != 0) {
/* move为0时光标不后移*/
cons->cur_x += 8;
Expand All @@ -133,17 +144,19 @@ void cons_newline(struct CONSOLE *cons)
cons->cur_y += 16; /*到下一行*/
} else {
/*滚动*/
for (y = 28; y < 28 + 112; y++) {
for (x = 8; x < 8 + 240; x++) {
sheet->buf[x + y * sheet->bxsize] = sheet->buf[x + (y + 16) * sheet->bxsize];
if (sheet != 0) {
for (y = 28; y < 28 + 112; y++) {
for (x = 8; x < 8 + 240; x++) {
sheet->buf[x + y * sheet->bxsize] = sheet->buf[x + (y + 16) * sheet->bxsize];
}
}
}
for (y = 28 + 112; y < 28 + 128; y++) {
for (x = 8; x < 8 + 240; x++) {
sheet->buf[x + y * sheet->bxsize] = COL8_000000;
for (y = 28 + 112; y < 28 + 128; y++) {
for (x = 8; x < 8 + 240; x++) {
sheet->buf[x + y * sheet->bxsize] = COL8_000000;
}
}
sheet_refresh(sheet, 8, 28, 8 + 240, 28 + 128);
}
sheet_refresh(sheet, 8, 28, 8 + 240, 28 + 128);
}
cons->cur_x = 8;
return;
Expand All @@ -168,19 +181,21 @@ void cons_putstr1(struct CONSOLE *cons, char *s, int l)

void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal)
{
if (strcmp(cmdline, "mem") == 0) {
if (strcmp(cmdline, "mem") == 0 && cons->sht != 0) {
cmd_mem(cons, memtotal);
} else if (strcmp(cmdline, "cls") == 0) {
} else if (strcmp(cmdline, "cls") == 0 && cons->sht != 0) {
cmd_cls(cons);
} else if (strcmp(cmdline, "dir") == 0 || strcmp(cmdline, "ls") == 0) {
} else if ((strcmp(cmdline, "dir") == 0 || strcmp(cmdline, "ls") == 0) && cons->sht != 0) {
cmd_dir(cons);
} else if (strncmp(cmdline, "type ", 5) == 0) {
} else if (strncmp(cmdline, "type ", 5) == 0 && cons->sht != 0) {
cmd_type(cons, fat, cmdline);
} else if (strcmp(cmdline, "exit") == 0) {
cmd_exit(cons, fat);
} else if (strncmp(cmdline, "start ", 6) == 0) {
cmd_start(cons, cmdline, memtotal);
} else if (cmdline[0] != 0) {
} else if (strncmp(cmdline, "ncst ", 5) == 0) {
cmd_ncst(cons, cmdline, memtotal);
}else if (cmdline[0] != 0) {
if (cmd_app(cons, fat, cmdline) == 0) {
/*不是命令,不是应用程序,也不是空行*/
cons_putstr0(cons, "Bad command.\n\n");
Expand Down Expand Up @@ -263,10 +278,16 @@ void cmd_exit(struct CONSOLE *cons, int *fat)
struct TASK *task = task_now();
struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
struct FIFO32 *fifo = (struct FIFO32 *) *((int *) 0x0fec);
timer_cancel(cons->timer);
if (cons->sht != 0) {
timer_cancel(cons->timer);
}
memman_free_4k(memman, (int) fat, 4 * 2880);
io_cli();
fifo32_put(fifo, cons->sht - shtctl->sheets0 + 768); /* 768〜1023 */
if (cons->sht != 0) {
fifo32_put(fifo, cons->sht - shtctl->sheets0 + 768); /* 768〜1023 */
} else {
fifo32_put(fifo, task - taskctl->tasks0 + 1024); /*1024~2023*/
}
io_sti();
for (;;) {
task_sleep(task);
Expand All @@ -290,6 +311,21 @@ void cmd_start(struct CONSOLE *cons, char *cmdline, int memtotal)
return;
}

void cmd_ncst(struct CONSOLE *cons, char *cmdline, int memtotal)
{
struct TASK *task = open_constask(0, memtotal);
struct FIFO32 *fifo = &task->fifo;
int i;

/*将命令行输入的字符串逐字复制到新的命令行窗口中*/
for (i = 5; cmdline[i] != 0; i++) {
fifo32_put(fifo, cmdline[i] + 256);
}
fifo32_put(fifo, 10 + 256); /*回车键*/
cons_newline(cons);
return;
}

int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
{
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
Expand Down

0 comments on commit 02e307e

Please sign in to comment.