1 //===============================================================================
2 // FPGA MOONCRESTA WAVE SOUND
6 // Copyright(c) 2004 Katsumi Degawa , All rights reserved
10 // This program is freeware for non-commercial use.
11 // An author does no guarantee about this program.
12 // You can use this under your own risk.
14 //================================================================================
35 input I_CLK1; // 18MHz
40 output [18:0]O_WAV_A0;
41 output [18:0]O_WAV_A1;
42 output [18:0]O_WAV_A2;
47 parameter sample_time = 1670/2; // sample time 22050Hz
48 //parameter sample_time = 1670; // sample time 11025Hz
49 parameter fire_cnt = 14'h3FF0;
50 parameter hit_cnt = 16'hA830;
51 parameter effect_cnt = 16'hBFC0;
56 always@(posedge I_CLK1 or negedge I_RSTn)
58 if(I_RSTn == 1'b0)begin
63 sample <= (sample == sample_time-1)? 0 : sample+1;
64 sample_pls <= (sample == sample_time-1)? 1 : 0 ;
68 //----------- FIRE SOUND ------------------------------------------
74 always@(posedge I_CLK1 or negedge I_RSTn)
76 if(I_RSTn == 1'b0)begin
81 s0_trg_ff[0] <= I_SW[0];
82 s0_trg_ff[1] <= s0_trg_ff[0];
83 s0_trg <= ~s0_trg_ff[1]&s0_trg_ff[0]&~s0_play;
87 always@(posedge I_CLK1 or negedge I_RSTn)
92 if(fire_ad <= fire_cnt-1)
99 always@(posedge I_CLK1 or negedge I_RSTn)
104 if(s0_trg) fire_ad <= 0;
107 if(fire_ad <= fire_cnt)
108 fire_ad <= fire_ad +1 ;
115 //----------- HIT SOUND ------------------------------------------
121 always@(posedge I_CLK1 or negedge I_RSTn)
123 if(I_RSTn == 1'b0)begin
128 s1_trg_ff[0] <= I_SW[1];
129 s1_trg_ff[1] <= s1_trg_ff[0];
130 s1_trg <= ~s1_trg_ff[1]&s1_trg_ff[0]&~s1_play;
134 always@(posedge I_CLK1 or negedge I_RSTn)
139 if(hit_ad <= hit_cnt-1)
146 always@(posedge I_CLK1 or negedge I_RSTn)
151 if(s1_trg) hit_ad <= 0;
154 if(hit_ad <= hit_cnt)
155 hit_ad <= hit_ad +1 ;
162 //----------- EFFICT SOUND ---------------------------------------
165 always@(posedge I_CLK1 or negedge I_RSTn)
168 effect_ad <= effect_cnt;
172 if(effect_ad >= effect_cnt)
175 effect_ad <= effect_ad + 1;
179 effect_ad <= effect_cnt;
184 assign O_WAV_A0 = {3'h1,2'h0,fire_ad};
185 assign O_WAV_A1 = {3'h1,4'h4+hit_ad[15:12],hit_ad[11:0]};
186 assign O_WAV_A2 = {3'h2,effect_ad};
188 wire [7:0]W_WAV_D0 = I_WAV_D0;
189 wire [7:0]W_WAV_D1 = I_WAV_D1;
190 wire [7:0]W_WAV_D2 = I_WAV_D2;
193 wire [8:0]mix0 = W_WAV_D0 + W_WAV_D1 ;
195 always@(posedge I_CLK1)
197 if(mix0 >= 9'h17F) // POS Limiter
199 else if(mix0 <= 9'h080)// NEG Limiter
202 mix_0 <= mix0 - 9'h080;
205 wire [8:0]mix1 = mix0[7:0] + W_WAV_D2 ;
207 always@(posedge I_CLK1)
209 if(mix1 >= 9'h17F) // POS Limiter
211 else if(mix1 <= 9'h080)// NEG Limiter
214 mix_1 <= mix1 - 9'h080;
217 assign O_SDAT = mix_1[7:0];