2 // Copyright (C) 2008 Tomasz Malesinski <tmal@mimuw.edu.pl>
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
56 ram
u_ram(.
clk_i(clk_i
),
65 defparam u_rom.size
= 'h1000
;
66 defparam u_rom.adrbits
= 12;
68 rom
u_rom(.
clk_i(clk_i
),
75 assign ack_o
= ramack_o | romack_o
;
76 assign dat_o
= ramstb ? ramdat_o
: romdat_o
;
78 assign ramstb
= stb_i
& (adr_i
[15:10] == 6'b0);
79 assign romstb
= stb_i
& (adr_i
[15:12] == 'hf
);
83 module cpu6502_test_reg(clk_i
, rst_i
,
88 test_done_o
, test_res_o
, test_finish_o
);
95 output test_done_o
, test_res_o
, test_finish_o
;
103 reg [15:0] test_seq_o
;
104 wire test_done_o
, test_res_o
;
107 assign ack_o
= stb_i
;
109 always @ (posedge clk_i
)
112 else if (stb_i
&& we_i
&& adr_i
== 1)
115 always @ (posedge clk_i
)
118 test_seq_o
[7:0] <= dat_i
;
120 test_seq_o
[15:8] <= dat_i
;
122 assign test_done_o
= (stb_i
&& we_i
&& adr_i
== 0);
123 assign test_res_o
= dat_i
[0];
133 wire memory_stb
, test_reg_stb
;
137 wire memory_ack
, test_reg_ack
;
139 wire [15:0] test_seq
;
140 wire test_done
, test_res
, test_finish
;
145 $readmemh("tests/cpu_test.memh", u_memory.u_rom.memory
);
146 //$monitor("%h %h a=%h %b %h %h", u_cpu.pc, u_cpu.ir, u_cpu.acc,
147 // u_cpu.regf, adr, u_cpu.dat_o);
155 always @ (posedge clk_o
) begin
156 if (test_finish
) begin
165 $display("Test at %d: PASSED", test_seq
);
167 $display("Test at %d: FAILED", test_seq
);
176 assign memory_stb
= cpu_stb_o
&& cpu_cyc_o
&&
177 (adr
[15:10] == 0 || adr
[15:12] == 'hf
);
178 assign test_reg_stb
= cpu_stb_o
&& cpu_cyc_o
&& (adr
[15:8] == 8'hee
);
180 assign ack
= memory_ack | test_reg_ack
;
182 memory
u_memory(.
clk_i(clk_o
),
191 cpu6502_test_reg
test_reg(.
clk_i(clk_o
),
195 .
stb_i(test_reg_stb
),
197 .
ack_o(test_reg_ack
),
198 .
test_seq_o(test_seq
),
199 .
test_done_o(test_done
),
200 .
test_res_o(test_res
),
201 .
test_finish_o(test_finish
));
203 cpu6502
u_cpu(.
clk_i(clk_o
),
213 endmodule // cpu6502_tb