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

Subversion Repositories t6507lp

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

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

powered by: WebSVN 2.1.0

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