snes9x/jma/portable.h

104 lines
2.6 KiB
C
Raw Permalink Normal View History

2010-09-25 15:46:12 +00:00
/*
Copyright (C) 2004-2006 NSRT Team ( http://nsrt.edgeemu.com )
Copyright (C) 2002 Andrea Mazzoleni ( http://advancemame.sf.net )
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __PORTABLE_H
#define __PORTABLE_H
#include <string.h>
2010-09-25 16:46:06 +00:00
#ifdef __GNUC__
#include <stdint.h>
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;
typedef uintptr_t UINT_PTR;
#else
typedef signed char INT8;
typedef unsigned char UINT8;
typedef short INT16;
typedef unsigned short UINT16;
typedef int INT32;
typedef unsigned int UINT32;
#ifdef _MSC_VER
typedef __int64 INT64;
typedef unsigned __int64 UINT64;
#else
typedef long long INT64;
typedef unsigned long long UINT64;
#endif
typedef unsigned UINT_PTR;
2010-09-25 15:46:12 +00:00
2010-09-25 16:46:06 +00:00
#endif
2010-09-25 15:46:12 +00:00
2010-09-25 16:46:06 +00:00
typedef UINT8 BYTE;
2010-09-25 15:46:12 +00:00
typedef UINT16 WORD;
typedef UINT32 DWORD;
typedef int BOOL;
#define FALSE 0
2010-09-25 16:46:06 +00:00
#define TRUE 1
2010-09-25 15:46:12 +00:00
2010-09-25 16:46:06 +00:00
#define HRESULT int
#define S_OK 0
#define E_INVALIDARG -1
#define E_OUTOFMEMORY -2
#define E_FAIL -3
2010-09-25 15:46:12 +00:00
#define E_INTERNAL_ERROR -4
2010-09-25 16:46:06 +00:00
#define E_INVALIDDATA -5
2010-09-25 15:46:12 +00:00
template <class T> inline T MyMin(T a, T b) {
return a < b ? a : b;
}
template <class T> inline T MyMax(T a, T b) {
return a > b ? a : b;
}
#define RETURN_IF_NOT_S_OK(x) { HRESULT __aResult_ = (x); if(__aResult_ != S_OK) return __aResult_; }
2010-09-25 16:46:06 +00:00
#define UINT_SIZE ((int)sizeof(unsigned int))
#define USHORT_SIZE ((int)sizeof(unsigned short))
2010-09-25 15:46:12 +00:00
//Convert an array of 4 bytes back into an integer
2010-09-25 16:46:06 +00:00
inline UINT32 charp_to_uint(const UINT8 buffer[UINT_SIZE])
2010-09-25 15:46:12 +00:00
{
2010-09-25 16:46:06 +00:00
UINT32 num = (UINT32)buffer[3];
num |= ((UINT32)buffer[2]) << 8;
num |= ((UINT32)buffer[1]) << 16;
num |= ((UINT32)buffer[0]) << 24;
2010-09-25 15:46:12 +00:00
return(num);
}
//Convert an array of 2 bytes back into a short integer
2010-09-25 16:46:06 +00:00
inline UINT16 charp_to_ushort(const UINT8 buffer[USHORT_SIZE])
2010-09-25 15:46:12 +00:00
{
2010-09-25 16:46:06 +00:00
UINT16 num = (UINT16)buffer[1];
num |= ((UINT16)buffer[0]) << 8;
2010-09-25 15:46:12 +00:00
return(num);
}
#endif