⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soundgd.c

📁 用主板上的小喇叭演奏的程序 C实现 挺有意思的
💻 C
字号:
#include <stdio.h>
#include <dos.h>
#define L1 1000
#define L2 L1/2
#define L3 L1/4

void interrupt(*old_int9)();
int HZ[4][7]={	{131,147,165,175,196,220,247},
		{262,294,330,349,392,440,494},
		{523,587,659,698,784,880,988},
		{1047,1174,1319,1568,1760,1976}};
int *s;
int buf[100]={11,L1,12,L3,13,L2,14,L2,15,L2,16,L2,17,L2,21,L2,22,L2,23,L2,24,L2,25,L2,26,L2,27,L2,31,L2,0,0,0};
void Sound(int freq)
{
	asm{
	mov   al,   0B6h
	out   43h,  al
	mov   dx,   12h
	mov   ax,   34DEh
	div   freq
	out   42h,  al
	mov   al,   ah
	out   42h,  al
	in    al,   61h
	or    al,   3
	out   61h,  al
	}
}

void Nosound(void)
{
	asm{
	in    al,   61h
	and   al,   252
	out   61h,  al
	}
}

void Delay(int clicks)
{
unsigned int far *clock=(unsigned int far *)0x0000046CL;
unsigned int now;
now=*clock;
while(abs(*clock-now)<clicks){}
}

void interrupt new_int9()
{
	static int count,tt=0;
	count++;
	if(*s!=0)
	{
		if(count>=tt)
		{
			Sound(HZ[*s/10][*s%10-1]);
			s++;
			tt=*s*18.2/1000;
			s++;
			count=0;
		}
	}
	else
		Nosound();
	(*old_int9)();
}

void play(int *ms)
{
	s=ms;
	old_int9=getvect(0x1c);
	setvect(0x1c,new_int9);
}

void main(void)
{
	int i;
	play(buf);
	for(i=0;i<20000;i++)
		printf("%d,",i);

	while(*s!=0&&!bioskey(0));
	Nosound();
	setvect(0x1c,*old_int9);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -