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

Subversion Repositories t6507lp

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

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

powered by: WebSVN 2.1.0

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