From: Joshua Wise Date: Mon, 28 Apr 2008 10:41:24 +0000 (-0400) Subject: Sound: Leave it to Dennis. X-Git-Url: http://git.joshuawise.com/fpgaboy.git/commitdiff_plain/01878f5fdca9d08e4cf7ceed7f5a39f4df602de4 Sound: Leave it to Dennis. --- diff --git a/Sound1.v b/Sound1.v index 9444dbf..41abaa5 100644 --- a/Sound1.v +++ b/Sound1.v @@ -17,11 +17,11 @@ module Sound1( ); /* 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; @@ -58,15 +58,10 @@ module Sound1( 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 diff --git a/Sound2.v b/Sound2.v index fa5e5e7..2bb9598 100644 --- a/Sound2.v +++ b/Sound2.v @@ -16,7 +16,7 @@ module Sound2( ); /* 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; diff --git a/Soundcore.v b/Soundcore.v index 16d6067..b2c4d35 100644 --- a/Soundcore.v +++ b/Soundcore.v @@ -17,9 +17,16 @@ module Soundcore( 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; @@ -34,14 +41,14 @@ module Soundcore( 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( @@ -52,7 +59,7 @@ module Soundcore( .data(data), .cntclk(cntclk[4]), .lenclk(lenclk[13]), - .en(nr52[7] & nr52[0]), + .en(nr52[7]), .snd_data(sndout1) ); @@ -64,7 +71,7 @@ module Soundcore( .data(data), .cntclk(cntclk[4]), .lenclk(lenclk[13]), - .en(nr52[7] & nr52[0]), + .en(nr52[7]), .snd_data(sndout2) ); diff --git a/bootrom.asm b/bootrom.asm index cd76097..4e780bf 100644 --- a/bootrom.asm +++ b/bootrom.asm @@ -185,8 +185,12 @@ boot: jr .running ; $0100 .running: ld a, $FF ld [$FF51], A + ld a, $00 + ld [$FF25], a .diq: ld A, [$FF51] cp 0 jr z, .diq + ld a, 0 + LD [$FF40],A jp $0000