1 `define ADDR_NR21 16'hFF16
2 `define ADDR_NR22 16'hFF17
3 `define ADDR_NR23 16'hFF18
4 `define ADDR_NR24 16'hFF19
18 /* can be optimized as register file */
19 reg [7:0] nr21 = 0, nr22 = 0, nr23 = 0, nr24 = 0;
20 reg [10:0] counter = 0;
22 reg [3:0] delta = 4'b1111;
24 reg [3:0] snd_out = 0;
26 assign snd_data = en ? snd_out : 0;
29 addr == `ADDR_NR21 ? nr21 :
30 addr == `ADDR_NR22 ? nr22 :
31 addr == `ADDR_NR23 ? nr23 :
32 addr == `ADDR_NR24 ? nr24 : 8'bzzzzzzzz
35 always @ (posedge core_clk) begin
38 `ADDR_NR21: nr21 <= data;
39 `ADDR_NR22: nr22 <= data;
40 `ADDR_NR23: nr23 <= data;
41 `ADDR_NR24: nr24 <= data;
52 always @ (posedge cntclk) begin
54 counter <= counter - 1;
56 counter <= ~{nr24[2:0],nr23} + 1; /* possible A */
57 dutycnt <= dutycnt + 1;
61 2'b00: snd_out <= dutycnt ? 0 : delta; /* probable A */
62 2'b01: snd_out <= (dutycnt[2:1] == 2'b0) ? delta : 0;
63 2'b10: snd_out <= dutycnt[2] ? delta : 0;
64 2'b11: snd_out <= (dutycnt[2:1] == 2'b0) ? 0 : delta;
68 always @ (posedge lenclk) begin
70 lencnt <= lencnt - 1; /* possible A */
72 lencnt <= ~nr21[4:0] + 1;