workaround a problem with the harmattan gcc
[drnoksnes] / spc700.cpp
1 /*
2  * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3  *
4  * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5  *                           Jerremy Koot (jkoot@snes9x.com)
6  *
7  * Super FX C emulator code 
8  * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
9  *                           Gary Henderson.
10  * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
11  *
12  * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
13  * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
14  * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
15  *
16  * DOS port code contains the works of other authors. See headers in
17  * individual files.
18  *
19  * Snes9x homepage: http://www.snes9x.com
20  *
21  * Permission to use, copy, modify and distribute Snes9x in both binary and
22  * source form, for non-commercial purposes, is hereby granted without fee,
23  * providing that this license information and copyright notice appear with
24  * all copies and any derived work.
25  *
26  * This software is provided 'as-is', without any express or implied
27  * warranty. In no event shall the authors be held liable for any damages
28  * arising from the use of this software.
29  *
30  * Snes9x is freeware for PERSONAL USE only. Commercial users should
31  * seek permission of the copyright holders first. Commercial use includes
32  * charging money for Snes9x or software derived from Snes9x.
33  *
34  * The copyright holders request that bug fixes and improvements to the code
35  * should be forwarded to them so everyone can benefit from the modifications
36  * in future versions.
37  *
38  * Super NES and Super Nintendo Entertainment System are trademarks of
39  * Nintendo Co., Limited and its subsidiary companies.
40  */
41 #include "snes9x.h"
42 #include "memmap.h"
43 #include "cpuexec.h"
44 #include "apu.h"
45 #include "spc700.h"
46
47 // SPC700/Sound DSP chips have a 24.57MHz crystal on their PCB.
48
49 #if defined(ASM_SPC700)
50
51 // we only need the memhandlers
52 #undef INLINE
53 #define INLINE extern "C"
54 #include "apumem.h"
55
56 #else
57
58 #if defined(NO_INLINE_SET_GET)
59 uint8 S9xAPUGetByteZ (uint8 address);
60 uint8 S9xAPUGetByte (uint32 address);
61 void S9xAPUSetByteZ (uint8, uint8 address);
62 void S9xAPUSetByte (uint8, uint32 address);
63 #else
64 #undef INLINE
65 #define INLINE inline
66 #include "apumem.h"
67 #endif
68
69 START_EXTERN_C
70 extern uint8 Work8;
71 extern uint16 Work16;
72 extern uint32 Work32;
73 extern signed char Int8;
74 extern short Int16;
75 extern long Int32;
76 extern short Int16;
77 extern uint8 W1;
78 extern uint8 W2;
79
80 END_EXTERN_C
81
82 #define OP1 (*(IAPU.PC + 1))
83 #define OP2 (*(IAPU.PC + 2))
84
85 #ifdef SPC700_SHUTDOWN
86 #define APUShutdown() \
87     if (Settings.Shutdown && (IAPU.PC == IAPU.WaitAddress1 || IAPU.PC == IAPU.WaitAddress2)) \
88     { \
89                 if (IAPU.WaitCounter == 0) \
90                 { \
91                         if (!ICPU.CPUExecuting) \
92                                 CPU.APU_Cycles = CPU.Cycles = CPU.NextEvent; \
93                         else \
94                                 CPU.APU_APUExecuting = FALSE; \
95                 } \
96                 else \
97                 if (IAPU.WaitCounter >= 2) \
98                         IAPU.WaitCounter = 1; \
99         else \
100             IAPU.WaitCounter--; \
101     }
102 #else
103 #define APUShutdown()
104 #endif
105
106 #define APUSetZN8(b)\
107     IAPU._Zero = (b);
108
109 #define APUSetZN16(w)\
110     IAPU._Zero = ((w) != 0) | ((w) >> 8);
111
112 void STOP (char *s)
113 {
114     char buffer[100];
115
116 #ifdef DEBUGGER
117     S9xAPUOPrint (buffer, IAPU.PC - IAPU.RAM);
118 #endif
119
120     sprintf (String, "Sound CPU in unknown state executing %s at 0x%tx\n%s\n", s, IAPU.PC - IAPU.RAM, buffer);
121     S9xMessage (S9X_ERROR, S9X_APU_STOPPED, String);
122     APU.TimerEnabled[0] = APU.TimerEnabled[1] = APU.TimerEnabled[2] = FALSE;
123     CPU.APU_APUExecuting = FALSE;
124
125 #ifdef DEBUGGER
126     CPU.Flags |= DEBUG_MODE_FLAG;
127 #else
128     abort();
129 #endif
130 }
131
132 #define TCALL(n)\
133 {\
134     PushW ((IAPU.PC - IAPU.RAM + 1)); \
135     IAPU.PC = IAPU.RAM + (APU.ExtraRAM [((15 - n) << 1)] + \
136              (APU.ExtraRAM [((15 - n) << 1) + 1] << 8)); \
137 }
138
139 // XXX: HalfCarry - BJ fixed?
140 #define SBC(a,b)\
141 Int16 = (short) (a) - (short) (b) + (short) (APUCheckCarry ()) - 1;\
142 IAPU._Carry = Int16 >= 0;\
143 if ((((a) ^ (b)) & 0x80) && (((a) ^ (uint8) Int16) & 0x80))\
144     APUSetOverflow ();\
145 else \
146     APUClearOverflow (); \
147 APUSetHalfCarry ();\
148 if(((a) ^ (b) ^ (uint8) Int16) & 0x10)\
149     APUClearHalfCarry ();\
150 (a) = (uint8) Int16;\
151 APUSetZN8 ((uint8) Int16);
152
153 // XXX: HalfCarry - BJ fixed?
154 #define ADC(a,b)\
155 Work16 = (a) + (b) + APUCheckCarry();\
156 IAPU._Carry = Work16 >= 0x100; \
157 if (~((a) ^ (b)) & ((b) ^ (uint8) Work16) & 0x80)\
158     APUSetOverflow ();\
159 else \
160     APUClearOverflow (); \
161 APUClearHalfCarry ();\
162 /*if(((a) ^ (b) ^ (uint8) Int16) & 0x10)  notaz: Int16!? */\
163 if(((a) ^ (b) ^ (uint8) Work16) & 0x10)\
164     APUSetHalfCarry ();\
165 (a) = (uint8) Work16;\
166 APUSetZN8 ((uint8) Work16);
167
168 #define CMP(a,b)\
169 Int16 = (short) (a) - (short) (b);\
170 IAPU._Carry = Int16 >= 0;\
171 APUSetZN8 ((uint8) Int16);
172
173 #define ASL(b)\
174     IAPU._Carry = ((b) & 0x80) != 0; \
175     (b) <<= 1;\
176     APUSetZN8 (b);
177 #define LSR(b)\
178     IAPU._Carry = (b) & 1;\
179     (b) >>= 1;\
180     APUSetZN8 (b);
181 #define ROL(b)\
182     Work16 = ((b) << 1) | APUCheckCarry (); \
183     IAPU._Carry = Work16 >= 0x100; \
184     (b) = (uint8) Work16; \
185     APUSetZN8 (b);
186 #define ROR(b)\
187     Work16 = (b) | ((uint16) APUCheckCarry () << 8); \
188     IAPU._Carry = (uint8) Work16 & 1; \
189     Work16 >>= 1; \
190     (b) = (uint8) Work16; \
191     APUSetZN8 (b);
192
193 #define Push(b)\
194     *(IAPU.RAM + 0x100 + IAPU.S) = b;\
195     IAPU.S--;
196
197 #define Pop(b)\
198     IAPU.S++;\
199     (b) = *(IAPU.RAM + 0x100 + IAPU.S);
200
201 #ifdef FAST_LSB_WORD_ACCESS
202 #define PushW(w)\
203     *(uint16 *) (IAPU.RAM + 0xff + IAPU.S) = w;\
204     IAPU.S -= 2;
205 #define PopW(w)\
206     IAPU.S += 2;\
207     w = *(uint16 *) (IAPU.RAM + 0xff + IAPU.S);
208 #else
209 #define PushW(w)\
210     *(IAPU.RAM + 0xff + IAPU.S) = w;\
211     *(IAPU.RAM + 0x100 + IAPU.S) = (w >> 8);\
212     IAPU.S -= 2;
213 #define PopW(w)\
214     IAPU.S += 2; \
215     (w) = *(IAPU.RAM + 0xff + IAPU.S) + (*(IAPU.RAM + 0x100 + IAPU.S) << 8);
216 #endif
217
218 #define Relative()\
219     Int8 = OP1;\
220     Int16 = (int) (IAPU.PC + 2 - IAPU.RAM) + Int8;
221
222 #define Relative2()\
223     Int8 = OP2;\
224     Int16 = (int) (IAPU.PC + 3 - IAPU.RAM) + Int8;
225
226 #ifdef FAST_LSB_WORD_ACCESS
227 #define IndexedXIndirect()\
228     IAPU.Address = *(uint16 *) (IAPU.DirectPage + ((OP1 + IAPU.X) & 0xff));
229
230 #define Absolute()\
231     IAPU.Address = *(uint16 *) (IAPU.PC + 1);
232
233 #define AbsoluteX()\
234     IAPU.Address = *(uint16 *) (IAPU.PC + 1) + IAPU.X;
235
236 #define AbsoluteY()\
237     IAPU.Address = *(uint16 *) (IAPU.PC + 1) + IAPU.YA.B.Y;
238
239 #define MemBit()\
240     IAPU.Address = *(uint16 *) (IAPU.PC + 1);\
241     IAPU.Bit = (uint8)(IAPU.Address >> 13);\
242     IAPU.Address &= 0x1fff;
243
244 #define IndirectIndexedY()\
245     IAPU.Address = *(uint16 *) (IAPU.DirectPage + OP1) + IAPU.YA.B.Y;
246 #else
247 #define IndexedXIndirect()\
248     IAPU.Address = *(IAPU.DirectPage + ((OP1 + IAPU.X) & 0xff)) + \
249                   (*(IAPU.DirectPage + ((OP1 + IAPU.X + 1) & 0xff)) << 8);
250 #define Absolute()\
251     IAPU.Address = OP1 + (OP2 << 8);
252
253 #define AbsoluteX()\
254     IAPU.Address = OP1 + (OP2 << 8) + IAPU.X;
255
256 #define AbsoluteY()\
257     IAPU.Address = OP1 + (OP2 << 8) + IAPU.YA.B.Y;
258
259 #define MemBit()\
260     IAPU.Address = OP1 + (OP2 << 8);\
261     IAPU.Bit = (int8) (IAPU.Address >> 13);\
262     IAPU.Address &= 0x1fff;
263
264 #define IndirectIndexedY()\
265     IAPU.Address = *(IAPU.DirectPage + OP1) + \
266                   (*(IAPU.DirectPage + OP1 + 1) << 8) + \
267                   IAPU.YA.B.Y;
268 #endif
269
270 void Apu00 ()
271 {
272 // NOP
273     IAPU.PC++;
274 }
275
276 void Apu01 () { TCALL (0) }
277
278 void Apu11 () { TCALL (1) }
279
280 void Apu21 () { TCALL (2) }
281
282 void Apu31 () { TCALL (3) }
283
284 void Apu41 () { TCALL (4) }
285
286 void Apu51 () { TCALL (5) }
287
288 void Apu61 () { TCALL (6) }
289
290 void Apu71 () { TCALL (7) }
291
292 void Apu81 () { TCALL (8) }
293
294 void Apu91 () { TCALL (9) }
295
296 void ApuA1 () { TCALL (10) }
297
298 void ApuB1 () { TCALL (11) }
299
300 void ApuC1 () { TCALL (12) }
301
302 void ApuD1 () { TCALL (13) }
303
304 void ApuE1 () { TCALL (14) }
305
306 void ApuF1 () { TCALL (15) }
307
308 void Apu3F () // CALL absolute
309 {
310     Absolute ();
311     // 0xB6f for Star Fox 2
312     PushW ((IAPU.PC + 3 - IAPU.RAM));
313     IAPU.PC = IAPU.RAM + IAPU.Address;
314 }
315
316 void Apu4F () // PCALL $XX
317 {
318     Work8 = OP1;
319     PushW ((IAPU.PC + 2 - IAPU.RAM));
320     IAPU.PC = IAPU.RAM + 0xff00 + Work8;
321 }
322
323 #define SET(b) \
324 S9xAPUSetByteZ ((uint8) (S9xAPUGetByteZ (OP1 ) | (1 << (b))), OP1); \
325 IAPU.PC += 2
326
327 void Apu02 ()
328 {
329     SET (0);
330 }
331
332 void Apu22 ()
333 {
334     SET (1);
335 }
336
337 void Apu42 ()
338 {
339     SET (2);
340 }
341
342 void Apu62 ()
343 {
344     SET (3);
345 }
346
347 void Apu82 ()
348 {
349     SET (4);
350 }
351
352 void ApuA2 ()
353 {
354     SET (5);
355 }
356
357 void ApuC2 ()
358 {
359     SET (6);
360 }
361
362 void ApuE2 ()
363 {
364     SET (7);
365 }
366
367 #define CLR(b) \
368 S9xAPUSetByteZ ((uint8) (S9xAPUGetByteZ (OP1) & ~(1 << (b))), OP1); \
369 IAPU.PC += 2;
370
371 void Apu12 ()
372 {
373     CLR (0);
374 }
375
376 void Apu32 ()
377 {
378     CLR (1);
379 }
380
381 void Apu52 ()
382 {
383     CLR (2);
384 }
385
386 void Apu72 ()
387 {
388     CLR (3);
389 }
390
391 void Apu92 ()
392 {
393     CLR (4);
394 }
395
396 void ApuB2 ()
397 {
398     CLR (5);
399 }
400
401 void ApuD2 ()
402 {
403     CLR (6);
404 }
405
406 void ApuF2 ()
407 {
408     CLR (7);
409 }
410
411 #define BBS(b) \
412 Work8 = OP1; \
413 Relative2 (); \
414 if (S9xAPUGetByteZ (Work8) & (1 << (b))) \
415 { \
416     IAPU.PC = IAPU.RAM + (uint16) Int16; \
417     CPU.APU_Cycles += IAPU.TwoCycles; \
418 } \
419 else \
420     IAPU.PC += 3
421
422 void Apu03 ()
423 {
424     BBS (0);
425 }
426
427 void Apu23 ()
428 {
429     BBS (1);
430 }
431
432 void Apu43 ()
433 {
434     BBS (2);
435 }
436
437 void Apu63 ()
438 {
439     BBS (3);
440 }
441
442 void Apu83 ()
443 {
444     BBS (4);
445 }
446
447 void ApuA3 ()
448 {
449     BBS (5);
450 }
451
452 void ApuC3 ()
453 {
454     BBS (6);
455 }
456
457 void ApuE3 ()
458 {
459     BBS (7);
460 }
461
462 #define BBC(b) \
463 Work8 = OP1; \
464 Relative2 (); \
465 if (!(S9xAPUGetByteZ (Work8) & (1 << (b)))) \
466 { \
467     IAPU.PC = IAPU.RAM + (uint16) Int16; \
468     CPU.APU_Cycles += IAPU.TwoCycles; \
469 } \
470 else \
471     IAPU.PC += 3
472
473 void Apu13 ()
474 {
475     BBC (0);
476 }
477
478 void Apu33 ()
479 {
480     BBC (1);
481 }
482
483 void Apu53 ()
484 {
485     BBC (2);
486 }
487
488 void Apu73 ()
489 {
490     BBC (3);
491 }
492
493 void Apu93 ()
494 {
495     BBC (4);
496 }
497
498 void ApuB3 ()
499 {
500     BBC (5);
501 }
502
503 void ApuD3 ()
504 {
505     BBC (6);
506 }
507
508 void ApuF3 ()
509 {
510     BBC (7);
511 }
512
513 void Apu04 ()
514 {
515 // OR A,dp
516     IAPU.YA.B.A |= S9xAPUGetByteZ (OP1);
517     APUSetZN8 (IAPU.YA.B.A);
518     IAPU.PC += 2;
519 }
520
521 void Apu05 ()
522 {
523 // OR A,abs
524     Absolute ();
525     IAPU.YA.B.A |= S9xAPUGetByte (IAPU.Address);
526     APUSetZN8 (IAPU.YA.B.A);
527     IAPU.PC += 3;
528 }
529
530 void Apu06 ()
531 {
532 // OR A,(X)
533     IAPU.YA.B.A |= S9xAPUGetByteZ (IAPU.X);
534     APUSetZN8 (IAPU.YA.B.A);
535     IAPU.PC++;
536 }
537
538 void Apu07 ()
539 {
540 // OR A,(dp+X)
541     IndexedXIndirect ();
542     IAPU.YA.B.A |= S9xAPUGetByte (IAPU.Address);
543     APUSetZN8 (IAPU.YA.B.A);
544     IAPU.PC += 2;
545 }
546
547 void Apu08 ()
548 {
549 // OR A,#00
550     IAPU.YA.B.A |= OP1;
551     APUSetZN8 (IAPU.YA.B.A);
552     IAPU.PC += 2;
553 }
554
555 void Apu09 ()
556 {
557 // OR dp(dest),dp(src)
558     Work8 = S9xAPUGetByteZ (OP1);
559     Work8 |= S9xAPUGetByteZ (OP2);
560     S9xAPUSetByteZ (Work8, OP2);
561     APUSetZN8 (Work8);
562     IAPU.PC += 3;
563 }
564
565 void Apu14 ()
566 {
567 // OR A,dp+X
568     IAPU.YA.B.A |= S9xAPUGetByteZ (OP1 + IAPU.X);
569     APUSetZN8 (IAPU.YA.B.A);
570     IAPU.PC += 2;
571 }
572
573 void Apu15 ()
574 {
575 // OR A,abs+X
576     AbsoluteX ();
577     IAPU.YA.B.A |= S9xAPUGetByte (IAPU.Address);
578     APUSetZN8 (IAPU.YA.B.A);
579     IAPU.PC += 3;
580 }
581
582 void Apu16 ()
583 {
584 // OR A,abs+Y
585     AbsoluteY ();
586     IAPU.YA.B.A |= S9xAPUGetByte (IAPU.Address);
587     APUSetZN8 (IAPU.YA.B.A);
588     IAPU.PC += 3;
589 }
590
591 void Apu17 ()
592 {
593 // OR A,(dp)+Y
594     IndirectIndexedY ();
595     IAPU.YA.B.A |= S9xAPUGetByte (IAPU.Address);
596     APUSetZN8 (IAPU.YA.B.A);
597     IAPU.PC += 2;
598 }
599
600 void Apu18 ()
601 {
602 // OR dp,#00
603     Work8 = OP1;
604     Work8 |= S9xAPUGetByteZ (OP2);
605     S9xAPUSetByteZ (Work8, OP2);
606     APUSetZN8 (Work8);
607     IAPU.PC += 3;
608 }
609
610 void Apu19 ()
611 {
612 // OR (X),(Y)
613     Work8 = S9xAPUGetByteZ (IAPU.X) | S9xAPUGetByteZ (IAPU.YA.B.Y);
614     APUSetZN8 (Work8);
615     S9xAPUSetByteZ (Work8, IAPU.X);
616     IAPU.PC++;
617 }
618
619 void Apu0A ()
620 {
621 // OR1 C,membit
622     MemBit ();
623     if (!APUCheckCarry ())
624     {
625         if (S9xAPUGetByte (IAPU.Address) & (1 << IAPU.Bit))
626             APUSetCarry ();
627     }
628     IAPU.PC += 3;
629 }
630
631 void Apu2A ()
632 {
633 // OR1 C,not membit
634     MemBit ();
635     if (!APUCheckCarry ())
636     {
637         if (!(S9xAPUGetByte (IAPU.Address) & (1 << IAPU.Bit)))
638             APUSetCarry ();
639     }
640     IAPU.PC += 3;
641 }
642
643 void Apu4A ()
644 {
645 // AND1 C,membit
646     MemBit ();
647     if (APUCheckCarry ())
648     {
649         if (!(S9xAPUGetByte (IAPU.Address) & (1 << IAPU.Bit)))
650             APUClearCarry ();
651     }
652     IAPU.PC += 3;
653 }
654
655 void Apu6A ()
656 {
657 // AND1 C, not membit
658     MemBit ();
659     if (APUCheckCarry ())
660     {
661         if ((S9xAPUGetByte (IAPU.Address) & (1 << IAPU.Bit)))
662             APUClearCarry ();
663     }
664     IAPU.PC += 3;
665 }
666
667 void Apu8A ()
668 {
669 // EOR1 C, membit
670     MemBit ();
671     if (APUCheckCarry ())
672     {
673         if (S9xAPUGetByte (IAPU.Address) & (1 << IAPU.Bit))
674             APUClearCarry ();
675     }
676     else
677     {
678         if (S9xAPUGetByte (IAPU.Address) & (1 << IAPU.Bit))
679             APUSetCarry ();
680     }
681     IAPU.PC += 3;
682 }
683
684 void ApuAA ()
685 {
686 // MOV1 C,membit
687     MemBit ();
688     if (S9xAPUGetByte (IAPU.Address) & (1 << IAPU.Bit))
689         APUSetCarry ();
690     else
691         APUClearCarry ();
692     IAPU.PC += 3;
693 }
694
695 void ApuCA ()
696 {
697 // MOV1 membit,C
698     MemBit ();
699     if (APUCheckCarry ())
700     {
701         S9xAPUSetByte (S9xAPUGetByte (IAPU.Address) | (1 << IAPU.Bit), IAPU.Address);
702     }
703     else
704     {
705         S9xAPUSetByte (S9xAPUGetByte (IAPU.Address) & ~(1 << IAPU.Bit), IAPU.Address);
706     }
707     IAPU.PC += 3;
708 }
709
710 void ApuEA ()
711 {
712 // NOT1 membit
713     MemBit ();
714     S9xAPUSetByte (S9xAPUGetByte (IAPU.Address) ^ (1 << IAPU.Bit), IAPU.Address);
715     IAPU.PC += 3;
716 }
717
718 void Apu0B ()
719 {
720 // ASL dp
721     Work8 = S9xAPUGetByteZ (OP1);
722     ASL (Work8);
723     S9xAPUSetByteZ (Work8, OP1);
724     IAPU.PC += 2;
725 }
726
727 void Apu0C ()
728 {
729 // ASL abs
730     Absolute ();
731     Work8 = S9xAPUGetByte (IAPU.Address);
732     ASL (Work8);
733     S9xAPUSetByte (Work8, IAPU.Address);
734     IAPU.PC += 3;
735 }
736
737 void Apu1B ()
738 {
739 // ASL dp+X
740     Work8 = S9xAPUGetByteZ (OP1 + IAPU.X);
741     ASL (Work8);
742     S9xAPUSetByteZ (Work8, OP1 + IAPU.X);
743     IAPU.PC += 2;
744 }
745
746 void Apu1C ()
747 {
748 // ASL A
749     ASL (IAPU.YA.B.A);
750     IAPU.PC++;
751 }
752
753 void Apu0D ()
754 {
755 // PUSH PSW
756     S9xAPUPackStatus ();
757     Push (IAPU.P);
758     IAPU.PC++;
759 }
760
761 void Apu2D ()
762 {
763 // PUSH A
764     Push (IAPU.YA.B.A);
765     IAPU.PC++;
766 }
767
768 void Apu4D ()
769 {
770 // PUSH X
771     Push (IAPU.X);
772     IAPU.PC++;
773 }
774
775 void Apu6D ()
776 {
777 // PUSH Y
778     Push (IAPU.YA.B.Y);
779     IAPU.PC++;
780 }
781
782 void Apu8E ()
783 {
784 // POP PSW
785     Pop (IAPU.P);
786     S9xAPUUnpackStatus ();
787     if (APUCheckDirectPage ())
788         IAPU.DirectPage = IAPU.RAM + 0x100;
789     else
790         IAPU.DirectPage = IAPU.RAM;
791     IAPU.PC++;
792 }
793
794 void ApuAE ()
795 {
796 // POP A
797     Pop (IAPU.YA.B.A);
798     IAPU.PC++;
799 }
800
801 void ApuCE ()
802 {
803 // POP X
804     Pop (IAPU.X);
805     IAPU.PC++;
806 }
807
808 void ApuEE ()
809 {
810 // POP Y
811     Pop (IAPU.YA.B.Y);
812     IAPU.PC++;
813 }
814
815 void Apu0E ()
816 {
817 // TSET1 abs
818     Absolute ();
819     Work8 = S9xAPUGetByte (IAPU.Address);
820     S9xAPUSetByte (Work8 | IAPU.YA.B.A, IAPU.Address);
821     Work8 &= IAPU.YA.B.A;
822     APUSetZN8 (Work8);
823     IAPU.PC += 3;
824 }
825
826 void Apu4E ()
827 {
828 // TCLR1 abs
829     Absolute ();
830     Work8 = S9xAPUGetByte (IAPU.Address);
831     S9xAPUSetByte (Work8 & ~IAPU.YA.B.A, IAPU.Address);
832     Work8 &= IAPU.YA.B.A;
833     APUSetZN8 (Work8);
834     IAPU.PC += 3;
835 }
836
837 void Apu0F ()
838 {
839 // BRK
840
841 #if 0
842     STOP ("BRK");
843 #else
844     PushW ((IAPU.PC + 1 - IAPU.RAM));
845     S9xAPUPackStatus ();
846     Push (IAPU.P);
847     APUSetBreak ();
848     APUClearInterrupt ();
849 // XXX:Where is the BRK vector ???
850     IAPU.PC = IAPU.RAM + APU.ExtraRAM[0x20] + (APU.ExtraRAM[0x21] << 8);
851 #endif
852 }
853
854 void ApuEF ()
855 {
856 // SLEEP
857     // XXX: sleep
858     // STOP ("SLEEP");
859     CPU.APU_APUExecuting = FALSE;
860     IAPU.PC++;
861 }
862
863 void ApuFF ()
864 {
865 // STOP
866     // STOP ("STOP");
867     CPU.APU_APUExecuting = FALSE;
868     IAPU.PC++;
869 }
870
871 void Apu10 ()
872 {
873 // BPL
874     Relative ();
875     if (!APUCheckNegative ())
876     {
877         IAPU.PC = IAPU.RAM + (uint16) Int16;
878         CPU.APU_Cycles += IAPU.TwoCycles;
879         APUShutdown ();
880     }
881     else
882         IAPU.PC += 2;
883 }
884
885 void Apu30 ()
886 {
887 // BMI
888     Relative ();
889     if (APUCheckNegative ())
890     {
891         IAPU.PC = IAPU.RAM + (uint16) Int16;
892         CPU.APU_Cycles += IAPU.TwoCycles;
893         APUShutdown ();
894     }
895     else
896         IAPU.PC += 2;
897 }
898
899 void Apu90 ()
900 {
901 // BCC
902     Relative ();
903     if (!APUCheckCarry ())
904     {
905         IAPU.PC = IAPU.RAM + (uint16) Int16;
906         CPU.APU_Cycles += IAPU.TwoCycles;
907         APUShutdown ();
908     }
909     else
910         IAPU.PC += 2;
911 }
912
913 void ApuB0 ()
914 {
915 // BCS
916     Relative ();
917     if (APUCheckCarry ())
918     {
919         IAPU.PC = IAPU.RAM + (uint16) Int16;
920         CPU.APU_Cycles += IAPU.TwoCycles;
921         APUShutdown ();
922     }
923     else
924         IAPU.PC += 2;
925 }
926
927 void ApuD0 ()
928 {
929 // BNE
930     Relative ();
931     if (!APUCheckZero ())
932     {
933         IAPU.PC = IAPU.RAM + (uint16) Int16;
934         CPU.APU_Cycles += IAPU.TwoCycles;
935         APUShutdown ();
936     }
937     else
938         IAPU.PC += 2;
939 }
940
941 void ApuF0 ()
942 {
943 // BEQ
944     Relative ();
945     if (APUCheckZero ())
946     {
947         IAPU.PC = IAPU.RAM + (uint16) Int16;
948         CPU.APU_Cycles += IAPU.TwoCycles;
949         APUShutdown ();
950     }
951     else
952         IAPU.PC += 2;
953 }
954
955 void Apu50 ()
956 {
957 // BVC
958     Relative ();
959     if (!APUCheckOverflow ())
960     {
961         IAPU.PC = IAPU.RAM + (uint16) Int16;
962         CPU.APU_Cycles += IAPU.TwoCycles;
963     }
964     else
965         IAPU.PC += 2;
966 }
967
968 void Apu70 ()
969 {
970 // BVS
971     Relative ();
972     if (APUCheckOverflow ())
973     {
974         IAPU.PC = IAPU.RAM + (uint16) Int16;
975         CPU.APU_Cycles += IAPU.TwoCycles;
976     }
977     else
978         IAPU.PC += 2;
979 }
980
981 void Apu2F ()
982 {
983 // BRA
984     Relative ();
985     IAPU.PC = IAPU.RAM + (uint16) Int16;
986 }
987
988 void Apu80 ()
989 {
990 // SETC
991     APUSetCarry ();
992     IAPU.PC++;
993 }
994
995 void ApuED ()
996 {
997 // NOTC
998     IAPU._Carry ^= 1;
999     IAPU.PC++;
1000 }
1001
1002 void Apu40 ()
1003 {
1004 // SETP
1005     APUSetDirectPage ();
1006     IAPU.DirectPage = IAPU.RAM + 0x100;
1007     IAPU.PC++;
1008 }
1009
1010 void Apu1A ()
1011 {
1012 // DECW dp
1013     Work16 = S9xAPUGetByteZ (OP1) + (S9xAPUGetByteZ (OP1 + 1) << 8);
1014     Work16--;
1015     S9xAPUSetByteZ ((uint8) Work16, OP1);
1016     S9xAPUSetByteZ (Work16 >> 8, OP1 + 1);
1017     APUSetZN16 (Work16);
1018     IAPU.PC += 2;
1019 }
1020
1021 void Apu5A ()
1022 {
1023 // CMPW YA,dp
1024     Work16 = S9xAPUGetByteZ (OP1) + (S9xAPUGetByteZ (OP1 + 1) << 8);
1025     Int32 = (long) IAPU.YA.W - (long) Work16;
1026     IAPU._Carry = Int32 >= 0;
1027     APUSetZN16 ((uint16) Int32);
1028     IAPU.PC += 2;
1029 }
1030
1031 void Apu3A ()
1032 {
1033 // INCW dp
1034     Work16 = S9xAPUGetByteZ (OP1) + (S9xAPUGetByteZ (OP1 + 1) << 8);
1035     Work16++;
1036     S9xAPUSetByteZ ((uint8) Work16, OP1);
1037     S9xAPUSetByteZ (Work16 >> 8, OP1 + 1);
1038     APUSetZN16 (Work16);
1039     IAPU.PC += 2;
1040 }
1041
1042 // XXX: HalfCarry - BJ Fixed? Or is it between bits 7 and 8 for ADDW/SUBW?
1043 void Apu7A ()
1044 {
1045 // ADDW YA,dp
1046     Work16 = S9xAPUGetByteZ (OP1) + (S9xAPUGetByteZ (OP1 + 1) << 8);
1047     Work32 = (uint32) IAPU.YA.W + Work16;
1048     IAPU._Carry = Work32 >= 0x10000;
1049     if (~(IAPU.YA.W ^ Work16) & (Work16 ^ (uint16) Work32) & 0x8000)
1050         APUSetOverflow ();
1051     else
1052         APUClearOverflow ();
1053     APUClearHalfCarry ();
1054     if((IAPU.YA.W ^ Work16 ^ (uint16) Work32) & 0x10)
1055         APUSetHalfCarry ();
1056     IAPU.YA.W = (uint16) Work32;
1057     APUSetZN16 (IAPU.YA.W);
1058     IAPU.PC += 2;
1059 }
1060
1061 // XXX: BJ: i think the old HalfCarry behavior was wrong...
1062 // XXX: Or is it between bits 7 and 8 for ADDW/SUBW?
1063 void Apu9A ()
1064 {
1065 // SUBW YA,dp
1066     Work16 = S9xAPUGetByteZ (OP1) + (S9xAPUGetByteZ (OP1 + 1) << 8);
1067     Int32 = (long) IAPU.YA.W - (long) Work16;
1068     APUClearHalfCarry ();
1069     IAPU._Carry = Int32 >= 0;
1070     if (((IAPU.YA.W ^ Work16) & 0x8000) &&
1071             ((IAPU.YA.W ^ (uint16) Int32) & 0x8000))
1072         APUSetOverflow ();
1073     else
1074         APUClearOverflow ();
1075 //    if (((IAPU.YA.W ^ Work16) & 0x0080) &&
1076 //          ((IAPU.YA.W ^ (uint16) Int32) & 0x0080))
1077 //      APUSetHalfCarry ();                              // notaz: strange here
1078     APUSetHalfCarry ();
1079 //    if((IAPU.YA.W ^ Work16 ^ (uint16) Work32) & 0x10) // notaz: Work32?!
1080     if((IAPU.YA.W ^ Work16 ^ (uint16) Int32) & 0x10)
1081         APUClearHalfCarry ();
1082     IAPU.YA.W = (uint16) Int32;
1083     APUSetZN16 (IAPU.YA.W);
1084     IAPU.PC += 2;
1085 }
1086
1087 void ApuBA ()
1088 {
1089 // MOVW YA,dp
1090     IAPU.YA.B.A = S9xAPUGetByteZ (OP1);
1091     IAPU.YA.B.Y = S9xAPUGetByteZ (OP1 + 1);
1092     APUSetZN16 (IAPU.YA.W);
1093     IAPU.PC += 2;
1094 }
1095
1096 void ApuDA ()
1097 {
1098 // MOVW dp,YA
1099     S9xAPUSetByteZ (IAPU.YA.B.A, OP1);
1100     S9xAPUSetByteZ (IAPU.YA.B.Y, OP1 + 1);
1101     IAPU.PC += 2;
1102 }
1103
1104 void Apu64 ()
1105 {
1106 // CMP A,dp
1107     Work8 = S9xAPUGetByteZ (OP1);
1108     CMP (IAPU.YA.B.A, Work8);
1109     IAPU.PC += 2;
1110 }
1111
1112 void Apu65 ()
1113 {
1114 // CMP A,abs
1115     Absolute ();
1116     Work8 = S9xAPUGetByte (IAPU.Address);
1117     CMP (IAPU.YA.B.A, Work8);
1118     IAPU.PC += 3;
1119 }
1120
1121 void Apu66 ()
1122 {
1123 // CMP A,(X)
1124     Work8 = S9xAPUGetByteZ (IAPU.X);
1125     CMP (IAPU.YA.B.A, Work8);
1126     IAPU.PC++;
1127 }
1128
1129 void Apu67 ()
1130 {
1131 // CMP A,(dp+X)
1132     IndexedXIndirect ();
1133     Work8 = S9xAPUGetByte (IAPU.Address);
1134     CMP (IAPU.YA.B.A, Work8);
1135     IAPU.PC += 2;
1136 }
1137
1138 void Apu68 ()
1139 {
1140 // CMP A,#00
1141     Work8 = OP1;
1142     CMP (IAPU.YA.B.A, Work8);
1143     IAPU.PC += 2;
1144 }
1145
1146 void Apu69 ()
1147 {
1148 // CMP dp(dest), dp(src)
1149     W1 = S9xAPUGetByteZ (OP1);
1150     Work8 = S9xAPUGetByteZ (OP2);
1151     CMP (Work8, W1);
1152     IAPU.PC += 3;
1153 }
1154
1155 void Apu74 ()
1156 {
1157 // CMP A, dp+X
1158     Work8 = S9xAPUGetByteZ (OP1 + IAPU.X);
1159     CMP (IAPU.YA.B.A, Work8);
1160     IAPU.PC += 2;
1161 }
1162
1163 void Apu75 ()
1164 {
1165 // CMP A,abs+X
1166     AbsoluteX ();
1167     Work8 = S9xAPUGetByte (IAPU.Address);
1168     CMP (IAPU.YA.B.A, Work8);
1169     IAPU.PC += 3;
1170 }
1171
1172 void Apu76 ()
1173 {
1174 // CMP A, abs+Y
1175     AbsoluteY ();
1176     Work8 = S9xAPUGetByte (IAPU.Address);
1177     CMP (IAPU.YA.B.A, Work8);
1178     IAPU.PC += 3;
1179 }
1180
1181 void Apu77 ()
1182 {
1183 // CMP A,(dp)+Y
1184     IndirectIndexedY ();
1185     Work8 = S9xAPUGetByte (IAPU.Address);
1186     CMP (IAPU.YA.B.A, Work8);
1187     IAPU.PC += 2;
1188 }
1189
1190 void Apu78 ()
1191 {
1192 // CMP dp,#00
1193     Work8 = OP1;
1194     W1 = S9xAPUGetByteZ (OP2);
1195     CMP (W1, Work8);
1196     IAPU.PC += 3;
1197 }
1198
1199 void Apu79 ()
1200 {
1201 // CMP (X),(Y)
1202     W1 = S9xAPUGetByteZ (IAPU.X);
1203     Work8 = S9xAPUGetByteZ (IAPU.YA.B.Y);
1204     CMP (W1, Work8);
1205     IAPU.PC++;
1206 }
1207
1208 void Apu1E ()
1209 {
1210 // CMP X,abs
1211     Absolute ();
1212     Work8 = S9xAPUGetByte (IAPU.Address);
1213     CMP (IAPU.X, Work8);
1214     IAPU.PC += 3;
1215 }
1216
1217 void Apu3E ()
1218 {
1219 // CMP X,dp
1220     Work8 = S9xAPUGetByteZ (OP1);
1221     CMP (IAPU.X, Work8);
1222     IAPU.PC += 2;
1223 }
1224
1225 void ApuC8 ()
1226 {
1227 // CMP X,#00
1228     CMP (IAPU.X, OP1);
1229     IAPU.PC += 2;
1230 }
1231
1232 void Apu5E ()
1233 {
1234 // CMP Y,abs
1235     Absolute ();
1236     Work8 = S9xAPUGetByte (IAPU.Address);
1237     CMP (IAPU.YA.B.Y, Work8);
1238     IAPU.PC += 3;
1239 }
1240
1241 void Apu7E ()
1242 {
1243 // CMP Y,dp
1244     Work8 = S9xAPUGetByteZ (OP1);
1245     CMP (IAPU.YA.B.Y, Work8);
1246     IAPU.PC += 2;
1247 }
1248
1249 void ApuAD ()
1250 {
1251 // CMP Y,#00
1252     Work8 = OP1;
1253     CMP (IAPU.YA.B.Y, Work8);
1254     IAPU.PC += 2;
1255 }
1256
1257 void Apu1F ()
1258 {
1259 // JMP (abs+X)
1260     Absolute ();
1261     IAPU.PC = IAPU.RAM + S9xAPUGetByte (IAPU.Address + IAPU.X) +
1262         (S9xAPUGetByte (IAPU.Address + IAPU.X + 1) << 8);
1263 // XXX: HERE:
1264     // APU.Flags |= TRACE_FLAG;
1265 }
1266
1267 void Apu5F ()
1268 {
1269 // JMP abs
1270     Absolute ();
1271     IAPU.PC = IAPU.RAM + IAPU.Address;
1272 }
1273
1274 void Apu20 ()
1275 {
1276 // CLRP
1277     APUClearDirectPage ();
1278     IAPU.DirectPage = IAPU.RAM;
1279     IAPU.PC++;
1280 }
1281
1282 void Apu60 ()
1283 {
1284 // CLRC
1285     APUClearCarry ();
1286     IAPU.PC++;
1287 }
1288
1289 void ApuE0 ()
1290 {
1291 // CLRV
1292     APUClearHalfCarry ();
1293     APUClearOverflow ();
1294     IAPU.PC++;
1295 }
1296
1297 void Apu24 ()
1298 {
1299 // AND A,dp
1300     IAPU.YA.B.A &= S9xAPUGetByteZ (OP1);
1301     APUSetZN8 (IAPU.YA.B.A);
1302     IAPU.PC += 2;
1303 }
1304
1305 void Apu25 ()
1306 {
1307 // AND A,abs
1308     Absolute ();
1309     IAPU.YA.B.A &= S9xAPUGetByte (IAPU.Address);
1310     APUSetZN8 (IAPU.YA.B.A);
1311     IAPU.PC += 3;
1312 }
1313
1314 void Apu26 ()
1315 {
1316 // AND A,(X)
1317     IAPU.YA.B.A &= S9xAPUGetByteZ (IAPU.X);
1318     APUSetZN8 (IAPU.YA.B.A);
1319     IAPU.PC++;
1320 }
1321
1322 void Apu27 ()
1323 {
1324 // AND A,(dp+X)
1325     IndexedXIndirect ();
1326     IAPU.YA.B.A &= S9xAPUGetByte (IAPU.Address);
1327     APUSetZN8 (IAPU.YA.B.A);
1328     IAPU.PC += 2;
1329 }
1330
1331 void Apu28 ()
1332 {
1333 // AND A,#00
1334     IAPU.YA.B.A &= OP1;
1335     APUSetZN8 (IAPU.YA.B.A);
1336     IAPU.PC += 2;
1337 }
1338
1339 void Apu29 ()
1340 {
1341 // AND dp(dest),dp(src)
1342     Work8 = S9xAPUGetByteZ (OP1);
1343     Work8 &= S9xAPUGetByteZ (OP2);
1344     S9xAPUSetByteZ (Work8, OP2);
1345     APUSetZN8 (Work8);
1346     IAPU.PC += 3;
1347 }
1348
1349 void Apu34 ()
1350 {
1351 // AND A,dp+X
1352     IAPU.YA.B.A &= S9xAPUGetByteZ (OP1 + IAPU.X);
1353     APUSetZN8 (IAPU.YA.B.A);
1354     IAPU.PC += 2;
1355 }
1356
1357 void Apu35 ()
1358 {
1359 // AND A,abs+X
1360     AbsoluteX ();
1361     IAPU.YA.B.A &= S9xAPUGetByte (IAPU.Address);
1362     APUSetZN8 (IAPU.YA.B.A);
1363     IAPU.PC += 3;
1364 }
1365
1366 void Apu36 ()
1367 {
1368 // AND A,abs+Y
1369     AbsoluteY ();
1370     IAPU.YA.B.A &= S9xAPUGetByte (IAPU.Address);
1371     APUSetZN8 (IAPU.YA.B.A);
1372     IAPU.PC += 3;
1373 }
1374
1375 void Apu37 ()
1376 {
1377 // AND A,(dp)+Y
1378     IndirectIndexedY ();
1379     IAPU.YA.B.A &= S9xAPUGetByte (IAPU.Address);
1380     APUSetZN8 (IAPU.YA.B.A);
1381     IAPU.PC += 2;
1382 }
1383
1384 void Apu38 ()
1385 {
1386 // AND dp,#00
1387     Work8 = OP1;
1388     Work8 &= S9xAPUGetByteZ (OP2);
1389     S9xAPUSetByteZ (Work8, OP2);
1390     APUSetZN8 (Work8);
1391     IAPU.PC += 3;
1392 }
1393
1394 void Apu39 ()
1395 {
1396 // AND (X),(Y)
1397     Work8 = S9xAPUGetByteZ (IAPU.X) & S9xAPUGetByteZ (IAPU.YA.B.Y);
1398     APUSetZN8 (Work8);
1399     S9xAPUSetByteZ (Work8, IAPU.X);
1400     IAPU.PC++;
1401 }
1402
1403 void Apu2B ()
1404 {
1405 // ROL dp
1406     Work8 = S9xAPUGetByteZ (OP1);
1407     ROL (Work8);
1408     S9xAPUSetByteZ (Work8, OP1);
1409     IAPU.PC += 2;
1410 }
1411
1412 void Apu2C ()
1413 {
1414 // ROL abs
1415     Absolute ();
1416     Work8 = S9xAPUGetByte (IAPU.Address);
1417     ROL (Work8);
1418     S9xAPUSetByte (Work8, IAPU.Address);
1419     IAPU.PC += 3;
1420 }
1421
1422 void Apu3B ()
1423 {
1424 // ROL dp+X
1425     Work8 = S9xAPUGetByteZ (OP1 + IAPU.X);
1426     ROL (Work8);
1427     S9xAPUSetByteZ (Work8, OP1 + IAPU.X);
1428     IAPU.PC += 2;
1429 }
1430
1431 void Apu3C ()
1432 {
1433 // ROL A
1434     ROL (IAPU.YA.B.A);
1435     IAPU.PC++;
1436 }
1437
1438 void Apu2E ()
1439 {
1440 // CBNE dp,rel
1441     Work8 = OP1;
1442     Relative2 ();
1443     
1444     if (S9xAPUGetByteZ (Work8) != IAPU.YA.B.A)
1445     {
1446         IAPU.PC = IAPU.RAM + (uint16) Int16;
1447         CPU.APU_Cycles += IAPU.TwoCycles;
1448         APUShutdown ();
1449     }
1450     else
1451         IAPU.PC += 3;
1452 }
1453
1454 void ApuDE ()
1455 {
1456 // CBNE dp+X,rel
1457     Work8 = OP1 + IAPU.X;
1458     Relative2 ();
1459
1460     if (S9xAPUGetByteZ (Work8) != IAPU.YA.B.A)
1461     {
1462         IAPU.PC = IAPU.RAM + (uint16) Int16;
1463         CPU.APU_Cycles += IAPU.TwoCycles;
1464         APUShutdown ();
1465     }
1466     else
1467         IAPU.PC += 3;
1468 }
1469
1470 void Apu3D ()
1471 {
1472 // INC X
1473     IAPU.X++;
1474     APUSetZN8 (IAPU.X);
1475
1476 #ifdef SPC700_SHUTDOWN
1477     IAPU.WaitCounter++;
1478 #endif
1479
1480     IAPU.PC++;
1481 }
1482
1483 void ApuFC ()
1484 {
1485 // INC Y
1486     IAPU.YA.B.Y++;
1487     APUSetZN8 (IAPU.YA.B.Y);
1488
1489 #ifdef SPC700_SHUTDOWN
1490     IAPU.WaitCounter++;
1491 #endif
1492
1493     IAPU.PC++;
1494 }
1495
1496 void Apu1D ()
1497 {
1498 // DEC X
1499     IAPU.X--;
1500     APUSetZN8 (IAPU.X);
1501
1502 #ifdef SPC700_SHUTDOWN
1503     IAPU.WaitCounter++;
1504 #endif
1505
1506     IAPU.PC++;
1507 }
1508
1509 void ApuDC ()
1510 {
1511 // DEC Y
1512     IAPU.YA.B.Y--;
1513     APUSetZN8 (IAPU.YA.B.Y);
1514
1515 #ifdef SPC700_SHUTDOWN
1516     IAPU.WaitCounter++;
1517 #endif
1518
1519     IAPU.PC++;
1520 }
1521
1522 void ApuAB ()
1523 {
1524 // INC dp
1525     Work8 = S9xAPUGetByteZ (OP1) + 1;
1526     S9xAPUSetByteZ (Work8, OP1);
1527     APUSetZN8 (Work8);
1528
1529 #ifdef SPC700_SHUTDOWN
1530     IAPU.WaitCounter++;
1531 #endif
1532
1533     IAPU.PC += 2;
1534 }
1535
1536 void ApuAC ()
1537 {
1538 // INC abs
1539     Absolute ();
1540     Work8 = S9xAPUGetByte (IAPU.Address) + 1;
1541     S9xAPUSetByte (Work8, IAPU.Address);
1542     APUSetZN8 (Work8);
1543
1544 #ifdef SPC700_SHUTDOWN
1545     IAPU.WaitCounter++;
1546 #endif
1547
1548     IAPU.PC += 3;
1549 }
1550
1551 void ApuBB ()
1552 {
1553 // INC dp+X
1554     Work8 = S9xAPUGetByteZ (OP1 + IAPU.X) + 1;
1555     S9xAPUSetByteZ (Work8, OP1 + IAPU.X);
1556     APUSetZN8 (Work8);
1557
1558 #ifdef SPC700_SHUTDOWN
1559     IAPU.WaitCounter++;
1560 #endif
1561
1562     IAPU.PC += 2;
1563 }
1564
1565 void ApuBC ()
1566 {
1567 // INC A
1568     IAPU.YA.B.A++;
1569     APUSetZN8 (IAPU.YA.B.A);
1570
1571 #ifdef SPC700_SHUTDOWN
1572     IAPU.WaitCounter++;
1573 #endif
1574
1575     IAPU.PC++;
1576 }
1577
1578 void Apu8B ()
1579 {
1580 // DEC dp
1581     Work8 = S9xAPUGetByteZ (OP1) - 1;
1582     S9xAPUSetByteZ (Work8, OP1);
1583     APUSetZN8 (Work8);
1584
1585 #ifdef SPC700_SHUTDOWN
1586     IAPU.WaitCounter++;
1587 #endif
1588
1589     IAPU.PC += 2;
1590 }
1591
1592 void Apu8C ()
1593 {
1594 // DEC abs
1595     Absolute ();
1596     Work8 = S9xAPUGetByte (IAPU.Address) - 1;
1597     S9xAPUSetByte (Work8, IAPU.Address);
1598     APUSetZN8 (Work8);
1599
1600 #ifdef SPC700_SHUTDOWN
1601     IAPU.WaitCounter++;
1602 #endif
1603
1604     IAPU.PC += 3;
1605 }
1606
1607 void Apu9B ()
1608 {
1609 // DEC dp+X
1610     Work8 = S9xAPUGetByteZ (OP1 + IAPU.X) - 1;
1611     S9xAPUSetByteZ (Work8, OP1 + IAPU.X);
1612     APUSetZN8 (Work8);
1613
1614 #ifdef SPC700_SHUTDOWN
1615     IAPU.WaitCounter++;
1616 #endif
1617
1618     IAPU.PC += 2;
1619 }
1620
1621 void Apu9C ()
1622 {
1623 // DEC A
1624     IAPU.YA.B.A--;
1625     APUSetZN8 (IAPU.YA.B.A);
1626
1627 #ifdef SPC700_SHUTDOWN
1628     IAPU.WaitCounter++;
1629 #endif
1630
1631     IAPU.PC++;
1632 }
1633
1634 void Apu44 ()
1635 {
1636 // EOR A,dp
1637     IAPU.YA.B.A ^= S9xAPUGetByteZ (OP1);
1638     APUSetZN8 (IAPU.YA.B.A);
1639     IAPU.PC += 2;
1640 }
1641
1642 void Apu45 ()
1643 {
1644 // EOR A,abs
1645     Absolute ();
1646     IAPU.YA.B.A ^= S9xAPUGetByte (IAPU.Address);
1647     APUSetZN8 (IAPU.YA.B.A);
1648     IAPU.PC += 3;
1649 }
1650
1651 void Apu46 ()
1652 {
1653 // EOR A,(X)
1654     IAPU.YA.B.A ^= S9xAPUGetByteZ (IAPU.X);
1655     APUSetZN8 (IAPU.YA.B.A);
1656     IAPU.PC++;
1657 }
1658
1659 void Apu47 ()
1660 {
1661 // EOR A,(dp+X)
1662     IndexedXIndirect ();
1663     IAPU.YA.B.A ^= S9xAPUGetByte (IAPU.Address);
1664     APUSetZN8 (IAPU.YA.B.A);
1665     IAPU.PC += 2;
1666 }
1667
1668 void Apu48 ()
1669 {
1670 // EOR A,#00
1671     IAPU.YA.B.A ^= OP1;
1672     APUSetZN8 (IAPU.YA.B.A);
1673     IAPU.PC += 2;
1674 }
1675
1676 void Apu49 ()
1677 {
1678 // EOR dp(dest),dp(src)
1679     Work8 = S9xAPUGetByteZ (OP1);
1680     Work8 ^= S9xAPUGetByteZ (OP2);
1681     S9xAPUSetByteZ (Work8, OP2);
1682     APUSetZN8 (Work8);
1683     IAPU.PC += 3;
1684 }
1685
1686 void Apu54 ()
1687 {
1688 // EOR A,dp+X
1689     IAPU.YA.B.A ^= S9xAPUGetByteZ (OP1 + IAPU.X);
1690     APUSetZN8 (IAPU.YA.B.A);
1691     IAPU.PC += 2;
1692 }
1693
1694 void Apu55 ()
1695 {
1696 // EOR A,abs+X
1697     AbsoluteX ();
1698     IAPU.YA.B.A ^= S9xAPUGetByte (IAPU.Address);
1699     APUSetZN8 (IAPU.YA.B.A);
1700     IAPU.PC += 3;
1701 }
1702
1703 void Apu56 ()
1704 {
1705 // EOR A,abs+Y
1706     AbsoluteY ();
1707     IAPU.YA.B.A ^= S9xAPUGetByte (IAPU.Address);
1708     APUSetZN8 (IAPU.YA.B.A);
1709     IAPU.PC += 3;
1710 }
1711
1712 void Apu57 ()
1713 {
1714 // EOR A,(dp)+Y
1715     IndirectIndexedY ();
1716     IAPU.YA.B.A ^= S9xAPUGetByte (IAPU.Address);
1717     APUSetZN8 (IAPU.YA.B.A);
1718     IAPU.PC += 2;
1719 }
1720
1721 void Apu58 ()
1722 {
1723 // EOR dp,#00
1724     Work8 = OP1;
1725     Work8 ^= S9xAPUGetByteZ (OP2);
1726     S9xAPUSetByteZ (Work8, OP2);
1727     APUSetZN8 (Work8);
1728     IAPU.PC += 3;
1729 }
1730
1731 void Apu59 ()
1732 {
1733 // EOR (X),(Y)
1734     Work8 = S9xAPUGetByteZ (IAPU.X) ^ S9xAPUGetByteZ (IAPU.YA.B.Y);
1735     APUSetZN8 (Work8);
1736     S9xAPUSetByteZ (Work8, IAPU.X);
1737     IAPU.PC++;
1738 }
1739
1740 void Apu4B ()
1741 {
1742 // LSR dp
1743     Work8 = S9xAPUGetByteZ (OP1);
1744     LSR (Work8);
1745     S9xAPUSetByteZ (Work8, OP1);
1746     IAPU.PC += 2;
1747 }
1748
1749 void Apu4C ()
1750 {
1751 // LSR abs
1752     Absolute ();
1753     Work8 = S9xAPUGetByte (IAPU.Address);
1754     LSR (Work8);
1755     S9xAPUSetByte (Work8, IAPU.Address);
1756     IAPU.PC += 3;
1757 }
1758
1759 void Apu5B ()
1760 {
1761 // LSR dp+X
1762     Work8 = S9xAPUGetByteZ (OP1 + IAPU.X);
1763     LSR (Work8);
1764     S9xAPUSetByteZ (Work8, OP1 + IAPU.X);
1765     IAPU.PC += 2;
1766 }
1767
1768 void Apu5C ()
1769 {
1770 // LSR A
1771     LSR (IAPU.YA.B.A);
1772     IAPU.PC++;
1773 }
1774
1775 void Apu7D ()
1776 {
1777 // MOV A,X
1778     IAPU.YA.B.A = IAPU.X;
1779     APUSetZN8 (IAPU.YA.B.A);
1780     IAPU.PC++;
1781 }
1782
1783 void ApuDD ()
1784 {
1785 // MOV A,Y
1786     IAPU.YA.B.A = IAPU.YA.B.Y;
1787     APUSetZN8 (IAPU.YA.B.A);
1788     IAPU.PC++;
1789 }
1790
1791 void Apu5D ()
1792 {
1793 // MOV X,A
1794     IAPU.X = IAPU.YA.B.A;
1795     APUSetZN8 (IAPU.X);
1796     IAPU.PC++;
1797 }
1798
1799 void ApuFD ()
1800 {
1801 // MOV Y,A
1802     IAPU.YA.B.Y = IAPU.YA.B.A;
1803     APUSetZN8 (IAPU.YA.B.Y);
1804     IAPU.PC++;
1805 }
1806
1807 void Apu9D ()
1808 {
1809 //MOV X,SP
1810     IAPU.X = IAPU.S;
1811     APUSetZN8 (IAPU.X);
1812     IAPU.PC++;
1813 }
1814
1815 void ApuBD ()
1816 {
1817 // MOV SP,X
1818     IAPU.S = IAPU.X;
1819     IAPU.PC++;
1820 }
1821
1822 void Apu6B ()
1823 {
1824 // ROR dp
1825     Work8 = S9xAPUGetByteZ (OP1);
1826     ROR (Work8);
1827     S9xAPUSetByteZ (Work8, OP1);
1828     IAPU.PC += 2;
1829 }
1830
1831 void Apu6C ()
1832 {
1833 // ROR abs
1834     Absolute ();
1835     Work8 = S9xAPUGetByte (IAPU.Address);
1836     ROR (Work8);
1837     S9xAPUSetByte (Work8, IAPU.Address);
1838     IAPU.PC += 3;
1839 }
1840
1841 void Apu7B ()
1842 {
1843 // ROR dp+X
1844     Work8 = S9xAPUGetByteZ (OP1 + IAPU.X);
1845     ROR (Work8);
1846     S9xAPUSetByteZ (Work8, OP1 + IAPU.X);
1847     IAPU.PC += 2;
1848 }
1849
1850 void Apu7C ()
1851 {
1852 // ROR A
1853     ROR (IAPU.YA.B.A);
1854     IAPU.PC++;
1855 }
1856
1857 void Apu6E ()
1858 {
1859 // DBNZ dp,rel
1860     Work8 = OP1;
1861     Relative2 ();
1862     W1 = S9xAPUGetByteZ (Work8) - 1;
1863     S9xAPUSetByteZ (W1, Work8);
1864     if (W1 != 0)
1865     {
1866         IAPU.PC = IAPU.RAM + (uint16) Int16;
1867         CPU.APU_Cycles += IAPU.TwoCycles;
1868     }
1869     else
1870         IAPU.PC += 3;
1871 }
1872
1873 void ApuFE ()
1874 {
1875 // DBNZ Y,rel
1876     Relative ();
1877     IAPU.YA.B.Y--;
1878     if (IAPU.YA.B.Y != 0)
1879     {
1880         IAPU.PC = IAPU.RAM + (uint16) Int16;
1881         CPU.APU_Cycles += IAPU.TwoCycles;
1882     }
1883     else
1884         IAPU.PC += 2;
1885 }
1886
1887 void Apu6F ()
1888 {
1889 // RET
1890     PopW (Work16);
1891     IAPU.PC = IAPU.RAM + Work16;
1892 }
1893
1894 void Apu7F ()
1895 {
1896 // RETI
1897     // STOP ("RETI");
1898     Pop (IAPU.P);
1899     S9xAPUUnpackStatus ();
1900     PopW (Work16);
1901     IAPU.PC = IAPU.RAM + Work16;
1902 }
1903
1904 void Apu84 ()
1905 {
1906 // ADC A,dp
1907     Work8 = S9xAPUGetByteZ (OP1);
1908     ADC (IAPU.YA.B.A, Work8);
1909     IAPU.PC += 2;
1910 }
1911
1912 void Apu85 ()
1913 {
1914 // ADC A, abs
1915     Absolute ();
1916     Work8 = S9xAPUGetByte (IAPU.Address);
1917     ADC (IAPU.YA.B.A, Work8);
1918     IAPU.PC += 3;
1919 }
1920
1921 void Apu86 ()
1922 {
1923 // ADC A,(X)
1924     Work8 = S9xAPUGetByteZ (IAPU.X);
1925     ADC (IAPU.YA.B.A, Work8);
1926     IAPU.PC++;
1927 }
1928
1929 void Apu87 ()
1930 {
1931 // ADC A,(dp+X)
1932     IndexedXIndirect ();
1933     Work8 = S9xAPUGetByte (IAPU.Address);
1934     ADC (IAPU.YA.B.A, Work8);
1935     IAPU.PC += 2;
1936 }
1937
1938 void Apu88 ()
1939 {
1940 // ADC A,#00
1941     Work8 = OP1;
1942     ADC (IAPU.YA.B.A, Work8);
1943     IAPU.PC += 2;
1944 }
1945
1946 void Apu89 ()
1947 {
1948 // ADC dp(dest),dp(src)
1949     Work8 = S9xAPUGetByteZ (OP1);
1950     W1 = S9xAPUGetByteZ (OP2);
1951     ADC (W1, Work8);
1952     S9xAPUSetByteZ (W1, OP2);
1953     IAPU.PC += 3;
1954 }
1955
1956 void Apu94 ()
1957 {
1958 // ADC A,dp+X
1959     Work8 = S9xAPUGetByteZ (OP1 + IAPU.X);
1960     ADC (IAPU.YA.B.A, Work8);
1961     IAPU.PC += 2;
1962 }
1963
1964 void Apu95 ()
1965 {
1966 // ADC A, abs+X
1967     AbsoluteX ();
1968     Work8 = S9xAPUGetByte (IAPU.Address);
1969     ADC (IAPU.YA.B.A, Work8);
1970     IAPU.PC += 3;
1971 }
1972
1973 void Apu96 ()
1974 {
1975 // ADC A, abs+Y
1976     AbsoluteY ();
1977     Work8 = S9xAPUGetByte (IAPU.Address);
1978     ADC (IAPU.YA.B.A, Work8);
1979     IAPU.PC += 3;
1980 }
1981
1982 void Apu97 ()
1983 {
1984 // ADC A, (dp)+Y
1985     IndirectIndexedY ();
1986     Work8 = S9xAPUGetByte (IAPU.Address);
1987     ADC (IAPU.YA.B.A, Work8);
1988     IAPU.PC += 2;
1989 }
1990
1991 void Apu98 ()
1992 {
1993 // ADC dp,#00
1994     Work8 = OP1;
1995     W1 = S9xAPUGetByteZ (OP2);
1996     ADC (W1, Work8);
1997     S9xAPUSetByteZ (W1, OP2);
1998     IAPU.PC += 3;
1999 }
2000
2001 void Apu99 ()
2002 {
2003 // ADC (X),(Y)
2004     W1 = S9xAPUGetByteZ (IAPU.X);
2005     Work8 = S9xAPUGetByteZ (IAPU.YA.B.Y);
2006     ADC (W1, Work8);
2007     S9xAPUSetByteZ (W1, IAPU.X);
2008     IAPU.PC++;
2009 }
2010
2011 void Apu8D ()
2012 {
2013 // MOV Y,#00
2014     IAPU.YA.B.Y = OP1;
2015     APUSetZN8 (IAPU.YA.B.Y);
2016     IAPU.PC += 2;
2017 }
2018
2019 void Apu8F ()
2020 {
2021 // MOV dp,#00
2022     Work8 = OP1;
2023     S9xAPUSetByteZ (Work8, OP2);
2024     IAPU.PC += 3;
2025 }
2026
2027 void Apu9E ()
2028 {
2029 // DIV YA,X
2030     if (IAPU.X == 0)
2031     {
2032         APUSetOverflow ();
2033         IAPU.YA.B.Y = 0xff;
2034         IAPU.YA.B.A = 0xff;
2035     }
2036     else
2037     {
2038         APUClearOverflow ();
2039         Work8 = IAPU.YA.W / IAPU.X;
2040         IAPU.YA.B.Y = IAPU.YA.W % IAPU.X;
2041         IAPU.YA.B.A = Work8;
2042     }
2043 // XXX How should Overflow, Half Carry, Zero and Negative flags be set??
2044     // APUSetZN16 (IAPU.YA.W);
2045     APUSetZN8 (IAPU.YA.B.A);
2046     IAPU.PC++;
2047 }
2048
2049 void Apu9F ()
2050 {
2051 // XCN A
2052     IAPU.YA.B.A = (IAPU.YA.B.A >> 4) | (IAPU.YA.B.A << 4);
2053     APUSetZN8 (IAPU.YA.B.A);
2054     IAPU.PC++;
2055 }
2056
2057 void ApuA4 ()
2058 {
2059 // SBC A, dp
2060     Work8 = S9xAPUGetByteZ (OP1);
2061     SBC (IAPU.YA.B.A, Work8);
2062     IAPU.PC += 2;
2063 }
2064
2065 void ApuA5 ()
2066 {
2067 // SBC A, abs
2068     Absolute ();
2069     Work8 = S9xAPUGetByte (IAPU.Address);
2070     SBC (IAPU.YA.B.A, Work8);
2071     IAPU.PC += 3;
2072 }
2073
2074 void ApuA6 ()
2075 {
2076 // SBC A, (X)
2077     Work8 = S9xAPUGetByteZ (IAPU.X);
2078     SBC (IAPU.YA.B.A, Work8);
2079     IAPU.PC++;
2080 }
2081
2082 void ApuA7 ()
2083 {
2084 // SBC A,(dp+X)
2085     IndexedXIndirect ();
2086     Work8 = S9xAPUGetByte (IAPU.Address);
2087     SBC (IAPU.YA.B.A, Work8);
2088     IAPU.PC += 2;
2089 }
2090
2091 void ApuA8 ()
2092 {
2093 // SBC A,#00
2094     Work8 = OP1;
2095     SBC (IAPU.YA.B.A, Work8);
2096     IAPU.PC += 2;
2097 }
2098
2099 void ApuA9 ()
2100 {
2101 // SBC dp(dest), dp(src)
2102     Work8 = S9xAPUGetByteZ (OP1);
2103     W1 = S9xAPUGetByteZ (OP2);
2104     SBC (W1, Work8);
2105     S9xAPUSetByteZ (W1, OP2);
2106     IAPU.PC += 3;
2107 }
2108
2109 void ApuB4 ()
2110 {
2111 // SBC A, dp+X
2112     Work8 = S9xAPUGetByteZ (OP1 + IAPU.X);
2113     SBC (IAPU.YA.B.A, Work8);
2114     IAPU.PC += 2;
2115 }
2116
2117 void ApuB5 ()
2118 {
2119 // SBC A,abs+X
2120     AbsoluteX ();
2121     Work8 = S9xAPUGetByte (IAPU.Address);
2122     SBC (IAPU.YA.B.A, Work8);
2123     IAPU.PC += 3;
2124 }
2125
2126 void ApuB6 ()
2127 {
2128 // SBC A,abs+Y
2129     AbsoluteY ();
2130     Work8 = S9xAPUGetByte (IAPU.Address);
2131     SBC (IAPU.YA.B.A, Work8);
2132     IAPU.PC += 3;
2133 }
2134
2135 void ApuB7 ()
2136 {
2137 // SBC A,(dp)+Y
2138     IndirectIndexedY ();
2139     Work8 = S9xAPUGetByte (IAPU.Address);
2140     SBC (IAPU.YA.B.A, Work8);
2141     IAPU.PC += 2;
2142 }
2143
2144 void ApuB8 ()
2145 {
2146 // SBC dp,#00
2147     Work8 = OP1;
2148     W1 = S9xAPUGetByteZ (OP2);
2149     SBC (W1, Work8);
2150     S9xAPUSetByteZ (W1, OP2);
2151     IAPU.PC += 3;
2152 }
2153
2154 void ApuB9 ()
2155 {
2156 // SBC (X),(Y)
2157     W1 = S9xAPUGetByteZ (IAPU.X);
2158     Work8 = S9xAPUGetByteZ (IAPU.YA.B.Y);
2159     SBC (W1, Work8);
2160     S9xAPUSetByteZ (W1, IAPU.X);
2161     IAPU.PC++;
2162 }
2163
2164 void ApuAF ()
2165 {
2166 // MOV (X)+, A
2167     S9xAPUSetByteZ (IAPU.YA.B.A, IAPU.X++);
2168     IAPU.PC++;
2169 }
2170
2171 void ApuBE ()
2172 {
2173 // DAS
2174     if ((IAPU.YA.B.A & 0x0f) > 9 || !APUCheckHalfCarry())
2175    {
2176         IAPU.YA.B.A -= 6;
2177    }
2178     if (IAPU.YA.B.A > 0x9f || !IAPU._Carry)
2179    {
2180         IAPU.YA.B.A -= 0x60;
2181         APUClearCarry ();
2182    }
2183     else { APUSetCarry (); }
2184     APUSetZN8 (IAPU.YA.B.A);
2185    IAPU.PC++;
2186 }
2187
2188 void ApuBF ()
2189 {
2190 // MOV A,(X)+
2191     IAPU.YA.B.A = S9xAPUGetByteZ (IAPU.X++);
2192     APUSetZN8 (IAPU.YA.B.A);
2193     IAPU.PC++;
2194 }
2195
2196 void ApuC0 ()
2197 {
2198 // DI
2199     APUClearInterrupt ();
2200     IAPU.PC++;
2201 }
2202
2203 void ApuA0 ()
2204 {
2205 // EI
2206     APUSetInterrupt ();
2207     IAPU.PC++;
2208 }
2209
2210 void ApuC4 ()
2211 {
2212 // MOV dp,A
2213     S9xAPUSetByteZ (IAPU.YA.B.A, OP1);
2214     IAPU.PC += 2;
2215 }
2216
2217 void ApuC5 ()
2218 {
2219 // MOV abs,A
2220     Absolute ();
2221     S9xAPUSetByte (IAPU.YA.B.A, IAPU.Address);
2222     IAPU.PC += 3;
2223 }
2224
2225 void ApuC6 ()
2226 {
2227 // MOV (X), A
2228     S9xAPUSetByteZ (IAPU.YA.B.A, IAPU.X);
2229     IAPU.PC++;
2230 }
2231
2232 void ApuC7 ()
2233 {
2234 // MOV (dp+X),A
2235     IndexedXIndirect ();
2236     S9xAPUSetByte (IAPU.YA.B.A, IAPU.Address);
2237     IAPU.PC += 2;
2238 }
2239
2240 void ApuC9 ()
2241 {
2242 // MOV abs,X
2243     Absolute ();
2244     S9xAPUSetByte (IAPU.X, IAPU.Address);
2245     IAPU.PC += 3;
2246 }
2247
2248 void ApuCB ()
2249 {
2250 // MOV dp,Y
2251     S9xAPUSetByteZ (IAPU.YA.B.Y, OP1);
2252     IAPU.PC += 2;
2253 }
2254
2255 void ApuCC ()
2256 {
2257 // MOV abs,Y
2258     Absolute ();
2259     S9xAPUSetByte (IAPU.YA.B.Y, IAPU.Address);
2260     IAPU.PC += 3;
2261 }
2262
2263 void ApuCD ()
2264 {
2265 // MOV X,#00
2266     IAPU.X = OP1;
2267     APUSetZN8 (IAPU.X);
2268     IAPU.PC += 2;
2269 }
2270
2271 void ApuCF ()
2272 {
2273 // MUL YA
2274     IAPU.YA.W = (uint16) IAPU.YA.B.A * IAPU.YA.B.Y;
2275     APUSetZN16 (IAPU.YA.W);
2276     IAPU.PC++;
2277 }
2278
2279 void ApuD4 ()
2280 {
2281 // MOV dp+X, A
2282     S9xAPUSetByteZ (IAPU.YA.B.A, OP1 + IAPU.X);
2283     IAPU.PC += 2;
2284 }
2285
2286 void ApuD5 ()
2287 {
2288 // MOV abs+X,A
2289     AbsoluteX ();
2290     S9xAPUSetByte (IAPU.YA.B.A, IAPU.Address);
2291     IAPU.PC += 3;
2292 }
2293
2294 void ApuD6 ()
2295 {
2296 // MOV abs+Y,A
2297     AbsoluteY ();
2298     S9xAPUSetByte (IAPU.YA.B.A, IAPU.Address);
2299     IAPU.PC += 3;
2300 }
2301
2302 void ApuD7 ()
2303 {
2304 // MOV (dp)+Y,A
2305     IndirectIndexedY ();
2306     S9xAPUSetByte (IAPU.YA.B.A, IAPU.Address);
2307     IAPU.PC += 2;
2308 }
2309
2310 void ApuD8 ()
2311 {
2312 // MOV dp,X
2313     S9xAPUSetByteZ (IAPU.X, OP1);
2314     IAPU.PC += 2;
2315 }
2316
2317 void ApuD9 ()
2318 {
2319 // MOV dp+Y,X
2320     S9xAPUSetByteZ (IAPU.X, OP1 + IAPU.YA.B.Y);
2321     IAPU.PC += 2;
2322 }
2323
2324 void ApuDB ()
2325 {
2326 // MOV dp+X,Y
2327     S9xAPUSetByteZ (IAPU.YA.B.Y, OP1 + IAPU.X);
2328     IAPU.PC += 2;
2329 }
2330
2331 void ApuDF ()
2332 {
2333 // DAA
2334     if ((IAPU.YA.B.A & 0x0f) > 9 || APUCheckHalfCarry())
2335     {
2336         if(IAPU.YA.B.A > 0xf0) APUSetCarry ();
2337         IAPU.YA.B.A += 6;
2338         //APUSetHalfCarry (); Intel procs do this, but this is a Sony proc...
2339     }
2340     //else { APUClearHalfCarry (); } ditto as above
2341     if (IAPU.YA.B.A > 0x9f || IAPU._Carry)
2342     {
2343         IAPU.YA.B.A += 0x60;
2344         APUSetCarry ();
2345     }
2346     else { APUClearCarry (); }
2347     APUSetZN8 (IAPU.YA.B.A);
2348     IAPU.PC++;
2349 }
2350
2351 void ApuE4 ()
2352 {
2353 // MOV A, dp
2354     IAPU.YA.B.A = S9xAPUGetByteZ (OP1);
2355     APUSetZN8 (IAPU.YA.B.A);
2356     IAPU.PC += 2;
2357 }
2358
2359 void ApuE5 ()
2360 {
2361 // MOV A,abs
2362     Absolute ();
2363     IAPU.YA.B.A = S9xAPUGetByte (IAPU.Address);
2364     APUSetZN8 (IAPU.YA.B.A);
2365     IAPU.PC += 3;
2366 }
2367
2368 void ApuE6 ()
2369 {
2370 // MOV A,(X)
2371     IAPU.YA.B.A = S9xAPUGetByteZ (IAPU.X);
2372     APUSetZN8 (IAPU.YA.B.A);
2373     IAPU.PC++;
2374 }
2375
2376 void ApuE7 ()
2377 {
2378 // MOV A,(dp+X)
2379     IndexedXIndirect ();
2380     IAPU.YA.B.A = S9xAPUGetByte (IAPU.Address);
2381     APUSetZN8 (IAPU.YA.B.A);
2382     IAPU.PC += 2;
2383 }
2384
2385 void ApuE8 ()
2386 {
2387 // MOV A,#00
2388     IAPU.YA.B.A = OP1;
2389     APUSetZN8 (IAPU.YA.B.A);
2390     IAPU.PC += 2;
2391 }
2392
2393 void ApuE9 ()
2394 {
2395 // MOV X, abs
2396     Absolute ();
2397     IAPU.X = S9xAPUGetByte (IAPU.Address);
2398     APUSetZN8 (IAPU.X);
2399     IAPU.PC += 3;
2400 }
2401
2402 void ApuEB ()
2403 {
2404 // MOV Y,dp
2405     IAPU.YA.B.Y = S9xAPUGetByteZ (OP1);
2406     APUSetZN8 (IAPU.YA.B.Y);
2407     IAPU.PC += 2;
2408 }
2409
2410 void ApuEC ()
2411 {
2412 // MOV Y,abs
2413     Absolute ();
2414     IAPU.YA.B.Y = S9xAPUGetByte (IAPU.Address);
2415     APUSetZN8 (IAPU.YA.B.Y);
2416     IAPU.PC += 3;
2417 }
2418
2419 void ApuF4 ()
2420 {
2421 // MOV A, dp+X
2422     IAPU.YA.B.A = S9xAPUGetByteZ (OP1 + IAPU.X);
2423     APUSetZN8 (IAPU.YA.B.A);
2424     IAPU.PC += 2;
2425 }
2426
2427 void ApuF5 ()
2428 {
2429 // MOV A, abs+X
2430     AbsoluteX ();
2431     IAPU.YA.B.A = S9xAPUGetByte (IAPU.Address);
2432     APUSetZN8 (IAPU.YA.B.A);
2433     IAPU.PC += 3;
2434 }
2435
2436 void ApuF6 ()
2437 {
2438 // MOV A, abs+Y
2439     AbsoluteY ();
2440     IAPU.YA.B.A = S9xAPUGetByte (IAPU.Address);
2441     APUSetZN8 (IAPU.YA.B.A);
2442     IAPU.PC += 3;
2443 }
2444
2445 void ApuF7 ()
2446 {
2447 // MOV A, (dp)+Y
2448     IndirectIndexedY ();
2449     IAPU.YA.B.A = S9xAPUGetByte (IAPU.Address);
2450     APUSetZN8 (IAPU.YA.B.A);
2451     IAPU.PC += 2;
2452 }
2453
2454 void ApuF8 ()
2455 {
2456 // MOV X,dp
2457     IAPU.X = S9xAPUGetByteZ (OP1);
2458     APUSetZN8 (IAPU.X);
2459     IAPU.PC += 2;
2460 }
2461
2462 void ApuF9 ()
2463 {
2464 // MOV X,dp+Y
2465     IAPU.X = S9xAPUGetByteZ (OP1 + IAPU.YA.B.Y);
2466     APUSetZN8 (IAPU.X);
2467     IAPU.PC += 2;
2468 }
2469
2470 void ApuFA ()
2471 {
2472 // MOV dp(dest),dp(src)
2473     S9xAPUSetByteZ (S9xAPUGetByteZ (OP1), OP2);
2474     IAPU.PC += 3;
2475 }
2476
2477 void ApuFB ()
2478 {
2479 // MOV Y,dp+X
2480     IAPU.YA.B.Y = S9xAPUGetByteZ (OP1 + IAPU.X);
2481     APUSetZN8 (IAPU.YA.B.Y);
2482     IAPU.PC += 2;
2483 }
2484
2485 #if defined(NO_INLINE_SET_GET)
2486 #undef INLINE
2487 #define INLINE
2488 #include "apumem.h"
2489 #endif
2490
2491
2492 void (*S9xApuOpcodes[256]) (void) =
2493 {
2494         Apu00, Apu01, Apu02, Apu03, Apu04, Apu05, Apu06, Apu07,
2495         Apu08, Apu09, Apu0A, Apu0B, Apu0C, Apu0D, Apu0E, Apu0F,
2496         Apu10, Apu11, Apu12, Apu13, Apu14, Apu15, Apu16, Apu17,
2497         Apu18, Apu19, Apu1A, Apu1B, Apu1C, Apu1D, Apu1E, Apu1F,
2498         Apu20, Apu21, Apu22, Apu23, Apu24, Apu25, Apu26, Apu27,
2499         Apu28, Apu29, Apu2A, Apu2B, Apu2C, Apu2D, Apu2E, Apu2F,
2500         Apu30, Apu31, Apu32, Apu33, Apu34, Apu35, Apu36, Apu37,
2501         Apu38, Apu39, Apu3A, Apu3B, Apu3C, Apu3D, Apu3E, Apu3F,
2502         Apu40, Apu41, Apu42, Apu43, Apu44, Apu45, Apu46, Apu47,
2503         Apu48, Apu49, Apu4A, Apu4B, Apu4C, Apu4D, Apu4E, Apu4F,
2504         Apu50, Apu51, Apu52, Apu53, Apu54, Apu55, Apu56, Apu57,
2505         Apu58, Apu59, Apu5A, Apu5B, Apu5C, Apu5D, Apu5E, Apu5F,
2506         Apu60, Apu61, Apu62, Apu63, Apu64, Apu65, Apu66, Apu67,
2507         Apu68, Apu69, Apu6A, Apu6B, Apu6C, Apu6D, Apu6E, Apu6F,
2508         Apu70, Apu71, Apu72, Apu73, Apu74, Apu75, Apu76, Apu77,
2509         Apu78, Apu79, Apu7A, Apu7B, Apu7C, Apu7D, Apu7E, Apu7F,
2510         Apu80, Apu81, Apu82, Apu83, Apu84, Apu85, Apu86, Apu87,
2511         Apu88, Apu89, Apu8A, Apu8B, Apu8C, Apu8D, Apu8E, Apu8F,
2512         Apu90, Apu91, Apu92, Apu93, Apu94, Apu95, Apu96, Apu97,
2513         Apu98, Apu99, Apu9A, Apu9B, Apu9C, Apu9D, Apu9E, Apu9F,
2514         ApuA0, ApuA1, ApuA2, ApuA3, ApuA4, ApuA5, ApuA6, ApuA7,
2515         ApuA8, ApuA9, ApuAA, ApuAB, ApuAC, ApuAD, ApuAE, ApuAF,
2516         ApuB0, ApuB1, ApuB2, ApuB3, ApuB4, ApuB5, ApuB6, ApuB7,
2517         ApuB8, ApuB9, ApuBA, ApuBB, ApuBC, ApuBD, ApuBE, ApuBF,
2518         ApuC0, ApuC1, ApuC2, ApuC3, ApuC4, ApuC5, ApuC6, ApuC7,
2519         ApuC8, ApuC9, ApuCA, ApuCB, ApuCC, ApuCD, ApuCE, ApuCF,
2520         ApuD0, ApuD1, ApuD2, ApuD3, ApuD4, ApuD5, ApuD6, ApuD7,
2521         ApuD8, ApuD9, ApuDA, ApuDB, ApuDC, ApuDD, ApuDE, ApuDF,
2522         ApuE0, ApuE1, ApuE2, ApuE3, ApuE4, ApuE5, ApuE6, ApuE7,
2523         ApuE8, ApuE9, ApuEA, ApuEB, ApuEC, ApuED, ApuEE, ApuEF,
2524         ApuF0, ApuF1, ApuF2, ApuF3, ApuF4, ApuF5, ApuF6, ApuF7,
2525         ApuF8, ApuF9, ApuFA, ApuFB, ApuFC, ApuFD, ApuFE, ApuFF
2526 };
2527
2528 #endif