diff --git a/19_day/Makefile b/19_day/Makefile index 6e5650f..bec5953 100644 --- a/19_day/Makefile +++ b/19_day/Makefile @@ -1,5 +1,6 @@ OBJS_BOOTPACK = bootpack.obj naskfunc.obj hankaku.obj graphic.obj dsctbl.obj \ - int.obj fifo.obj keyboard.obj mouse.obj memory.obj sheet.obj timer.obj mtask.obj + int.obj fifo.obj keyboard.obj mouse.obj memory.obj sheet.obj timer.obj \ + mtask.obj window.obj console.obj file.obj TOOLPATH = ../z_tools/ INCPATH = ../z_tools/haribote/ diff --git a/19_day/bootpack.c b/19_day/bootpack.c index ac6f823..68d25e2 100644 --- a/19_day/bootpack.c +++ b/19_day/bootpack.c @@ -1,24 +1,7 @@ -/* bootpack�̃��C�� */ +/* bootpack */ #include "bootpack.h" #include -#include - -struct FILEINFO { - unsigned char name[8], ext[3], type; - char reserve[10]; - unsigned short time, date, clustno; - unsigned int size; -}; - -void make_window8(unsigned char *buf, int xsize, int ysize, char *title, char act); -void putfonts8_asc_sht(struct SHEET *sht, int x, int y, int c, int b, char *s, int l); -void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c); -void make_wtitle8(unsigned char *buf, int xsize, char *title, char act); -void console_task(struct SHEET *sheet, unsigned int memtotal); -int cons_newline(int cursor_y, struct SHEET *sheet); -void file_readfat(int *fat, unsigned char *img); -void file_loadfile(int clustno, int size, char *buf, int *fat, char *img); #define KEYCMD_LED 0xed @@ -295,353 +278,3 @@ void HariMain(void) } } } - -void make_window8(unsigned char *buf, int xsize, int ysize, char *title, char act) -{ - boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, xsize - 1, 0 ); - boxfill8(buf, xsize, COL8_FFFFFF, 1, 1, xsize - 2, 1 ); - boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, 0, ysize - 1); - boxfill8(buf, xsize, COL8_FFFFFF, 1, 1, 1, ysize - 2); - boxfill8(buf, xsize, COL8_848484, xsize - 2, 1, xsize - 2, ysize - 2); - boxfill8(buf, xsize, COL8_000000, xsize - 1, 0, xsize - 1, ysize - 1); - boxfill8(buf, xsize, COL8_C6C6C6, 2, 2, xsize - 3, ysize - 3); - boxfill8(buf, xsize, COL8_848484, 1, ysize - 2, xsize - 2, ysize - 2); - boxfill8(buf, xsize, COL8_000000, 0, ysize - 1, xsize - 1, ysize - 1); - make_wtitle8(buf, xsize, title, act); - return; -} - -void make_wtitle8(unsigned char *buf, int xsize, char *title, char act) -{ - static char closebtn[14][16] = { - "OOOOOOOOOOOOOOO@", - "OQQQQQQQQQQQQQ$@", - "OQQQQQQQQQQQQQ$@", - "OQQQ@@QQQQ@@QQ$@", - "OQQQQ@@QQ@@QQQ$@", - "OQQQQQ@@@@QQQQ$@", - "OQQQQQQ@@QQQQQ$@", - "OQQQQQ@@@@QQQQ$@", - "OQQQQ@@QQ@@QQQ$@", - "OQQQ@@QQQQ@@QQ$@", - "OQQQQQQQQQQQQQ$@", - "OQQQQQQQQQQQQQ$@", - "O$$$$$$$$$$$$$$@", - "@@@@@@@@@@@@@@@@" - }; - int x, y; - char c, tc, tbc; - if (act != 0) { - tc = COL8_FFFFFF; - tbc = COL8_000084; - } else { - tc = COL8_C6C6C6; - tbc = COL8_848484; - } - boxfill8(buf, xsize, tbc, 3, 3, xsize - 4, 20); - putfonts8_asc(buf, xsize, 24, 4, tc, title); - for (y = 0; y < 14; y++) { - for (x = 0; x < 16; x++) { - c = closebtn[y][x]; - if (c == '@') { - c = COL8_000000; - } else if (c == '$') { - c = COL8_848484; - } else if (c == 'Q') { - c = COL8_C6C6C6; - } else { - c = COL8_FFFFFF; - } - buf[(5 + y) * xsize + (xsize - 21 + x)] = c; - } - } - return; -} - -void putfonts8_asc_sht(struct SHEET *sht, int x, int y, int c, int b, char *s, int l) -{ - boxfill8(sht->buf, sht->bxsize, b, x, y, x + l * 8 - 1, y + 15); - putfonts8_asc(sht->buf, sht->bxsize, x, y, c, s); - sheet_refresh(sht, x, y, x + l * 8, y + 16); - return; -} - -void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c) -{ - int x1 = x0 + sx, y1 = y0 + sy; - boxfill8(sht->buf, sht->bxsize, COL8_848484, x0 - 2, y0 - 3, x1 + 1, y0 - 3); - boxfill8(sht->buf, sht->bxsize, COL8_848484, x0 - 3, y0 - 3, x0 - 3, y1 + 1); - boxfill8(sht->buf, sht->bxsize, COL8_FFFFFF, x0 - 3, y1 + 2, x1 + 1, y1 + 2); - boxfill8(sht->buf, sht->bxsize, COL8_FFFFFF, x1 + 2, y0 - 3, x1 + 2, y1 + 2); - boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 1, y0 - 2, x1 + 0, y0 - 2); - boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 2, y0 - 2, x0 - 2, y1 + 0); - boxfill8(sht->buf, sht->bxsize, COL8_C6C6C6, x0 - 2, y1 + 1, x1 + 0, y1 + 1); - boxfill8(sht->buf, sht->bxsize, COL8_C6C6C6, x1 + 1, y0 - 2, x1 + 1, y1 + 1); - boxfill8(sht->buf, sht->bxsize, c, x0 - 1, y0 - 1, x1 + 0, y1 + 0); - return; -} - -void console_task(struct SHEET *sheet, unsigned int memtotal) -{ - struct TIMER *timer; - struct TASK *task = task_now(); - int i, fifobuf[128], cursor_x = 16, cursor_y = 28, cursor_c = -1; - char s[30], cmdline[30], *p; - struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; - int x, y; - struct FILEINFO *finfo = (struct FILEINFO *) (ADR_DISKIMG + 0x002600); - int *fat = (int *) memman_alloc_4k(memman, 4 * 2880); - - fifo32_init(&task->fifo, 128, fifobuf, task); - timer = timer_alloc(); - timer_init(timer, &task->fifo, 1); - timer_settime(timer, 50); - file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200)); - - /*显示提示符*/ - putfonts8_asc_sht(sheet, 8, 28, COL8_FFFFFF, COL8_000000, ">", 1); - - for (;;) { - io_cli(); - if (fifo32_status(&task->fifo) == 0) { - task_sleep(task); - io_sti(); - } else { - i = fifo32_get(&task->fifo); - io_sti(); - if (i <= 1) { /*光标用定时器*/ - if (i != 0) { - timer_init(timer, &task->fifo, 0); /*下次置0 */ - if (cursor_c >= 0) { - cursor_c = COL8_FFFFFF; - } - } else { - timer_init(timer, &task->fifo, 1); /*下次置1 */ - if (cursor_c >= 0) { - cursor_c = COL8_000000; - } - } - timer_settime(timer, 50); - } - if (i == 2) { /*光标ON */ - cursor_c = COL8_FFFFFF; - } - if (i == 3) { /*光标OFF */ - boxfill8(sheet->buf, sheet->bxsize, COL8_000000, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15); - cursor_c = -1; - } - if (256 <= i && i <= 511) { /*键盘数据(通过任务A) */ - if (i == 8 + 256) { - /*退格键*/ - if (cursor_x > 16) { - /*用空白擦除光标后将光标前移一位*/ - putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1); - cursor_x -= 8; - } - } else if (i == 10 + 256) { - /*回车键*/ - /*用空格将光标擦除*/ - putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1); - cmdline[cursor_x / 8 - 2] = 0; - cursor_y = cons_newline(cursor_y, sheet); - /*执行命令*/ - if (strcmp(cmdline, "mem") == 0) { - /* mem命令*/ - sprintf(s, "total %dMB", memtotal / (1024 * 1024)); - putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30); - cursor_y = cons_newline(cursor_y, sheet); - sprintf(s, "free %dKB", memman_total(memman) / 1024); - putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30); - cursor_y = cons_newline(cursor_y, sheet); - cursor_y = cons_newline(cursor_y, sheet); - } else if (strcmp(cmdline, "cls") == 0) { - /* cls命令*/ - for (y = 28; 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); - cursor_y = 28; - } else if (strcmp(cmdline, "dir") == 0 || strcmp(cmdline, "ls") == 0) { - /* dir命令 */ - for (x = 0; x < 224; x++) { - if (finfo[x].name[0] == 0x00) { - break; - } - if (finfo[x].name[0] != 0xe5) { - if ((finfo[x].type & 0x18) == 0) { - sprintf(s, "filename.ext %7d", finfo[x].size); - for (y = 0; y < 8; y++) { - s[y] = finfo[x].name[y]; - } - s[ 9] = finfo[x].ext[0]; - s[10] = finfo[x].ext[1]; - s[11] = finfo[x].ext[2]; - putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30); - cursor_y = cons_newline(cursor_y, sheet); - } - } - } - cursor_y = cons_newline(cursor_y, sheet); - } else if (strncmp(cmdline, "type ", 5) == 0 ) { - /* type命令*/ - /*准备文件名*/ - for (y = 0; y < 11; y++) { - s[y] = ' '; - } - y = 0; - for (x = 5; y < 11 && cmdline[x] != 0; x++) { - if (cmdline[x] == '.' && y <= 8) { - y = 8; - } else { - s[y] = cmdline[x]; - if ('a' <= s[y] && s[y] <= 'z') { - /*将小写字母转换成大写字母 */ - s[y] -= 0x20; - } - y++; - } - } - /*寻找文件*/ - for (x = 0; x < 224; ) { - if (finfo[x].name[0] == 0x00) { - break; - } - if ((finfo[x].type & 0x18) == 0) { - for (y = 0; y < 11; y++) { - if (finfo[x].name[y] != s[y]) { - goto type_next_file; - } - } - break; /*找到文件*/ - } - type_next_file: - x++; - } - if (x < 224 && finfo[x].name[0] != 0x00) { - /*找到文件的情况*/ - y = finfo[x].size; - p = (char *) memman_alloc_4k(memman, finfo[x].size); - file_loadfile(finfo[x].clustno, finfo[x].size, p, fat, (char *) (ADR_DISKIMG + 0x003e00)); - cursor_x = 8; - for (y = 0; y < finfo[x].size; y++) { - /*逐字输出*/ - s[0] = p[y]; - s[1] = 0; - if (s[0] == 0x09) { /*制表符*/ - for (;;) { - putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1); - cursor_x += 8; - if (cursor_x == 8 + 240) { - cursor_x = 8; - cursor_y = cons_newline(cursor_y, sheet); - } - if (((cursor_x - 8) & 0x1f) == 0) { - break; /*被32整除则break */ - } - } - } else if (s[0] == 0x0a) { /*换行*/ - cursor_x = 8; - cursor_y = cons_newline(cursor_y, sheet); - } else if (s[0] == 0x0d) { /*回车*/ - /*这里暂且不进行任何操作*/ - } else { /*一般字符*/ - putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, s, 1); - cursor_x += 8; - if (cursor_x == 8 + 240) { - cursor_x = 8; - cursor_y = cons_newline(cursor_y, sheet); - } - } - } - memman_free_4k(memman, (int) p, finfo[x].size); - } else { - /*没有找到文件的情况*/ - putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "File not found.", 15); - cursor_y = cons_newline(cursor_y, sheet); - } - cursor_y = cons_newline(cursor_y, sheet); - } else if (cmdline[0] != 0) { - /*不是命令,也不是空行 */ - putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "Bad command.", 12); - cursor_y = cons_newline(cursor_y, sheet); - cursor_y = cons_newline(cursor_y, sheet); - } - /*显示提示符*/ - putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, ">", 1); - cursor_x = 16; - } else { - /*一般字符*/ - if (cursor_x < 240) { - /*显示一个字符之后将光标后移一位 */ - s[0] = i - 256; - s[1] = 0; - cmdline[cursor_x / 8 - 2] = i - 256; - putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, s, 1); - cursor_x += 8; - } - } - } - /*重新显示光标*/ - if (cursor_c >= 0) { - boxfill8(sheet->buf, sheet->bxsize, cursor_c, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15); - } - sheet_refresh(sheet, cursor_x, cursor_y, cursor_x + 8, cursor_y + 16); - } - } -} - -int cons_newline(int cursor_y, struct SHEET *sheet) -{ - int x, y; - if (cursor_y < 28 + 112) { - cursor_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]; - } - } - 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); - } - return cursor_y; -} - -void file_readfat(int *fat, unsigned char *img) -/*将磁盘映像中的FAT解压缩 */ -{ - int i, j = 0; - for (i = 0; i < 2880; i += 2) { - fat[i + 0] = (img[j + 0] | img[j + 1] << 8) & 0xfff; - fat[i + 1] = (img[j + 1] >> 4 | img[j + 2] << 4) & 0xfff; - j += 3; - } - return; -} - -void file_loadfile(int clustno, int size, char *buf, int *fat, char *img) -{ - int i; - for (;;) { - if (size <= 512) { - for (i = 0; i < size; i++) { - buf[i] = img[clustno * 512 + i]; - } - break; - } - for (i = 0; i < 512; i++) { - buf[i] = img[clustno * 512 + i]; - } - size -= 512; - buf += 512; - clustno = fat[clustno]; - } - return; -} diff --git a/19_day/bootpack.h b/19_day/bootpack.h index 1b58836..91618b5 100644 --- a/19_day/bootpack.h +++ b/19_day/bootpack.h @@ -220,3 +220,23 @@ struct TASK *task_alloc(void); void task_run(struct TASK *task, int level, int priority); void task_switch(void); void task_sleep(struct TASK *task); + +/* window.c */ +void make_window8(unsigned char *buf, int xsize, int ysize, char *title, char act); +void putfonts8_asc_sht(struct SHEET *sht, int x, int y, int c, int b, char *s, int l); +void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c); +void make_wtitle8(unsigned char *buf, int xsize, char *title, char act); + +/* console.c */ +void console_task(struct SHEET *sheet, unsigned int memtotal); +int cons_newline(int cursor_y, struct SHEET *sheet); + +/* file.c */ +struct FILEINFO { + unsigned char name[8], ext[3], type; + char reserve[10]; + unsigned short time, date, clustno; + unsigned int size; +}; +void file_readfat(int *fat, unsigned char *img); +void file_loadfile(int clustno, int size, char *buf, int *fat, char *img); diff --git a/19_day/console.c b/19_day/console.c new file mode 100644 index 0000000..4001293 --- /dev/null +++ b/19_day/console.c @@ -0,0 +1,238 @@ +/* 命令行窗口相关 */ + +#include "bootpack.h" +#include +#include + +int cons_newline(int cursor_y, struct SHEET *sheet) +{ + int x, y; + if (cursor_y < 28 + 112) { + cursor_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]; + } + } + 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); + } + return cursor_y; +} + +void console_task(struct SHEET *sheet, unsigned int memtotal) +{ + struct TIMER *timer; + struct TASK *task = task_now(); + int i, fifobuf[128], cursor_x = 16, cursor_y = 28, cursor_c = -1; + char s[30], cmdline[30], *p; + struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; + int x, y; + struct FILEINFO *finfo = (struct FILEINFO *) (ADR_DISKIMG + 0x002600); + int *fat = (int *) memman_alloc_4k(memman, 4 * 2880); + + fifo32_init(&task->fifo, 128, fifobuf, task); + timer = timer_alloc(); + timer_init(timer, &task->fifo, 1); + timer_settime(timer, 50); + file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200)); + + /*显示提示符*/ + putfonts8_asc_sht(sheet, 8, 28, COL8_FFFFFF, COL8_000000, ">", 1); + + for (;;) { + io_cli(); + if (fifo32_status(&task->fifo) == 0) { + task_sleep(task); + io_sti(); + } else { + i = fifo32_get(&task->fifo); + io_sti(); + if (i <= 1) { /*光标用定时器*/ + if (i != 0) { + timer_init(timer, &task->fifo, 0); /*下次置0 */ + if (cursor_c >= 0) { + cursor_c = COL8_FFFFFF; + } + } else { + timer_init(timer, &task->fifo, 1); /*下次置1 */ + if (cursor_c >= 0) { + cursor_c = COL8_000000; + } + } + timer_settime(timer, 50); + } + if (i == 2) { /*光标ON */ + cursor_c = COL8_FFFFFF; + } + if (i == 3) { /*光标OFF */ + boxfill8(sheet->buf, sheet->bxsize, COL8_000000, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15); + cursor_c = -1; + } + if (256 <= i && i <= 511) { /*键盘数据(通过任务A) */ + if (i == 8 + 256) { + /*退格键*/ + if (cursor_x > 16) { + /*用空白擦除光标后将光标前移一位*/ + putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1); + cursor_x -= 8; + } + } else if (i == 10 + 256) { + /*回车键*/ + /*用空格将光标擦除*/ + putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1); + cmdline[cursor_x / 8 - 2] = 0; + cursor_y = cons_newline(cursor_y, sheet); + /*执行命令*/ + if (strcmp(cmdline, "mem") == 0) { + /* mem命令*/ + sprintf(s, "total %dMB", memtotal / (1024 * 1024)); + putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30); + cursor_y = cons_newline(cursor_y, sheet); + sprintf(s, "free %dKB", memman_total(memman) / 1024); + putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30); + cursor_y = cons_newline(cursor_y, sheet); + cursor_y = cons_newline(cursor_y, sheet); + } else if (strcmp(cmdline, "cls") == 0) { + /* cls命令*/ + for (y = 28; 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); + cursor_y = 28; + } else if (strcmp(cmdline, "dir") == 0 || strcmp(cmdline, "ls") == 0) { + /* dir命令 */ + for (x = 0; x < 224; x++) { + if (finfo[x].name[0] == 0x00) { + break; + } + if (finfo[x].name[0] != 0xe5) { + if ((finfo[x].type & 0x18) == 0) { + sprintf(s, "filename.ext %7d", finfo[x].size); + for (y = 0; y < 8; y++) { + s[y] = finfo[x].name[y]; + } + s[ 9] = finfo[x].ext[0]; + s[10] = finfo[x].ext[1]; + s[11] = finfo[x].ext[2]; + putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30); + cursor_y = cons_newline(cursor_y, sheet); + } + } + } + cursor_y = cons_newline(cursor_y, sheet); + } else if (strncmp(cmdline, "type ", 5) == 0 ) { + /* type命令*/ + /*准备文件名*/ + for (y = 0; y < 11; y++) { + s[y] = ' '; + } + y = 0; + for (x = 5; y < 11 && cmdline[x] != 0; x++) { + if (cmdline[x] == '.' && y <= 8) { + y = 8; + } else { + s[y] = cmdline[x]; + if ('a' <= s[y] && s[y] <= 'z') { + /*将小写字母转换成大写字母 */ + s[y] -= 0x20; + } + y++; + } + } + /*寻找文件*/ + for (x = 0; x < 224; ) { + if (finfo[x].name[0] == 0x00) { + break; + } + if ((finfo[x].type & 0x18) == 0) { + for (y = 0; y < 11; y++) { + if (finfo[x].name[y] != s[y]) { + goto type_next_file; + } + } + break; /*找到文件*/ + } + type_next_file: + x++; + } + if (x < 224 && finfo[x].name[0] != 0x00) { + /*找到文件的情况*/ + y = finfo[x].size; + p = (char *) memman_alloc_4k(memman, finfo[x].size); + file_loadfile(finfo[x].clustno, finfo[x].size, p, fat, (char *) (ADR_DISKIMG + 0x003e00)); + cursor_x = 8; + for (y = 0; y < finfo[x].size; y++) { + /*逐字输出*/ + s[0] = p[y]; + s[1] = 0; + if (s[0] == 0x09) { /*制表符*/ + for (;;) { + putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1); + cursor_x += 8; + if (cursor_x == 8 + 240) { + cursor_x = 8; + cursor_y = cons_newline(cursor_y, sheet); + } + if (((cursor_x - 8) & 0x1f) == 0) { + break; /*被32整除则break */ + } + } + } else if (s[0] == 0x0a) { /*换行*/ + cursor_x = 8; + cursor_y = cons_newline(cursor_y, sheet); + } else if (s[0] == 0x0d) { /*回车*/ + /*这里暂且不进行任何操作*/ + } else { /*一般字符*/ + putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, s, 1); + cursor_x += 8; + if (cursor_x == 8 + 240) { + cursor_x = 8; + cursor_y = cons_newline(cursor_y, sheet); + } + } + } + memman_free_4k(memman, (int) p, finfo[x].size); + } else { + /*没有找到文件的情况*/ + putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "File not found.", 15); + cursor_y = cons_newline(cursor_y, sheet); + } + cursor_y = cons_newline(cursor_y, sheet); + } else if (cmdline[0] != 0) { + /*不是命令,也不是空行 */ + putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "Bad command.", 12); + cursor_y = cons_newline(cursor_y, sheet); + cursor_y = cons_newline(cursor_y, sheet); + } + /*显示提示符*/ + putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, ">", 1); + cursor_x = 16; + } else { + /*一般字符*/ + if (cursor_x < 240) { + /*显示一个字符之后将光标后移一位 */ + s[0] = i - 256; + s[1] = 0; + cmdline[cursor_x / 8 - 2] = i - 256; + putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, s, 1); + cursor_x += 8; + } + } + } + /*重新显示光标*/ + if (cursor_c >= 0) { + boxfill8(sheet->buf, sheet->bxsize, cursor_c, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15); + } + sheet_refresh(sheet, cursor_x, cursor_y, cursor_x + 8, cursor_y + 16); + } + } +} diff --git a/19_day/file.c b/19_day/file.c new file mode 100644 index 0000000..c743de9 --- /dev/null +++ b/19_day/file.c @@ -0,0 +1,35 @@ +/* 文件相关函数 */ + +#include "bootpack.h" + +void file_readfat(int *fat, unsigned char *img) +/*将磁盘映像中的FAT解压缩 */ +{ + int i, j = 0; + for (i = 0; i < 2880; i += 2) { + fat[i + 0] = (img[j + 0] | img[j + 1] << 8) & 0xfff; + fat[i + 1] = (img[j + 1] >> 4 | img[j + 2] << 4) & 0xfff; + j += 3; + } + return; +} + +void file_loadfile(int clustno, int size, char *buf, int *fat, char *img) +{ + int i; + for (;;) { + if (size <= 512) { + for (i = 0; i < size; i++) { + buf[i] = img[clustno * 512 + i]; + } + break; + } + for (i = 0; i < 512; i++) { + buf[i] = img[clustno * 512 + i]; + } + size -= 512; + buf += 512; + clustno = fat[clustno]; + } + return; +} diff --git a/19_day/window.c b/19_day/window.c new file mode 100644 index 0000000..ec625bb --- /dev/null +++ b/19_day/window.c @@ -0,0 +1,88 @@ +/* 窗口相关函数 */ + +#include "bootpack.h" + +void make_window8(unsigned char *buf, int xsize, int ysize, char *title, char act) +{ + boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, xsize - 1, 0 ); + boxfill8(buf, xsize, COL8_FFFFFF, 1, 1, xsize - 2, 1 ); + boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, 0, ysize - 1); + boxfill8(buf, xsize, COL8_FFFFFF, 1, 1, 1, ysize - 2); + boxfill8(buf, xsize, COL8_848484, xsize - 2, 1, xsize - 2, ysize - 2); + boxfill8(buf, xsize, COL8_000000, xsize - 1, 0, xsize - 1, ysize - 1); + boxfill8(buf, xsize, COL8_C6C6C6, 2, 2, xsize - 3, ysize - 3); + boxfill8(buf, xsize, COL8_848484, 1, ysize - 2, xsize - 2, ysize - 2); + boxfill8(buf, xsize, COL8_000000, 0, ysize - 1, xsize - 1, ysize - 1); + make_wtitle8(buf, xsize, title, act); + return; +} + +void make_wtitle8(unsigned char *buf, int xsize, char *title, char act) +{ + static char closebtn[14][16] = { + "OOOOOOOOOOOOOOO@", + "OQQQQQQQQQQQQQ$@", + "OQQQQQQQQQQQQQ$@", + "OQQQ@@QQQQ@@QQ$@", + "OQQQQ@@QQ@@QQQ$@", + "OQQQQQ@@@@QQQQ$@", + "OQQQQQQ@@QQQQQ$@", + "OQQQQQ@@@@QQQQ$@", + "OQQQQ@@QQ@@QQQ$@", + "OQQQ@@QQQQ@@QQ$@", + "OQQQQQQQQQQQQQ$@", + "OQQQQQQQQQQQQQ$@", + "O$$$$$$$$$$$$$$@", + "@@@@@@@@@@@@@@@@" + }; + int x, y; + char c, tc, tbc; + if (act != 0) { + tc = COL8_FFFFFF; + tbc = COL8_000084; + } else { + tc = COL8_C6C6C6; + tbc = COL8_848484; + } + boxfill8(buf, xsize, tbc, 3, 3, xsize - 4, 20); + putfonts8_asc(buf, xsize, 24, 4, tc, title); + for (y = 0; y < 14; y++) { + for (x = 0; x < 16; x++) { + c = closebtn[y][x]; + if (c == '@') { + c = COL8_000000; + } else if (c == '$') { + c = COL8_848484; + } else if (c == 'Q') { + c = COL8_C6C6C6; + } else { + c = COL8_FFFFFF; + } + buf[(5 + y) * xsize + (xsize - 21 + x)] = c; + } + } + return; +} + +void putfonts8_asc_sht(struct SHEET *sht, int x, int y, int c, int b, char *s, int l) +{ + boxfill8(sht->buf, sht->bxsize, b, x, y, x + l * 8 - 1, y + 15); + putfonts8_asc(sht->buf, sht->bxsize, x, y, c, s); + sheet_refresh(sht, x, y, x + l * 8, y + 16); + return; +} + +void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c) +{ + int x1 = x0 + sx, y1 = y0 + sy; + boxfill8(sht->buf, sht->bxsize, COL8_848484, x0 - 2, y0 - 3, x1 + 1, y0 - 3); + boxfill8(sht->buf, sht->bxsize, COL8_848484, x0 - 3, y0 - 3, x0 - 3, y1 + 1); + boxfill8(sht->buf, sht->bxsize, COL8_FFFFFF, x0 - 3, y1 + 2, x1 + 1, y1 + 2); + boxfill8(sht->buf, sht->bxsize, COL8_FFFFFF, x1 + 2, y0 - 3, x1 + 2, y1 + 2); + boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 1, y0 - 2, x1 + 0, y0 - 2); + boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 2, y0 - 2, x0 - 2, y1 + 0); + boxfill8(sht->buf, sht->bxsize, COL8_C6C6C6, x0 - 2, y1 + 1, x1 + 0, y1 + 1); + boxfill8(sht->buf, sht->bxsize, COL8_C6C6C6, x1 + 1, y0 - 2, x1 + 1, y1 + 1); + boxfill8(sht->buf, sht->bxsize, c, x0 - 1, y0 - 1, x1 + 0, y1 + 0); + return; +}