2 * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
4 * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5 * Jerremy Koot (jkoot@snes9x.com)
7 * Super FX C emulator code
8 * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
10 * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
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).
16 * DOS port code contains the works of other authors. See headers in
19 * Snes9x homepage: http://www.snes9x.com
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.
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.
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.
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
38 * Super NES and Super Nintendo Entertainment System are trademarks of
39 * Nintendo Co., Limited and its subsidiary companies.
45 #define NO_CHANNEL_STRUCT
46 #include "spctool/dsp.h"
47 #include "spctool/spc700.h"
48 #include "spctool/soundmod.h"
57 #define DirectPageFlag 32
61 #define APUClearCarry() (IAPU._Carry = 0)
62 #define APUSetCarry() (IAPU._Carry = 1)
63 #define APUSetInterrupt() (IAPU.P |= Interrupt)
64 #define APUClearInterrupt() (IAPU.P &= ~Interrupt)
65 #define APUSetHalfCarry() (IAPU.P |= HalfCarry)
66 #define APUClearHalfCarry() (IAPU.P &= ~HalfCarry)
67 #define APUSetBreak() (IAPU.P |= BreakFlag)
68 #define APUClearBreak() (IAPU.P &= ~BreakFlag)
69 #define APUSetDirectPage() (IAPU.P |= DirectPageFlag)
70 #define APUClearDirectPage() (IAPU.P &= ~DirectPageFlag)
71 #define APUSetOverflow() (IAPU._Overflow = 1)
72 #define APUClearOverflow() (IAPU._Overflow = 0)
74 #define APUCheckZero() (IAPU._Zero == 0)
75 #define APUCheckCarry() (IAPU._Carry)
76 #define APUCheckInterrupt() (IAPU.P & Interrupt)
77 #define APUCheckHalfCarry() (IAPU.P & HalfCarry)
78 #define APUCheckBreak() (IAPU.P & BreakFlag)
79 #define APUCheckDirectPage() (IAPU.P & DirectPageFlag)
80 #define APUCheckOverflow() (IAPU._Overflow)
81 #define APUCheckNegative() (IAPU._Zero & 0x80)
83 //#define APUClearFlags(f) (IAPU.P &= ~(f))
84 //#define APUSetFlags(f) (IAPU.P |= (f))
85 //#define APUCheckFlag(f) (IAPU.P & (f))
90 struct { uint8 A, Y; } B;
92 struct { uint8 Y, A; } B;
95 uint32 _padder; // make sure this whole thing takes 4 bytes
106 //EXTERN_C struct SAPURegisters APURegisters;
108 // Needed by ILLUSION OF GAIA
109 //#define ONE_APU_CYCLE 14
110 #define ONE_APU_CYCLE 21
112 // Needed by all games written by the software company called Human
113 //#define ONE_APU_CYCLE_HUMAN 17
114 #define ONE_APU_CYCLE_HUMAN 21
116 // 1.953us := 1.024065.54MHz
119 EXTERN_C int32 ESPC (int32);
121 #define APU_EXECUTE() \
123 int32 l = (CPU.Cycles - CPU.APU_Cycles) / 14; \
127 CPU.APU_Cycles += l * 14; \
135 // return cycles left (always negative)
136 extern "C" int spc700_execute(int cycles);
138 #define APU_EXECUTE1() \
140 CPU.APU_Cycles -= spc700_execute(0); \
143 // notaz: CPU.APU_APUExecuting: 0 == disabled, 1 == enabled normal, 3 == enabled in hack mode
145 #define APU_EXECUTE(mode) \
146 if (CPU.APU_APUExecuting == mode) \
148 if(CPU.APU_Cycles <= CPU.Cycles) { \
149 int cycles = CPU.Cycles - CPU.APU_Cycles; \
150 CPU.APU_Cycles += cycles - spc700_execute(cycles); \
156 #define APU_EXECUTE1() \
158 CPU.APU_Cycles += S9xAPUCycles [*IAPU.PC]; \
159 (*S9xApuOpcodes[*IAPU.PC]) (); \
162 #define APU_EXECUTE(x) \
163 if (CPU.APU_APUExecuting) \
165 while (CPU.APU_Cycles <= CPU.Cycles) \