-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcpu.prg
More file actions
1678 lines (1506 loc) · 55.5 KB
/
cpu.prg
File metadata and controls
1678 lines (1506 loc) · 55.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//#define XHB_BITOP // Habilita das operações | & ^^
#include "xhb.ch"
#include "common.ch"
#include "hbclass.ch"
#translate ( <exp1> | <exp2> ) => ( hb_qbitOr( ( <exp1> ), ( <exp2> ) ) )
#translate ( <exp1> & <exp2> ) => ( hb_qbitAnd( ( <exp1> ), ( <exp2> ) ) )
#translate ( <exp1> ^^ <exp2> ) => ( hb_qbitXor( ( <exp1> ), ( <exp2> ) ) )
Static nH:=0
Static instructionModes := {;
6 , 7, 6, 7, 11, 11, 11, 11, 6, 5, 4, 5, 1, 1, 1, 1,;
10, 9, 6, 9, 12, 12, 12, 12, 6, 3, 6, 3, 2, 2, 2, 2,;
1 , 7, 6, 7, 11, 11, 11, 11, 6, 5, 4, 5, 1, 1, 1, 1,;
10, 9, 6, 9, 12, 12, 12, 12, 6, 3, 6, 3, 2, 2, 2, 2,;
6 , 7, 6, 7, 11, 11, 11, 11, 6, 5, 4, 5, 1, 1, 1, 1,;
10, 9, 6, 9, 12, 12, 12, 12, 6, 3, 6, 3, 2, 2, 2, 2,;
6 , 7, 6, 7, 11, 11, 11, 11, 6, 5, 4, 5, 8, 1, 1, 1,;
10, 9, 6, 9, 12, 12, 12, 12, 6, 3, 6, 3, 2, 2, 2, 2,;
5 , 7, 5, 7, 11, 11, 11, 11, 6, 5, 6, 5, 1, 1, 1, 1,;
10, 9, 6, 9, 12, 12, 13, 13, 6, 3, 6, 3, 2, 2, 3, 3,;
5 , 7, 5, 7, 11, 11, 11, 11, 6, 5, 6, 5, 1, 1, 1, 1,;
10, 9, 6, 9, 12, 12, 13, 13, 6, 3, 6, 3, 2, 2, 3, 3,;
5 , 7, 5, 7, 11, 11, 11, 11, 6, 5, 6, 5, 1, 1, 1, 1,;
10, 9, 6, 9, 12, 12, 12, 12, 6, 3, 6, 3, 2, 2, 2, 2,;
5 , 7, 5, 7, 11, 11, 11, 11, 6, 5, 6, 5, 1, 1, 1, 1,;
10, 9, 6, 9, 12, 12, 12, 12, 6, 3, 6, 3, 2, 2, 2, 2;
}
// instructionSizes indicates the size of each instruction in bytes
Static instructionSizes := {;
2, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,;
2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 3, 3, 3, 0,;
3, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,;
2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 3, 3, 3, 0,;
1, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,;
2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 3, 3, 3, 0,;
1, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,;
2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 3, 3, 3, 0,;
2, 2, 0, 0, 2, 2, 2, 0, 1, 0, 1, 0, 3, 3, 3, 0,;
2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 0, 3, 0, 0,;
2, 2, 2, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,;
2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 3, 3, 3, 0,;
2, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,;
2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 3, 3, 3, 0,;
2, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,;
2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 3, 3, 3, 0;
}
// instructionCycles indicates the number of cycles used by each instruction,
// not including conditional cycles
Static instructionCycles := {;
7, 6, 2, 8, 3, 3, 5, 5, 3, 2, 2, 2, 4, 4, 6, 6,;
2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7,;
6, 6, 2, 8, 3, 3, 5, 5, 4, 2, 2, 2, 4, 4, 6, 6,;
2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7,;
6, 6, 2, 8, 3, 3, 5, 5, 3, 2, 2, 2, 3, 4, 6, 6,;
2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7,;
6, 6, 2, 8, 3, 3, 5, 5, 4, 2, 2, 2, 5, 4, 6, 6,;
2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7,;
2, 6, 2, 6, 3, 3, 3, 3, 2, 2, 2, 2, 4, 4, 4, 4,;
2, 6, 2, 6, 4, 4, 4, 4, 2, 5, 2, 5, 5, 5, 5, 5,;
2, 6, 2, 6, 3, 3, 3, 3, 2, 2, 2, 2, 4, 4, 4, 4,;
2, 5, 2, 5, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 4, 4,;
2, 6, 2, 8, 3, 3, 5, 5, 2, 2, 2, 2, 4, 4, 6, 6,;
2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7,;
2, 6, 2, 8, 3, 3, 5, 5, 2, 2, 2, 2, 4, 4, 6, 6,;
2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7;
}
// instructionPageCycles indicates the number of cycles used by each
// instruction when a page is crossed
Static instructionPageCycles := {;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,;
1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0,;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,;
1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0,;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,;
1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0,;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,;
1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0,;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,;
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,;
1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1,;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,;
1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0,;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,;
1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0;
}
// instructionNames indicates the name of each instruction
Static instructionNames := {;
"BRK", "ORA", "KIL", "SLO", "NOP", "ORA", "ASL", "SLO",;
"PHP", "ORA", "ASL", "ANC", "NOP", "ORA", "ASL", "SLO",;
"BPL", "ORA", "KIL", "SLO", "NOP", "ORA", "ASL", "SLO",;
"CLC", "ORA", "NOP", "SLO", "NOP", "ORA", "ASL", "SLO",;
"JSR", "AND", "KIL", "RLA", "BIT", "AND", "ROL", "RLA",;
"PLP", "AND", "ROL", "ANC", "BIT", "AND", "ROL", "RLA",;
"BMI", "AND", "KIL", "RLA", "NOP", "AND", "ROL", "RLA",;
"SEC", "AND", "NOP", "RLA", "NOP", "AND", "ROL", "RLA",;
"RTI", "EOR", "KIL", "SRE", "NOP", "EOR", "LSR", "SRE",;
"PHA", "EOR", "LSR", "ALR", "JMP", "EOR", "LSR", "SRE",;
"BVC", "EOR", "KIL", "SRE", "NOP", "EOR", "LSR", "SRE",;
"CLI", "EOR", "NOP", "SRE", "NOP", "EOR", "LSR", "SRE",;
"RTS", "ADC", "KIL", "RRA", "NOP", "ADC", "ROR", "RRA",;
"PLA", "ADC", "ROR", "ARR", "JMP", "ADC", "ROR", "RRA",;
"BVS", "ADC", "KIL", "RRA", "NOP", "ADC", "ROR", "RRA",;
"SEI", "ADC", "NOP", "RRA", "NOP", "ADC", "ROR", "RRA",;
"NOP", "STA", "NOP", "SAX", "STY", "STA", "STX", "SAX",;
"DEY", "NOP", "TXA", "XAA", "STY", "STA", "STX", "SAX",;
"BCC", "STA", "KIL", "AHX", "STY", "STA", "STX", "SAX",;
"TYA", "STA", "TXS", "TAS", "SHY", "STA", "SHX", "AHX",;
"LDY", "LDA", "LDX", "LAX", "LDY", "LDA", "LDX", "LAX",;
"TAY", "LDA", "TAX", "LAX", "LDY", "LDA", "LDX", "LAX",;
"BCS", "LDA", "KIL", "LAX", "LDY", "LDA", "LDX", "LAX",;
"CLV", "LDA", "TSX", "LAS", "LDY", "LDA", "LDX", "LAX",;
"CPY", "CMP", "NOP", "DCP", "CPY", "CMP", "DEC", "DCP",;
"INY", "CMP", "DEX", "AXS", "CPY", "CMP", "DEC", "DCP",;
"BNE", "CMP", "KIL", "DCP", "NOP", "CMP", "DEC", "DCP",;
"CLD", "CMP", "NOP", "DCP", "NOP", "CMP", "DEC", "DCP",;
"CPX", "SBC", "NOP", "ISC", "CPX", "SBC", "INC", "ISC",;
"INX", "SBC", "NOP", "SBC", "CPX", "SBC", "INC", "ISC",;
"BEQ", "SBC", "KIL", "ISC", "NOP", "SBC", "INC", "ISC",;
"SED", "SBC", "NOP", "ISC", "NOP", "SBC", "INC", "ISC";
}
CREATE CLASS CPU
VAR Memory
VAR Cycles INIT 0 // number of cycles
VAR PC INIT 0 // program counter
VAR SP INIT 0 // stack pointer
VAR A INIT 0 // accumulator
VAR X INIT 0 // x register
VAR Y INIT 0 // y register
VAR C INIT 0 // carry flag
VAR Z INIT 0 // zero flag
VAR I INIT 0 // interrupt disable flag
VAR D INIT 0 // decimal mode flag
VAR B INIT 0 // break command flag
VAR U INIT 0 // unused flag
VAR V INIT 0 // overflow flag
VAR N INIT 0 // negative flag
VAR interrupt INIT 0 // interrupt type to perform
VAR stall INIT 0 // number of cycles to stall
VAR table INIT {}
VAR cOphash INIT {=>}
METHOD New(console)
METHOD Reset()
METHOD PrintInstruction()
METHOD PrintReg()
METHOD addBranchCycles(info)
METHOD compare(a, b)
METHOD Read16(address)
METHOD read16bug(address)
METHOD push(value)
METHOD pull()
METHOD push16(value)
METHOD pull16()
METHOD Flags()
METHOD SetFlags(flags)
METHOD setZ(value)
METHOD setN(value)
METHOD setZN(value)
METHOD triggerNMI()
METHOD triggerIRQ()
METHOD Step()
METHOD nmi()
METHOD irq()
METHOD adc(info)
METHOD and(info)
METHOD asl(info)
METHOD bcc(info)
METHOD bcs(info)
METHOD beq(info)
METHOD bit(info)
METHOD bmi(info)
METHOD bne(info)
METHOD bpl(info)
METHOD brk(info)
METHOD bvc(info)
METHOD bvs(info)
METHOD clc(info)
METHOD cld(info)
METHOD cli(info)
METHOD clv(info)
METHOD cmp(info)
METHOD cpx(info)
METHOD cpy(info)
METHOD dec(info)
METHOD dex(info)
METHOD dey(info)
METHOD eor(info)
METHOD inc(info)
METHOD inx(info)
METHOD iny(info)
METHOD jmp(info)
METHOD jsr(info)
METHOD lda(info)
METHOD ldx(info)
METHOD ldy(info)
METHOD lsr(info)
METHOD nop(info)
METHOD ora(info)
METHOD pha(info)
METHOD php(info)
METHOD pla(info)
METHOD plp(info)
METHOD rol(info)
METHOD ror(info)
METHOD rti(info)
METHOD rts(info)
METHOD sbc(info)
METHOD sec(info)
METHOD sed(info)
METHOD sei(info)
METHOD sta(info)
METHOD stx(info)
METHOD sty(info)
METHOD tax(info)
METHOD tay(info)
METHOD tsx(info)
METHOD txa(info)
METHOD txs(info)
METHOD tya(info)
METHOD ahx(info)
METHOD alr(info)
METHOD anc(info)
METHOD arr(info)
METHOD axs(info)
METHOD dcp(info)
METHOD isc(info)
METHOD kil(info)
METHOD las(info)
METHOD lax(info)
METHOD rla(info)
METHOD rra(info)
METHOD sax(info)
METHOD shx(info)
METHOD shy(info)
METHOD slo(info)
METHOD sre(info)
METHOD tas(info)
METHOD xaa(info)
END CLASS
METHOD New(console) CLASS CPU
::Memory= Memory():New(@console)
::Reset()
::table = {;
{|x|::brk(x)}, {|x|::ora(x)}, {|x|::kil(x)}, {|x|::slo(x)}, {|x|::nop(x)}, {|x|::ora(x)}, {|x|::asl(x)}, {|x|::slo(x)},;
{|x|::php(x)}, {|x|::ora(x)}, {|x|::asl(x)}, {|x|::anc(x)}, {|x|::nop(x)}, {|x|::ora(x)}, {|x|::asl(x)}, {|x|::slo(x)},;
{|x|::bpl(x)}, {|x|::ora(x)}, {|x|::kil(x)}, {|x|::slo(x)}, {|x|::nop(x)}, {|x|::ora(x)}, {|x|::asl(x)}, {|x|::slo(x)},;
{|x|::clc(x)}, {|x|::ora(x)}, {|x|::nop(x)}, {|x|::slo(x)}, {|x|::nop(x)}, {|x|::ora(x)}, {|x|::asl(x)}, {|x|::slo(x)},;
{|x|::jsr(x)}, {|x|::and(x)}, {|x|::kil(x)}, {|x|::rla(x)}, {|x|::bit(x)}, {|x|::and(x)}, {|x|::rol(x)}, {|x|::rla(x)},;
{|x|::plp(x)}, {|x|::and(x)}, {|x|::rol(x)}, {|x|::anc(x)}, {|x|::bit(x)}, {|x|::and(x)}, {|x|::rol(x)}, {|x|::rla(x)},;
{|x|::bmi(x)}, {|x|::and(x)}, {|x|::kil(x)}, {|x|::rla(x)}, {|x|::nop(x)}, {|x|::and(x)}, {|x|::rol(x)}, {|x|::rla(x)},;
{|x|::sec(x)}, {|x|::and(x)}, {|x|::nop(x)}, {|x|::rla(x)}, {|x|::nop(x)}, {|x|::and(x)}, {|x|::rol(x)}, {|x|::rla(x)},;
{|x|::rti(x)}, {|x|::eor(x)}, {|x|::kil(x)}, {|x|::sre(x)}, {|x|::nop(x)}, {|x|::eor(x)}, {|x|::lsr(x)}, {|x|::sre(x)},;
{|x|::pha(x)}, {|x|::eor(x)}, {|x|::lsr(x)}, {|x|::alr(x)}, {|x|::jmp(x)}, {|x|::eor(x)}, {|x|::lsr(x)}, {|x|::sre(x)},;
{|x|::bvc(x)}, {|x|::eor(x)}, {|x|::kil(x)}, {|x|::sre(x)}, {|x|::nop(x)}, {|x|::eor(x)}, {|x|::lsr(x)}, {|x|::sre(x)},;
{|x|::cli(x)}, {|x|::eor(x)}, {|x|::nop(x)}, {|x|::sre(x)}, {|x|::nop(x)}, {|x|::eor(x)}, {|x|::lsr(x)}, {|x|::sre(x)},;
{|x|::rts(x)}, {|x|::adc(x)}, {|x|::kil(x)}, {|x|::rra(x)}, {|x|::nop(x)}, {|x|::adc(x)}, {|x|::ror(x)}, {|x|::rra(x)},;
{|x|::pla(x)}, {|x|::adc(x)}, {|x|::ror(x)}, {|x|::arr(x)}, {|x|::jmp(x)}, {|x|::adc(x)}, {|x|::ror(x)}, {|x|::rra(x)},;
{|x|::bvs(x)}, {|x|::adc(x)}, {|x|::kil(x)}, {|x|::rra(x)}, {|x|::nop(x)}, {|x|::adc(x)}, {|x|::ror(x)}, {|x|::rra(x)},;
{|x|::sei(x)}, {|x|::adc(x)}, {|x|::nop(x)}, {|x|::rra(x)}, {|x|::nop(x)}, {|x|::adc(x)}, {|x|::ror(x)}, {|x|::rra(x)},;
{|x|::nop(x)}, {|x|::sta(x)}, {|x|::nop(x)}, {|x|::sax(x)}, {|x|::sty(x)}, {|x|::sta(x)}, {|x|::stx(x)}, {|x|::sax(x)},;
{|x|::dey(x)}, {|x|::nop(x)}, {|x|::txa(x)}, {|x|::xaa(x)}, {|x|::sty(x)}, {|x|::sta(x)}, {|x|::stx(x)}, {|x|::sax(x)},;
{|x|::bcc(x)}, {|x|::sta(x)}, {|x|::kil(x)}, {|x|::ahx(x)}, {|x|::sty(x)}, {|x|::sta(x)}, {|x|::stx(x)}, {|x|::sax(x)},;
{|x|::tya(x)}, {|x|::sta(x)}, {|x|::txs(x)}, {|x|::tas(x)}, {|x|::shy(x)}, {|x|::sta(x)}, {|x|::shx(x)}, {|x|::ahx(x)},;
{|x|::ldy(x)}, {|x|::lda(x)}, {|x|::ldx(x)}, {|x|::lax(x)}, {|x|::ldy(x)}, {|x|::lda(x)}, {|x|::ldx(x)}, {|x|::lax(x)},;
{|x|::tay(x)}, {|x|::lda(x)}, {|x|::tax(x)}, {|x|::lax(x)}, {|x|::ldy(x)}, {|x|::lda(x)}, {|x|::ldx(x)}, {|x|::lax(x)},;
{|x|::bcs(x)}, {|x|::lda(x)}, {|x|::kil(x)}, {|x|::lax(x)}, {|x|::ldy(x)}, {|x|::lda(x)}, {|x|::ldx(x)}, {|x|::lax(x)},;
{|x|::clv(x)}, {|x|::lda(x)}, {|x|::tsx(x)}, {|x|::las(x)}, {|x|::ldy(x)}, {|x|::lda(x)}, {|x|::ldx(x)}, {|x|::lax(x)},;
{|x|::cpy(x)}, {|x|::cmp(x)}, {|x|::nop(x)}, {|x|::dcp(x)}, {|x|::cpy(x)}, {|x|::cmp(x)}, {|x|::dec(x)}, {|x|::dcp(x)},;
{|x|::iny(x)}, {|x|::cmp(x)}, {|x|::dex(x)}, {|x|::axs(x)}, {|x|::cpy(x)}, {|x|::cmp(x)}, {|x|::dec(x)}, {|x|::dcp(x)},;
{|x|::bne(x)}, {|x|::cmp(x)}, {|x|::kil(x)}, {|x|::dcp(x)}, {|x|::nop(x)}, {|x|::cmp(x)}, {|x|::dec(x)}, {|x|::dcp(x)},;
{|x|::cld(x)}, {|x|::cmp(x)}, {|x|::nop(x)}, {|x|::dcp(x)}, {|x|::nop(x)}, {|x|::cmp(x)}, {|x|::dec(x)}, {|x|::dcp(x)},;
{|x|::cpx(x)}, {|x|::sbc(x)}, {|x|::nop(x)}, {|x|::isc(x)}, {|x|::cpx(x)}, {|x|::sbc(x)}, {|x|::inc(x)}, {|x|::isc(x)},;
{|x|::inx(x)}, {|x|::sbc(x)}, {|x|::nop(x)}, {|x|::sbc(x)}, {|x|::cpx(x)}, {|x|::sbc(x)}, {|x|::inc(x)}, {|x|::isc(x)},;
{|x|::beq(x)}, {|x|::sbc(x)}, {|x|::kil(x)}, {|x|::isc(x)}, {|x|::nop(x)}, {|x|::sbc(x)}, {|x|::inc(x)}, {|x|::isc(x)},;
{|x|::sed(x)}, {|x|::sbc(x)}, {|x|::nop(x)}, {|x|::isc(x)}, {|x|::nop(x)}, {|x|::sbc(x)}, {|x|::inc(x)}, {|x|::isc(x)};
}
::cOphash={0 => {|x|::brk(x)},1 => {|x|::ora(x)},2 => {|x|::kil(x)},3 => {|x|::slo(x)},4 => {|x|::nop(x)},5 => {|x|::ora(x)},6 => {|x|::asl(x)},7 => {|x|::slo(x)},8 => {|x|::php(x)},;
9 => {|x|::ora(x)},10 => {|x|::asl(x)},11 => {|x|::anc(x)},12 => {|x|::nop(x)},13 => {|x|::ora(x)},14 => {|x|::asl(x)},15 => {|x|::slo(x)},16 => {|x|::bpl(x)},17 => {|x|::ora(x)},;
18 => {|x|::kil(x)},19 => {|x|::slo(x)},20 => {|x|::nop(x)},21 => {|x|::ora(x)},22 => {|x|::asl(x)},23 => {|x|::slo(x)},24 => {|x|::clc(x)},25 => {|x|::ora(x)},26 => {|x|::nop(x)},;
27 => {|x|::slo(x)},28 => {|x|::nop(x)},29 => {|x|::ora(x)},30 => {|x|::asl(x)},31 => {|x|::slo(x)},32 => {|x|::jsr(x)},33 => {|x|::and(x)},34 => {|x|::kil(x)},35 => {|x|::rla(x)},;
36 => {|x|::bit(x)},37 => {|x|::and(x)},38 => {|x|::rol(x)},39 => {|x|::rla(x)},40 => {|x|::plp(x)},41 => {|x|::and(x)},42 => {|x|::rol(x)},43 => {|x|::anc(x)},44 => {|x|::bit(x)},;
45 => {|x|::and(x)},46 => {|x|::rol(x)},47 => {|x|::rla(x)},48 => {|x|::bmi(x)},49 => {|x|::and(x)},50 => {|x|::kil(x)},51 => {|x|::rla(x)},52 => {|x|::nop(x)},53 => {|x|::and(x)},;
54 => {|x|::rol(x)},55 => {|x|::rla(x)},56 => {|x|::sec(x)},57 => {|x|::and(x)},58 => {|x|::nop(x)},59 => {|x|::rla(x)},60 => {|x|::nop(x)},61 => {|x|::and(x)},62 => {|x|::rol(x)},;
63 => {|x|::rla(x)},64 => {|x|::rti(x)},65 => {|x|::eor(x)},66 => {|x|::kil(x)},67 => {|x|::sre(x)},68 => {|x|::nop(x)},69 => {|x|::eor(x)},70 => {|x|::lsr(x)},71 => {|x|::sre(x)},;
72 => {|x|::pha(x)},73 => {|x|::eor(x)},74 => {|x|::lsr(x)},75 => {|x|::alr(x)},76 => {|x|::jmp(x)},77 => {|x|::eor(x)},78 => {|x|::lsr(x)},79 => {|x|::sre(x)},80 => {|x|::bvc(x)},;
81 => {|x|::eor(x)},82 => {|x|::kil(x)},83 => {|x|::sre(x)},84 => {|x|::nop(x)},85 => {|x|::eor(x)},86 => {|x|::lsr(x)},87 => {|x|::sre(x)},88 => {|x|::cli(x)},89 => {|x|::eor(x)},;
90 => {|x|::nop(x)},91 => {|x|::sre(x)},92 => {|x|::nop(x)},93 => {|x|::eor(x)},94 => {|x|::lsr(x)},95 => {|x|::sre(x)},96 => {|x|::rts(x)},97 => {|x|::adc(x)},98 => {|x|::kil(x)},;
99 => {|x|::rra(x)},100 => {|x|::nop(x)},101 => {|x|::adc(x)},102 => {|x|::ror(x)},103 => {|x|::rra(x)},104 => {|x|::pla(x)},105 => {|x|::adc(x)},106 => {|x|::ror(x)},107 => {|x|::arr(x)},;
108 => {|x|::jmp(x)},109 => {|x|::adc(x)},110 => {|x|::ror(x)},111 => {|x|::rra(x)},112 => {|x|::bvs(x)},113 => {|x|::adc(x)},114 => {|x|::kil(x)},115 => {|x|::rra(x)},116 => {|x|::nop(x)},;
117 => {|x|::adc(x)},118 => {|x|::ror(x)},119 => {|x|::rra(x)},120 => {|x|::sei(x)},121 => {|x|::adc(x)},122 => {|x|::nop(x)},123 => {|x|::rra(x)},124 => {|x|::nop(x)},125 => {|x|::adc(x)},;
126 => {|x|::ror(x)},127 => {|x|::rra(x)},128 => {|x|::nop(x)},129 => {|x|::sta(x)},130 => {|x|::nop(x)},131 => {|x|::sax(x)},132 => {|x|::sty(x)},133 => {|x|::sta(x)},134 => {|x|::stx(x)},;
135 => {|x|::sax(x)},136 => {|x|::dey(x)},137 => {|x|::nop(x)},138 => {|x|::txa(x)},139 => {|x|::xaa(x)},140 => {|x|::sty(x)},141 => {|x|::sta(x)},142 => {|x|::stx(x)},143 => {|x|::sax(x)},;
144 => {|x|::bcc(x)},145 => {|x|::sta(x)},146 => {|x|::kil(x)},147 => {|x|::ahx(x)},148 => {|x|::sty(x)},149 => {|x|::sta(x)},150 => {|x|::stx(x)},151 => {|x|::sax(x)},152 => {|x|::tya(x)},;
153 => {|x|::sta(x)},154 => {|x|::txs(x)},155 => {|x|::tas(x)},156 => {|x|::shy(x)},157 => {|x|::sta(x)},158 => {|x|::shx(x)},159 => {|x|::ahx(x)},160 => {|x|::ldy(x)},161 => {|x|::lda(x)},;
162 => {|x|::ldx(x)},163 => {|x|::lax(x)},164 => {|x|::ldy(x)},165 => {|x|::lda(x)},166 => {|x|::ldx(x)},167 => {|x|::lax(x)},168 => {|x|::tay(x)},169 => {|x|::lda(x)},170 => {|x|::tax(x)},;
171 => {|x|::lax(x)},172 => {|x|::ldy(x)},173 => {|x|::lda(x)},174 => {|x|::ldx(x)},175 => {|x|::lax(x)},176 => {|x|::bcs(x)},177 => {|x|::lda(x)},178 => {|x|::kil(x)},179 => {|x|::lax(x)},;
180 => {|x|::ldy(x)},181 => {|x|::lda(x)},182 => {|x|::ldx(x)},183 => {|x|::lax(x)},184 => {|x|::clv(x)},185 => {|x|::lda(x)},186 => {|x|::tsx(x)},187 => {|x|::las(x)},188 => {|x|::ldy(x)},;
189 => {|x|::lda(x)},190 => {|x|::ldx(x)},191 => {|x|::lax(x)},192 => {|x|::cpy(x)},193 => {|x|::cmp(x)},194 => {|x|::nop(x)},195 => {|x|::dcp(x)},196 => {|x|::cpy(x)},197 => {|x|::cmp(x)},;
198 => {|x|::dec(x)},199 => {|x|::dcp(x)},200 => {|x|::iny(x)},201 => {|x|::cmp(x)},202 => {|x|::dex(x)},203 => {|x|::axs(x)},204 => {|x|::cpy(x)},205 => {|x|::cmp(x)},206 => {|x|::dec(x)},;
207 => {|x|::dcp(x)},208 => {|x|::bne(x)},209 => {|x|::cmp(x)},210 => {|x|::kil(x)},211 => {|x|::dcp(x)},212 => {|x|::nop(x)},213 => {|x|::cmp(x)},214 => {|x|::dec(x)},215 => {|x|::dcp(x)},;
216 => {|x|::cld(x)},217 => {|x|::cmp(x)},218 => {|x|::nop(x)},219 => {|x|::dcp(x)},220 => {|x|::nop(x)},221 => {|x|::cmp(x)},222 => {|x|::dec(x)},223 => {|x|::dcp(x)},224 => {|x|::cpx(x)},;
225 => {|x|::sbc(x)},226 => {|x|::nop(x)},227 => {|x|::isc(x)},228 => {|x|::cpx(x)},229 => {|x|::sbc(x)},230 => {|x|::inc(x)},231 => {|x|::isc(x)},232 => {|x|::inx(x)},233 => {|x|::sbc(x)},;
234 => {|x|::nop(x)},235 => {|x|::sbc(x)},236 => {|x|::cpx(x)},237 => {|x|::sbc(x)},238 => {|x|::inc(x)},239 => {|x|::isc(x)},240 => {|x|::beq(x)},241 => {|x|::sbc(x)},242 => {|x|::kil(x)},;
243 => {|x|::isc(x)},244 => {|x|::nop(x)},245 => {|x|::sbc(x)},246 => {|x|::inc(x)},247 => {|x|::isc(x)},248 => {|x|::sed(x)},249 => {|x|::sbc(x)},250 => {|x|::nop(x)},251 => {|x|::isc(x)},;
252 => {|x|::nop(x)},253 => {|x|::sbc(x)},254 => {|x|::inc(x)},255 => {|x|::isc(x)}}
RETURN Self
// Reset resets the CPU to its initial powerup state
METHOD Reset() CLASS CPU
::PC = ::Read16(0xFFFC)
::SP = 0xFD
::SetFlags(0x24)
// PrintInstruction prints the current CPU state
METHOD PrintInstruction() CLASS CPU
local opcode,bytes,name,w0,w1,w2,xInstruction
opcode := ::Memory:Read(::PC)
bytes := instructionSizes[opcode+1]
name := instructionNames[opcode+1]
w0 := hb_numtohex(::Memory:Read(::PC+0),2)
w1 := hb_numtohex(::Memory:Read(::PC+1),2)
w2 := hb_numtohex(::Memory:Read(::PC+2),2)
if bytes < 2
w1 = " "
end if
if bytes < 3
w2 = " "
end if
xInstruction=space(5)
if !empty(w2) .or. !empty(w1)
xInstruction=padr("$"+alltrim(w2)+alltrim(w1),5," ")
end if
//scroll(16,0,maxrow(),59,+1)
//@ maxrow(),0 say hb_numtohex(::PC,4)+" : "+w0+" : "+alltrim(name)+" "+xInstruction
//nRow=row()
//nCol=col()
/*@ 0,60 say "Cycles : " + alltrim(str(::Cycles))
@ 1,60 say "PC : " + hb_numtohex(::PC,4)+" ("+alltrim(str(::PC))+") "
@ 2,60 say "SP : " + hb_numtohex(::SP,4)+" ("+alltrim(str(::SP))+") "
@ 3,60 say "A : " + hb_numtohex(::A,2)+" ("+alltrim(str(::A))+") "
@ 4,60 say "X : " + hb_numtohex(::X,2)+" ("+alltrim(str(::X))+") "
@ 5,60 say "Y : " + hb_numtohex(::Y,2)+" ("+alltrim(str(::Y))+") "
@ 7,60 say "C : " + hb_numtohex(::C,2)+" ("+alltrim(str(::C))+") "
@ 8,60 say "Z : " + hb_numtohex(::Z,2)+" ("+alltrim(str(::Z))+") "
@ 9,60 say "I : " + hb_numtohex(::I,2)+" ("+alltrim(str(::I))+") "
@ 10,60 say "D : " + hb_numtohex(::D,2)+" ("+alltrim(str(::D))+") "
@ 11,60 say "B : " + hb_numtohex(::B,2)+" ("+alltrim(str(::B))+") "
// @ 11,60 say "U : " + hb_numtohex(::U,2)+" ("+alltrim(str(::U))+")"
@ 12,60 say "V : " + hb_numtohex(::V,2)+" ("+alltrim(str(::V))+") "
// @ 13,60 say "N : " + hb_numtohex(::N,2)+" ("+alltrim(str(::N))+") "
@ 13,60 say "Interupt: " + hb_numtohex(::interrupt,2)+" ("+alltrim(str(::interrupt))+") "
// @ 15,60 say "Stall : " + alltrim(str(::stall))+" ("+alltrim(str(::PC))+")"
// setpos(0,0)*/
//," CPU - A:",hb_numtohex(::A,2),"X: ",hb_numtohex(::X,2),"Y: ",hb_numtohex(::Y,2)," F: ",hb_numtohex(::Flags(),1)," Sp:",hb_numtohex(::SP,4)," Cy:",(::Cycles*3) % 341
clog(::PC," ",w0," ", w1," ", w2," ", name, " A:",::A," X: ", ::X," Y:", ::Y, " P:",::Flags(), " SP:",::SP, " CYC:",(::Cycles*3) % 341)
METHOD PrintReg() CLASS CPU
@ 0,70 say "Cycles : " + alltrim(str(::Cycles))
@ 1,70 say "PC : " + hb_numtohex(::PC,4)+" ("+alltrim(str(::PC))+")"
@ 2,70 say "SP : " + hb_numtohex(::SP,4)+" ("+alltrim(str(::SP))+")"
@ 3,70 say "A : " + hb_numtohex(::A,2)+" ("+alltrim(str(::A))+")"
@ 4,70 say "X : " + hb_numtohex(::X,2)+" ("+alltrim(str(::X))+")"
@ 5,70 say "Y : " + hb_numtohex(::Y,2)+" ("+alltrim(str(::Y))+")"
@ 6,70 say "C : " + hb_numtohex(::C,2)+" ("+alltrim(str(::C))+")"
@ 7,70 say "Z : " + hb_numtohex(::Z,2)+" ("+alltrim(str(::Z))+")"
@ 8,70 say "I : " + hb_numtohex(::I,2)+" ("+alltrim(str(::I))+")"
@ 9,70 say "D : " + hb_numtohex(::D,2)+" ("+alltrim(str(::D))+")"
@ 10,70 say "B : " + hb_numtohex(::B,2)+" ("+alltrim(str(::B))+")"
// @ 11,70 say "U : " + hb_numtohex(::U,2)+" ("+alltrim(str(::U))+")"
@ 11,70 say "V : " + hb_numtohex(::V,2)+" ("+alltrim(str(::V))+")"
@ 12,70 say "N : " + hb_numtohex(::N,2)+" ("+alltrim(str(::N))+")"
@ 13,70 say "Interupt: " + hb_numtohex(::interrupt,2)+" ("+alltrim(str(::interrupt))+")"
// @ 15,60 say "Stall : " + alltrim(str(::stall))+" ("+alltrim(str(::PC))+")"
// setpos(0,0)
// pagesDiffer returns .t. if the two addresses reference different pages
FUNCTION pagesDiffer(a, b)
return (a & 0xFF00) != (b & 0xFF00)
// addBranchCycles adds a cycle for taking a branch and adds another cycle
// if the branch jumps to a new page
METHOD addBranchCycles(info) CLASS CPU
::Cycles++
if pagesDiffer(info[2], info[1])
::Cycles++
end if
METHOD compare(a, b) CLASS CPU
::setZN(a - b)
if a >= b
::C = 1
else
::C = 0
end if
// Read16 reads two bytes using Read to return a double-word value
METHOD Read16(address) CLASS CPU
local lo,hi
lo := ::Memory:Read(address)
hi := ::Memory:Read(address + 1)
return ((hi << 8) | lo)
// read16bug emulates a 6502 bug that caused the low byte to wrap without
// incrementing the high byte
METHOD read16bug(address) CLASS CPU
local a,b,lo,hi
a := address
b := ((a & 0xFF00) | (a+1 & 0xFFFF))
lo := ::Memory:Read(a)
hi := ::Memory:Read(b)
return ((hi << 8) | lo)
// push pushes a byte onto the stack
METHOD push(value) CLASS CPU
::Memory:Write( (0x100 | ::SP), value)
::SP--
// pull pops a byte from the stack
METHOD pull() CLASS CPU
::SP++
return ::Memory:Read( (0x100 | (::SP)))
// push16 pushes two bytes onto the stack
METHOD push16(value) CLASS CPU
local hi,lo
hi := ((value >> 8) & 0xFF)
lo := (value & 0xFF)
::push(hi)
::push(lo)
// pull16 pops two bytes from the stack
METHOD pull16() CLASS CPU
local lo,hi
lo := ::pull()
hi := ::pull()
return ((hi << 8) | lo)
// Flags returns the processor status flags
METHOD Flags() CLASS CPU
local flags:=0
flags = (flags | (::C << 0))
flags = (flags | (::Z << 1))
flags = (flags | (::I << 2))
flags = (flags | (::D << 3))
flags = (flags | (::B << 4))
flags = (flags | (::U << 5))
flags = (flags | (::V << 6))
flags = (flags | (::N << 7))
return flags
// SetFlags sets the processor status flags
METHOD SetFlags(flags) CLASS CPU
::C = ((flags >> 0) & 1)
::Z = ((flags >> 1) & 1)
::I = ((flags >> 2) & 1)
::D = ((flags >> 3) & 1)
::B = ((flags >> 4) & 1)
::U = ((flags >> 5) & 1)
::V = ((flags >> 6) & 1)
::N = ((flags >> 7) & 1)
// setZ sets the zero flag if the argument is zero
METHOD setZ(value) CLASS CPU
if value = 0 .or. value>255
::Z = 1
else
::Z = 0
end if
// setN sets the negative flag if the argument is negative (high bit is set)
METHOD setN(value) CLASS CPU
if(value & 0x80) != 0 //(value & 0x80) != 0 value<0 //
::N = 1
else
::N = 0
end if
// setZN sets the zero flag and the negative flag
METHOD setZN(value) CLASS CPU
::setZ(value)
::setN(value)
// triggerNMI causes a non-maskable interrupt to occur on the next cycle
METHOD triggerNMI() CLASS CPU
::interrupt = interruptNMI
// triggerIRQ causes an IRQ interrupt to occur on the next cycle
METHOD triggerIRQ() CLASS CPU
if ::I == 0
::interrupt = interruptIRQ
end if
// stepInfo contains information that the instruction functions use
/*
CREATE CLASS stepInfo
VAR address INIT 0
VAR pc INIT 0
VAR mode INIT 0
END CLASS
*/
// Step executes a single CPU instruction
METHOD Step(pPPU) CLASS CPU
local cycles,opcode,mode,address,pageCrossed,info
if ::stall > 0
::stall--
return 1
end if
cycles := ::Cycles
do case
case ::interrupt=interruptNMI
//clog("NMI INTERRUPT")
::nmi()
case ::interrupt=interruptIRQ
//clog("IRQ INTERRUPT")
::irq()
end case
::interrupt = interruptNone
opcode := ::Memory:Read(::PC) + 1
mode := instructionModes[opcode]
address :=0
pageCrossed := .f.
//clog("case")
do case
case mode=modeAbsolute
//clog("modeAbsolute")
address = ::Read16(::PC + 1)
case mode=modeAbsoluteX
//clog("modeAbsoluteX")
address = ::Read16(::PC + 1) + ::X
pageCrossed = pagesDiffer(address-::X, address)
case mode=modeAbsoluteY
//clog("modeAbsoluteY")
address = ::Read16(::PC+1) + ::Y
pageCrossed = pagesDiffer(address - ::Y, address)
case mode=modeAccumulator
//clog("modeAccumulator")
address = 0
case mode=modeImmediate
//clog("modeImmediate")
address = ::PC + 1
case mode=modeImplied
//clog("modeImplied")
address = 0
case mode=modeIndexedIndirect
//clog("modeIndexedIndirect")
address = ::read16bug(::Memory:Read(::PC + 1) + ::X )
case mode=modeIndirect
//clog("modeIndirect")
address = ::read16bug(::Read16(::PC + 1))
case mode=modeIndirectIndexed
//clog("modeIndirectIndexed")
//clog("PC: ",::PC+1)
//clog("Y: ",(::Y & 0xFFFF))
address = ::read16bug(::Memory:Read(::PC + 1) ) + ::Y
//clog("ADD: ",(address & 0xFFFF))
pageCrossed = pagesDiffer(address - ::Y, address)
case mode=modeRelative
//clog("modeRelative")
offset := ::Memory:Read(::PC + 1)
if offset < 0x80
address = ::PC + 2 + offset
else
address = ::PC + 2 + offset - 0x100
end if
case mode=modeZeroPage
//clog("modeZeroPage")
address = ::Memory:Read(::PC + 1)
case mode=modeZeroPageX
//clog("modeZeroPageX")
address = ::Memory:Read(::PC + 1) + ::X
case mode=modeZeroPageY
//clog("modeZeroPageY")
address = ::Memory:Read(::PC + 1) + ::Y
end case
::PC += instructionSizes[opcode]
::Cycles += instructionCycles[opcode]
if pageCrossed
::Cycles += instructionPageCycles[opcode]
end if
// clog("Address:",address)
//#define ARRAY_OPCODE
//#define HASH_OPCODE
#define CASE_OPCODE
#ifdef ARRAY_OPCODE
eval(::table[opcode],{address, ::PC, mode})
#endif
#ifdef HASH_OPCODE
opcode--
eval(::cOphash[opcode],{address, ::PC, mode})
#endif
#ifdef CASE_OPCODE
opcode--
do case
case opcode=0
::brk({address, ::PC, mode})
case opcode=1
::ora({address, ::PC, mode})
case opcode=2
::kil({address, ::PC, mode})
case opcode=3
::slo({address, ::PC, mode})
case opcode=4
::nop({address, ::PC, mode})
case opcode=5
::ora({address, ::PC, mode})
case opcode=6
::asl({address, ::PC, mode})
case opcode=7
::slo({address, ::PC, mode})
case opcode=8
::php({address, ::PC, mode})
case opcode=9
::ora({address, ::PC, mode})
case opcode=10
::asl({address, ::PC, mode})
case opcode=11
::anc({address, ::PC, mode})
case opcode=12
::nop({address, ::PC, mode})
case opcode=13
::ora({address, ::PC, mode})
case opcode=14
::asl({address, ::PC, mode})
case opcode=15
::slo({address, ::PC, mode})
case opcode=16
::bpl({address, ::PC, mode})
case opcode=17
::ora({address, ::PC, mode})
case opcode=18
::kil({address, ::PC, mode})
case opcode=19
::slo({address, ::PC, mode})
case opcode=20
::nop({address, ::PC, mode})
case opcode=21
::ora({address, ::PC, mode})
case opcode=22
::asl({address, ::PC, mode})
case opcode=23
::slo({address, ::PC, mode})
case opcode=24
::clc({address, ::PC, mode})
case opcode=25
::ora({address, ::PC, mode})
case opcode=26
::nop({address, ::PC, mode})
case opcode=27
::slo({address, ::PC, mode})
case opcode=28
::nop({address, ::PC, mode})
case opcode=29
::ora({address, ::PC, mode})
case opcode=30
::asl({address, ::PC, mode})
case opcode=31
::slo({address, ::PC, mode})
case opcode=32
::jsr({address, ::PC, mode})
case opcode=33
::and({address, ::PC, mode})
case opcode=34
::kil({address, ::PC, mode})
case opcode=35
::rla({address, ::PC, mode})
case opcode=36
::bit({address, ::PC, mode})
case opcode=37
::and({address, ::PC, mode})
case opcode=38
::rol({address, ::PC, mode})
case opcode=39
::rla({address, ::PC, mode})
case opcode=40
::plp({address, ::PC, mode})
case opcode=41
::and({address, ::PC, mode})
case opcode=42
::rol({address, ::PC, mode})
case opcode=43
::anc({address, ::PC, mode})
case opcode=44
::bit({address, ::PC, mode})
case opcode=45
::and({address, ::PC, mode})
case opcode=46
::rol({address, ::PC, mode})
case opcode=47
::rla({address, ::PC, mode})
case opcode=48
::bmi({address, ::PC, mode})
case opcode=49
::and({address, ::PC, mode})
case opcode=50
::kil({address, ::PC, mode})
case opcode=51
::rla({address, ::PC, mode})
case opcode=52
::nop({address, ::PC, mode})
case opcode=53
::and({address, ::PC, mode})
case opcode=54
::rol({address, ::PC, mode})
case opcode=55
::rla({address, ::PC, mode})
case opcode=56
::sec({address, ::PC, mode})
case opcode=57
::and({address, ::PC, mode})
case opcode=58
::nop({address, ::PC, mode})
case opcode=59
::rla({address, ::PC, mode})
case opcode=60
::nop({address, ::PC, mode})
case opcode=61
::and({address, ::PC, mode})
case opcode=62
::rol({address, ::PC, mode})
case opcode=63
::rla({address, ::PC, mode})
case opcode=64
::rti({address, ::PC, mode})
case opcode=65
::eor({address, ::PC, mode})
case opcode=66
::kil({address, ::PC, mode})
case opcode=67
::sre({address, ::PC, mode})
case opcode=68
::nop({address, ::PC, mode})
case opcode=69
::eor({address, ::PC, mode})
case opcode=70
::lsr({address, ::PC, mode})
case opcode=71
::sre({address, ::PC, mode})
case opcode=72
::pha({address, ::PC, mode})
case opcode=73
::eor({address, ::PC, mode})
case opcode=74
::lsr({address, ::PC, mode})
case opcode=75
::alr({address, ::PC, mode})
case opcode=76
::jmp({address, ::PC, mode})
case opcode=77
::eor({address, ::PC, mode})
case opcode=78
::lsr({address, ::PC, mode})
case opcode=79
::sre({address, ::PC, mode})
case opcode=80
::bvc({address, ::PC, mode})
case opcode=81
::eor({address, ::PC, mode})
case opcode=82
::kil({address, ::PC, mode})
case opcode=83
::sre({address, ::PC, mode})
case opcode=84
::nop({address, ::PC, mode})
case opcode=85
::eor({address, ::PC, mode})
case opcode=86
::lsr({address, ::PC, mode})
case opcode=87
::sre({address, ::PC, mode})
case opcode=88
::cli({address, ::PC, mode})
case opcode=89
::eor({address, ::PC, mode})
case opcode=90
::nop({address, ::PC, mode})
case opcode=91
::sre({address, ::PC, mode})
case opcode=92
::nop({address, ::PC, mode})
case opcode=93
::eor({address, ::PC, mode})
case opcode=94
::lsr({address, ::PC, mode})
case opcode=95
::sre({address, ::PC, mode})
case opcode=96
::rts({address, ::PC, mode})
case opcode=97
::adc({address, ::PC, mode})
case opcode=98
::kil({address, ::PC, mode})
case opcode=99
::rra({address, ::PC, mode})
case opcode=100
::nop({address, ::PC, mode})
case opcode=101
::adc({address, ::PC, mode})
case opcode=102
::ror({address, ::PC, mode})
case opcode=103
::rra({address, ::PC, mode})
case opcode=104
::pla({address, ::PC, mode})
case opcode=105
::adc({address, ::PC, mode})
case opcode=106
::ror({address, ::PC, mode})
case opcode=107
::arr({address, ::PC, mode})
case opcode=108
::jmp({address, ::PC, mode})
case opcode=109
::adc({address, ::PC, mode})
case opcode=110
::ror({address, ::PC, mode})
case opcode=111
::rra({address, ::PC, mode})
case opcode=112
::bvs({address, ::PC, mode})
case opcode=113
::adc({address, ::PC, mode})
case opcode=114
::kil({address, ::PC, mode})
case opcode=115
::rra({address, ::PC, mode})
case opcode=116
::nop({address, ::PC, mode})
case opcode=117
::adc({address, ::PC, mode})
case opcode=118
::ror({address, ::PC, mode})
case opcode=119
::rra({address, ::PC, mode})
case opcode=120
::sei({address, ::PC, mode})
case opcode=121
::adc({address, ::PC, mode})
case opcode=122
::nop({address, ::PC, mode})
case opcode=123
::rra({address, ::PC, mode})
case opcode=124
::nop({address, ::PC, mode})
case opcode=125
::adc({address, ::PC, mode})
case opcode=126
::ror({address, ::PC, mode})
case opcode=127
::rra({address, ::PC, mode})
case opcode=128
::nop({address, ::PC, mode})
case opcode=129
::sta({address, ::PC, mode})
case opcode=130
::nop({address, ::PC, mode})
case opcode=131
::sax({address, ::PC, mode})
case opcode=132
::sty({address, ::PC, mode})
case opcode=133
::sta({address, ::PC, mode})
case opcode=134
::stx({address, ::PC, mode})
case opcode=135
::sax({address, ::PC, mode})
case opcode=136
::dey({address, ::PC, mode})
case opcode=137
::nop({address, ::PC, mode})
case opcode=138
::txa({address, ::PC, mode})
case opcode=139
::xaa({address, ::PC, mode})
case opcode=140
::sty({address, ::PC, mode})
case opcode=141
::sta({address, ::PC, mode})
case opcode=142
::stx({address, ::PC, mode})
case opcode=143
::sax({address, ::PC, mode})
case opcode=144
::bcc({address, ::PC, mode})
case opcode=145
::sta({address, ::PC, mode})
case opcode=146
::kil({address, ::PC, mode})
case opcode=147
::ahx({address, ::PC, mode})
case opcode=148
::sty({address, ::PC, mode})
case opcode=149
::sta({address, ::PC, mode})
case opcode=150
::stx({address, ::PC, mode})
case opcode=151
::sax({address, ::PC, mode})
case opcode=152
::tya({address, ::PC, mode})
case opcode=153
::sta({address, ::PC, mode})
case opcode=154
::txs({address, ::PC, mode})
case opcode=155
::tas({address, ::PC, mode})
case opcode=156
::shy({address, ::PC, mode})
case opcode=157
::sta({address, ::PC, mode})
case opcode=158
::shx({address, ::PC, mode})
case opcode=159
::ahx({address, ::PC, mode})
case opcode=160
::ldy({address, ::PC, mode})
case opcode=161
::lda({address, ::PC, mode})
case opcode=162
::ldx({address, ::PC, mode})
case opcode=163
::lax({address, ::PC, mode})
case opcode=164
::ldy({address, ::PC, mode})
case opcode=165
::lda({address, ::PC, mode})
case opcode=166
::ldx({address, ::PC, mode})
case opcode=167
::lax({address, ::PC, mode})
case opcode=168
::tay({address, ::PC, mode})
case opcode=169
::lda({address, ::PC, mode})
case opcode=170
::tax({address, ::PC, mode})
case opcode=171
::lax({address, ::PC, mode})
case opcode=172
::ldy({address, ::PC, mode})
case opcode=173
::lda({address, ::PC, mode})
case opcode=174
::ldx({address, ::PC, mode})
case opcode=175
::lax({address, ::PC, mode})
case opcode=176
::bcs({address, ::PC, mode})
case opcode=177
::lda({address, ::PC, mode})
case opcode=178
::kil({address, ::PC, mode})
case opcode=179
::lax({address, ::PC, mode})
case opcode=180
::ldy({address, ::PC, mode})
case opcode=181
::lda({address, ::PC, mode})
case opcode=182
::ldx({address, ::PC, mode})
case opcode=183
::lax({address, ::PC, mode})
case opcode=184
::clv({address, ::PC, mode})
case opcode=185