);
/* can be optimized as register file */
- reg [7:0] nr10, nr11, nr12, nr13, nr14;
+ reg [7:0] nr10 = 0, nr11 = 0, nr12 = 0, nr13 = 0, nr14 = 0;
reg [10:0] counter = 0;
reg [4:0] lencnt = 0;
reg [3:0] delta = 4'b1111;
- reg [2:0] dutycnt;
+ reg toggle = 0;
reg [3:0] snd_out = 0;
assign snd_data = en ? snd_out : 0;
counter <= counter - 1;
else begin
counter <= ~{nr14[2:0],nr13} + 1; /* possible A */
- dutycnt <= dutycnt + 1;
+ toggle <= ~toggle;
end
-
- case (nr11[7:6])
- 2'b00: snd_out <= dutycnt ? 0 : delta; /* probable A */
- 2'b01: snd_out <= (dutycnt[2:1] == 2'b0) ? delta : 0;
- 2'b10: snd_out <= dutycnt[2] ? delta : 0;
- 2'b11: snd_out <= (dutycnt[2:1] == 2'b0) ? 0 : delta;
- endcase
+
+ snd_out <= toggle ? delta : 0; /* Leave it to Dennis. */
end
always @ (posedge lenclk) begin
);
/* can be optimized as register file */
- reg [7:0] nr21, nr22, nr23, nr24;
+ reg [7:0] nr21 = 0, nr22 = 0, nr23 = 0, nr24 = 0;
reg [10:0] counter = 0;
reg [4:0] lencnt = 0;
reg [3:0] delta = 4'b1111;
reg [4:0] cntclk;
reg [13:0] lenclk;
wire [3:0] sndout1,sndout2,sndout3,sndout4;
- wire [3:0] right_snd = nr51[0] ? sndout1 : 4'b0;
- wire [3:0] left_snd = nr51[4] ? sndout1 : 4'b0;
-
+ wire [3:0] right_snd =
+ (nr51[0] ? sndout1 : 4'b0) +
+ (nr51[1] ? sndout2 : 4'b0) +
+ (nr51[2] ? sndout3 : 4'b0) +
+ (nr51[3] ? sndout4 : 4'b0);
+ wire [3:0] left_snd =
+ (nr51[4] ? sndout1 : 4'b0) +
+ (nr51[5] ? sndout2 : 4'b0) +
+ (nr51[6] ? sndout3 : 4'b0) +
+ (nr51[7] ? sndout4 : 4'b0);
assign sndout3 = 0;
assign sndout4 = 0;
case(addr)
`ADDR_NR50: nr50 <= data;
`ADDR_NR51: nr51 <= data;
- `ADDR_NR52: nr52 <= {data[7],3'b1,data[3:0]};
+ `ADDR_NR52: nr52 <= {data[7],7'b1111111};
endcase
end
cntclk <= cntclk + 1;
lenclk <= lenclk + 1;
pwmcnt <= pwmcnt + 1;
- snd_data_l <= (pwmcnt <= left_snd) ? 1 : 0;
- snd_data_r <= (pwmcnt <= right_snd) ? 1 : 0;
+ snd_data_l <= (pwmcnt <= left_snd) ? nr50[7] : 0;
+ snd_data_r <= (pwmcnt <= right_snd) ? nr50[3] : 0;
end
Sound1 s1(
.data(data),
.cntclk(cntclk[4]),
.lenclk(lenclk[13]),
- .en(nr52[7] & nr52[0]),
+ .en(nr52[7]),
.snd_data(sndout1)
);
.data(data),
.cntclk(cntclk[4]),
.lenclk(lenclk[13]),
- .en(nr52[7] & nr52[0]),
+ .en(nr52[7]),
.snd_data(sndout2)
);