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 10

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
                mem[16'h1003] = 8'hbf; // stx #$102             
95
                mem[16'h1004] = 8'h01; // 
96
                mem[16'h1005] = 8'h02; // 
97
 
98
                mem[16'h1006] = 8'hbd; // jsr #$1010
99
                mem[16'h1007] = 8'h10; // 
100
                mem[16'h1008] = 8'h10; // 
101
 
102
                mem[16'h1009] = 8'h20; // bra *
103
                mem[16'h100a] = 8'hfe; // 
104
 
105
                mem[16'h100b] = 8'hc1; // 
106
                mem[16'h100c] = 8'h10; // 
107
                mem[16'h100d] = 8'h26; // 
108
                mem[16'h100e] = 8'hf7; // 
109
 
110
                mem[16'h100f] = 8'h4c; // 
111
 
112
                mem[16'h1010] = 8'h4f; // clra
113
                mem[16'h1011] = 8'h5f; // clrb
114
                mem[16'h1012] = 8'h39; // rts
115 2 ale500
 
116
 
117
 
118
/*
119
// test indexed store
120 4 ale500
                mem[16'h1000] = 8'h86; // lda #$02
121 2 ale500
                mem[16'h1001] = 8'h02; //
122
                mem[16'h1002] = 8'h9e; // ldx $00 (direct)
123
                mem[16'h1003] = 8'h00; //
124
 
125
                mem[16'h1004] = 8'ha7; // lda ,x
126
                mem[16'h1005] = 8'b10000100; // ofs0
127
                mem[16'h1006] = 8'ha7; // lda ,x+
128
                mem[16'h1007] = 8'b10000000; //
129
 
130
 
131
                mem[16'h1008] = 8'ha7; // lda ,x++
132
                mem[16'h1009] = 8'b10000001; //
133
                mem[16'h100a] = 8'ha6; // lda ,-x
134
                mem[16'h100b] = 8'b10000010; //
135
 
136
                mem[16'h100c] = 8'ha7; // lda ,--x
137
                mem[16'h100d] = 8'b10000011; //
138
 
139
                mem[16'h100e] = 8'ha7; // lda 0,x ofs 5
140
                mem[16'h100f] = 8'h00; //
141
 
142
                mem[16'h1010] = 8'ha7; // lda 0,x ofs 8
143
                mem[16'h1011] = 8'b10001000; //
144
                mem[16'h1012] = 8'h00; //
145
 
146
                mem[16'h1013] = 8'ha7; // lda 0,x ofs 16
147
                mem[16'h1014] = 8'b10001001; //
148
                mem[16'h1015] = 8'h00; //
149
                mem[16'h1016] = 8'h00; //
150
*/
151
 
152
/* test indexed load
153
                mem[16'h1000] = 8'h86; // lda #$02
154
                mem[16'h1001] = 8'h02; //
155
                mem[16'h1002] = 8'h9e; // ldx $00 (direct)
156
                mem[16'h1003] = 8'h00; //
157
 
158
                mem[16'h1004] = 8'ha6; // lda ,x
159
                mem[16'h1005] = 8'b10000100; // ofs0
160
                mem[16'h1006] = 8'ha6; // lda ,x+
161
                mem[16'h1007] = 8'b10000000; //
162
 
163
 
164
                mem[16'h1008] = 8'ha6; // lda ,x++
165
                mem[16'h1009] = 8'b10000001; //
166
                mem[16'h100a] = 8'ha6; // lda ,-x
167
                mem[16'h100b] = 8'b10000010; //
168
 
169
                mem[16'h100c] = 8'ha6; // lda ,--x
170
                mem[16'h100d] = 8'b10000011; //
171
 
172
                mem[16'h100e] = 8'ha6; // lda 0,x ofs 5
173
                mem[16'h100f] = 8'h00; //
174
 
175
                mem[16'h1010] = 8'ha6; // lda 0,x ofs 8
176
                mem[16'h1011] = 8'b10001000; //
177
                mem[16'h1012] = 8'h00; //
178
 
179
                mem[16'h1013] = 8'ha6; // lda 0,x ofs 16
180
                mem[16'h1014] = 8'b10001001; //
181
                mem[16'h1015] = 8'h00; //
182
                mem[16'h1016] = 8'h00; //
183
*/
184
 
185 10 ale500
/* test extended
186 4 ale500
                mem[16'h1000] = 8'h86; // ldb #$fe
187
                mem[16'h1001] = 8'h02; //
188
                mem[16'h1002] = 8'hc6; // lda #$0
189 2 ale500
                mem[16'h1003] = 8'h00; //
190
 
191 4 ale500
                mem[16'h1004] = 8'h97; // inca
192
                mem[16'h1005] = 8'h00; // sta $0000
193
                mem[16'h1006] = 8'hd7; //
194
                mem[16'h1007] = 8'h01; //
195 2 ale500
 
196
 
197
                mem[16'h1008] = 8'hb6; // lda $0000
198
                mem[16'h1009] = 8'h00; //
199
                mem[16'h100a] = 8'h00; //
200
 
201
                mem[16'h100b] = 8'h26; // bne$.-5
202
                mem[16'h100c] = 8'hf7; //
203
 
204
                mem[16'h100d] = 8'h5c; // incb
205
 
206
                mem[16'h100e] = 8'hf7; // stb $0001
207
                mem[16'h100f] = 8'h00; //
208
                mem[16'h1010] = 8'h01; //
209
 
210
                mem[16'h1011] = 8'h20; // bra
211
                mem[16'h1012] = 8'hec; // $.-18
212 10 ale500
*/
213 2 ale500
                mem[16'hfff0] = 8'h20; // reset
214
                mem[16'hfff1] = 8'h00;
215
                mem[16'hfff2] = 8'h20; // reset
216
                mem[16'hfff3] = 8'h02;
217
                mem[16'hfff4] = 8'h20; // reset
218
                mem[16'hfff5] = 8'h04;
219
                mem[16'hfff6] = 8'h20; // reset
220
                mem[16'hfff7] = 8'h06;
221
                mem[16'hfff8] = 8'h20; // reset
222
                mem[16'hfff9] = 8'h08;
223
                mem[16'hfffa] = 8'h20; // reset
224
                mem[16'hfffb] = 8'h0a;
225
                mem[16'hfffc] = 8'h20; // reset
226
                mem[16'hfffd] = 8'h0c;
227
                mem[16'hfffe] = 8'h10; // reset
228
                mem[16'hffff] = 8'h00;
229
`endif
230
        end
231
 
232
endmodule

powered by: WebSVN 2.1.0

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