Subversion Repositories pentevo

Rev

Rev 394 | Rev 469 | 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 2008-2009
  4. //
  5. // Z80 memory manager: routes ROM/RAM accesses, makes wait-states for 14MHz or stall condition, etc.
  6. //
  7. //
  8. // fclk    _/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\
  9. //          |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  10. // zclk     /```\___/```\___/```\___/```````\_______/```````\_______/```````````````\_______________/```````````````\_______________/`
  11. //          |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  12. // zpos     `\___/```\___/```\___/```\___________/```\___________/```\___________________________/```\___________________________/```\
  13. //          |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  14. // zneg     _/```\___/```\___/```\_______/```\___________/```\___________________/```\___________________________/```\________________
  15.  
  16. module zmem(
  17.  
  18.         input fclk,
  19.         input rst_n,
  20.  
  21.         input zpos, //
  22.         input zneg, // strobes which show positive and negative edges of zclk; this is to stay in single clock domain
  23.  
  24.         input cend,  // DRAM cycle end
  25.         input pre_cend, // pre cycle end
  26.  
  27.  
  28.         input [15:0] za,
  29.  
  30.         input [7:0] zd_in, // won't emit anything to Z80 bus, data bus mux is another module
  31.         output reg [7:0] zd_out, // output to Z80 bus
  32.  
  33.         output zd_ena, // out bus to the Z80
  34.  
  35.         input m1_n,
  36.         input rfsh_n,
  37.         input mreq_n,
  38.         input iorq_n,
  39.         input rd_n,
  40.         input wr_n,
  41.  
  42.  
  43.  
  44.  
  45.         input  wire        win0_romnram, // four windows, each 16k,
  46.         input  wire        win1_romnram, // ==1 - there is rom,
  47.         input  wire        win2_romnram, // ==0 - there is ram
  48.         input  wire        win3_romnram, //
  49.  
  50.         input  wire [ 7:0] win0_page, // which 16k page is in given window
  51.         input  wire [ 7:0] win1_page, //
  52.         input  wire [ 7:0] win2_page, //
  53.         input  wire [ 7:0] win3_page, //
  54.  
  55.  
  56.         input  wire        romrw_en,
  57.  
  58.  
  59.         output reg  [ 4:0] rompg, // output for ROM paging
  60.         output wire        romoe_n,
  61.         output wire        romwe_n,
  62.         output wire        csrom,
  63.  
  64.  
  65.         output cpu_req,
  66.         output cpu_rnw,
  67.         output [20:0] cpu_addr,
  68.         output [7:0] cpu_wrdata,
  69.         output cpu_wrbsel,
  70.  
  71.         input [15:0] cpu_rddata,
  72.         input cpu_strobe
  73.  
  74. );
  75.  
  76.  
  77.         wire [1:0] win;
  78.         reg [7:0] page;
  79.         reg romnram;
  80.  
  81.         wire ramreq;
  82.  
  83.         wire ramwr,ramrd;
  84.  
  85.         reg ramrd_reg,ramwr_reg,ramrd_prereg;
  86.  
  87.  
  88.         // make paging
  89.         assign win[1:0] = za[15:14];
  90.  
  91.         always @*
  92.         case( win )
  93.                 2'b00: begin
  94.                         page    = win0_page;
  95.                         romnram = win0_romnram;
  96.                 end
  97.  
  98.                 2'b01: begin
  99.                         page    = win1_page;
  100.                         romnram = win1_romnram;
  101.                 end
  102.  
  103.                 2'b10: begin
  104.                         page    = win2_page;
  105.                         romnram = win2_romnram;
  106.                 end
  107.  
  108.                 2'b11: begin
  109.                         page    = win3_page;
  110.                         romnram = win3_romnram;
  111.                 end
  112.         endcase
  113.  
  114.  
  115.         // rom paging - only half a megabyte addressing.
  116.         always @*
  117.         begin
  118.                 rompg[4:0] = page[4:0];
  119.         end
  120.  
  121.  
  122.  
  123.  
  124.         assign romwe_n = wr_n | mreq_n | (~romrw_en);
  125.         assign romoe_n = rd_n | mreq_n;
  126.  
  127.         assign csrom = romnram; // positive polarity!
  128.  
  129.  
  130.  
  131.         // DRAM accesses
  132.  
  133.         assign ramreq = (~mreq_n) && (~romnram) && rfsh_n;
  134.  
  135.         assign ramrd = ramreq & (~rd_n);
  136.         assign ramwr = ramreq & (~wr_n);
  137.  
  138.  
  139.         assign zd_ena = ramrd;
  140.         assign cpu_wrdata = zd_in;
  141.  
  142.         assign cpu_wrbsel = za[0];
  143.         assign cpu_addr[20:0] = { page[7:0], za[13:1] };
  144.  
  145.         always @* if( cpu_strobe ) // WARNUNG! ACHTING! LATCH!!!
  146.                 zd_out <= cpu_wrbsel ? cpu_rddata[7:0] : cpu_rddata[15:8];
  147.  
  148.  
  149. //      always @(posedge fclk) if( pre_cend )
  150. //              ramrd_prereg <= ramrd;
  151. //      assign cpu_rnw = ramrd_prereg; // is it correct???
  152. //
  153. // removed because it could be source of problems for NMOS Z80
  154. //
  155. // new one:
  156. //
  157.         assign cpu_rnw = ramrd;
  158.  
  159.  
  160.         always @(posedge fclk) if( cend )
  161.         begin
  162.                 ramrd_reg <= ramrd;
  163.                 ramwr_reg <= ramwr;
  164.         end
  165.  
  166.         assign cpu_req = ( ramrd & (~ramrd_reg) ) | ( ramwr & (~ramwr_reg) );
  167.  
  168.  
  169.  
  170. endmodule
  171.  
  172.