forked from backup/30dayMakeOS
蜂鸣器发声
This commit is contained in:
@@ -429,6 +429,18 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int
|
||||
timer_settime((struct TIMER *) ebx, eax);
|
||||
} else if (edx == 19) {
|
||||
timer_free((struct TIMER *) ebx);
|
||||
} else if (edx == 20) {
|
||||
if (eax == 0) {
|
||||
i = io_in8(0x61);
|
||||
io_out8(0x61, i & 0x0d);
|
||||
} else {
|
||||
i = 1193180000 / eax;
|
||||
io_out8(0x43, 0xb6);
|
||||
io_out8(0x42, i & 0xff);
|
||||
io_out8(0x42, i >> 8);
|
||||
i = io_in8(0x61);
|
||||
io_out8(0x61, (i | 0x03) & 0x0f);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -155,10 +155,24 @@ noodle.bim : noodle.obj a_nask.obj Makefile
|
||||
noodle.hrb : noodle.bim Makefile
|
||||
$(BIM2HRB) noodle.bim noodle.hrb 40k
|
||||
|
||||
beepdown.bim : beepdown.obj a_nask.obj Makefile
|
||||
$(OBJ2BIM) @$(RULEFILE) out:beepdown.bim stack:1k map:beepdown.map \
|
||||
beepdown.obj a_nask.obj
|
||||
|
||||
beepdown.hrb : beepdown.bim Makefile
|
||||
$(BIM2HRB) beepdown.bim beepdown.hrb 40k
|
||||
|
||||
beepup.bim : beepup.obj a_nask.obj Makefile
|
||||
$(OBJ2BIM) @$(RULEFILE) out:beepup.bim stack:1k map:beepup.map \
|
||||
beepup.obj a_nask.obj
|
||||
|
||||
beepup.hrb : beepup.bim Makefile
|
||||
$(BIM2HRB) beepup.bim beepup.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 noodle.hrb
|
||||
lines.hrb walk.hrb noodle.hrb beepdown.hrb beepup.hrb
|
||||
$(EDIMG) imgin:../z_tools/fdimg0at.tek \
|
||||
wbinimg src:ipl10.bin len:512 from:0 to:0 \
|
||||
copy from:haribote.sys to:@: \
|
||||
@@ -179,6 +193,8 @@ haribote.img : ipl10.bin haribote.sys Makefile \
|
||||
copy from:lines.hrb to:@: \
|
||||
copy from:walk.hrb to:@: \
|
||||
copy from:noodle.hrb to:@: \
|
||||
copy from:beepdown.hrb to:@: \
|
||||
copy from:beepup.hrb to:@: \
|
||||
imgout:haribote.img
|
||||
|
||||
# 其他指令
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
GLOBAL _api_inittimer
|
||||
GLOBAL _api_settimer
|
||||
GLOBAL _api_freetimer
|
||||
GLOBAL _api_beep
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
@@ -221,3 +222,9 @@ _api_freetimer: ; void api_freetimer(int timer);
|
||||
INT 0x40
|
||||
POP EBX
|
||||
RET
|
||||
|
||||
_api_beep: ; void api_beep(int tone);
|
||||
MOV EDX,20
|
||||
MOV EAX,[ESP+4] ; tone
|
||||
INT 0x40
|
||||
RET
|
||||
|
||||
24
25_day/beepdown.c
Normal file
24
25_day/beepdown.c
Normal file
@@ -0,0 +1,24 @@
|
||||
void api_end(void);
|
||||
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_beep(int tone);
|
||||
|
||||
void HariMain(void)
|
||||
{
|
||||
int i, timer;
|
||||
timer = api_alloctimer();
|
||||
api_inittimer(timer, 128);
|
||||
for (i = 20000000; i >= 20000; i -= i / 100) {
|
||||
/* 20KHz~20Hz,即人类可以听到的声音范围*/
|
||||
/* i以1%的速度递减*/
|
||||
api_beep(i);
|
||||
api_settimer(timer, 1); /* 0.01秒*/
|
||||
if (api_getkey(1) != 128) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
api_beep(0);
|
||||
api_end();
|
||||
}
|
||||
22
25_day/beepup.c
Normal file
22
25_day/beepup.c
Normal file
@@ -0,0 +1,22 @@
|
||||
void api_end(void);
|
||||
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_beep(int tone);
|
||||
|
||||
void HariMain(void)
|
||||
{
|
||||
int i, timer;
|
||||
timer = api_alloctimer();
|
||||
api_inittimer(timer, 128);
|
||||
for (i = 20000; i <= 20000000; i += i / 100) {
|
||||
api_beep(i);
|
||||
api_settimer(timer, 1); /* 0.01秒*/
|
||||
if (api_getkey(1) != 128) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
api_beep(0);
|
||||
api_end();
|
||||
}
|
||||
Reference in New Issue
Block a user