From 2fb28adf44fbec13caaff56fffb97eda180006e9 Mon Sep 17 00:00:00 2001 From: Yourtion Date: Tue, 3 May 2016 11:55:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E5=BA=94=E7=94=A8=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E8=87=AA=E7=94=B1=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 20_day/Makefile | 8 +++--- 20_day/bootpack.h | 2 +- 20_day/console.c | 49 +++++++++++++++++++++++++---------- 20_day/{hlt.nas => hello.nas} | 0 4 files changed, 40 insertions(+), 19 deletions(-) rename 20_day/{hlt.nas => hello.nas} (100%) diff --git a/20_day/Makefile b/20_day/Makefile index 4e019c9..aed58d4 100644 --- a/20_day/Makefile +++ b/20_day/Makefile @@ -46,10 +46,10 @@ bootpack.bim : $(OBJS_BOOTPACK) Makefile bootpack.hrb : bootpack.bim Makefile $(BIM2HRB) bootpack.bim bootpack.hrb 0 -hlt.hrb : hlt.nas Makefile - $(NASK) hlt.nas hlt.hrb hlt.lst +hello.hrb : hello.nas Makefile + $(NASK) hello.nas hello.hrb hello.lst -haribote.sys : asmhead.bin bootpack.hrb hlt.hrb Makefile +haribote.sys : asmhead.bin bootpack.hrb hello.hrb Makefile copy /B asmhead.bin+bootpack.hrb haribote.sys haribote.img : ipl10.bin haribote.sys Makefile @@ -58,7 +58,7 @@ haribote.img : ipl10.bin haribote.sys Makefile copy from:haribote.sys to:@: \ copy from:ipl10.nas to:@: \ copy from:make.bat to:@: \ - copy from:hlt.hrb to:@: \ + copy from:hello.hrb to:@: \ imgout:haribote.img # 其他指令 diff --git a/20_day/bootpack.h b/20_day/bootpack.h index e850791..d350ba4 100644 --- a/20_day/bootpack.h +++ b/20_day/bootpack.h @@ -242,7 +242,7 @@ void cmd_mem(struct CONSOLE *cons, unsigned 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_hlt(struct CONSOLE *cons, int *fat); +int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline); /* file.c */ struct FILEINFO { diff --git a/20_day/console.c b/20_day/console.c index b99d188..5a4112e 100644 --- a/20_day/console.c +++ b/20_day/console.c @@ -157,13 +157,13 @@ void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, unsigned int mem cmd_dir(cons); } else if (strncmp(cmdline, "type ", 5) == 0) { cmd_type(cons, fat, cmdline); - } else if (strcmp(cmdline, "hlt") == 0) { - cmd_hlt(cons, fat); } else if (cmdline[0] != 0) { - /*不是命令,也不是空行*/ - putfonts8_asc_sht(cons->sht, 8, cons->cur_y, COL8_FFFFFF, COL8_000000, "Bad command.", 12); - cons_newline(cons); - cons_newline(cons); + if (cmd_app(cons, fat, cmdline) == 0) { + /*不是命令,不是应用程序,也不是空行*/ + putfonts8_asc_sht(cons->sht, 8, cons->cur_y, COL8_FFFFFF, COL8_000000, "Bad command.", 12); + cons_newline(cons); + cons_newline(cons); + } } return; } @@ -245,12 +245,35 @@ void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline) return; } -void cmd_hlt(struct CONSOLE *cons, int *fat) +int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline) { struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; - struct FILEINFO *finfo = file_search("HLT.HRB", (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); + struct FILEINFO *finfo; struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT; - char *p; + char name[18], *p; + int i; + + /*根据命令行生成文件名*/ + for (i = 0; i < 13; i++) { + if (cmdline[i] <= ' ') { + break; + } + name[i] = cmdline[i]; + } + name[i] = 0; /*暂且将文件名的后面置为0*/ + + /*寻找文件 */ + finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); + if (finfo == 0 && name[i -1]!= '.') { + /*由于找不到文件,故在文件名后面加上“.hrb”后重新寻找*/ + name[i ] = '.'; + name[i + 1] = 'H'; + name[i + 2] = 'R'; + name[i + 3] = 'B'; + name[i + 4] = 0; + finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); + } + if (finfo != 0) { /*找到文件的情况*/ p = (char *) memman_alloc_4k(memman, finfo->size); @@ -258,11 +281,9 @@ void cmd_hlt(struct CONSOLE *cons, int *fat) set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER); farcall(0, 1003 * 8); memman_free_4k(memman, (int) p, finfo->size); - } else { - /*没有找到文件的情况*/ - putfonts8_asc_sht(cons->sht, 8, cons->cur_y, COL8_FFFFFF, COL8_000000, "File not found.", 15); cons_newline(cons); + return 1; } - cons_newline(cons); - return; + /*没有找到文件的情况*/ + return 0; } diff --git a/20_day/hlt.nas b/20_day/hello.nas similarity index 100% rename from 20_day/hlt.nas rename to 20_day/hello.nas