Subversion Repositories pentevo

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. `include "../include/tune.v"
  2.  
  3. // Pentevo project (c) NedoPC 2011
  4. //
  5. // integrates sound features: tapeout, beeper and covox
  6.  
  7. module sound(
  8.  
  9.         input  wire       clk,
  10.  
  11.         input  wire [7:0] din,
  12.  
  13.  
  14.         input  wire       beeper_wr,
  15.         input  wire       covox_wr,
  16.  
  17.         input  wire       beeper_mux, // output either tape_out or beeper
  18.  
  19.  
  20.         output wire       sound_bit
  21. );
  22.  
  23.         reg [6:0] ctr;
  24.         reg [7:0] val;
  25.  
  26.         reg mx_beep_n_covox;
  27.  
  28.         reg beep_bit;
  29.  
  30.         wire covox_bit;
  31.  
  32.  
  33.  
  34.  
  35.         always @(posedge clk)
  36.         begin
  37.                 if( beeper_wr )
  38.                         mx_beep_n_covox <= 1'b1;
  39.                 else if( covox_wr )
  40.                         mx_beep_n_covox <= 1'b0;
  41.         end
  42.  
  43.  
  44.         always @(posedge clk)
  45.         if( beeper_wr )
  46.                 beep_bit <= beeper_mux ? din[3] /*tapeout*/ : din[4] /*beeper*/;
  47.  
  48.  
  49.         always @(posedge clk)
  50.         if( covox_wr )
  51.                 val <= din;
  52.  
  53.         always @(negedge clk)
  54.                 ctr <= ctr + 6'd1;
  55.  
  56.         assign covox_bit = ( {ctr,clk} < val );
  57.  
  58.  
  59.         bothedge trigger
  60.         (
  61.                 .clk( clk ),
  62.  
  63.                 .d( mx_beep_n_covox ? beep_bit : covox_bit ),
  64.  
  65.                 .q( sound_bit )
  66.         );
  67.  
  68.  
  69.  
  70. endmodule
  71.  
  72.  
  73.  
  74.  
  75. // both-edge trigger emulator
  76. module bothedge(
  77.  
  78.         input  wire clk,
  79.  
  80.         input  wire d,
  81.  
  82.         output wire q
  83.  
  84. );
  85.         reg trgp, trgn;
  86.  
  87.         assign q = trgp ^ trgn;
  88.  
  89.         always @(posedge clk)
  90.         if( d!=q )
  91.                 trgp <= ~trgp;
  92.  
  93.         always @(negedge clk)
  94.         if( d!=q )
  95.                 trgn <= ~trgn;
  96.  
  97. endmodule
  98.  
  99.