1 `define ADDR_NR50 16'hFF24
2 `define ADDR_NR51 16'hFF25
3 `define ADDR_NR52 16'hFF26
11 output reg snd_data_l,
15 reg [7:0] nr50 = 8'h00, nr51 = 8'h00, nr52 = 8'hF0;
16 reg [3:0] pwmcnt = 4'b0000;
17 reg [4:0] cntclk = 5'b00000;
19 wire [3:0] sndout1,sndout2,sndout3,sndout4;
20 wire [3:0] right_snd =
21 (nr51[0] ? sndout1 : 4'b0) +
22 (nr51[1] ? sndout2 : 4'b0) +
23 (nr51[2] ? sndout3 : 4'b0) +
24 (nr51[3] ? sndout4 : 4'b0);
26 (nr51[4] ? sndout1 : 4'b0) +
27 (nr51[5] ? sndout2 : 4'b0) +
28 (nr51[6] ? sndout3 : 4'b0) +
29 (nr51[7] ? sndout4 : 4'b0);
36 assign data = rdlatch ?
37 addrlatch == `ADDR_NR50 ? nr50 :
38 addrlatch == `ADDR_NR51 ? nr51 :
39 addrlatch == `ADDR_NR52 ? nr52 : 8'bzzzzzzzz
42 always @ (posedge core_clk) begin
47 `ADDR_NR50: nr50 <= data;
48 `ADDR_NR51: nr51 <= data;
49 `ADDR_NR52: nr52 <= {data[7],7'b1111111};
55 snd_data_l <= (pwmcnt <= left_snd) ? 1 : 0;
56 snd_data_r <= (pwmcnt <= right_snd) ? 1 : 0;