From 9231ce4a386e43ae1173a75562f47778a03b5ae9 Mon Sep 17 00:00:00 2001 From: Yourtion Date: Wed, 18 May 2016 11:31:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=93=8D=E4=BD=9CAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 28_day/Makefile | 7 +++- 28_day/apilib.h | 5 +++ 28_day/apilib/Makefile | 4 +-- 28_day/apilib/api021.nas | 16 +++++++++ 28_day/apilib/api022.nas | 14 ++++++++ 28_day/apilib/api023.nas | 18 ++++++++++ 28_day/apilib/api024.nas | 15 ++++++++ 28_day/apilib/api025.nas | 18 ++++++++++ 28_day/haribote/bootpack.h | 7 ++++ 28_day/haribote/console.c | 72 +++++++++++++++++++++++++++++++++++++ 28_day/typeipl/!cons_9x.bat | 1 + 28_day/typeipl/!cons_nt.bat | 1 + 28_day/typeipl/Makefile | 5 +++ 28_day/typeipl/make.bat | 1 + 28_day/typeipl/typeipl.c | 17 +++++++++ 15 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 28_day/apilib/api021.nas create mode 100644 28_day/apilib/api022.nas create mode 100644 28_day/apilib/api023.nas create mode 100644 28_day/apilib/api024.nas create mode 100644 28_day/apilib/api025.nas create mode 100644 28_day/typeipl/!cons_9x.bat create mode 100644 28_day/typeipl/!cons_nt.bat create mode 100644 28_day/typeipl/Makefile create mode 100644 28_day/typeipl/make.bat create mode 100644 28_day/typeipl/typeipl.c diff --git a/28_day/Makefile b/28_day/Makefile index 732a74d..3cd3639 100644 --- a/28_day/Makefile +++ b/28_day/Makefile @@ -20,7 +20,8 @@ haribote.img : haribote/ipl10.bin haribote/haribote.sys Makefile \ star1/star1.hrb stars/stars.hrb stars2/stars2.hrb \ 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 + sosu/sosu.hrb sosu2/sosu2.hrb sosu3/sosu3.hrb \ + typeipl/typeipl.hrb $(EDIMG) imgin:../z_tools/fdimg0at.tek \ wbinimg src:haribote/ipl10.bin len:512 from:0 to:0 \ copy from:haribote/haribote.sys to:@: \ @@ -45,6 +46,7 @@ haribote.img : haribote/ipl10.bin haribote/haribote.sys Makefile \ copy from:sosu/sosu.hrb to:@: \ copy from:sosu2/sosu2.hrb to:@: \ copy from:sosu3/sosu3.hrb to:@: \ + copy from:typeipl/typeipl.hrb to:@: \ imgout:haribote.img #命令 @@ -80,6 +82,7 @@ full : $(MAKE) -C sosu $(MAKE) -C sosu2 $(MAKE) -C sosu3 + $(MAKE) -C typeipl $(MAKE) haribote.img run_full : @@ -124,6 +127,7 @@ clean_full : $(MAKE) -C sosu clean $(MAKE) -C sosu2 clean $(MAKE) -C sosu3 clean + $(MAKE) -C typeipl clean src_only_full : $(MAKE) -C haribote src_only @@ -147,6 +151,7 @@ src_only_full : $(MAKE) -C sosu src_only $(MAKE) -C sosu2 src_only $(MAKE) -C sosu3 src_only + $(MAKE) -C typeipl src_only -$(DEL) haribote.img refresh : diff --git a/28_day/apilib.h b/28_day/apilib.h index 80ec6e0..07b8021 100644 --- a/28_day/apilib.h +++ b/28_day/apilib.h @@ -18,3 +18,8 @@ void api_inittimer(int timer, int data); void api_settimer(int timer, int time); void api_freetimer(int timer); void api_beep(int tone); +int api_fopen(char *fname); +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); diff --git a/28_day/apilib/Makefile b/28_day/apilib/Makefile index 05c00ea..3c35274 100644 --- a/28_day/apilib/Makefile +++ b/28_day/apilib/Makefile @@ -1,8 +1,8 @@ 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 \ - alloca.obj + api019.obj api020.obj api021.obj api022.obj api023.obj api024.obj \ + api025.obj alloca.obj TOOLPATH = ../../z_tools/ INCPATH = ../../z_tools/haribote/ diff --git a/28_day/apilib/api021.nas b/28_day/apilib/api021.nas new file mode 100644 index 0000000..565a037 --- /dev/null +++ b/28_day/apilib/api021.nas @@ -0,0 +1,16 @@ +[FORMAT "WCOFF"] +[INSTRSET "i486p"] +[BITS 32] +[FILE "api021.nas"] + + GLOBAL _api_fopen + +[SECTION .text] + +_api_fopen: ; int api_fopen(char *fname); + PUSH EBX + MOV EDX,21 + MOV EBX,[ESP+8] ; fname + INT 0x40 + POP EBX + RET diff --git a/28_day/apilib/api022.nas b/28_day/apilib/api022.nas new file mode 100644 index 0000000..a21f508 --- /dev/null +++ b/28_day/apilib/api022.nas @@ -0,0 +1,14 @@ +[FORMAT "WCOFF"] +[INSTRSET "i486p"] +[BITS 32] +[FILE "api022.nas"] + + GLOBAL _api_fclose + +[SECTION .text] + +_api_fclose: ; void api_fclose(int fhandle); + MOV EDX,22 + MOV EAX,[ESP+4] ; fhandle + INT 0x40 + RET diff --git a/28_day/apilib/api023.nas b/28_day/apilib/api023.nas new file mode 100644 index 0000000..f34c33b --- /dev/null +++ b/28_day/apilib/api023.nas @@ -0,0 +1,18 @@ +[FORMAT "WCOFF"] +[INSTRSET "i486p"] +[BITS 32] +[FILE "api023.nas"] + + GLOBAL _api_fseek + +[SECTION .text] + +_api_fseek: ; void api_fseek(int fhandle, int offset, int mode); + PUSH EBX + MOV EDX,23 + MOV EAX,[ESP+8] ; fhandle + MOV ECX,[ESP+16] ; mode + MOV EBX,[ESP+12] ; offset + INT 0x40 + POP EBX + RET diff --git a/28_day/apilib/api024.nas b/28_day/apilib/api024.nas new file mode 100644 index 0000000..5352889 --- /dev/null +++ b/28_day/apilib/api024.nas @@ -0,0 +1,15 @@ +[FORMAT "WCOFF"] +[INSTRSET "i486p"] +[BITS 32] +[FILE "api024.nas"] + + GLOBAL _api_fsize + +[SECTION .text] + +_api_fsize: ; int api_fsize(int fhandle, int mode); + MOV EDX,24 + MOV EAX,[ESP+4] ; fhandle + MOV ECX,[ESP+8] ; mode + INT 0x40 + RET diff --git a/28_day/apilib/api025.nas b/28_day/apilib/api025.nas new file mode 100644 index 0000000..9f394d3 --- /dev/null +++ b/28_day/apilib/api025.nas @@ -0,0 +1,18 @@ +[FORMAT "WCOFF"] +[INSTRSET "i486p"] +[BITS 32] +[FILE "api025.nas"] + + GLOBAL _api_fread + +[SECTION .text] + +_api_fread: ; int api_fread(char *buf, int maxsize, int fhandle); + PUSH EBX + MOV EDX,25 + MOV EAX,[ESP+16] ; fhandle + 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 f4ec328..85ee710 100644 --- a/28_day/haribote/bootpack.h +++ b/28_day/haribote/bootpack.h @@ -214,6 +214,8 @@ struct TASK { struct SEGMENT_DESCRIPTOR ldt[2]; struct CONSOLE *cons; int ds_base, cons_stack; + struct FILEHANDLE *fhandle; + int *fat; }; struct TASKLEVEL { int running; /*正在运行的任务数量*/ @@ -248,6 +250,11 @@ struct CONSOLE { int cur_x, cur_y, cur_c; struct TIMER *timer; }; +struct FILEHANDLE { + char *buf; + int size; + int pos; +}; void console_task(struct SHEET *sheet, int memtotal); void cons_putchar(struct CONSOLE *cons, int chr, char move); void cons_newline(struct CONSOLE *cons); diff --git a/28_day/haribote/console.c b/28_day/haribote/console.c index 6ce8fdc..3dd0440 100644 --- a/28_day/haribote/console.c +++ b/28_day/haribote/console.c @@ -9,8 +9,10 @@ void console_task(struct SHEET *sheet, int memtotal) struct TASK *task = task_now(); struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; int i, *fat = (int *) memman_alloc_4k(memman, 4 * 2880); + struct FILEHANDLE fhandle[8]; struct CONSOLE cons; char cmdline[30]; + cons.sht = sheet; cons.cur_x = 8; cons.cur_y = 28; @@ -23,6 +25,11 @@ void console_task(struct SHEET *sheet, int memtotal) timer_settime(cons.timer, 50); } file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200)); + for (i = 0; i < 8; i++) { + fhandle[i].buf = 0; /*未使用标记*/ + } + task->fhandle = fhandle; + task->fat = fat; /*显示提示符*/ cons_putchar(&cons, '>', 1); @@ -387,6 +394,12 @@ int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline) sheet_free(sht); /*关闭*/ } } + for (i = 0; i < 8; i++) { /*将未关闭的文件关闭*/ + if (task->fhandle[i].buf != 0) { + memman_free_4k(memman, (int) task->fhandle[i].buf, task->fhandle[i].size); + task->fhandle[i].buf = 0; + } + } timer_cancelall(&task->fifo); memman_free_4k(memman, (int) q, segsiz); } else { @@ -413,6 +426,9 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int /* reg[0] : EDI, reg[1] : ESI, reg[2] : EBP, reg[3] : ESP */ /* reg[4] : EBX, reg[5] : EDX, reg[6] : ECX, reg[7] : EAX */ int i; + struct FILEINFO *finfo; + struct FILEHANDLE *fh; + struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; if (edx == 1) { cons_putchar(cons, eax & 0xff, 1); @@ -528,6 +544,62 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int i = io_in8(0x61); io_out8(0x61, (i | 0x03) & 0x0f); } + } else if (edx == 21) { + for (i = 0; i < 8; i++) { + if (task->fhandle[i].buf == 0) { + break; + } + } + fh = &task->fhandle[i]; + reg[7] = 0; + if (i < 8) { + finfo = file_search((char *) ebx + ds_base, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); + if (finfo != 0) { + reg[7] = (int) fh; + fh->buf = (char *) memman_alloc_4k(memman, finfo->size); + fh->size = finfo->size; + fh->pos = 0; + file_loadfile(finfo->clustno, finfo->size, fh->buf, task->fat, (char *) (ADR_DISKIMG + 0x003e00)); + } + } + } else if (edx == 22) { + fh = (struct FILEHANDLE *) eax; + memman_free_4k(memman, (int) fh->buf, fh->size); + fh->buf = 0; + } else if (edx == 23) { + fh = (struct FILEHANDLE *) eax; + if (ecx == 0) { + fh->pos = ebx; + } else if (ecx == 1) { + fh->pos += ebx; + } else if (ecx == 2) { + fh->pos = fh->size + ebx; + } + if (fh->pos < 0) { + fh->pos = 0; + } + if (fh->pos > fh->size) { + fh->pos = fh->size; + } + } else if (edx == 24) { + fh = (struct FILEHANDLE *) eax; + if (ecx == 0) { + reg[7] = fh->size; + } else if (ecx == 1) { + reg[7] = fh->pos; + } else if (ecx == 2) { + reg[7] = fh->pos - fh->size; + } + } else if (edx == 25) { + fh = (struct FILEHANDLE *) eax; + for (i = 0; i < ecx; i++) { + if (fh->pos == fh->size) { + break; + } + *((char *) ebx + ds_base + i) = fh->buf[fh->pos]; + fh->pos++; + } + reg[7] = i; } return 0; } diff --git a/28_day/typeipl/!cons_9x.bat b/28_day/typeipl/!cons_9x.bat new file mode 100644 index 0000000..e42252a --- /dev/null +++ b/28_day/typeipl/!cons_9x.bat @@ -0,0 +1 @@ +command \ No newline at end of file diff --git a/28_day/typeipl/!cons_nt.bat b/28_day/typeipl/!cons_nt.bat new file mode 100644 index 0000000..6e07473 --- /dev/null +++ b/28_day/typeipl/!cons_nt.bat @@ -0,0 +1 @@ +cmd.exe \ No newline at end of file diff --git a/28_day/typeipl/Makefile b/28_day/typeipl/Makefile new file mode 100644 index 0000000..f5b423e --- /dev/null +++ b/28_day/typeipl/Makefile @@ -0,0 +1,5 @@ +APP = typeipl +STACK = 1k +MALLOC = 0k + +include ../app_make.txt diff --git a/28_day/typeipl/make.bat b/28_day/typeipl/make.bat new file mode 100644 index 0000000..6b0dbfc --- /dev/null +++ b/28_day/typeipl/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/typeipl/typeipl.c b/28_day/typeipl/typeipl.c new file mode 100644 index 0000000..90a0273 --- /dev/null +++ b/28_day/typeipl/typeipl.c @@ -0,0 +1,17 @@ +#include "apilib.h" + +void HariMain(void) +{ + int fh; + char c; + fh = api_fopen("ipl10.nas"); + if (fh != 0) { + for (;;) { + if (api_fread(&c, 1, fh) == 0) { + break; + } + api_putchar(c); + } + } + api_end(); +}