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

Subversion Repositories t6507lp

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

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

powered by: WebSVN 2.1.0

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