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;
31 assign data = rdlatch ?
32 addrlatch == `ADDR_NR21 ? nr21 :
33 addrlatch == `ADDR_NR22 ? nr22 :
34 addrlatch == `ADDR_NR23 ? nr23 :
35 addrlatch == `ADDR_NR24 ? nr24 : 8'bzzzzzzzz
38 always @ (posedge core_clk) begin
43 `ADDR_NR21: nr21 <= data;
44 `ADDR_NR22: nr22 <= data;
45 `ADDR_NR23: nr23 <= data;
46 `ADDR_NR24: nr24 <= data;
57 always @ (posedge cntclk) begin
59 counter <= counter - 1;
61 counter <= ~{nr24[2:0],nr23} + 1; /* possible A */
62 dutycnt <= dutycnt + 1;
66 2'b00: snd_out <= dutycnt ? 0 : delta; /* probable A */
67 2'b01: snd_out <= (dutycnt[2:1] == 2'b0) ? delta : 0;
68 2'b10: snd_out <= dutycnt[2] ? delta : 0;
69 2'b11: snd_out <= (dutycnt[2:1] == 2'b0) ? 0 : delta;
73 always @ (posedge lenclk) begin
75 lencnt <= lencnt - 1; /* possible A */
77 lencnt <= ~nr21[4:0] + 1;