From d84bab78e1601f83ae7ba393f7b9b37c6497e6f7 Mon Sep 17 00:00:00 2001 From: Yourtion Date: Fri, 13 May 2016 10:32:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=9C=82=E9=B8=A3=E5=99=A8=E5=8F=91=E5=A3=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 24_day/console.c | 12 ++++++++++++ 25_day/Makefile | 18 +++++++++++++++++- 25_day/a_nask.nas | 7 +++++++ 25_day/beepdown.c | 24 ++++++++++++++++++++++++ 25_day/beepup.c | 22 ++++++++++++++++++++++ 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 25_day/beepdown.c create mode 100644 25_day/beepup.c diff --git a/24_day/console.c b/24_day/console.c index ab3f80a..ceb2fc4 100644 --- a/24_day/console.c +++ b/24_day/console.c @@ -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; } diff --git a/25_day/Makefile b/25_day/Makefile index 4e81e55..c77e73f 100644 --- a/25_day/Makefile +++ b/25_day/Makefile @@ -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 # 其他指令 diff --git a/25_day/a_nask.nas b/25_day/a_nask.nas index 56fe642..9e63654 100644 --- a/25_day/a_nask.nas +++ b/25_day/a_nask.nas @@ -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 diff --git a/25_day/beepdown.c b/25_day/beepdown.c new file mode 100644 index 0000000..db1aa59 --- /dev/null +++ b/25_day/beepdown.c @@ -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(); +} diff --git a/25_day/beepup.c b/25_day/beepup.c new file mode 100644 index 0000000..d14ccb6 --- /dev/null +++ b/25_day/beepup.c @@ -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(); +}