nes 发声程序

nes 发声程序

通过cc65编译成nes文件,用nes模拟器运行。
音色不是很准。

编译方式:
cc65 -t nes test.c  
ca65 -t nes test.s
ld65 -t nes test.o nes.lib -o test.nes
pause

#include <conio.h> 
#define kg *(char*)0x4015//开关
#define ys1 *(char*)0x4000
#define ys2 *(char*)0x4001
#define ys3 *(char*)0x4002
#define ys4 *(char*)0x4003
typedef unsigned char u8;

#define address(add) (*(u8 *)(add))
void wav1(int j);
void wav2();
int j;
int jj[80]={1,1,5,5,6,6,5,0,4,4,3,3,2,2,1,0,
            5,5,4,4,3,3,2,0,5,5,4,4,3,3,2,0};

void delay(int i) //延时函数,传入延时参数i
{
   while(i--){
      waitvblank();   //等待垂直中断
   }
}



int main (void)
{

   address(0x4015) = 0x0f;//打开声音开关
   //发声
   address(0x4000) = 0x8f;
   address(0x4001) = 0x00;
   address(0x2000) = 0x80;
   //address(0x4003) = 0x80;
    clrscr();
cprintf("hello kal.");
while(1) 
       {
	    wav1(jj[j]);
	    j++;
		if(j>=32)j=1;
	    //wav1();
        //delay(10); 
		//wav2();
		delay(40);
		//wav2();
		//delay(80);
		}
}

void wav1(int j)
{  address(0x4000) = 0x8f;
   address(0x4001) = 0x00;
   address(0x4002) = j*(0x1c*8+2);
   address(0x4003) = 0x80*2;

}
void wav2()
{   address(0x4000) = 0x8f;//4000
    address(0x4001) = 0x00;//4001
    address(0x4002) = 0x09*8+2;//4002
   address(0x4003) = 0x80;//4003

}




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值