From 9475d3d828b5abaecbadb4d50bc85f5d50c4d993 Mon Sep 17 00:00:00 2001 From: Yourtion Date: Wed, 11 May 2016 15:24:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=99=A8API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 24_day/Makefile | 10 +++++++++- 24_day/a_nask.nas | 35 +++++++++++++++++++++++++++++++++++ 24_day/console.c | 10 +++++++++- 24_day/noodle.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 24_day/noodle.c diff --git a/24_day/Makefile b/24_day/Makefile index b61f4a2..4e81e55 100644 --- a/24_day/Makefile +++ b/24_day/Makefile @@ -148,10 +148,17 @@ walk.bim : walk.obj a_nask.obj Makefile walk.hrb : walk.bim Makefile $(BIM2HRB) walk.bim walk.hrb 48k +noodle.bim : noodle.obj a_nask.obj Makefile + $(OBJ2BIM) @$(RULEFILE) out:noodle.bim stack:1k map:noodle.map \ + noodle.obj a_nask.obj + +noodle.hrb : noodle.bim Makefile + $(BIM2HRB) noodle.bim noodle.hrb 40k + haribote.img : ipl10.bin haribote.sys Makefile \ hello.hrb hello2.hrb a.hrb hello3.hrb hello4.hrb hello5.hrb \ winhelo.hrb winhelo2.hrb winhelo3.hrb star1.hrb stars.hrb stars2.hrb \ - lines.hrb walk.hrb + lines.hrb walk.hrb noodle.hrb $(EDIMG) imgin:../z_tools/fdimg0at.tek \ wbinimg src:ipl10.bin len:512 from:0 to:0 \ copy from:haribote.sys to:@: \ @@ -171,6 +178,7 @@ haribote.img : ipl10.bin haribote.sys Makefile \ copy from:stars2.hrb to:@: \ copy from:lines.hrb to:@: \ copy from:walk.hrb to:@: \ + copy from:noodle.hrb to:@: \ imgout:haribote.img # 其他指令 diff --git a/24_day/a_nask.nas b/24_day/a_nask.nas index bce3b4a..56fe642 100644 --- a/24_day/a_nask.nas +++ b/24_day/a_nask.nas @@ -17,6 +17,10 @@ GLOBAL _api_linewin GLOBAL _api_closewin GLOBAL _api_getkey + GLOBAL _api_alloctimer + GLOBAL _api_inittimer + GLOBAL _api_settimer + GLOBAL _api_freetimer [SECTION .text] @@ -186,3 +190,34 @@ _api_getkey: ; int api_getkey(int mode); MOV EAX,[ESP+4] ; mode INT 0x40 RET + +_api_alloctimer: ; int api_alloctimer(void); + MOV EDX,16 + INT 0x40 + RET + +_api_inittimer: ; void api_inittimer(int timer, int data); + PUSH EBX + MOV EDX,17 + MOV EBX,[ESP+ 8] ; timer + MOV EAX,[ESP+12] ; data + INT 0x40 + POP EBX + RET + +_api_settimer: ; void api_settimer(int timer, int time); + PUSH EBX + MOV EDX,18 + MOV EBX,[ESP+ 8] ; timer + MOV EAX,[ESP+12] ; time + INT 0x40 + POP EBX + RET + +_api_freetimer: ; void api_freetimer(int timer); + PUSH EBX + MOV EDX,19 + MOV EBX,[ESP+ 8] ; timer + INT 0x40 + POP EBX + RET diff --git a/24_day/console.c b/24_day/console.c index b9748b0..d61d65c 100644 --- a/24_day/console.c +++ b/24_day/console.c @@ -414,11 +414,19 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int if (i == 3) { /*光标OFF */ cons->cur_c = -1; } - if (256 <= i && i <= 511) { /*键盘数据(通过任务A)*/ + if (i >= 256) { /*键盘数据(通过任务A)等*/ reg[7] = i - 256; return 0; } } + } else if (edx == 16) { + reg[7] = (int) timer_alloc(); + } else if (edx == 17) { + timer_init((struct TIMER *) ebx, &task->fifo, eax + 256); + } else if (edx == 18) { + timer_settime((struct TIMER *) ebx, eax); + } else if (edx == 19) { + timer_free((struct TIMER *) ebx); } return 0; } diff --git a/24_day/noodle.c b/24_day/noodle.c new file mode 100644 index 0000000..13b9033 --- /dev/null +++ b/24_day/noodle.c @@ -0,0 +1,42 @@ +#include + +int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title); +void api_putstrwin(int win, int x, int y, int col, int len, char *str); +void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col); +void api_initmalloc(void); +char *api_malloc(int size); +int api_getkey(int mode); +int api_alloctimer(void); +void api_inittimer(int timer, int data); +void api_settimer(int timer, int time); +void api_end(void); + +void HariMain(void) +{ + char *buf, s[12]; + int win, timer, sec = 0, min = 0, hou = 0; + api_initmalloc(); + buf = api_malloc(150 * 50); + win = api_openwin(buf, 150, 50, -1, "noodle"); + timer = api_alloctimer(); + api_inittimer(timer, 128); + for (;;) { + sprintf(s, "%5d:%02d:%02d", hou, min, sec); + api_boxfilwin(win, 28, 27, 115, 41, 7);/*白色*/ + api_putstrwin(win, 28, 27, 0, 11, s); /*黑色*/ + api_settimer(timer, 100); /* 1秒 */ + if (api_getkey(1) != 128) { + break; + } + sec++; + if (sec == 60) { + sec = 0; + min++; + if (min == 60) { + min = 0; + hou++; + } + } + } + api_end(); +}