]>
Commit | Line | Data |
---|---|---|
1 | //===============================================================================\r | |
2 | // FPGA MOONCRESTA WAVE SOUND\r | |
3 | //\r | |
4 | // Version : 1.00\r | |
5 | //\r | |
6 | // Copyright(c) 2004 Katsumi Degawa , All rights reserved\r | |
7 | //\r | |
8 | // Important !\r | |
9 | //\r | |
10 | // This program is freeware for non-commercial use. \r | |
11 | // An author does no guarantee about this program.\r | |
12 | // You can use this under your own risk.\r | |
13 | //\r | |
14 | //================================================================================\r | |
15 | \r | |
16 | \r | |
17 | module mc_sound_b(\r | |
18 | \r | |
19 | I_CLK1,\r | |
20 | I_CLK2,\r | |
21 | I_RSTn,\r | |
22 | I_SW,\r | |
23 | \r | |
24 | O_WAV_A0,\r | |
25 | O_WAV_A1,\r | |
26 | O_WAV_A2,\r | |
27 | I_WAV_D0,\r | |
28 | I_WAV_D1,\r | |
29 | I_WAV_D2,\r | |
30 | \r | |
31 | O_SDAT\r | |
32 | \r | |
33 | );\r | |
34 | \r | |
35 | input I_CLK1; // 18MHz\r | |
36 | input I_CLK2; // 6MHz\r | |
37 | input I_RSTn;\r | |
38 | input [2:0]I_SW;\r | |
39 | output [7:0]O_SDAT;\r | |
40 | output [18:0]O_WAV_A0;\r | |
41 | output [18:0]O_WAV_A1;\r | |
42 | output [18:0]O_WAV_A2;\r | |
43 | input [7:0]I_WAV_D0;\r | |
44 | input [7:0]I_WAV_D1;\r | |
45 | input [7:0]I_WAV_D2;\r | |
46 | \r | |
47 | parameter sample_time = 1670/2; // sample time 22050Hz\r | |
48 | //parameter sample_time = 1670; // sample time 11025Hz\r | |
49 | parameter fire_cnt = 14'h3FF0;\r | |
50 | parameter hit_cnt = 16'hA830;\r | |
51 | parameter effect_cnt = 16'hBFC0;\r | |
52 | \r | |
53 | reg [9:0]sample;\r | |
54 | reg sample_pls;\r | |
55 | \r | |
56 | always@(posedge I_CLK1 or negedge I_RSTn)\r | |
57 | begin\r | |
58 | if(I_RSTn == 1'b0)begin\r | |
59 | sample <= 0;\r | |
60 | sample_pls <= 0;\r | |
61 | end\r | |
62 | else begin\r | |
63 | sample <= (sample == sample_time-1)? 0 : sample+1;\r | |
64 | sample_pls <= (sample == sample_time-1)? 1 : 0 ;\r | |
65 | end\r | |
66 | end\r | |
67 | \r | |
68 | //----------- FIRE SOUND ------------------------------------------\r | |
69 | reg [13:0]fire_ad;\r | |
70 | reg [1:0]s0_trg_ff;\r | |
71 | reg s0_trg;\r | |
72 | reg s0_play;\r | |
73 | \r | |
74 | always@(posedge I_CLK1 or negedge I_RSTn)\r | |
75 | begin\r | |
76 | if(I_RSTn == 1'b0)begin\r | |
77 | s0_trg_ff <= 0;\r | |
78 | s0_trg <= 0;\r | |
79 | end\r | |
80 | else begin\r | |
81 | s0_trg_ff[0] <= I_SW[0];\r | |
82 | s0_trg_ff[1] <= s0_trg_ff[0];\r | |
83 | s0_trg <= ~s0_trg_ff[1]&s0_trg_ff[0]&~s0_play;\r | |
84 | end\r | |
85 | end\r | |
86 | \r | |
87 | always@(posedge I_CLK1 or negedge I_RSTn)\r | |
88 | begin\r | |
89 | if(I_RSTn == 1'b0)\r | |
90 | s0_play <= 0;\r | |
91 | else begin\r | |
92 | if(fire_ad <= fire_cnt-1)\r | |
93 | s0_play <= 1;\r | |
94 | else\r | |
95 | s0_play <= 0;\r | |
96 | end\r | |
97 | end\r | |
98 | \r | |
99 | always@(posedge I_CLK1 or negedge I_RSTn)\r | |
100 | begin\r | |
101 | if(I_RSTn == 1'b0)\r | |
102 | fire_ad <= fire_cnt;\r | |
103 | else begin\r | |
104 | if(s0_trg) fire_ad <= 0;\r | |
105 | else begin\r | |
106 | if(sample_pls)begin \r | |
107 | if(fire_ad <= fire_cnt)\r | |
108 | fire_ad <= fire_ad +1 ;\r | |
109 | else\r | |
110 | fire_ad <= fire_ad ;\r | |
111 | end\r | |
112 | end\r | |
113 | end\r | |
114 | end\r | |
115 | //----------- HIT SOUND ------------------------------------------\r | |
116 | reg [15:0]hit_ad;\r | |
117 | reg [1:0]s1_trg_ff;\r | |
118 | reg s1_trg;\r | |
119 | reg s1_play;\r | |
120 | \r | |
121 | always@(posedge I_CLK1 or negedge I_RSTn)\r | |
122 | begin\r | |
123 | if(I_RSTn == 1'b0)begin\r | |
124 | s1_trg_ff <= 0;\r | |
125 | s1_trg <= 0;\r | |
126 | end\r | |
127 | else begin\r | |
128 | s1_trg_ff[0] <= I_SW[1];\r | |
129 | s1_trg_ff[1] <= s1_trg_ff[0];\r | |
130 | s1_trg <= ~s1_trg_ff[1]&s1_trg_ff[0]&~s1_play;\r | |
131 | end\r | |
132 | end\r | |
133 | \r | |
134 | always@(posedge I_CLK1 or negedge I_RSTn)\r | |
135 | begin\r | |
136 | if(I_RSTn == 1'b0)\r | |
137 | s1_play <= 0;\r | |
138 | else begin\r | |
139 | if(hit_ad <= hit_cnt-1)\r | |
140 | s1_play <= 1;\r | |
141 | else\r | |
142 | s1_play <= 0;\r | |
143 | end\r | |
144 | end\r | |
145 | \r | |
146 | always@(posedge I_CLK1 or negedge I_RSTn)\r | |
147 | begin\r | |
148 | if(I_RSTn == 1'b0)\r | |
149 | hit_ad <= hit_cnt;\r | |
150 | else begin\r | |
151 | if(s1_trg) hit_ad <= 0;\r | |
152 | else begin\r | |
153 | if(sample_pls)begin \r | |
154 | if(hit_ad <= hit_cnt)\r | |
155 | hit_ad <= hit_ad +1 ;\r | |
156 | else\r | |
157 | hit_ad <= hit_ad ;\r | |
158 | end\r | |
159 | end\r | |
160 | end\r | |
161 | end\r | |
162 | //----------- EFFICT SOUND ---------------------------------------\r | |
163 | reg [15:0]effect_ad;\r | |
164 | \r | |
165 | always@(posedge I_CLK1 or negedge I_RSTn)\r | |
166 | begin\r | |
167 | if(I_RSTn == 1'b0)\r | |
168 | effect_ad <= effect_cnt;\r | |
169 | else begin\r | |
170 | if(I_SW[2])begin\r | |
171 | if(sample_pls)begin\r | |
172 | if(effect_ad >= effect_cnt)\r | |
173 | effect_ad <= 0;\r | |
174 | else\r | |
175 | effect_ad <= effect_ad + 1;\r | |
176 | end\r | |
177 | end\r | |
178 | else begin\r | |
179 | effect_ad <= effect_cnt;\r | |
180 | end \r | |
181 | end\r | |
182 | end\r | |
183 | \r | |
184 | assign O_WAV_A0 = {3'h1,2'h0,fire_ad};\r | |
185 | assign O_WAV_A1 = {3'h1,4'h4+hit_ad[15:12],hit_ad[11:0]};\r | |
186 | assign O_WAV_A2 = {3'h2,effect_ad};\r | |
187 | \r | |
188 | wire [7:0]W_WAV_D0 = I_WAV_D0;\r | |
189 | wire [7:0]W_WAV_D1 = I_WAV_D1;\r | |
190 | wire [7:0]W_WAV_D2 = I_WAV_D2;\r | |
191 | \r | |
192 | // sound mix\r | |
193 | wire [8:0]mix0 = W_WAV_D0 + W_WAV_D1 ; \r | |
194 | reg [8:0]mix_0;\r | |
195 | always@(posedge I_CLK1)\r | |
196 | begin\r | |
197 | if(mix0 >= 9'h17F) // POS Limiter\r | |
198 | mix_0 <= 9'h0FF;\r | |
199 | else if(mix0 <= 9'h080)// NEG Limiter\r | |
200 | mix_0 <= 9'h000;\r | |
201 | else\r | |
202 | mix_0 <= mix0 - 9'h080; \r | |
203 | end\r | |
204 | \r | |
205 | wire [8:0]mix1 = mix0[7:0] + W_WAV_D2 ; \r | |
206 | reg [8:0]mix_1;\r | |
207 | always@(posedge I_CLK1)\r | |
208 | begin\r | |
209 | if(mix1 >= 9'h17F) // POS Limiter\r | |
210 | mix_1 <= 9'h0FF;\r | |
211 | else if(mix1 <= 9'h080)// NEG Limiter\r | |
212 | mix_1 <= 9'h000;\r | |
213 | else\r | |
214 | mix_1 <= mix1 - 9'h080; \r | |
215 | end\r | |
216 | \r | |
217 | assign O_SDAT = mix_1[7:0];\r | |
218 | \r | |
219 | \r | |
220 | endmodule\r |