snes9xgx/source/snes9x/port.h

209 lines
5.8 KiB
C
Raw Normal View History

/*****************************************************************************\
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
This file is licensed under the Snes9x License.
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
2009-11-30 09:14:38 +01:00
#ifndef _PORT_H_
#define _PORT_H_
2010-01-27 23:08:56 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <limits.h>
2018-08-20 17:11:01 +02:00
#ifndef GEKKO
2010-10-03 22:13:53 +02:00
#include <memory.h>
#endif
2010-01-27 23:08:56 +01:00
#include <time.h>
#include <string.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
2010-01-27 23:08:56 +01:00
#include <sys/types.h>
#ifdef __WIN32__
2018-11-12 02:31:52 +01:00
#define NOMINMAX 1
2010-01-27 23:08:56 +01:00
#include <windows.h>
#endif
2010-01-27 23:08:56 +01:00
#ifdef __WIN32__
//#define RIGHTSHIFT_IS_SAR
#define RIGHTSHIFT_int8_IS_SAR
#define RIGHTSHIFT_int16_IS_SAR
#define RIGHTSHIFT_int32_IS_SAR
2018-11-12 02:31:52 +01:00
#ifndef GEKKO
2010-01-27 23:08:56 +01:00
#define SNES_JOY_READ_CALLBACKS
2018-11-12 02:31:52 +01:00
#define GFX_MULTI_FORMAT
#endif
#endif
#ifdef __LIBRETRO__
#define GFX_MULTI_FORMAT
#endif
#ifdef __MACOSX__
2010-01-27 23:08:56 +01:00
#undef GFX_MULTI_FORMAT
#define PIXEL_FORMAT RGB555
#endif
#ifndef PIXEL_FORMAT
#define PIXEL_FORMAT RGB565
#endif
#ifndef snes9x_types_defined
#define snes9x_types_defined
2010-01-27 23:08:56 +01:00
typedef unsigned char bool8;
#ifdef HAVE_STDINT_H
#include <stdint.h>
2010-01-27 23:08:56 +01:00
typedef intptr_t pint;
typedef int8_t int8;
typedef uint8_t uint8;
typedef int16_t int16;
typedef uint16_t uint16;
typedef int32_t int32;
typedef uint32_t uint32;
typedef int64_t int64;
typedef uint64_t uint64;
#else // HAVE_STDINT_H
2010-10-03 22:13:53 +02:00
#ifdef __WIN32__
typedef intptr_t pint;
2010-01-27 23:08:56 +01:00
typedef signed char int8;
typedef unsigned char uint8;
typedef signed short int16;
typedef unsigned short uint16;
2018-11-12 02:31:52 +01:00
typedef signed int int32;
2010-01-27 23:08:56 +01:00
typedef unsigned int uint32;
typedef signed __int64 int64;
typedef unsigned __int64 uint64;
2018-11-12 02:31:52 +01:00
typedef int8 int8_t;
typedef uint8 uint8_t;
typedef int16 int16_t;
typedef uint16 uint16_t;
typedef int32 int32_t;
typedef uint32 uint32_t;
typedef int64 int64_t;
typedef uint64 uint64_t;
2010-01-27 23:08:56 +01:00
typedef int socklen_t;
#else // __WIN32__
typedef signed char int8;
typedef unsigned char uint8;
typedef signed short int16;
typedef unsigned short uint16;
typedef signed int int32;
typedef unsigned int uint32;
#ifdef __GNUC__
// long long is not part of ISO C++
__extension__
2008-09-10 07:57:37 +02:00
#endif
2010-01-27 23:08:56 +01:00
typedef long long int64;
typedef unsigned long long uint64;
2018-11-12 02:31:52 +01:00
#ifdef PTR_NOT_INT
typedef size_t pint;
#else // __PTR_NOT_INT
typedef size_t pint;
#endif // __PTR_NOT_INT
2010-01-27 23:08:56 +01:00
#endif // __WIN32__
#endif // HAVE_STDINT_H
#endif // snes9x_types_defined
#ifndef TRUE
2010-01-27 23:08:56 +01:00
#define TRUE 1
#endif
#ifndef FALSE
2010-01-27 23:08:56 +01:00
#define FALSE 0
#endif
2010-01-27 23:08:56 +01:00
#define START_EXTERN_C extern "C" {
#define END_EXTERN_C }
#ifndef __WIN32__
#ifndef PATH_MAX
2010-01-27 23:08:56 +01:00
#define PATH_MAX 1024
#endif
2010-01-27 23:08:56 +01:00
#define _MAX_DRIVE 1
#define _MAX_DIR PATH_MAX
#define _MAX_FNAME PATH_MAX
#define _MAX_EXT PATH_MAX
#define _MAX_PATH PATH_MAX
#else
#ifndef PATH_MAX
#define PATH_MAX _MAX_PATH
#endif
#endif
2010-01-27 23:08:56 +01:00
#ifndef __WIN32__
void _splitpath (const char *, char *, char *, char *, char *);
void _makepath (char *, const char *, const char *, const char *, const char *);
#define S9xDisplayString DisplayStringFromBottom
2018-11-12 02:31:52 +01:00
#else // __WIN32__
2010-01-27 23:08:56 +01:00
#define snprintf _snprintf
#define strcasecmp stricmp
#define strncasecmp strnicmp
2018-11-12 02:31:52 +01:00
#ifndef __LIBRETRO__
2010-01-27 23:08:56 +01:00
void WinDisplayStringFromBottom(const char *string, int linesFromBottom, int pixelsFromLeft, bool allowWrap);
#define S9xDisplayString WinDisplayStringFromBottom
2010-10-03 22:13:53 +02:00
void SetInfoDlgColor(unsigned char, unsigned char, unsigned char);
#define SET_UI_COLOR(r,g,b) SetInfoDlgColor(r,g,b)
2018-11-12 02:31:52 +01:00
#else // __LIBRETRO__
#define S9xDisplayString DisplayStringFromBottom
#endif // __LIBRETRO__
#endif // __WIN32__
inline void sstrncpy(char *dst, const char *src, size_t size)
{
strncpy(dst, src, size - 1);
dst[size - 1] = '\0';
}
2018-11-12 02:31:52 +01:00
#if defined(__DJGPP) || defined(__WIN32__)
2010-01-27 23:08:56 +01:00
#define SLASH_STR "\\"
#define SLASH_CHAR '\\'
#else
2010-01-27 23:08:56 +01:00
#define SLASH_STR "/"
#define SLASH_CHAR '/'
#endif
#ifndef SIG_PF
2010-01-27 23:08:56 +01:00
#define SIG_PF void (*) (int)
#endif
#ifdef __linux
2010-01-27 23:08:56 +01:00
#define TITLE "Snes9x: Linux"
#define SYS_CONFIG_FILE "/etc/snes9x/snes9x.conf"
#endif
#ifndef TITLE
#define TITLE "Snes9x"
#endif
2018-11-12 02:31:52 +01:00
#if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(__x86_64__) || defined(__alpha__) || defined(__MIPSEL__) || defined(_M_IX86) || defined(_M_X64) || defined(_XBOX1) || defined(__arm__) || defined(ANDROID) || defined(__aarch64__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN__)
2010-01-27 23:08:56 +01:00
#define LSB_FIRST
#define FAST_LSB_WORD_ACCESS
#else
2010-01-27 23:08:56 +01:00
#define MSB_FIRST
#endif
#ifdef FAST_LSB_WORD_ACCESS
2010-01-27 23:08:56 +01:00
#define READ_WORD(s) (*(uint16 *) (s))
#define READ_3WORD(s) (*(uint32 *) (s) & 0x00ffffff)
#define READ_DWORD(s) (*(uint32 *) (s))
#define WRITE_WORD(s, d) *(uint16 *) (s) = (d)
#define WRITE_3WORD(s, d) *(uint16 *) (s) = (uint16) (d), *((uint8 *) (s) + 2) = (uint8) ((d) >> 16)
#define WRITE_DWORD(s, d) *(uint32 *) (s) = (d)
#else
2010-01-27 23:08:56 +01:00
#define READ_WORD(s) (*(uint8 *) (s) | (*((uint8 *) (s) + 1) << 8))
#define READ_3WORD(s) (*(uint8 *) (s) | (*((uint8 *) (s) + 1) << 8) | (*((uint8 *) (s) + 2) << 16))
#define READ_DWORD(s) (*(uint8 *) (s) | (*((uint8 *) (s) + 1) << 8) | (*((uint8 *) (s) + 2) << 16) | (*((uint8 *) (s) + 3) << 24))
#define WRITE_WORD(s, d) *(uint8 *) (s) = (uint8) (d), *((uint8 *) (s) + 1) = (uint8) ((d) >> 8)
#define WRITE_3WORD(s, d) *(uint8 *) (s) = (uint8) (d), *((uint8 *) (s) + 1) = (uint8) ((d) >> 8), *((uint8 *) (s) + 2) = (uint8) ((d) >> 16)
#define WRITE_DWORD(s, d) *(uint8 *) (s) = (uint8) (d), *((uint8 *) (s) + 1) = (uint8) ((d) >> 8), *((uint8 *) (s) + 2) = (uint8) ((d) >> 16), *((uint8 *) (s) + 3) = (uint8) ((d) >> 24)
#endif
2010-01-27 23:08:56 +01:00
#define SWAP_WORD(s) (s) = (((s) & 0xff) << 8) | (((s) & 0xff00) >> 8)
#define SWAP_DWORD(s) (s) = (((s) & 0xff) << 24) | (((s) & 0xff00) << 8) | (((s) & 0xff0000) >> 8) | (((s) & 0xff000000) >> 24)
2009-11-30 09:14:38 +01:00
2010-01-27 23:08:56 +01:00
#include "pixform.h"
#endif