ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

endian.h File Reference

Endian conversion and byteswap conversion functions or macros. More...

#include "common/scummsys.h"
Include dependency graph for endian.h:

Go to the source code of this file.

Defines

#define SWAP_CONSTANT_64(a)
#define SWAP_CONSTANT_32(a)
#define SWAP_CONSTANT_16(a)
#define MKTAG(a0, a1, a2, a3)   ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24)))
 A wrapper macro used around four character constants, like 'DATA', to ensure portability.
#define MKTAG16(a0, a1)   ((uint16)((a1) | ((a0) << 8)))
 A wrapper macro used around two character constants, like 'wb', to ensure portability.
#define READ_UINT24(a)   READ_BE_UINT24(a)

Functions

uint16 SWAP_BYTES_16 (const uint16 a)
 Swap the bytes in a 16 bit word in order to convert LE encoded data to BE and vice versa.
uint32 SWAP_BYTES_32 (uint32 a)
 Swap the bytes in a 32 bit word in order to convert LE encoded data to BE and vice versa.
uint64 SWAP_BYTES_64 (uint64 a)
 Swap the bytes in a 64 bit word in order to convert LE encoded data to BE and vice versa.
FORCEINLINE uint16 READ_UINT16 (const void *ptr)
FORCEINLINE uint32 READ_UINT32 (const void *ptr)
FORCEINLINE void WRITE_UINT16 (void *ptr, uint16 value)
FORCEINLINE void WRITE_UINT32 (void *ptr, uint32 value)
FORCEINLINE uint64 READ_UINT64 (const void *ptr)
FORCEINLINE void WRITE_UINT64 (void *ptr, uint64 value)
uint32 READ_LE_UINT24 (const void *ptr)
uint32 READ_BE_UINT24 (const void *ptr)
int16 READ_LE_INT16 (const void *ptr)
void WRITE_LE_INT16 (void *ptr, int16 value)
int16 READ_BE_INT16 (const void *ptr)
void WRITE_BE_INT16 (void *ptr, int16 value)
int32 READ_LE_INT32 (const void *ptr)
void WRITE_LE_INT32 (void *ptr, int32 value)
int32 READ_BE_INT32 (const void *ptr)
void WRITE_BE_INT32 (void *ptr, int32 value)

Detailed Description

Endian conversion and byteswap conversion functions or macros.

SWAP_BYTES_??(a) - inverse byte order SWAP_CONSTANT_??(a) - inverse byte order, implemented as macro. Use with compiletime-constants only, the result will be a compiletime-constant aswell. Unlike most other functions these can be used for eg. switch-case labels

READ_UINT??(a) - read native value from pointer a READ_??_UINT??(a) - read LE/BE value from pointer a and convert it to native WRITE_??_UINT??(a, v) - write native value v to pointer a with LE/BE encoding TO_??_??(a) - convert native value v to LE/BE FROM_??_??(a) - convert LE/BE value v to native CONSTANT_??_??(a) - convert LE/BE value v to native, implemented as macro. Use with compiletime-constants only, the result will be a compiletime-constant aswell. Unlike most other functions these can be used for eg. switch-case labels

Definition in file endian.h.


Define Documentation

#define MKTAG (   a0,
  a1,
  a2,
  a3 
)    ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24)))

A wrapper macro used around four character constants, like 'DATA', to ensure portability.

Typical usage: MKTAG('D','A','T','A').

Why is this necessary? The C/C++ standard does not define the endianess to be used for character constants. Hence if one uses multi-byte character constants, a potential portability problem opens up.

Definition at line 212 of file endian.h.

#define MKTAG16 (   a0,
  a1 
)    ((uint16)((a1) | ((a0) << 8)))

A wrapper macro used around two character constants, like 'wb', to ensure portability.

Typical usage: MKTAG16('w','b').

Definition at line 218 of file endian.h.

#define READ_UINT24 (   a  )     READ_BE_UINT24(a)

Definition at line 584 of file endian.h.

#define SWAP_CONSTANT_16 (   a  ) 
Value:
((uint16)((((a) >>  8) & 0x00FF) | \
              (((a) <<  8) & 0xFF00) ))

Definition at line 68 of file endian.h.

#define SWAP_CONSTANT_32 (   a  ) 
Value:
((uint32)((((a) >> 24) & 0x00FF) | \
              (((a) >>  8) & 0xFF00) | \
              (((a) & 0xFF00) <<  8) | \
              (((a) & 0x00FF) << 24) ))

Definition at line 62 of file endian.h.

#define SWAP_CONSTANT_64 (   a  ) 
Value:
((uint64)((((a) >> 56) & 0x000000FF) | \
              (((a) >> 40) & 0x0000FF00) | \
              (((a) >> 24) & 0x00FF0000) | \
              (((a) >>  8) & 0xFF000000) | \
              (((a) & 0xFF000000) <<  8) | \
              (((a) & 0x00FF0000) << 24) | \
              (((a) & 0x0000FF00) << 40) | \
              (((a) & 0x000000FF) << 56) ))

Definition at line 52 of file endian.h.


Function Documentation

int16 READ_BE_INT16 ( const void *  ptr  )  [inline]

Definition at line 595 of file endian.h.

int32 READ_BE_INT32 ( const void *  ptr  )  [inline]

Definition at line 611 of file endian.h.

uint32 READ_BE_UINT24 ( const void *  ptr  )  [inline]

Definition at line 576 of file endian.h.

int16 READ_LE_INT16 ( const void *  ptr  )  [inline]

Definition at line 587 of file endian.h.

int32 READ_LE_INT32 ( const void *  ptr  )  [inline]

Definition at line 603 of file endian.h.

uint32 READ_LE_UINT24 ( const void *  ptr  )  [inline]

Definition at line 571 of file endian.h.

FORCEINLINE uint16 READ_UINT16 ( const void *  ptr  ) 

Definition at line 264 of file endian.h.

FORCEINLINE uint32 READ_UINT32 ( const void *  ptr  ) 

Definition at line 268 of file endian.h.

FORCEINLINE uint64 READ_UINT64 ( const void *  ptr  ) 

Definition at line 280 of file endian.h.

uint16 SWAP_BYTES_16 ( const uint16  a  )  [inline]

Swap the bytes in a 16 bit word in order to convert LE encoded data to BE and vice versa.

Definition at line 95 of file endian.h.

uint32 SWAP_BYTES_32 ( uint32  a  )  [inline]

Swap the bytes in a 32 bit word in order to convert LE encoded data to BE and vice versa.

Definition at line 144 of file endian.h.

uint64 SWAP_BYTES_64 ( uint64  a  )  [inline]

Swap the bytes in a 64 bit word in order to convert LE encoded data to BE and vice versa.

Definition at line 190 of file endian.h.

void WRITE_BE_INT16 ( void *  ptr,
int16  value 
) [inline]

Definition at line 599 of file endian.h.

void WRITE_BE_INT32 ( void *  ptr,
int32  value 
) [inline]

Definition at line 615 of file endian.h.

void WRITE_LE_INT16 ( void *  ptr,
int16  value 
) [inline]

Definition at line 591 of file endian.h.

void WRITE_LE_INT32 ( void *  ptr,
int32  value 
) [inline]

Definition at line 607 of file endian.h.

FORCEINLINE void WRITE_UINT16 ( void *  ptr,
uint16  value 
)

Definition at line 272 of file endian.h.

FORCEINLINE void WRITE_UINT32 ( void *  ptr,
uint32  value 
)

Definition at line 276 of file endian.h.

FORCEINLINE void WRITE_UINT64 ( void *  ptr,
uint64  value 
)

Definition at line 284 of file endian.h.



Generated on Sat Mar 23 2019 05:03:17 for ResidualVM by doxygen 1.7.1
curved edge   curved edge