Path: blob/main/misc/emulator/xnes/snes9x/jma/portable.h
28798 views
/*1Copyright (C) 2004-2006 NSRT Team ( http://nsrt.edgeemu.com )2Copyright (C) 2002 Andrea Mazzoleni ( http://advancemame.sf.net )34This program is free software; you can redistribute it and/or5modify it under the terms of the GNU General Public License6version 2 as published by the Free Software Foundation.78This program is distributed in the hope that it will be useful,9but WITHOUT ANY WARRANTY; without even the implied warranty of10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11GNU General Public License for more details.1213You should have received a copy of the GNU General Public License14along with this program; if not, write to the Free Software15Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.16*/1718#ifndef __PORTABLE_H19#define __PORTABLE_H2021#include <string.h>22#ifdef __GNUC__23#include <stdint.h>2425typedef int8_t INT8;26typedef uint8_t UINT8;27typedef int16_t INT16;28typedef uint16_t UINT16;29typedef int32_t INT32;30typedef uint32_t UINT32;31typedef int64_t INT64;32typedef uint64_t UINT64;33typedef uintptr_t UINT_PTR;3435#else3637typedef signed char INT8;38typedef unsigned char UINT8;39typedef short INT16;40typedef unsigned short UINT16;41typedef int INT32;42typedef unsigned int UINT32;43#ifdef _MSC_VER44typedef __int64 INT64;45typedef unsigned __int64 UINT64;46#else47typedef long long INT64;48typedef unsigned long long UINT64;49#endif50typedef unsigned UINT_PTR;5152#endif5354typedef UINT8 BYTE;55typedef UINT16 WORD;56typedef UINT32 DWORD;5758typedef int BOOL;59#define FALSE 060#define TRUE 16162#define HRESULT int63#define S_OK 064#define E_INVALIDARG -165#define E_OUTOFMEMORY -266#define E_FAIL -367#define E_INTERNAL_ERROR -468#define E_INVALIDDATA -56970template <class T> inline T MyMin(T a, T b) {71return a < b ? a : b;72}7374template <class T> inline T MyMax(T a, T b) {75return a > b ? a : b;76}7778#define RETURN_IF_NOT_S_OK(x) { HRESULT __aResult_ = (x); if(__aResult_ != S_OK) return __aResult_; }798081#define UINT_SIZE ((int)sizeof(unsigned int))82#define USHORT_SIZE ((int)sizeof(unsigned short))8384//Convert an array of 4 bytes back into an integer85inline UINT32 charp_to_uint(const UINT8 buffer[UINT_SIZE])86{87UINT32 num = (UINT32)buffer[3];88num |= ((UINT32)buffer[2]) << 8;89num |= ((UINT32)buffer[1]) << 16;90num |= ((UINT32)buffer[0]) << 24;91return(num);92}9394//Convert an array of 2 bytes back into a short integer95inline UINT16 charp_to_ushort(const UINT8 buffer[USHORT_SIZE])96{97UINT16 num = (UINT16)buffer[1];98num |= ((UINT16)buffer[0]) << 8;99return(num);100}101102#endif103104105