]> git.zerfleddert.de Git - fpga-games/blame - galaxian/src/mc_sound_b.v
we have no sound rom
[fpga-games] / galaxian / src / mc_sound_b.v
CommitLineData
782690d0
MG
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
17module mc_sound_b(\r
18\r
19I_CLK1,\r
20I_CLK2,\r
21I_RSTn,\r
22I_SW,\r
23\r
24O_WAV_A0,\r
25O_WAV_A1,\r
26O_WAV_A2,\r
27I_WAV_D0,\r
28I_WAV_D1,\r
29I_WAV_D2,\r
30\r
31O_SDAT\r
32\r
33);\r
34\r
35input I_CLK1; // 18MHz\r
36input I_CLK2; // 6MHz\r
37input I_RSTn;\r
38input [2:0]I_SW;\r
39output [7:0]O_SDAT;\r
40output [18:0]O_WAV_A0;\r
41output [18:0]O_WAV_A1;\r
42output [18:0]O_WAV_A2;\r
43input [7:0]I_WAV_D0;\r
44input [7:0]I_WAV_D1;\r
45input [7:0]I_WAV_D2;\r
46\r
47parameter sample_time = 1670/2; // sample time 22050Hz\r
48//parameter sample_time = 1670; // sample time 11025Hz\r
49parameter fire_cnt = 14'h3FF0;\r
50parameter hit_cnt = 16'hA830;\r
51parameter effect_cnt = 16'hBFC0;\r
52\r
53reg [9:0]sample;\r
54reg sample_pls;\r
55\r
56always@(posedge I_CLK1 or negedge I_RSTn)\r
57begin\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
66end\r
67\r
68//----------- FIRE SOUND ------------------------------------------\r
69reg [13:0]fire_ad;\r
70reg [1:0]s0_trg_ff;\r
71reg s0_trg;\r
72reg s0_play;\r
73\r
74always@(posedge I_CLK1 or negedge I_RSTn)\r
75begin\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
85end\r
86\r
87always@(posedge I_CLK1 or negedge I_RSTn)\r
88begin\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
97end\r
98\r
99always@(posedge I_CLK1 or negedge I_RSTn)\r
100begin\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
114end\r
115//----------- HIT SOUND ------------------------------------------\r
116reg [15:0]hit_ad;\r
117reg [1:0]s1_trg_ff;\r
118reg s1_trg;\r
119reg s1_play;\r
120\r
121always@(posedge I_CLK1 or negedge I_RSTn)\r
122begin\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
132end\r
133\r
134always@(posedge I_CLK1 or negedge I_RSTn)\r
135begin\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
144end\r
145\r
146always@(posedge I_CLK1 or negedge I_RSTn)\r
147begin\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
161end\r
162//----------- EFFICT SOUND ---------------------------------------\r
163reg [15:0]effect_ad;\r
164\r
165always@(posedge I_CLK1 or negedge I_RSTn)\r
166begin\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
182end\r
183\r
184assign O_WAV_A0 = {3'h1,2'h0,fire_ad};\r
185assign O_WAV_A1 = {3'h1,4'h4+hit_ad[15:12],hit_ad[11:0]};\r
186assign O_WAV_A2 = {3'h2,effect_ad};\r
187\r
188wire [7:0]W_WAV_D0 = I_WAV_D0;\r
189wire [7:0]W_WAV_D1 = I_WAV_D1;\r
190wire [7:0]W_WAV_D2 = I_WAV_D2;\r
191\r
192// sound mix\r
193wire [8:0]mix0 = W_WAV_D0 + W_WAV_D1 ; \r
194reg [8:0]mix_0;\r
195always@(posedge I_CLK1)\r
196begin\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
203end\r
204\r
205wire [8:0]mix1 = mix0[7:0] + W_WAV_D2 ; \r
206reg [8:0]mix_1;\r
207always@(posedge I_CLK1)\r
208begin\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
215end\r
216\r
217assign O_SDAT = mix_1[7:0];\r
218\r
219\r
220endmodule\r
Impressum, Datenschutz