-
Notifications
You must be signed in to change notification settings - Fork 1
/
PCE.js
3485 lines (2931 loc) · 80.4 KB
/
PCE.js
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
"use strict";
class PCE {
constructor() {
/* ************* */
/* **** ETC **** */
/* ************* */
this.TimerID = null;
this.MainCanvas = null;
this.Ctx = null;
this.ImageData = null;
this.SuperGrafx = false;
/* ************* */
/* **** CPU **** */
/* ************* */
this.OpCycles = [
8, 7, 3, 4, 6, 4, 6, 7, 3, 2, 2, 2, 7, 5, 7, 6,// 0x00
2, 7, 7, 4, 6, 4, 6, 7, 2, 5, 2, 2, 7, 5, 7, 6,// 0x10
7, 7, 3, 4, 4, 4, 6, 7, 3, 2, 2, 2, 5, 5, 7, 6,// 0x20
2, 7, 7, 2, 4, 4, 6, 7, 2, 5, 2, 2, 5, 5, 7, 6,// 0x30
7, 7, 3, 4, 8, 4, 6, 7, 3, 2, 2, 2, 4, 5, 7, 6,// 0x40
2, 7, 7, 5, 2, 4, 6, 7, 2, 5, 3, 2, 2, 5, 7, 6,// 0x50
7, 7, 2, 2, 4, 4, 6, 7, 3, 2, 2, 2, 7, 5, 7, 6,// 0x60
2, 7, 7, 0, 4, 4, 6, 7, 2, 5, 3, 2, 7, 5, 7, 6,// 0x70
4, 7, 2, 7, 4, 4, 4, 7, 2, 2, 2, 2, 5, 5, 5, 6,// 0x80
2, 7, 7, 8, 4, 4, 4, 7, 2, 5, 2, 2, 5, 5, 5, 6,// 0x90
2, 7, 2, 7, 4, 4, 4, 7, 2, 2, 2, 2, 5, 5, 5, 6,// 0xA0
2, 7, 7, 8, 4, 4, 4, 7, 2, 5, 2, 2, 5, 5, 5, 6,// 0xB0
2, 7, 2, 0, 4, 4, 6, 7, 2, 2, 2, 2, 5, 5, 7, 6,// 0xC0
2, 7, 7, 0, 2, 4, 6, 7, 2, 5, 3, 2, 2, 5, 7, 6,// 0xD0
2, 7, 2, 0, 4, 4, 6, 7, 2, 2, 2, 2, 5, 5, 7, 6,// 0xE0
2, 7, 7, 0, 2, 4, 6, 7, 2, 5, 3, 2, 2, 5, 7, 6];//0xF0
this.OpBytes = [
0, 2, 1, 2, 2, 2, 2, 2, 1, 2, 1, 1, 3, 3, 3, 0,// 0x00
0, 2, 2, 2, 2, 2, 2, 2, 1, 3, 1, 1, 3, 3, 3, 0,// 0x10
0, 2, 1, 2, 2, 2, 2, 2, 1, 2, 1, 1, 3, 3, 3, 0,// 0x20
0, 2, 2, 1, 2, 2, 2, 2, 1, 3, 1, 1, 3, 3, 3, 0,// 0x30
0, 2, 1, 2, 0, 2, 2, 2, 1, 2, 1, 1, 0, 3, 3, 0,// 0x40
0, 2, 2, 2, 1, 2, 2, 2, 1, 3, 1, 1, 1, 3, 3, 0,// 0x50
0, 2, 1, 1, 2, 2, 2, 2, 1, 2, 1, 1, 0, 3, 3, 0,// 0x60
0, 2, 2, 0, 2, 2, 2, 2, 1, 3, 1, 1, 0, 3, 3, 0,// 0x70
0, 2, 1, 3, 2, 2, 2, 2, 1, 2, 1, 1, 3, 3, 3, 0,// 0x80
0, 2, 2, 4, 2, 2, 2, 2, 1, 3, 1, 1, 3, 3, 3, 0,// 0x90
2, 2, 2, 3, 2, 2, 2, 2, 1, 2, 1, 1, 3, 3, 3, 0,// 0xA0
0, 2, 2, 4, 2, 2, 2, 2, 1, 3, 1, 1, 3, 3, 3, 0,// 0xB0
2, 2, 1, 0, 2, 2, 2, 2, 1, 2, 1, 1, 3, 3, 3, 0,// 0xC0
0, 2, 2, 0, 1, 2, 2, 2, 1, 3, 1, 1, 1, 3, 3, 0,// 0xD0
2, 2, 1, 0, 2, 2, 2, 2, 1, 2, 1, 1, 3, 3, 3, 0,// 0xE0
0, 2, 2, 0, 1, 2, 2, 2, 1, 3, 1, 1, 1, 3, 3, 0];//0xF0
this.A = 0;
this.X = 0;
this.Y = 0;
this.PC = 0;
this.S = 0;
this.P = 0;
this.NZCacheTable = new Array(0x100).fill(0x00);
this.NZCacheTable = this.NZCacheTable.map((d, i) => { return i & 0x80; });
this.NZCacheTable[0x00] = 0x02;
this.NFlag = 0x80;
this.VFlag = 0x40;
this.TFlag = 0x20;
this.BFlag = 0x10;
this.DFlag = 0x08;
this.IFlag = 0x04;
this.ZFlag = 0x02;
this.CFlag = 0x01;
this.TIQFlag = 0x04;
this.IRQ1Flag = 0x02;
this.IRQ2Flag = 0x01;
this.ProgressClock = 0;
this.CPUBaseClock = 0;
this.BaseClock1 = 12;
this.BaseClock3 = 6;
this.BaseClock5 = 4;
this.BaseClock7 = 3;
this.BaseClock10 = 2;
this.TransferSrc = 0;
this.TransferDist = 0;
this.TransferLen = 0;
this.TransferAlt = 0;
/* ***************** */
/* **** Storage **** */
/* ***************** */
this.MPR = new Array(8);
this.MPRSelect = 0;
this.RAM = new Array(0x8000);
this.RAMMask = 0x1FFF;
this.BRAM = new Array(0x2000).fill(0x00);
this.BRAMUse = false;
this.INTIRQ2 = 0x00;
this.IntDisableRegister = 0;
this.Mapper = null;
this.MapperBase = class {
constructor(core) {
this.ROM = null;
this.Core = core;
}
Init() {
}
Read(address) {
return 0xFF;
}
Write(address, data) {
}
};
this.Mapper0 = class extends this.MapperBase {
constructor(rom, core) {
super(core);
this.ROM = rom;
let tmp = this.ROM.length - 1;
this.Address = 0x80000;
while(this.Address > 0x0000) {
if((this.Address & tmp) != 0x0000)
break;
this.Address >>>= 1;
}
}
Read(address) {
if(address >= this.ROM.length)
return this.ROM[(address & (this.Address - 1)) | this.Address];
else
return this.ROM[address];
}
};
this.Mapper1 = class extends this.MapperBase {
constructor(rom, core) {
super(core);
this.ROM = rom;
this.Address = 0;
}
Init() {
this.Address = 0;
}
Read(address) {
if(address < 0x80000)
return this.ROM[address];
else
return this.ROM[this.Address | (address & 0x7FFFF)];
}
Write(address, data) {
this.Address = ((address & 0x000F) + 1) << 19;
}
};
this.Mapper2 = class extends this.MapperBase {
constructor(rom, core) {
super(core);
this.ROM = rom.concat(new Array(0x80000).fill(0x00));
}
Read(address) {
return this.ROM[address];
}
Write(address, data) {
if(address >= 0x80000)
this.ROM[address] = data;
}
};
/* ************* */
/* **** VCE **** */
/* ************* */
this.Palette = new Array(512);
this.PaletteData = new Array(512);
this.MonoPaletteData = new Array(512);
this.VCEBaseClock = 0;
this.VCEControl = 0;
this.VCEAddress = 0;
this.VCEData = 0;
/* ************* */
/* **** VPC **** */
/* ************* */
this.VPCRegister = new Array(8);
this.VDCSelect = 0;
this.VPCWindow1 = 0;
this.VPCWindow2 = 0;
this.VPCPriority = new Array(4);
/* ************* */
/* **** VDC **** */
/* ************* */
this.DrawFlag = false;
this.VDCPutLineProgressClock = 0;
this.VDCPutLine = 0;
this.VDC = new Array(2);
this.VDCLineClock = 1368;
this.ScreenSize = [];
this.ScreenSize[this.BaseClock5] = 342;
this.ScreenSize[this.BaseClock7] = 456;
this.ScreenSize[this.BaseClock10] = 684;
this.PutScreenSize = [];
this.PutScreenSize[this.BaseClock5] = 320;
this.PutScreenSize[this.BaseClock7] = 428;
this.PutScreenSize[this.BaseClock10] = 640;
this.ScreenHeightMAX = 262;
this.ScreenWidthMAX = 684;
this.VScreenWidthArray = [];
this.VScreenWidthArray[0x00] = 32;
this.VScreenWidthArray[0x10] = 64;
this.VScreenWidthArray[0x20] = 128;
this.VScreenWidthArray[0x30] = 128;
this.ReverseBit = new Array(0x100).fill(0x00);
this.ReverseBit = this.ReverseBit.map((d, i) => { return ((i & 0x80) >> 7) | ((i & 0x40) >> 5) |
((i & 0x20) >> 3) | ((i & 0x10) >> 1) |
((i & 0x08) << 1) | ((i & 0x04) << 3) |
((i & 0x02) << 5) | ((i & 0x01) << 7); });
this.ReverseBit16 = new Array(0x10000).fill(0x00);
this.ReverseBit16 = this.ReverseBit16.map((d, i) => { return (this.ReverseBit[i & 0x00FF] << 8) | this.ReverseBit[(i & 0xFF00) >> 8]; });
this.ReverseBit256 = new Array(0x100).fill(0x00);
this.ReverseBit256 = this.ReverseBit256.map((d, i) => { let b = this.ReverseBit[i];
return ((b & 0x80) << (28 - 7)) |
((b & 0x40) << (24 - 6)) |
((b & 0x20) << (20 - 5)) |
((b & 0x10) << (16 - 4)) |
((b & 0x08) << (12 - 3)) |
((b & 0x04) << ( 8 - 2)) |
((b & 0x02) << ( 4 - 1)) |
((b & 0x01) << ( 0 - 0)); });
this.SPAddressMask = [];
this.SPAddressMask[16] = [];
this.SPAddressMask[32] = [];
this.SPAddressMask[16][16] = 0x07FE;
this.SPAddressMask[16][32] = 0x07FE & 0x07FA;
this.SPAddressMask[16][64] = 0x07FE & 0x07F2;
this.SPAddressMask[32][16] = 0x07FC;
this.SPAddressMask[32][32] = 0x07FC & 0x07FA;
this.SPAddressMask[32][64] = 0x07FC & 0x07F2;
/* *************** */
/* **** Sound **** */
/* *************** */
this.WaveDataArray = [];
this.WaveClockCounter = 0;
this.WaveVolume = 1.0;
this.WebAudioCtx = null;
this.WebAudioJsNode = null;
this.WebAudioGainNode = null;
this.WebAudioBufferSize = 2048;
this.PSGClock = 3579545;
/* ************* */
/* **** PSG **** */
/* ************* */
this.PSGChannel = new Array(6);
this.PSGBaseClock = this.BaseClock3;
this.PSGProgressClock = 0;
this.WaveVolumeLeft = 0;
this.WaveVolumeRight = 0;
this.WaveLfoOn = false;
this.WaveLfoControl = 0;
this.WaveLfoFreqency = 0;
/* *************** */
/* **** TIMER **** */
/* *************** */
this.TimerBaseClock = this.BaseClock7;
this.TimerReload = 0;
this.TimerFlag = false;
this.TimerCounter = 0;
this.TimerPrescaler = 0;
this.INTTIQ = 0;
/* ****************** */
/* **** Joystick **** */
/* ****************** */
this.JoystickSEL = 0;
this.JoystickCLR = 0;
this.KeyUpFunction = null;
this.KeyDownFunction = null;
this.CountryTypePCE = 0x40;
this.CountryTypeTG16 = 0x00;
this.CountryType = this.CountryTypePCE;
this.Keybord = new Array(5).fill([]);
this.Keybord = this.Keybord.map((d) => { return new Array(4); });
this.GamePad = new Array(5).fill([]);
this.GamePad = this.Keybord.map((d) => { return new Array(4); });
this.GamePadSelect = 0x00;
this.GamePadButtonSelect = 0x00;
this.GamePadBuffer = 0x00;
this.GamePadButton6 = false;
this.MultiTap = false;
this.GamePadData = [];
this.GamePadData["STANDARD PAD"] = [
[[{type:"B", index:1}],// SHOT1
[{type:"B", index:0}],// SHOT2
[{type:"B", index:8}],// SELECT
[{type:"B", index:9}, {type:"B", index:2}],// RUN
[{type:"B", index:12}],// UP
[{type:"B", index:13}],// DOWN
[{type:"B", index:14}],// LEFT
[{type:"B", index:15}]],// RIGHT
[[{type:"B", index:1}],// SHOT1
[{type:"B", index:0}],// SHOT2
[{type:"B", index:8}],// SELECT
[{type:"B", index:9}],// RUN
[{type:"B", index:12}],// UP
[{type:"B", index:13}],// DOWN
[{type:"B", index:14}],// LEFT
[{type:"B", index:15}],// RIGHT
[{type:"B", index:7}],// SHOT3
[{type:"B", index:5}],// SHOT4
[{type:"B", index:2}],// SHOT5
[{type:"B", index:3}]]];// SHOT6
this.GamePadData["HORI PAD 3 TURBO (Vendor: 0f0d Product: 0009)"] = [// Chrome
[[{type:"B", index:2}],// SHOT1
[{type:"B", index:1}],// SHOT2
[{type:"B", index:8}],// SELECT
[{type:"B", index:9}, {type:"B", index:0}],// RUN
[{type:"P", index:9}],// UP (POV)
[{type:"N", index:0}],// DOWN (POV)
[{type:"N", index:0}],// LEFT (POV)
[{type:"N", index:0}]],// RIGHT (POV)
[[{type:"B", index:2}],// SHOT1
[{type:"B", index:1}],// SHOT2
[{type:"B", index:8}],// SELECT
[{type:"B", index:9}],// RUN
[{type:"P", index:9}],// UP (POV)
[{type:"N", index:0}],// DOWN (POV)
[{type:"N", index:0}],// LEFT (POV)
[{type:"N", index:0}],// RIGHT (POV)
[{type:"B", index:7}],// SHOT3
[{type:"B", index:5}],// SHOT4
[{type:"B", index:0}],// SHOT5
[{type:"B", index:3}]]];// SHOT6
this.GamePadData["0f0d-0009-HORI PAD 3 TURBO"] = this.GamePadData["HORI PAD 3 TURBO (Vendor: 0f0d Product: 0009)"];// Firefox
this.GamePadData["UNKNOWN PAD"] = this.GamePadData["HORI PAD 3 TURBO (Vendor: 0f0d Product: 0009)"];
this.GamePadKeyData = [{index:0, data:0x01}, {index:0, data:0x02},
{index:0, data:0x04}, {index:0, data:0x08},
{index:1, data:0x01}, {index:1, data:0x04},
{index:1, data:0x08}, {index:1, data:0x02},
{index:2, data:0x01}, {index:2, data:0x02},
{index:2, data:0x04}, {index:2, data:0x08}];
this.GamePadPovData = [0x01, 0x01|0x02, 0x02, 0x02|0x04, 0x04, 0x04|0x08, 0x08, 0x01|0x08];
}
/* ************* */
/* **** ETC **** */
/* ************* */
UpdateAnimationFrame() {
this.TimerID = window.requestAnimationFrame(this.UpdateAnimationFrame.bind(this));
this.Run();
}
CancelAnimationFrame() {
window.cancelAnimationFrame(this.TimerID);
this.TimerID = null;
}
Pause() {
if(this.TimerID != null) {
this.JoystickEventRelease();
this.CancelAnimationFrame();
}
}
Start() {
if(this.TimerID == null) {
this.JoystickEventInit();
this.UpdateAnimationFrame();
}
}
Run() {
this.CheckGamePad();
this.DrawFlag = false;
while(!this.DrawFlag) {
this.CPURun();
this.VDCRun();
this.TimerRun();
this.PSGRun();
}
}
Reset() {
this.StorageReset();
this.Mapper.Init();
this.CPUInit();
this.VCEInit();
this.VPCInit();
this.VDCInit();
this.TimerInit();
this.JoystickInit();
this.PSGInit();
this.CPUReset();
}
Init() {
this.StorageInit();
this.CPUInit();
this.VCEInit();
this.VPCInit();
this.VDCInit();
this.TimerInit();
this.JoystickInit();
this.PSGInit();
}
SetCanvas(canvasID) {
this.MainCanvas = document.getElementById(canvasID);
if (!this.MainCanvas.getContext)
return false;
this.Ctx = this.MainCanvas.getContext("2d");
this.ImageData = this.Ctx.createImageData(this.ScreenWidthMAX, this.ScreenHeightMAX);
for(let i=0; i<this.ScreenWidthMAX*this.ScreenHeightMAX*4; i+=4) {
this.ImageData.data[i] = 0;
this.ImageData.data[i + 1] = 0;
this.ImageData.data[i + 2] = 0;
this.ImageData.data[i + 3] = 255;
}
this.Ctx.putImageData(this.ImageData, 0, 0);
return true;
}
/* ************* */
/* **** CPU **** */
/* ************* */
CPUReset() {
this.TransferSrc = 0;
this.TransferDist = 0;
this.TransferLen = 0;
this.TransferAlt = 0;
this.CPUBaseClock = this.BaseClock1;
this.SetIFlag();
this.PC = this.Get16(0xFFFE);
}
CPUInit() {
this.A = 0;
this.X = 0;
this.Y = 0;
this.PC = 0;
this.S = 0;
this.P = 0x00;
this.ProgressClock = 0;
this.CPUBaseClock = this.BaseClock1;
this.TransferSrc = 0;
this.TransferDist = 0;
this.TransferLen = 0;
this.TransferAlt = 0;
this.LastInt = 0x00;
}
CPURun() {
this.ProgressClock = 0;
let tmp = this.LastInt;
this.LastInt = (this.P & this.IFlag) == 0x00 ? this.GetIntStatus() : 0x00;
if(tmp != 0x00 && this.TransferLen == 0) {
this.LastInt = 0x00;
if((tmp & this.TIQFlag) == this.TIQFlag) {//TIQ
this.Push(this.PCH());
this.Push(this.PCL());
this.Push(this.P);
this.P = 0x04;
this.PC = this.Get16(0xFFFA);
} else if((tmp & this.IRQ1Flag) == this.IRQ1Flag) {//IRQ1
this.Push(this.PCH());
this.Push(this.PCL());
this.Push(this.P);
this.P = 0x04;
this.PC = this.Get16(0xFFF8);
} else if((tmp & this.IRQ2Flag) == this.IRQ2Flag) {//IRQ2
this.Push(this.PCH());
this.Push(this.PCL());
this.Push(this.P);
this.SetIFlag();
this.PC = this.Get16(0xFFF6);
}
this.ProgressClock = 8 * this.CPUBaseClock;
} else
this.OpExec();
}
OpExec() {
let address;
let tmp;
let data;
let bit;
let i;
let op = this.Get(this.PC);
switch(op) {
case 0x69: // ADC IMM
this.ADC(this.PC + 1);
break;
case 0x65: // ADC ZP
this.ADC(this.ZP());
break;
case 0x75: // ADC ZP, X
this.ADC(this.ZP_X());
break;
case 0x72: // ADC (IND)
this.ADC(this.IND());
break;
case 0x61: // ADC (IND, X)
this.ADC(this.IND_X());
break;
case 0x71: // ADC (IND), Y
this.ADC(this.IND_Y());
break;
case 0x6D: // ADC ABS
this.ADC(this.ABS());
break;
case 0x7D: // ADC ABS, X
this.ADC(this.ABS_X());
break;
case 0x79: // ADC ABS, Y
this.ADC(this.ABS_Y());
break;
case 0xE9: // SBC IMM
this.SBC(this.PC + 1);
break;
case 0xE5: // SBC ZP
this.SBC(this.ZP());
break;
case 0xF5: // SBC ZP, X
this.SBC(this.ZP_X());
break;
case 0xF2: // SBC (IND)
this.SBC(this.IND());
break;
case 0xE1: // SBC (IND, X)
this.SBC(this.IND_X());
break;
case 0xF1: // SBC (IND), Y
this.SBC(this.IND_Y());
break;
case 0xED: // SBC ABS
this.SBC(this.ABS());
break;
case 0xFD: // SBC ABS, X
this.SBC(this.ABS_X());
break;
case 0xF9: // SBC ABS, Y
this.SBC(this.ABS_Y());
break;
case 0x29: // AND IMM
this.AND(this.PC + 1);
break;
case 0x25: // AND ZP
this.AND(this.ZP());
break;
case 0x35: // AND ZP, X
this.AND(this.ZP_X());
break;
case 0x32: // AND (IND)
this.AND(this.IND());
break;
case 0x21: // AND (IND, X)
this.AND(this.IND_X());
break;
case 0x31: // AND (IND), Y
this.AND(this.IND_Y());
break;
case 0x2D: // AND ABS
this.AND(this.ABS());
break;
case 0x3D: // AND ABS, X
this.AND(this.ABS_X());
break;
case 0x39: // AND ABS, Y
this.AND(this.ABS_Y());
break;
case 0x49: // EOR IMM
this.EOR(this.PC + 1);
break;
case 0x45: // EOR ZP
this.EOR(this.ZP());
break;
case 0x55: // EOR ZP, X
this.EOR(this.ZP_X());
break;
case 0x52: // EOR (IND)
this.EOR(this.IND());
break;
case 0x41: // EOR (IND, X)
this.EOR(this.IND_X());
break;
case 0x51: // EOR (IND), Y
this.EOR(this.IND_Y());
break;
case 0x4D: // EOR ABS
this.EOR(this.ABS());
break;
case 0x5D: // EOR ABS, X
this.EOR(this.ABS_X());
break;
case 0x59: // EOR ABS, Y
this.EOR(this.ABS_Y());
break;
case 0x09: // ORA IMM
this.ORA(this.PC + 1);
break;
case 0x05: // ORA ZP
this.ORA(this.ZP());
break;
case 0x15: // ORA ZP, X
this.ORA(this.ZP_X());
break;
case 0x12: // ORA (IND)
this.ORA(this.IND());
break;
case 0x01: // ORA (IND, X)
this.ORA(this.IND_X());
break;
case 0x11: // ORA (IND), Y
this.ORA(this.IND_Y());
break;
case 0x0D: // ORA ABS
this.ORA(this.ABS());
break;
case 0x1D: // ORA ABS, X
this.ORA(this.ABS_X());
break;
case 0x19: // ORA ABS, Y
this.ORA(this.ABS_Y());
break;
case 0x06: // ASL ZP
address = this.ZP();
this.Set(address, this.ASL(this.Get(address)));
break;
case 0x16: // ASL ZP, X
address = this.ZP_X();
this.Set(address, this.ASL(this.Get(address)));
break;
case 0x0E: // ASL ABS
address = this.ABS();
this.Set(address, this.ASL(this.Get(address)));
break;
case 0x1E: // ASL ABS, X
address = this.ABS_X();
this.Set(address, this.ASL(this.Get(address)));
break;
case 0x0A: // ASL A
this.A = this.ASL(this.A);
break;
case 0x46: // LSR ZP
address = this.ZP();
this.Set(address, this.LSR(this.Get(address)));
break;
case 0x56: // LSR ZP, X
address = this.ZP_X();
this.Set(address, this.LSR(this.Get(address)));
break;
case 0x4E: // LSR ABS
address = this.ABS();
this.Set(address, this.LSR(this.Get(address)));
break;
case 0x5E: // LSR ABS, X
address = this.ABS_X();
this.Set(address, this.LSR(this.Get(address)));
break;
case 0x4A: // LSR A
this.A = this.LSR(this.A);
break;
case 0x26: // ROL ZP
address = this.ZP();
this.Set(address, this.ROL(this.Get(address)));
break;
case 0x36: // ROL ZP, X
address = this.ZP_X();
this.Set(address, this.ROL(this.Get(address)));
break;
case 0x2E: // ROL ABS
address = this.ABS();
this.Set(address, this.ROL(this.Get(address)));
break;
case 0x3E: // ROL ABS, X
address = this.ABS_X();
this.Set(address, this.ROL(this.Get(address)));
break;
case 0x2A: // ROL A
this.A = this.ROL(this.A);
break;
case 0x66: // ROR ZP
address = this.ZP();
this.Set(address, this.ROR(this.Get(address)));
break;
case 0x76: // ROR ZP, X
address = this.ZP_X();
this.Set(address, this.ROR(this.Get(address)));
break;
case 0x6E: // ROR ABS
address = this.ABS();
this.Set(address, this.ROR(this.Get(address)));
break;
case 0x7E: // ROR ABS, X
address = this.ABS_X();
this.Set(address, this.ROR(this.Get(address)));
break;
case 0x6A: // ROR A
this.A = this.ROR(this.A);
break;
case 0x0F: // BBR0
this.BBRi(0);
break;
case 0x1F: // BBR1
this.BBRi(1);
break;
case 0x2F: // BBR2
this.BBRi(2);
break;
case 0x3F: // BBR3
this.BBRi(3);
break;
case 0x4F: // BBR4
this.BBRi(4);
break;
case 0x5F: // BBR5
this.BBRi(5);
break;
case 0x6F: // BBR6
this.BBRi(6);
break;
case 0x7F: // BBR7
this.BBRi(7);
break;
case 0x8F: // BBS0
this.BBSi(0);
break;
case 0x9F: // BBS1
this.BBSi(1);
break;
case 0xAF: // BBS2
this.BBSi(2);
break;
case 0xBF: // BBS3
this.BBSi(3);
break;
case 0xCF: // BBS4
this.BBSi(4);
break;
case 0xDF: // BBS5
this.BBSi(5);
break;
case 0xEF: // BBS6
this.BBSi(6);
break;
case 0xFF: // BBS7
this.BBSi(7);
break;
case 0x90: // BCC
this.Branch((this.P & this.CFlag) == 0x00, 1);
break;
case 0xB0: // BCS
this.Branch((this.P & this.CFlag) == this.CFlag, 1);
break;
case 0xD0: // BNE
this.Branch((this.P & this.ZFlag) == 0x00, 1);
break;
case 0xF0: // BEQ
this.Branch((this.P & this.ZFlag) == this.ZFlag, 1);
break;
case 0x10: // BPL
this.Branch((this.P & this.NFlag) == 0x00, 1);
break;
case 0x30: // BMI
this.Branch((this.P & this.NFlag) == this.NFlag, 1);
break;
case 0x50: // BVC
this.Branch((this.P & this.VFlag) == 0x00, 1);
break;
case 0x70: // BVS
this.Branch((this.P & this.VFlag) == this.VFlag, 1);
break;
case 0x80: // BRA
this.Branch(true, 1);
break;
case 0x44: // BSR
this.PC++;
this.Push(this.PCH());
this.Push(this.PCL());
this.Branch(true, 0);
break;
case 0x20: // JSR ABS
tmp = this.ABS();
this.PC += 2;
this.Push(this.PCH());
this.Push(this.PCL());
this.PC = tmp;
this.ClearTFlag();
break;
case 0x40: // RTI
this.P = this.Pull();
this.toPCL(this.Pull());
this.toPCH(this.Pull());
break;
case 0x60: // RTS
this.ClearTFlag();
this.toPCL(this.Pull());
this.toPCH(this.Pull());
this.PC++;
break;
case 0x4C: // JMP ABS
this.PC = this.ABS();
this.ClearTFlag();
break;
case 0x6C: // JMP (ABS)
this.PC = this.ABS_IND();
this.ClearTFlag();
break;
case 0x7C: // JMP (ABS, X)
this.PC = this.ABS_X_IND();
this.ClearTFlag();
break;
case 0x00: // BRK
this.PC += 2;
this.Push(this.PCH());
this.Push(this.PCL());
this.SetBFlag();
this.Push(this.P);
this.ClearDFlag();
this.ClearTFlag();
this.SetIFlag();
this.PC = this.Get16(0xFFF6);
break;
case 0x62: // CLA
this.A = 0x00;
this.ClearTFlag();
break;
case 0x82: // CLX
this.X = 0x00;
this.ClearTFlag();
break;
case 0xC2: // CLY
this.Y = 0x00;
this.ClearTFlag();
break;
case 0x18: // CLC
this.ClearCFlag();
this.ClearTFlag();
break;
case 0xD8: // CLD
this.ClearDFlag();
this.ClearTFlag();
break;
case 0x58: // CLI
this.ClearIFlag();
this.ClearTFlag();
break;
case 0xB8: // CLV
this.ClearVFlag();
this.ClearTFlag();
break;
case 0x38: // SEC
this.SetCFlag();
this.ClearTFlag();
break;
case 0xF8: // SED
this.SetDFlag();
this.ClearTFlag();
break;
case 0x78: // SEI
this.SetIFlag();
this.ClearTFlag();
break;
case 0xF4: // SET
this.SetTFlag();
break;
case 0xC9: // CMP IMM
this.Compare(this.A, this.PC + 1);
break;
case 0xC5: // CMP ZP
this.Compare(this.A, this.ZP());
break;
case 0xD5: // CMP ZP, X
this.Compare(this.A, this.ZP_X());
break;
case 0xD2: // CMP (IND)
this.Compare(this.A, this.IND());
break;
case 0xC1: // CMP (IND, X)
this.Compare(this.A, this.IND_X());
break;
case 0xD1: // CMP (IND), Y
this.Compare(this.A, this.IND_Y());
break;
case 0xCD: // CMP ABS
this.Compare(this.A, this.ABS());
break;
case 0xDD: // CMP ABS, X
this.Compare(this.A, this.ABS_X());
break;
case 0xD9: // CMP ABS, Y
this.Compare(this.A, this.ABS_Y());
break;
case 0xE0: // CPX IMM
this.Compare(this.X, this.PC + 1);
break;
case 0xE4: // CPX ZP
this.Compare(this.X, this.ZP());
break;
case 0xEC: // CPX ABS
this.Compare(this.X, this.ABS());
break;
case 0xC0: // CPY IMM
this.Compare(this.Y, this.PC + 1);
break;
case 0xC4: // CPY ZP
this.Compare(this.Y, this.ZP());
break;
case 0xCC: // CPY ABS
this.Compare(this.Y, this.ABS());
break;
case 0xC6: // DEC ZP
address = this.ZP();
this.Set(address, this.Decrement(this.Get(address)));