Subversion Repositories pentevo

Rev

Rev 473 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. // ZX-Evo Base Configuration (c) NedoPC 2008,2009,2010,2011,2012,2013,2014
  2. //
  3. // integrates sound features: tapeout, beeper and covox
  4.  
  5. /*
  6.     This file is part of ZX-Evo Base Configuration firmware.
  7.  
  8.     ZX-Evo Base Configuration firmware is free software:
  9.     you can redistribute it and/or modify it under the terms of
  10.     the GNU General Public License as published by
  11.     the Free Software Foundation, either version 3 of the License, or
  12.     (at your option) any later version.
  13.  
  14.     ZX-Evo Base Configuration firmware is distributed in the hope that
  15.     it will be useful, but WITHOUT ANY WARRANTY; without even
  16.     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17.     See the GNU General Public License for more details.
  18.  
  19.     You should have received a copy of the GNU General Public License
  20.     along with ZX-Evo Base Configuration firmware.
  21.     If not, see <http://www.gnu.org/licenses/>.
  22. */
  23.  
  24. `include "../include/tune.v"
  25.  
  26. module sound(
  27.  
  28.         input  wire       clk,
  29.  
  30.         input  wire [7:0] din,
  31.  
  32.  
  33.         input  wire       beeper_wr,
  34.         input  wire       covox_wr,
  35.  
  36.         input  wire       beeper_mux, // output either tape_out or beeper
  37.  
  38.  
  39.         output wire       sound_bit
  40. );
  41.  
  42.         reg [6:0] ctr;
  43.         reg [7:0] val;
  44.  
  45.         reg mx_beep_n_covox;
  46.  
  47.         reg beep_bit;
  48.         reg beep_bit_old;
  49.  
  50.         wire covox_bit;
  51.  
  52.  
  53.  
  54.  
  55.         always @(posedge clk)
  56.         begin
  57. /*              if( beeper_wr ) */
  58.                                 if( beeper_wr && (beep_bit!=beep_bit_old) )
  59.                         mx_beep_n_covox <= 1'b1;
  60.                 else if( covox_wr )
  61.                         mx_beep_n_covox <= 1'b0;
  62.         end
  63.  
  64.         always @(posedge clk) if( beeper_wr ) beep_bit_old <= beep_bit;
  65.  
  66.         always @(posedge clk)
  67.         if( beeper_wr )
  68.                 beep_bit <= beeper_mux ? din[3] /*tapeout*/ : din[4] /*beeper*/;
  69.  
  70.  
  71.         always @(posedge clk)
  72.         if( covox_wr )
  73.                 val <= din;
  74.  
  75.         always @(negedge clk)
  76.                 ctr <= ctr + 6'd1;
  77.  
  78.         assign covox_bit = ( {ctr,clk} < val );
  79.  
  80.  
  81.         bothedge trigger
  82.         (
  83.                 .clk( clk ),
  84.  
  85.                 .d( mx_beep_n_covox ? beep_bit : covox_bit ),
  86.  
  87.                 .q( sound_bit )
  88.         );
  89.  
  90.  
  91.  
  92. endmodule
  93.  
  94.  
  95.  
  96.  
  97. // both-edge trigger emulator
  98. module bothedge(
  99.  
  100.         input  wire clk,
  101.  
  102.         input  wire d,
  103.  
  104.         output wire q
  105.  
  106. );
  107.         reg trgp, trgn;
  108.  
  109.         assign q = trgp ^ trgn;
  110.  
  111.         always @(posedge clk)
  112.         if( d!=q )
  113.                 trgp <= ~trgp;
  114.  
  115.         always @(negedge clk)
  116.         if( d!=q )
  117.                 trgn <= ~trgn;
  118.  
  119. endmodule
  120.  
  121.