OpenCores
URL https://opencores.org/ocsvn/t6507lp/t6507lp/trunk

Subversion Repositories t6507lp

[/] [t6507lp/] [trunk/] [fv/] [fsm_chk.e] - Blame information for rev 212

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

Line No. Rev Author Line
1 206 creep
<'
2
import fsm_components;
3
type state_t : [RESET, CYCLE_1, CYCLE_2, CYCLE_3, CYCLE_4, CYCLE_5, CYCLE_6, CYCLE_7];
4
unit fsm_chk_u {
5
        !A  : byte;
6
          keep soft A == 0;
7
        !X  : byte;
8
          keep soft X == 0;
9
        !Y  : byte;
10
          keep soft Y == 0;
11
        !PC : uint(bits : 13);
12
          keep soft PC == 0;
13
//      !SP : uint(bits : 9);
14
//        keep soft SP == 9'b100000000;
15
        !SP : byte;
16
          keep soft SP == 0;
17
 
18 212 creep
        !more_cycles : bool;
19
          keep soft more_cycles == FALSE;
20 206 creep
        --!R  : byte;
21
        -- keep soft R == 0;
22
        --!PS : byte;
23
        --  keep soft PS[0:0] == 0;
24
        --  keep soft PS[1:1] == 0;
25
        --  keep soft PS[2:2] == 0;
26
        --  keep soft PS[3:3] == 0;
27
        --  keep soft PS[4:4] == 0;
28
        --  keep soft PS[5:5] == 1;
29
        --  keep soft PS[6:6] == 0;
30
        --  keep soft PS[7:7] == 0;
31
        -- N : bit;
32
        -- V : bit;
33
        -- B : bit;
34
        -- D : bit;
35
        -- I : bit;
36
        -- Z : bit;
37
        -- C : bit;
38
        -- keep soft N == 0;
39
        -- keep soft V == 0;
40
        -- keep soft B == 0;
41
        -- keep soft D == 0;
42
        -- keep soft I == 0;
43
        -- keep soft Z == 0;
44
        -- keep soft C == 0;
45
 
46
        !new_inst   : bool;
47
        keep new_inst == FALSE;
48
        !new_input : fsm_input_s;
49
        !old_input : fsm_input_s;
50
        --!new_inst  : bool;
51
        --keep soft new_inst == FALSE;
52
 
53
        --!i : ps_index;
54
 
55
        !new_state : state_t;
56
        !old_state : state_t;
57
 
58
        --count_cycles : int;
59
        --first_cycle  : bool;
60
        --last_a       : byte;
61
        --last_status  : byte;
62
        --last_result  : byte;
63
        !PCL:byte;
64
        !PCH:byte;
65
        !SP_aux:byte;
66
        !rst : bit;
67
        !rst_counter  : byte;
68
 
69
        --keep first_cycle  == TRUE;
70
        --keep count_cycles == 0;
71
        keep rst_counter  == 0;
72
 
73
        !instruction      : valid_opcodes;
74
        !last_instruction : valid_opcodes;
75
        !instructions     : valid_opcodes;
76
 
77
        print_state () is {
78
                outf("-------------------------------------------------------\n");
79
                print instructions;
80
                -- print instruction;
81
                print 't6507lp_fsm.ir';
82
                print 't6507lp_fsm.sp';
83
                print SP + 256;
84
                print 't6507lp_fsm.pc';
85
                print PC;
86
                --print addr;
87
                case ('t6507lp_fsm.state') {
88
 
89
                        2  : { outf("  t6507lp_fsm.state = FETCH_LOW\n");};
90
                        3  : { outf("  t6507lp_fsm.state = FETCH_HIGH\n"); };
91
                        4  : { outf("  t6507lp_fsm.state = READ_MEM\n"); };
92
                        5  : { outf("  t6507lp_fsm.state = DUMMY_WRT_CALC\n"); };
93
                        6  : { outf("  t6507lp_fsm.state = WRITE_MEM\n"); };
94
                        7  : { outf("  t6507lp_fsm.state = FETCH_OP_CALC_PARAM\n"); };
95
                        8  : { outf("  t6507lp_fsm.state = READ_MEM_CALC_INDEX\n"); };
96
                        9  : { outf("  t6507lp_fsm.state = FETCH_HIGH_CALC_INDEX\n"); };
97
                        10 : { outf("  t6507lp_fsm.state = READ_MEM_FIX_ADDR\n"); };
98
                        11 : { outf("  t6507lp_fsm.state = FETCH_OP_EVAL_BRANCH\n"); };
99
                        12 : { outf("  t6507lp_fsm.state = FETCH_OP_FIX_PC\n"); };
100
                        13 : { outf("  t6507lp_fsm.state = READ_FROM_POINTER\n"); };
101
                        14 : { outf("  t6507lp_fsm.state = READ_FROM_POINTER_X\n"); };
102
                        15 : { outf("  t6507lp_fsm.state = READ_FROM_POINTER_X1\n"); };
103
                        16 : { outf("  t6507lp_fsm.state = PUSH_PCH\n"); };
104
                        17 : { outf("  t6507lp_fsm.state = PUSH_PCL\n"); };
105
                        18 : { outf("  t6507lp_fsm.state = PUSH_STATUS\n"); };
106
                        19 : { outf("  t6507lp_fsm.state = FETCH_PCL\n"); };
107
                        20 : { outf("  t6507lp_fsm.state = FETCH_PCH\n"); };
108
                        21 : { outf("  t6507lp_fsm.state = INCREMENT_SP\n"); };
109
                        22 : { outf("  t6507lp_fsm.state = PULL_STATUS\n"); };
110
                        23 : { outf("  t6507lp_fsm.state = PULL_PCL\n"); };
111
                        24 : { outf("  t6507lp_fsm.state = PULL_PCH\n"); };
112
                        25 : { outf("  t6507lp_fsm.state = INCREMENT_PC\n"); };
113
                        26 : { outf("  t6507lp_fsm.state = PUSH_REGISTER\n"); };
114
                        27 : { outf("  t6507lp_fsm.state = PULL_REGISTER\n"); };
115
                        28 : { outf("  t6507lp_fsm.state = DUMMY\n"); };
116
                        31 : { outf("  t6507lp_fsm.state = RESET\n"); };
117
                };
118
        };
119
 
120
        store(input : fsm_input_s) is {
121
        --reset_n    : bit;
122
        --alu_result : byte;
123
        --alu_status : byte;
124
        --data_in    : byte;
125
        --alu_x      : byte;
126
        --alu_y      : byte;
127
        //print me;
128
        //print input;
129
                if (input.reset_n == 0) {
130
                  rst_counter = 0;
131
                  new_state = RESET;
132
                  old_state = RESET;
133
                  A = 0;
134
                  X = 0;
135
                  Y = 0;
136
                  PC = 0;
137
                  SP = 255;
138
                }
139
                else {
140
                        case (old_state) {
141
                                RESET    : {
142
                                        if (rst_counter == 7) {
143
                                                new_state = CYCLE_1;
144
                                        };
145
                                };
146
                                CYCLE_1 : {
147
                                        instruction = input.data_in.as_a(valid_opcodes);
148
                                        new_state = CYCLE_2;
149
                                };
150
                                CYCLE_2 : {
151 212 creep
                                        X = input.alu_x;
152
                                        Y = input.alu_y;
153
                                        print X, Y;
154
                                        outf("CYCLE_1\n");
155 206 creep
                                        case {
156
                                                (
157
                                                  instruction == BRK_IMP ||
158
                                                  instruction == PHA_IMP ||
159
                                                  instruction == PHP_IMP ||
160
                                                  instruction == PLA_IMP ||
161
                                                  instruction == PLP_IMP ||
162
                                                  instruction == RTI_IMP ||
163
                                                  instruction == RTS_IMP
164
                                                ) : {
165
                                                        new_state = CYCLE_3;
166
                                                };
167
                                                //JSR_ABS : {
168
                                                //      new_state = CYCLE_3;
169
                                                //      PCL = input.data_in;
170
                                                //};
171
                                                (
172
                                                  instruction == ADC_ABS ||
173
                                                  instruction == ASL_ABS ||
174
                                                  instruction == BIT_ABS ||
175
                                                  instruction == AND_ABS ||
176
                                                  instruction == CMP_ABS ||
177
                                                  instruction == DEC_ABS ||
178
                                                  instruction == EOR_ABS ||
179
                                                  instruction == INC_ABS ||
180
                                                  instruction == JMP_ABS ||
181
                                                  instruction == LDA_ABS ||
182
                                                  instruction == LDX_ABS ||
183
                                                  instruction == LDY_ABS ||
184
                                                  instruction == LSR_ABS ||
185
                                                  instruction == ORA_ABS ||
186
                                                  instruction == ROL_ABS ||
187
                                                  instruction == ROR_ABS ||
188
                                                  instruction == SBC_ABS ||
189
                                                  instruction == STA_ABS ||
190
                                                  instruction == STX_ABS ||
191
                                                  instruction == STY_ABS ||
192
                                                  instruction == LDA_ZPG ||
193
                                                  instruction == LDX_ZPG ||
194
                                                  instruction == LDY_ZPG ||
195
                                                  instruction == EOR_ZPG ||
196
                                                  instruction == AND_ZPG ||
197
                                                  instruction == ORA_ZPG ||
198
                                                  instruction == ADC_ZPG ||
199
                                                  instruction == SBC_ZPG ||
200
                                                  instruction == CMP_ZPG ||
201
                                                  instruction == BIT_ZPG ||
202
                                                  instruction == STA_ZPG ||
203
                                                  instruction == STX_ZPG ||
204
                                                  instruction == STY_ZPG ||
205
                                                  instruction == ASL_ZPG ||
206
                                                  instruction == LSR_ZPG ||
207
                                                  instruction == ROL_ZPG ||
208
                                                  instruction == ROR_ZPG ||
209
                                                  instruction == INC_ZPG ||
210 212 creep
                                                  instruction == DEC_ZPG ||
211 206 creep
                                                  instruction == LDA_ZPX ||
212
                                                  instruction == LDX_ZPY ||
213
                                                  instruction == LDY_ZPX ||
214
                                                  instruction == EOR_ZPX ||
215
                                                  instruction == AND_ZPX ||
216
                                                  instruction == ORA_ZPX ||
217
                                                  instruction == ADC_ZPX ||
218
                                                  instruction == SBC_ZPX ||
219 212 creep
                                                  instruction == CMP_ZPX ||
220
                                                  instruction == ASL_ZPX ||
221
                                                  instruction == LSR_ZPX ||
222
                                                  instruction == ROL_ZPX ||
223
                                                  instruction == ROR_ZPX ||
224
                                                  instruction == INC_ZPX ||
225
                                                  instruction == DEC_ZPX ||
226
                                                  instruction == STA_ZPX ||
227
                                                  instruction == STX_ZPY ||
228
                                                  instruction == STY_ZPX
229 206 creep
                                                ) : {
230
                                                        new_state = CYCLE_3;
231
                                                        PCL = input.data_in;
232 212 creep
                                                        --print X, Y;
233
                                                        --print input.alu_x, input.alu_y;
234
                                                        --print 't6507lp_fsm.index';
235 206 creep
                                                };
236
                                                (
237 212 creep
                                                  instruction == LDA_ABX ||
238
                                                  instruction == LDA_ABY ||
239
                                                  instruction == LDX_ABY ||
240
                                                  instruction == LDY_ABX ||
241
                                                  instruction == EOR_ABX ||
242
                                                  instruction == EOR_ABY ||
243
                                                  instruction == AND_ABX ||
244
                                                  instruction == AND_ABY ||
245
                                                  instruction == ORA_ABX ||
246
                                                  instruction == ORA_ABY ||
247
                                                  instruction == ADC_ABX ||
248
                                                  instruction == ADC_ABY ||
249
                                                  instruction == SBC_ABX ||
250
                                                  instruction == SBC_ABY ||
251
                                                  instruction == CMP_ABX ||
252
                                                  instruction == CMP_ABY
253
                                                ) : {
254
                                                        new_state = CYCLE_3;
255
                                                        PCL = input.data_in;
256
                                                        --X = input.alu_x;
257
                                                        --Y = input.alu_y;
258
                                                        --print X, Y;
259
                                                        --print input.alu_x, input.alu_y;
260
                                                        --print 't6507lp_fsm.index';
261
                                                        --outf("CYCLE_2\n");
262
                                                };
263
                                                (
264 206 creep
                                                  instruction == TXS_IMP
265
                                                ) : {
266
                                                        new_state = CYCLE_1;
267
                                                        SP_aux    = input.alu_x;
268
                                                };
269
                                                default : {
270
                                                        new_state = CYCLE_1;
271
                                                };
272
                                        };
273
                                };
274
                                CYCLE_3 : {
275
                                        case {
276
                                                (
277
                                                  instruction == BRK_IMP ||
278
                                                  instruction == PLA_IMP ||
279
                                                  instruction == PLP_IMP ||
280
                                                  instruction == RTI_IMP ||
281
                                                  instruction == RTS_IMP ||
282
                                                  instruction == ASL_ZPG ||
283
                                                  instruction == LSR_ZPG ||
284
                                                  instruction == ROL_ZPG ||
285
                                                  instruction == ROR_ZPG ||
286
                                                  instruction == INC_ZPG ||
287 212 creep
                                                  instruction == DEC_ZPG
288
                                                ) : {
289
                                                        new_state = CYCLE_4;
290
                                                };
291
                                                //JSR_ABS : {
292
                                                //      new_state = CYCLE_4;
293
                                                //      PCH = input.data_in;
294
                                                //};
295
                                                (
296 206 creep
                                                  instruction == LDA_ZPX ||
297
                                                  instruction == LDX_ZPY ||
298
                                                  instruction == LDY_ZPX ||
299
                                                  instruction == EOR_ZPX ||
300
                                                  instruction == AND_ZPX ||
301
                                                  instruction == ORA_ZPX ||
302
                                                  instruction == ADC_ZPX ||
303
                                                  instruction == SBC_ZPX ||
304 212 creep
                                                  instruction == CMP_ZPX ||
305
                                                  instruction == ASL_ZPX ||
306
                                                  instruction == LSR_ZPX ||
307
                                                  instruction == ROL_ZPX ||
308
                                                  instruction == ROR_ZPX ||
309
                                                  instruction == INC_ZPX ||
310
                                                  instruction == DEC_ZPX ||
311
                                                  instruction == STA_ZPX ||
312
                                                  instruction == STX_ZPY ||
313
                                                  instruction == STY_ZPX
314 206 creep
                                                ) : {
315
                                                        new_state = CYCLE_4;
316 212 creep
                                                        --X = input.alu_x;
317
                                                        --Y = input.alu_y;
318
                                                        --print X, Y;
319
                                                        --print input.alu_x, input.alu_y;
320
                                                        --print 't6507lp_fsm.index';
321 206 creep
                                                };
322
                                                (
323
                                                  instruction == ADC_ABS ||
324
                                                  instruction == ASL_ABS ||
325
                                                  instruction == BIT_ABS ||
326
                                                  instruction == AND_ABS ||
327
                                                  instruction == CMP_ABS ||
328
                                                  instruction == DEC_ABS ||
329
                                                  instruction == EOR_ABS ||
330
                                                  instruction == INC_ABS ||
331
                                                  instruction == LDA_ABS ||
332
                                                  instruction == LDX_ABS ||
333
                                                  instruction == LDY_ABS ||
334
                                                  instruction == LSR_ABS ||
335
                                                  instruction == ORA_ABS ||
336
                                                  instruction == ROL_ABS ||
337
                                                  instruction == ROR_ABS ||
338
                                                  instruction == SBC_ABS ||
339
                                                  instruction == STA_ABS ||
340
                                                  instruction == STX_ABS ||
341 212 creep
                                                  instruction == STY_ABS ||
342
                                                  instruction == LDA_ABX ||
343
                                                  instruction == LDA_ABY ||
344
                                                  instruction == LDX_ABY ||
345
                                                  instruction == LDY_ABX ||
346
                                                  instruction == EOR_ABX ||
347
                                                  instruction == EOR_ABY ||
348
                                                  instruction == AND_ABX ||
349
                                                  instruction == AND_ABY ||
350
                                                  instruction == ORA_ABX ||
351
                                                  instruction == ORA_ABY ||
352
                                                  instruction == ADC_ABX ||
353
                                                  instruction == ADC_ABY ||
354
                                                  instruction == SBC_ABX ||
355
                                                  instruction == SBC_ABY ||
356
                                                  instruction == CMP_ABX ||
357
                                                  instruction == CMP_ABY
358 206 creep
                                                ) : {
359
                                                        new_state = CYCLE_4;
360
                                                        PCH = input.data_in;
361 212 creep
                                                        --X = input.alu_x;
362
                                                        --Y = input.alu_y;
363
                                                        --print X, Y;
364
                                                        --print input.alu_x, input.alu_y;
365
                                                        --print 't6507lp_fsm.index';
366
                                                        --outf("CYCLE_3\n");
367 206 creep
                                                };
368
                                                (
369
                                                  instruction == JMP_ABS
370
                                                ) : {
371
                                                        new_state = CYCLE_1;
372
                                                        PCH = input.data_in;
373
                                                };
374
                                                default : {
375
                                                        new_state = CYCLE_1;
376
                                                };
377
                                        };
378
                                };
379
                                CYCLE_4 : {
380
                                        case {
381
                                                //JSR_ABS : {
382
                                                //      new_state = CYCLE_5;
383
                                                //};
384
                                                (
385
                                                  instruction == RTS_IMP
386
                                                ) : {
387
                                                        new_state = CYCLE_5;
388
                                                        PCL = input.data_in;
389
                                                };
390
                                                (
391
                                                  instruction == ASL_ABS ||
392
                                                  instruction == BRK_IMP ||
393
                                                  instruction == DEC_ABS ||
394
                                                  instruction == INC_ABS ||
395
                                                  instruction == LSR_ABS ||
396
                                                  instruction == ROL_ABS ||
397
                                                  instruction == ROR_ABS ||
398
                                                  instruction == RTI_IMP ||
399
                                                  instruction == ASL_ZPG ||
400
                                                  instruction == LSR_ZPG ||
401
                                                  instruction == ROL_ZPG ||
402
                                                  instruction == ROR_ZPG ||
403
                                                  instruction == INC_ZPG ||
404 212 creep
                                                  instruction == DEC_ZPG ||
405
                                                  instruction == ASL_ZPX ||
406
                                                  instruction == LSR_ZPX ||
407
                                                  instruction == ROL_ZPX ||
408
                                                  instruction == ROR_ZPX ||
409
                                                  instruction == INC_ZPX ||
410
                                                  instruction == DEC_ZPX ||
411
                                                  (
412
                                                        more_cycles == TRUE &&
413
                                                        (
414
                                                          instruction == LDA_ABX ||
415
                                                          instruction == LDA_ABY ||
416
                                                          instruction == LDX_ABY ||
417
                                                          instruction == LDY_ABX ||
418
                                                          instruction == EOR_ABX ||
419
                                                          instruction == EOR_ABY ||
420
                                                          instruction == AND_ABX ||
421
                                                          instruction == AND_ABY ||
422
                                                          instruction == ORA_ABX ||
423
                                                          instruction == ORA_ABY ||
424
                                                          instruction == ADC_ABX ||
425
                                                          instruction == ADC_ABY ||
426
                                                          instruction == SBC_ABX ||
427
                                                          instruction == SBC_ABY ||
428
                                                          instruction == CMP_ABX ||
429
                                                          instruction == CMP_ABY
430
                                                        )
431
                                                  )
432 206 creep
                                                ) : {
433 212 creep
                                                        --X = input.alu_x;
434
                                                        --Y = input.alu_y;
435
                                                        --print X, Y;
436
                                                        --print input.alu_x, input.alu_y;
437
                                                        --print 't6507lp_fsm.index';
438
                                                        --outf("CYCLE_4\n");
439 206 creep
                                                        new_state = CYCLE_5;
440
                                                };
441
                                                default : {
442
                                                        new_state = CYCLE_1;
443
                                                };
444
                                        };
445
                                };
446
                                CYCLE_5 : {
447
                                        case {
448
                                                //JSR_ABS : {
449
                                                //      new_state = CYCLE_6;
450
                                                //};
451
                                                (
452
                                                  instruction == RTI_IMP
453
                                                ) : {
454
                                                        new_state = CYCLE_6;
455
                                                        PCL = input.data_in;
456
                                                };
457
                                                (
458
                                                  instruction == RTS_IMP
459
                                                ) : {
460
                                                        new_state = CYCLE_6;
461
                                                        PCH = input.data_in;
462
                                                };
463
                                                (
464
                                                  instruction == ASL_ABS ||
465
                                                  instruction == BRK_IMP ||
466
                                                  instruction == DEC_ABS ||
467
                                                  instruction == INC_ABS ||
468
                                                  instruction == LSR_ABS ||
469
                                                  instruction == ROL_ABS ||
470 212 creep
                                                  instruction == ROR_ABS ||
471
                                                  instruction == ASL_ZPX ||
472
                                                  instruction == LSR_ZPX ||
473
                                                  instruction == ROL_ZPX ||
474
                                                  instruction == ROR_ZPX ||
475
                                                  instruction == INC_ZPX ||
476
                                                  instruction == DEC_ZPX
477 206 creep
                                                ) : {
478
                                                        new_state = CYCLE_6;
479
                                                };
480 212 creep
                                                (
481
                                                  instruction == LDA_ABX ||
482
                                                  instruction == LDA_ABY ||
483
                                                  instruction == LDX_ABY ||
484
                                                  instruction == LDY_ABX ||
485
                                                  instruction == EOR_ABX ||
486
                                                  instruction == EOR_ABY ||
487
                                                  instruction == AND_ABX ||
488
                                                  instruction == AND_ABY ||
489
                                                  instruction == ORA_ABX ||
490
                                                  instruction == ORA_ABY ||
491
                                                  instruction == ADC_ABX ||
492
                                                  instruction == ADC_ABY ||
493
                                                  instruction == SBC_ABX ||
494
                                                  instruction == SBC_ABY ||
495
                                                  instruction == CMP_ABX ||
496
                                                  instruction == CMP_ABY
497
                                                ) : {
498
                                                        new_state = CYCLE_1;
499
                                                        --X = input.alu_x;
500
                                                        --Y = input.alu_y;
501
                                                        --print X, Y;
502
                                                        --print input.alu_x, input.alu_y;
503
                                                        --print 't6507lp_fsm.index';
504
                                                        --outf("CYCLE_5\n");
505
                                                };
506
                                                --(
507
                                                --  instruction == LDA_ZPX ||
508
                                                --  instruction == LDX_ZPY ||
509
                                                --  instruction == LDY_ZPX ||
510
                                                --  instruction == EOR_ZPX ||
511
                                                --  instruction == AND_ZPX ||
512
                                                --  instruction == ORA_ZPX ||
513
                                                --  instruction == ADC_ZPX ||
514
                                                --  instruction == SBC_ZPX ||
515
                                                --  instruction == CMP_ZPX ||
516
                                                --  instruction == ASL_ZPX ||
517
                                                --  instruction == LSR_ZPX ||
518
                                                --  instruction == ROL_ZPX ||
519
                                                --  instruction == ROR_ZPX ||
520
                                                --  instruction == INC_ZPX ||
521
                                                --  instruction == DEC_ZPX ||
522
                                                --  instruction == STA_ZPX ||
523
                                                --  instruction == STX_ZPY ||
524
                                                --  instruction == STY_ZPX
525
                                                --) : {
526
                                                --      new_state = CYCLE_1;
527
                                                        --X = input.alu_x;
528
                                                        --Y = input.alu_y;
529
                                                        --print input.alu_x, input.alu_y;
530
 
531
                                                --};
532 206 creep
                                                default : {
533
                                                        new_state = CYCLE_1;
534
                                                };
535
                                        };
536
                                };
537
                                CYCLE_6 : {
538
                                        case {
539
                                                (
540
                                                  instruction == BRK_IMP
541
                                                ) : {
542
                                                        new_state = CYCLE_7;
543
                                                        PCL = input.data_in;
544
                                                };
545
                                                (
546
                                                  instructions == RTI_IMP
547
                                                ) : {
548
                                                        new_state = CYCLE_1;
549
                                                        PCH = input.data_in;
550
                                                };
551
                                                default : {
552
                                                        new_state = CYCLE_1;
553
                                                };
554
                                        };
555
                                };
556
                                CYCLE_7 : {
557
                                        //case (instruction) {
558
                                        //      BRK_IMP : {
559
                                        //              new_state = CYCLE_6;
560
                                        //      };
561
                                        //      default :
562
                                                new_state = CYCLE_1;
563
                                                PCH = input.data_in
564
                                        };
565
                        };
566
                        old_input = new_input;
567
                        new_input = input;
568
                };
569
        };
570
 
571
        compare(addr: uint(bits:13), mem_rw:bit, data_out:byte, alu_opcode:valid_opcodes, alu_a:byte, alu_enable:bit) is {
572
                case (old_state) {
573
                        RESET    : {
574
                                print_state();
575
                                rst = 1;
576
                                rst_counter = rst_counter + 1;
577
                        };
578
                        CYCLE_1 : {
579 212 creep
                                more_cycles = FALSE;
580 206 creep
                                print_state();
581
                                print addr;
582
                                last_instruction = instructions;
583
                                instructions = instruction;
584
                                //print instructions;
585
                                //print last_instruction;
586
                                if (mem_rw != 0) {
587
                                        dut_error("Mem_rw is Wrong!");
588
                                };
589
                                if (rst == 0) {
590
                                        case {
591
                                                (
592
                                                  last_instruction == ADC_ABS ||
593
                                                  last_instruction == ADC_IMM ||
594
                                                  last_instruction == AND_ABS ||
595
                                                  last_instruction == AND_IMM ||
596
                                                  last_instruction == BIT_ABS ||
597
                                                  last_instruction == CMP_ABS ||
598
                                                  last_instruction == CMP_IMM ||
599
                                                  last_instruction == CPX_IMM ||
600
                                                  last_instruction == CPY_IMM ||
601
                                                  last_instruction == EOR_ABS ||
602
                                                  last_instruction == EOR_IMM ||
603
                                                  last_instruction == LDA_ABS ||
604
                                                  last_instruction == LDA_IMM ||
605
                                                  last_instruction == LDX_ABS ||
606
                                                  last_instruction == LDX_IMM ||
607
                                                  last_instruction == LDY_ABS ||
608
                                                  last_instruction == LDY_IMM ||
609
                                                  last_instruction == ORA_ABS ||
610
                                                  last_instruction == ORA_IMM ||
611
                                                  last_instruction == PLA_IMP ||
612
                                                  last_instruction == PLP_IMP ||
613
                                                  last_instruction == SBC_ABS ||
614
                                                  last_instruction == SBC_IMM ||
615
                                                  last_instruction == LDA_ZPG ||
616
                                                  last_instruction == LDX_ZPG ||
617
                                                  last_instruction == LDY_ZPG ||
618
                                                  last_instruction == EOR_ZPG ||
619
                                                  last_instruction == AND_ZPG ||
620
                                                  last_instruction == ORA_ZPG ||
621
                                                  last_instruction == ADC_ZPG ||
622
                                                  last_instruction == SBC_ZPG ||
623
                                                  last_instruction == CMP_ZPG ||
624 212 creep
                                                  last_instruction == BIT_ZPG ||
625
                                                  last_instruction == LDA_ZPX ||
626
                                                  last_instruction == LDX_ZPY ||
627
                                                  last_instruction == LDY_ZPX ||
628
                                                  last_instruction == EOR_ZPX ||
629
                                                  last_instruction == AND_ZPX ||
630
                                                  last_instruction == ORA_ZPX ||
631
                                                  last_instruction == ADC_ZPX ||
632
                                                  last_instruction == SBC_ZPX ||
633
                                                  last_instruction == CMP_ZPX ||
634
                                                  last_instruction == LDA_ABX ||
635
                                                  last_instruction == LDA_ABY ||
636
                                                  last_instruction == LDX_ABY ||
637
                                                  last_instruction == LDY_ABX ||
638
                                                  last_instruction == EOR_ABX ||
639
                                                  last_instruction == EOR_ABY ||
640
                                                  last_instruction == AND_ABX ||
641
                                                  last_instruction == AND_ABY ||
642
                                                  last_instruction == ORA_ABX ||
643
                                                  last_instruction == ORA_ABY ||
644
                                                  last_instruction == ADC_ABX ||
645
                                                  last_instruction == ADC_ABY ||
646
                                                  last_instruction == SBC_ABX ||
647
                                                  last_instruction == SBC_ABY ||
648
                                                  last_instruction == CMP_ABX ||
649
                                                  last_instruction == CMP_ABY
650 206 creep
                                                ) : {
651
                                                        if (alu_opcode != last_instruction) {
652 212 creep
                                                                --print addr[7:0],X + PCL;
653 206 creep
                                                                dut_error("alu_opcode is Wrong!");
654
                                                        };
655
                                                        if (alu_enable != 1) {
656
                                                                dut_error("alu_enable is Wrong!");
657
                                                        };
658
                                                        if (addr != PC) {
659
                                                                dut_error("Address is Wrong!");
660
                                                        };
661
                                                };
662
                                                default : {
663
                                                        if (alu_opcode.as_a(byte) != 0) {
664 212 creep
                                                                --print alu_enable;
665
                                                                --print alu_opcode;
666
                                                                --print last_instruction;
667 206 creep
                                                                dut_error("alu_opcode is Wrong!");
668
                                                        };
669
                                                        if (alu_enable != 0) {
670
                                                                dut_error("alu_enable is Wrong!");
671
                                                        };
672
                                                        if (alu_a != 0) {
673
                                                                dut_error("alu_a is Wrong!");
674
                                                        };
675
                                                        if (addr != PC) {
676
                                                                dut_error("Address is Wrong!");
677
                                                        };
678
                                                };
679
                                        };
680
                                }
681
                                else {
682
                                        rst = 0;
683
                                        if (alu_enable != 0) {
684
                                                dut_error("alu_enable is Wrong!");
685
                                        };
686
                                        if (alu_opcode.as_a(byte) != 0) {
687
                                                dut_error("alu_opcode is Wrong!");
688
                                        };
689
                                        if (alu_a != 0) {
690
                                                dut_error("alu_a is Wrong!");
691
                                        };
692
                                        if (addr != PC) {
693
                                                dut_error("Address is Wrong!");
694
                                        };
695
                                };
696
                                PC = PC + 1;
697
                        };
698
                        CYCLE_2 : {
699
                                print_state();
700
                                print addr;
701
                                if (addr != PC) {
702
                                        dut_error("ADDR should be equal PC!");
703
                                };
704
                                if (mem_rw != 0) {
705
                                        dut_error("MEM_RW should be 0 (READ)");
706
                                };
707
                                case {
708
                                        (
709
                                          instructions == ADC_ABS ||
710
                                          instructions == ADC_IMM ||
711
                                          instructions == AND_ABS ||
712
                                          instructions == AND_IMM ||
713
                                          instructions == ASL_ABS ||
714
                                          instructions == BIT_ABS ||
715
                                          instructions == BRK_IMP ||
716
                                          instructions == CMP_ABS ||
717
                                          instructions == CMP_IMM ||
718
                                          instructions == CPX_IMM ||
719
                                          instructions == CPY_IMM ||
720
                                          instructions == DEC_ABS ||
721
                                          instructions == EOR_ABS ||
722
                                          instructions == EOR_IMM ||
723
                                          instructions == INC_ABS ||
724
                                          instructions == JMP_ABS ||
725
                                          instructions == LDA_ABS ||
726
                                          instructions == LDA_IMM ||
727
                                          instructions == LDX_ABS ||
728
                                          instructions == LDX_IMM ||
729
                                          instructions == LDY_ABS ||
730
                                          instructions == LDY_IMM ||
731
                                          instructions == LSR_ABS ||
732
                                          instructions == ORA_ABS ||
733
                                          instructions == ORA_IMM ||
734
                                          instructions == ROL_ABS ||
735
                                          instructions == ROR_ABS ||
736
                                          instructions == SBC_ABS ||
737
                                          instructions == SBC_IMM ||
738
                                          instructions == LDA_ZPG ||
739
                                          instructions == LDX_ZPG ||
740
                                          instructions == LDY_ZPG ||
741
                                          instructions == EOR_ZPG ||
742
                                          instructions == AND_ZPG ||
743
                                          instructions == ORA_ZPG ||
744
                                          instructions == ADC_ZPG ||
745
                                          instructions == SBC_ZPG ||
746
                                          instructions == CMP_ZPG ||
747
                                          instructions == BIT_ZPG ||
748
                                          instructions == ASL_ZPG ||
749
                                          instructions == LSR_ZPG ||
750
                                          instructions == ROL_ZPG ||
751
                                          instructions == ROR_ZPG ||
752
                                          instructions == INC_ZPG ||
753 212 creep
                                          instructions == DEC_ZPG ||
754
                                          instructions == LDA_ZPX ||
755
                                          instructions == LDX_ZPY ||
756
                                          instructions == LDY_ZPX ||
757
                                          instructions == EOR_ZPX ||
758
                                          instructions == AND_ZPX ||
759
                                          instructions == ORA_ZPX ||
760
                                          instructions == ADC_ZPX ||
761
                                          instructions == SBC_ZPX ||
762
                                          instructions == CMP_ZPX ||
763
                                          instructions == ASL_ZPX ||
764
                                          instructions == LSR_ZPX ||
765
                                          instructions == ROL_ZPX ||
766
                                          instructions == ROR_ZPX ||
767
                                          instructions == INC_ZPX ||
768
                                          instructions == DEC_ZPX ||
769
                                          instructions == STX_ZPY ||
770
                                          instructions == STY_ZPX ||
771
                                          instructions == STA_ZPX ||
772
                                          instructions == LDA_ABX ||
773
                                          instructions == LDA_ABY ||
774
                                          instructions == LDX_ABY ||
775
                                          instructions == LDY_ABX ||
776
                                          instructions == EOR_ABX ||
777
                                          instructions == EOR_ABY ||
778
                                          instructions == AND_ABX ||
779
                                          instructions == AND_ABY ||
780
                                          instructions == ORA_ABX ||
781
                                          instructions == ORA_ABY ||
782
                                          instructions == ADC_ABX ||
783
                                          instructions == ADC_ABY ||
784
                                          instructions == SBC_ABX ||
785
                                          instructions == SBC_ABY ||
786
                                          instructions == CMP_ABX ||
787
                                          instructions == CMP_ABY
788 206 creep
                                        ) : {
789
                                                if (alu_opcode.as_a(byte) != 0) {
790
                                                        dut_error("Opcode is Wrong!");
791
                                                };
792
                                                if (alu_enable != 0) {
793
                                                        dut_error("BRK_IMP is Wrong!");
794
                                                };
795
                                                PC = PC + 1;
796
                                        };
797 212 creep
                                        -- TODO: STX and STY should not
798
                                        -- TODO: they dont need access to alu at any cycle
799
                                        -- TODO: because X and Y are available at alu_x and alu_y
800 206 creep
                                        (
801
                                          instructions == STA_ABS ||
802 212 creep
                                          instructions == STA_ZPG ||
803
                                          instructions == STX_ABS ||
804 206 creep
                                          instructions == STY_ABS ||
805
                                          instructions == STX_ZPG ||
806 212 creep
                                          instructions == STY_ZPG
807 206 creep
                                        ) : {
808
                                                if (alu_opcode != instructions) {
809
                                                        dut_error("Opcode is Wrong!");
810
                                                };
811
                                                if (alu_enable != 1) {
812
                                                        dut_error("ASL_ACC is Wrong!");
813
                                                };
814
                                                PC = PC + 1;
815
                                        };
816
                                        (
817
                                          instructions == NOP_IMP ||
818
                                          instructions == PHP_IMP ||
819
                                          instructions == PLA_IMP ||
820
                                          instructions == PLP_IMP ||
821
                                          instructions == RTI_IMP ||
822
                                          instructions == RTS_IMP
823
 
824
                                        ) : {
825
                                                if (alu_opcode.as_a(byte) != 0) {
826
                                                        dut_error("Opcode is Wrong!");
827
                                                };
828
                                                if (alu_enable != 0) {
829
                                                        dut_error("ASL_ACC is Wrong!");
830
                                                };
831
                                        };
832
                                        (
833
                                          instructions == ASL_ACC ||
834
                                          instructions == CLC_IMP ||
835
                                          instructions == CLD_IMP ||
836
                                          instructions == CLI_IMP ||
837
                                          instructions == CLV_IMP ||
838
                                          instructions == DEX_IMP ||
839
                                          instructions == DEY_IMP ||
840
                                          instructions == INX_IMP ||
841
                                          instructions == INY_IMP ||
842
                                          instructions == LSR_ACC ||
843
                                          instructions == PHA_IMP ||
844
                                          instructions == ROL_ACC ||
845
                                          instructions == SEC_IMP ||
846
                                          instructions == SED_IMP ||
847
                                          instructions == SEI_IMP ||
848
                                          instructions == TAX_IMP ||
849
                                          instructions == TAY_IMP ||
850
                                          instructions == TXA_IMP ||
851
                                          instructions == TYA_IMP
852
                                        ) : {
853
                                                if (alu_opcode != instructions) {
854
                                                        dut_error("Opcode is Wrong!");
855
                                                };
856
                                                if (alu_enable != 1) {
857
                                                        dut_error("ASL_ACC is Wrong!");
858
                                                };
859
                                        };
860
                                        //JSR_ABS : {
861
                                        //      if (alu_opcode.as_a(byte) != 0) {
862
                                        //              dut_error("Opcode is Wrong!");
863
                                        //      };
864
                                        //      if (mem_rw != 0) {
865
                                        //              dut_error("MEM_RW should be 1 (WRITE)");
866
                                        //      };
867
                                        //      if (alu_enable != 0) {
868
                                        //              dut_error("JSR_IMP is Wrong!");
869
                                        //      };
870
                                        //      if (addr != PC) {
871
                                        //              dut_error("ADDR should be equal SP!");
872
                                        //      };
873
                                        //      PC = PC + 1;
874
                                        //};
875
                                        (
876
                                          instructions == TSX_IMP
877
                                        ) : {
878
                                                if (alu_opcode != instructions) {
879
                                                        dut_error("Opcode is Wrong!");
880
                                                };
881
                                                if (alu_enable != 1) {
882
                                                        dut_error("TSX_IMP is Wrong!");
883
                                                };
884
                                                if (alu_a != SP) {
885
                                                        dut_error("TSX_IMP is Wrong!");
886
                                                };
887
                                        };
888
                                        (
889
                                          instructions == TXS_IMP
890
                                        ) : {
891
                                                if (alu_opcode != instructions) {
892
                                                        dut_error("Opcode is Wrong!");
893
                                                };
894
                                                if (alu_enable != 1) {
895
                                                        dut_error("TXS_IMP is Wrong!");
896
                                                };
897
                                                SP = SP_aux;
898
                                        };
899
                                };
900
                        };
901
                        CYCLE_3 : {
902
                                print_state();
903
                                print addr;
904
                                case {
905
                                        (
906
                                          instructions == BRK_IMP
907
                                        ) : {
908
                                                if (alu_opcode.as_a(byte) != 0) {
909
                                                        dut_error("Opcode is Wrong!");
910
                                                };
911
                                                if (mem_rw != 1) {
912
                                                        dut_error("MEM_RW should be 1 (WRITE)");
913
                                                };
914
                                                if (alu_enable != 0) {
915
                                                        dut_error("BRK_IMP is Wrong!");
916
                                                };
917
                                                if (data_out[4:0] != PC[12:8] && data_out[7:5] != 0) {
918
                                                        dut_error("BRK_IMP is Wrong!");
919
                                                };
920
                                                if (addr != SP + 256) {
921
                                                        dut_error("ADDR should be equal SP!");
922
                                                };
923
                                                SP = SP - 1;
924
                                        };
925
                                        //JSR_ABS : {
926
                                        //      if (alu_opcode.as_a(byte) != 0) {
927
                                        //              dut_error("Opcode is Wrong!");
928
                                        //      };
929
                                        //      if (mem_rw != 0) {
930
                                        //              dut_error("MEM_RW should be 1 (WRITE)");
931
                                        //      };
932
                                        //      if (alu_enable != 0) {
933
                                        //              dut_error("JSR_IMP is Wrong!");
934
                                        //      };
935
                                        //      if (addr != PC) {
936
                                        //              dut_error("ADDR should be equal PC!");
937
                                        //      };
938
                                        //};
939 212 creep
                                        -- TODO: This is probably an error STA should not use ALU on the third cycle
940 206 creep
                                        (
941 212 creep
                                          instructions == STA_ZPX ||
942
                                          instructions == STX_ZPY ||
943
                                          instructions == STY_ZPX
944
                                        ) : {
945
                                                if (alu_opcode != instructions) {
946
                                                        dut_error("Opcode is Wrong!");
947
                                                };
948
                                                if (alu_enable != 1) {
949
                                                        dut_error("ASL_ACC is Wrong!");
950
                                                };
951
                                                if (mem_rw != 0) {
952
                                                        dut_error("MEM_RW should be 1 (WRITE)");
953
                                                };
954
                                                if (addr != PCL) {
955
                                                        dut_error("ADDR should be equal SP!");
956
                                                };
957
                                        };
958
                                        (
959 206 creep
                                          instructions == STA_ZPG ||
960
                                          instructions == STX_ZPG ||
961
                                          instructions == STY_ZPG
962
                                        ) : {
963
                                                if (alu_opcode.as_a(byte) != 0) {
964
                                                        dut_error("Opcode is Wrong!");
965
                                                };
966
                                                if (alu_enable != 0) {
967
                                                        dut_error("ASL_ACC is Wrong!");
968
                                                };
969
                                                if (mem_rw != 1) {
970
                                                        dut_error("MEM_RW should be 1 (WRITE)");
971
                                                };
972
                                                if (addr != PCL) {
973
                                                        dut_error("ADDR should be equal SP!");
974
                                                };
975
                                        };
976
                                        (
977
                                          instructions == JMP_ABS
978
                                        ) : {
979
                                                if (alu_opcode.as_a(byte) != 0) {
980
                                                        dut_error("Opcode is Wrong!");
981
                                                };
982
                                                if (alu_enable != 0) {
983
                                                        dut_error("ASL_ACC is Wrong!");
984
                                                };
985
                                                if (mem_rw != 0) {
986
                                                        dut_error("MEM_RW should be 1 (WRITE)");
987
                                                };
988
                                                PC[7:0] = PCL;
989
                                                PC[12:8] = PCH[4:0];
990
                                        };
991
                                        (
992
                                          instructions == LDA_ZPX ||
993
                                          instructions == LDX_ZPY ||
994
                                          instructions == LDY_ZPX ||
995
                                          instructions == EOR_ZPX ||
996
                                          instructions == AND_ZPX ||
997
                                          instructions == ORA_ZPX ||
998
                                          instructions == ADC_ZPX ||
999
                                          instructions == SBC_ZPX ||
1000 212 creep
                                          instructions == CMP_ZPX ||
1001
                                          instructions == ASL_ZPX ||
1002
                                          instructions == LSR_ZPX ||
1003
                                          instructions == ROL_ZPX ||
1004
                                          instructions == ROR_ZPX ||
1005
                                          instructions == INC_ZPX ||
1006
                                          instructions == DEC_ZPX
1007 206 creep
                                        ) : {
1008
                                                if (alu_opcode.as_a(byte) != 0) {
1009
                                                        dut_error("Opcode is Wrong!");
1010
                                                };
1011
                                                if (alu_enable != 0) {
1012
                                                        dut_error("ASL_ACC is Wrong!");
1013
                                                };
1014
                                                if (mem_rw != 0) {
1015
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1016
                                                };
1017
                                                if (addr != PCL) {
1018
                                                        dut_error("ADDR should be equal SP!");
1019
                                                };
1020
                                        };
1021
                                        (
1022
                                          instructions == ADC_ABS ||
1023
                                          instructions == AND_ABS ||
1024
                                          instructions == ASL_ABS ||
1025
                                          instructions == BIT_ABS ||
1026
                                          instructions == CMP_ABS ||
1027
                                          instructions == DEC_ABS ||
1028
                                          instructions == EOR_ABS ||
1029
                                          instructions == INC_ABS ||
1030
                                          instructions == LDA_ABS ||
1031
                                          instructions == LDX_ABS ||
1032
                                          instructions == LDY_ABS ||
1033
                                          instructions == LSR_ABS ||
1034
                                          instructions == ORA_ABS ||
1035
                                          instructions == ROL_ABS ||
1036
                                          instructions == ROR_ABS ||
1037
                                          instructions == SBC_ABS ||
1038
                                          instructions == STA_ABS ||
1039
                                          instructions == STX_ABS ||
1040 212 creep
                                          instructions == STY_ABS ||
1041
                                          instructions == LDA_ABX ||
1042
                                          instructions == LDY_ABX ||
1043
                                          instructions == EOR_ABX ||
1044
                                          instructions == AND_ABX ||
1045
                                          instructions == ORA_ABX ||
1046
                                          instructions == ADC_ABX ||
1047
                                          instructions == SBC_ABX ||
1048
                                          instructions == CMP_ABX
1049 206 creep
                                        ) : {
1050
                                                if (alu_opcode.as_a(byte) != 0) {
1051
                                                        dut_error("Opcode is Wrong!");
1052
                                                };
1053
                                                if (alu_enable != 0) {
1054
                                                        dut_error("ASL_ACC is Wrong!");
1055
                                                };
1056
                                                if (addr != PC) {
1057
                                                        dut_error("ADDR should be equal SP!");
1058
                                                };
1059
                                                if (mem_rw != 0) {
1060
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1061
                                                };
1062
                                                PC = PC + 1;
1063 212 creep
                                                if (PCL + X > 255) {
1064
                                                        more_cycles = TRUE;
1065
                                                };
1066 206 creep
                                        };
1067
                                        (
1068 212 creep
                                          instructions == LDA_ABY ||
1069
                                          instructions == LDX_ABY ||
1070
                                          instructions == AND_ABY ||
1071
                                          instructions == EOR_ABY ||
1072
                                          instructions == ORA_ABY ||
1073
                                          instructions == ADC_ABY ||
1074
                                          instructions == SBC_ABY ||
1075
                                          instructions == CMP_ABY
1076
                                        ) : {
1077
                                                if (alu_opcode.as_a(byte) != 0) {
1078
                                                        dut_error("Opcode is Wrong!");
1079
                                                };
1080
                                                if (alu_enable != 0) {
1081
                                                        dut_error("ASL_ACC is Wrong!");
1082
                                                };
1083
                                                if (addr != PC) {
1084
                                                        dut_error("ADDR should be equal SP!");
1085
                                                };
1086
                                                if (mem_rw != 0) {
1087
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1088
                                                };
1089
                                                PC = PC + 1;
1090
                                                if (PCL + Y > 255) {
1091
                                                        more_cycles = TRUE;
1092
                                                };
1093
                                        };
1094
                                        (
1095 206 creep
                                          instructions == LDA_ZPG ||
1096
                                          instructions == LDX_ZPG ||
1097
                                          instructions == LDY_ZPG ||
1098
                                          instructions == EOR_ZPG ||
1099
                                          instructions == AND_ZPG ||
1100
                                          instructions == ORA_ZPG ||
1101
                                          instructions == ADC_ZPG ||
1102
                                          instructions == SBC_ZPG ||
1103
                                          instructions == CMP_ZPG ||
1104
                                          instructions == BIT_ZPG ||
1105
                                          instructions == ASL_ZPG ||
1106
                                          instructions == LSR_ZPG ||
1107
                                          instructions == ROL_ZPG ||
1108
                                          instructions == ROR_ZPG ||
1109
                                          instructions == INC_ZPG ||
1110
                                          instructions == DEC_ZPG
1111
                                        ) : {
1112
                                                if (alu_opcode.as_a(byte) != 0) {
1113
                                                        dut_error("Opcode is Wrong!");
1114
                                                };
1115
                                                if (alu_enable != 0) {
1116
                                                        dut_error("ASL_ACC is Wrong!");
1117
                                                };
1118
                                                if (mem_rw != 0) {
1119
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1120
                                                };
1121
                                                if (addr != PCL) {
1122
                                                        dut_error("ADDR should be equal SP!");
1123
                                                };
1124
                                        };
1125
                                        (
1126
                                          instructions == PHA_IMP ||
1127
                                          instructions == PHP_IMP
1128
                                        ) : {
1129
                                                if (alu_opcode.as_a(byte) != 0) {
1130
                                                        dut_error("Opcode is Wrong!");
1131
                                                };
1132
                                                if (mem_rw != 1) {
1133
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1134
                                                };
1135
                                                if (alu_a != 0) {
1136
                                                        dut_error("PHP_IMP is Wrong!");
1137
                                                };
1138
                                                if (addr != SP + 256) {
1139
                                                        dut_error("ADDR should be equal SP!");
1140
                                                };
1141
                                                SP = SP - 1;
1142
                                                if (alu_enable != 0) {
1143
                                                        dut_error("PHP_IMP is Wrong!");
1144
                                                };
1145
                                        };
1146
                                        (
1147
                                          instructions == PLA_IMP ||
1148
                                          instructions == PLP_IMP ||
1149
                                          instructions == RTI_IMP ||
1150
                                          instructions == RTS_IMP
1151
                                        ) : {
1152
                                                if (alu_opcode.as_a(byte) != 0) {
1153
                                                        dut_error("Opcode is Wrong!");
1154
                                                };
1155
                                                if (alu_enable != 0) {
1156
                                                        dut_error("PLA_IMP is Wrong!");
1157
                                                };
1158
                                                if (mem_rw != 0) {
1159
                                                        dut_error("MEM_RW should be 0 (READ)");
1160
                                                };
1161
                                                if (addr != SP + 256) {
1162
                                                        dut_error("ADDR should be equal SP!");
1163
                                                };
1164
                                                SP = SP + 1;
1165
                                        };
1166
                                };
1167
                        };
1168
                        CYCLE_4 : {
1169
                                print_state();
1170
                                print addr;
1171
                                case {
1172
                                        (
1173
                                          instructions == BRK_IMP
1174
                                        ) : {
1175
                                                if (alu_opcode.as_a(byte) != 0) {
1176
                                                        dut_error("Opcode is Wrong!");
1177
                                                };
1178
                                                if (mem_rw != 1) {
1179
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1180
                                                };
1181
                                                if (alu_enable != 0) {
1182
                                                        dut_error("BRK_IMP is Wrong!");
1183
                                                };
1184
                                                if (data_out != PC[7:0]) {
1185
                                                        dut_error("BRK_IMP is Wrong!");
1186
                                                };
1187
                                                if (addr != SP + 256) {
1188
                                                        dut_error("ADDR should be equal SP!");
1189
                                                };
1190
                                                SP = SP - 1;
1191
                                        };
1192
                                        //JSR_ABS : {
1193
                                        //      if (alu_opcode.as_a(byte) != 0) {
1194
                                        //              dut_error("Opcode is Wrong!");
1195
                                        //      };
1196
                                        //      if (mem_rw != 1) {
1197
                                        //              dut_error("MEM_RW should be 1 (WRITE)");
1198
                                        //      };
1199
                                        //      if (alu_enable != 0) {
1200
                                        //              dut_error("JSR_ABS is Wrong!");
1201
                                        //      };
1202
                                        //      if (data_out != PC[7:0]) {
1203
                                        //              dut_error("JSR_ABS is Wrong!");
1204
                                        //      };
1205
                                        //      if (addr != SP + 256) {
1206
                                        //              dut_error("ADDR should be equal SP!");
1207
                                        //      };
1208
                                        //      SP = SP - 1;
1209
                                        //};
1210
                                        (
1211
                                          instructions == LDA_ZPX ||
1212
                                          instructions == LDY_ZPX ||
1213
                                          instructions == EOR_ZPX ||
1214
                                          instructions == AND_ZPX ||
1215
                                          instructions == ORA_ZPX ||
1216
                                          instructions == ADC_ZPX ||
1217
                                          instructions == SBC_ZPX ||
1218 212 creep
                                          instructions == CMP_ZPX ||
1219
                                          instructions == ASL_ZPX ||
1220
                                          instructions == LSR_ZPX ||
1221
                                          instructions == ROL_ZPX ||
1222
                                          instructions == ROR_ZPX ||
1223
                                          instructions == INC_ZPX ||
1224
                                          instructions == DEC_ZPX
1225 206 creep
                                        ) : {
1226
                                                if (alu_opcode.as_a(byte) != 0) {
1227
                                                        dut_error("Opcode is Wrong!");
1228
                                                };
1229
                                                if (alu_enable != 0) {
1230
                                                        dut_error("ASL_ACC is Wrong!");
1231
                                                };
1232
                                                if (mem_rw != 0) {
1233
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1234
                                                };
1235 212 creep
                                                --TODO: Isn`t it suppose to have ADDRH == 0????
1236 206 creep
                                                if (addr != PCL + X) {
1237 212 creep
                                                        print addr[7:0], PCL+X, PCL, X, 't6507lp_fsm.index';
1238 206 creep
                                                        dut_error("ADDR should be equal SP!");
1239
                                                };
1240
                                        };
1241
                                        (
1242 212 creep
                                          instructions == LDA_ABX ||
1243
                                          instructions == LDY_ABX ||
1244
                                          instructions == EOR_ABX ||
1245
                                          instructions == AND_ABX ||
1246
                                          instructions == ORA_ABX ||
1247
                                          instructions == ADC_ABX ||
1248
                                          instructions == SBC_ABX ||
1249
                                          instructions == CMP_ABX
1250 206 creep
                                        ) : {
1251
                                                if (alu_opcode.as_a(byte) != 0) {
1252
                                                        dut_error("Opcode is Wrong!");
1253
                                                };
1254
                                                if (alu_enable != 0) {
1255
                                                        dut_error("ASL_ACC is Wrong!");
1256
                                                };
1257
                                                if (mem_rw != 0) {
1258
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1259
                                                };
1260 212 creep
                                                if (PCL + X > 255) {
1261
                                                        more_cycles = TRUE;
1262
                                                        if (addr[7:0] != PCL + X - 256) {
1263
                                                                --print addr[7:0], PCL + X - 256;
1264
                                                                dut_error("ADDR should be equal SP!");
1265
                                                        };
1266
                                                }
1267
                                                else {
1268
                                                        if (addr[7:0] != PCL + X) {
1269
                                                                dut_error("ADDR should be equal SP!");
1270
                                                        };
1271 206 creep
                                                };
1272
                                        };
1273
                                        (
1274 212 creep
                                          instructions == LDX_ZPY ||
1275
                                          instructions == LDA_ABY ||
1276
                                          instructions == LDX_ABY ||
1277
                                          instructions == EOR_ABY ||
1278
                                          instructions == AND_ABY ||
1279
                                          instructions == ORA_ABY ||
1280
                                          instructions == ADC_ABY ||
1281
                                          instructions == SBC_ABY ||
1282
                                          instructions == CMP_ABY
1283
                                        ) : {
1284
                                                if (alu_opcode.as_a(byte) != 0) {
1285
                                                        dut_error("Opcode is Wrong!");
1286
                                                };
1287
                                                if (alu_enable != 0) {
1288
                                                        dut_error("ASL_ACC is Wrong!");
1289
                                                };
1290
                                                if (mem_rw != 0) {
1291
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1292
                                                };
1293
                                                if (PCL + Y > 255) {
1294
                                                        more_cycles = TRUE;
1295
                                                        if (addr[7:0] != PCL + Y - 256) {
1296
                                                                print addr[7:0], PCL + Y - 256;
1297
                                                                print PCL, Y;
1298
                                                                print 't6507lp_fsm.index';
1299
                                                                dut_error("ADDR should be equal SP!");
1300
                                                        };
1301
                                                }
1302
                                                else {
1303
                                                        if (addr[7:0] != PCL + Y) {
1304
                                                                dut_error("ADDR should be equal SP!");
1305
                                                        };
1306
                                                };
1307
                                        };
1308
                                        (
1309 206 creep
                                          instructions == ADC_ABS ||
1310
                                          instructions == AND_ABS ||
1311
                                          instructions == ASL_ABS ||
1312
                                          instructions == BIT_ABS ||
1313
                                          instructions == CMP_ABS ||
1314
                                          instructions == DEC_ABS ||
1315
                                          instructions == EOR_ABS ||
1316
                                          instructions == INC_ABS ||
1317
                                          instructions == LDA_ABS ||
1318
                                          instructions == LDX_ABS ||
1319
                                          instructions == LDY_ABS ||
1320
                                          instructions == LSR_ABS ||
1321
                                          instructions == ORA_ABS ||
1322
                                          instructions == ROL_ABS ||
1323
                                          instructions == ROR_ABS ||
1324
                                          instructions == SBC_ABS
1325
                                          ) : {
1326
                                                if (alu_opcode.as_a(byte) != 0) {
1327
                                                        dut_error("Opcode is Wrong!");
1328
                                                };
1329
                                                if (alu_enable != 0) {
1330
                                                        dut_error("ASL_ACC is Wrong!");
1331
                                                };
1332
                                                if (addr[7:0] != PCL) {
1333
                                                        dut_error("ADDR should be equal SP!");
1334
                                                };
1335
                                                if (addr[12:8] != PCH[4:0]) {
1336
                                                        dut_error("ADDR should be equal SP!");
1337
                                                };
1338
                                                if (mem_rw != 0) {
1339
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1340
                                                };
1341
                                        };
1342
                                        (
1343
                                          instructions == STA_ABS ||
1344
                                          instructions == STX_ABS ||
1345
                                          instructions == STY_ABS
1346
                                        ) : {
1347
                                                if (alu_opcode.as_a(byte) != 0) {
1348
                                                        dut_error("Opcode is Wrong!");
1349
                                                };
1350
                                                if (alu_enable != 0) {
1351
                                                        dut_error("ASL_ACC is Wrong!");
1352
                                                };
1353
                                                if (addr[7:0] != PCL) {
1354
                                                        dut_error("ADDR should be equal SP!");
1355
                                                };
1356
                                                if (addr[12:8] != PCH[4:0]) {
1357
                                                        dut_error("ADDR should be equal SP!");
1358
                                                };
1359
                                                if (mem_rw != 1) {
1360
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1361
                                                };
1362
                                        };
1363
                                        (
1364
                                          instructions == ASL_ZPG ||
1365
                                          instructions == LSR_ZPG ||
1366
                                          instructions == ROL_ZPG ||
1367
                                          instructions == ROR_ZPG ||
1368
                                          instructions == INC_ZPG ||
1369
                                          instructions == DEC_ZPG
1370
                                        ) : {
1371
                                                if (alu_opcode != instructions) {
1372
                                                        dut_error("Opcode is Wrong!");
1373
                                                };
1374
                                                if (mem_rw != 1) {
1375
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1376
                                                };
1377
                                                if (alu_enable != 1) {
1378
                                                        dut_error("BRK_IMP is Wrong!");
1379
                                                };
1380
                                                if (addr[7:0] != PCL) {
1381
                                                        dut_error("ADDR should be equal SP!");
1382
                                                };
1383
                                        };
1384
                                        (
1385 212 creep
                                          instructions == STA_ZPX ||
1386
                                          instructions == STY_ZPX
1387
                                        ) : {
1388
                                                if (alu_opcode.as_a(byte) != 0) {
1389
                                                        dut_error("Opcode is Wrong!");
1390
                                                };
1391
                                                if (alu_enable != 0) {
1392
                                                        dut_error("ASL_ACC is Wrong!");
1393
                                                };
1394
                                                if (mem_rw != 1) {
1395
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1396
                                                };
1397
                                                if (addr != PCL + X) {
1398
                                                        dut_error("ADDR should be equal SP!");
1399
                                                };
1400
                                        };
1401
                                        (
1402
                                          instructions == STX_ZPY
1403
                                        ) : {
1404
                                                if (alu_opcode.as_a(byte) != 0) {
1405
                                                        dut_error("Opcode is Wrong!");
1406
                                                };
1407
                                                if (alu_enable != 0) {
1408
                                                        dut_error("ASL_ACC is Wrong!");
1409
                                                };
1410
                                                if (mem_rw != 1) {
1411
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1412
                                                };
1413
                                                if (addr != PCL + Y) {
1414
                                                        dut_error("ADDR should be equal SP!");
1415
                                                };
1416
                                        };
1417
                                        (
1418 206 creep
                                          instructions == PLA_IMP ||
1419
                                          instructions == PLP_IMP
1420
                                        ) : {
1421
                                                if (alu_opcode.as_a(byte) != 0) {
1422
                                                        dut_error("Opcode is Wrong!");
1423
                                                };
1424
                                                if (mem_rw != 0) {
1425
                                                        dut_error("MEM_RW should be 0 (READ)");
1426
                                                };
1427
                                                if (alu_enable != 0) {
1428
                                                        dut_error("PLP_IMP is Wrong!");
1429
                                                };
1430
                                                if (addr != SP + 256) {
1431
                                                        dut_error("ADDR should be equal SP!");
1432
                                                };
1433
                                        };
1434
                                        (
1435
                                          instructions == RTI_IMP
1436
                                        ) : {
1437
                                                if (alu_opcode.as_a(byte) != 0) {
1438
                                                        dut_error("Opcode is Wrong!");
1439
                                                };
1440
                                                if (mem_rw != 0) {
1441
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1442
                                                };
1443
                                                if (alu_enable != 0) {
1444
                                                        dut_error("RTI_IMP is Wrong!");
1445
                                                };
1446
                                                if (addr != SP + 256) {
1447 212 creep
                                                        --print addr, SP;
1448 206 creep
                                                        dut_error("ADDR should be equal SP!");
1449
                                                };
1450
                                                SP = SP + 1;
1451
                                        };
1452
                                        (
1453
                                          instructions == RTS_IMP
1454
                                        ) : {
1455
                                                if (alu_opcode.as_a(byte) != 0) {
1456
                                                        dut_error("Opcode is Wrong!");
1457
                                                };
1458
                                                if (alu_enable != 0) {
1459
                                                        dut_error("RTS_IMP is Wrong!");
1460
                                                };
1461
                                                if (addr != SP + 256) {
1462
                                                        dut_error("ADDR should be equal SP!");
1463
                                                };
1464
                                                SP = SP + 1;
1465
                                                PC[7:0] = PCL;
1466
                                        };
1467
                                };
1468
                        };
1469
                        CYCLE_5 : {
1470
                                print_state();
1471
                                print addr;
1472
                                case {
1473
                                        (
1474
                                          instructions == BRK_IMP
1475
                                        ) : {
1476
                                                if (alu_opcode.as_a(byte) != 0) {
1477
                                                        dut_error("Opcode is Wrong!");
1478
                                                };
1479
                                                if (mem_rw != 1) {
1480
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1481
                                                };
1482
                                                if (alu_enable != 0) {
1483
                                                        dut_error("BRK_IMP is Wrong!");
1484
                                                };
1485
                                                if (addr != SP + 256) {
1486
                                                        dut_error("ADDR should be equal SP!");
1487
                                                };
1488
                                                SP = SP - 1;
1489
                                        };
1490
                                        //JSR_ABS : {
1491
                                        //      if (alu_opcode.as_a(byte) != 0) {
1492
                                        //              dut_error("Opcode is Wrong!");
1493
                                        //      };
1494
                                        //      if (mem_rw != 1) {
1495
                                        //              dut_error("MEM_RW should be 1 (WRITE)");
1496
                                        //      };
1497
                                        //      if (alu_enable != 0) {
1498
                                        //              dut_error("JSR_ABS is Wrong!");
1499
                                        //      };
1500
                                        //      if (data_out != PC[12:8]) {
1501
                                        //              dut_error("JSR_ABS is Wrong!");
1502
                                        //      };
1503
                                        //      if (addr != SP + 256) {
1504
                                        //              dut_error("ADDR should be equal SP!");
1505
                                        //      };
1506
                                        //      SP = SP - 1;
1507
                                        //};
1508
                                        (
1509
                                          instructions == RTI_IMP
1510
                                        ) : {
1511
                                                if (alu_opcode != instructions) {
1512
                                                        dut_error("Opcode is Wrong!");
1513
                                                };
1514
                                                if (mem_rw != 0) {
1515
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1516
                                                };
1517
                                                if (alu_enable != 1) {
1518
                                                        dut_error("RTI_IMP is Wrong!");
1519
                                                };
1520
                                                if (addr != SP + 256) {
1521
                                                        dut_error("ADDR should be equal SP!");
1522
                                                };
1523
                                                SP = SP + 1;
1524
                                                PC[7:0] = PCL;
1525
                                        };
1526
                                        (
1527
                                          instructions == RTS_IMP
1528
                                        ) : {
1529
                                                if (alu_opcode.as_a(byte) != 0) {
1530
                                                        dut_error("Opcode is Wrong!");
1531
                                                };
1532
                                                if (alu_enable != 0) {
1533
                                                        dut_error("SEI_IMP is Wrong!");
1534
                                                };
1535
                                                if (addr != SP + 256) {
1536
                                                        dut_error("ADDR should be equal SP!");
1537
                                                };
1538
                                                PC[12:8] = PCH[4:0];
1539
                                        };
1540
                                        (
1541
                                          instructions == ASL_ZPG ||
1542
                                          instructions == LSR_ZPG ||
1543
                                          instructions == ROL_ZPG ||
1544
                                          instructions == ROR_ZPG ||
1545
                                          instructions == INC_ZPG ||
1546
                                          instructions == DEC_ZPG
1547
                                        ) : {
1548
                                                if (alu_opcode.as_a(byte) != 0) {
1549
                                                        dut_error("Opcode is Wrong!");
1550
                                                };
1551
                                                if (mem_rw != 1) {
1552
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1553
                                                };
1554
                                                if (alu_enable != 0) {
1555
                                                        dut_error("BRK_IMP is Wrong!");
1556
                                                };
1557
                                                if (addr[7:0] != PCL) {
1558
                                                        dut_error("ADDR should be equal SP!");
1559
                                                };
1560
                                        };
1561
                                        (
1562 212 creep
                                          instructions == LDA_ABX ||
1563
                                          instructions == LDY_ABX ||
1564
                                          instructions == EOR_ABX ||
1565
                                          instructions == AND_ABX ||
1566
                                          instructions == ORA_ABX ||
1567
                                          instructions == ADC_ABX ||
1568
                                          instructions == SBC_ABX ||
1569
                                          instructions == CMP_ABX
1570
                                        ) : {
1571
                                                if (alu_opcode.as_a(byte) != 0) {
1572
                                                        dut_error("Opcode is Wrong!");
1573
                                                };
1574
                                                if (alu_enable != 0) {
1575
                                                        dut_error("ASL_ACC is Wrong!");
1576
                                                };
1577
                                                if (mem_rw != 0) {
1578
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1579
                                                };
1580
                                                if (addr[7:0] != PCL + X - 256) {
1581
                                                        dut_error("ADDR is wrong!");
1582
                                                };
1583
                                                if (addr[12:8] != PCH[4:0] + 1) {
1584
                                                        dut_error("ADDR is wrong!");
1585
                                                };
1586
                                        };
1587
                                        (
1588
                                          instructions == LDX_ZPY ||
1589
                                          instructions == LDA_ABY ||
1590
                                          instructions == LDX_ABY ||
1591
                                          instructions == EOR_ABY ||
1592
                                          instructions == AND_ABY ||
1593
                                          instructions == ORA_ABY ||
1594
                                          instructions == ADC_ABY ||
1595
                                          instructions == SBC_ABY ||
1596
                                          instructions == CMP_ABY
1597
                                        ) : {
1598
                                                if (alu_opcode.as_a(byte) != 0) {
1599
                                                        dut_error("Opcode is Wrong!");
1600
                                                };
1601
                                                if (alu_enable != 0) {
1602
                                                        dut_error("ASL_ACC is Wrong!");
1603
                                                };
1604
                                                if (mem_rw != 0) {
1605
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1606
                                                };
1607
                                                if (addr[7:0] != PCL + Y - 256) {
1608
                                                        dut_error("ADDR is wrong!");
1609
                                                };
1610
                                                if (addr[12:8] != PCH[4:0] + 1) {
1611
                                                        dut_error("ADDR is wrong!");
1612
                                                };
1613
                                        };
1614
                                        (
1615
                                          instructions == ASL_ZPX ||
1616
                                          instructions == LSR_ZPX ||
1617
                                          instructions == ROL_ZPX ||
1618
                                          instructions == ROR_ZPX ||
1619
                                          instructions == INC_ZPX ||
1620
                                          instructions == DEC_ZPX
1621
                                        ) : {
1622
                                                if (alu_opcode != instructions) {
1623
                                                        dut_error("Opcode is Wrong!");
1624
                                                };
1625
                                                if (alu_enable != 1) {
1626
                                                        dut_error("ASL_ACC is Wrong!");
1627
                                                };
1628
                                                if (mem_rw != 1) {
1629
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1630
                                                };
1631
                                                if (addr != PCL + X) {
1632
                                                        dut_error("ADDR should be equal SP!");
1633
                                                };
1634
                                        };
1635
                                        (
1636 206 creep
                                          instructions == ASL_ABS ||
1637
                                          instructions == DEC_ABS ||
1638
                                          instructions == INC_ABS ||
1639
                                          instructions == LSR_ABS ||
1640
                                          instructions == ROL_ABS ||
1641
                                          instructions == ROR_ABS
1642
                                        ) : {
1643
                                                if (alu_opcode != instructions) {
1644
                                                        dut_error("Opcode is Wrong!");
1645
                                                };
1646
                                                if (mem_rw != 1) {
1647
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1648
                                                };
1649
                                                if (alu_enable != 1) {
1650
                                                        dut_error("BRK_IMP is Wrong!");
1651
                                                };
1652
                                                if (addr[7:0] != PCL) {
1653
                                                        dut_error("ADDR should be equal SP!");
1654
                                                };
1655
                                                if (addr[12:8] != PCH[4:0]) {
1656
                                                        dut_error("ADDR should be equal SP!");
1657
                                                };
1658
                                        };
1659
                                };
1660
                        };
1661
                        CYCLE_6 : {
1662
                                print_state();
1663
                                print addr;
1664
                                case {
1665
                                        (
1666
                                          instructions == BRK_IMP
1667
                                        ) : {
1668
                                                if (alu_opcode.as_a(byte) != 0) {
1669
                                                        dut_error("Opcode is Wrong!");
1670
                                                };
1671
                                                if (mem_rw != 0) {
1672
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1673
                                                };
1674
                                                if (alu_enable != 0) {
1675
                                                        dut_error("BRK_IMP is Wrong!");
1676
                                                };
1677
                                                if (addr != 13'b1111111111110) {
1678
                                                        dut_error("BRK_IMP is Wrong!");
1679
                                                };
1680
                                                PC[7:0] = PCL;
1681
                                        };
1682
                                        //JSR_ABS : {
1683
                                        //      if (alu_opcode.as_a(byte) != 0) {
1684
                                        //              dut_error("Opcode is Wrong!");
1685
                                        //      };
1686
                                        //      if (mem_rw != 0) {
1687
                                        //              dut_error("MEM_RW should be 1 (WRITE)");
1688
                                        //      };
1689
                                        //      if (alu_enable != 0) {
1690
                                        //              dut_error("JSR_ABS is Wrong!");
1691
                                        //      };
1692
                                        //      if (addr != PC) {
1693
                                        //              dut_error("ADDR should be equal SP!");
1694
                                        //      };
1695
                                        //      PC [7:0] = PCL;
1696
                                        //      PC[12:8] = PCH[4:0];
1697
                                        //};
1698
                                        (
1699
                                          instructions == RTI_IMP
1700
                                        ) : {
1701
                                                if (alu_opcode.as_a(byte) != 0) {
1702
                                                        dut_error("Opcode is Wrong!");
1703
                                                };
1704
                                                if (mem_rw != 0) {
1705
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1706
                                                };
1707
                                                if (alu_enable != 0) {
1708
                                                        dut_error("RTI_IMP is Wrong!");
1709
                                                };
1710
                                                if (addr != SP + 256) {
1711
                                                        dut_error("ADDR should be equal SP!");
1712
                                                };
1713
                                                PC[12:8] = PCH[4:0];
1714
                                        };
1715
                                        (
1716
                                          instructions == RTS_IMP
1717
                                        ) : {
1718
                                                if (alu_opcode.as_a(byte) != 0) {
1719
                                                        dut_error("Opcode is Wrong!");
1720
                                                };
1721
                                                if (mem_rw != 0) {
1722
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1723
                                                };
1724
                                                if (alu_enable != 0) {
1725
                                                        dut_error("RTI_IMP is Wrong!");
1726
                                                };
1727
                                                if (addr != PC) {
1728
                                                        dut_error("ADDR should be equal SP!");
1729
                                                };
1730
                                                PC = PC + 1;
1731
                                        };
1732
                                        (
1733 212 creep
                                          instructions == ASL_ZPX ||
1734
                                          instructions == LSR_ZPX ||
1735
                                          instructions == ROL_ZPX ||
1736
                                          instructions == ROR_ZPX ||
1737
                                          instructions == INC_ZPX ||
1738
                                          instructions == DEC_ZPX
1739
                                        ) : {
1740
                                                if (alu_opcode.as_a(byte) != 0) {
1741
                                                        dut_error("Opcode is Wrong!");
1742
                                                };
1743
                                                if (alu_enable != 0) {
1744
                                                        dut_error("ASL_ACC is Wrong!");
1745
                                                };
1746
                                                if (mem_rw != 1) {
1747
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1748
                                                };
1749
                                                if (addr != PCL + X) {
1750
                                                        dut_error("ADDR should be equal SP!");
1751
                                                };
1752
                                        };
1753
                                        (
1754 206 creep
                                          instructions == ASL_ABS ||
1755
                                          instructions == DEC_ABS ||
1756
                                          instructions == INC_ABS ||
1757
                                          instructions == LSR_ABS ||
1758
                                          instructions == ROL_ABS ||
1759
                                          instructions == ROR_ABS
1760
                                        ) : {
1761
                                                if (alu_opcode.as_a(byte) != 0) {
1762
                                                        dut_error("Opcode is Wrong!");
1763
                                                };
1764
                                                if (mem_rw != 1) {
1765
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1766
                                                };
1767
                                                if (alu_enable != 0) {
1768
                                                        dut_error("BRK_IMP is Wrong!");
1769
                                                };
1770
                                                if (addr[7:0] != PCL) {
1771
                                                        dut_error("ADDR should be equal SP!");
1772
                                                };
1773
                                                if (addr[12:8] != PCH[4:0]) {
1774
                                                        dut_error("ADDR should be equal SP!");
1775
                                                };
1776
                                        };
1777
                                };
1778
                        };
1779
                        CYCLE_7 : {
1780
                                print_state();
1781
                                print addr;
1782
                                case {
1783
                                        (
1784
                                          instructions == BRK_IMP
1785
                                        ) : {
1786
                                                if (alu_opcode.as_a(byte) != 0) {
1787
                                                        dut_error("Opcode is Wrong!");
1788
                                                };
1789
                                                if (mem_rw != 0) {
1790
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1791
                                                };
1792
                                                if (alu_enable != 0) {
1793
                                                        dut_error("BRK_IMP is Wrong!");
1794
                                                };
1795
                                                if (addr != 13'b1111111111111) {
1796
                                                        dut_error("BRK_IMP is Wrong!");
1797
                                                };
1798
                                                PC[12:8] = PCH[4:0];
1799
                                        };
1800
                                };
1801
                        };
1802
                };
1803
        old_state = new_state;
1804
        };
1805
};
1806
'>

powered by: WebSVN 2.1.0

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