datatypes.h

Go to the documentation of this file.
00001 /* ES40 emulator.
00002  * Copyright (C) 2007-2008 by the ES40 Emulator Project
00003  *
00004  * WWW    : http://sourceforge.net/projects/es40
00005  * E-mail : camiel@camicom.com
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020  * 
00021  * Although this is not required, the author would appreciate being notified of, 
00022  * and receiving any modifications you may make to the source code that might serve
00023  * the general public.
00024  */
00025 
00097 #if !defined(INCLUDED_DATATYPES_H)
00098 #define INCLUDED_DATATYPES_H
00099 
00100 #if defined(HAVE_STDINT_H)
00101 #include <stdint.h>
00102 #endif
00103 
00104 #if defined(HAVE_INTTYPES_H)
00105 #include <inttypes.h>
00106 #endif
00107 
00108 #if defined(_WIN32) && !defined(__GNUWIN32__)
00109 
00110 #define U64(a)  a##ui64
00111 #define LL      "I64"
00112 
00113 #else // defined(_WIN32)
00114 
00115 #define U64(a)  a##ll
00116 #define LL      "ll"
00117 
00118 #endif // defined(_WIN32)
00119 
00120 
00121 typedef uint8_t   u8;
00122 typedef uint16_t  u16;
00123 typedef uint32_t  u32;
00124 typedef uint64_t  u64;
00125 
00126 typedef int8_t    s8;
00127 typedef int16_t   s16;
00128 typedef int32_t   s32;
00129 typedef int64_t   s64;
00130 
00131 typedef u8  u_int8_t;
00132 typedef u16 u_int16_t;
00133 typedef u32 u_int32_t;
00134 typedef u64 u_int64_t;
00135 
00136 #define HAVE_U_INT8_T   1
00137 #define HAVE_INT8_T     1
00138 #define HAVE_U_INT16_T  1
00139 #define HAVE_INT16_T    1
00140 #define HAVE_U_INT32_T  1
00141 #define HAVE_INT32_T    1
00142 #define HAVE_U_INT64_T  1
00143 #define HAVE_INT64_T    1
00144 
00148 inline u64 sext_u64_8(u64 a)
00149 {
00150   return
00151     (
00152       ((a) & U64(0x0000000000000080)) ? ((a) | U64(0xffffffffffffff00)) :
00153         ((a) & U64(0x00000000000000ff))
00154     );
00155 }
00156 
00160 inline u64 sext_u64_12(u64 a)
00161 {
00162   return
00163     (
00164       ((a) & U64(0x0000000000000800)) ? ((a) | U64(0xfffffffffffff000)) :
00165         ((a) & U64(0x0000000000000fff))
00166     );
00167 }
00168 
00172 inline u64 sext_u64_13(u64 a)
00173 {
00174   return
00175     (
00176       ((a) & U64(0x0000000000001000)) ? ((a) | U64(0xffffffffffffe000)) :
00177         ((a) & U64(0x0000000000001fff))
00178     );
00179 }
00180 
00184 inline u64 sext_u64_16(u64 a)
00185 {
00186   return
00187     (
00188       ((a) & U64(0x0000000000008000)) ? ((a) | U64(0xffffffffffff0000)) :
00189         ((a) & U64(0x000000000000ffff))
00190     );
00191 }
00192 
00196 inline u64 sext_u64_21(u64 a)
00197 {
00198   return
00199     (
00200       ((a) & U64(0x0000000000100000)) ? ((a) | U64(0xffffffffffe00000)) :
00201         ((a) & U64(0x00000000001fffff))
00202     );
00203 }
00204 
00208 inline u64 sext_u64_32(u64 a)
00209 {
00210   return
00211     (
00212       ((a) & U64(0x0000000080000000)) ? ((a) | U64(0xffffffff00000000)) :
00213         ((a) & U64(0x00000000ffffffff))
00214     );
00215 }
00216 
00220 inline u64 sext_u64_48(u64 a)
00221 {
00222   return
00223     (
00224       ((a) & U64(0x0000800000000000)) ? ((a) | U64(0xffff000000000000)) :
00225         ((a) & U64(0x0000ffffffffffff))
00226     );
00227 }
00228 
00229 inline bool test_bit_64(u64 x, int bit)
00230 {
00231   return(x & (U64(0x1) << bit)) ? true : false;
00232 }
00233 
00237 inline u32 sext_u32_24(u32 a)
00238 {
00239   return(((a) & 0x00800000) ? ((a) | 0xff000000) : ((a) & 0x00ffffff));
00240 }
00241 #endif //INCLUDED_DATATYPES_H

SourceForge.net Logo
Project space on SourceForge.net