1/*
2Copyright (C) 2004-2006 NSRT Team ( http://nsrt.edgeemu.com )
3Copyright (C) 2002 Andrea Mazzoleni ( http://advancemame.sf.net )
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7version 2 as published by the Free Software Foundation.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17*/
18
19#ifndef __PORTABLE_H
20#define __PORTABLE_H
21
22#include <string.h>
23#ifdef __GNUC__
24#include <stdint.h>
25
26typedef int8_t INT8;
27typedef uint8_t UINT8;
28typedef int16_t INT16;
29typedef uint16_t UINT16;
30typedef int32_t INT32;
31typedef uint32_t UINT32;
32typedef int64_t INT64;
33typedef uint64_t UINT64;
34typedef uintptr_t UINT_PTR;
35
36#else
37
38typedef signed char INT8;
39typedef unsigned char UINT8;
40typedef short INT16;
41typedef unsigned short UINT16;
42typedef int INT32;
43typedef unsigned int UINT32;
44#ifdef _MSC_VER
45typedef __int64 INT64;
46typedef unsigned __int64 UINT64;
47#else
48typedef long long INT64;
49typedef unsigned long long UINT64;
50#endif
51typedef unsigned UINT_PTR;
52
53#endif
54
55typedef UINT8 BYTE;
56typedef UINT16 WORD;
57typedef UINT32 DWORD;
58
59typedef int BOOL;
60#define FALSE 0
61#define TRUE 1
62
63#define HRESULT int
64#define S_OK 0
65#define E_INVALIDARG -1
66#define E_OUTOFMEMORY -2
67#define E_FAIL -3
68#define E_INTERNAL_ERROR -4
69#define E_INVALIDDATA -5
70
71template <class T> inline T MyMin(T a, T b) {
72 return a < b ? a : b;
73}
74
75template <class T> inline T MyMax(T a, T b) {
76 return a > b ? a : b;
77}
78
79#define RETURN_IF_NOT_S_OK(x) { HRESULT __aResult_ = (x); if(__aResult_ != S_OK) return __aResult_; }
80
81
82#define UINT_SIZE ((int)sizeof(unsigned int))
83#define USHORT_SIZE ((int)sizeof(unsigned short))
84
85//Convert an array of 4 bytes back into an integer
86inline UINT32 charp_to_uint(const UINT8 buffer[UINT_SIZE])
87{
88 UINT32 num = (UINT32)buffer[3];
89 num |= ((UINT32)buffer[2]) << 8;
90 num |= ((UINT32)buffer[1]) << 16;
91 num |= ((UINT32)buffer[0]) << 24;
92 return(num);
93}
94
95//Convert an array of 2 bytes back into a short integer
96inline UINT16 charp_to_ushort(const UINT8 buffer[USHORT_SIZE])
97{
98 UINT16 num = (UINT16)buffer[1];
99 num |= ((UINT16)buffer[0]) << 8;
100 return(num);
101}
102
103#endif
104