| 1 |
17 |
bporcella |
///////////////////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
////
|
| 3 |
|
|
//// file name: z80_core_top.v
|
| 4 |
|
|
//// description: interconnect module for z80 core.
|
| 5 |
|
|
//// project: wb_z80 ////
|
| 6 |
|
|
////
|
| 7 |
|
|
//// Author: B.J. Porcella
|
| 8 |
|
|
//// bporcella@sbcglobal.net
|
| 9 |
|
|
////
|
| 10 |
|
|
////
|
| 11 |
|
|
////
|
| 12 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
| 13 |
|
|
////
|
| 14 |
|
|
//// Copyright (C) 2000-2002 B.J. Porcella
|
| 15 |
|
|
//// Real Time Solutions
|
| 16 |
|
|
////
|
| 17 |
|
|
////
|
| 18 |
|
|
//// This source file may be used and distributed without
|
| 19 |
|
|
//// restriction provided that this copyright statement is not
|
| 20 |
|
|
//// removed from the file and that any derivative work contains
|
| 21 |
|
|
//// the original copyright notice and the associated disclaimer.
|
| 22 |
|
|
////
|
| 23 |
|
|
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY
|
| 24 |
|
|
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
| 25 |
|
|
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
| 26 |
|
|
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR
|
| 27 |
|
|
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 28 |
|
|
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 29 |
|
|
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
| 30 |
|
|
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
| 31 |
|
|
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 32 |
|
|
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 33 |
|
|
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
| 34 |
|
|
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 35 |
|
|
//// POSSIBILITY OF SUCH DAMAGE.
|
| 36 |
|
|
////
|
| 37 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
| 38 |
|
|
// CVS Log
|
| 39 |
|
|
//
|
| 40 |
27 |
bporcella |
// $Id: z80_core_top.v,v 1.6 2004-05-27 14:23:36 bporcella Exp $
|
| 41 |
17 |
bporcella |
//
|
| 42 |
27 |
bporcella |
// $Date: 2004-05-27 14:23:36 $
|
| 43 |
|
|
// $Revision: 1.6 $
|
| 44 |
17 |
bporcella |
// $Author: bporcella $
|
| 45 |
|
|
// $Locker: $
|
| 46 |
|
|
// $State: Exp $
|
| 47 |
|
|
//
|
| 48 |
|
|
// Change History:
|
| 49 |
|
|
// $Log: not supported by cvs2svn $
|
| 50 |
27 |
bporcella |
// Revision 1.5 2004/05/21 02:51:25 bporcella
|
| 51 |
|
|
// inst test got to the worked macro
|
| 52 |
|
|
//
|
| 53 |
26 |
bporcella |
// Revision 1.4 2004/05/18 22:31:21 bporcella
|
| 54 |
|
|
// instruction test getting to final stages
|
| 55 |
|
|
//
|
| 56 |
25 |
bporcella |
// Revision 1.3 2004/05/13 14:58:53 bporcella
|
| 57 |
|
|
// testbed built and verification in progress
|
| 58 |
|
|
//
|
| 59 |
23 |
bporcella |
// Revision 1.2 2004/04/27 21:38:22 bporcella
|
| 60 |
|
|
// test lint on core
|
| 61 |
|
|
//
|
| 62 |
18 |
bporcella |
// Revision 1.1 2004/04/27 21:27:13 bporcella
|
| 63 |
|
|
// first core build
|
| 64 |
|
|
//
|
| 65 |
17 |
bporcella |
// Revision 1.1.1.1 2004/04/13 23:47:42 bporcella
|
| 66 |
|
|
// import first files
|
| 67 |
|
|
//
|
| 68 |
|
|
//
|
| 69 |
|
|
//
|
| 70 |
|
|
// connects modules:
|
| 71 |
27 |
bporcella |
// z80_memstate2.v main state machine for z8 pc - sp and wishbone regiters
|
| 72 |
|
|
// z80_inst_exec.v main execution engine for z80 general programming registers - alu's
|
| 73 |
|
|
// z80_sram.v main memory (on board)
|
| 74 |
|
|
// z80_bist_logic.v memory initialization and some simple test peripherals.
|
| 75 |
|
|
//
|
| 76 |
|
|
// WARNING be sure the "test peripherals" in the bist_logic do not interfere with your
|
| 77 |
|
|
// system.
|
| 78 |
|
|
//
|
| 79 |
17 |
bporcella |
//-------1---------2---------3--------Module Name and Port List------7---------8---------9--------0
|
| 80 |
23 |
bporcella |
module z80_core_top(
|
| 81 |
|
|
wb_dat_o,
|
| 82 |
17 |
bporcella |
wb_stb_o,
|
| 83 |
|
|
wb_cyc_o,
|
| 84 |
|
|
wb_we_o,
|
| 85 |
|
|
wb_adr_o,
|
| 86 |
|
|
wb_tga_o,
|
| 87 |
|
|
wb_ack_i,
|
| 88 |
|
|
wb_clk_i,
|
| 89 |
|
|
wb_dat_i,
|
| 90 |
23 |
bporcella |
wb_rst_i,
|
| 91 |
|
|
`ifdef COMPILE_BIST
|
| 92 |
|
|
bist_ack_o,
|
| 93 |
|
|
bist_err_o,
|
| 94 |
17 |
bporcella |
bist_req_i,
|
| 95 |
23 |
bporcella |
`endif
|
| 96 |
17 |
bporcella |
int_req_i
|
| 97 |
|
|
|
| 98 |
|
|
);
|
| 99 |
|
|
|
| 100 |
|
|
//-------1---------2---------3--------Output Ports---------6---------7---------8---------9--------0
|
| 101 |
|
|
|
| 102 |
|
|
output [7:0] wb_dat_o;
|
| 103 |
|
|
output wb_stb_o;
|
| 104 |
|
|
output wb_cyc_o;
|
| 105 |
|
|
output wb_we_o;
|
| 106 |
|
|
output [15:0] wb_adr_o;
|
| 107 |
|
|
output [1:0] wb_tga_o;
|
| 108 |
|
|
|
| 109 |
|
|
|
| 110 |
|
|
//-------1---------2---------3--------Input Ports----------6---------7---------8---------9--------0
|
| 111 |
|
|
|
| 112 |
|
|
input wb_ack_i;
|
| 113 |
|
|
input wb_clk_i;
|
| 114 |
|
|
input [7:0] wb_dat_i;
|
| 115 |
23 |
bporcella |
input wb_rst_i;
|
| 116 |
17 |
bporcella |
input int_req_i;
|
| 117 |
|
|
|
| 118 |
|
|
|
| 119 |
23 |
bporcella |
`ifdef COMPILE_BIST
|
| 120 |
|
|
output bist_err_o;
|
| 121 |
|
|
output bist_ack_o;
|
| 122 |
|
|
input bist_req_i;
|
| 123 |
|
|
`endif
|
| 124 |
|
|
|
| 125 |
|
|
|
| 126 |
17 |
bporcella |
//-------1---------2---------3--------Parameters-----------6---------7---------8---------9--------0
|
| 127 |
|
|
//-------1---------2---------3--------Wires------5---------6---------7---------8---------9--------0
|
| 128 |
|
|
wire [15:0] wb_adr_o;
|
| 129 |
|
|
wire [9:0] ir1, ir2;
|
| 130 |
|
|
wire [15:0] nn;
|
| 131 |
|
|
wire [15:0] sp;
|
| 132 |
23 |
bporcella |
wire [7:0] ar, fr, br, cr, dr, er, hr, lr, intr;
|
| 133 |
17 |
bporcella |
wire [15:0] ixr, iyr;
|
| 134 |
27 |
bporcella |
wire [7:0] wb_dat_i, wb_dat_o, sdram_do, cfg_do, bist_do;
|
| 135 |
26 |
bporcella |
wire [15:0] add16; // ir2 execution engine output for sp updates
|
| 136 |
|
|
wire [15:0] adr_alu; // address alu to inst to update hl and de on block moves
|
| 137 |
27 |
bporcella |
wire [7:0] alu8_out, sh_alu, bit_alu; // gotta move these to data out register
|
| 138 |
|
|
// for memory operations.
|
| 139 |
17 |
bporcella |
|
| 140 |
27 |
bporcella |
wire sram_addr;
|
| 141 |
|
|
wire ce_sram;
|
| 142 |
|
|
wire [7:0] wb_rd_dat;
|
| 143 |
|
|
wire wb_ack;
|
| 144 |
17 |
bporcella |
//-------1---------2---------3--------Registers--5---------6---------7---------8---------9--------0
|
| 145 |
|
|
//-------1---------2---------3--------Assignments----------6---------7---------8---------9--------0
|
| 146 |
|
|
//-------1---------2---------3--------State Machines-------6---------7---------8---------9--------0
|
| 147 |
|
|
|
| 148 |
23 |
bporcella |
|
| 149 |
|
|
`ifdef COMPILE_BIST
|
| 150 |
27 |
bporcella |
wire [7:0] bist_dat_o;
|
| 151 |
|
|
wire bist_io_ack;
|
| 152 |
|
|
|
| 153 |
23 |
bporcella |
z80_bist_logic i_z80_bist_logic(
|
| 154 |
27 |
bporcella |
.bist_err_o(bist_err_o),
|
| 155 |
|
|
.bist_ack_o(bist_ack_o),
|
| 156 |
|
|
.wb_dat_o(bist_dat_o),
|
| 157 |
|
|
.wb_ack_o(bist_io_ack),
|
| 158 |
|
|
.int_req_o(bist_int_req),
|
| 159 |
|
|
.wb_adr_i(wb_adr_o),
|
| 160 |
|
|
.wb_dat_i(wb_dat_o),
|
| 161 |
|
|
.wb_we_i(wb_we_o),
|
| 162 |
|
|
.wb_cyc_i(wb_cyc_o),
|
| 163 |
|
|
.wb_stb_i(wb_stb_o),
|
| 164 |
|
|
.wb_tga_i(wb_tga_o),
|
| 165 |
|
|
.int_req_i(int_req_i),
|
| 166 |
|
|
.wb_clk_i(wb_clk_i),
|
| 167 |
|
|
.wb_rst_i(wb_rst_i)
|
| 168 |
23 |
bporcella |
);
|
| 169 |
27 |
bporcella |
|
| 170 |
|
|
`else
|
| 171 |
|
|
wire bist_io_ack = 1'b0;
|
| 172 |
|
|
wire [7:0] bist_dat_o = 8'b0;
|
| 173 |
23 |
bporcella |
`endif
|
| 174 |
|
|
|
| 175 |
|
|
|
| 176 |
|
|
|
| 177 |
17 |
bporcella |
z80_memstate2 i_z80_memstate2(
|
| 178 |
|
|
.wb_adr_o(wb_adr_o), .wb_we_o(wb_we_o), .wb_cyc_o(wb_cyc_o), .wb_stb_o(wb_stb_o), .wb_tga_o(wb_tga_o), .wb_dat_o(wb_dat_o),
|
| 179 |
26 |
bporcella |
.exec_ir2(exec_ir2),
|
| 180 |
|
|
.exec_decbc(exec_decbc), .exec_decb(exec_decb),
|
| 181 |
|
|
.ir1(ir1), .ir2(ir2), .ir1dd(ir1dd), .ir1fd(ir1fd), .ir2dd(ir2dd), .ir2fd(ir2fd), .nn(nn), .sp(sp),
|
| 182 |
17 |
bporcella |
.upd_ar(upd_ar), .upd_br(upd_br), .upd_cr(upd_cr), .upd_dr(upd_dr), .upd_er(upd_er), .upd_hr(upd_hr), .upd_lr(upd_lr),.upd_fr(upd_fr),
|
| 183 |
23 |
bporcella |
.beq0(br_eq0), .ceq0(cr_eq0),
|
| 184 |
17 |
bporcella |
.ar(ar), .fr(fr), .br(br), .cr(cr), .dr(dr), .er(er), .hr(hr), .lr(lr),
|
| 185 |
27 |
bporcella |
.ixr(ixr), .iyr(iyr), .intr(intr),
|
| 186 |
|
|
.wb_dat_i(wb_rd_dat), .wb_ack_i(wb_ack),
|
| 187 |
|
|
.int_req_i(bist_int_req),
|
| 188 |
17 |
bporcella |
.add16(add16),
|
| 189 |
25 |
bporcella |
.alu8_out(alu8_out),
|
| 190 |
26 |
bporcella |
.adr_alu(adr_alu),
|
| 191 |
|
|
.blk_mv_upd_hl(blk_mv_upd_hl),
|
| 192 |
|
|
.blk_mv_upd_de(blk_mv_upd_de),
|
| 193 |
25 |
bporcella |
.sh_alu(sh_alu),
|
| 194 |
|
|
.bit_alu(bit_alu),
|
| 195 |
17 |
bporcella |
.wb_clk_i(wb_clk_i),
|
| 196 |
23 |
bporcella |
.rst_i(wb_rst_i) // keep this generic - may turn out to be different from wb_rst
|
| 197 |
|
|
);
|
| 198 |
17 |
bporcella |
|
| 199 |
|
|
|
| 200 |
|
|
z80_inst_exec i_z80_inst_exec(
|
| 201 |
|
|
.br_eq0(br_eq0),
|
| 202 |
|
|
.cr_eq0(cr_eq0),
|
| 203 |
|
|
.upd_ar(upd_ar), .upd_br(upd_br), .upd_cr(upd_cr), .upd_dr(upd_dr), .upd_er(upd_er), .upd_hr(upd_hr), .upd_lr(upd_lr),.upd_fr(upd_fr),
|
| 204 |
23 |
bporcella |
.ar(ar), .fr(fr), .br(br), .cr(cr), .dr(dr), .er(er), .hr(hr), .lr(lr), .intr(intr),
|
| 205 |
25 |
bporcella |
.ixr(ixr), .iyr(iyr), .add16(add16), .alu8_out(alu8_out),
|
| 206 |
26 |
bporcella |
.adr_alu(adr_alu),
|
| 207 |
|
|
.blk_mv_upd_hl(blk_mv_upd_hl),
|
| 208 |
|
|
.blk_mv_upd_de(blk_mv_upd_de),
|
| 209 |
25 |
bporcella |
.sh_alu(sh_alu),
|
| 210 |
|
|
.bit_alu(bit_alu),
|
| 211 |
17 |
bporcella |
.exec_ir2(exec_ir2),
|
| 212 |
|
|
.exec_decbc(exec_decbc), .exec_decb(exec_decb),
|
| 213 |
|
|
.ir2(ir2),
|
| 214 |
|
|
.clk(wb_clk_i),
|
| 215 |
23 |
bporcella |
.rst(wb_rst_i),
|
| 216 |
17 |
bporcella |
.nn(nn), .sp(sp),
|
| 217 |
23 |
bporcella |
.ir2dd(ir2dd),
|
| 218 |
|
|
.ir2fd(ir2fd)
|
| 219 |
17 |
bporcella |
);
|
| 220 |
|
|
|
| 221 |
27 |
bporcella |
//------------------- routing logic for the wishbone ------------------------
|
| 222 |
17 |
bporcella |
//
|
| 223 |
27 |
bporcella |
// I guess purists would prefer this logic in a lower module --- "no logic on top level"
|
| 224 |
|
|
// Somehow I tend to think that this is the kind of logic that belongs on the top
|
| 225 |
|
|
// level.
|
| 226 |
17 |
bporcella |
|
| 227 |
27 |
bporcella |
assign sram_addr = ~wb_adr_o[15] & (wb_tga_o == 2'b00);
|
| 228 |
|
|
assign ce_sram = sram_addr & wb_cyc_o & wb_stb_o;
|
| 229 |
|
|
assign wb_rd_dat = sram_addr ? sdram_do :
|
| 230 |
|
|
bist_io_ack ? bist_dat_o :
|
| 231 |
|
|
wb_dat_i;
|
| 232 |
|
|
assign wb_ack = ce_sram | bist_io_ack | wb_ack_i;
|
| 233 |
|
|
|
| 234 |
|
|
|
| 235 |
|
|
|
| 236 |
|
|
z80_sram #(15) i_z80_sram(
|
| 237 |
17 |
bporcella |
// Generic synchronous single-port RAM interface
|
| 238 |
27 |
bporcella |
.clk(wb_clk_i), .rst(wb_rst_i), .ce(ce_sram), .we(wb_we_o), .oe(1'b1),
|
| 239 |
|
|
.addr(wb_adr_o[14:0]), .di(wb_dat_o), .do(sdram_do)
|
| 240 |
23 |
bporcella |
);
|
| 241 |
17 |
bporcella |
|
| 242 |
|
|
|
| 243 |
|
|
|
| 244 |
|
|
|
| 245 |
|
|
|
| 246 |
27 |
bporcella |
|
| 247 |
|
|
|
| 248 |
|
|
|
| 249 |
17 |
bporcella |
endmodule
|