| 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 |
|
|
//// 6507 FSM ////
|
| 10 |
|
|
//// ////
|
| 11 |
|
|
//// TODO: ////
|
| 12 |
|
|
//// - Perform simple tests before going into serious verification ////
|
| 13 |
|
|
//// ////
|
| 14 |
|
|
//// Author(s): ////
|
| 15 |
|
|
//// - Gabriel Oshiro Zardo, gabrieloshiro@gmail.com ////
|
| 16 |
|
|
//// - Samuel Nascimento Pagliarini (creep), snpagliarini@gmail.com ////
|
| 17 |
|
|
//// ////
|
| 18 |
|
|
////////////////////////////////////////////////////////////////////////////
|
| 19 |
|
|
//// ////
|
| 20 |
|
|
//// Copyright (C) 2001 Authors and OPENCORES.ORG ////
|
| 21 |
|
|
//// ////
|
| 22 |
|
|
//// This source file may be used and distributed without ////
|
| 23 |
|
|
//// restriction provided that this copyright statement is not ////
|
| 24 |
|
|
//// removed from the file and that any derivative work contains ////
|
| 25 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
| 26 |
|
|
//// ////
|
| 27 |
|
|
//// This source file is free software; you can redistribute it ////
|
| 28 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
| 29 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
| 30 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
| 31 |
|
|
//// later version. ////
|
| 32 |
|
|
//// ////
|
| 33 |
|
|
//// This source is distributed in the hope that it will be ////
|
| 34 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
| 35 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
| 36 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
| 37 |
|
|
//// details. ////
|
| 38 |
|
|
//// ////
|
| 39 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
| 40 |
|
|
//// Public License along with this source; if not, download it ////
|
| 41 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
| 42 |
|
|
//// ////
|
| 43 |
|
|
////////////////////////////////////////////////////////////////////////////
|
| 44 |
|
|
|
| 45 |
|
|
|
| 46 |
|
|
`timescale 1ns / 1ps
|
| 47 |
|
|
|
| 48 |
|
|
module t6507lp_fsm_tb();
|
| 49 |
71 |
creep |
reg clk;
|
| 50 |
|
|
reg reset_n;
|
| 51 |
67 |
creep |
reg [7:0] alu_result;
|
| 52 |
|
|
reg [7:0] alu_status;
|
| 53 |
|
|
reg [7:0] data_in;
|
| 54 |
|
|
|
| 55 |
86 |
creep |
reg [7:0] alu_x;
|
| 56 |
|
|
reg [7:0] alu_y;
|
| 57 |
|
|
|
| 58 |
67 |
creep |
wire [12:0] address;
|
| 59 |
|
|
wire control; // one bit is enough? read = 0, write = 1
|
| 60 |
|
|
wire [7:0] data_out;
|
| 61 |
|
|
wire [7:0] alu_opcode;
|
| 62 |
|
|
wire [7:0] alu_a;
|
| 63 |
|
|
wire alu_enable;
|
| 64 |
|
|
|
| 65 |
95 |
creep |
integer i;
|
| 66 |
|
|
|
| 67 |
67 |
creep |
`include "../T6507LP_Package.v"
|
| 68 |
|
|
|
| 69 |
86 |
creep |
t6507lp_fsm #(8,13) my_dut(clk, reset_n, alu_result, alu_status, data_in, address, control, data_out, alu_opcode, alu_a, alu_enable, alu_x, alu_y);
|
| 70 |
67 |
creep |
|
| 71 |
71 |
creep |
always #10 clk = ~clk;
|
| 72 |
67 |
creep |
|
| 73 |
95 |
creep |
reg[7:0] fake_mem[2**13-1:0];
|
| 74 |
71 |
creep |
|
| 75 |
67 |
creep |
initial begin
|
| 76 |
71 |
creep |
clk = 0;
|
| 77 |
|
|
reset_n = 1'b0;
|
| 78 |
|
|
alu_result = 8'h01;
|
| 79 |
94 |
creep |
alu_status = 8'h00;
|
| 80 |
86 |
creep |
alu_x = 8'h07;
|
| 81 |
|
|
alu_y = 8'h03;
|
| 82 |
95 |
creep |
|
| 83 |
|
|
for (i=0; i < 2**13; i= i+1) begin
|
| 84 |
|
|
$write("\n%d",i);
|
| 85 |
|
|
fake_mem[i]=8'h00;
|
| 86 |
|
|
end
|
| 87 |
67 |
creep |
|
| 88 |
95 |
creep |
|
| 89 |
71 |
creep |
fake_mem[0] = ASL_ACC; // testing ACC mode
|
| 90 |
|
|
fake_mem[1] = ADC_IMM; // testing IMM mode
|
| 91 |
|
|
fake_mem[2] = 8'h27;
|
| 92 |
|
|
fake_mem[3] = JMP_ABS; // testing ABS mode, JMP type
|
| 93 |
|
|
fake_mem[4] = 8'h09;
|
| 94 |
|
|
fake_mem[5] = 8'h00;
|
| 95 |
|
|
fake_mem[6] = ASL_ACC; // wont be executed
|
| 96 |
|
|
fake_mem[7] = ASL_ACC; // wont be executed
|
| 97 |
|
|
fake_mem[8] = ASL_ACC; // wont be executed
|
| 98 |
|
|
fake_mem[9] = ASL_ACC; // wont be executed
|
| 99 |
|
|
fake_mem[10] = LDA_ABS; // testing ABS mode, READ type. A = MEM[0002]. (a=27)
|
| 100 |
|
|
fake_mem[11] = 8'h02;
|
| 101 |
|
|
fake_mem[12] = 8'h00;
|
| 102 |
|
|
fake_mem[13] = ASL_ABS; // testing ABS mode, READ_MODIFY_WRITE type. should overwrite the first ASL_ACC
|
| 103 |
76 |
creep |
fake_mem[14] = 8'h00;
|
| 104 |
71 |
creep |
fake_mem[15] = 8'h00;
|
| 105 |
76 |
creep |
fake_mem[16] = STA_ABS; // testing ABS mode, WRITE type. should write alu_result on MEM[1]
|
| 106 |
|
|
fake_mem[17] = 8'h01;
|
| 107 |
|
|
fake_mem[18] = 8'h00;
|
| 108 |
|
|
fake_mem[19] = LDA_ZPG; // testing ZPG mode, READ type
|
| 109 |
|
|
fake_mem[20] = 8'h00;
|
| 110 |
78 |
creep |
fake_mem[21] = ASL_ZPG; // testing ZPG mode, READ_MODIFY_WRITE type
|
| 111 |
|
|
fake_mem[22] = 8'h00;
|
| 112 |
|
|
fake_mem[23] = STA_ZPG; // testing ZPG mode, WRITE type
|
| 113 |
|
|
fake_mem[24] = 8'h00;
|
| 114 |
86 |
creep |
fake_mem[25] = LDA_ZPX; // testing ZPX mode, READ type. A = MEM[x+1]
|
| 115 |
|
|
fake_mem[26] = 8'h01;
|
| 116 |
|
|
fake_mem[27] = ASL_ZPX; // testing ZPX mode, READ_MODIFY_WRITE type. MEM[x+1] = MEM[x+1] << 1;
|
| 117 |
|
|
fake_mem[28] = 8'h01;
|
| 118 |
|
|
fake_mem[29] = STA_ZPX; // testing ZPX mode, WRITE type. MEM[x+2] = A;
|
| 119 |
|
|
fake_mem[30] = 8'h02;
|
| 120 |
87 |
creep |
fake_mem[31] = LDA_ABX; // testing ABX mode, READ TYPE. No page crossed.
|
| 121 |
|
|
fake_mem[32] = 8'h0a;
|
| 122 |
|
|
fake_mem[33] = 8'h00;
|
| 123 |
88 |
creep |
fake_mem[34] = LDA_ABX; // testing ABX mode, READ TYPE. Page crossed.
|
| 124 |
|
|
fake_mem[35] = 8'hff;
|
| 125 |
|
|
fake_mem[36] = 8'h00;
|
| 126 |
89 |
creep |
fake_mem[37] = ASL_ABX; // testing ABX mode, READ_MODIFY_WRITE TYPE. No page crossed.
|
| 127 |
|
|
fake_mem[38] = 8'h01;
|
| 128 |
96 |
creep |
fake_mem[39] = 8'd35;
|
| 129 |
91 |
creep |
fake_mem[40] = ASL_ABX; // testing ABX mode, READ_MODIFY_WRITE TYPE. Page crossed.
|
| 130 |
|
|
fake_mem[41] = 8'hff;
|
| 131 |
|
|
fake_mem[42] = 8'h00;
|
| 132 |
92 |
creep |
fake_mem[40] = STA_ABX; // testing ABX mode, WRITE TYPE. No page crossed.
|
| 133 |
|
|
fake_mem[41] = 8'h04;
|
| 134 |
|
|
fake_mem[42] = 8'h00;
|
| 135 |
94 |
creep |
fake_mem[43] = STA_ABX; // testing ABX mode, WRITE TYPE. Page crossed.
|
| 136 |
|
|
fake_mem[44] = 8'hff;
|
| 137 |
|
|
fake_mem[45] = 8'h00;
|
| 138 |
|
|
fake_mem[46] = BNE_REL; // testing REL mode, taking a branch, no page crossed.
|
| 139 |
|
|
fake_mem[47] = 8'h0a;
|
| 140 |
|
|
fake_mem[58] = BNE_REL; // testing REL mode, taking a branch, page crossed.
|
| 141 |
|
|
fake_mem[59] = 8'hff;
|
| 142 |
96 |
creep |
fake_mem[254] = 8'hff;
|
| 143 |
|
|
fake_mem[255] = 8'h11;
|
| 144 |
94 |
creep |
fake_mem[315] = BEQ_REL; // testing REL mode, not taking a branch, page would have crossed.
|
| 145 |
|
|
fake_mem[316] = 8'hff;
|
| 146 |
|
|
fake_mem[317] = BEQ_REL; // testing REL mode, not taking a branch, page would not have crossed.
|
| 147 |
95 |
creep |
fake_mem[318] = 8'h00;
|
| 148 |
|
|
fake_mem[319] = LDA_IDX; // testing IDX mode READ TYPE, no page crossed;
|
| 149 |
|
|
fake_mem[320] = 8'h0a;
|
| 150 |
|
|
fake_mem[321] = LDA_IDX; // testing IDX mode READ TYPE, page crossed; this will actually do A = MEM[6] because there is no carry
|
| 151 |
|
|
fake_mem[322] = 8'hff;
|
| 152 |
|
|
//fake_mem[319] = SLO_IDX; // testing IDX mode READ_MODIFY_WRITE TYPE
|
| 153 |
|
|
//fake_mem[320] = 8'h0a; // all of read modify write instructions are not documented therefore will not be simulated
|
| 154 |
|
|
fake_mem[323] = STA_IDX; // testing IDX mode WRITE TYPE, page crossed being ignored
|
| 155 |
|
|
fake_mem[324] = 8'hff;
|
| 156 |
|
|
fake_mem[325] = STA_IDX; // testing IDX mode WRITE TYPE, page not crossed;
|
| 157 |
96 |
creep |
fake_mem[326] = 8'h00;
|
| 158 |
|
|
fake_mem[327] = LDA_IDY; // testing IDY mode READ TYPE, page not crossed;
|
| 159 |
|
|
fake_mem[328] = 8'h00;
|
| 160 |
|
|
fake_mem[329] = LDA_IDY; // testing IDY mode READ TYPE, page not crossed but pointer overflowed.
|
| 161 |
|
|
fake_mem[330] = 8'hff;
|
| 162 |
|
|
/* testing IDY mode READ TYPE, page crossed.
|
| 163 |
|
|
address may assume a invalid value when page is crossed but it is fixed on the next cycle when the true read occurs.
|
| 164 |
|
|
this is probably not an issue */
|
| 165 |
|
|
fake_mem[331] = LDA_IDY;
|
| 166 |
|
|
fake_mem[332] = 8'hfe;
|
| 167 |
|
|
// FALTOU O WRITE INDIRETO Y!
|
| 168 |
71 |
creep |
@(negedge clk) // will wait for next negative edge of the clock (t=20)
|
| 169 |
|
|
reset_n=1'b1;
|
| 170 |
|
|
|
| 171 |
67 |
creep |
|
| 172 |
95 |
creep |
#3000;
|
| 173 |
67 |
creep |
$finish; // to shut down the simulation
|
| 174 |
|
|
end //initial
|
| 175 |
|
|
|
| 176 |
71 |
creep |
always @(clk) begin
|
| 177 |
|
|
if (control == 0) begin // MEM_READ
|
| 178 |
|
|
data_in <= fake_mem[address];
|
| 179 |
|
|
$write("\nreading from mem position %h: %h", address, fake_mem[address]);
|
| 180 |
|
|
end
|
| 181 |
|
|
else if (control == 1'b1) begin // MEM_WRITE
|
| 182 |
|
|
fake_mem[address] <= data_out;
|
| 183 |
|
|
$write("\nreading from mem position %h: %h", address, fake_mem[address]);
|
| 184 |
|
|
end
|
| 185 |
|
|
end
|
| 186 |
67 |
creep |
|
| 187 |
|
|
endmodule
|