OpenCores
URL https://opencores.org/ocsvn/6809_6309_compatible_core/6809_6309_compatible_core/trunk

Subversion Repositories 6809_6309_compatible_core

[/] [6809_6309_compatible_core/] [trunk/] [sim/] [tb.v] - Blame information for rev 11

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ale500
/* MC6809/HD6309 Compatible core
2
 * (c) 2013 R.A. Paz Schmidt rapazschmidt@gmail.com
3
 *
4
 * Distributed under the terms of the Lesser GPL
5
 */
6 4 ale500
`timescale 1ns/1ns
7
 
8
module tb(output wire [15:0] addr_o, output wire [7:0] data_o_o);
9
 
10
reg clk, reset;
11
 
12
assign addr_o = addr;
13
assign data_o_o = data_o;
14
wire [15:0] addr;
15
wire [7:0] data_o, data_i;
16
wire oe, we;
17
always
18
        #5 clk = ~clk;
19
 
20
MC6809_cpu cpu(
21
        .cpu_clk(clk),
22
        .cpu_reset(reset),
23
        .cpu_we_o(we),
24
        .cpu_oe_o(oe),
25
        .cpu_addr_o(addr),
26
        .cpu_data_i(data_i),
27
        .cpu_data_o(data_o)
28
        );
29
 
30
memory imem(addr, !oe, !we, data_i, data_o);
31 2 ale500
 
32
initial
33
        begin
34 4 ale500
                $dumpvars;
35
                clk = 0;
36
                reset = 1;
37
                #0
38
                #46
39
                reset = 0;
40 7 ale500
                #7000
41 4 ale500
                $finish;
42
        end
43
 
44
endmodule
45
 
46 2 ale500
module memory(
47
        input wire [15:0] addr,
48
        input wire oe,
49
        input wire we,
50
        output wire [7:0] data_o,
51
        input wire [7:0] data_i
52
        );
53
 
54
reg [7:0] mem[65535:0];
55
reg [7:0] latecheddata;
56
wire [7:0] mem0, mem1, mem2, mem3;
57
 
58
assign mem0 = mem[0];
59
assign mem1 = mem[1];
60
assign mem2 = mem[2];
61
assign mem3 = mem[3];
62
 
63 4 ale500
assign data_o = latecheddata;
64
always @(negedge oe)
65 2 ale500
        latecheddata <= mem[addr];
66
 
67 4 ale500
always @(negedge we)
68
        begin
69 2 ale500
                mem[addr] <= data_i;
70
                $display("W %04x = %02x %t", addr, data_i, $time);
71
        end
72
 
73
always @(negedge oe)
74
        begin
75
                $display("R %04x = %02x %t", addr, mem[addr], $time);
76
        end
77 10 ale500
//`define READTESTBIN
78 2 ale500
integer i;
79
initial
80
        begin
81
`ifdef READTESTBIN
82
                $readmemh("instructions_test.hex", mem);
83
                $display("instructions_test.hex read");
84 10 ale500
                mem[16'hfffe] = 8'hf0; // setup reset
85 2 ale500
                mem[16'hffff] = 8'h00;
86
`else
87
                for (i = 0; i < 65536; i=i+1)
88
                        mem[i] = 8'ha5;
89 10 ale500
 
90
                mem[16'h1000] = 8'h8e; // ldx #$100
91
                mem[16'h1001] = 8'h01; // 
92
                mem[16'h1002] = 8'h00; // 
93
 
94 11 ale500
                mem[16'h1003] = 8'hbf; // stx $102              
95 10 ale500
                mem[16'h1004] = 8'h01; // 
96
                mem[16'h1005] = 8'h02; // 
97
 
98 11 ale500
                mem[16'h1006] = 8'h0f; // clr $10
99
                mem[16'h1007] = 8'h10; // 
100
 
101
                mem[16'h1008] = 8'h7f; // clr $1234
102
                mem[16'h1009] = 8'h12; // 
103
                mem[16'h100a] = 8'h34; // 
104 10 ale500
 
105 11 ale500
                mem[16'h100b] = 8'h0c; // inc $10
106
                mem[16'h100c] = 8'h10; // 
107
 
108
                mem[16'h100d] = 8'h7c; // inc $1234
109
                mem[16'h100e] = 8'h12; // 
110
                mem[16'h100f] = 8'h34; // 
111 10 ale500
 
112 11 ale500
                mem[16'h1010] = 8'h0a; // dec $10
113
                mem[16'h1011] = 8'h10; // 
114 2 ale500
 
115 11 ale500
                mem[16'h1012] = 8'h7a; // dec $1234
116
                mem[16'h1013] = 8'h12; // 
117
                mem[16'h1014] = 8'h34; // 
118
 
119
                mem[16'h1015] = 8'h20; // bra *
120
                mem[16'h1016] = 8'hfe; // 
121 2 ale500
 
122
 
123 11 ale500
 
124 2 ale500
/*
125
// test indexed store
126 4 ale500
                mem[16'h1000] = 8'h86; // lda #$02
127 2 ale500
                mem[16'h1001] = 8'h02; //
128
                mem[16'h1002] = 8'h9e; // ldx $00 (direct)
129
                mem[16'h1003] = 8'h00; //
130
 
131
                mem[16'h1004] = 8'ha7; // lda ,x
132
                mem[16'h1005] = 8'b10000100; // ofs0
133
                mem[16'h1006] = 8'ha7; // lda ,x+
134
                mem[16'h1007] = 8'b10000000; //
135
 
136
 
137
                mem[16'h1008] = 8'ha7; // lda ,x++
138
                mem[16'h1009] = 8'b10000001; //
139
                mem[16'h100a] = 8'ha6; // lda ,-x
140
                mem[16'h100b] = 8'b10000010; //
141
 
142
                mem[16'h100c] = 8'ha7; // lda ,--x
143
                mem[16'h100d] = 8'b10000011; //
144
 
145
                mem[16'h100e] = 8'ha7; // lda 0,x ofs 5
146
                mem[16'h100f] = 8'h00; //
147
 
148
                mem[16'h1010] = 8'ha7; // lda 0,x ofs 8
149
                mem[16'h1011] = 8'b10001000; //
150
                mem[16'h1012] = 8'h00; //
151
 
152
                mem[16'h1013] = 8'ha7; // lda 0,x ofs 16
153
                mem[16'h1014] = 8'b10001001; //
154
                mem[16'h1015] = 8'h00; //
155
                mem[16'h1016] = 8'h00; //
156
*/
157
 
158
/* test indexed load
159
                mem[16'h1000] = 8'h86; // lda #$02
160
                mem[16'h1001] = 8'h02; //
161
                mem[16'h1002] = 8'h9e; // ldx $00 (direct)
162
                mem[16'h1003] = 8'h00; //
163
 
164
                mem[16'h1004] = 8'ha6; // lda ,x
165
                mem[16'h1005] = 8'b10000100; // ofs0
166
                mem[16'h1006] = 8'ha6; // lda ,x+
167
                mem[16'h1007] = 8'b10000000; //
168
 
169
 
170
                mem[16'h1008] = 8'ha6; // lda ,x++
171
                mem[16'h1009] = 8'b10000001; //
172
                mem[16'h100a] = 8'ha6; // lda ,-x
173
                mem[16'h100b] = 8'b10000010; //
174
 
175
                mem[16'h100c] = 8'ha6; // lda ,--x
176
                mem[16'h100d] = 8'b10000011; //
177
 
178
                mem[16'h100e] = 8'ha6; // lda 0,x ofs 5
179
                mem[16'h100f] = 8'h00; //
180
 
181
                mem[16'h1010] = 8'ha6; // lda 0,x ofs 8
182
                mem[16'h1011] = 8'b10001000; //
183
                mem[16'h1012] = 8'h00; //
184
 
185
                mem[16'h1013] = 8'ha6; // lda 0,x ofs 16
186
                mem[16'h1014] = 8'b10001001; //
187
                mem[16'h1015] = 8'h00; //
188
                mem[16'h1016] = 8'h00; //
189
*/
190
 
191 10 ale500
/* test extended
192 4 ale500
                mem[16'h1000] = 8'h86; // ldb #$fe
193
                mem[16'h1001] = 8'h02; //
194
                mem[16'h1002] = 8'hc6; // lda #$0
195 2 ale500
                mem[16'h1003] = 8'h00; //
196
 
197 4 ale500
                mem[16'h1004] = 8'h97; // inca
198
                mem[16'h1005] = 8'h00; // sta $0000
199
                mem[16'h1006] = 8'hd7; //
200
                mem[16'h1007] = 8'h01; //
201 2 ale500
 
202
 
203
                mem[16'h1008] = 8'hb6; // lda $0000
204
                mem[16'h1009] = 8'h00; //
205
                mem[16'h100a] = 8'h00; //
206
 
207
                mem[16'h100b] = 8'h26; // bne$.-5
208
                mem[16'h100c] = 8'hf7; //
209
 
210
                mem[16'h100d] = 8'h5c; // incb
211
 
212
                mem[16'h100e] = 8'hf7; // stb $0001
213
                mem[16'h100f] = 8'h00; //
214
                mem[16'h1010] = 8'h01; //
215
 
216
                mem[16'h1011] = 8'h20; // bra
217
                mem[16'h1012] = 8'hec; // $.-18
218 10 ale500
*/
219 2 ale500
                mem[16'hfff0] = 8'h20; // reset
220
                mem[16'hfff1] = 8'h00;
221
                mem[16'hfff2] = 8'h20; // reset
222
                mem[16'hfff3] = 8'h02;
223
                mem[16'hfff4] = 8'h20; // reset
224
                mem[16'hfff5] = 8'h04;
225
                mem[16'hfff6] = 8'h20; // reset
226
                mem[16'hfff7] = 8'h06;
227
                mem[16'hfff8] = 8'h20; // reset
228
                mem[16'hfff9] = 8'h08;
229
                mem[16'hfffa] = 8'h20; // reset
230
                mem[16'hfffb] = 8'h0a;
231
                mem[16'hfffc] = 8'h20; // reset
232
                mem[16'hfffd] = 8'h0c;
233
                mem[16'hfffe] = 8'h10; // reset
234
                mem[16'hffff] = 8'h00;
235
`endif
236
        end
237
 
238
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.