From 203dd63152150f1863a160b617cd13903b2cb68e Mon Sep 17 00:00:00 2001 From: Yourtion Date: Thu, 19 May 2016 14:05:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E5=87=86=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 29_day/Makefile | 3 +++ 29_day/app_make.txt | 13 +++++++--- 29_day/hello4/Makefile | 2 +- 29_day/hello4/hello4.c | 6 ++--- 29_day/stdlib.h | 4 +++ 29_day/stdlib/!cons_9x.bat | 1 + 29_day/stdlib/!cons_nt.bat | 1 + 29_day/stdlib/Makefile | 50 +++++++++++++++++++++++++++++++++++++ 29_day/stdlib/make.bat | 1 + 29_day/stdlib/stdlib.c | 51 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 125 insertions(+), 7 deletions(-) create mode 100644 29_day/stdlib.h create mode 100644 29_day/stdlib/!cons_9x.bat create mode 100644 29_day/stdlib/!cons_nt.bat create mode 100644 29_day/stdlib/Makefile create mode 100644 29_day/stdlib/make.bat create mode 100644 29_day/stdlib/stdlib.c diff --git a/29_day/Makefile b/29_day/Makefile index ff541d5..af3fc84 100644 --- a/29_day/Makefile +++ b/29_day/Makefile @@ -67,6 +67,7 @@ install : full : $(MAKE) -C haribote $(MAKE) -C apilib + $(MAKE) -C stdlib $(MAKE) -C a $(MAKE) -C hello3 $(MAKE) -C hello4 @@ -114,6 +115,7 @@ src_only : clean_full : $(MAKE) -C haribote clean $(MAKE) -C apilib clean + $(MAKE) -C stdlib clean $(MAKE) -C a clean $(MAKE) -C hello3 clean $(MAKE) -C hello4 clean @@ -140,6 +142,7 @@ clean_full : src_only_full : $(MAKE) -C haribote src_only $(MAKE) -C apilib src_only + $(MAKE) -C stdlib src_only $(MAKE) -C a src_only $(MAKE) -C hello3 src_only $(MAKE) -C hello4 src_only diff --git a/29_day/app_make.txt b/29_day/app_make.txt index 30421f4..b1e4436 100644 --- a/29_day/app_make.txt +++ b/29_day/app_make.txt @@ -1,6 +1,7 @@ TOOLPATH = ../../z_tools/ INCPATH = ../../z_tools/haribote/ APILIBPATH = ../apilib/ +STDLIBPATH = ../stdlib/ HARIBOTEPATH = ../haribote/ MAKE = $(TOOLPATH)make.exe -r @@ -26,9 +27,13 @@ default : #文件生成规则 -$(APP).bim : $(APP).obj $(APILIBPATH)apilib.lib Makefile ../app_make.txt +$(APP).bim : $(APP).obj $(APILIBPATH)apilib.lib $(STDLIBPATH)stdlib.lib Makefile ../app_make.txt $(OBJ2BIM) @$(RULEFILE) out:$(APP).bim map:$(APP).map stack:$(STACK) \ - $(APP).obj $(APILIBPATH)apilib.lib + $(APP).obj $(APILIBPATH)apilib.lib $(STDLIBPATH)stdlib.lib + +$(STDAPP).bim : $(APP).obj $(STDLIBPATH)stdlib.lib Makefile ../app_make.txt + $(OBJ2BIM) @$(RULEFILE) out:$(APP).bim map:$(APP).map stack:$(STACK) \ + $(APP).obj $(STDLIBPATH)stdlib.lib haribote.img : ../haribote/ipl20.bin ../haribote/haribote.sys $(APP).hrb \ Makefile ../app_make.txt @@ -41,7 +46,7 @@ haribote.img : ../haribote/ipl20.bin ../haribote/haribote.sys $(APP).hrb \ #一般规则 -%.gas : %.c ../apilib.h Makefile ../app_make.txt +%.gas : %.c ../apilib.h ../stdlib.h Makefile ../app_make.txt $(CC1) -o $*.gas $*.c %.nas : %.gas Makefile ../app_make.txt @@ -65,10 +70,12 @@ run : full : $(MAKE) -C $(APILIBPATH) + $(MAKE) -C $(STDLIBPATH) $(MAKE) $(APP).hrb run_full : $(MAKE) -C $(APILIBPATH) + $(MAKE) -C $(STDLIBPATH) $(MAKE) -C ../haribote $(MAKE) run diff --git a/29_day/hello4/Makefile b/29_day/hello4/Makefile index 557a184..ade47c9 100644 --- a/29_day/hello4/Makefile +++ b/29_day/hello4/Makefile @@ -4,5 +4,5 @@ MALLOC = 0k include ../app_make.txt -$(APP).hrb : $(APP).org Makefile +$(STDAPP).hrb : $(APP).org Makefile $(COPY) $(APP).org $(APP).hrb diff --git a/29_day/hello4/hello4.c b/29_day/hello4/hello4.c index ec04384..5a69068 100644 --- a/29_day/hello4/hello4.c +++ b/29_day/hello4/hello4.c @@ -1,7 +1,7 @@ -#include "apilib.h" +#include "stdlib.h" void HariMain(void) { - api_putstr0("hello, world\n"); - api_end(); + printf("hello, world : %s %d\n", "aaa", 10); + exit(0); } diff --git a/29_day/stdlib.h b/29_day/stdlib.h new file mode 100644 index 0000000..e55f70c --- /dev/null +++ b/29_day/stdlib.h @@ -0,0 +1,4 @@ +int putchar(int c); +void exit(int status); +int printf(char *format, ...); +void *malloc(int size); \ No newline at end of file diff --git a/29_day/stdlib/!cons_9x.bat b/29_day/stdlib/!cons_9x.bat new file mode 100644 index 0000000..e42252a --- /dev/null +++ b/29_day/stdlib/!cons_9x.bat @@ -0,0 +1 @@ +command \ No newline at end of file diff --git a/29_day/stdlib/!cons_nt.bat b/29_day/stdlib/!cons_nt.bat new file mode 100644 index 0000000..6e07473 --- /dev/null +++ b/29_day/stdlib/!cons_nt.bat @@ -0,0 +1 @@ +cmd.exe \ No newline at end of file diff --git a/29_day/stdlib/Makefile b/29_day/stdlib/Makefile new file mode 100644 index 0000000..faee897 --- /dev/null +++ b/29_day/stdlib/Makefile @@ -0,0 +1,50 @@ +OBJS_API = stdlib.obj + +TOOLPATH = ../../z_tools/ +INCPATH = ../../z_tools/haribote/ + +MAKE = $(TOOLPATH)make.exe -r +NASK = $(TOOLPATH)nask.exe +CC1 = $(TOOLPATH)cc1.exe -I$(INCPATH) -Os -Wall -quiet +GAS2NASK = $(TOOLPATH)gas2nask.exe -a +OBJ2BIM = $(TOOLPATH)obj2bim.exe +MAKEFONT = $(TOOLPATH)makefont.exe +BIN2OBJ = $(TOOLPATH)bin2obj.exe +BIM2HRB = $(TOOLPATH)bim2hrb.exe +RULEFILE = ../haribote.rul +EDIMG = $(TOOLPATH)edimg.exe +IMGTOL = $(TOOLPATH)imgtol.com +GOLIB = $(TOOLPATH)golib00.exe +COPY = copy +DEL = del + +#默认动作 + +default : + $(MAKE) stdlib.lib + +#库生成规则 + +stdlib.lib : Makefile $(OBJS_API) + $(GOLIB) $(OBJS_API) out:stdlib.lib + +#文件生成规则 + +%.gas : %.c ../stdlib.h Makefile + $(CC1) -o $*.gas $*.c + +%.nas : %.gas Makefile + $(GAS2NASK) $*.gas $*.nas + +%.obj : %.nas Makefile + $(NASK) $*.nas $*.obj $*.lst + +#命令 + +clean : + -$(DEL) *.lst + -$(DEL) *.obj + +src_only : + $(MAKE) clean + -$(DEL) stdlib.lib \ No newline at end of file diff --git a/29_day/stdlib/make.bat b/29_day/stdlib/make.bat new file mode 100644 index 0000000..6b0dbfc --- /dev/null +++ b/29_day/stdlib/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/29_day/stdlib/stdlib.c b/29_day/stdlib/stdlib.c new file mode 100644 index 0000000..5bbeae6 --- /dev/null +++ b/29_day/stdlib/stdlib.c @@ -0,0 +1,51 @@ +#include "../apilib.h" +#include "../stdlib.h" + +#include +#include + +int putchar(int c) +{ + api_putchar(c); + return c; +} + +void exit(int status) +{ + api_end(); +} + +int printf(char *format, ...) +{ + va_list ap; + char s[1000]; + int i; + + va_start(ap, format); + i = vsprintf(s, format, ap); + api_putstr0(s); + va_end(ap); + return i; +} + +void *malloc(int size) +{ + char *p = api_malloc(size + 16); + if (p != 0) { + *((int *) p) = size; + p += 16; + } + return p; +} + +void free(void *p) +{ + char *q = p; + int size; + if (q != 0) { + q -= 16; + size = *((int *) q); + api_free(q, size + 16); + } + return; +} \ No newline at end of file