mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-02 17:49:01 +08:00
定时器API
This commit is contained in:
@@ -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
|
||||
|
||||
# 其他指令
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
42
24_day/noodle.c
Normal file
42
24_day/noodle.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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();
|
||||
}
|
||||
Reference in New Issue
Block a user