1 /*
2 Copyright (C) 2004-2006 NSRT Team ( http://nsrt.edgeemu.com )
3 Copyright (C) 2002 Andrea Mazzoleni ( http://advancemame.sf.net )
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, 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
26 typedef int8_t INT8;
27 typedef uint8_t UINT8;
28 typedef int16_t INT16;
29 typedef uint16_t UINT16;
30 typedef int32_t INT32;
31 typedef uint32_t UINT32;
32 typedef int64_t INT64;
33 typedef uint64_t UINT64;
34 typedef uintptr_t UINT_PTR;
35
36 #else
37
38 typedef signed char INT8;
39 typedef unsigned char UINT8;
40 typedef short INT16;
41 typedef unsigned short UINT16;
42 typedef int INT32;
43 typedef unsigned int UINT32;
44 #ifdef _MSC_VER
45 typedef __int64 INT64;
46 typedef unsigned __int64 UINT64;
47 #else
48 typedef long long INT64;
49 typedef unsigned long long UINT64;
50 #endif
51 typedef unsigned UINT_PTR;
52
53 #endif
54
55 typedef UINT8 BYTE;
56 typedef UINT16 WORD;
57 typedef UINT32 DWORD;
58
59 typedef 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
MyMin(T a,T b)71 template <class T> inline T MyMin(T a, T b) {
72 return a < b ? a : b;
73 }
74
MyMax(T a,T b)75 template <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
charp_to_uint(const UINT8 buffer[UINT_SIZE])86 inline 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
charp_to_ushort(const UINT8 buffer[USHORT_SIZE])96 inline 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