-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspc700.cpp
More file actions
2509 lines (2189 loc) · 60.2 KB
/
Copy pathspc700.cpp
File metadata and controls
2509 lines (2189 loc) · 60.2 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
/*
* Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
*
* (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
* Jerremy Koot (jkoot@snes9x.com)
*
* Super FX C emulator code
* (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
* Gary Henderson.
* Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
*
* DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
* C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
* C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
*
* DOS port code contains the works of other authors. See headers in
* individual files.
*
* Snes9x homepage: http://www.snes9x.com
*
* Permission to use, copy, modify and distribute Snes9x in both binary and
* source form, for non-commercial purposes, is hereby granted without fee,
* providing that this license information and copyright notice appear with
* all copies and any derived work.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event shall the authors be held liable for any damages
* arising from the use of this software.
*
* Snes9x is freeware for PERSONAL USE only. Commercial users should
* seek permission of the copyright holders first. Commercial use includes
* charging money for Snes9x or software derived from Snes9x.
*
* The copyright holders request that bug fixes and improvements to the code
* should be forwarded to them so everyone can benefit from the modifications
* in future versions.
*
* Super NES and Super Nintendo Entertainment System are trademarks of
* Nintendo Co., Limited and its subsidiary companies.
*/
#include "snes9x.h"
#include "spc700.h"
#include "memmap.h"
#include "display.h"
#include "cpuexec.h"
#include "apu.h"
// SPC700/Sound DSP chips have a 24.57MHz crystal on their PCB.
#ifdef NO_INLINE_SET_GET
uint8 S9xAPUGetByteZ (uint8 address, struct SIAPU *);
uint8 S9xAPUGetByte (uint32 address, struct SIAPU *);
void S9xAPUSetByteZ (uint8, uint8 address, struct SIAPU *, struct SAPU *);
void S9xAPUSetByte (uint8, uint32 address, struct SIAPU *, struct SAPU *);
#else
#undef INLINE
#define INLINE inline
#include "apumem.h"
#endif
START_EXTERN_C
/*
extern uint8 Work8;
extern uint16 Work16;
extern uint32 Work32;
extern signed char Int8;
extern short Int16;
extern long Int32;
extern short Int16;
extern uint8 W1;
extern uint8 W2;
*/
END_EXTERN_C
#define OP1 (*(iapu->PC + 1))
#define OP2 (*(iapu->PC + 2))
#ifdef SPC700_SHUTDOWN
#define APUShutdown() \
if (Settings.Shutdown && (iapu->PC == iapu->WaitAddress1 || iapu->PC == iapu->WaitAddress2)) \
{ \
if (iapu->WaitCounter == 0) \
{ \
if (!ICPU.CPUExecuting) \
apu->Cycles = CPU.Cycles = CPU.NextEvent; \
else \
iapu->APUExecuting = FALSE; \
} \
else \
if (iapu->WaitCounter >= 2) \
iapu->WaitCounter = 1; \
else \
iapu->WaitCounter--; \
}
#else
#define APUShutdown()
#endif
#define APUSetZN8(b)\
iapu->_Zero = (b);
#define APUSetZN16(w)\
iapu->_Zero = ((w) != 0) | ((w) >> 8);
#ifndef _ZAURUS
void STOP (char *s)
{
char buffer[100];
#ifdef DEBUGGER
S9xAPUOPrint (buffer, IAPU.PC - IAPU.RAM);
#endif
sprintf (String, "Sound CPU in unknown state executing %s at %04X\n%s\n", s, IAPU.PC - IAPU.RAM, buffer);
S9xMessage (S9X_ERROR, S9X_APU_STOPPED, String);
APU.TimerEnabled[0] = APU.TimerEnabled[1] = APU.TimerEnabled[2] = FALSE;
IAPU.APUExecuting = FALSE;
#ifdef DEBUGGER
CPU.Flags |= DEBUG_MODE_FLAG;
#else
S9xExit ();
#endif
}
#endif
#define TCALL(n)\
{\
PushW (iapu->PC - iapu->RAM + 1); \
iapu->PC = iapu->RAM + (apu->ExtraRAM [((15 - n) << 1)] + \
(apu->ExtraRAM [((15 - n) << 1) + 1] << 8)); \
}
// XXX: HalfCarry
#define SBC(a,b)\
int16 Int16 = (short) (a) - (short) (b) + (short) (APUCheckCarry ()) - 1;\
APUClearHalfCarry ();\
iapu->_Carry = Int16 >= 0;\
if ((((a) ^ (b)) & 0x80) && (((a) ^ (uint8) Int16) & 0x80))\
APUSetOverflow ();\
else \
APUClearOverflow (); \
(a) = (uint8) Int16;\
APUSetZN8 ((uint8) Int16);
// XXX: HalfCarry
#define ADC(a,b)\
uint16 Work16 = (a) + (b) + APUCheckCarry();\
APUClearHalfCarry ();\
iapu->_Carry = Work16 >= 0x100; \
if (~((a) ^ (b)) & ((b) ^ (uint8) Work16) & 0x80)\
APUSetOverflow ();\
else \
APUClearOverflow (); \
(a) = (uint8) Work16;\
APUSetZN8 ((uint8) Work16);
#define CMP(a,b)\
int16 Int16 = (short) (a) - (short) (b);\
iapu->_Carry = Int16 >= 0;\
APUSetZN8 ((uint8) Int16);
#define ASL(b)\
iapu->_Carry = ((b) & 0x80) != 0; \
(b) <<= 1;\
APUSetZN8 (b);
#define LSR(b)\
iapu->_Carry = (b) & 1;\
(b) >>= 1;\
APUSetZN8 (b);
#define ROL(b)\
uint16 Work16 = ((b) << 1) | APUCheckCarry (); \
iapu->_Carry = Work16 >= 0x100; \
(b) = (uint8) Work16; \
APUSetZN8 (b);
#define ROR(b)\
uint16 Work16 = (b) | ((uint16) APUCheckCarry () << 8); \
iapu->_Carry = (uint8) Work16 & 1; \
Work16 >>= 1; \
(b) = (uint8) Work16; \
APUSetZN8 (b);
#define Push(b)\
*(iapu->RAM + 0x100 + areg->S) = b;\
areg->S = ((areg->S-1) & 0xff);
#define Pop(b)\
areg->S = ((areg->S+1) & 0xff);\
(b) = *(iapu->RAM + 0x100 + areg->S);
#ifdef FAST_LSB_WORD_ACCESS
#define PushW(w)\
*(uint16 *) (iapu->RAM + 0xff + areg->S) = w;\
areg->S = ((areg->S-2) & 0xff);;
#define PopW(w)\
areg->S = ((areg->S+2) & 0xff);\
w = *(uint16 *) (iapu->RAM + 0xff + areg->S);
#else
#define PushW(w)\
*(iapu->RAM + 0xff + areg->S) = w;\
*(iapu->RAM + 0x100 + areg->S) = (w >> 8);\
areg->S = ((areg->S-2) & 0xff);;
#define PopW(w)\
areg->S = ((areg->S+2) & 0xff);; \
(w) = *(iapu->RAM + 0xff + areg->S) + (*(iapu->RAM + 0x100 + areg->S) << 8);
#endif
#define Relative()\
int8 Int8 = OP1;\
int16 Int16 = (int) (iapu->PC + 2 - iapu->RAM) + Int8;
#define Relative2()\
int8 Int8 = OP2;\
int16 Int16 = (int) (iapu->PC + 3 - iapu->RAM) + Int8;
#ifdef FAST_LSB_WORD_ACCESS
#define IndexedXIndirect()\
iapu->Address = *(uint16 *) (iapu->DirectPage + ((OP1 + areg->X) & 0xff));
#define Absolute()\
iapu->Address = *(uint16 *) (iapu->PC + 1);
#define AbsoluteX()\
iapu->Address = *(uint16 *) (iapu->PC + 1) + areg->X;
#define AbsoluteY()\
iapu->Address = *(uint16 *) (iapu->PC + 1) + areg->YA.B.Y;
#define MemBit()\
iapu->Address = *(uint16 *) (iapu->PC + 1);\
iapu->Bit = (uint8)(iapu->Address >> 13);\
iapu->Address &= 0x1fff;
#define IndirectIndexedY()\
iapu->Address = *(uint16 *) (iapu->DirectPage + OP1) + areg->YA.B.Y;
#else
#define IndexedXIndirect()\
iapu->Address = *(iapu->DirectPage + ((OP1 + areg->X) & 0xff)) + \
(*(iapu->DirectPage + ((OP1 + areg->X + 1) & 0xff)) << 8);
#define Absolute()\
iapu->Address = OP1 + (OP2 << 8);
#define AbsoluteX()\
iapu->Address = OP1 + (OP2 << 8) + areg->X;
#define AbsoluteY()\
iapu->Address = OP1 + (OP2 << 8) + areg->YA.B.Y;
#define MemBit()\
iapu->Address = OP1 + (OP2 << 8);\
iapu->Bit = (int8) (iapu->Address >> 13);\
iapu->Address &= 0x1fff;
#define IndirectIndexedY()\
iapu->Address = *(iapu->DirectPage + OP1) + \
(*(iapu->DirectPage + OP1 + 1) << 8) + \
areg->YA.B.Y;
#endif
void Apu00 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// NOP
iapu->PC++;
}
void Apu01 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (0) }
void Apu11 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (1) }
void Apu21 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (2) }
void Apu31 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (3) }
void Apu41 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (4) }
void Apu51 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (5) }
void Apu61 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (6) }
void Apu71 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (7) }
void Apu81 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (8) }
void Apu91 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (9) }
void ApuA1 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (10) }
void ApuB1 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (11) }
void ApuC1 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (12) }
void ApuD1 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (13) }
void ApuE1 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (14) }
void ApuF1 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) { TCALL (15) }
void Apu3F (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) // CALL absolute
{
Absolute ();
// 0xB6f for Star Fox 2
PushW (iapu->PC + 3 - iapu->RAM);
iapu->PC = iapu->RAM + iapu->Address;
}
void Apu4F (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu) // PCALL $XX
{
uint8 Work8 = OP1;
PushW (iapu->PC + 2 - iapu->RAM);
iapu->PC = iapu->RAM + 0xff00 + Work8;
}
#define SET(b) \
S9xAPUSetByteZ ((uint8) (S9xAPUGetByteZ (OP1 , iapu) | (1 << (b))), OP1, iapu, apu); \
iapu->PC += 2
void Apu02 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
SET (0);
}
void Apu22 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
SET (1);
}
void Apu42 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
SET (2);
}
void Apu62 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
SET (3);
}
void Apu82 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
SET (4);
}
void ApuA2 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
SET (5);
}
void ApuC2 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
SET (6);
}
void ApuE2 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
SET (7);
}
#define CLR(b) \
S9xAPUSetByteZ ((uint8) (S9xAPUGetByteZ (OP1, iapu) & ~(1 << (b))), OP1, iapu, apu); \
iapu->PC += 2;
void Apu12 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
CLR (0);
}
void Apu32 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
CLR (1);
}
void Apu52 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
CLR (2);
}
void Apu72 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
CLR (3);
}
void Apu92 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
CLR (4);
}
void ApuB2 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
CLR (5);
}
void ApuD2 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
CLR (6);
}
void ApuF2 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
CLR (7);
}
#define BBS(b) \
uint8 Work8 = OP1; \
Relative2 (); \
if (S9xAPUGetByteZ (Work8, iapu) & (1 << (b))) \
{ \
iapu->PC = iapu->RAM + (uint16) Int16; \
apu->Cycles += iapu->TwoCycles; \
} \
else \
iapu->PC += 3
void Apu03 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBS (0);
}
void Apu23 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBS (1);
}
void Apu43 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBS (2);
}
void Apu63 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBS (3);
}
void Apu83 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBS (4);
}
void ApuA3 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBS (5);
}
void ApuC3 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBS (6);
}
void ApuE3 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBS (7);
}
#define BBC(b) \
uint8 Work8 = OP1; \
Relative2 (); \
if (!(S9xAPUGetByteZ (Work8, iapu) & (1 << (b)))) \
{ \
iapu->PC = iapu->RAM + (uint16) Int16; \
apu->Cycles += iapu->TwoCycles; \
} \
else \
iapu->PC += 3
void Apu13 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBC (0);
}
void Apu33 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBC (1);
}
void Apu53 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBC (2);
}
void Apu73 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBC (3);
}
void Apu93 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBC (4);
}
void ApuB3 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBC (5);
}
void ApuD3 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBC (6);
}
void ApuF3 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
BBC (7);
}
void Apu04 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// OR A,dp
areg->YA.B.A |= S9xAPUGetByteZ (OP1, iapu);
APUSetZN8 (areg->YA.B.A);
iapu->PC += 2;
}
void Apu05 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// OR A,abs
Absolute ();
areg->YA.B.A |= S9xAPUGetByte (iapu->Address, iapu);
APUSetZN8 (areg->YA.B.A);
iapu->PC += 3;
}
void Apu06 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// OR A,(X)
areg->YA.B.A |= S9xAPUGetByteZ (areg->X, iapu);
APUSetZN8 (areg->YA.B.A);
iapu->PC++;
}
void Apu07 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// OR A,(dp+X)
IndexedXIndirect ();
areg->YA.B.A |= S9xAPUGetByte (iapu->Address, iapu);
APUSetZN8 (areg->YA.B.A);
iapu->PC += 2;
}
void Apu08 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// OR A,#00
areg->YA.B.A |= OP1;
APUSetZN8 (areg->YA.B.A);
iapu->PC += 2;
}
void Apu09 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// OR dp(dest),dp(src)
uint8 Work8 = S9xAPUGetByteZ (OP1, iapu);
Work8 |= S9xAPUGetByteZ (OP2, iapu);
S9xAPUSetByteZ (Work8, OP2, iapu, apu);
APUSetZN8 (Work8);
iapu->PC += 3;
}
void Apu14 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// OR A,dp+X
areg->YA.B.A |= S9xAPUGetByteZ (OP1 + areg->X, iapu);
APUSetZN8 (areg->YA.B.A);
iapu->PC += 2;
}
void Apu15 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// OR A,abs+X
AbsoluteX ();
areg->YA.B.A |= S9xAPUGetByte (iapu->Address, iapu);
APUSetZN8 (areg->YA.B.A);
iapu->PC += 3;
}
void Apu16 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// OR A,abs+Y
AbsoluteY ();
areg->YA.B.A |= S9xAPUGetByte (iapu->Address, iapu);
APUSetZN8 (areg->YA.B.A);
iapu->PC += 3;
}
void Apu17 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// OR A,(dp)+Y
IndirectIndexedY ();
areg->YA.B.A |= S9xAPUGetByte (iapu->Address, iapu);
APUSetZN8 (areg->YA.B.A);
iapu->PC += 2;
}
void Apu18 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// OR dp,#00
uint8 Work8 = OP1;
Work8 |= S9xAPUGetByteZ (OP2, iapu);
S9xAPUSetByteZ (Work8, OP2, iapu, apu);
APUSetZN8 (Work8);
iapu->PC += 3;
}
void Apu19 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// OR (X),(Y)
uint8 Work8 = S9xAPUGetByteZ (areg->X, iapu) | S9xAPUGetByteZ (areg->YA.B.Y, iapu);
APUSetZN8 (Work8);
S9xAPUSetByteZ (Work8, areg->X, iapu, apu);
iapu->PC++;
}
void Apu0A (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// OR1 C,membit
MemBit ();
if (!APUCheckCarry ())
{
if (S9xAPUGetByte (iapu->Address, iapu) & (1 << iapu->Bit))
APUSetCarry ();
}
iapu->PC += 3;
}
void Apu2A (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// OR1 C,not membit
MemBit ();
if (!APUCheckCarry ())
{
if (!(S9xAPUGetByte (iapu->Address, iapu) & (1 << iapu->Bit)))
APUSetCarry ();
}
iapu->PC += 3;
}
void Apu4A (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// AND1 C,membit
MemBit ();
if (APUCheckCarry ())
{
if (!(S9xAPUGetByte (iapu->Address, iapu) & (1 << iapu->Bit)))
APUClearCarry ();
}
iapu->PC += 3;
}
void Apu6A (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// AND1 C, not membit
MemBit ();
if (APUCheckCarry ())
{
if ((S9xAPUGetByte (iapu->Address, iapu) & (1 << iapu->Bit)))
APUClearCarry ();
}
iapu->PC += 3;
}
void Apu8A (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// EOR1 C, membit
MemBit ();
if (APUCheckCarry ())
{
if (S9xAPUGetByte (iapu->Address, iapu) & (1 << iapu->Bit))
APUClearCarry ();
}
else
{
if (S9xAPUGetByte (iapu->Address, iapu) & (1 << iapu->Bit))
APUSetCarry ();
}
iapu->PC += 3;
}
void ApuAA (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// MOV1 C,membit
MemBit ();
if (S9xAPUGetByte (iapu->Address, iapu) & (1 << iapu->Bit))
APUSetCarry ();
else
APUClearCarry ();
iapu->PC += 3;
}
void ApuCA (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// MOV1 membit,C
MemBit ();
if (APUCheckCarry ())
{
S9xAPUSetByte (S9xAPUGetByte (iapu->Address, iapu) | (1 << iapu->Bit), iapu->Address, iapu, apu);
}
else
{
S9xAPUSetByte (S9xAPUGetByte (iapu->Address, iapu) & ~(1 << iapu->Bit), iapu->Address, iapu, apu);
}
iapu->PC += 3;
}
void ApuEA (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// NOT1 membit
MemBit ();
S9xAPUSetByte (S9xAPUGetByte (iapu->Address, iapu) ^ (1 << iapu->Bit), iapu->Address, iapu, apu);
iapu->PC += 3;
}
void Apu0B (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// ASL dp
uint8 Work8 = S9xAPUGetByteZ (OP1, iapu);
ASL (Work8);
S9xAPUSetByteZ (Work8, OP1, iapu, apu);
iapu->PC += 2;
}
void Apu0C (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// ASL abs
Absolute ();
uint8 Work8 = S9xAPUGetByte (iapu->Address, iapu);
ASL (Work8);
S9xAPUSetByte (Work8, iapu->Address, iapu, apu);
iapu->PC += 3;
}
void Apu1B (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// ASL dp+X
uint8 Work8 = S9xAPUGetByteZ (OP1 + areg->X, iapu);
ASL (Work8);
S9xAPUSetByteZ (Work8, OP1 + areg->X, iapu, apu);
iapu->PC += 2;
}
void Apu1C (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// ASL A
ASL (areg->YA.B.A);
iapu->PC++;
}
void Apu0D (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// PUSH PSW
S9xAPUPackStatus_OP ();
Push (areg->P);
iapu->PC++;
}
void Apu2D (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// PUSH A
Push (areg->YA.B.A);
iapu->PC++;
}
void Apu4D (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// PUSH X
Push (areg->X);
iapu->PC++;
}
void Apu6D (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// PUSH Y
Push (areg->YA.B.Y);
iapu->PC++;
}
void Apu8E (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// POP PSW
Pop (areg->P);
S9xAPUUnpackStatus_OP();
if (APUCHECKDIRECTPAGE_OP ())
iapu->DirectPage = iapu->RAM + 0x100;
else
iapu->DirectPage = iapu->RAM;
iapu->PC++;
}
void ApuAE (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// POP A
Pop (areg->YA.B.A);
iapu->PC++;
}
void ApuCE (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// POP X
Pop (areg->X);
iapu->PC++;
}
void ApuEE (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// POP Y
Pop (areg->YA.B.Y);
iapu->PC++;
}
void Apu0E (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// TSET1 abs
Absolute ();
uint8 Work8 = S9xAPUGetByte (iapu->Address, iapu);
S9xAPUSetByte (Work8 | areg->YA.B.A, iapu->Address, iapu, apu);
Work8 &= areg->YA.B.A;
APUSetZN8 (Work8);
iapu->PC += 3;
}
void Apu4E (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// TCLR1 abs
Absolute ();
uint8 Work8 = S9xAPUGetByte (iapu->Address, iapu);
S9xAPUSetByte (Work8 & ~areg->YA.B.A, iapu->Address, iapu, apu);
Work8 &= areg->YA.B.A;
APUSetZN8 (Work8);
iapu->PC += 3;
}
void Apu0F (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// BRK
#if 0
STOP ("BRK");
#else
PushW (iapu->PC + 1 - iapu->RAM);
S9xAPUPackStatus_OP ();
Push (areg->P);
APUSetBreak ();
APUClearInterrupt ();
// XXX:Where is the BRK vector ???
iapu->PC = iapu->RAM + apu->ExtraRAM[0x20] + (apu->ExtraRAM[0x21] << 8);
#endif
}
void ApuEF (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// SLEEP
// XXX: sleep
// STOP ("SLEEP");
iapu->APUExecuting = FALSE;
iapu->PC++;
}
void ApuFF (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// STOP
// STOP ("STOP");
iapu->APUExecuting = FALSE;
iapu->PC++;
}
void Apu10 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// BPL
Relative ();
if (!APUCheckNegative ())
{
iapu->PC = iapu->RAM + (uint16) Int16;
apu->Cycles += iapu->TwoCycles;
APUShutdown ();
}
else
iapu->PC += 2;
}
void Apu30 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// BMI
Relative ();
if (APUCheckNegative ())
{
iapu->PC = iapu->RAM + (uint16) Int16;
apu->Cycles += iapu->TwoCycles;
APUShutdown ();
}
else
iapu->PC += 2;
}
void Apu90 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// BCC
Relative ();
if (!APUCheckCarry ())
{
iapu->PC = iapu->RAM + (uint16) Int16;
apu->Cycles += iapu->TwoCycles;
APUShutdown ();
}
else
iapu->PC += 2;
}
void ApuB0 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// BCS
Relative ();
if (APUCheckCarry ())
{
iapu->PC = iapu->RAM + (uint16) Int16;
apu->Cycles += iapu->TwoCycles;
APUShutdown ();
}
else
iapu->PC += 2;
}
void ApuD0 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// BNE
Relative ();
if (!APUCheckZero ())
{
iapu->PC = iapu->RAM + (uint16) Int16;
apu->Cycles += iapu->TwoCycles;
APUShutdown ();
}
else
iapu->PC += 2;
}
void ApuF0 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// BEQ
Relative ();
if (APUCheckZero ())
{
iapu->PC = iapu->RAM + (uint16) Int16;
apu->Cycles += iapu->TwoCycles;
APUShutdown ();
}
else
iapu->PC += 2;
}
void Apu50 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// BVC
Relative ();
if (!APUCheckOverflow ())
{
iapu->PC = iapu->RAM + (uint16) Int16;
apu->Cycles += iapu->TwoCycles;
}
else
iapu->PC += 2;
}
void Apu70 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// BVS
Relative ();
if (APUCheckOverflow ())
{
iapu->PC = iapu->RAM + (uint16) Int16;
apu->Cycles += iapu->TwoCycles;
}
else
iapu->PC += 2;
}
void Apu2F (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// BRA
Relative ();
iapu->PC = iapu->RAM + (uint16) Int16;
}
void Apu80 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// SETC
APUSetCarry ();
iapu->PC++;
}
void ApuED (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// NOTC
iapu->_Carry ^= 1;
iapu->PC++;
}
void Apu40 (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)
{
// SETP
APUSetDirectPage ();
iapu->DirectPage = iapu->RAM + 0x100;
iapu->PC++;
}
void Apu1A (struct SAPURegisters * areg, struct SIAPU * iapu, struct SAPU * apu)