workaround a problem with the harmattan gcc
[drnoksnes] / apumem.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 _apumemory_h_
42 #define _apumemory_h_
43
44 START_EXTERN_C
45 extern uint8 W4;
46 extern uint8 APUROM[64];
47 END_EXTERN_C
48
49 INLINE uint8 S9xAPUGetByteZ (uint8 Address)
50 {
51     if (Address >= 0xf0 && IAPU.DirectPage == IAPU.RAM)
52     {
53         if (Address >= 0xf4 && Address <= 0xf7)
54         {
55 #ifdef SPC700_SHUTDOWN
56             IAPU.WaitAddress2 = IAPU.WaitAddress1;
57             IAPU.WaitAddress1 = IAPU.PC;
58 #endif      
59             return (IAPU.RAM [Address]);
60         }
61         if (Address >= 0xfd)
62         {
63 #ifdef SPC700_SHUTDOWN
64             IAPU.WaitAddress2 = IAPU.WaitAddress1;
65             IAPU.WaitAddress1 = IAPU.PC;
66 #endif      
67             uint8 t = IAPU.RAM [Address];
68             IAPU.RAM [Address] = 0;
69             return (t);
70         }
71         else
72         if (Address == 0xf3)
73             return (S9xGetAPUDSP ());
74
75         return (IAPU.RAM [Address]);
76     }
77     else
78         return (IAPU.DirectPage [Address]);
79 }
80
81 INLINE void S9xAPUSetByteZ (uint8 val, uint8 Address)
82 {
83     if (Address >= 0xf0 && IAPU.DirectPage == IAPU.RAM)
84     {
85         if (Address == 0xf3)
86             S9xSetAPUDSP (val);
87         else
88         if (Address >= 0xf4 && Address <= 0xf7)
89             APU.OutPorts [Address - 0xf4] = val;
90         else
91         if (Address == 0xf1)
92             S9xSetAPUControl (val);
93         else
94         if (Address < 0xfd)
95         {
96             IAPU.RAM [Address] = val;
97             if (Address >= 0xfa)
98             {
99                 if (val == 0)
100                     APU.TimerTarget [Address - 0xfa] = 0x100;
101                 else
102                     APU.TimerTarget [Address - 0xfa] = val;
103             }
104         }
105     }
106     else
107         IAPU.DirectPage [Address] = val;
108 }
109
110 INLINE uint8 S9xAPUGetByte (uint32 Address)
111 {
112     Address &= 0xffff;
113     
114     if (Address <= 0xff && Address >= 0xf0)
115     {
116         if (Address >= 0xf4 && Address <= 0xf7)
117         {
118 #ifdef SPC700_SHUTDOWN
119             IAPU.WaitAddress2 = IAPU.WaitAddress1;
120             IAPU.WaitAddress1 = IAPU.PC;
121 #endif      
122             return (IAPU.RAM [Address]);
123         }
124         else
125         if (Address == 0xf3)
126             return (S9xGetAPUDSP ());
127         if (Address >= 0xfd)
128         {
129 #ifdef SPC700_SHUTDOWN
130             IAPU.WaitAddress2 = IAPU.WaitAddress1;
131             IAPU.WaitAddress1 = IAPU.PC;
132 #endif
133             uint8 t = IAPU.RAM [Address];
134             IAPU.RAM [Address] = 0;
135             return (t);
136         }
137         return (IAPU.RAM [Address]);
138     }
139     else
140         return (IAPU.RAM [Address]);
141 }
142
143 INLINE void S9xAPUSetByte (uint8 val, uint32 Address)
144 {
145     Address &= 0xffff;
146     
147     if (Address <= 0xff && Address >= 0xf0)
148     {
149         if (Address == 0xf3)
150             S9xSetAPUDSP (val);
151         else
152         if (Address >= 0xf4 && Address <= 0xf7)
153             APU.OutPorts [Address - 0xf4] = val;
154         else
155         if (Address == 0xf1)
156             S9xSetAPUControl (val);
157         else
158         if (Address < 0xfd)
159         {
160             IAPU.RAM [Address] = val;
161             if (Address >= 0xfa)
162             {
163                 if (val == 0)
164                     APU.TimerTarget [Address - 0xfa] = 0x100;
165                 else
166                     APU.TimerTarget [Address - 0xfa] = val;
167             }
168         }
169     }
170     else
171     {
172 #if 0
173 if (Address >= 0x2500 && Address <= 0x2504)
174 printf ("%06d %04x <- %02x\n", ICPU.Scanline, Address, val);
175 if (Address == 0x26c6)
176 {
177     extern FILE *apu_trace;
178     extern FILE *trace;
179     APU.Flags |= TRACE_FLAG;
180     CPU.Flags |= TRACE_FLAG;
181     if (apu_trace == NULL)
182         apu_trace = fopen ("aputrace.log", "wb");
183     if (trace == NULL)
184         trace = fopen ("trace.log", "wb");
185     printf ("TRACING SWITCHED ON\n");
186 }
187 #endif
188         if (Address < 0xffc0)
189             IAPU.RAM [Address] = val;
190         else
191         {
192             APU.ExtraRAM [Address - 0xffc0] = val;
193             if (!APU.ShowROM)
194                 IAPU.RAM [Address] = val;
195         }
196     }
197 }
198 #endif