Skip to content

Commit 02e307e

Browse files
committed
ncst命令
1 parent 87b1d40 commit 02e307e

File tree

3 files changed

+96
-49
lines changed

3 files changed

+96
-49
lines changed

26_day/bootpack.c

+31-25
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
void keywin_off(struct SHEET *key_win);
99
void keywin_on(struct SHEET *key_win);
10-
struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal);
1110
void close_console(struct SHEET *sht);
1211
void close_constask(struct TASK *task);
1312

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

92-
sheet_slide(sht_back, 0, 0);
93-
sheet_slide(key_win, 32, 4);
91+
sheet_slide(sht_back, 0, 0);
92+
sheet_slide(key_win, 32, 4);
9493
sheet_slide(sht_mouse, mx, my);
95-
sheet_updown(sht_back, 0);
96-
sheet_updown(key_win, 1);
94+
sheet_updown(sht_back, 0);
95+
sheet_updown(key_win, 1);
9796
sheet_updown(sht_mouse, 2);
9897
keywin_on(key_win);
9998

@@ -189,17 +188,17 @@ void HariMain(void)
189188
fifo32_put(&keycmd, KEYCMD_LED);
190189
fifo32_put(&keycmd, key_leds);
191190
}
192-
if (i == 256 + 0x3b && key_shift != 0 && key_win != 0) {
191+
if (i == 256 + 0x3b && key_shift != 0 && key_win != 0) { /* Shift+F1 */
193192
task = key_win->task;
194-
if (task != 0 && task->tss.ss0 != 0) { /* Shift+F1 */
193+
if (task != 0 && task->tss.ss0 != 0) {
195194
cons_putstr0(task->cons, "\nBreak(key) :\n");
196195
io_cli(); /*强制结束处理时禁止任务切换*/
197196
task->tss.eax = (int) &(task->tss.esp0);
198197
task->tss.eip = (int) asm_end_app;
199198
io_sti();
200199
}
201200
}
202-
if (i == 256 + 0x3c && key_shift != 0) { /* Shift+F2 */
201+
if (i == 256 + 0x3c && key_shift != 0) { /* Shift+F2 */
203202
if (key_win != 0) {
204203
keywin_off(key_win);
205204
}
@@ -256,7 +255,7 @@ void HariMain(void)
256255
if (3 <= x && x < sht->bxsize - 3 && 3 <= y && y < 21) {
257256
mmx = mx; /*进入窗口移动模式*/
258257
mmy = my;
259-
mmx2 = sht->vx0;
258+
mmx2 = sht->vx0;
260259
new_wy = sht->vy0;
261260
}
262261
if (sht->bxsize - 21 <= x && x < sht->bxsize - 5 && 5 <= y && y < 19) {
@@ -274,7 +273,7 @@ void HariMain(void)
274273
fifo32_put(&task->fifo, 4);
275274
io_sti();
276275
}
277-
}
276+
}
278277
break;
279278
}
280279
}
@@ -284,7 +283,7 @@ void HariMain(void)
284283
x = mx - mmx; /*计算鼠标指针移动量*/
285284
y = my - mmy;
286285
new_wx = (mmx2 + x + 2) & ~3;
287-
new_wy = new_wy + y;
286+
new_wy = new_wy + y;
288287
mmy = my;
289288
}
290289
} else {
@@ -293,11 +292,13 @@ void HariMain(void)
293292
if (new_wx != 0x7fffffff) {
294293
sheet_slide(sht, new_wx, new_wy); /*固定图层位置*/
295294
new_wx = 0x7fffffff;
296-
}
295+
}
297296
}
298297
}
299298
} else if (768 <= i && i <= 1023) { /*命令行窗口关闭处理*/
300299
close_console(shtctl->sheets0 + (i - 768));
300+
} else if (1024 <= i && i <= 2023) {
301+
close_constask(taskctl->tasks0 + (i - 1024));
301302
}
302303
}
303304
}
@@ -321,19 +322,13 @@ void keywin_on(struct SHEET *key_win)
321322
return;
322323
}
323324

324-
struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal)
325+
struct TASK *open_constask(struct SHEET *sht, unsigned int memtotal)
325326
{
326327
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
327-
struct SHEET *sht = sheet_alloc(shtctl);
328-
unsigned char *buf = (unsigned char *) memman_alloc_4k(memman, 256 * 165);
329328
struct TASK *task = task_alloc();
329+
int *cons_fifo = (int *) memman_alloc_4k(memman, 128 * 4);
330330
task->cons_stack = memman_alloc_4k(memman, 64 * 1024);
331331
task->tss.esp = task->cons_stack + 64 * 1024 - 12;
332-
int *cons_fifo = (int *) memman_alloc_4k(memman, 128 * 4);
333-
sheet_setbuf(sht, buf, 256, 165, -1); /*无透明色*/
334-
make_window8(buf, 256, 165, "console", 0);
335-
make_textbox8(sht, 8, 28, 240, 128, COL8_000000);
336-
task->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 12;
337332
task->tss.eip = (int) &console_task;
338333
task->tss.es = 1 * 8;
339334
task->tss.cs = 2 * 8;
@@ -344,9 +339,20 @@ struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal)
344339
*((int *) (task->tss.esp + 4)) = (int) sht;
345340
*((int *) (task->tss.esp + 8)) = memtotal;
346341
task_run(task, 2, 2); /* level=2, priority=2 */
347-
sht->task = task;
348-
sht->flags |= 0x20; /*有光标*/
349342
fifo32_init(&task->fifo, 128, cons_fifo, task);
343+
return task;
344+
}
345+
346+
struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal)
347+
{
348+
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
349+
struct SHEET *sht = sheet_alloc(shtctl);
350+
unsigned char *buf = (unsigned char *) memman_alloc_4k(memman, 256 * 165);
351+
sheet_setbuf(sht, buf, 256, 165, -1); /*无透明色*/
352+
make_window8(buf, 256, 165, "console", 0);
353+
make_textbox8(sht, 8, 28, 240, 128, COL8_000000);
354+
sht->task = open_constask(sht, memtotal);
355+
sht->flags |= 0x20; /*有光标*/
350356
return sht;
351357
}
352358

26_day/bootpack.h

+5
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ struct TASKCTL {
224224
struct TASKLEVEL level[MAX_TASKLEVELS];
225225
struct TASK tasks0[MAX_TASKS];
226226
};
227+
extern struct TASKCTL *taskctl;
227228
extern struct TIMER *task_timer;
228229
struct TASK *task_now(void);
229230
struct TASK *task_init(struct MEMMAN *memman);
@@ -257,6 +258,7 @@ void cmd_dir(struct CONSOLE *cons);
257258
void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline);
258259
void cmd_exit(struct CONSOLE *cons, int *fat);
259260
void cmd_start(struct CONSOLE *cons, char *cmdline, int memtotal);
261+
void cmd_ncst(struct CONSOLE *cons, char *cmdline, int memtotal);
260262
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline);
261263
int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax);
262264
int *inthandler0d(int *esp);
@@ -274,3 +276,6 @@ void file_readfat(int *fat, unsigned char *img);
274276
void file_loadfile(int clustno, int size, char *buf, int *fat, char *img);
275277
struct FILEINFO *file_search(char *name, struct FILEINFO *finfo, int max);
276278

279+
/* bootpack.c */
280+
struct TASK *open_constask(struct SHEET *sht, unsigned int memtotal);
281+
struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal);

26_day/console.c

+60-24
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ void console_task(struct SHEET *sheet, int memtotal)
1717
cons.cur_c = -1;
1818
task->cons = &cons;
1919

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

2527
/*显示提示符*/
@@ -72,6 +74,9 @@ void console_task(struct SHEET *sheet, int memtotal)
7274
cmdline[cons.cur_x / 8 - 2] = 0;
7375
cons_newline(&cons);
7476
cons_runcmd(cmdline, &cons, fat, memtotal); /*运行命令*/
77+
if (sheet == 0) {
78+
cmd_exit(&cons, fat);
79+
}
7580
/*显示提示符*/
7681
cons_putchar(&cons, '>', 1);
7782
} else {
@@ -84,10 +89,12 @@ void console_task(struct SHEET *sheet, int memtotal)
8489
}
8590
}
8691
/*重新显示光标*/
87-
if (cons.cur_c >= 0) {
88-
boxfill8(sheet->buf, sheet->bxsize, cons.cur_c, cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15);
92+
if (sheet != 0) {
93+
if (cons.cur_c >= 0) {
94+
boxfill8(sheet->buf, sheet->bxsize, cons.cur_c, cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15);
95+
}
96+
sheet_refresh(sheet, cons.cur_x, cons.cur_y, cons.cur_x + 8, cons.cur_y + 16);
8997
}
90-
sheet_refresh(sheet, cons.cur_x, cons.cur_y, cons.cur_x + 8, cons.cur_y + 16);
9198
}
9299
}
93100
}
@@ -99,8 +106,10 @@ void cons_putchar(struct CONSOLE *cons, int chr, char move)
99106
s[1] = 0;
100107
if (s[0] == 0x09) { /*制表符*/
101108
for (;;) {
102-
putfonts8_asc_sht(cons->sht, cons->cur_x, cons->cur_y, COL8_FFFFFF, COL8_000000, " ", 1);
103-
cons->cur_x += 8;
109+
if (cons->sht != 0) {
110+
putfonts8_asc_sht(cons->sht, cons->cur_x, cons->cur_y, COL8_FFFFFF, COL8_000000, " ", 1);
111+
cons->cur_x += 8;
112+
}
104113
if (cons->cur_x == 8 + 240) {
105114
cons_newline(cons);
106115
}
@@ -113,7 +122,9 @@ void cons_putchar(struct CONSOLE *cons, int chr, char move)
113122
} else if (s[0] == 0x0d) { /*回车*/
114123
/*先不做任何操作*/
115124
} else { /*一般字符*/
116-
putfonts8_asc_sht(cons->sht, cons->cur_x, cons->cur_y, COL8_FFFFFF, COL8_000000, s, 1);
125+
if (cons->sht != 0) {
126+
putfonts8_asc_sht(cons->sht, cons->cur_x, cons->cur_y, COL8_FFFFFF, COL8_000000, s, 1);
127+
}
117128
if (move != 0) {
118129
/* move为0时光标不后移*/
119130
cons->cur_x += 8;
@@ -133,17 +144,19 @@ void cons_newline(struct CONSOLE *cons)
133144
cons->cur_y += 16; /*到下一行*/
134145
} else {
135146
/*滚动*/
136-
for (y = 28; y < 28 + 112; y++) {
137-
for (x = 8; x < 8 + 240; x++) {
138-
sheet->buf[x + y * sheet->bxsize] = sheet->buf[x + (y + 16) * sheet->bxsize];
147+
if (sheet != 0) {
148+
for (y = 28; y < 28 + 112; y++) {
149+
for (x = 8; x < 8 + 240; x++) {
150+
sheet->buf[x + y * sheet->bxsize] = sheet->buf[x + (y + 16) * sheet->bxsize];
151+
}
139152
}
140-
}
141-
for (y = 28 + 112; y < 28 + 128; y++) {
142-
for (x = 8; x < 8 + 240; x++) {
143-
sheet->buf[x + y * sheet->bxsize] = COL8_000000;
153+
for (y = 28 + 112; y < 28 + 128; y++) {
154+
for (x = 8; x < 8 + 240; x++) {
155+
sheet->buf[x + y * sheet->bxsize] = COL8_000000;
156+
}
144157
}
158+
sheet_refresh(sheet, 8, 28, 8 + 240, 28 + 128);
145159
}
146-
sheet_refresh(sheet, 8, 28, 8 + 240, 28 + 128);
147160
}
148161
cons->cur_x = 8;
149162
return;
@@ -168,19 +181,21 @@ void cons_putstr1(struct CONSOLE *cons, char *s, int l)
168181

169182
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal)
170183
{
171-
if (strcmp(cmdline, "mem") == 0) {
184+
if (strcmp(cmdline, "mem") == 0 && cons->sht != 0) {
172185
cmd_mem(cons, memtotal);
173-
} else if (strcmp(cmdline, "cls") == 0) {
186+
} else if (strcmp(cmdline, "cls") == 0 && cons->sht != 0) {
174187
cmd_cls(cons);
175-
} else if (strcmp(cmdline, "dir") == 0 || strcmp(cmdline, "ls") == 0) {
188+
} else if ((strcmp(cmdline, "dir") == 0 || strcmp(cmdline, "ls") == 0) && cons->sht != 0) {
176189
cmd_dir(cons);
177-
} else if (strncmp(cmdline, "type ", 5) == 0) {
190+
} else if (strncmp(cmdline, "type ", 5) == 0 && cons->sht != 0) {
178191
cmd_type(cons, fat, cmdline);
179192
} else if (strcmp(cmdline, "exit") == 0) {
180193
cmd_exit(cons, fat);
181194
} else if (strncmp(cmdline, "start ", 6) == 0) {
182195
cmd_start(cons, cmdline, memtotal);
183-
} else if (cmdline[0] != 0) {
196+
} else if (strncmp(cmdline, "ncst ", 5) == 0) {
197+
cmd_ncst(cons, cmdline, memtotal);
198+
}else if (cmdline[0] != 0) {
184199
if (cmd_app(cons, fat, cmdline) == 0) {
185200
/*不是命令,不是应用程序,也不是空行*/
186201
cons_putstr0(cons, "Bad command.\n\n");
@@ -263,10 +278,16 @@ void cmd_exit(struct CONSOLE *cons, int *fat)
263278
struct TASK *task = task_now();
264279
struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
265280
struct FIFO32 *fifo = (struct FIFO32 *) *((int *) 0x0fec);
266-
timer_cancel(cons->timer);
281+
if (cons->sht != 0) {
282+
timer_cancel(cons->timer);
283+
}
267284
memman_free_4k(memman, (int) fat, 4 * 2880);
268285
io_cli();
269-
fifo32_put(fifo, cons->sht - shtctl->sheets0 + 768); /* 768〜1023 */
286+
if (cons->sht != 0) {
287+
fifo32_put(fifo, cons->sht - shtctl->sheets0 + 768); /* 768〜1023 */
288+
} else {
289+
fifo32_put(fifo, task - taskctl->tasks0 + 1024); /*1024~2023*/
290+
}
270291
io_sti();
271292
for (;;) {
272293
task_sleep(task);
@@ -290,6 +311,21 @@ void cmd_start(struct CONSOLE *cons, char *cmdline, int memtotal)
290311
return;
291312
}
292313

314+
void cmd_ncst(struct CONSOLE *cons, char *cmdline, int memtotal)
315+
{
316+
struct TASK *task = open_constask(0, memtotal);
317+
struct FIFO32 *fifo = &task->fifo;
318+
int i;
319+
320+
/*将命令行输入的字符串逐字复制到新的命令行窗口中*/
321+
for (i = 5; cmdline[i] != 0; i++) {
322+
fifo32_put(fifo, cmdline[i] + 256);
323+
}
324+
fifo32_put(fifo, 10 + 256); /*回车键*/
325+
cons_newline(cons);
326+
return;
327+
}
328+
293329
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
294330
{
295331
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;

0 commit comments

Comments
 (0)