mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-03 01:53:24 +08:00
标准函数
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
4
29_day/stdlib.h
Normal file
4
29_day/stdlib.h
Normal file
@@ -0,0 +1,4 @@
|
||||
int putchar(int c);
|
||||
void exit(int status);
|
||||
int printf(char *format, ...);
|
||||
void *malloc(int size);
|
||||
1
29_day/stdlib/!cons_9x.bat
Normal file
1
29_day/stdlib/!cons_9x.bat
Normal file
@@ -0,0 +1 @@
|
||||
command
|
||||
1
29_day/stdlib/!cons_nt.bat
Normal file
1
29_day/stdlib/!cons_nt.bat
Normal file
@@ -0,0 +1 @@
|
||||
cmd.exe
|
||||
50
29_day/stdlib/Makefile
Normal file
50
29_day/stdlib/Makefile
Normal file
@@ -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
|
||||
1
29_day/stdlib/make.bat
Normal file
1
29_day/stdlib/make.bat
Normal file
@@ -0,0 +1 @@
|
||||
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
51
29_day/stdlib/stdlib.c
Normal file
51
29_day/stdlib/stdlib.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "../apilib.h"
|
||||
#include "../stdlib.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user