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

Subversion Repositories t6507lp

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

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 241 creep
                                                instruction == JSR_ABS : {
170
                                                        new_state = CYCLE_3;
171
                                                        PCL = input.data_in;
172
                                                };
173 206 creep
                                                (
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 241 creep
                                                instruction == 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 241 creep
                                                instruction == JSR_ABS : {
426
                                                        new_state = CYCLE_5;
427
                                                };
428 206 creep
                                                (
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 241 creep
                                                instruction == JSR_ABS : {
522
                                                        new_state = CYCLE_6;
523
                                                };
524 206 creep
                                                (
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 241 creep
                                                  instruction == RTI_IMP
606 206 creep
                                                ) : {
607
                                                        new_state = CYCLE_1;
608
                                                        PCH = input.data_in;
609
                                                };
610 214 creep
                                                (
611 241 creep
                                                  instruction == JSR_ABS
612
                                                ) : {
613
                                                        new_state = CYCLE_1;
614
                                                        PCH = input.data_in;
615
                                                };
616
                                                (
617 214 creep
                                                  instruction == ASL_ABX ||
618
                                                  instruction == LSR_ABX ||
619
                                                  instruction == ROL_ABX ||
620
                                                  instruction == ROR_ABX ||
621
                                                  instruction == INC_ABX ||
622
                                                  instruction == DEC_ABX
623
                                                ) : {
624
                                                        new_state = CYCLE_7;
625
                                                };
626 206 creep
                                                default : {
627
                                                        new_state = CYCLE_1;
628
                                                };
629
                                        };
630
                                };
631
                                CYCLE_7 : {
632 214 creep
                                        case (instruction) {
633
                                                BRK_IMP : {
634
                                                        new_state = CYCLE_1;
635
                                                        PCH = input.data_in;
636
                                                };
637
                                                default : {
638
                                                        new_state = CYCLE_1;
639
                                                };
640 206 creep
                                        };
641 214 creep
                                };
642 206 creep
                        };
643
                        old_input = new_input;
644
                        new_input = input;
645
                };
646
        };
647
 
648
        compare(addr: uint(bits:13), mem_rw:bit, data_out:byte, alu_opcode:valid_opcodes, alu_a:byte, alu_enable:bit) is {
649
                case (old_state) {
650
                        RESET    : {
651
                                print_state();
652
                                rst = 1;
653
                                rst_counter = rst_counter + 1;
654
                        };
655
                        CYCLE_1 : {
656 212 creep
                                more_cycles = FALSE;
657 206 creep
                                print_state();
658
                                print addr;
659
                                last_instruction = instructions;
660
                                instructions = instruction;
661
                                if (mem_rw != 0) {
662
                                        dut_error("Mem_rw is Wrong!");
663
                                };
664
                                if (rst == 0) {
665
                                        case {
666
                                                (
667
                                                  last_instruction == ADC_ABS ||
668
                                                  last_instruction == ADC_IMM ||
669
                                                  last_instruction == AND_ABS ||
670
                                                  last_instruction == AND_IMM ||
671
                                                  last_instruction == BIT_ABS ||
672
                                                  last_instruction == CMP_ABS ||
673 216 creep
                                                  last_instruction == CPX_ABS ||
674
                                                  last_instruction == CPY_ABS ||
675 206 creep
                                                  last_instruction == CMP_IMM ||
676
                                                  last_instruction == CPX_IMM ||
677
                                                  last_instruction == CPY_IMM ||
678
                                                  last_instruction == EOR_ABS ||
679
                                                  last_instruction == EOR_IMM ||
680
                                                  last_instruction == LDA_ABS ||
681
                                                  last_instruction == LDA_IMM ||
682
                                                  last_instruction == LDX_ABS ||
683
                                                  last_instruction == LDX_IMM ||
684
                                                  last_instruction == LDY_ABS ||
685
                                                  last_instruction == LDY_IMM ||
686
                                                  last_instruction == ORA_ABS ||
687
                                                  last_instruction == ORA_IMM ||
688
                                                  last_instruction == PLA_IMP ||
689
                                                  last_instruction == PLP_IMP ||
690
                                                  last_instruction == SBC_ABS ||
691
                                                  last_instruction == SBC_IMM ||
692
                                                  last_instruction == LDA_ZPG ||
693
                                                  last_instruction == LDX_ZPG ||
694
                                                  last_instruction == LDY_ZPG ||
695
                                                  last_instruction == EOR_ZPG ||
696
                                                  last_instruction == AND_ZPG ||
697
                                                  last_instruction == ORA_ZPG ||
698
                                                  last_instruction == ADC_ZPG ||
699
                                                  last_instruction == SBC_ZPG ||
700
                                                  last_instruction == CMP_ZPG ||
701 216 creep
                                                  last_instruction == CPX_ZPG ||
702
                                                  last_instruction == CPY_ZPG ||
703 212 creep
                                                  last_instruction == BIT_ZPG ||
704
                                                  last_instruction == LDA_ZPX ||
705
                                                  last_instruction == LDX_ZPY ||
706
                                                  last_instruction == LDY_ZPX ||
707
                                                  last_instruction == EOR_ZPX ||
708
                                                  last_instruction == AND_ZPX ||
709
                                                  last_instruction == ORA_ZPX ||
710
                                                  last_instruction == ADC_ZPX ||
711
                                                  last_instruction == SBC_ZPX ||
712
                                                  last_instruction == CMP_ZPX ||
713
                                                  last_instruction == LDA_ABX ||
714
                                                  last_instruction == LDA_ABY ||
715
                                                  last_instruction == LDX_ABY ||
716
                                                  last_instruction == LDY_ABX ||
717
                                                  last_instruction == EOR_ABX ||
718
                                                  last_instruction == EOR_ABY ||
719
                                                  last_instruction == AND_ABX ||
720
                                                  last_instruction == AND_ABY ||
721
                                                  last_instruction == ORA_ABX ||
722
                                                  last_instruction == ORA_ABY ||
723
                                                  last_instruction == ADC_ABX ||
724
                                                  last_instruction == ADC_ABY ||
725
                                                  last_instruction == SBC_ABX ||
726
                                                  last_instruction == SBC_ABY ||
727
                                                  last_instruction == CMP_ABX ||
728 214 creep
                                                  last_instruction == CMP_ABY ||
729
                                                  last_instruction == LDA_IDX ||
730
                                                  last_instruction == ORA_IDX ||
731
                                                  last_instruction == EOR_IDX ||
732
                                                  last_instruction == AND_IDX ||
733
                                                  last_instruction == ADC_IDX ||
734
                                                  last_instruction == CMP_IDX ||
735 215 creep
                                                  last_instruction == SBC_IDX ||
736
                                                  last_instruction == LDA_IDY ||
737
                                                  last_instruction == ORA_IDY ||
738
                                                  last_instruction == EOR_IDY ||
739
                                                  last_instruction == AND_IDY ||
740
                                                  last_instruction == ADC_IDY ||
741
                                                  last_instruction == CMP_IDY ||
742
                                                  last_instruction == SBC_IDY
743 206 creep
                                                ) : {
744
                                                        if (alu_opcode != last_instruction) {
745
                                                                dut_error("alu_opcode is Wrong!");
746
                                                        };
747
                                                        if (alu_enable != 1) {
748
                                                                dut_error("alu_enable is Wrong!");
749
                                                        };
750
                                                        if (addr != PC) {
751
                                                                dut_error("Address is Wrong!");
752
                                                        };
753
                                                };
754 214 creep
                                                --(
755
                                                --) : {
756
                                                --      if (alu_opcode != last_instruction) {
757
                                                --              dut_error("alu_opcode is Wrong!");
758
                                                --      };
759
                                                --      if (alu_enable != 1) {
760
                                                --              dut_error("alu_enable is Wrong!");
761
                                                --      };
762
                                                --      if (addr[7:0] != PCL) {
763
                                                --              dut_error("Address is Wrong!");
764
                                                --      };
765
                                                --      if (addr[12:8] != PCH[4:0]) {
766
                                                --              dut_error("Address is Wrong!");
767
                                                --      };
768
                                                --};
769 206 creep
                                                default : {
770
                                                        if (alu_opcode.as_a(byte) != 0) {
771
                                                                dut_error("alu_opcode is Wrong!");
772
                                                        };
773
                                                        if (alu_enable != 0) {
774
                                                                dut_error("alu_enable is Wrong!");
775
                                                        };
776
                                                        if (alu_a != 0) {
777
                                                                dut_error("alu_a is Wrong!");
778
                                                        };
779
                                                        if (addr != PC) {
780
                                                                dut_error("Address is Wrong!");
781
                                                        };
782
                                                };
783
                                        };
784
                                }
785
                                else {
786
                                        rst = 0;
787
                                        if (alu_enable != 0) {
788
                                                dut_error("alu_enable is Wrong!");
789
                                        };
790
                                        if (alu_opcode.as_a(byte) != 0) {
791
                                                dut_error("alu_opcode is Wrong!");
792
                                        };
793
                                        if (alu_a != 0) {
794
                                                dut_error("alu_a is Wrong!");
795
                                        };
796
                                        if (addr != PC) {
797
                                                dut_error("Address is Wrong!");
798
                                        };
799
                                };
800
                                PC = PC + 1;
801
                        };
802
                        CYCLE_2 : {
803
                                print_state();
804
                                print addr;
805
                                if (addr != PC) {
806
                                        dut_error("ADDR should be equal PC!");
807
                                };
808
                                if (mem_rw != 0) {
809
                                        dut_error("MEM_RW should be 0 (READ)");
810
                                };
811
                                case {
812
                                        (
813
                                          instructions == ADC_ABS ||
814
                                          instructions == ADC_IMM ||
815
                                          instructions == AND_ABS ||
816
                                          instructions == AND_IMM ||
817
                                          instructions == ASL_ABS ||
818
                                          instructions == BIT_ABS ||
819
                                          instructions == BRK_IMP ||
820
                                          instructions == CMP_ABS ||
821 216 creep
                                          instructions == CPX_ABS ||
822
                                          instructions == CPY_ABS ||
823 206 creep
                                          instructions == CMP_IMM ||
824
                                          instructions == CPX_IMM ||
825
                                          instructions == CPY_IMM ||
826
                                          instructions == DEC_ABS ||
827
                                          instructions == EOR_ABS ||
828
                                          instructions == EOR_IMM ||
829
                                          instructions == INC_ABS ||
830
                                          instructions == JMP_ABS ||
831
                                          instructions == LDA_ABS ||
832
                                          instructions == LDA_IMM ||
833
                                          instructions == LDX_ABS ||
834
                                          instructions == LDX_IMM ||
835
                                          instructions == LDY_ABS ||
836
                                          instructions == LDY_IMM ||
837
                                          instructions == LSR_ABS ||
838
                                          instructions == ORA_ABS ||
839
                                          instructions == ORA_IMM ||
840
                                          instructions == ROL_ABS ||
841
                                          instructions == ROR_ABS ||
842
                                          instructions == SBC_ABS ||
843
                                          instructions == SBC_IMM ||
844
                                          instructions == LDA_ZPG ||
845
                                          instructions == LDX_ZPG ||
846
                                          instructions == LDY_ZPG ||
847
                                          instructions == EOR_ZPG ||
848
                                          instructions == AND_ZPG ||
849
                                          instructions == ORA_ZPG ||
850
                                          instructions == ADC_ZPG ||
851
                                          instructions == SBC_ZPG ||
852
                                          instructions == CMP_ZPG ||
853 216 creep
                                          instructions == CPX_ZPG ||
854
                                          instructions == CPY_ZPG ||
855 206 creep
                                          instructions == BIT_ZPG ||
856
                                          instructions == ASL_ZPG ||
857
                                          instructions == LSR_ZPG ||
858
                                          instructions == ROL_ZPG ||
859
                                          instructions == ROR_ZPG ||
860
                                          instructions == INC_ZPG ||
861 212 creep
                                          instructions == DEC_ZPG ||
862
                                          instructions == LDA_ZPX ||
863
                                          instructions == LDX_ZPY ||
864
                                          instructions == LDY_ZPX ||
865
                                          instructions == EOR_ZPX ||
866
                                          instructions == AND_ZPX ||
867
                                          instructions == ORA_ZPX ||
868
                                          instructions == ADC_ZPX ||
869
                                          instructions == SBC_ZPX ||
870
                                          instructions == CMP_ZPX ||
871
                                          instructions == ASL_ZPX ||
872
                                          instructions == LSR_ZPX ||
873
                                          instructions == ROL_ZPX ||
874
                                          instructions == ROR_ZPX ||
875
                                          instructions == INC_ZPX ||
876
                                          instructions == DEC_ZPX ||
877
                                          instructions == STX_ZPY ||
878
                                          instructions == STY_ZPX ||
879
                                          instructions == STA_ZPX ||
880
                                          instructions == LDA_ABX ||
881
                                          instructions == LDA_ABY ||
882 216 creep
                                          instructions == STA_ABX ||
883
                                          instructions == STA_ABY ||
884 212 creep
                                          instructions == LDX_ABY ||
885
                                          instructions == LDY_ABX ||
886
                                          instructions == EOR_ABX ||
887
                                          instructions == EOR_ABY ||
888
                                          instructions == AND_ABX ||
889
                                          instructions == AND_ABY ||
890
                                          instructions == ORA_ABX ||
891
                                          instructions == ORA_ABY ||
892
                                          instructions == ADC_ABX ||
893
                                          instructions == ADC_ABY ||
894
                                          instructions == SBC_ABX ||
895
                                          instructions == SBC_ABY ||
896
                                          instructions == CMP_ABX ||
897 214 creep
                                          instructions == CMP_ABY ||
898
                                          instructions == ASL_ABX ||
899
                                          instructions == LSR_ABX ||
900
                                          instructions == ROL_ABX ||
901
                                          instructions == ROR_ABX ||
902
                                          instructions == INC_ABX ||
903
                                          instructions == DEC_ABX ||
904
                                          instructions == LDA_IDX ||
905
                                          instructions == STA_IDX ||
906
                                          instructions == ORA_IDX ||
907
                                          instructions == EOR_IDX ||
908
                                          instructions == AND_IDX ||
909
                                          instructions == ADC_IDX ||
910
                                          instructions == CMP_IDX ||
911 215 creep
                                          instructions == SBC_IDX ||
912
                                          instructions == LDA_IDY ||
913 216 creep
                                          instructions == STA_IDY ||
914 215 creep
                                          instructions == ORA_IDY ||
915
                                          instructions == EOR_IDY ||
916
                                          instructions == AND_IDY ||
917
                                          instructions == ADC_IDY ||
918
                                          instructions == CMP_IDY ||
919 216 creep
                                          instructions == SBC_IDY ||
920 241 creep
                                          instructions == JMP_IND ||
921
                                          instructions == JSR_ABS
922 206 creep
                                        ) : {
923
                                                if (alu_opcode.as_a(byte) != 0) {
924
                                                        dut_error("Opcode is Wrong!");
925
                                                };
926
                                                if (alu_enable != 0) {
927
                                                        dut_error("BRK_IMP is Wrong!");
928
                                                };
929
                                                PC = PC + 1;
930
                                        };
931 212 creep
                                        -- TODO: STX and STY should not
932
                                        -- TODO: they dont need access to alu at any cycle
933
                                        -- TODO: because X and Y are available at alu_x and alu_y
934 206 creep
                                        (
935
                                          instructions == STA_ABS ||
936 212 creep
                                          instructions == STA_ZPG ||
937
                                          instructions == STX_ABS ||
938 206 creep
                                          instructions == STY_ABS ||
939
                                          instructions == STX_ZPG ||
940 212 creep
                                          instructions == STY_ZPG
941 206 creep
                                        ) : {
942
                                                if (alu_opcode != instructions) {
943
                                                        dut_error("Opcode is Wrong!");
944
                                                };
945
                                                if (alu_enable != 1) {
946
                                                        dut_error("ASL_ACC is Wrong!");
947
                                                };
948
                                                PC = PC + 1;
949
                                        };
950
                                        (
951
                                          instructions == NOP_IMP ||
952
                                          instructions == PHP_IMP ||
953
                                          instructions == PLA_IMP ||
954
                                          instructions == PLP_IMP ||
955
                                          instructions == RTI_IMP ||
956
                                          instructions == RTS_IMP
957
 
958
                                        ) : {
959
                                                if (alu_opcode.as_a(byte) != 0) {
960
                                                        dut_error("Opcode is Wrong!");
961
                                                };
962
                                                if (alu_enable != 0) {
963
                                                        dut_error("ASL_ACC is Wrong!");
964
                                                };
965
                                        };
966
                                        (
967
                                          instructions == ASL_ACC ||
968
                                          instructions == CLC_IMP ||
969
                                          instructions == CLD_IMP ||
970
                                          instructions == CLI_IMP ||
971
                                          instructions == CLV_IMP ||
972
                                          instructions == DEX_IMP ||
973
                                          instructions == DEY_IMP ||
974
                                          instructions == INX_IMP ||
975
                                          instructions == INY_IMP ||
976
                                          instructions == LSR_ACC ||
977
                                          instructions == PHA_IMP ||
978
                                          instructions == ROL_ACC ||
979 214 creep
                                          instructions == ROR_ACC ||
980 206 creep
                                          instructions == SEC_IMP ||
981
                                          instructions == SED_IMP ||
982
                                          instructions == SEI_IMP ||
983
                                          instructions == TAX_IMP ||
984
                                          instructions == TAY_IMP ||
985
                                          instructions == TXA_IMP ||
986
                                          instructions == TYA_IMP
987
                                        ) : {
988
                                                if (alu_opcode != instructions) {
989
                                                        dut_error("Opcode is Wrong!");
990
                                                };
991
                                                if (alu_enable != 1) {
992
                                                        dut_error("ASL_ACC is Wrong!");
993
                                                };
994
                                        };
995
                                        //JSR_ABS : {
996
                                        //      if (alu_opcode.as_a(byte) != 0) {
997
                                        //              dut_error("Opcode is Wrong!");
998
                                        //      };
999
                                        //      if (mem_rw != 0) {
1000
                                        //              dut_error("MEM_RW should be 1 (WRITE)");
1001
                                        //      };
1002
                                        //      if (alu_enable != 0) {
1003
                                        //              dut_error("JSR_IMP is Wrong!");
1004
                                        //      };
1005
                                        //      if (addr != PC) {
1006
                                        //              dut_error("ADDR should be equal SP!");
1007
                                        //      };
1008
                                        //      PC = PC + 1;
1009
                                        //};
1010
                                        (
1011
                                          instructions == TSX_IMP
1012
                                        ) : {
1013
                                                if (alu_opcode != instructions) {
1014
                                                        dut_error("Opcode is Wrong!");
1015
                                                };
1016
                                                if (alu_enable != 1) {
1017
                                                        dut_error("TSX_IMP is Wrong!");
1018
                                                };
1019
                                                if (alu_a != SP) {
1020
                                                        dut_error("TSX_IMP is Wrong!");
1021
                                                };
1022
                                        };
1023
                                        (
1024
                                          instructions == TXS_IMP
1025
                                        ) : {
1026
                                                if (alu_opcode != instructions) {
1027
                                                        dut_error("Opcode is Wrong!");
1028
                                                };
1029
                                                if (alu_enable != 1) {
1030
                                                        dut_error("TXS_IMP is Wrong!");
1031
                                                };
1032
                                                SP = SP_aux;
1033
                                        };
1034
                                };
1035
                        };
1036
                        CYCLE_3 : {
1037
                                print_state();
1038
                                print addr;
1039
                                case {
1040
                                        (
1041
                                          instructions == BRK_IMP
1042
                                        ) : {
1043
                                                if (alu_opcode.as_a(byte) != 0) {
1044
                                                        dut_error("Opcode is Wrong!");
1045
                                                };
1046
                                                if (mem_rw != 1) {
1047
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1048
                                                };
1049
                                                if (alu_enable != 0) {
1050
                                                        dut_error("BRK_IMP is Wrong!");
1051
                                                };
1052
                                                if (data_out[4:0] != PC[12:8] && data_out[7:5] != 0) {
1053
                                                        dut_error("BRK_IMP is Wrong!");
1054
                                                };
1055
                                                if (addr != SP + 256) {
1056
                                                        dut_error("ADDR should be equal SP!");
1057
                                                };
1058
                                                SP = SP - 1;
1059
                                        };
1060 241 creep
                                        instructions == JSR_ABS : {
1061
                                                if (alu_opcode.as_a(byte) != 0) {
1062
                                                        dut_error("Opcode is Wrong!");
1063
                                                };
1064
                                                if (mem_rw != 0) {
1065
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1066
                                                };
1067
                                                if (alu_enable != 0) {
1068
                                                        dut_error("JSR_IMP is Wrong!");
1069
                                                };
1070
                                                if (addr != SP + 256) {
1071
                                                        dut_error("ADDR should be equal PC!");
1072
                                                };
1073
                                        };
1074 212 creep
                                        -- TODO: This is probably an error STA should not use ALU on the third cycle
1075 206 creep
                                        (
1076 212 creep
                                          instructions == STA_ZPX ||
1077
                                          instructions == STX_ZPY ||
1078
                                          instructions == STY_ZPX
1079
                                        ) : {
1080
                                                if (alu_opcode != instructions) {
1081
                                                        dut_error("Opcode is Wrong!");
1082
                                                };
1083
                                                if (alu_enable != 1) {
1084
                                                        dut_error("ASL_ACC is Wrong!");
1085
                                                };
1086
                                                if (mem_rw != 0) {
1087
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1088
                                                };
1089
                                                if (addr != PCL) {
1090
                                                        dut_error("ADDR should be equal SP!");
1091
                                                };
1092
                                        };
1093
                                        (
1094 206 creep
                                          instructions == STA_ZPG ||
1095
                                          instructions == STX_ZPG ||
1096
                                          instructions == STY_ZPG
1097
                                        ) : {
1098
                                                if (alu_opcode.as_a(byte) != 0) {
1099
                                                        dut_error("Opcode is Wrong!");
1100
                                                };
1101
                                                if (alu_enable != 0) {
1102
                                                        dut_error("ASL_ACC is Wrong!");
1103
                                                };
1104
                                                if (mem_rw != 1) {
1105
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1106
                                                };
1107
                                                if (addr != PCL) {
1108
                                                        dut_error("ADDR should be equal SP!");
1109
                                                };
1110
                                        };
1111
                                        (
1112
                                          instructions == JMP_ABS
1113
                                        ) : {
1114
                                                if (alu_opcode.as_a(byte) != 0) {
1115
                                                        dut_error("Opcode is Wrong!");
1116
                                                };
1117
                                                if (alu_enable != 0) {
1118
                                                        dut_error("ASL_ACC is Wrong!");
1119
                                                };
1120
                                                if (mem_rw != 0) {
1121
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1122
                                                };
1123
                                                PC[7:0] = PCL;
1124
                                                PC[12:8] = PCH[4:0];
1125
                                        };
1126
                                        (
1127
                                          instructions == LDA_ZPX ||
1128
                                          instructions == LDX_ZPY ||
1129
                                          instructions == LDY_ZPX ||
1130
                                          instructions == EOR_ZPX ||
1131
                                          instructions == AND_ZPX ||
1132
                                          instructions == ORA_ZPX ||
1133
                                          instructions == ADC_ZPX ||
1134
                                          instructions == SBC_ZPX ||
1135 212 creep
                                          instructions == CMP_ZPX ||
1136
                                          instructions == ASL_ZPX ||
1137
                                          instructions == LSR_ZPX ||
1138
                                          instructions == ROL_ZPX ||
1139
                                          instructions == ROR_ZPX ||
1140
                                          instructions == INC_ZPX ||
1141
                                          instructions == DEC_ZPX
1142 206 creep
                                        ) : {
1143
                                                if (alu_opcode.as_a(byte) != 0) {
1144
                                                        dut_error("Opcode is Wrong!");
1145
                                                };
1146
                                                if (alu_enable != 0) {
1147
                                                        dut_error("ASL_ACC is Wrong!");
1148
                                                };
1149
                                                if (mem_rw != 0) {
1150
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1151
                                                };
1152
                                                if (addr != PCL) {
1153
                                                        dut_error("ADDR should be equal SP!");
1154
                                                };
1155
                                        };
1156
                                        (
1157 214 creep
                                          instructions == LDA_IDX ||
1158
                                          instructions == STA_IDX ||
1159
                                          instructions == ORA_IDX ||
1160
                                          instructions == EOR_IDX ||
1161
                                          instructions == AND_IDX ||
1162
                                          instructions == ADC_IDX ||
1163
                                          instructions == CMP_IDX ||
1164 215 creep
                                          instructions == SBC_IDX ||
1165
                                          instructions == LDA_IDY ||
1166 216 creep
                                          instructions == STA_IDY ||
1167 215 creep
                                          instructions == ORA_IDY ||
1168
                                          instructions == EOR_IDY ||
1169
                                          instructions == AND_IDY ||
1170
                                          instructions == ADC_IDY ||
1171
                                          instructions == CMP_IDY ||
1172
                                          instructions == SBC_IDY
1173 214 creep
                                        ) : {
1174
                                                if (alu_opcode.as_a(byte) != 0) {
1175
                                                        dut_error("Opcode is Wrong!");
1176
                                                };
1177
                                                if (alu_enable != 0) {
1178
                                                        dut_error("ASL_ACC is Wrong!");
1179
                                                };
1180
                                                if (mem_rw != 0) {
1181
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1182
                                                };
1183
                                                if (addr != pointer) {
1184
                                                        dut_error("ADDR should be equal SP!");
1185
                                                };
1186
                                        };
1187
                                        (
1188 206 creep
                                          instructions == ADC_ABS ||
1189
                                          instructions == AND_ABS ||
1190
                                          instructions == ASL_ABS ||
1191
                                          instructions == BIT_ABS ||
1192
                                          instructions == CMP_ABS ||
1193 216 creep
                                          instructions == CPX_ABS ||
1194
                                          instructions == CPY_ABS ||
1195 206 creep
                                          instructions == DEC_ABS ||
1196
                                          instructions == EOR_ABS ||
1197
                                          instructions == INC_ABS ||
1198
                                          instructions == LDA_ABS ||
1199
                                          instructions == LDX_ABS ||
1200
                                          instructions == LDY_ABS ||
1201
                                          instructions == LSR_ABS ||
1202
                                          instructions == ORA_ABS ||
1203
                                          instructions == ROL_ABS ||
1204
                                          instructions == ROR_ABS ||
1205
                                          instructions == SBC_ABS ||
1206
                                          instructions == STA_ABS ||
1207
                                          instructions == STX_ABS ||
1208 212 creep
                                          instructions == STY_ABS ||
1209
                                          instructions == LDA_ABX ||
1210
                                          instructions == LDY_ABX ||
1211
                                          instructions == EOR_ABX ||
1212
                                          instructions == AND_ABX ||
1213
                                          instructions == ORA_ABX ||
1214
                                          instructions == ADC_ABX ||
1215
                                          instructions == SBC_ABX ||
1216 214 creep
                                          instructions == CMP_ABX ||
1217
                                          instructions == ASL_ABX ||
1218
                                          instructions == LSR_ABX ||
1219
                                          instructions == ROL_ABX ||
1220
                                          instructions == ROR_ABX ||
1221
                                          instructions == INC_ABX ||
1222
                                          instructions == DEC_ABX
1223 206 creep
                                        ) : {
1224
                                                if (alu_opcode.as_a(byte) != 0) {
1225
                                                        dut_error("Opcode is Wrong!");
1226
                                                };
1227
                                                if (alu_enable != 0) {
1228
                                                        dut_error("ASL_ACC is Wrong!");
1229
                                                };
1230
                                                if (addr != PC) {
1231
                                                        dut_error("ADDR should be equal SP!");
1232
                                                };
1233
                                                if (mem_rw != 0) {
1234
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1235
                                                };
1236
                                                PC = PC + 1;
1237 212 creep
                                                if (PCL + X > 255) {
1238
                                                        more_cycles = TRUE;
1239
                                                };
1240 206 creep
                                        };
1241
                                        (
1242 212 creep
                                          instructions == LDA_ABY ||
1243
                                          instructions == LDX_ABY ||
1244
                                          instructions == AND_ABY ||
1245
                                          instructions == EOR_ABY ||
1246
                                          instructions == ORA_ABY ||
1247
                                          instructions == ADC_ABY ||
1248
                                          instructions == SBC_ABY ||
1249
                                          instructions == CMP_ABY
1250
                                        ) : {
1251
                                                if (alu_opcode.as_a(byte) != 0) {
1252
                                                        dut_error("Opcode is Wrong!");
1253
                                                };
1254
                                                if (alu_enable != 0) {
1255
                                                        dut_error("ASL_ACC is Wrong!");
1256
                                                };
1257
                                                if (addr != PC) {
1258
                                                        dut_error("ADDR should be equal SP!");
1259
                                                };
1260
                                                if (mem_rw != 0) {
1261
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1262
                                                };
1263
                                                PC = PC + 1;
1264
                                                if (PCL + Y > 255) {
1265
                                                        more_cycles = TRUE;
1266
                                                };
1267
                                        };
1268
                                        (
1269 216 creep
                                          instructions == STA_ABX ||
1270
                                          instructions == STA_ABY ||
1271
                                          instructions == JMP_IND
1272
                                        ) : {
1273
                                                if (alu_opcode.as_a(byte) != 0) {
1274
                                                        dut_error("Opcode is Wrong!");
1275
                                                };
1276
                                                if (alu_enable != 0) {
1277
                                                        dut_error("ASL_ACC is Wrong!");
1278
                                                };
1279
                                                if (addr != PC) {
1280
                                                        dut_error("ADDR should be equal SP!");
1281
                                                };
1282
                                                if (mem_rw != 0) {
1283
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1284
                                                };
1285
                                                PC = PC + 1;
1286
                                        };
1287
                                        (
1288 206 creep
                                          instructions == LDA_ZPG ||
1289
                                          instructions == LDX_ZPG ||
1290
                                          instructions == LDY_ZPG ||
1291
                                          instructions == EOR_ZPG ||
1292
                                          instructions == AND_ZPG ||
1293
                                          instructions == ORA_ZPG ||
1294
                                          instructions == ADC_ZPG ||
1295
                                          instructions == SBC_ZPG ||
1296
                                          instructions == CMP_ZPG ||
1297 216 creep
                                          instructions == CPX_ZPG ||
1298
                                          instructions == CPY_ZPG ||
1299 206 creep
                                          instructions == BIT_ZPG ||
1300
                                          instructions == ASL_ZPG ||
1301
                                          instructions == LSR_ZPG ||
1302
                                          instructions == ROL_ZPG ||
1303
                                          instructions == ROR_ZPG ||
1304
                                          instructions == INC_ZPG ||
1305
                                          instructions == DEC_ZPG
1306
                                        ) : {
1307
                                                if (alu_opcode.as_a(byte) != 0) {
1308
                                                        dut_error("Opcode is Wrong!");
1309
                                                };
1310
                                                if (alu_enable != 0) {
1311
                                                        dut_error("ASL_ACC is Wrong!");
1312
                                                };
1313
                                                if (mem_rw != 0) {
1314
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1315
                                                };
1316
                                                if (addr != PCL) {
1317
                                                        dut_error("ADDR should be equal SP!");
1318
                                                };
1319
                                        };
1320
                                        (
1321
                                          instructions == PHA_IMP ||
1322
                                          instructions == PHP_IMP
1323
                                        ) : {
1324
                                                if (alu_opcode.as_a(byte) != 0) {
1325
                                                        dut_error("Opcode is Wrong!");
1326
                                                };
1327
                                                if (mem_rw != 1) {
1328
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1329
                                                };
1330
                                                if (alu_a != 0) {
1331
                                                        dut_error("PHP_IMP is Wrong!");
1332
                                                };
1333
                                                if (addr != SP + 256) {
1334
                                                        dut_error("ADDR should be equal SP!");
1335
                                                };
1336
                                                SP = SP - 1;
1337
                                                if (alu_enable != 0) {
1338
                                                        dut_error("PHP_IMP is Wrong!");
1339
                                                };
1340
                                        };
1341
                                        (
1342
                                          instructions == PLA_IMP ||
1343
                                          instructions == PLP_IMP ||
1344
                                          instructions == RTI_IMP ||
1345
                                          instructions == RTS_IMP
1346
                                        ) : {
1347
                                                if (alu_opcode.as_a(byte) != 0) {
1348
                                                        dut_error("Opcode is Wrong!");
1349
                                                };
1350
                                                if (alu_enable != 0) {
1351
                                                        dut_error("PLA_IMP is Wrong!");
1352
                                                };
1353
                                                if (mem_rw != 0) {
1354
                                                        dut_error("MEM_RW should be 0 (READ)");
1355
                                                };
1356
                                                if (addr != SP + 256) {
1357
                                                        dut_error("ADDR should be equal SP!");
1358
                                                };
1359
                                                SP = SP + 1;
1360
                                        };
1361
                                };
1362
                        };
1363
                        CYCLE_4 : {
1364
                                print_state();
1365
                                print addr;
1366
                                case {
1367
                                        (
1368
                                          instructions == BRK_IMP
1369
                                        ) : {
1370
                                                if (alu_opcode.as_a(byte) != 0) {
1371
                                                        dut_error("Opcode is Wrong!");
1372
                                                };
1373
                                                if (mem_rw != 1) {
1374
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1375
                                                };
1376
                                                if (alu_enable != 0) {
1377
                                                        dut_error("BRK_IMP is Wrong!");
1378
                                                };
1379
                                                if (data_out != PC[7:0]) {
1380
                                                        dut_error("BRK_IMP is Wrong!");
1381
                                                };
1382
                                                if (addr != SP + 256) {
1383
                                                        dut_error("ADDR should be equal SP!");
1384
                                                };
1385
                                                SP = SP - 1;
1386
                                        };
1387 241 creep
                                        instructions == JSR_ABS : {
1388
                                                if (alu_opcode.as_a(byte) != 0) {
1389
                                                        dut_error("Opcode is Wrong!");
1390
                                                };
1391
                                                if (mem_rw != 1) {
1392
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1393
                                                };
1394
                                                if (alu_enable != 0) {
1395
                                                        dut_error("JSR_ABS is Wrong!");
1396
                                                };
1397
                                                if (data_out[4:0] != PC[12:8]) {
1398
                                                        dut_error("JSR_ABS is Wrong!");
1399
                                                };
1400
                                                if (addr != SP + 256) {
1401
                                                        dut_error("ADDR should be equal SP!");
1402
                                                };
1403
                                                SP = SP - 1;
1404
                                        };
1405 206 creep
                                        (
1406 216 creep
                                          instructions == STA_ABX
1407
                                        ) : {
1408
                                                if (alu_opcode != instructions) {
1409
                                                        dut_error("Opcode is Wrong!");
1410
                                                };
1411
                                                if (alu_enable != 1) {
1412
                                                        dut_error("ASL_ACC is Wrong!");
1413
                                                };
1414
                                                if (PCL + X > 255) {
1415
                                                        if (addr[7:0] != PCL + X - 256) {
1416
                                                                dut_error("ADDR should be equal SP!");
1417
                                                        };
1418
                                                }
1419
                                                else {
1420
                                                        if (addr[7:0] != PCL + X) {
1421
                                                                dut_error("ADDR should be equal SP!");
1422
                                                        };
1423
                                                };
1424
                                                if (addr[12:8] != PCH[4:0]) {
1425
                                                        dut_error("ADDR should be equal SP!");
1426
                                                };
1427
                                                if (mem_rw != 0) {
1428
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1429
                                                };
1430
                                        };
1431
                                        (
1432
                                          instructions == STA_ABY
1433
                                        ) : {
1434
                                                if (alu_opcode != instructions) {
1435
                                                        dut_error("Opcode is Wrong!");
1436
                                                };
1437
                                                if (alu_enable != 1) {
1438
                                                        dut_error("ASL_ACC is Wrong!");
1439
                                                };
1440
                                                if (PCL + Y > 255) {
1441
                                                        if (addr[7:0] != PCL + Y - 256) {
1442
                                                                dut_error("ADDR should be equal SP!");
1443
                                                        };
1444
                                                }
1445
                                                else {
1446
                                                        if (addr[7:0] != PCL + Y) {
1447
                                                                dut_error("ADDR should be equal SP!");
1448
                                                        };
1449
                                                };
1450
                                                if (addr[12:8] != PCH[4:0]) {
1451
                                                        dut_error("ADDR should be equal SP!");
1452
                                                };
1453
                                                if (mem_rw != 0) {
1454
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1455
                                                };
1456
                                        };
1457
                                        (
1458 206 creep
                                          instructions == LDA_ZPX ||
1459
                                          instructions == LDY_ZPX ||
1460
                                          instructions == EOR_ZPX ||
1461
                                          instructions == AND_ZPX ||
1462
                                          instructions == ORA_ZPX ||
1463
                                          instructions == ADC_ZPX ||
1464
                                          instructions == SBC_ZPX ||
1465 212 creep
                                          instructions == CMP_ZPX ||
1466
                                          instructions == ASL_ZPX ||
1467
                                          instructions == LSR_ZPX ||
1468
                                          instructions == ROL_ZPX ||
1469
                                          instructions == ROR_ZPX ||
1470
                                          instructions == INC_ZPX ||
1471
                                          instructions == DEC_ZPX
1472 206 creep
                                        ) : {
1473
                                                if (alu_opcode.as_a(byte) != 0) {
1474
                                                        dut_error("Opcode is Wrong!");
1475
                                                };
1476
                                                if (alu_enable != 0) {
1477
                                                        dut_error("ASL_ACC is Wrong!");
1478
                                                };
1479
                                                if (mem_rw != 0) {
1480
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1481
                                                };
1482 212 creep
                                                --TODO: Isn`t it suppose to have ADDRH == 0????
1483 214 creep
                                                if (PCL + X > 255) {
1484
                                                        if (addr[7:0] != PCL + X - 256) {
1485
                                                                dut_error("ADDR should be equal SP!");
1486
                                                        };
1487
                                                }
1488
                                                else {
1489
                                                        if (addr[7:0] != PCL + X) {
1490
                                                                dut_error("ADDR should be equal SP!");
1491
                                                        };
1492 206 creep
                                                };
1493
                                        };
1494
                                        (
1495 212 creep
                                          instructions == LDA_ABX ||
1496
                                          instructions == LDY_ABX ||
1497
                                          instructions == EOR_ABX ||
1498
                                          instructions == AND_ABX ||
1499
                                          instructions == ORA_ABX ||
1500
                                          instructions == ADC_ABX ||
1501
                                          instructions == SBC_ABX ||
1502 214 creep
                                          instructions == CMP_ABX ||
1503
                                          instructions == ASL_ABX ||
1504
                                          instructions == LSR_ABX ||
1505
                                          instructions == ROL_ABX ||
1506
                                          instructions == ROR_ABX ||
1507
                                          instructions == INC_ABX ||
1508
                                          instructions == DEC_ABX
1509 206 creep
                                        ) : {
1510
                                                if (alu_opcode.as_a(byte) != 0) {
1511
                                                        dut_error("Opcode is Wrong!");
1512
                                                };
1513
                                                if (alu_enable != 0) {
1514
                                                        dut_error("ASL_ACC is Wrong!");
1515
                                                };
1516
                                                if (mem_rw != 0) {
1517
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1518
                                                };
1519 212 creep
                                                if (PCL + X > 255) {
1520
                                                        more_cycles = TRUE;
1521
                                                        if (addr[7:0] != PCL + X - 256) {
1522
                                                                dut_error("ADDR should be equal SP!");
1523
                                                        };
1524
                                                }
1525
                                                else {
1526
                                                        if (addr[7:0] != PCL + X) {
1527
                                                                dut_error("ADDR should be equal SP!");
1528
                                                        };
1529 206 creep
                                                };
1530
                                        };
1531
                                        (
1532 214 creep
                                          instructions == LDA_IDX ||
1533
                                          instructions == STA_IDX ||
1534
                                          instructions == ORA_IDX ||
1535
                                          instructions == EOR_IDX ||
1536
                                          instructions == AND_IDX ||
1537
                                          instructions == ADC_IDX ||
1538
                                          instructions == CMP_IDX ||
1539
                                          instructions == SBC_IDX
1540
                                        ) : {
1541
                                                if (alu_opcode.as_a(byte) != 0) {
1542
                                                        dut_error("Opcode is Wrong!");
1543
                                                };
1544
                                                if (alu_enable != 0) {
1545
                                                        dut_error("ASL_ACC is Wrong!");
1546
                                                };
1547
                                                if (mem_rw != 0) {
1548
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1549
                                                };
1550
                                                if (pointer + X > 255) {
1551
                                                        if (addr[7:0] != pointer + X - 256) {
1552
                                                                dut_error("ADDR is wrong");
1553
                                                        };
1554
                                                }
1555
                                                else {
1556
                                                        if (addr[7:0] != pointer + X) {
1557
                                                                dut_error("ADDR is wrong");
1558
                                                        };
1559
                                                };
1560
                                        };
1561
                                        (
1562 215 creep
                                          instructions == LDA_IDY ||
1563 216 creep
                                          instructions == STA_IDY ||
1564 215 creep
                                          instructions == ORA_IDY ||
1565
                                          instructions == EOR_IDY ||
1566
                                          instructions == AND_IDY ||
1567
                                          instructions == ADC_IDY ||
1568
                                          instructions == CMP_IDY ||
1569
                                          instructions == SBC_IDY
1570
                                        ) : {
1571
                                                if (alu_opcode.as_a(byte) != 0) {
1572
                                                        dut_error("Opcode is Wrong!");
1573
                                                };
1574
                                                if (alu_enable != 0) {
1575
                                                        dut_error("ASL_ACC is Wrong!");
1576
                                                };
1577
                                                if (mem_rw != 0) {
1578
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1579
                                                };
1580
                                                if (addr != pointer + 1) {
1581
                                                        dut_error("ADDR should be equal SP!");
1582
                                                };
1583
                                                if (PCL + Y > 255) {
1584
                                                        more_cycles = TRUE;
1585
                                                };
1586
                                        };
1587
                                        (
1588 216 creep
                                          instructions == JMP_IND
1589
                                        ) : {
1590
                                                if (alu_opcode.as_a(byte) != 0) {
1591
                                                        dut_error("Opcode is Wrong!");
1592
                                                };
1593
                                                if (alu_enable != 0) {
1594
                                                        dut_error("ASL_ACC is Wrong!");
1595
                                                };
1596
                                                if (mem_rw != 0) {
1597
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1598
                                                };
1599
                                                if (addr[7:0] != pointer) {
1600
                                                        dut_error("ADDR should be equal SP!");
1601
                                                };
1602
                                                if (addr[12:8] != pointer_h[4:0]) {
1603
                                                        dut_error("ADDR should be equal SP!");
1604
                                                };
1605
                                        };
1606
                                        (
1607 212 creep
                                          instructions == LDX_ZPY ||
1608
                                          instructions == LDA_ABY ||
1609
                                          instructions == LDX_ABY ||
1610
                                          instructions == EOR_ABY ||
1611
                                          instructions == AND_ABY ||
1612
                                          instructions == ORA_ABY ||
1613
                                          instructions == ADC_ABY ||
1614
                                          instructions == SBC_ABY ||
1615
                                          instructions == CMP_ABY
1616
                                        ) : {
1617
                                                if (alu_opcode.as_a(byte) != 0) {
1618
                                                        dut_error("Opcode is Wrong!");
1619
                                                };
1620
                                                if (alu_enable != 0) {
1621
                                                        dut_error("ASL_ACC is Wrong!");
1622
                                                };
1623
                                                if (mem_rw != 0) {
1624
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1625
                                                };
1626
                                                if (PCL + Y > 255) {
1627
                                                        more_cycles = TRUE;
1628
                                                        if (addr[7:0] != PCL + Y - 256) {
1629
                                                                dut_error("ADDR should be equal SP!");
1630
                                                        };
1631
                                                }
1632
                                                else {
1633
                                                        if (addr[7:0] != PCL + Y) {
1634
                                                                dut_error("ADDR should be equal SP!");
1635
                                                        };
1636
                                                };
1637
                                        };
1638
                                        (
1639 206 creep
                                          instructions == ADC_ABS ||
1640
                                          instructions == AND_ABS ||
1641
                                          instructions == ASL_ABS ||
1642
                                          instructions == BIT_ABS ||
1643
                                          instructions == CMP_ABS ||
1644 216 creep
                                          instructions == CPX_ABS ||
1645
                                          instructions == CPY_ABS ||
1646 206 creep
                                          instructions == DEC_ABS ||
1647
                                          instructions == EOR_ABS ||
1648
                                          instructions == INC_ABS ||
1649
                                          instructions == LDA_ABS ||
1650
                                          instructions == LDX_ABS ||
1651
                                          instructions == LDY_ABS ||
1652
                                          instructions == LSR_ABS ||
1653
                                          instructions == ORA_ABS ||
1654
                                          instructions == ROL_ABS ||
1655
                                          instructions == ROR_ABS ||
1656
                                          instructions == SBC_ABS
1657
                                          ) : {
1658
                                                if (alu_opcode.as_a(byte) != 0) {
1659
                                                        dut_error("Opcode is Wrong!");
1660
                                                };
1661
                                                if (alu_enable != 0) {
1662
                                                        dut_error("ASL_ACC is Wrong!");
1663
                                                };
1664
                                                if (addr[7:0] != PCL) {
1665
                                                        dut_error("ADDR should be equal SP!");
1666
                                                };
1667
                                                if (addr[12:8] != PCH[4:0]) {
1668
                                                        dut_error("ADDR should be equal SP!");
1669
                                                };
1670
                                                if (mem_rw != 0) {
1671
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1672
                                                };
1673
                                        };
1674
                                        (
1675
                                          instructions == STA_ABS ||
1676
                                          instructions == STX_ABS ||
1677
                                          instructions == STY_ABS
1678
                                        ) : {
1679
                                                if (alu_opcode.as_a(byte) != 0) {
1680
                                                        dut_error("Opcode is Wrong!");
1681
                                                };
1682
                                                if (alu_enable != 0) {
1683
                                                        dut_error("ASL_ACC is Wrong!");
1684
                                                };
1685
                                                if (addr[7:0] != PCL) {
1686
                                                        dut_error("ADDR should be equal SP!");
1687
                                                };
1688
                                                if (addr[12:8] != PCH[4:0]) {
1689
                                                        dut_error("ADDR should be equal SP!");
1690
                                                };
1691
                                                if (mem_rw != 1) {
1692
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1693
                                                };
1694
                                        };
1695
                                        (
1696
                                          instructions == ASL_ZPG ||
1697
                                          instructions == LSR_ZPG ||
1698
                                          instructions == ROL_ZPG ||
1699
                                          instructions == ROR_ZPG ||
1700
                                          instructions == INC_ZPG ||
1701
                                          instructions == DEC_ZPG
1702
                                        ) : {
1703
                                                if (alu_opcode != instructions) {
1704
                                                        dut_error("Opcode is Wrong!");
1705
                                                };
1706
                                                if (mem_rw != 1) {
1707
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1708
                                                };
1709
                                                if (alu_enable != 1) {
1710
                                                        dut_error("BRK_IMP is Wrong!");
1711
                                                };
1712
                                                if (addr[7:0] != PCL) {
1713
                                                        dut_error("ADDR should be equal SP!");
1714
                                                };
1715
                                        };
1716
                                        (
1717 212 creep
                                          instructions == STA_ZPX ||
1718
                                          instructions == STY_ZPX
1719
                                        ) : {
1720
                                                if (alu_opcode.as_a(byte) != 0) {
1721
                                                        dut_error("Opcode is Wrong!");
1722
                                                };
1723
                                                if (alu_enable != 0) {
1724
                                                        dut_error("ASL_ACC is Wrong!");
1725
                                                };
1726
                                                if (mem_rw != 1) {
1727
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1728
                                                };
1729 214 creep
                                                if (PCL + X > 255) {
1730
                                                        if (addr[7:0] != PCL + X - 256) {
1731
                                                                dut_error("ADDR should be equal SP!");
1732
                                                        };
1733
                                                }
1734
                                                else {
1735
                                                        if (addr[7:0] != PCL + X) {
1736
                                                                dut_error("ADDR should be equal SP!");
1737
                                                        };
1738 212 creep
                                                };
1739
                                        };
1740
                                        (
1741
                                          instructions == STX_ZPY
1742
                                        ) : {
1743
                                                if (alu_opcode.as_a(byte) != 0) {
1744
                                                        dut_error("Opcode is Wrong!");
1745
                                                };
1746
                                                if (alu_enable != 0) {
1747
                                                        dut_error("ASL_ACC is Wrong!");
1748
                                                };
1749
                                                if (mem_rw != 1) {
1750
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1751
                                                };
1752 214 creep
                                                if (PCL + Y > 255) {
1753
                                                        if (addr[7:0] != PCL + Y - 256) {
1754
                                                                dut_error("ADDR should be equal SP!");
1755
                                                        };
1756
                                                }
1757
                                                else {
1758
                                                        if (addr[7:0] != PCL + Y) {
1759
                                                                dut_error("ADDR should be equal SP!");
1760
                                                        };
1761 212 creep
                                                };
1762
                                        };
1763
                                        (
1764 206 creep
                                          instructions == PLA_IMP ||
1765
                                          instructions == PLP_IMP
1766
                                        ) : {
1767
                                                if (alu_opcode.as_a(byte) != 0) {
1768
                                                        dut_error("Opcode is Wrong!");
1769
                                                };
1770
                                                if (mem_rw != 0) {
1771
                                                        dut_error("MEM_RW should be 0 (READ)");
1772
                                                };
1773
                                                if (alu_enable != 0) {
1774
                                                        dut_error("PLP_IMP is Wrong!");
1775
                                                };
1776
                                                if (addr != SP + 256) {
1777
                                                        dut_error("ADDR should be equal SP!");
1778
                                                };
1779
                                        };
1780
                                        (
1781
                                          instructions == RTI_IMP
1782
                                        ) : {
1783
                                                if (alu_opcode.as_a(byte) != 0) {
1784
                                                        dut_error("Opcode is Wrong!");
1785
                                                };
1786
                                                if (mem_rw != 0) {
1787
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1788
                                                };
1789
                                                if (alu_enable != 0) {
1790
                                                        dut_error("RTI_IMP is Wrong!");
1791
                                                };
1792
                                                if (addr != SP + 256) {
1793
                                                        dut_error("ADDR should be equal SP!");
1794
                                                };
1795
                                                SP = SP + 1;
1796
                                        };
1797
                                        (
1798
                                          instructions == RTS_IMP
1799
                                        ) : {
1800
                                                if (alu_opcode.as_a(byte) != 0) {
1801
                                                        dut_error("Opcode is Wrong!");
1802
                                                };
1803
                                                if (alu_enable != 0) {
1804
                                                        dut_error("RTS_IMP is Wrong!");
1805
                                                };
1806
                                                if (addr != SP + 256) {
1807
                                                        dut_error("ADDR should be equal SP!");
1808
                                                };
1809
                                                SP = SP + 1;
1810
                                                PC[7:0] = PCL;
1811
                                        };
1812
                                };
1813
                        };
1814
                        CYCLE_5 : {
1815
                                print_state();
1816
                                print addr;
1817
                                case {
1818
                                        (
1819
                                          instructions == BRK_IMP
1820
                                        ) : {
1821
                                                if (alu_opcode.as_a(byte) != 0) {
1822
                                                        dut_error("Opcode is Wrong!");
1823
                                                };
1824
                                                if (mem_rw != 1) {
1825
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1826
                                                };
1827
                                                if (alu_enable != 0) {
1828
                                                        dut_error("BRK_IMP is Wrong!");
1829
                                                };
1830
                                                if (addr != SP + 256) {
1831
                                                        dut_error("ADDR should be equal SP!");
1832
                                                };
1833
                                                SP = SP - 1;
1834
                                        };
1835 216 creep
                                        (
1836
                                          instructions == JMP_IND
1837
                                        ) : {
1838
                                                if (alu_opcode.as_a(byte) != 0) {
1839
                                                        dut_error("Opcode is Wrong!");
1840
                                                };
1841
                                                if (alu_enable != 0) {
1842
                                                        dut_error("ASL_ACC is Wrong!");
1843
                                                };
1844
                                                if (mem_rw != 0) {
1845
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1846
                                                };
1847
                                                if (pointer + 1 > 255) {
1848
                                                        if (addr[7:0] != pointer + 1 - 256) {
1849
                                                                dut_error("ADDR should be equal SP!");
1850
                                                        };
1851
                                                }
1852
                                                else {
1853
                                                        if (addr[7:0] != pointer + 1) {
1854
                                                                dut_error("ADDR should be equal SP!");
1855
                                                        };
1856
                                                };
1857
                                                -- TODO: This is the correct behaviour expected from spec
1858
                                                --if (addr[12:8] != pointer_h[4:0]) {
1859
                                                --      print addr[7:0], pointer;
1860
                                                --      print addr[12:8], pointer_h[4:0];
1861
                                                --      dut_error("ADDR should be equal SP!");
1862
                                                --};
1863
                                                PC[7:0] = PCL;
1864
                                                PC[12:8] = PCH[4:0];
1865
                                        };
1866 241 creep
                                        instructions == JSR_ABS : {
1867
                                                if (alu_opcode.as_a(byte) != 0) {
1868
                                                        dut_error("Opcode is Wrong!");
1869
                                                };
1870
                                                if (mem_rw != 1) {
1871
                                                        dut_error("MEM_RW should be 1 (WRITE)");
1872
                                                };
1873
                                                if (alu_enable != 0) {
1874
                                                        dut_error("JSR_ABS is Wrong!");
1875
                                                };
1876
                                                if (data_out != PC[7:0]) {
1877
                                                        dut_error("JSR_ABS is Wrong!");
1878
                                                };
1879
                                                if (addr != SP + 256) {
1880
                                                        dut_error("ADDR should be equal SP!");
1881
                                                };
1882
                                                SP = SP - 1;
1883
                                        };
1884 206 creep
                                        (
1885 214 creep
                                          instructions == LDA_IDX ||
1886
                                          instructions == ORA_IDX ||
1887
                                          instructions == EOR_IDX ||
1888
                                          instructions == AND_IDX ||
1889
                                          instructions == ADC_IDX ||
1890
                                          instructions == CMP_IDX ||
1891
                                          instructions == SBC_IDX
1892
                                        ) : {
1893
                                                if (alu_opcode.as_a(byte) != 0) {
1894
                                                        dut_error("Opcode is Wrong!");
1895
                                                };
1896
                                                if (alu_enable != 0) {
1897
                                                        dut_error("ASL_ACC is Wrong!");
1898
                                                };
1899
                                                if (mem_rw != 0) {
1900
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1901
                                                };
1902
                                                if (pointer + X + 1 > 255) {
1903
                                                        if (addr[7:0] != pointer + X + 1 - 256) {
1904
                                                                dut_error("ADDR is wrong");
1905
                                                        };
1906
                                                }
1907
                                                else {
1908
                                                        if (addr[7:0] != pointer + X + 1) {
1909
                                                                dut_error("ADDR is wrong");
1910
                                                        };
1911
                                                };
1912 216 creep
                                                if (addr[12:8] != 0) {
1913
                                                        print addr[12:8], PCH[4:0];
1914
                                                        dut_error("ADDR is wrong");
1915
                                                };
1916 214 creep
                                        };
1917
                                        (
1918 215 creep
                                          instructions == LDA_IDY ||
1919 241 creep
                                          //instructions == STA_IDY ||
1920 215 creep
                                          instructions == ORA_IDY ||
1921
                                          instructions == EOR_IDY ||
1922
                                          instructions == AND_IDY ||
1923
                                          instructions == ADC_IDY ||
1924
                                          instructions == CMP_IDY ||
1925
                                          instructions == SBC_IDY
1926
                                        ) : {
1927
                                                if (alu_opcode.as_a(byte) != 0) {
1928
                                                        dut_error("Opcode is Wrong!");
1929
                                                };
1930
                                                if (alu_enable != 0) {
1931
                                                        dut_error("ASL_ACC is Wrong!");
1932
                                                };
1933
                                                if (mem_rw != 0) {
1934
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1935
                                                };
1936
                                                if (PCL + Y > 255) {
1937
                                                        if (addr[7:0] != PCL + Y - 256) {
1938
                                                                dut_error("ADDR is wrong");
1939
                                                        };
1940
                                                }
1941
                                                else {
1942
                                                        if (addr[7:0] != PCL + Y) {
1943
                                                                dut_error("ADDR is wrong");
1944
                                                        };
1945
                                                };
1946 216 creep
                                                -- TODO: This is the expected behavior (took from spec)
1947
                                                -- addr[12:8] is 0 or 1 acording to PCL + Y > 255
1948
                                                --if (addr[12:8] != PCH[4:0]) {
1949
                                                --      print addr[12:8], PCH[4:0];
1950
                                                --      dut_error("ADDR is wrong");
1951
                                                --};
1952 215 creep
                                        };
1953
                                        (
1954
                                          instructions == STA_IDX
1955
                                        ) : {
1956
                                                if (alu_opcode != instructions) {
1957
                                                        dut_error("Opcode is Wrong!");
1958
                                                };
1959
                                                if (alu_enable != 1) {
1960
                                                        dut_error("ASL_ACC is Wrong!");
1961
                                                };
1962
                                                if (mem_rw != 0) {
1963
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1964
                                                };
1965
                                                if (pointer + X + 1 > 255) {
1966
                                                        if (addr[7:0] != pointer + X + 1 - 256) {
1967
                                                                dut_error("ADDR is wrong");
1968
                                                        };
1969
                                                }
1970
                                                else {
1971
                                                        if (addr[7:0] != pointer + X + 1) {
1972
                                                                dut_error("ADDR is wrong");
1973
                                                        };
1974
                                                };
1975
                                        };
1976
                                        (
1977 241 creep
                                          instructions == STA_IDY
1978
                                        ) : {
1979
                                                if (alu_opcode != instructions) {
1980
                                                        dut_error("Opcode is Wrong!");
1981
                                                };
1982
                                                if (alu_enable != 1) {
1983
                                                        dut_error("ASL_ACC is Wrong!");
1984
                                                };
1985
                                                if (mem_rw != 0) {
1986
                                                        dut_error("MEM_RW should be 0 (WRITE)");
1987
                                                };
1988
                                                if (pointer + Y > 255) {
1989
                                                        if (addr[7:0] != pointer + Y - 256) {
1990
                                                                dut_error("ADDR is wrong");
1991
                                                        };
1992
                                                }
1993
                                                else {
1994
                                                        if (addr[7:0] != pointer + Y) {
1995
                                                                dut_error("ADDR is wrong");
1996
                                                        };
1997
                                                };
1998
                                        };
1999
 
2000
                                        (
2001 216 creep
                                          instructions == STA_ABX
2002
                                        ) : {
2003
                                                if (alu_opcode.as_a(byte) != 0) {
2004
                                                        dut_error("Opcode is Wrong!");
2005
                                                };
2006
                                                if (alu_enable != 0) {
2007
                                                        dut_error("ASL_ACC is Wrong!");
2008
                                                };
2009
                                                if (PCL + X > 255) {
2010
                                                        if (addr[7:0] != PCL + X - 256) {
2011
                                                                dut_error("ADDR should be equal SP!");
2012
                                                        };
2013
                                                        if (addr[12:8] != PCH + 1) {
2014
                                                                dut_error("ADDR should be equal SP!");
2015
                                                        };
2016
                                                }
2017
                                                else {
2018
                                                        if (addr[7:0] != PCL + X) {
2019
                                                                dut_error("ADDR should be equal SP!");
2020
                                                        };
2021
                                                        if (addr[12:8] != PCH[4:0]) {
2022
                                                                dut_error("ADDR should be equal SP!");
2023
                                                        };
2024
                                                };
2025
                                                if (mem_rw != 1) {
2026
                                                        dut_error("MEM_RW should be 1 (WRITE)");
2027
                                                };
2028
                                        };
2029
                                        (
2030
                                          instructions == STA_ABY
2031
                                        ) : {
2032
                                                if (alu_opcode.as_a(byte) != 0) {
2033
                                                        dut_error("Opcode is Wrong!");
2034
                                                };
2035
                                                if (alu_enable != 0) {
2036
                                                        dut_error("ASL_ACC is Wrong!");
2037
                                                };
2038
                                                if (PCL + Y > 255) {
2039
                                                        if (addr[7:0] != PCL + Y - 256) {
2040
                                                                dut_error("ADDR should be equal SP!");
2041
                                                        };
2042
                                                        if (addr[12:8] != PCH + 1) {
2043
                                                                dut_error("ADDR should be equal SP!");
2044
                                                        };
2045
                                                }
2046
                                                else {
2047
                                                        if (addr[7:0] != PCL + Y) {
2048
                                                                dut_error("ADDR should be equal SP!");
2049
                                                        };
2050
                                                        if (addr[12:8] != PCH[4:0]) {
2051
                                                                dut_error("ADDR should be equal SP!");
2052
                                                        };
2053
                                                };
2054
                                                if (mem_rw != 1) {
2055
                                                        dut_error("MEM_RW should be 1 (WRITE)");
2056
                                                };
2057
                                        };
2058
                                        (
2059 206 creep
                                          instructions == RTI_IMP
2060
                                        ) : {
2061
                                                if (alu_opcode != instructions) {
2062
                                                        dut_error("Opcode is Wrong!");
2063
                                                };
2064
                                                if (mem_rw != 0) {
2065
                                                        dut_error("MEM_RW should be 1 (WRITE)");
2066
                                                };
2067
                                                if (alu_enable != 1) {
2068
                                                        dut_error("RTI_IMP is Wrong!");
2069
                                                };
2070
                                                if (addr != SP + 256) {
2071
                                                        dut_error("ADDR should be equal SP!");
2072
                                                };
2073
                                                SP = SP + 1;
2074
                                                PC[7:0] = PCL;
2075
                                        };
2076
                                        (
2077
                                          instructions == RTS_IMP
2078
                                        ) : {
2079
                                                if (alu_opcode.as_a(byte) != 0) {
2080
                                                        dut_error("Opcode is Wrong!");
2081
                                                };
2082
                                                if (alu_enable != 0) {
2083
                                                        dut_error("SEI_IMP is Wrong!");
2084
                                                };
2085
                                                if (addr != SP + 256) {
2086
                                                        dut_error("ADDR should be equal SP!");
2087
                                                };
2088
                                                PC[12:8] = PCH[4:0];
2089
                                        };
2090
                                        (
2091
                                          instructions == ASL_ZPG ||
2092
                                          instructions == LSR_ZPG ||
2093
                                          instructions == ROL_ZPG ||
2094
                                          instructions == ROR_ZPG ||
2095
                                          instructions == INC_ZPG ||
2096
                                          instructions == DEC_ZPG
2097
                                        ) : {
2098
                                                if (alu_opcode.as_a(byte) != 0) {
2099
                                                        dut_error("Opcode is Wrong!");
2100
                                                };
2101
                                                if (mem_rw != 1) {
2102
                                                        dut_error("MEM_RW should be 1 (WRITE)");
2103
                                                };
2104
                                                if (alu_enable != 0) {
2105
                                                        dut_error("BRK_IMP is Wrong!");
2106
                                                };
2107
                                                if (addr[7:0] != PCL) {
2108
                                                        dut_error("ADDR should be equal SP!");
2109
                                                };
2110
                                        };
2111
                                        (
2112 212 creep
                                          instructions == LDA_ABX ||
2113
                                          instructions == LDY_ABX ||
2114
                                          instructions == EOR_ABX ||
2115
                                          instructions == AND_ABX ||
2116
                                          instructions == ORA_ABX ||
2117
                                          instructions == ADC_ABX ||
2118
                                          instructions == SBC_ABX ||
2119 214 creep
                                          instructions == CMP_ABX ||
2120
                                          (
2121
                                                more_cycles == TRUE &&
2122
                                                (
2123
                                                  instructions == ASL_ABX ||
2124
                                                  instructions == LSR_ABX ||
2125
                                                  instructions == ROL_ABX ||
2126
                                                  instructions == ROR_ABX ||
2127
                                                  instructions == INC_ABX ||
2128
                                                  instructions == DEC_ABX
2129
                                                )
2130
                                          )
2131 212 creep
                                        ) : {
2132
                                                if (alu_opcode.as_a(byte) != 0) {
2133
                                                        dut_error("Opcode is Wrong!");
2134
                                                };
2135
                                                if (alu_enable != 0) {
2136
                                                        dut_error("ASL_ACC is Wrong!");
2137
                                                };
2138
                                                if (mem_rw != 0) {
2139
                                                        dut_error("MEM_RW should be 0 (WRITE)");
2140
                                                };
2141
                                                if (addr[7:0] != PCL + X - 256) {
2142
                                                        dut_error("ADDR is wrong!");
2143
                                                };
2144
                                                if (addr[12:8] != PCH[4:0] + 1) {
2145
                                                        dut_error("ADDR is wrong!");
2146
                                                };
2147
                                        };
2148
                                        (
2149 214 creep
                                          more_cycles == FALSE &&
2150
                                          (
2151
                                                  instructions == ASL_ABX ||
2152
                                                  instructions == LSR_ABX ||
2153
                                                  instructions == ROL_ABX ||
2154
                                                  instructions == ROR_ABX ||
2155
                                                  instructions == INC_ABX ||
2156
                                                  instructions == DEC_ABX
2157
                                          )
2158
                                        ) : {
2159
                                                if (alu_opcode.as_a(byte) != 0) {
2160
                                                        dut_error("Opcode is Wrong!");
2161
                                                };
2162
                                                if (alu_enable != 0) {
2163
                                                        dut_error("ASL_ACC is Wrong!");
2164
                                                };
2165
                                                if (mem_rw != 0) {
2166
                                                        dut_error("MEM_RW should be 0 (WRITE)");
2167
                                                };
2168
                                                if (addr[7:0] != PCL + X) {
2169
                                                        dut_error("ADDR should be equal SP!");
2170
                                                };
2171
                                        };
2172
                                        (
2173 212 creep
                                          instructions == LDX_ZPY ||
2174
                                          instructions == LDA_ABY ||
2175
                                          instructions == LDX_ABY ||
2176
                                          instructions == EOR_ABY ||
2177
                                          instructions == AND_ABY ||
2178
                                          instructions == ORA_ABY ||
2179
                                          instructions == ADC_ABY ||
2180
                                          instructions == SBC_ABY ||
2181
                                          instructions == CMP_ABY
2182
                                        ) : {
2183
                                                if (alu_opcode.as_a(byte) != 0) {
2184
                                                        dut_error("Opcode is Wrong!");
2185
                                                };
2186
                                                if (alu_enable != 0) {
2187
                                                        dut_error("ASL_ACC is Wrong!");
2188
                                                };
2189
                                                if (mem_rw != 0) {
2190
                                                        dut_error("MEM_RW should be 0 (WRITE)");
2191
                                                };
2192
                                                if (addr[7:0] != PCL + Y - 256) {
2193
                                                        dut_error("ADDR is wrong!");
2194
                                                };
2195
                                                if (addr[12:8] != PCH[4:0] + 1) {
2196
                                                        dut_error("ADDR is wrong!");
2197
                                                };
2198
                                        };
2199
                                        (
2200
                                          instructions == ASL_ZPX ||
2201
                                          instructions == LSR_ZPX ||
2202
                                          instructions == ROL_ZPX ||
2203
                                          instructions == ROR_ZPX ||
2204
                                          instructions == INC_ZPX ||
2205
                                          instructions == DEC_ZPX
2206
                                        ) : {
2207
                                                if (alu_opcode != instructions) {
2208
                                                        dut_error("Opcode is Wrong!");
2209
                                                };
2210
                                                if (alu_enable != 1) {
2211
                                                        dut_error("ASL_ACC is Wrong!");
2212
                                                };
2213
                                                if (mem_rw != 1) {
2214
                                                        dut_error("MEM_RW should be 0 (WRITE)");
2215
                                                };
2216 214 creep
                                                if (PCL + X > 255) {
2217
                                                        if (addr[7:0] != PCL + X - 256) {
2218
                                                                dut_error("ADDR should be equal SP!");
2219
                                                        };
2220
                                                }
2221
                                                else {
2222
                                                        if (addr[7:0] != PCL + X) {
2223
                                                                dut_error("ADDR should be equal SP!");
2224
                                                        };
2225 212 creep
                                                };
2226
                                        };
2227
                                        (
2228 206 creep
                                          instructions == ASL_ABS ||
2229
                                          instructions == DEC_ABS ||
2230
                                          instructions == INC_ABS ||
2231
                                          instructions == LSR_ABS ||
2232
                                          instructions == ROL_ABS ||
2233
                                          instructions == ROR_ABS
2234
                                        ) : {
2235
                                                if (alu_opcode != instructions) {
2236
                                                        dut_error("Opcode is Wrong!");
2237
                                                };
2238
                                                if (mem_rw != 1) {
2239
                                                        dut_error("MEM_RW should be 1 (WRITE)");
2240
                                                };
2241
                                                if (alu_enable != 1) {
2242
                                                        dut_error("BRK_IMP is Wrong!");
2243
                                                };
2244
                                                if (addr[7:0] != PCL) {
2245
                                                        dut_error("ADDR should be equal SP!");
2246
                                                };
2247
                                                if (addr[12:8] != PCH[4:0]) {
2248
                                                        dut_error("ADDR should be equal SP!");
2249
                                                };
2250
                                        };
2251
                                };
2252
                        };
2253
                        CYCLE_6 : {
2254
                                print_state();
2255
                                print addr;
2256
                                case {
2257
                                        (
2258
                                          instructions == BRK_IMP
2259
                                        ) : {
2260
                                                if (alu_opcode.as_a(byte) != 0) {
2261
                                                        dut_error("Opcode is Wrong!");
2262
                                                };
2263
                                                if (mem_rw != 0) {
2264
                                                        dut_error("MEM_RW should be 1 (WRITE)");
2265
                                                };
2266
                                                if (alu_enable != 0) {
2267
                                                        dut_error("BRK_IMP is Wrong!");
2268
                                                };
2269
                                                if (addr != 13'b1111111111110) {
2270
                                                        dut_error("BRK_IMP is Wrong!");
2271
                                                };
2272
                                                PC[7:0] = PCL;
2273
                                        };
2274 241 creep
                                        instructions == JSR_ABS : {
2275
                                                if (alu_opcode.as_a(byte) != 0) {
2276
                                                        dut_error("Opcode is Wrong!");
2277
                                                };
2278
                                                if (mem_rw != 0) {
2279
                                                        dut_error("MEM_RW should be 1 (WRITE)");
2280
                                                };
2281
                                                if (alu_enable != 0) {
2282
                                                        dut_error("JSR_ABS is Wrong!");
2283
                                                };
2284
                                                if (addr != PC) {
2285
                                                        dut_error("ADDR should be equal SP!");
2286
                                                };
2287
                                                PC [7:0] = PCL;
2288
                                                PC[12:8] = PCH[4:0];
2289
                                        };
2290 206 creep
                                        (
2291 214 creep
                                          instructions == LDA_IDX ||
2292
                                          instructions == ORA_IDX ||
2293
                                          instructions == EOR_IDX ||
2294
                                          instructions == AND_IDX ||
2295
                                          instructions == ADC_IDX ||
2296
                                          instructions == CMP_IDX ||
2297
                                          instructions == SBC_IDX
2298
                                        ) : {
2299
                                                if (alu_opcode.as_a(byte) != 0) {
2300
                                                        dut_error("Opcode is Wrong!");
2301
                                                };
2302
                                                if (alu_enable != 0) {
2303
                                                        dut_error("ASL_ACC is Wrong!");
2304
                                                };
2305
                                                if (mem_rw != 0) {
2306
                                                        dut_error("MEM_RW should be 0 (WRITE)");
2307
                                                };
2308
                                                if (addr[7:0] != PCL) {
2309
                                                        dut_error("ADDR is wrong");
2310
                                                };
2311
                                                if (addr[12:8] != PCH[4:0]) {
2312
                                                        dut_error("ADDR is wrong");
2313
                                                };
2314
                                        };
2315
                                        (
2316 215 creep
                                          instructions == LDA_IDY ||
2317
                                          --instructions == STA_IDY ||
2318
                                          instructions == ORA_IDY ||
2319
                                          instructions == EOR_IDY ||
2320
                                          instructions == AND_IDY ||
2321
                                          instructions == ADC_IDY ||
2322
                                          instructions == CMP_IDY ||
2323
                                          instructions == SBC_IDY
2324 214 creep
                                        ) : {
2325
                                                if (alu_opcode.as_a(byte) != 0) {
2326
                                                        dut_error("Opcode is Wrong!");
2327
                                                };
2328
                                                if (alu_enable != 0) {
2329
                                                        dut_error("ASL_ACC is Wrong!");
2330
                                                };
2331 215 creep
                                                if (mem_rw != 0) {
2332
                                                        dut_error("MEM_RW should be 0 (WRITE)");
2333
                                                };
2334
                                                if (addr[7:0] != PCL + Y - 256) {
2335
                                                        dut_error("ADDR is wrong");
2336
                                                };
2337
                                                if (addr[12:8] != PCH[4:0] + 1) {
2338
                                                        print PCH, addr[12:8];
2339
                                                        print PCL + Y, addr[7:0];
2340
                                                        dut_error("ADDR is wrong");
2341
                                                };
2342
                                        };
2343
                                        (
2344 216 creep
                                          instructions == STA_IDY
2345
                                        ) : {
2346
                                                if (alu_opcode.as_a(byte) != 0) {
2347
                                                        dut_error("Opcode is Wrong!");
2348
                                                };
2349
                                                if (alu_enable != 0) {
2350
                                                        dut_error("ASL_ACC is Wrong!");
2351
                                                };
2352
                                                if (mem_rw != 1) {
2353
                                                        dut_error("MEM_RW should be 0 (WRITE)");
2354
                                                };
2355
                                                if (PCL + Y > 255) {
2356
                                                        if (addr[7:0] != PCL + Y - 256) {
2357
                                                                dut_error("ADDR is wrong");
2358
                                                        };
2359
                                                        if (addr[12:8] != PCH[4:0] + 1) {
2360
                                                                dut_error("ADDR is wrong");
2361
                                                        };
2362
                                                }
2363
                                                else {
2364
                                                        if (addr[7:0] != PCL + Y) {
2365
                                                                dut_error("ADDR is wrong");
2366
                                                        };
2367
                                                        if (addr[12:8] != PCH[4:0]) {
2368
                                                                dut_error("ADDR is wrong");
2369
                                                        };
2370
                                                };
2371
                                        };
2372
                                        (
2373 215 creep
                                          instructions == STA_IDX
2374
                                        ) : {
2375
                                                if (alu_opcode.as_a(byte) != 0) {
2376
                                                        dut_error("Opcode is Wrong!");
2377
                                                };
2378
                                                if (alu_enable != 0) {
2379
                                                        dut_error("ASL_ACC is Wrong!");
2380
                                                };
2381 214 creep
                                                if (mem_rw != 1) {
2382
                                                        dut_error("MEM_RW should be 0 (WRITE)");
2383
                                                };
2384
                                                if (addr[7:0] != PCL) {
2385
                                                        dut_error("ADDR is wrong");
2386
                                                };
2387
                                                if (addr[12:8] != PCH[4:0]) {
2388
                                                        dut_error("ADDR is wrong");
2389
                                                };
2390
                                        };
2391
                                        (
2392 206 creep
                                          instructions == RTI_IMP
2393
                                        ) : {
2394
                                                if (alu_opcode.as_a(byte) != 0) {
2395
                                                        dut_error("Opcode is Wrong!");
2396
                                                };
2397
                                                if (mem_rw != 0) {
2398
                                                        dut_error("MEM_RW should be 1 (WRITE)");
2399
                                                };
2400
                                                if (alu_enable != 0) {
2401
                                                        dut_error("RTI_IMP is Wrong!");
2402
                                                };
2403
                                                if (addr != SP + 256) {
2404
                                                        dut_error("ADDR should be equal SP!");
2405
                                                };
2406
                                                PC[12:8] = PCH[4:0];
2407
                                        };
2408
                                        (
2409
                                          instructions == RTS_IMP
2410
                                        ) : {
2411
                                                if (alu_opcode.as_a(byte) != 0) {
2412
                                                        dut_error("Opcode is Wrong!");
2413
                                                };
2414
                                                if (mem_rw != 0) {
2415
                                                        dut_error("MEM_RW should be 1 (WRITE)");
2416
                                                };
2417
                                                if (alu_enable != 0) {
2418
                                                        dut_error("RTI_IMP is Wrong!");
2419
                                                };
2420
                                                if (addr != PC) {
2421
                                                        dut_error("ADDR should be equal SP!");
2422
                                                };
2423
                                                PC = PC + 1;
2424
                                        };
2425
                                        (
2426 212 creep
                                          instructions == ASL_ZPX ||
2427
                                          instructions == LSR_ZPX ||
2428
                                          instructions == ROL_ZPX ||
2429
                                          instructions == ROR_ZPX ||
2430
                                          instructions == INC_ZPX ||
2431
                                          instructions == DEC_ZPX
2432
                                        ) : {
2433
                                                if (alu_opcode.as_a(byte) != 0) {
2434
                                                        dut_error("Opcode is Wrong!");
2435
                                                };
2436
                                                if (alu_enable != 0) {
2437
                                                        dut_error("ASL_ACC is Wrong!");
2438
                                                };
2439
                                                if (mem_rw != 1) {
2440
                                                        dut_error("MEM_RW should be 0 (WRITE)");
2441
                                                };
2442 214 creep
                                                if (PCL + X > 255) {
2443
                                                        if (addr[7:0] != PCL + X - 256) {
2444
                                                                dut_error("ADDR should be equal SP!");
2445
                                                        };
2446
                                                }
2447
                                                else {
2448
                                                        if (addr[7:0] != PCL + X) {
2449
                                                                dut_error("ADDR should be equal SP!");
2450
                                                        };
2451 212 creep
                                                };
2452
                                        };
2453
                                        (
2454 214 creep
                                          more_cycles == TRUE &&
2455
                                          (
2456
                                                instructions == ASL_ABX ||
2457
                                                instructions == LSR_ABX ||
2458
                                                instructions == ROL_ABX ||
2459
                                                instructions == ROR_ABX ||
2460
                                                instructions == INC_ABX ||
2461
                                                instructions == DEC_ABX
2462
                                          )
2463
                                        ) : {
2464
                                                if (alu_opcode != instructions) {
2465
                                                        dut_error("Opcode is Wrong!");
2466
                                                };
2467
                                                if (alu_enable != 1) {
2468
                                                        dut_error("ASL_ACC is Wrong!");
2469
                                                };
2470
                                                if (mem_rw != 1) {
2471
                                                        dut_error("MEM_RW should be 0 (WRITE)");
2472
                                                };
2473
                                                if (addr[7:0] != PCL + X - 256) {
2474
                                                        dut_error("ADDR is wrong!");
2475
                                                };
2476
                                                if (addr[12:8] != PCH[4:0] + 1) {
2477
                                                        dut_error("ADDR is wrong!");
2478
                                                };
2479
                                        };
2480
                                        (
2481
                                          more_cycles == FALSE &&
2482
                                          (
2483
                                                instructions == ASL_ABX ||
2484
                                                instructions == LSR_ABX ||
2485
                                                instructions == ROL_ABX ||
2486
                                                instructions == ROR_ABX ||
2487
                                                instructions == INC_ABX ||
2488
                                                instructions == DEC_ABX
2489
                                          )
2490
                                        ) : {
2491
                                                if (alu_opcode != instructions) {
2492
                                                        dut_error("Opcode is Wrong!");
2493
                                                };
2494
                                                if (alu_enable != 1) {
2495
                                                        dut_error("ASL_ACC is Wrong!");
2496
                                                };
2497
                                                if (mem_rw != 1) {
2498
                                                        dut_error("MEM_RW should be 0 (WRITE)");
2499
                                                };
2500
                                                if (addr[7:0] != PCL + X) {
2501
                                                        dut_error("ADDR is wrong!");
2502
                                                };
2503
                                                if (addr[12:8] != PCH[4:0]) {
2504
                                                        dut_error("ADDR is wrong!");
2505
                                                };
2506
                                        };
2507
                                        (
2508 206 creep
                                          instructions == ASL_ABS ||
2509
                                          instructions == DEC_ABS ||
2510
                                          instructions == INC_ABS ||
2511
                                          instructions == LSR_ABS ||
2512
                                          instructions == ROL_ABS ||
2513
                                          instructions == ROR_ABS
2514
                                        ) : {
2515
                                                if (alu_opcode.as_a(byte) != 0) {
2516
                                                        dut_error("Opcode is Wrong!");
2517
                                                };
2518
                                                if (mem_rw != 1) {
2519
                                                        dut_error("MEM_RW should be 1 (WRITE)");
2520
                                                };
2521
                                                if (alu_enable != 0) {
2522
                                                        dut_error("BRK_IMP is Wrong!");
2523
                                                };
2524
                                                if (addr[7:0] != PCL) {
2525
                                                        dut_error("ADDR should be equal SP!");
2526
                                                };
2527
                                                if (addr[12:8] != PCH[4:0]) {
2528
                                                        dut_error("ADDR should be equal SP!");
2529
                                                };
2530
                                        };
2531
                                };
2532
                        };
2533
                        CYCLE_7 : {
2534
                                print_state();
2535
                                print addr;
2536
                                case {
2537
                                        (
2538 214 creep
                                          more_cycles == TRUE &&
2539
                                          (
2540
                                                instructions == ASL_ABX ||
2541
                                                instructions == LSR_ABX ||
2542
                                                instructions == ROL_ABX ||
2543
                                                instructions == ROR_ABX ||
2544
                                                instructions == INC_ABX ||
2545
                                                instructions == DEC_ABX
2546
                                          )
2547
                                        ) : {
2548
                                                if (alu_opcode.as_a(byte) != 0) {
2549
                                                        dut_error("Opcode is Wrong!");
2550
                                                };
2551
                                                if (alu_enable != 0) {
2552
                                                        dut_error("ASL_ACC is Wrong!");
2553
                                                };
2554
                                                if (mem_rw != 1) {
2555
                                                        dut_error("MEM_RW should be 0 (WRITE)");
2556
                                                };
2557
                                                if (addr[7:0] != PCL + X - 256) {
2558
                                                        dut_error("ADDR is wrong!");
2559
                                                };
2560
                                                if (addr[12:8] != PCH[4:0] + 1) {
2561
                                                        dut_error("ADDR is wrong!");
2562
                                                };
2563
                                        };
2564
                                        (
2565
                                          more_cycles == FALSE &&
2566
                                          (
2567
                                                instructions == ASL_ABX ||
2568
                                                instructions == LSR_ABX ||
2569
                                                instructions == ROL_ABX ||
2570
                                                instructions == ROR_ABX ||
2571
                                                instructions == INC_ABX ||
2572
                                                instructions == DEC_ABX
2573
                                          )
2574
                                        ) : {
2575
                                                if (alu_opcode.as_a(byte) != 0) {
2576
                                                        dut_error("Opcode is Wrong!");
2577
                                                };
2578
                                                if (alu_enable != 0) {
2579
                                                        dut_error("ASL_ACC is Wrong!");
2580
                                                };
2581
                                                if (mem_rw != 1) {
2582
                                                        dut_error("MEM_RW should be 0 (WRITE)");
2583
                                                };
2584
                                                if (addr[7:0] != PCL + X) {
2585
                                                        dut_error("ADDR is wrong!");
2586
                                                };
2587
                                                if (addr[12:8] != PCH[4:0]) {
2588
                                                        dut_error("ADDR is wrong!");
2589
                                                };
2590
                                        };
2591
                                        (
2592 206 creep
                                          instructions == BRK_IMP
2593
                                        ) : {
2594
                                                if (alu_opcode.as_a(byte) != 0) {
2595
                                                        dut_error("Opcode is Wrong!");
2596
                                                };
2597
                                                if (mem_rw != 0) {
2598
                                                        dut_error("MEM_RW should be 1 (WRITE)");
2599
                                                };
2600
                                                if (alu_enable != 0) {
2601
                                                        dut_error("BRK_IMP is Wrong!");
2602
                                                };
2603
                                                if (addr != 13'b1111111111111) {
2604
                                                        dut_error("BRK_IMP is Wrong!");
2605
                                                };
2606
                                                PC[12:8] = PCH[4:0];
2607
                                        };
2608
                                };
2609
                        };
2610
                };
2611
        old_state = new_state;
2612
        };
2613
};
2614
'>

powered by: WebSVN 2.1.0

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