aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2006-02-25 11:45:56 +0000
committerMax Horn2006-02-25 11:45:56 +0000
commit1c93f7bcead228faebc0c79bc31c038de8c26016 (patch)
treee65a06c3740b71e6d1f098010c672e1dd29857e7 /common
parent1f987027f8f901e48f064cdc766064f4bf4b6fc9 (diff)
downloadscummvm-rg350-1c93f7bcead228faebc0c79bc31c038de8c26016.tar.gz
scummvm-rg350-1c93f7bcead228faebc0c79bc31c038de8c26016.tar.bz2
scummvm-rg350-1c93f7bcead228faebc0c79bc31c038de8c26016.zip
Removed the obsolete MKID macro; added some doxygen comments, in particular for MKID_BE
svn-id: r20873
Diffstat (limited to 'common')
-rw-r--r--common/endian.h51
1 files changed, 38 insertions, 13 deletions
diff --git a/common/endian.h b/common/endian.h
index 4e1f46c026..c3ff673235 100644
--- a/common/endian.h
+++ b/common/endian.h
@@ -29,6 +29,10 @@
// Endian conversion functions, macros etc., follow from here!
//
+/**
+ * Swap the bytes in a 32 bit word in order to convert LE encoded data to BE
+ * and vice versa.
+ */
FORCEINLINE uint32 SWAP_BYTES_32(uint32 a) {
return ((a >> 24) & 0x000000FF) |
((a >> 8) & 0x0000FF00) |
@@ -36,26 +40,46 @@ FORCEINLINE uint32 SWAP_BYTES_32(uint32 a) {
((a << 24) & 0xFF000000);
}
+/**
+ * Swap the bytes in a 16 bit word in order to convert LE encoded data to BE
+ * and vice versa.
+ */
FORCEINLINE uint16 SWAP_BYTES_16(uint16 a) {
return ((a >> 8) & 0x00FF) + ((a << 8) & 0xFF00);
}
-#if defined(SCUMM_LITTLE_ENDIAN)
+/**
+ * A wrapper macro used around four character constants, like 'DATA', to
+ * ensure portability. Typical usage: MKID_BE('DATA').
+ *
+ * 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.
+ *
+ * Fortunately, a semi-standard has been established: On almost all systems
+ * and compilers, multi-byte character constants are encoded using the big
+ * endian convention (probably in analogy to the encoding of string constants).
+ * Still some systems differ. This is why we provide the MKID_BE macro. If
+ * you wrap your four character constants with it, the result will always be
+ * BE encoded, even on systems which differ from the default BE encoding.
+ *
+ * For the latter systems we provide the INVERSE_MKID override.
+ */
+#if defined(INVERSE_MKID)
+#define MKID_BE(a) ((uint32) \
+ (((a) >> 24) & 0x000000FF) | \
+ (((a) >> 8) & 0x0000FF00) | \
+ (((a) << 8) & 0x00FF0000) | \
+ (((a) << 24) & 0xFF000000))
+
+#else
+# define MKID_BE(a) ((uint32)(a))
+#endif
- #define PROTO_MKID(a) ((uint32) \
- (((a) >> 24) & 0x000000FF) | \
- (((a) >> 8) & 0x0000FF00) | \
- (((a) << 8) & 0x00FF0000) | \
- (((a) << 24) & 0xFF000000))
- #if defined(INVERSE_MKID)
- # define MKID(a) ((uint32)(a))
- # define MKID_BE(a) PROTO_MKID(a)
- #else
- # define MKID(a) PROTO_MKID(a)
- # define MKID_BE(a) ((uint32)(a))
- #endif
+
+#if defined(SCUMM_LITTLE_ENDIAN)
#define READ_UINT16(a) READ_LE_UINT16(a)
#define READ_UINT32(a) READ_LE_UINT32(a)
@@ -96,6 +120,7 @@ FORCEINLINE uint16 SWAP_BYTES_16(uint16 a) {
#error No endianness defined
+
#endif