Subversion Repositories pentevo

Rev

Rev 1319 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // ZX-Evo Base Configuration (c) NedoPC 2008,2009,2010,2011,2012,2013,2014
  2. //
  3. // frame INT generation
  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 zint
  27. (
  28.         input  wire fclk,
  29.         input  wire rst_n,
  30.  
  31.         input  wire zpos,
  32.         input  wire zneg,
  33.  
  34.         // irq initiators
  35.         input  wire vbl_start, // vblank interrupt
  36.         input  wire tmr_start, // timer interrupt
  37.         // TODO: more inputs
  38.  
  39.         input  wire iorq_n,
  40.         input  wire m1_n,
  41.  
  42.         input  wire wait_n,
  43.  
  44.         output reg  int_n,
  45.  
  46.         input  wire        irq_enh,
  47.         input  wire        irq_ena_int_vec,
  48.         input  wire        irq_ena_ext_vec,
  49.         input  wire        irq_int_autoclr,
  50.         //
  51.         output reg  [ 6:0] irq_stat,
  52.         //
  53.         input  wire        irq_stat_setnrst,
  54.         input  wire [ 6:0] irq_stat_wr_sel,
  55.         input  wire        irq_stat_wr_stb,
  56.         //
  57.         output reg  [ 6:0] irq_ena,
  58.         //
  59.         input  wire        irq_ena_setnrst,
  60.         input  wire [ 6:0] irq_ena_wr_sel,
  61.         input  wire        irq_ena_wr_stb
  62. );
  63.  
  64.         wire intend;
  65.  
  66.         reg [9:0] intctr;
  67.  
  68.         reg [1:0] wr;
  69.  
  70.  
  71.         wire [6:0] irq_act;
  72.         wire [6:0] irq_autoclr;
  73.  
  74.  
  75.  
  76.  
  77. `ifdef SIMULATE
  78.         initial
  79.         begin
  80.                 intctr = 10'b1100000000;
  81.         end
  82. `endif
  83.  
  84.         always @(posedge fclk)
  85.                 wr[1:0] <= { wr[0], wait_n };
  86.  
  87.         always @(posedge fclk)
  88.         begin
  89.                 if( vbl_start )
  90.                         intctr <= 10'd0;
  91.                 else if( !intctr[9:8] && wr[1] )
  92.                         intctr <= intctr + 10'd1;
  93.         end
  94.  
  95.  
  96.         assign intend = intctr[9:8] || ( (!iorq_n) && (!m1_n) && zneg );
  97.  
  98.  
  99.         always @(posedge fclk)
  100.         begin
  101.                 if( vbl_start )
  102.                         int_n <= 1'b0;
  103.                 else if( intend )
  104.                         int_n <= 1'bZ;
  105.         end
  106.  
  107.  
  108.  
  109.  
  110.  
  111.         // enhanced IRQs control
  112.  
  113.         // enable
  114.         always @(posedge fclk, negedge rst_n)
  115.         if( !rst_n )
  116.                 irq_ena <= 7'd0;
  117.         else if( !irq_enh )
  118.                 irq_ena <= 7'd0;
  119.         else if( irq_ena_wr_stb )
  120.                 irq_ena <= (irq_ena & (~irq_ena_wr_sel)) | ({7{irq_ena_setnrst}} & irq_ena_wr_sel);
  121.  
  122.         // status
  123.         assign irq_autoclr = 7'd0; // TODO: implement autoclr feature
  124.         assign irq_act = {5'd0, tmr_start, vbl_start};
  125.  
  126.         always @(posedge fclk, negedge rst_n)
  127.         if( !rst_n )
  128.                 irq_stat <= 7'd0;
  129.         else if( !irq_enh )
  130.                 irq_stat <= 7'd0;
  131.         else
  132.         begin : status_bits
  133.                 integer i;
  134.                 for(i=0;i<7;i=i+1) begin
  135.                         if( irq_act[i] || (irq_ena_wr_stb && irq_ena_setnrst && irq_ena_wr_sel[i]) )
  136.                                 irq_stat[i] <= 1'b1;
  137.                         else if( irq_autoclr[i] || (irq_ena_wr_stb && !irq_ena_setnrst && irq_ena_wr_sel[i]) )
  138.                                 irq_stat[i] <= 1'b0;
  139.                 end
  140.         end
  141.  
  142.  
  143.  
  144. endmodule
  145.  
  146.