アクセスランキング
ホーム   »  マイコン  »  R8C/M12Aでファミコン音源の実装

R8C/M12Aでファミコン音源の実装



ルネサスのマイコン「R8C/M12A」でファミコン音源の実装を試みました。

「ファミコンなんて昔の8bitコンピュータだから余裕っしょ」

と考えていたら甘かった。。
ファミコンすごいわ。

最初はDDS(Direct Digital Synthesizer)を作り出したけれどフィルターがうまくいかなくてファミコンってどんなフィルター持ってるんだろうと調べたらフィルター持ってないことが分かりどーやってあんなに色んな音色を作り出しているのか気になって作ることになりました。

y[i] = y[i-1] + m * (x[i] - y[i-1])
この簡単なローパス・フィルタをうまく動かせないー

アナログシンセを作るにあたって自分が一番めんどいなーと思うのはオシレータのチューニング。なのでJUNO-106にならいオシレータはデジタルでDCOにすればいいかとR8C/M12Aでやってみたら意外に簡単にできたのでじゃあ1チップシンセにしてしまえーとやりだしたら三角関数が使えないわ小数使えないわで壁にぶち当たってます。

カットオフとレゾナンスは必須っす。

話は戻りファミコン音源。サンプル周波数32kHzでパルス派2個、三角波1個、ノイズ1個の計4個波形を生成しようと試みたけれど、クロックが20MHzの場合割り込み間隔が625クロックしかなくて生成が間に合わず(多分…)、16kHzに変更。でもそうするとPWMの幅を決める値がアバウトになりすぎてかなーり音痴になってしまう。じつは32kHzでも気にすれば気になるくらいのずれがあった。16kHzにして処理が間に合っても音痴では使いものにならない。

とゆーわけで考えた仕様がこれ。
MIDIノート69、鍵盤番号A4、周波数440Hzの場合、割り込み回数は32.363636…となって、0.363636…の部分が音痴の原因となる。
ので1周期は32回、2周期は64回、3周期は108回 + 1.090909…回となるので3周期したら割り込み1回スルーして0.090909…を誤差とするようにした。これで大分音痴は改善された。

今回は単体でスーパーマリオを演奏するようにしたけれどやっぱりMIDI機能つけたいなー。まぁこれはまた今度。
以下ソースです

/**********************************************************
「16kHzサンプリングのリニアPCM音声データ」のPWMによる出力
16kHzのPWM周波数をもちいる
カットオフ=8kHzのアナログローパスフィルタ(91Ω、0.1uF)が必要

時間割り込みによって16KHzにてPWM信号を出力
タイマRC TRCIOB を用いる
クロックは20,000kHzに設定する

コンペアマッチAでカウンタクリア
TCNT=0; TRCIOB立ち上がり
TCNT=GRB: TRCIOB立ち下がり
TCNT=GRA: TCNT=0
20000000/16000=1250 → 20MHzクロック1250サンプルで16,000Hzサンプル音
1250クロック中最初の200サンプルのHを置く これは割り込み処理のための時間稼ぎ
8ビットの音声データは0から255の値を持つので、
音声データ 0 200のH区間+1050のL区間
音声データ255 455のH区間+795のL区間
となる
割り込み周波数は16kHzになる


参考URLは以下の通り!感謝します!

R8C/M12A全般
http://j-mcr.net/tech/r8cm12a/main00.html

R8C/M12Aのメモリサイズを増やす
http://www.geocities.jp/toida_sadahiro/R8C_M1x/R8C_M1x.html

PWMを使用した音声信号の出力
http://tokyo-ct.net/usr/kosaka/for_students/H8/pwmsound/pwmsound.html

ノイズ生成
http://nekosan0.bake-neko.net/connection2_noise_gen.html

**********************************************************/
/*
R8C/M12Aマイコンのピンを、下記のように結線します。
18(P1_2) CRフィルタ→スピーカ
20(P1_0) LED
*/

/*======================================*/
/* インクルード */
/*======================================*/
#include "sfr_r8m12a.h" /* R8C/M12A SFRの定義ファイル */


/*======================================*/
/* シンボル定義 */
/*======================================*/
#define Padd 100
#define PWMPERIOD 1250


/*======================================*/
/* プロトタイプ宣言 */
/*======================================*/
void init( void );
void timer( unsigned short int timer_set );
int random_num();


/*======================================*/
/* 変数宣言 */
/*======================================*/
unsigned short int asa,val,val2,cnt2,cnt3,cnt4,cnt5,cnt6,cnt7,cnt8,cnt9;
unsigned short int m1_2,m1_3,m2_2,m2_3,m3_2,m3_3;
unsigned char m1_1,m1_4,m2_1,m2_4,m3_1,m3_4,m1,m2,m3;
char noise_vol,noise_3,noise_pitch;

const unsigned short int freq[88][3]={
{1,291,581},
{6,275,549},
{3,259,518},
{4,245,489},
{1,231,461},
{1,218,435},
{2,206,411},
{3,194,388},
{2,183,366},
{1,173,345},
{2,163,326},
{5,154,308},
{1,145,290},
{2,137,274},
{6,130,259},
{2,122,244},
{1,115,230},
{1,109,217},
{1,103,205},
{6,97,194},
{4,92,183},
{1,86,172},
{4,82,163},
{10,77,154},
{2,73,145},
{3,69,137},
{2,65,129},
{3,61,122},
{2,58,115},
{1,54,108},
{1,51,102},
{13,49,97},
{2,46,91},
{2,43,86},
{2,41,81},
{19,39,77},
{1,36,72},
{2,34,68},
{1,32,64},
{6,31,61},
{1,29,57},
{2,27,54},
{2,26,51},
{2,24,48},
{1,23,45},
{4,22,43},
{1,20,40},
{2,19,38},
{3,18,36},
{3,17,34},
{3,16,32},
{2,15,30},
{1,14,28},
{4,14,27},
{1,13,25},
{4,12,24},
{1,11,22},
{2,11,21},
{2,10,20},
{4,10,19},
{5,9,18},
{6,9,17},
{5,8,16},
{3,8,15},
{2,7,14},
{2,7,13},
{1,6,12},
{7,6,12},
{2,6,11},
{1,5,10},
{5,5,10},
{2,5,9},
{11,5,9},
{2,4,8},
{10,4,8},
{2,4,7},
{5,4,7},
{1,3,6},
{2,3,6},
{15,3,6},
{1,3,5},
{2,3,5},
{10,3,5},
{1,2,4},
{2,2,4},
{3,2,4},
{20,2,4},
{1,2,3}
};


/************************************************************************/
/* メインプログラム */
/************************************************************************/
void main( void )
{
asm("FCLR I"); /* 全体の割り込み禁止 */

init(); /* 初期化 */

asm("FSET I"); /* 全体の割り込み許可 */

while(1) {
p1_0=~p1_0;
noise_vol = 32;
while (asa < 200){noise_pitch+=1;asa++;timer(4);}
asa=0;
noise_vol = 0;
timer(100);


/* コイン */
p1_0=~p1_0;
m1 = 62; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]-1; m1_4 = 32; timer(40);
m1 = 69; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]-1; m1_4 = 32; timer(100);
m1_4 = 16; timer(100);
m1_4 = 8; timer(100);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0; timer(60);



/**********/
/* 1拍目 */
/**********/
p1_0=~p1_0;
m1 = 55; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 45; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 29; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 1; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 55; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 45; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 29; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);


noise_pitch = 3; noise_vol=32; noise_3=32; timer(10);noise_vol=0;
timer(90);

m1 = 55; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 45; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 29; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 1; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);


/**********/
/* 2拍目 */
/**********/
p1_0=~p1_0;
timer(100);

m1 = 51; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 45; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 29; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 3; noise_vol=32; noise_3=32; timer(10);noise_vol=0;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 55; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 45; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 29; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 1; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

timer(100);


/**********/
/* 3拍目 */
/**********/
p1_0=~p1_0;
m1 = 58; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 50; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 46; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 1; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

timer(200);

noise_pitch = 1; noise_vol=32; timer(50);noise_vol=0;
timer(30);


/**********/
/* 4拍目 */
/**********/
p1_0=~p1_0;
m1 = 46; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 34; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
//m3 = 34; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

noise_pitch = 1; noise_vol=32; timer(50);noise_vol=0;
timer(50);

noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(90);

noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(90);


/**********/
/* 5拍目 */
/**********/
p1_0=~p1_0;
m1 = 51; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 43; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 34; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 5; noise_vol=32; timer(10);noise_vol=0;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

timer(100);

noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(90);

m1 = 46; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 39; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 31; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(20);

noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(40);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);


/**********/
/* 6拍目 */
/**********/
p1_0=~p1_0;
noise_pitch = 1; noise_vol=32; timer(50);noise_vol=0;
timer(50);

timer(100);

m1 = 43; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 34; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 27; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

timer(25);
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(65);


/**********/
/* 7拍目 */
/**********/
p1_0=~p1_0;
noise_pitch = 5; noise_vol=32; timer(30);noise_vol=0;
timer(70);

m1 = 48; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 39; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 32; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(90);

m1 = 50; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 41; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 34; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(20);

noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(40);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);



/**********/
/* 8拍目 */
/**********/
p1_0=~p1_0;
noise_pitch = 1; noise_vol=32; timer(50);noise_vol=0;
timer(50);

m1 = 49; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 40; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 33; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 48; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 39; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 32; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

timer(25);
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(65);



/**********/
/* 9拍目 */
/**********/
p1_0=~p1_0;
m1 = 46; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 39; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 31; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 5; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(53);

m1 = 55; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 46; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 39; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(67);

noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(3);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(53);

m1 = 58; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 50; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 43; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(58);

noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(12);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(53);



/**********/
/* 10拍目 */
/**********/
p1_0=~p1_0;
m1 = 60; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 51; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 44; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 1; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

timer(100);

m1 = 56; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 48; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 41; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 58; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 50; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 42; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(25);
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(45);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);



/**********/
/* 11拍目 */
/**********/
p1_0=~p1_0;
noise_pitch = 5; noise_vol=32; timer(30);noise_vol=0;
timer(70);

m1 = 55; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 48; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 39; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(90);

m1 = 51; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 43; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 36; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(25);
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(45);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);



/**********/
/* 12拍目 */
/**********/
p1_0=~p1_0;
m1 = 53; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 44; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 38; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 1; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 50; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 41; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 34; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

timer(125);
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(65);



/************************************/
/* 13~20拍目は繰り返しなのでカット */
/************************************/



/**********/
/* 21拍目 */
/**********/
p1_0=~p1_0;
m3 = 27; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 5; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

timer(100);

m1 = 58; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 55; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 57; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 54; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 34; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(25);
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(45);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);



/**********/
/* 22拍目 */
/**********/
p1_0=~p1_0;
m1 = 56; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 53; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
noise_pitch = 1; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 54; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 50; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m3 = 39; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 55; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 51; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
timer(25);
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(45);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);



/**********/
/* 23拍目 */
/**********/
p1_0=~p1_0;
m3 = 32; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 5; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 47; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 43; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 48; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 44; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 51; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 46; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 39; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(25);
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(45);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);



/**********/
/* 24拍目 */
/**********/
p1_0=~p1_0;
m3 = 39; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 1; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 48; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 39; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 51; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 43; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 32; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 53; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 44; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
timer(25);
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(45);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

/**********/
/* 25拍目 */
/**********/
p1_0=~p1_0;
m3 = 27; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 5; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

timer(100);

m1 = 58; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 55; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 57; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 54; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 31; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(25);
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(45);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);



/**********/
/* 26拍目 */
/**********/
p1_0=~p1_0;
m1 = 56; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 53; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
noise_pitch = 1; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 54; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 50; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m3 = 34; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 55; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 51; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 39; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(25);
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(45);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);



/**********/
/* 27拍目 */
/**********/
p1_0=~p1_0;
noise_pitch = 5; noise_vol=32; timer(30);noise_vol=0;
timer(70);

m1 = 63; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 58; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 56; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(90);

m1 = 63; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 58; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 56; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(25);
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(45);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);



/**********/
/* 28拍目 */
/**********/
p1_0=~p1_0;
m1 = 63; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 58; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 56; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 1; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

timer(100);

m3 = 34; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

timer(25);
noise_pitch = 3; noise_vol=32; timer(10);noise_vol=0;
timer(65);



/**********/
/* 29拍目 */
/**********/
p1_0=~p1_0;
m3 = 27; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
noise_pitch = 5; noise_vol=32; timer(50);noise_vol=0;
timer(30);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

//timer(300);


/* 敵に当たった! */
/**********/
/* 1拍目 */
/**********/
p1_0=~p1_0;
m1 = 51; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]-1; m1_4 = 32; timer(20);
m1 = 52; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]-1; m1_4 = 32; timer(20);
m1 = 53; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]-1; m1_4 = 32; timer(60);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0; timer(300);


/**********/
/* 2拍目 */
/**********/
p1_0=~p1_0;
m1 = 50; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 46; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 34; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 56; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 53; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 34; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

timer(100);

m1 = 56; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 53; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 34; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);



/**********/
/* 3拍目 */
/**********/
p1_0=~p1_0;
m1 = 56; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 53; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 34; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(63);

m1 = 55; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 51; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 36; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(63);

m1 = 53; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 50; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 38; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(70);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(63);



/**********/
/* 4拍目 */
/**********/
p1_0=~p1_0;
m1 = 51; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m2 = 46; m2_1 = freq[m2][0]; m2_2 = freq[m2][1]/2; m2_3 = freq[m2][2]; m2_4 = 32;
m3 = 39; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 43; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m3 = 34; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

m1 = 43; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);




/**********/
/* 5拍目 */
/**********/
p1_0=~p1_0;
m1 = 39; m1_1 = freq[m1][0]; m1_2 = freq[m1][1]; m1_3 = freq[m1][2]; m1_4 = 32;
m3 = 27; m3_1 = freq[m3][0]; m3_2 = freq[m3][1]; m3_3 = freq[m3][2]-1; m3_4 = 32;
timer(80);

m1_4 = 0; m2_4 = 0; m3_4 = 0; noise_vol = 0;
timer(20);

timer(300);

}
}

/************************************************************************/
/* R8C/M12A スペシャルファンクションレジスタ(SFR)の初期化 */
/************************************************************************/
void init( void )
{
unsigned char i;

/* クロックを高速オンチップオシレータ(20MHz)に変更 */
prc0 = 1; /* プロテクト解除 */
hocoe = 1; /* 高速オンチップオシレータ発信開始 */
for(i=0; i<50; i++ ); /* 安定するまで少し待つ(約10ms) */
hscksel = 1; /* 高速オンチップオシレータのクロックに切換え*/
scksel = 1; /* システム基準クロック 低速→高速切換え*/
phissel0 = 0; /* 000: 1分周 */
phissel1 = 0; /* 010: 4分周 */
phissel2 = 0; /* 101:32分周 */
prc0 = 0; /* プロテクト保護 */

/* ポートの入出力設定 */
pd1 = 0x7f; /* ポート1入出力設定 0111:1111 */
pd3 = 0xff; /* ポート3入出力設定 */
pd4 = 0xdf; /* ポート4入出力設定 1101:1111 */
pda = 0xff; /* ポートA入出力設定 */

/* 端子のプルアップ設定 */
pu1_7 = 1; /* ポート1のプルアップ設定 */
pu4_5 = 1; /* ポート4のプルアップ設定 */

// P4_5端子を使う場合
p45sel1 = 0; /* P4_5をINT0端子にする */
p45sel0 = 1;
int0en = 1; /* INT0入力許可ビット:許可 */
int0f1 = 1; /* INT0入力フィルタ選択ビット */
int0f0 = 1; /* 11=f32でサンプリング */
int0sb = 0; /* INT0入力エッジ選択ビット */
int0sa = 0; /* 00=立ち下がりエッジで割込発生 */
ilvle5 = 1; /* 割り込み優先レベル設定ビット */
ilvle4 = 0; /* INT0はe1とe0に設定 10=レベル2*/

// P1_7端子を使う場合
p17sel1 = 0; /* P1_7をINT1端子にする */
p17sel0 = 1;
int1en = 1; /* INT1入力許可ビット:許可 */
int1f1 = 1; /* INT1入力フィルタ選択ビット */
int1f0 = 1; /* 11=f32でサンプリング */
int1sb = 0; /* INT1入力エッジ選択ビット */
int1sa = 0; /* 00=立ち下がりエッジで割込発生 */
ilvlc5 = 1; /* 割り込み優先レベル設定ビット */
ilvlc4 = 0; /* INT1はc1とc0に設定 10=レベル2*/

/* タイマRCによるPWM出力 */
msttrc = 0; /* タイマRCを有効にする */
p12sel1 = 0; /* TRCIOB端子の選択 */
p12sel0 = 1; /* P1_2をTRCIOB端子にする */
pwm2_trcmr = 1; /* PWMモード */
pwmb_trcmr = 1; /* TRCIOB出力 PWM出力する */
cclr_trccr1 = 1; /* コンペア一致AでTRCCNTカウンタクリア */
cks0_trccr1 = 0; /* 000:f1(1分周)カウントソース */
cks1_trccr1 = 0;
cks2_trccr1 = 0;
asm("nop");
asm("nop");
polb_trccr2 = 0; /* TRDIOB outputレベル:Lアクティブ */
trccnt = 0x0000; /* TRCCNT カウントクリア */
trcgra = PWMPERIOD-1; /* PWM周期の設定 */
trcgrb = Padd; /* TRCIOB端子のON幅の設定 */
eb_trcoer = 0; /* TRCIOBの出力 出力許可 */
imiea_trcier = 1;
imieb_trcier = 1;
ilvl3 = 0x10; /* 0001:0000 割り込み許可(レベル1)*/
cts_trcmr = 1; /* TRCCNT カウント開始 */
}

/************************************************************************/
/* タイマ本体 */
/* 引数  タイマ値 1=1ms */
/************************************************************************/
void timer( unsigned short int timer_set )
{
int i;

do {
//for( i=0; i<871; i++ );
for( i=0; i<700; i++ );
} while( timer_set-- );
cnt4 = cnt5 = cnt6 = cnt7 =cnt8 = cnt9 = 0;
}

/************************************************************************/
/* Timer RC 割り込み処理 */
/************************************************************************/
#pragma interrupt _timer_rc(vect=7)
void _timer_rc(void)
{
/*TCNT=GRAとなったときの割り込み要求を許可*/
if ( imfa_trcsr == 1 ) { /* IMFA flag on? */
imfa_trcsr = 0; /* IMFA flag clear */


/*ここで TRCIOB にPWM値+Paddを与える*/


/* Noise */
cnt2++;
if (cnt2 > noise_pitch) {
cnt2 = 0;
val2 =val = (random_num()&0x01)*noise_vol;
}else{val = val2;}

/* Music1 短形波 */
cnt5++;
if(cnt4 == m1_1){cnt5--;cnt4=0;}
else{
if(cnt5 <= m1_2){val += m1_4;}
else if(cnt5 == m1_3){cnt5 = 0;cnt4++;}
}

/* Music2 短形波 */
cnt9++;
if(cnt8 == m2_1){cnt9--;cnt8=0;}
else{
if(cnt9 <= m2_2){val += m2_4;}
else if(cnt9 == m2_3){cnt9 = 0;cnt8++;}
}

/* Music3 三角波 */
cnt7++;
if(cnt6 == m3_1){cnt7--;cnt6=0;}
else{
if(cnt7 <= m3_2){val += m3_4 * cnt7 / m3_2;}
else if(cnt7 <= m3_3){val -= m3_4 * cnt7 / m3_2;}
else if(cnt7 == m3_3 +1){cnt7 = 0;cnt6++;}
}

trcgrb = val + Padd;
}

if ( imfb_trcsr == 1 ) { /* IMFB flag on? */
imfb_trcsr = 0; /* IMFB flag clear */
}
}

/************************************************************************/
/* making random num */
/************************************************************************/
int random_num() {

static int seed = 12345; //random seed
unsigned int random_value;

// random_value = (seed>>1) + (bitRead(seed, 16) xor bitRead(seed, 13) xor 1)*0x8000;
random_value = (seed>>1) + (0x01&(seed>>13) ^ 0x01&(seed>>4) ^ 1)*0x8000;

seed = random_value;
return seed;
}
/************************************************************************/
/* end of file */
/************************************************************************/










関連記事
コメント
こんにちは
凄い物作られますね(⦿_⦿)
さっぱり解りません&%$இ#@
信頼度の低い請売り情報ですが
ファミコンかスーパーファミコンを当時
ロシアが持ち帰って戦闘機に積もうとしたそうです
ゲーム機のCPU?同時期のPCと比べ物にならない性能だと聞いてました。
Re: こんにちは
mechagakuさんこんにちは!

いやいや、mechagakuさんこそFXという難しいことやってるじゃないですか!
お金の運用には興味あって証券会社に口座を持ってはいるんですが、、やってないです。

ファミコンのCPUはApple社製のもので、他社がこのCPUを特定するのに1年かかったとか。
そんな周りにあまりない部品を使い、開発環境を整え、プラットフォームを作成するのは凄く先見の目が必要だったと思います。
トラックバック
トラックバック URL
コメントの投稿
管理者にだけ表示を許可する




ランキング
SNS RSS
follow us in feedly


FC2カウンター