这是我用中断,通过对计数器的设置编写出的音乐程序,而不同直接调用函数"sound"的.虽然还不完善,但也能听出是一首歌拉,哈哈....要执行就在turboc里编译一下就行了.
#include<stdio.h>
#include<dos.h>
int n=0,fg=0;
int b;
void soundkid(int x,int y)
{
int a;
outportb(0x43,0xb6);
outportb(0x42,x);
outportb(0x42,y);
a=inportb(0x61);
a=a3;
outportb(0x61,a);
};
void nosoundkid()
{
int a;
a=inportb(0x61);
a=a&0xfd;
outportb(0x61,a);
};
void interrupt(*old)(void);
void interrupt new()
{
switch(b)
{
case 1:soundkid(200,17);break;
case 2:soundkid(216,15);break;
case 3:soundkid(30,14);break;
case 4:soundkid(109,13);break;
case 5:soundkid(226,11);break;
case 6:soundkid(150,10);break;
case 7:soundkid(110,9);break;
case 0:nosoundkid();break;
case'e':nosoundkid();break;
default:;
}
if(b!=0&b!='e')
{
n++;if(n>10){n=0;fg=1;}
}
else
{n++;if(n>0){n=0;fg=1;}}
};
main()
{
int code[42]={3,0,3,4,5,0,5,4,3,2,1,0,1,2,3,0,3,2,0,2,3,0,3,4,5,0,5,4,3,2,1,0,1,2,3,2,1,0,1,0,1,'e'};
int i;
for(i=0;i<42;i++)
{
b=code[i];
old=getvect(0x1C);
setvect(0x1c,new);
for(;;)
{
if(fg==1)
{fg=0;setvect(0x1c,old);break;}
}
}
}
点这里下载