Subversion Repositories pentevo

Rev

Rev 425 | Rev 674 | Go to most recent revision | 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. // ATM-like memory pager (it pages specific 16kb region)
  4. //  with additions to support 4m addressable memory
  5. //  and pent1m mode.
  6. //
  7. // contain ports 3FF7,7FF7,BFF7,FFF7 as well as 37F7, 77F7, B7F7, F7F7
  8.  
  9. /*
  10.     This file is part of ZX-Evo Base Configuration firmware.
  11.  
  12.     ZX-Evo Base Configuration firmware is free software:
  13.     you can redistribute it and/or modify it under the terms of
  14.     the GNU General Public License as published by
  15.     the Free Software Foundation, either version 3 of the License, or
  16.     (at your option) any later version.
  17.  
  18.     ZX-Evo Base Configuration firmware is distributed in the hope that
  19.     it will be useful, but WITHOUT ANY WARRANTY; without even
  20.     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  21.     See the GNU General Public License for more details.
  22.  
  23.     You should have received a copy of the GNU General Public License
  24.     along with ZX-Evo Base Configuration firmware.
  25.     If not, see <http://www.gnu.org/licenses/>.
  26. */
  27.  
  28. `include "../include/tune.v"
  29.  
  30. module atm_pager(
  31.  
  32.         input  wire rst_n,
  33.  
  34.         input  wire fclk,
  35.         input  wire zpos,
  36.         input  wire zneg,
  37.  
  38.  
  39.         input  wire [15:0] za, // Z80 address bus
  40.  
  41.         input  wire [ 7:0] zd, // Z80 data bus - for latching port data
  42.  
  43.         input  wire        mreq_n,rd_n,m1_n, // to track DOS turn on/turn off
  44.  
  45.  
  46.         input  wire        pager_off, // PEN as in ATM2: turns off memory paging, service ROM is everywhere
  47.  
  48.  
  49.         input  wire        pent1m_ROM,    // for memory maps switching: d4 of 7ffd
  50.         input  wire [ 5:0] pent1m_page,   // 1 megabyte from pentagon1024 addressing, from 7FFD port
  51.         input  wire        pent1m_ram0_0, // RAM0 to the window 0 from pentagon1024 mode
  52.         input  wire        pent1m_1m_on,  // 1 meg addressing of pent1m mode on
  53.  
  54.         input  wire        in_nmi, // when we are in nmi, in 0000-3FFF must be last (FFth)
  55.                                    // RAM page. analoguous to pent1m_ram0_0
  56.                                    // but has higher priority
  57.  
  58.         input  wire        atmF7_wr, // write strobe for the xxF7 ATM port
  59.  
  60.  
  61.         input  wire        dos, // indicates state of computer: also determines ROM mapping
  62.  
  63.  
  64.         output wire        dos_turn_on,  // turns on or off DOS signal
  65.         output wire        dos_turn_off, //
  66.  
  67.         output wire        zclk_stall, // stall Z80 clock during DOS turning on
  68.  
  69.         output reg  [ 7:0] page,
  70.         output reg         romnram,
  71.  
  72.         // output for xxBE port read
  73.         output wire     [ 7:0] rd_page0,
  74.         output wire     [ 7:0] rd_page1,
  75.         output wire [ 1:0] rd_dos7ffd,
  76.         output wire [ 1:0] rd_ramnrom
  77. );
  78.         parameter ADDR = 2'b00;
  79.  
  80.  
  81.         reg [ 7:0] pages [0:1]; // 2 pages for each map - switched by pent1m_ROM
  82.  
  83.         reg [ 1:0] ramnrom; // ram(=1) or rom(=0)
  84.         reg [ 1:0] dos_7ffd; // =1 7ffd bits (ram) or DOS enter mode (rom) for given page
  85.  
  86.         reg mreq_n_reg, rd_n_reg, m1_n_reg;
  87.  
  88.         wire dos_exec_stb, ram_exec_stb;
  89.  
  90.  
  91.         reg [2:0] stall_count;
  92.  
  93.  
  94.  
  95.         // output data for port xxBE
  96.         assign rd_page0 = pages[0];
  97.         assign rd_page1 = pages[1];
  98.         //
  99.         assign rd_dos7ffd = dos_7ffd;
  100.         assign rd_ramnrom = ramnrom;
  101.  
  102.  
  103.  
  104.         // paging function, does not set pages, ramnrom, dos_7ffd
  105.         //
  106.         always @(posedge fclk)
  107.         begin
  108.                 if( pager_off )
  109.                 begin // atm no pager mode - each window has same ROM
  110.                         romnram <= 1'b1;
  111.                         page    <= 8'hFF;
  112.                 end
  113.                 else // pager on
  114.                 begin
  115.                         if( (ADDR==2'b00) && (pent1m_ram0_0 || in_nmi) ) // pent ram0 OR nmi
  116.                         begin
  117.                                 if( in_nmi )
  118.                                 begin
  119.                                         romnram <= 1'b0;
  120.                                         page    <= 8'hFF;
  121.                                 end
  122.                                 else // if( pent1m_ram0_0 )
  123.                                 begin
  124.                                         romnram <= 1'b0;
  125.                                         page    <= 8'd0;
  126.                                 end
  127.                         end
  128.                         else
  129.                         begin
  130.                                 romnram <= ~ramnrom[ pent1m_ROM ];
  131.  
  132.                                 if( dos_7ffd[ pent1m_ROM ] ) // 7ffd memmap switching
  133.                                 begin
  134.                                         if( ramnrom[ pent1m_ROM ] )
  135.                                         begin // ram map
  136.                                                 if( pent1m_1m_on )
  137.                                                 begin // map whole Mb from 7ffd to atm pages
  138.                                                         page <= { pages[ pent1m_ROM ][7:6], pent1m_page[5:0] };
  139.                                                 end
  140.                                                 else //128k like in atm2
  141.                                                 begin
  142.                                                         page <= { pages[ pent1m_ROM ][7:3], pent1m_page[2:0] };
  143.                                                 end
  144.                                         end
  145.                                         else // rom map with dos
  146.                                         begin
  147.                                                 page <= { pages[ pent1m_ROM ][7:1], dos };
  148.                                         end
  149.                                 end
  150.                                 else // no 7ffd impact
  151.                                 begin
  152.                                         page <= pages[ pent1m_ROM ];
  153.                                 end
  154.                         end
  155.                 end
  156.         end
  157.  
  158.  
  159.  
  160.  
  161.         // port reading: sets pages, ramnrom, dos_7ffd
  162.         //
  163.         always @(posedge fclk) if( atmF7_wr )
  164.         begin
  165.                 if( za[15:14]==ADDR )
  166.                 begin
  167.                         if( za[11] ) // xff7 ports - 1 meg
  168.                         begin
  169.                                 pages   [ pent1m_ROM ] <= ~{ 2'b11, zd[5:0] };
  170.                                 ramnrom [ pent1m_ROM ] <= zd[6];
  171.                                 dos_7ffd[ pent1m_ROM ] <= zd[7];
  172.                         end
  173.                         else // x7f7 ports - 4 meg ram
  174.                         begin
  175.                                 pages   [ pent1m_ROM ] <= ~zd;
  176.                                 ramnrom [ pent1m_ROM ] <= 1'b1; // RAM on
  177.                                 // dos_7ffd - UNCHANGED!!! (possibility to use 7ffd 1m and 128k addressing in the whole 4m!)
  178.                         end
  179.                 end
  180.         end
  181.  
  182.  
  183.         // DOS turn on/turn off
  184.         //
  185.  
  186. `ifdef SIMULATE
  187.         initial
  188.         begin
  189.                 m1_n_reg   = 1'b1;
  190.                 mreq_n_reg = 1'b1;
  191.                 rd_n_reg   = 1'b1;
  192.  
  193.                 stall_count = 3'b000;
  194.         end
  195. `endif
  196.  
  197.         always @(posedge fclk) if( zpos )
  198.         begin
  199.                 m1_n_reg <= m1_n;
  200.         end
  201.  
  202.         always @(posedge fclk) if( zneg )
  203.         begin
  204.                 mreq_n_reg <= mreq_n;
  205.         end
  206.  
  207.  
  208.  
  209.         assign dos_exec_stb = zneg && (za[15:14]==ADDR) &&
  210.                               (!m1_n_reg) && (!mreq_n) && mreq_n_reg &&
  211.                               (za[13:8]==6'h3D) &&
  212.                               dos_7ffd[1'b1] && (!ramnrom[1'b1]) && pent1m_ROM;
  213.  
  214.         assign ram_exec_stb = zneg && (za[15:14]==ADDR) &&
  215.                               (!m1_n_reg) && (!mreq_n) && mreq_n_reg &&
  216.                               ramnrom[pent1m_ROM];
  217.  
  218.         assign dos_turn_on  = dos_exec_stb;
  219.         assign dos_turn_off = ram_exec_stb;
  220.  
  221.  
  222.         // stall Z80 for some time when dos turning on to allow ROM chip to supply new data
  223.         // this can be important at 7 or even 14 mhz. minimum stall time is
  224.         // 3 clocks @ 28 MHz
  225.         always @(posedge fclk)
  226.         begin
  227.                 // яхЁхъы■ўхэшх т ─╬╤ ячє яЁюшёїюфшЄ чр яюыЄръЄр z80 фю Єюую, ъръ
  228.                 // z80 ёўшЄрхЄ фрээ√х. Є.х. є ячє яюыЄръЄр фы  т√фрўш эют√ї фрээ√ї.
  229.                 // 3.5ьуЎ - 140 эрэ, 7ьуЎ - 70 эрэ, 14ьуЎ - 35 эрэ.
  230.                 // фы  ячєїш 120эё эр 14ьуЎ эрфю х∙х 3 яюыЄръЄр фюсртшЄ№, шыш фЁєушьш
  231.                 // ёыютрьш, фюсртшЄ№ ъ ы■сющ чрфхЁцъх эр ы■сющ ўрёЄюЄх ьшэшьєь 3 ЄръЄр
  232.                 // 28 ьуЎ.
  233.                 if( dos_turn_on )
  234.                 begin
  235.                         stall_count[2] <= 1'b1; // count: 000(stop) -> 101 -> 110 -> 111 -> 000(stop)
  236.                         stall_count[0] <= 1'b1;
  237.                 end
  238.                 else if( stall_count[2] )
  239.                 begin
  240.                         stall_count[2:0] <= stall_count[2:0] + 3'd1;
  241.                 end
  242.  
  243.         end
  244.  
  245.         assign zclk_stall = dos_turn_on | stall_count[2];
  246.  
  247.  
  248.  
  249. endmodule
  250.  
  251.