Day 26 done.
This commit is contained in:
parent
9711bf8386
commit
a8b8ccf3b1
@ -73,12 +73,18 @@ $ make qemu DEBUG=1
|
||||
- [X] 第23天:应用程序图形处理
|
||||
- [X] 第24天:窗口操作
|
||||
- [X] 第25天:更多窗口
|
||||
- [ ] 第26天
|
||||
- [X] 第26天:窗口操作提速
|
||||
- [ ] 第27天
|
||||
- [ ] 第28天
|
||||
- [ ] 第29天
|
||||
- [ ] 第30天
|
||||
|
||||
## 待解决问题
|
||||
|
||||
- [ ] 定时器执行若使用`io_sti`而非`io_stihlt`时会卡死
|
||||
- [ ] 启动时偶尔黑屏,无法正常绘制界面
|
||||
- [ ] 多个命令行同时执行命令时会卡死
|
||||
|
||||
## 博客文章
|
||||
|
||||
- [第0天:前言](https://www.ghosind.com/2021/03/31/hariboteos-0)
|
||||
|
@ -347,6 +347,8 @@ int main(void) {
|
||||
}
|
||||
} else if (768 <= data && data <= 1023) {
|
||||
close_console(shtctl->sheets0 + (data - 768));
|
||||
} else if (1024 <= data && data <= 2023) {
|
||||
close_cons_task(taskctl->tasks0 + (data - 1024));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,16 +88,53 @@ void cmd_exit(struct Console *cons, int *fat) {
|
||||
struct Shtctl *shtctl = (struct Shtctl *)*((int *)0x0fe4);
|
||||
struct FIFO32 *fifo = (struct FIFO32 *)*((int *)0x0fec);
|
||||
|
||||
timer_cancel(cons->timer);
|
||||
if (cons->sheet) {
|
||||
timer_cancel(cons->timer);
|
||||
}
|
||||
|
||||
memman_free_4k(memman, (int)fat, 4 * 2880);
|
||||
io_cli();
|
||||
fifo32_put(fifo, cons->sheet - shtctl->sheets0 + 768);
|
||||
|
||||
if (cons->sheet) {
|
||||
fifo32_put(fifo, cons->sheet - shtctl->sheets0 + 768);
|
||||
} else {
|
||||
fifo32_put(fifo, task - taskctl->tasks0 + 1024);
|
||||
}
|
||||
|
||||
io_sti();
|
||||
for (;;) {
|
||||
task_sleep(task);
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_start(struct Console *cons, char *cmdline, int memtotal) {
|
||||
struct Shtctl *shtctl = (struct Shtctl *)*((int *)0x0fe4);
|
||||
struct Sheet *sht = open_console(shtctl, memtotal);
|
||||
struct FIFO32 *fifo = &sht->task->fifo;
|
||||
|
||||
sheet_slide(sht, 32, 4);
|
||||
sheet_updown(sht, shtctl->top);
|
||||
|
||||
for (int i = 6; cmdline[i] != '\0'; i++) {
|
||||
fifo32_put(fifo, cmdline[i] + 256);
|
||||
}
|
||||
|
||||
fifo32_put(fifo, 10 + 256);
|
||||
cons_newline(cons);
|
||||
}
|
||||
|
||||
void cmd_ncst(struct Console *cons, char *cmdline, int memtotal) {
|
||||
struct Task *task = open_cons_task(0, memtotal);
|
||||
struct FIFO32 *fifo = &task->fifo;
|
||||
|
||||
for (int i = 5; cmdline[i] != '\0'; i++) {
|
||||
fifo32_put(fifo, cmdline[i] + 256);
|
||||
}
|
||||
|
||||
fifo32_put(fifo, 10 + 256);
|
||||
cons_newline(cons);
|
||||
}
|
||||
|
||||
int cmd_app(struct Console *cons, int *fat, char *cmdline) {
|
||||
struct MemMan *memman = (struct MemMan *)MEMMAN_ADDR;
|
||||
struct FileInfo *finfo;
|
||||
|
102
day26/console.c
102
day26/console.c
@ -31,9 +31,11 @@ void console_task(struct Sheet *sheet, unsigned int memtotal) {
|
||||
cons.cur_c = -1;
|
||||
task->cons = &cons;
|
||||
|
||||
struct Timer *timer = timer_alloc();
|
||||
timer_init(timer, &task->fifo, 1);
|
||||
timer_set_timer(timer, 50);
|
||||
if (sheet) {
|
||||
cons.timer = timer_alloc();
|
||||
timer_init(cons.timer, &task->fifo, 1);
|
||||
timer_set_timer(cons.timer, 50);
|
||||
}
|
||||
|
||||
file_read_fat(fat, (unsigned char *)(ADR_DISKIMG + 0x000200));
|
||||
|
||||
@ -50,18 +52,18 @@ void console_task(struct Sheet *sheet, unsigned int memtotal) {
|
||||
io_sti();
|
||||
if (data <= 1) {
|
||||
if (data) {
|
||||
timer_init(timer, &task->fifo, 0);
|
||||
timer_init(cons.timer, &task->fifo, 0);
|
||||
if (cons.cur_c >= 0) {
|
||||
cons.cur_c = COL8_FFFFFF;
|
||||
}
|
||||
} else {
|
||||
timer_init(timer, &task->fifo, 1);
|
||||
timer_init(cons.timer, &task->fifo, 1);
|
||||
if (cons.cur_c >= 0) {
|
||||
cons.cur_c = COL8_000000;
|
||||
}
|
||||
}
|
||||
|
||||
timer_set_timer(timer, 50);
|
||||
timer_set_timer(cons.timer, 50);
|
||||
}
|
||||
|
||||
// 光标ON
|
||||
@ -95,6 +97,10 @@ void console_task(struct Sheet *sheet, unsigned int memtotal) {
|
||||
cons_newline(&cons);
|
||||
cons_run_cmd(cmdline, &cons, fat, memtotal);
|
||||
|
||||
if (!sheet) {
|
||||
cmd_exit(&cons, fat);
|
||||
}
|
||||
|
||||
cons_putchar(&cons, '>', 1);
|
||||
} else {
|
||||
if (cons.cur_x < 240) {
|
||||
@ -104,12 +110,14 @@ void console_task(struct Sheet *sheet, unsigned int memtotal) {
|
||||
}
|
||||
}
|
||||
|
||||
if (cons.cur_c >= 0) {
|
||||
box_fill8(sheet->buf, sheet->bxsize, cons.cur_c, cons.cur_x, cons.cur_y,
|
||||
cons.cur_x + 7, cons.cur_y + 15);
|
||||
if (sheet) {
|
||||
if (cons.cur_c >= 0) {
|
||||
box_fill8(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -122,8 +130,11 @@ void cons_putchar(struct Console *cons, int ch, char move) {
|
||||
|
||||
if (s[0] == '\t') {
|
||||
for (;;) {
|
||||
put_fonts8_asc_sht(cons->sheet, cons->cur_x, cons->cur_y, COL8_FFFFFF,
|
||||
COL8_000000, " ", 1);
|
||||
if (cons->sheet) {
|
||||
put_fonts8_asc_sht(cons->sheet, cons->cur_x, cons->cur_y, COL8_FFFFFF,
|
||||
COL8_000000, " ", 1);
|
||||
}
|
||||
|
||||
cons->cur_x += 8;
|
||||
if (cons->cur_x == 8 + 240) {
|
||||
cons_newline(cons);
|
||||
@ -139,8 +150,11 @@ void cons_putchar(struct Console *cons, int ch, char move) {
|
||||
} else if (s[0] == '\r') {
|
||||
// 回车符,暂不处理
|
||||
} else {
|
||||
put_fonts8_asc_sht(cons->sheet, cons->cur_x, cons->cur_y, COL8_FFFFFF,
|
||||
COL8_000000, s, 1);
|
||||
if (cons->sheet) {
|
||||
put_fonts8_asc_sht(cons->sheet, cons->cur_x, cons->cur_y, COL8_FFFFFF,
|
||||
COL8_000000, s, 1);
|
||||
}
|
||||
|
||||
if (move) {
|
||||
cons->cur_x += 8;
|
||||
if (cons->cur_x == 8 + 240) {
|
||||
@ -157,19 +171,21 @@ void cons_newline(struct Console *cons) {
|
||||
cons->cur_y += 16;
|
||||
} else {
|
||||
// 滚动
|
||||
for (int y = 28; y < 28 + 112; y++) {
|
||||
for (int x = 8; x < 8 + 240; x++) {
|
||||
sheet->buf[x + y * sheet->bxsize] =
|
||||
sheet->buf[x + (y + 16) * sheet->bxsize];
|
||||
if (sheet) {
|
||||
for (int y = 28; y < 28 + 112; y++) {
|
||||
for (int x = 8; x < 8 + 240; x++) {
|
||||
sheet->buf[x + y * sheet->bxsize] =
|
||||
sheet->buf[x + (y + 16) * sheet->bxsize];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int y = 28 + 112; y < 28 + 128; y++) {
|
||||
for (int x = 8; x < 8 + 240; x++) {
|
||||
sheet->buf[x + y * sheet->bxsize] = COL8_000000;
|
||||
for (int y = 28 + 112; y < 28 + 128; y++) {
|
||||
for (int 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;
|
||||
@ -190,16 +206,20 @@ void cons_putnstr(struct Console *cons, char *s, int n) {
|
||||
|
||||
void cons_run_cmd(char *cmdline, struct Console *cons, int *fat,
|
||||
unsigned int memtotal) {
|
||||
if (!strcmp(cmdline, "mem")) {
|
||||
if (!strcmp(cmdline, "mem") && cons->sheet) {
|
||||
cmd_mem(cons, memtotal);
|
||||
} else if (!strcmp(cmdline, "cls")) {
|
||||
} else if (!strcmp(cmdline, "cls") && cons->sheet) {
|
||||
cmd_cls(cons);
|
||||
} else if (!strcmp(cmdline, "dir")) {
|
||||
} else if (!strcmp(cmdline, "dir") && cons->sheet) {
|
||||
cmd_dir(cons);
|
||||
} else if (!strncmp(cmdline, "type ", 5)) {
|
||||
} else if (!strncmp(cmdline, "type ", 5) && cons->sheet) {
|
||||
cmd_type(cons, fat, cmdline);
|
||||
} else if (!strcmp(cmdline, "exit")) {
|
||||
cmd_exit(cons, fat);
|
||||
} else if (!strncmp(cmdline, "start ", 6)) {
|
||||
cmd_start(cons, cmdline, memtotal);
|
||||
} else if (!strncmp(cmdline, "ncst ", 5)) {
|
||||
cmd_ncst(cons, cmdline, memtotal);
|
||||
} else if (strcmp(cmdline, "")) {
|
||||
if (!cmd_app(cons, fat, cmdline)) {
|
||||
cons_putstr(cons, "Bad command.\n\n");
|
||||
@ -207,16 +227,11 @@ void cons_run_cmd(char *cmdline, struct Console *cons, int *fat,
|
||||
}
|
||||
}
|
||||
|
||||
struct Sheet *open_console(struct Shtctl *shtctl, unsigned int memtotal) {
|
||||
struct Task *open_cons_task(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);
|
||||
|
||||
sheet_setbuf(sht, buf, 256, 165, -1);
|
||||
make_window8(buf, 256, 165, "console", 0);
|
||||
make_textbox8(sht, 8, 28, 240, 128, COL8_000000);
|
||||
task->cons_stack = memman_alloc(memman, 64 * 1024);
|
||||
task->tss.esp = task->cons_stack + 64 * 1024 - 12;
|
||||
task->tss.eip = (int)&console_task;
|
||||
@ -229,10 +244,23 @@ 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);
|
||||
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_cons_task(sht, memtotal);
|
||||
sht->flags |= 0x20;
|
||||
|
||||
return sht;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@ 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);
|
||||
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);
|
||||
|
||||
|
@ -18,6 +18,7 @@ void cons_run_cmd(char *cmdline, struct Console *cons, int *fat, unsigned int me
|
||||
void cons_putstr(struct Console *cons, char *s);
|
||||
void cons_putnstr(struct Console *cons, char *s, int n);
|
||||
|
||||
struct Task *open_cons_task(struct Sheet *sht, unsigned int memtotal);
|
||||
struct Sheet *open_console(struct Shtctl *shtctl, unsigned int memtotal);
|
||||
void close_cons_task(struct Task *task);
|
||||
void close_console(struct Sheet *sht);
|
||||
|
Loading…
x
Reference in New Issue
Block a user