-
Notifications
You must be signed in to change notification settings - Fork 14
/
CPU_emulcycle.i
executable file
·1174 lines (1027 loc) · 20 KB
/
CPU_emulcycle.i
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
/*
Frodo, Commodore 64 emulator for the iPhone
Copyright (C) 1994-1997,2002 Christian Bauer
See gpl.txt for license information.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* CPU_emulcycle.i - SC 6510/6502 emulation core (body of
* EmulateCycle() function, the same for
* both 6510 and 6502)
*
* Frodo (C) 1994-1997,2002 Christian Bauer
*/
/*
* Stack macros
*/
// Pop processor flags from the stack
#define pop_flags() \
read_to(sp | 0x100, data); \
n_flag = data; \
v_flag = data & 0x40; \
d_flag = data & 0x08; \
i_flag = data & 0x04; \
z_flag = !(data & 0x02); \
c_flag = data & 0x01;
// Push processor flags onto the stack
#define push_flags(b_flag) \
data = 0x20 | (n_flag & 0x80); \
if (v_flag) data |= 0x40; \
if (b_flag) data |= 0x10; \
if (d_flag) data |= 0x08; \
if (i_flag) data |= 0x04; \
if (!z_flag) data |= 0x02; \
if (c_flag) data |= 0x01; \
write_byte(sp-- | 0x100, data);
/*
* Other macros
*/
// Branch (cycle 1)
#define Branch(flag) \
read_to(pcSC, data); \
pcSC++; \
if (flag) { \
ar = pcSC + (int8)data; \
if ((ar >> 8) != (pcSC >> 8)) { \
if (data & 0x80) \
state = O_BRANCH_BP; \
else \
state = O_BRANCH_FP; \
} else \
state = O_BRANCH_NP; \
} else \
state = 0; \
break;
// Set N and Z flags according to byte
#define set_nz(x) (z_flag = n_flag = (x))
// Address fetch of RMW instruction done, now read and write operand
#define DoRMW state = RMW_DO_IT; break;
// Operand fetch done, now execute opcode
#define Execute state = OpTab[op]; break;
// Last cycle of opcode
#define Last state = 0; break;
/*
* EmulCycle() function
*/
// Opcode fetch (cycle 0)
//case 0:
read_to(pcSC, op);
pcSC++;
state = ModeTab[op];
break;
// IRQ
case 0x0008:
read_idle(pcSC);
state = 0x0009;
break;
case 0x0009:
read_idle(pcSC);
state = 0x000a;
break;
case 0x000a:
write_byte(sp-- | 0x100, pcSC >> 8);
state = 0x000b;
break;
case 0x000b:
write_byte(sp-- | 0x100, pcSC);
state = 0x000c;
break;
case 0x000c:
push_flags(false);
i_flag = true;
state = 0x000d;
break;
case 0x000d:
read_to(0xfffe, pcSC);
state = 0x000e;
break;
case 0x000e:
read_to(0xffff, data);
pcSC |= data << 8;
Last;
// NMI
case 0x0010:
read_idle(pcSC);
state = 0x0011;
break;
case 0x0011:
read_idle(pcSC);
state = 0x0012;
break;
case 0x0012:
write_byte(sp-- | 0x100, pcSC >> 8);
state = 0x0013;
break;
case 0x0013:
write_byte(sp-- | 0x100, pcSC);
state = 0x0014;
break;
case 0x0014:
push_flags(false);
i_flag = true;
state = 0x0015;
break;
case 0x0015:
read_to(0xfffa, pcSC);
state = 0x0016;
break;
case 0x0016:
read_to(0xfffb, data);
pcSC |= data << 8;
Last;
// Addressing modes: Fetch effective address, no extra cycles (-> ar)
case A_ZERO:
read_to(pcSC, ar);
pcSC++;
Execute;
case A_ZEROX:
read_to(pcSC, ar);
pcSC++;
state = A_ZEROX1;
break;
case A_ZEROX1:
read_idle(ar);
ar = (ar + x) & 0xff;
Execute;
case A_ZEROY:
read_to(pcSC, ar);
pcSC++;
state = A_ZEROY1;
break;
case A_ZEROY1:
read_idle(ar);
ar = (ar + y) & 0xff;
Execute;
case A_ABS:
read_to(pcSC, ar);
pcSC++;
state = A_ABS1;
break;
case A_ABS1:
read_to(pcSC, data);
pcSC++;
ar = ar | (data << 8);
Execute;
case A_ABSX:
read_to(pcSC, ar);
pcSC++;
state = A_ABSX1;
break;
case A_ABSX1:
read_to(pcSC, ar2); // Note: Some undocumented opcodes rely on the value of ar2
pcSC++;
if (ar+x < 0x100)
state = A_ABSX2;
else
state = A_ABSX3;
ar = (ar + x) & 0xff | (ar2 << 8);
break;
case A_ABSX2: // No page crossed
read_idle(ar);
Execute;
case A_ABSX3: // Page crossed
read_idle(ar);
ar += 0x100;
Execute;
case A_ABSY:
read_to(pcSC, ar);
pcSC++;
state = A_ABSY1;
break;
case A_ABSY1:
read_to(pcSC, ar2); // Note: Some undocumented opcodes rely on the value of ar2
pcSC++;
if (ar+y < 0x100)
state = A_ABSY2;
else
state = A_ABSY3;
ar = (ar + y) & 0xff | (ar2 << 8);
break;
case A_ABSY2: // No page crossed
read_idle(ar);
Execute;
case A_ABSY3: // Page crossed
read_idle(ar);
ar += 0x100;
Execute;
case A_INDX:
read_to(pcSC, ar2);
pcSC++;
state = A_INDX1;
break;
case A_INDX1:
read_idle(ar2);
ar2 = (ar2 + x) & 0xff;
state = A_INDX2;
break;
case A_INDX2:
read_to(ar2, ar);
state = A_INDX3;
break;
case A_INDX3:
read_to((ar2 + 1) & 0xff, data);
ar = ar | (data << 8);
Execute;
case A_INDY:
read_to(pcSC, ar2);
pcSC++;
state = A_INDY1;
break;
case A_INDY1:
read_to(ar2, ar);
state = A_INDY2;
break;
case A_INDY2:
read_to((ar2 + 1) & 0xff, ar2); // Note: Some undocumented opcodes rely on the value of ar2
if (ar+y < 0x100)
state = A_INDY3;
else
state = A_INDY4;
ar = (ar + y) & 0xff | (ar2 << 8);
break;
case A_INDY3: // No page crossed
read_idle(ar);
Execute;
case A_INDY4: // Page crossed
read_idle(ar);
ar += 0x100;
Execute;
// Addressing modes: Fetch effective address, extra cycle on page crossing (-> ar)
case AE_ABSX:
read_to(pcSC, ar);
pcSC++;
state = AE_ABSX1;
break;
case AE_ABSX1:
read_to(pcSC, data);
pcSC++;
if (ar+x < 0x100) {
ar = (ar + x) & 0xff | (data << 8);
Execute;
} else {
ar = (ar + x) & 0xff | (data << 8);
state = AE_ABSX2;
}
break;
case AE_ABSX2: // Page crossed
read_idle(ar);
ar += 0x100;
Execute;
case AE_ABSY:
read_to(pcSC, ar);
pcSC++;
state = AE_ABSY1;
break;
case AE_ABSY1:
read_to(pcSC, data);
pcSC++;
if (ar+y < 0x100) {
ar = (ar + y) & 0xff | (data << 8);
Execute;
} else {
ar = (ar + y) & 0xff | (data << 8);
state = AE_ABSY2;
}
break;
case AE_ABSY2: // Page crossed
read_idle(ar);
ar += 0x100;
Execute;
case AE_INDY:
read_to(pcSC, ar2);
pcSC++;
state = AE_INDY1;
break;
case AE_INDY1:
read_to(ar2, ar);
state = AE_INDY2;
break;
case AE_INDY2:
read_to((ar2 + 1) & 0xff, data);
if (ar+y < 0x100) {
ar = (ar + y) & 0xff | (data << 8);
Execute;
} else {
ar = (ar + y) & 0xff | (data << 8);
state = AE_INDY3;
}
break;
case AE_INDY3: // Page crossed
read_idle(ar);
ar += 0x100;
Execute;
// Addressing modes: Read operand, write it back, no extra cycles (-> ar, rdbuf)
case M_ZERO:
read_to(pcSC, ar);
pcSC++;
DoRMW;
case M_ZEROX:
read_to(pcSC, ar);
pcSC++;
state = M_ZEROX1;
break;
case M_ZEROX1:
read_idle(ar);
ar = (ar + x) & 0xff;
DoRMW;
case M_ZEROY:
read_to(pcSC, ar);
pcSC++;
state = M_ZEROY1;
break;
case M_ZEROY1:
read_idle(ar);
ar = (ar + y) & 0xff;
DoRMW;
case M_ABS:
read_to(pcSC, ar);
pcSC++;
state = M_ABS1;
break;
case M_ABS1:
read_to(pcSC, data);
pcSC++;
ar = ar | (data << 8);
DoRMW;
case M_ABSX:
read_to(pcSC, ar);
pcSC++;
state = M_ABSX1;
break;
case M_ABSX1:
read_to(pcSC, data);
pcSC++;
if (ar+x < 0x100)
state = M_ABSX2;
else
state = M_ABSX3;
ar = (ar + x) & 0xff | (data << 8);
break;
case M_ABSX2: // No page crossed
read_idle(ar);
DoRMW;
case M_ABSX3: // Page crossed
read_idle(ar);
ar += 0x100;
DoRMW;
case M_ABSY:
read_to(pcSC, ar);
pcSC++;
state = M_ABSY1;
break;
case M_ABSY1:
read_to(pcSC, data);
pcSC++;
if (ar+y < 0x100)
state = M_ABSY2;
else
state = M_ABSY3;
ar = (ar + y) & 0xff | (data << 8);
break;
case M_ABSY2: // No page crossed
read_idle(ar);
DoRMW;
case M_ABSY3: // Page crossed
read_idle(ar);
ar += 0x100;
DoRMW;
case M_INDX:
read_to(pcSC, ar2);
pcSC++;
state = M_INDX1;
break;
case M_INDX1:
read_idle(ar2);
ar2 = (ar2 + x) & 0xff;
state = M_INDX2;
break;
case M_INDX2:
read_to(ar2, ar);
state = M_INDX3;
break;
case M_INDX3:
read_to((ar2 + 1) & 0xff, data);
ar = ar | (data << 8);
DoRMW;
case M_INDY:
read_to(pcSC, ar2);
pcSC++;
state = M_INDY1;
break;
case M_INDY1:
read_to(ar2, ar);
state = M_INDY2;
break;
case M_INDY2:
read_to((ar2 + 1) & 0xff, data);
if (ar+y < 0x100)
state = M_INDY3;
else
state = M_INDY4;
ar = (ar + y) & 0xff | (data << 8);
break;
case M_INDY3: // No page crossed
read_idle(ar);
DoRMW;
case M_INDY4: // Page crossed
read_idle(ar);
ar += 0x100;
DoRMW;
case RMW_DO_IT:
read_to(ar, rdbuf);
state = RMW_DO_IT1;
break;
case RMW_DO_IT1:
write_byte(ar, rdbuf);
Execute;
// Load group
case O_LDA:
read_to(ar, data);
set_nz(a = data);
Last;
case O_LDA_I:
read_to(pcSC, data);
pcSC++;
set_nz(a = data);
Last;
case O_LDX:
read_to(ar, data);
set_nz(x = data);
Last;
case O_LDX_I:
read_to(pcSC, data);
pcSC++;
set_nz(x = data);
Last;
case O_LDY:
read_to(ar, data);
set_nz(y = data);
Last;
case O_LDY_I:
read_to(pcSC, data);
pcSC++;
set_nz(y = data);
Last;
// Store group
case O_STA:
write_byte(ar, a);
Last;
case O_STX:
write_byte(ar, x);
Last;
case O_STY:
write_byte(ar, y);
Last;
// Transfer group
case O_TAX:
read_idle(pcSC);
set_nz(x = a);
Last;
case O_TXA:
read_idle(pcSC);
set_nz(a = x);
Last;
case O_TAY:
read_idle(pcSC);
set_nz(y = a);
Last;
case O_TYA:
read_idle(pcSC);
set_nz(a = y);
Last;
case O_TSX:
read_idle(pcSC);
set_nz(x = sp);
Last;
case O_TXS:
read_idle(pcSC);
sp = x;
Last;
// Arithmetic group
case O_ADC:
read_to(ar, data);
do_adc(data);
Last;
case O_ADC_I:
read_to(pcSC, data);
pcSC++;
do_adc(data);
Last;
case O_SBC:
read_to(ar, data);
do_sbc(data);
Last;
case O_SBC_I:
read_to(pcSC, data);
pcSC++;
do_sbc(data);
Last;
// Increment/decrement group
case O_INX:
read_idle(pcSC);
set_nz(++x);
Last;
case O_DEX:
read_idle(pcSC);
set_nz(--x);
Last;
case O_INY:
read_idle(pcSC);
set_nz(++y);
Last;
case O_DEY:
read_idle(pcSC);
set_nz(--y);
Last;
case O_INC:
write_byte(ar, set_nz(rdbuf + 1));
Last;
case O_DEC:
write_byte(ar, set_nz(rdbuf - 1));
Last;
// Logic group
case O_AND:
read_to(ar, data);
set_nz(a &= data);
Last;
case O_AND_I:
read_to(pcSC, data);
pcSC++;
set_nz(a &= data);
Last;
case O_ORA:
read_to(ar, data);
set_nz(a |= data);
Last;
case O_ORA_I:
read_to(pcSC, data);
pcSC++;
set_nz(a |= data);
Last;
case O_EOR:
read_to(ar, data);
set_nz(a ^= data);
Last;
case O_EOR_I:
read_to(pcSC, data);
pcSC++;
set_nz(a ^= data);
Last;
// Compare group
case O_CMP:
read_to(ar, data);
set_nz(ar = a - data);
c_flag = ar < 0x100;
Last;
case O_CMP_I:
read_to(pcSC, data);
pcSC++;
set_nz(ar = a - data);
c_flag = ar < 0x100;
Last;
case O_CPX:
read_to(ar, data);
set_nz(ar = x - data);
c_flag = ar < 0x100;
Last;
case O_CPX_I:
read_to(pcSC, data);
pcSC++;
set_nz(ar = x - data);
c_flag = ar < 0x100;
Last;
case O_CPY:
read_to(ar, data);
set_nz(ar = y - data);
c_flag = ar < 0x100;
Last;
case O_CPY_I:
read_to(pcSC, data);
pcSC++;
set_nz(ar = y - data);
c_flag = ar < 0x100;
Last;
// Bit-test group
case O_BIT:
read_to(ar, data);
z_flag = a & data;
n_flag = data;
v_flag = data & 0x40;
Last;
// Shift/rotate group
case O_ASL:
c_flag = rdbuf & 0x80;
write_byte(ar, set_nz(rdbuf << 1));
Last;
case O_ASL_A:
read_idle(pcSC);
c_flag = a & 0x80;
set_nz(a <<= 1);
Last;
case O_LSR:
c_flag = rdbuf & 0x01;
write_byte(ar, set_nz(rdbuf >> 1));
Last;
case O_LSR_A:
read_idle(pcSC);
c_flag = a & 0x01;
set_nz(a >>= 1);
Last;
case O_ROL:
write_byte(ar, set_nz(c_flag ? (rdbuf << 1) | 0x01 : rdbuf << 1));
c_flag = rdbuf & 0x80;
Last;
case O_ROL_A:
read_idle(pcSC);
data = a & 0x80;
set_nz(a = c_flag ? (a << 1) | 0x01 : a << 1);
c_flag = data;
Last;
case O_ROR:
write_byte(ar, set_nz(c_flag ? (rdbuf >> 1) | 0x80 : rdbuf >> 1));
c_flag = rdbuf & 0x01;
Last;
case O_ROR_A:
read_idle(pcSC);
data = a & 0x01;
set_nz(a = (c_flag ? (a >> 1) | 0x80 : a >> 1));
c_flag = data;
Last;
// Stack group
case O_PHA:
read_idle(pcSC);
state = O_PHA1;
break;
case O_PHA1:
write_byte(sp-- | 0x100, a);
Last;
case O_PLA:
read_idle(pcSC);
state = O_PLA1;
break;
case O_PLA1:
read_idle(sp | 0x100);
sp++;
state = O_PLA2;
break;
case O_PLA2:
read_to(sp | 0x100, data);
set_nz(a = data);
Last;
case O_PHP:
read_idle(pcSC);
state = O_PHP1;
break;
case O_PHP1:
push_flags(true);
Last;
case O_PLP:
read_idle(pcSC);
state = O_PLP1;
break;
case O_PLP1:
read_idle(sp | 0x100);
sp++;
state = O_PLP2;
break;
case O_PLP2:
pop_flags();
Last;
// Jump/branch group
case O_JMP:
read_to(pcSC, ar);
pcSC++;
state = O_JMP1;
break;
case O_JMP1:
read_to(pcSC, data);
pcSC = (data << 8) | ar;
Last;
case O_JMP_I:
read_to(ar, pcSC);
state = O_JMP_I1;
break;
case O_JMP_I1:
read_to((ar + 1) & 0xff | ar & 0xff00, data);
pcSC |= data << 8;
Last;
case O_JSR:
read_to(pcSC, ar);
pcSC++;
state = O_JSR1;
break;
case O_JSR1:
read_idle(sp | 0x100);
state = O_JSR2;
break;
case O_JSR2:
write_byte(sp-- | 0x100, pcSC >> 8);
state = O_JSR3;
break;
case O_JSR3:
write_byte(sp-- | 0x100, pcSC);
state = O_JSR4;
break;
case O_JSR4:
read_to(pcSC, data);
pcSC++;
pcSC = ar | (data << 8);
Last;
case O_RTS:
read_idle(pcSC);
state = O_RTS1;
break;
case O_RTS1:
read_idle(sp | 0x100);
sp++;
state = O_RTS2;
break;
case O_RTS2:
read_to(sp | 0x100, pcSC);
sp++;
state = O_RTS3;
break;
case O_RTS3:
read_to(sp | 0x100, data);
pcSC |= data << 8;
state = O_RTS4;
break;
case O_RTS4:
read_idle(pcSC);
pcSC++;
Last;
case O_RTI:
read_idle(pcSC);
state = O_RTI1;
break;
case O_RTI1:
read_idle(sp | 0x100);
sp++;
state = O_RTI2;
break;
case O_RTI2:
pop_flags();
sp++;
state = O_RTI3;
break;
case O_RTI3:
read_to(sp | 0x100, pcSC);
sp++;
state = O_RTI4;
break;
case O_RTI4:
read_to(sp | 0x100, data);
pcSC |= data << 8;
Last;
case O_BRK:
read_idle(pcSC);
pcSC++;
state = O_BRK1;
break;
case O_BRK1:
write_byte(sp-- | 0x100, pcSC >> 8);
state = O_BRK2;
break;
case O_BRK2:
write_byte(sp-- | 0x100, pcSC);
state = O_BRK3;
break;
case O_BRK3:
push_flags(true);
i_flag = true;
#ifndef IS_CPU_1541
if (interrupt.intr[INT_NMI]) { // BRK interrupted by NMI?
interrupt.intr[INT_NMI] = false; // Simulate an edge-triggered input
state = 0x0015; // Jump to NMI sequence
break;
}
#endif
state = O_BRK4;
break;
case O_BRK4:
#ifndef IS_CPU_1541
first_nmi_cycle++; // Delay NMI
#endif
read_to(0xfffe, pcSC);
state = O_BRK5;
break;
case O_BRK5:
read_to(0xffff, data);
pcSC |= data << 8;
Last;
case O_BCS:
Branch(c_flag);
case O_BCC:
Branch(!c_flag);
case O_BEQ:
Branch(!z_flag);
case O_BNE:
Branch(z_flag);
case O_BVS:
#ifndef IS_CPU_1541
Branch(v_flag);
#else
Branch((via2_pcr & 0x0e) == 0x0e ? 1 : v_flag); // GCR byte ready flag
#endif
case O_BVC:
#ifndef IS_CPU_1541
Branch(!v_flag);
#else
Branch(!((via2_pcr & 0x0e) == 0x0e) ? 0 : v_flag); // GCR byte ready flag
#endif
case O_BMI:
Branch(n_flag & 0x80);
case O_BPL:
Branch(!(n_flag & 0x80));
case O_BRANCH_NP: // No page crossed
first_irq_cycle++; // Delay IRQ
#ifndef IS_CPU_1541
first_nmi_cycle++; // Delay NMI
#endif
read_idle(pcSC);
pcSC = ar;
Last;
case O_BRANCH_BP: // Page crossed, branch backwards
read_idle(pcSC);
pcSC = ar;
state = O_BRANCH_BP1;
break;
case O_BRANCH_BP1:
read_idle(pcSC + 0x100);
Last;
case O_BRANCH_FP: // Page crossed, branch forwards
read_idle(pcSC);
pcSC = ar;
state = O_BRANCH_FP1;
break;
case O_BRANCH_FP1:
read_idle(pcSC - 0x100);
Last;
// Flag group
case O_SEC:
read_idle(pcSC);
c_flag = true;
Last;
case O_CLC:
read_idle(pcSC);
c_flag = false;
Last;
case O_SED:
read_idle(pcSC);
d_flag = true;
Last;
case O_CLD:
read_idle(pcSC);
d_flag = false;
Last;
case O_SEI:
read_idle(pcSC);
i_flag = true;
Last;