initial upstream import
[drnoksnes] / port.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 _PORT_H_
42 #define _PORT_H_
43
44 /*
45 This port.h is really a right-of-passage for anyone trying to port the emulator 
46         to another platform.  It must have started out as a set of defines for a
47         single platform, and instead of using define blocks as new platforms were
48         added, individual coders simply added exceptions and sprinkled #ifdef and #ifndef
49         statements throughout the original list.
50
51 I can't take it anymore, it's too convoluted.  So I've commented out the entire
52         section, and preemptively rewritten the first #define segment the way god intended,
53         with a single define-block for each target platform.
54 */
55
56 /*
57 **  _SNESPPC DEFINES
58 */
59
60 #ifdef __GIZ__
61
62 //Title
63 #define TITLE "Snes9x"
64
65 //Required Includes
66 #include "pixform.h"
67 #include <zlib.h> //RC
68 //#include <windows.h>
69 #include <limits.h>
70 #include <string.h>
71 //Types Defined
72 typedef unsigned char   bool8;
73 typedef unsigned char   uint8;
74 typedef unsigned short  uint16;
75 typedef unsigned int    uint32;
76 typedef signed char             int8;
77 typedef short                   int16;
78 typedef int                             int32;
79 typedef long long               int64;
80
81 //CSNES Types for conversion to 32 bit
82 /*typedef unsigned long bool8_32;
83 typedef unsigned long   uint8_32;
84 typedef unsigned long   uint16_32;
85 typedef long                    int8_32;
86 typedef long                    int16_32;*/
87
88 //For Debugging Purposes:
89
90 typedef unsigned char   bool8_32;
91 typedef unsigned char   uint8_32;
92 typedef unsigned short  uint16_32;
93 typedef signed char             int8_32;
94 typedef short                   int16_32;
95
96
97 //Defines for Extern C
98 #define EXTERN_C extern
99 #define START_EXTERN_C extern "C" {
100 #define END_EXTERN_C }
101
102 //Path Defines
103 #undef  _MAX_PATH
104 #define _MAX_DIR PATH_MAX
105 #define _MAX_DRIVE 1
106 #define _MAX_FNAME PATH_MAX
107 #define _MAX_EXT PATH_MAX
108 #define PATH_MAX 1024
109 #define _MAX_PATH (1024)
110
111 //True/False Defines
112 #define TRUE 1
113 #define FALSE 0
114
115 //Slash Char Definitions
116 #define SLASH_STR "\\"
117 #define SLASH_CHAR '\\'
118
119 //Misc Items
120 #define VAR_CYCLES
121 //#define SPC700_SHUTDOWN
122 #define LSB_FIRST
123 #define STATIC static
124 #define FASTCALL
125 #define PIXEL_FORMAT RGB565
126 #define CHECK_SOUND()
127 #define VOID void
128 #define CPU_SHUTDOWN
129 #define UNZIP_SUPPORT
130 #define ZeroMemory(a,b) memset((a),0,(b))
131 #define PACKING __attribute__ ((packed))
132 #define ALIGN_BY_ONE  __attribute__ ((aligned (1), packed))
133 #define LSB_FIRST
134 #undef  FAST_LSB_WORD_ACCESS
135 #define ASM_SPC700
136
137 EXTERN_C void S9xGenerateSound ();
138
139 //Additional Items for _SNESPPC port
140 void _makepath (char *path, const char *drive, const char *dir,
141                 const char *fname, const char *ext);
142 void _splitpath (const char *path, char *drive, char *dir, char *fname,
143                  char *ext);
144 #define strcasecmp strcmp
145 #define strncasecmp strncmp
146 #define time(a) (0)
147
148 #ifdef INLINE
149 #undef INLINE
150 #define INLINE __inline
151 #endif
152
153 #ifdef inline
154 #undef inline
155 #define inline __inline
156 #endif
157
158 #endif //  _SNESPPC
159
160 #ifdef __GP2X__
161
162 //Title
163 #define TITLE "Snes9x"
164
165 //Required Includes
166 #include "pixform.h"
167 #include <zlib.h> //RC
168 //#include <windows.h>
169 #include <limits.h>
170 #include <string.h>
171 //Types Defined
172 typedef unsigned char   bool8;
173 typedef unsigned char   uint8;
174 typedef unsigned short  uint16;
175 typedef unsigned int    uint32;
176 typedef signed char             int8;
177 typedef short                   int16;
178 typedef int                             int32;
179 typedef long long               int64;
180
181 //CSNES Types for conversion to 32 bit
182 /*typedef unsigned long bool8_32;
183 typedef unsigned long   uint8_32;
184 typedef unsigned long   uint16_32;
185 typedef long                    int8_32;
186 typedef long                    int16_32;*/
187
188 //For Debugging Purposes:
189
190 typedef unsigned char   bool8_32;
191 typedef unsigned char   uint8_32;
192 typedef unsigned short  uint16_32;
193 typedef signed char             int8_32;
194 typedef short                   int16_32;
195
196
197 //Defines for Extern C
198 #define EXTERN_C extern
199 #define START_EXTERN_C extern "C" {
200 #define END_EXTERN_C }
201
202 //Path Defines
203 #undef  _MAX_PATH
204 #define _MAX_DIR PATH_MAX
205 #define _MAX_DRIVE 1
206 #define _MAX_FNAME PATH_MAX
207 #define _MAX_EXT PATH_MAX
208 #define _MAX_PATH (1024)
209
210 //True/False Defines
211 #define TRUE 1
212 #define FALSE 0
213
214 //Slash Char Definitions
215 #define SLASH_STR "/"
216 #define SLASH_CHAR '/'
217
218 //Misc Items
219 #define VAR_CYCLES
220 //#define SPC700_SHUTDOWN
221 #define LSB_FIRST
222 #define STATIC static
223 #define FASTCALL
224 #define PIXEL_FORMAT RGB565
225 #define CHECK_SOUND()
226 #define VOID void
227 #define CPU_SHUTDOWN
228 #define UNZIP_SUPPORT
229 #define ZeroMemory(a,b) memset((a),0,(b))
230 #define PACKING __attribute__ ((packed))
231 #define ALIGN_BY_ONE  __attribute__ ((aligned (1), packed))
232 #define LSB_FIRST
233 #undef  FAST_LSB_WORD_ACCESS
234 #define ASM_SPC700
235 #define SUPER_FX
236
237 EXTERN_C void S9xGenerateSound ();
238
239 //Additional Items for _SNESPPC port
240 void _makepath (char *path, const char *drive, const char *dir,
241                 const char *fname, const char *ext);
242 void _splitpath (const char *path, char *drive, char *dir, char *fname,
243                  char *ext);
244 #define strcasecmp strcmp
245 #define strncasecmp strncmp
246 #define time(a) (0)
247
248 #ifdef INLINE
249 #undef INLINE
250 #define INLINE inline
251 #endif
252
253 #ifdef inline
254 #undef inline
255 #define inline inline
256 #endif
257
258 #endif //  _SNESPPC
259 #endif //  _PORT_H_
260
261 /*
262 #ifndef _SNESPPC
263 #define _SNESPPC
264 #endif 
265
266 #ifndef RC_OPTIMIZED
267 #define RC_OPTIMIZED
268 #endif
269
270 #ifdef inline
271 #undef inline
272 #endif
273
274 #ifdef INLINE
275 #undef INLINE
276 #endif
277
278 #define inline __inline
279 #define INLINE __inline
280
281 #ifdef DEBUG
282 #ifndef _PROFILE_
283 #define _PROFILE_
284 #endif
285 #endif
286
287 #ifndef _SNESPPC
288 #ifndef STORM
289 #include <memory.h>
290 #include <string.h>
291 #else
292 //#include <strings.h>
293 //#include <clib/powerpc_protos.h>
294 #endif
295
296 #include <sys/types.h>
297 #else
298 #include <windows.h>
299 #endif
300
301 #define PIXEL_FORMAT RGB565
302 //#define GFX_MULTI_FORMAT
303
304 #if defined(TARGET_OS_MAC) && TARGET_OS_MAC
305
306 #ifdef _SNESPPC
307 #include "zlib/zlib.h" //RC
308 #else
309 #include "zlib.h"
310 #endif
311
312 #define ZLIB
313 #define EXECUTE_SUPERFX_PER_LINE
314 #define SOUND
315 #define VAR_CYCLES
316 #define CPU_SHUTDOWN
317 #define SPC700_SHUTDOWN
318 #define PIXEL_FORMAT RGB555
319 #define CHECK_SOUND()
320 #define M_PI 3.14159265359
321 #undef  _MAX_PATH
322
323 #undef DEBUGGER // Apple Universal Headers sometimes #define DEBUGGER
324 #undef GFX_MULTI_FORMAT
325
326 int    strncasecmp(const char *s1, const char *s2, unsigned n);
327 int    strcasecmp(const char *s1, const char *s2 );
328
329 #endif
330
331 #ifndef snes9x_types_defined
332 #define snes9x_types_defined
333
334 //CSNES
335 #ifdef _SNESPPC
336 typedef unsigned long bool8;
337 #else
338 typedef unsigned char bool8;
339 #endif
340
341 #ifndef __WIN32__
342 typedef unsigned char uint8;
343 typedef unsigned short uint16;
344 typedef signed char int8;
345 typedef short int16;
346 //typedef long int32;
347 //typedef unsigned long uint32;
348 typedef int int32;
349 typedef unsigned int uint32;
350 #ifdef _SNESPPC
351 typedef __int64 int64;
352 //CSNES
353 typedef unsigned long   uint8_32;
354 typedef unsigned long   uint16_32;
355 typedef long                    int8_32;
356 typedef long                    int16_32;
357
358 #else
359 typedef long long int64;
360 #endif
361 #else // __WIN32__
362
363 #ifdef __BORLANDC__
364 //#include <systypes.h>
365 #else
366
367 typedef unsigned char uint8;
368 typedef unsigned short uint16;
369 typedef signed char int8;
370 typedef short int16;
371
372 #ifndef WSAAPI
373 // winsock2.h typedefs int32 as well.
374 typedef long int32;
375 #endif
376
377 typedef unsigned int uint32;
378
379 #endif // __BORLANDC__
380
381 typedef __int64 int64;
382
383 #endif // __WIN32__
384 #endif // snes9x_types_defined
385 #include "pixform.h"
386
387 #ifndef TRUE
388 #define TRUE 1
389 #endif
390
391 #ifndef FALSE
392 #define FALSE 0
393 #endif
394
395 #ifdef STORM
396 #define EXTERN_C
397 #define START_EXTERN_C
398 #define END_EXTERN_C
399 #else
400 #if defined(__cplusplus) || defined(c_plusplus)
401 #define EXTERN_C extern "C"
402 #define START_EXTERN_C extern "C" {
403 #define END_EXTERN_C }
404 #else
405 #define EXTERN_C extern
406 #define START_EXTERN_C
407 #define END_EXTERN_C
408 #endif
409 #endif
410
411 #ifndef __WIN32__
412
413 #ifndef PATH_MAX
414 #define PATH_MAX 1024
415 #endif
416
417 #define _MAX_DIR PATH_MAX
418 #define _MAX_DRIVE 1
419 #define _MAX_FNAME PATH_MAX
420 #define _MAX_EXT PATH_MAX
421 #ifndef _MAX_PATH
422 #define _MAX_PATH PATH_MAX
423 #endif
424
425 #ifdef _SNESPPC
426 #define strcasecmp strcmp
427 #define strncasecmp strncmp
428 #define time(a) (0)
429 #ifdef _MAX_PATH
430 #undef _MAX_PATH
431 #define _MAX_PATH (1024)
432 #endif
433 #endif
434
435 #define ZeroMemory(a,b) memset((a),0,(b))
436
437 void _makepath (char *path, const char *drive, const char *dir,
438                 const char *fname, const char *ext);
439 void _splitpath (const char *path, char *drive, char *dir, char *fname,
440                  char *ext);
441 #else // __WIN32__
442 #define strcasecmp stricmp
443 #define strncasecmp strnicmp
444 #endif
445
446 EXTERN_C void S9xGenerateSound ();
447
448 #ifdef STORM
449 EXTERN_C int soundsignal;
450 EXTERN_C void MixSound(void);
451 //Yes, CHECK_SOUND is getting defined correctly!
452 #define CHECK_SOUND if (Settings.APUEnabled) if(SetSignalPPC(0L, soundsignal) & soundsignal) MixSound
453 #else
454 #define CHECK_SOUND()
455 #endif
456
457 #ifdef __DJGPP
458 #define SLASH_STR "\\"
459 #define SLASH_CHAR '\\'
460 #else
461 #define SLASH_STR "/"
462 #define SLASH_CHAR '/'
463 #endif
464
465 #ifdef __linux
466 typedef void (*SignalHandler)(int);
467 #define SIG_PF SignalHandler
468 #endif
469
470 #if defined(__i386__) || defined(__i486__) || defined(__i586__) || \
471     defined(__WIN32__) || defined(__alpha__)
472 #define LSB_FIRST
473 #define FAST_LSB_WORD_ACCESS
474 #else
475 #ifdef _SNESPPC
476 #define LSB_FIRST
477 //NOPE! #define FAST_LSB_WORD_ACCESS //RC
478 #else 
479 #define MSB_FIRST
480 #endif
481 #endif
482
483 #ifdef __sun
484 #define TITLE "Snes9X: Solaris"
485 #endif
486
487 #ifdef __linux
488 #define TITLE "Snes9X: Linux"
489 #endif
490
491 #ifndef TITLE
492 #define TITLE "Snes9x"
493 #endif
494
495 #ifdef STORM
496 #define STATIC
497 #define strncasecmp strnicmp
498 #else
499 #define STATIC static
500 #endif
501
502 #endif
503 */
504