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
通过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
}