Skip to content

Commit

Permalink
蜂鸣器发声
Browse files Browse the repository at this point in the history
  • Loading branch information
yourtion committed May 13, 2016
1 parent 907b8c6 commit d84bab7
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
12 changes: 12 additions & 0 deletions 24_day/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 17 additions & 1 deletion 25_day/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:@: \
Expand All @@ -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

# 其他指令
Expand Down
7 changes: 7 additions & 0 deletions 25_day/a_nask.nas
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
GLOBAL _api_inittimer
GLOBAL _api_settimer
GLOBAL _api_freetimer
GLOBAL _api_beep

[SECTION .text]

Expand Down Expand Up @@ -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 changes: 24 additions & 0 deletions 25_day/beepdown.c
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions 25_day/beepup.c
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit d84bab7

Please sign in to comment.