workaround a problem with the harmattan gcc
[drnoksnes] / spc700.h
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 #ifndef _SPC700_H_
42 #define _SPC700_H_
43
44 #ifdef SPCTOOL
45 #define NO_CHANNEL_STRUCT
46 #include "spctool/dsp.h"
47 #include "spctool/spc700.h"
48 #include "spctool/soundmod.h"
49 #endif
50
51
52 #define Carry       1
53 #define Zero        2
54 #define Interrupt   4
55 #define HalfCarry   8
56 #define BreakFlag  16
57 #define DirectPageFlag 32
58 #define Overflow   64
59 #define Negative  128
60
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)
73
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)
82
83 //#define APUClearFlags(f) (IAPU.P &= ~(f))
84 //#define APUSetFlags(f)   (IAPU.P |=  (f))
85 //#define APUCheckFlag(f)  (IAPU.P &   (f))
86
87 typedef union
88 {
89 #ifdef LSB_FIRST
90     struct { uint8 A, Y; } B;
91 #else
92     struct { uint8 Y, A; } B;
93 #endif
94     uint16 W;
95         uint32 _padder; // make sure this whole thing takes 4 bytes
96 } YAndA;
97
98 struct SAPURegisters{
99     uint8  P;
100     YAndA YA;
101     uint8  X;
102     uint8  S;
103     uint16  PC;
104 };
105
106 //EXTERN_C struct SAPURegisters APURegisters;
107
108 // Needed by ILLUSION OF GAIA
109 //#define ONE_APU_CYCLE 14
110 #define ONE_APU_CYCLE 21
111
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
115
116 // 1.953us := 1.024065.54MHz
117
118 #ifdef SPCTOOL
119 EXTERN_C int32 ESPC (int32);
120
121 #define APU_EXECUTE() \
122 { \
123     int32 l = (CPU.Cycles - CPU.APU_Cycles) / 14; \
124     if (l > 0) \
125     { \
126         l -= _EmuSPC(l); \
127         CPU.APU_Cycles += l * 14; \
128     } \
129 }
130
131 #else
132
133 #ifdef ASM_SPC700
134
135 // return cycles left (always negative)
136 extern "C" int spc700_execute(int cycles);
137
138 #define APU_EXECUTE1() \
139 { \
140         CPU.APU_Cycles -= spc700_execute(0); \
141 }
142
143 // notaz: CPU.APU_APUExecuting: 0 == disabled, 1 == enabled normal, 3 == enabled in hack mode
144
145 #define APU_EXECUTE(mode) \
146 if (CPU.APU_APUExecuting == mode) \
147 {\
148         if(CPU.APU_Cycles <= CPU.Cycles) { \
149                 int cycles = CPU.Cycles - CPU.APU_Cycles; \
150                 CPU.APU_Cycles += cycles - spc700_execute(cycles); \
151         } \
152 }
153
154 #else
155
156 #define APU_EXECUTE1() \
157 { \
158     CPU.APU_Cycles += S9xAPUCycles [*IAPU.PC]; \
159     (*S9xApuOpcodes[*IAPU.PC]) (); \
160 }
161
162 #define APU_EXECUTE(x) \
163 if (CPU.APU_APUExecuting) \
164 {\
165     while (CPU.APU_Cycles <= CPU.Cycles) \
166         APU_EXECUTE1(); \
167 }
168
169 #endif // ASM_SPC700
170
171 #endif // SPCTOOL
172
173 #endif