mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-02 17:49:01 +08:00
命令行API
This commit is contained in:
@@ -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 :
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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/
|
||||
|
||||
17
28_day/apilib/api026.nas
Normal file
17
28_day/apilib/api026.nas
Normal file
@@ -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
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
1
28_day/type/!cons_9x.bat
Normal file
1
28_day/type/!cons_9x.bat
Normal file
@@ -0,0 +1 @@
|
||||
command
|
||||
1
28_day/type/!cons_nt.bat
Normal file
1
28_day/type/!cons_nt.bat
Normal file
@@ -0,0 +1 @@
|
||||
cmd.exe
|
||||
5
28_day/type/Makefile
Normal file
5
28_day/type/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
APP = type
|
||||
STACK = 1k
|
||||
MALLOC = 0k
|
||||
|
||||
include ../app_make.txt
|
||||
1
28_day/type/make.bat
Normal file
1
28_day/type/make.bat
Normal file
@@ -0,0 +1 @@
|
||||
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
23
28_day/type/type.c
Normal file
23
28_day/type/type.c
Normal file
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user