1 |
67 |
creep |
////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// T6507LP IP Core ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This file is part of the T6507LP project ////
|
6 |
|
|
//// http://www.opencores.org/cores/t6507lp/ ////
|
7 |
|
|
//// ////
|
8 |
|
|
//// Description ////
|
9 |
98 |
creep |
//// 6507 FSM testbench ////
|
10 |
67 |
creep |
//// ////
|
11 |
|
|
//// Author(s): ////
|
12 |
|
|
//// - Gabriel Oshiro Zardo, gabrieloshiro@gmail.com ////
|
13 |
|
|
//// - Samuel Nascimento Pagliarini (creep), snpagliarini@gmail.com ////
|
14 |
|
|
//// ////
|
15 |
|
|
////////////////////////////////////////////////////////////////////////////
|
16 |
|
|
//// ////
|
17 |
|
|
//// Copyright (C) 2001 Authors and OPENCORES.ORG ////
|
18 |
|
|
//// ////
|
19 |
|
|
//// This source file may be used and distributed without ////
|
20 |
|
|
//// restriction provided that this copyright statement is not ////
|
21 |
|
|
//// removed from the file and that any derivative work contains ////
|
22 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
23 |
|
|
//// ////
|
24 |
|
|
//// This source file is free software; you can redistribute it ////
|
25 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
26 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
27 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
28 |
|
|
//// later version. ////
|
29 |
|
|
//// ////
|
30 |
|
|
//// This source is distributed in the hope that it will be ////
|
31 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
32 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
33 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
34 |
|
|
//// details. ////
|
35 |
|
|
//// ////
|
36 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
37 |
|
|
//// Public License along with this source; if not, download it ////
|
38 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
39 |
|
|
//// ////
|
40 |
|
|
////////////////////////////////////////////////////////////////////////////
|
41 |
|
|
|
42 |
112 |
creep |
`include "timescale.v"
|
43 |
67 |
creep |
|
44 |
|
|
module t6507lp_fsm_tb();
|
45 |
115 |
creep |
// mem_rw signals
|
46 |
|
|
localparam MEM_READ = 1'b0;
|
47 |
|
|
localparam MEM_WRITE = 1'b1;
|
48 |
|
|
|
49 |
117 |
creep |
reg clk; // regs are inputs
|
50 |
71 |
creep |
reg reset_n;
|
51 |
67 |
creep |
reg [7:0] alu_result;
|
52 |
|
|
reg [7:0] alu_status;
|
53 |
|
|
reg [7:0] data_in;
|
54 |
86 |
creep |
reg [7:0] alu_x;
|
55 |
|
|
reg [7:0] alu_y;
|
56 |
117 |
creep |
wire [12:0] address; // wires are outputs
|
57 |
115 |
creep |
wire mem_rw;
|
58 |
67 |
creep |
wire [7:0] data_out;
|
59 |
|
|
wire [7:0] alu_opcode;
|
60 |
|
|
wire [7:0] alu_a;
|
61 |
|
|
wire alu_enable;
|
62 |
|
|
|
63 |
111 |
creep |
integer my_i;
|
64 |
95 |
creep |
|
65 |
115 |
creep |
`include "T6507LP_Package.v"
|
66 |
67 |
creep |
|
67 |
117 |
creep |
t6507lp_fsm #(8,13) t6507lp_fsm(
|
68 |
116 |
creep |
.clk(clk),
|
69 |
|
|
.reset_n(reset_n),
|
70 |
|
|
.alu_result(alu_result),
|
71 |
|
|
.alu_status(alu_status),
|
72 |
|
|
.data_in(data_in),
|
73 |
117 |
creep |
.alu_x(alu_x),
|
74 |
|
|
.alu_y(alu_y),
|
75 |
116 |
creep |
.address(address),
|
76 |
|
|
.mem_rw(mem_rw),
|
77 |
|
|
.data_out(data_out),
|
78 |
|
|
.alu_opcode(alu_opcode),
|
79 |
|
|
.alu_a(alu_a),
|
80 |
117 |
creep |
.alu_enable(alu_enable)
|
81 |
116 |
creep |
);
|
82 |
67 |
creep |
|
83 |
71 |
creep |
always #10 clk = ~clk;
|
84 |
67 |
creep |
|
85 |
95 |
creep |
reg[7:0] fake_mem[2**13-1:0];
|
86 |
71 |
creep |
|
87 |
67 |
creep |
initial begin
|
88 |
117 |
creep |
clk = 1'b0;
|
89 |
71 |
creep |
reset_n = 1'b0;
|
90 |
|
|
alu_result = 8'h01;
|
91 |
94 |
creep |
alu_status = 8'h00;
|
92 |
86 |
creep |
alu_x = 8'h07;
|
93 |
|
|
alu_y = 8'h03;
|
94 |
95 |
creep |
|
95 |
111 |
creep |
for (my_i=0; my_i < 2**13; my_i= my_i+1) begin
|
96 |
|
|
$write("\n%d",my_i);
|
97 |
|
|
fake_mem[my_i]=8'h00;
|
98 |
95 |
creep |
end
|
99 |
67 |
creep |
|
100 |
71 |
creep |
fake_mem[0] = ASL_ACC; // testing ACC mode
|
101 |
|
|
fake_mem[1] = ADC_IMM; // testing IMM mode
|
102 |
|
|
fake_mem[2] = 8'h27;
|
103 |
|
|
fake_mem[3] = JMP_ABS; // testing ABS mode, JMP type
|
104 |
|
|
fake_mem[4] = 8'h09;
|
105 |
|
|
fake_mem[5] = 8'h00;
|
106 |
|
|
fake_mem[6] = ASL_ACC; // wont be executed
|
107 |
|
|
fake_mem[7] = ASL_ACC; // wont be executed
|
108 |
|
|
fake_mem[8] = ASL_ACC; // wont be executed
|
109 |
|
|
fake_mem[9] = ASL_ACC; // wont be executed
|
110 |
|
|
fake_mem[10] = LDA_ABS; // testing ABS mode, READ type. A = MEM[0002]. (a=27)
|
111 |
|
|
fake_mem[11] = 8'h02;
|
112 |
|
|
fake_mem[12] = 8'h00;
|
113 |
|
|
fake_mem[13] = ASL_ABS; // testing ABS mode, READ_MODIFY_WRITE type. should overwrite the first ASL_ACC
|
114 |
76 |
creep |
fake_mem[14] = 8'h00;
|
115 |
71 |
creep |
fake_mem[15] = 8'h00;
|
116 |
76 |
creep |
fake_mem[16] = STA_ABS; // testing ABS mode, WRITE type. should write alu_result on MEM[1]
|
117 |
|
|
fake_mem[17] = 8'h01;
|
118 |
|
|
fake_mem[18] = 8'h00;
|
119 |
|
|
fake_mem[19] = LDA_ZPG; // testing ZPG mode, READ type
|
120 |
|
|
fake_mem[20] = 8'h00;
|
121 |
78 |
creep |
fake_mem[21] = ASL_ZPG; // testing ZPG mode, READ_MODIFY_WRITE type
|
122 |
|
|
fake_mem[22] = 8'h00;
|
123 |
|
|
fake_mem[23] = STA_ZPG; // testing ZPG mode, WRITE type
|
124 |
|
|
fake_mem[24] = 8'h00;
|
125 |
86 |
creep |
fake_mem[25] = LDA_ZPX; // testing ZPX mode, READ type. A = MEM[x+1]
|
126 |
|
|
fake_mem[26] = 8'h01;
|
127 |
|
|
fake_mem[27] = ASL_ZPX; // testing ZPX mode, READ_MODIFY_WRITE type. MEM[x+1] = MEM[x+1] << 1;
|
128 |
|
|
fake_mem[28] = 8'h01;
|
129 |
|
|
fake_mem[29] = STA_ZPX; // testing ZPX mode, WRITE type. MEM[x+2] = A;
|
130 |
|
|
fake_mem[30] = 8'h02;
|
131 |
87 |
creep |
fake_mem[31] = LDA_ABX; // testing ABX mode, READ TYPE. No page crossed.
|
132 |
|
|
fake_mem[32] = 8'h0a;
|
133 |
|
|
fake_mem[33] = 8'h00;
|
134 |
88 |
creep |
fake_mem[34] = LDA_ABX; // testing ABX mode, READ TYPE. Page crossed.
|
135 |
|
|
fake_mem[35] = 8'hff;
|
136 |
|
|
fake_mem[36] = 8'h00;
|
137 |
89 |
creep |
fake_mem[37] = ASL_ABX; // testing ABX mode, READ_MODIFY_WRITE TYPE. No page crossed.
|
138 |
|
|
fake_mem[38] = 8'h01;
|
139 |
96 |
creep |
fake_mem[39] = 8'd35;
|
140 |
91 |
creep |
fake_mem[40] = ASL_ABX; // testing ABX mode, READ_MODIFY_WRITE TYPE. Page crossed.
|
141 |
|
|
fake_mem[41] = 8'hff;
|
142 |
|
|
fake_mem[42] = 8'h00;
|
143 |
92 |
creep |
fake_mem[40] = STA_ABX; // testing ABX mode, WRITE TYPE. No page crossed.
|
144 |
|
|
fake_mem[41] = 8'h04;
|
145 |
|
|
fake_mem[42] = 8'h00;
|
146 |
94 |
creep |
fake_mem[43] = STA_ABX; // testing ABX mode, WRITE TYPE. Page crossed.
|
147 |
|
|
fake_mem[44] = 8'hff;
|
148 |
|
|
fake_mem[45] = 8'h00;
|
149 |
|
|
fake_mem[46] = BNE_REL; // testing REL mode, taking a branch, no page crossed.
|
150 |
|
|
fake_mem[47] = 8'h0a;
|
151 |
|
|
fake_mem[58] = BNE_REL; // testing REL mode, taking a branch, page crossed.
|
152 |
|
|
fake_mem[59] = 8'hff;
|
153 |
101 |
creep |
fake_mem[60] = 8'hff;
|
154 |
96 |
creep |
fake_mem[254] = 8'hff;
|
155 |
110 |
creep |
fake_mem[256] = 8'h55; // PCL fetched from here when executing RTS_IMP
|
156 |
|
|
fake_mem[257] = 8'h01; // PCH fetched from here when executing RTS_IMP
|
157 |
107 |
creep |
fake_mem[264] = 8'd340;
|
158 |
94 |
creep |
fake_mem[315] = BEQ_REL; // testing REL mode, not taking a branch, page would have crossed.
|
159 |
|
|
fake_mem[316] = 8'hff;
|
160 |
|
|
fake_mem[317] = BEQ_REL; // testing REL mode, not taking a branch, page would not have crossed.
|
161 |
95 |
creep |
fake_mem[318] = 8'h00;
|
162 |
|
|
fake_mem[319] = LDA_IDX; // testing IDX mode READ TYPE, no page crossed;
|
163 |
|
|
fake_mem[320] = 8'h0a;
|
164 |
|
|
fake_mem[321] = LDA_IDX; // testing IDX mode READ TYPE, page crossed; this will actually do A = MEM[6] because there is no carry
|
165 |
|
|
fake_mem[322] = 8'hff;
|
166 |
|
|
//fake_mem[319] = SLO_IDX; // testing IDX mode READ_MODIFY_WRITE TYPE
|
167 |
|
|
//fake_mem[320] = 8'h0a; // all of read modify write instructions are not documented therefore will not be simulated
|
168 |
|
|
fake_mem[323] = STA_IDX; // testing IDX mode WRITE TYPE, page crossed being ignored
|
169 |
|
|
fake_mem[324] = 8'hff;
|
170 |
|
|
fake_mem[325] = STA_IDX; // testing IDX mode WRITE TYPE, page not crossed;
|
171 |
96 |
creep |
fake_mem[326] = 8'h00;
|
172 |
|
|
fake_mem[327] = LDA_IDY; // testing IDY mode READ TYPE, page not crossed;
|
173 |
|
|
fake_mem[328] = 8'h00;
|
174 |
|
|
fake_mem[329] = LDA_IDY; // testing IDY mode READ TYPE, page not crossed but pointer overflowed.
|
175 |
|
|
fake_mem[330] = 8'hff;
|
176 |
|
|
/* testing IDY mode READ TYPE, page crossed.
|
177 |
|
|
address may assume a invalid value when page is crossed but it is fixed on the next cycle when the true read occurs.
|
178 |
|
|
this is probably not an issue */
|
179 |
|
|
fake_mem[331] = LDA_IDY;
|
180 |
100 |
creep |
fake_mem[332] = 8'hfe;
|
181 |
101 |
creep |
fake_mem[333] = STA_IDY; // testing IDY mode WRITE TYPE, page crossed;
|
182 |
|
|
fake_mem[334] = 8'h00;
|
183 |
|
|
fake_mem[335] = STA_IDY; // testing IDY mode WRITE TYPE, page not crossed;
|
184 |
102 |
creep |
fake_mem[336] = 8'h0e;
|
185 |
|
|
fake_mem[337] = INX_IMP;
|
186 |
104 |
creep |
//fake_mem[338] = JMP_IND; // testing absolute indirect addressing. page crossed when updating pointer.
|
187 |
|
|
//fake_mem[339] = 8'hff;
|
188 |
|
|
//fake_mem[340] = 8'h00;
|
189 |
101 |
creep |
//fake_mem[337] = JMP_IND; // testing absolute indirect addressing. no page crossed when updating pointer.
|
190 |
104 |
creep |
//fake_mem[338] = 8'h3b; // these are commented cause they will actually jump
|
191 |
|
|
//fake_mem[339] = 8'h00;
|
192 |
110 |
creep |
//fake_mem[338] = BRK_IMP;
|
193 |
|
|
//fake_mem[339] = RTI_IMP;
|
194 |
|
|
//fake_mem[340] = RTS_IMP;
|
195 |
107 |
creep |
// 341 is skipped due to RTS internal functionality
|
196 |
110 |
creep |
//fake_mem[342] = PHA_IMP;
|
197 |
|
|
//fake_mem[343] = PHP_IMP;
|
198 |
|
|
//fake_mem[344] = PLA_IMP;
|
199 |
|
|
//fake_mem[345] = PLP_IMP;
|
200 |
|
|
fake_mem[338] = JSR_ABS;
|
201 |
|
|
fake_mem[339] = 8'h01;
|
202 |
|
|
fake_mem[340] = 8'h01;
|
203 |
|
|
|
204 |
100 |
creep |
|
205 |
|
|
|
206 |
104 |
creep |
fake_mem[8190] = 8'h53; // this is the reset vector
|
207 |
|
|
fake_mem[8191] = 8'h01;
|
208 |
71 |
creep |
@(negedge clk) // will wait for next negative edge of the clock (t=20)
|
209 |
|
|
reset_n=1'b1;
|
210 |
|
|
|
211 |
67 |
creep |
|
212 |
102 |
creep |
#4000;
|
213 |
67 |
creep |
$finish; // to shut down the simulation
|
214 |
|
|
end //initial
|
215 |
|
|
|
216 |
71 |
creep |
always @(clk) begin
|
217 |
115 |
creep |
if (mem_rw == MEM_READ) begin // MEM_READ
|
218 |
71 |
creep |
data_in <= fake_mem[address];
|
219 |
|
|
$write("\nreading from mem position %h: %h", address, fake_mem[address]);
|
220 |
|
|
end
|
221 |
115 |
creep |
else begin // MEM_WRITE
|
222 |
71 |
creep |
fake_mem[address] <= data_out;
|
223 |
|
|
$write("\nreading from mem position %h: %h", address, fake_mem[address]);
|
224 |
|
|
end
|
225 |
|
|
end
|
226 |
67 |
creep |
|
227 |
|
|
endmodule
|