From 86791cd7f4cd939ff8f4f0fcf2befdc78d03d824 Mon Sep 17 00:00:00 2001 From: Yourtion Date: Wed, 18 May 2016 11:41:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=A1=8CAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 28_day/Makefile | 6 +++++- 28_day/apilib.h | 1 + 28_day/apilib/Makefile | 2 +- 28_day/apilib/api026.nas | 17 +++++++++++++++++ 28_day/haribote/bootpack.h | 2 +- 28_day/haribote/console.c | 35 ++++++++++++++--------------------- 28_day/type/!cons_9x.bat | 1 + 28_day/type/!cons_nt.bat | 1 + 28_day/type/Makefile | 5 +++++ 28_day/type/make.bat | 1 + 28_day/type/type.c | 23 +++++++++++++++++++++++ 11 files changed, 70 insertions(+), 24 deletions(-) create mode 100644 28_day/apilib/api026.nas create mode 100644 28_day/type/!cons_9x.bat create mode 100644 28_day/type/!cons_nt.bat create mode 100644 28_day/type/Makefile create mode 100644 28_day/type/make.bat create mode 100644 28_day/type/type.c diff --git a/28_day/Makefile b/28_day/Makefile index 3cd3639..046fcf9 100644 --- a/28_day/Makefile +++ b/28_day/Makefile @@ -21,7 +21,7 @@ haribote.img : haribote/ipl10.bin haribote/haribote.sys Makefile \ lines/lines.hrb walk/walk.hrb noodle/noodle.hrb \ beepdown/beepdown.hrb color/color.hrb color2/color2.hrb \ sosu/sosu.hrb sosu2/sosu2.hrb sosu3/sosu3.hrb \ - typeipl/typeipl.hrb + typeipl/typeipl.hrb type/type.hrb $(EDIMG) imgin:../z_tools/fdimg0at.tek \ wbinimg src:haribote/ipl10.bin len:512 from:0 to:0 \ copy from:haribote/haribote.sys to:@: \ @@ -47,6 +47,7 @@ haribote.img : haribote/ipl10.bin haribote/haribote.sys Makefile \ copy from:sosu2/sosu2.hrb to:@: \ copy from:sosu3/sosu3.hrb to:@: \ copy from:typeipl/typeipl.hrb to:@: \ + copy from:type/type.hrb to:@: \ imgout:haribote.img #命令 @@ -83,6 +84,7 @@ full : $(MAKE) -C sosu2 $(MAKE) -C sosu3 $(MAKE) -C typeipl + $(MAKE) -C type $(MAKE) haribote.img run_full : @@ -128,6 +130,7 @@ clean_full : $(MAKE) -C sosu2 clean $(MAKE) -C sosu3 clean $(MAKE) -C typeipl clean + $(MAKE) -C type clean src_only_full : $(MAKE) -C haribote src_only @@ -152,6 +155,7 @@ src_only_full : $(MAKE) -C sosu2 src_only $(MAKE) -C sosu3 src_only $(MAKE) -C typeipl src_only + $(MAKE) -C type src_only -$(DEL) haribote.img refresh : diff --git a/28_day/apilib.h b/28_day/apilib.h index 07b8021..fbf0884 100644 --- a/28_day/apilib.h +++ b/28_day/apilib.h @@ -23,3 +23,4 @@ void api_fclose(int fhandle); void api_fseek(int fhandle, int offset, int mode); int api_fsize(int fhandle, int mode); int api_fread(char *buf, int maxsize, int fhandle); +int api_cmdline(char *buf, int maxsize); diff --git a/28_day/apilib/Makefile b/28_day/apilib/Makefile index 3c35274..b40633b 100644 --- a/28_day/apilib/Makefile +++ b/28_day/apilib/Makefile @@ -2,7 +2,7 @@ OBJS_API = api001.obj api002.obj api003.obj api004.obj api005.obj api006.obj \ api007.obj api008.obj api009.obj api010.obj api011.obj api012.obj \ api013.obj api014.obj api015.obj api016.obj api017.obj api018.obj \ api019.obj api020.obj api021.obj api022.obj api023.obj api024.obj \ - api025.obj alloca.obj + api025.obj api026.obj alloca.obj TOOLPATH = ../../z_tools/ INCPATH = ../../z_tools/haribote/ diff --git a/28_day/apilib/api026.nas b/28_day/apilib/api026.nas new file mode 100644 index 0000000..33bb2f5 --- /dev/null +++ b/28_day/apilib/api026.nas @@ -0,0 +1,17 @@ +[FORMAT "WCOFF"] +[INSTRSET "i486p"] +[BITS 32] +[FILE "api026.nas"] + + GLOBAL _api_cmdline + +[SECTION .text] + +_api_cmdline: ; int api_cmdline(char *buf, int maxsize); + PUSH EBX + MOV EDX,26 + MOV ECX,[ESP+12] ; maxsize + MOV EBX,[ESP+8] ; buf + INT 0x40 + POP EBX + RET diff --git a/28_day/haribote/bootpack.h b/28_day/haribote/bootpack.h index 85ee710..56c12b8 100644 --- a/28_day/haribote/bootpack.h +++ b/28_day/haribote/bootpack.h @@ -216,6 +216,7 @@ struct TASK { int ds_base, cons_stack; struct FILEHANDLE *fhandle; int *fat; + char *cmdline; }; struct TASKLEVEL { int running; /*正在运行的任务数量*/ @@ -264,7 +265,6 @@ void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal); void cmd_mem(struct CONSOLE *cons, 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_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); diff --git a/28_day/haribote/console.c b/28_day/haribote/console.c index 3dd0440..3d0c70b 100644 --- a/28_day/haribote/console.c +++ b/28_day/haribote/console.c @@ -18,6 +18,7 @@ void console_task(struct SHEET *sheet, int memtotal) cons.cur_y = 28; cons.cur_c = -1; task->cons = &cons; + task->cmdline = cmdline; if (cons.sht != 0) { cons.timer = timer_alloc(); @@ -198,8 +199,6 @@ void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal) cmd_cls(cons); } else if ((strcmp(cmdline, "dir") == 0 || strcmp(cmdline, "ls") == 0) && cons->sht != 0) { cmd_dir(cons); - } 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) { @@ -264,25 +263,6 @@ void cmd_dir(struct CONSOLE *cons) return; } -void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline) -{ - struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; - struct FILEINFO *finfo = file_search(cmdline + 5, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); - char *p; - if (finfo != 0) { - /*找到文件的情况*/ - p = (char *) memman_alloc_4k(memman, finfo->size); - file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00)); - cons_putstr1(cons, p, finfo->size); - memman_free_4k(memman, (int) p, finfo->size); - } else { - /*没有找到文件的情况*/ - cons_putstr0(cons, "File not found.\n"); - } - cons_newline(cons); - return; -} - void cmd_exit(struct CONSOLE *cons, int *fat) { struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; @@ -600,6 +580,19 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int fh->pos++; } reg[7] = i; + } else if (edx == 26) { + i = 0; + for (;;) { + *((char *) ebx + ds_base + i) = task->cmdline[i]; + if (task->cmdline[i] == 0) { + break; + } + if (i >= ecx) { + break; + } + i++; + } + reg[7] = i; } return 0; } diff --git a/28_day/type/!cons_9x.bat b/28_day/type/!cons_9x.bat new file mode 100644 index 0000000..e42252a --- /dev/null +++ b/28_day/type/!cons_9x.bat @@ -0,0 +1 @@ +command \ No newline at end of file diff --git a/28_day/type/!cons_nt.bat b/28_day/type/!cons_nt.bat new file mode 100644 index 0000000..6e07473 --- /dev/null +++ b/28_day/type/!cons_nt.bat @@ -0,0 +1 @@ +cmd.exe \ No newline at end of file diff --git a/28_day/type/Makefile b/28_day/type/Makefile new file mode 100644 index 0000000..7314b7b --- /dev/null +++ b/28_day/type/Makefile @@ -0,0 +1,5 @@ +APP = type +STACK = 1k +MALLOC = 0k + +include ../app_make.txt diff --git a/28_day/type/make.bat b/28_day/type/make.bat new file mode 100644 index 0000000..6b0dbfc --- /dev/null +++ b/28_day/type/make.bat @@ -0,0 +1 @@ +..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 \ No newline at end of file diff --git a/28_day/type/type.c b/28_day/type/type.c new file mode 100644 index 0000000..c6fc99f --- /dev/null +++ b/28_day/type/type.c @@ -0,0 +1,23 @@ +#include "apilib.h" + +void HariMain(void) +{ + int fh; + char c, cmdline[30], *p; + + api_cmdline(cmdline, 30); + for (p = cmdline; *p > ' '; p++) { } /*跳过之前的内容,直到遇到空格*/ + for (; *p == ' '; p++) { } /*跳过空格*/ + fh = api_fopen(p); + if (fh != 0) { + for (;;) { + if (api_fread(&c, 1, fh) == 0) { + break; + } + api_putchar(c); + } + } else { + api_putstr0("File not found.\n"); + } + api_end(); +}