mirror of https://github.com/OpenTTD/OpenTTD
(svn r13552) -Codechange: use TTD_ENDIAN comparations instead of tests if TTD_[BIG/LITTLE]_ENDIAN is defined
parent
dedb0033b3
commit
9da745b381
|
@ -999,6 +999,10 @@
|
||||||
RelativePath=".\..\src\core\endian_func.hpp"
|
RelativePath=".\..\src\core\endian_func.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\core\endian_type.hpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\engine_base.h"
|
RelativePath=".\..\src\engine_base.h"
|
||||||
>
|
>
|
||||||
|
|
|
@ -996,6 +996,10 @@
|
||||||
RelativePath=".\..\src\core\endian_func.hpp"
|
RelativePath=".\..\src\core\endian_func.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\core\endian_type.hpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\engine_base.h"
|
RelativePath=".\..\src\engine_base.h"
|
||||||
>
|
>
|
||||||
|
|
|
@ -175,6 +175,7 @@ effectvehicle_func.h
|
||||||
effectvehicle_base.h
|
effectvehicle_base.h
|
||||||
elrail_func.h
|
elrail_func.h
|
||||||
core/endian_func.hpp
|
core/endian_func.hpp
|
||||||
|
core/endian_type.hpp
|
||||||
engine_base.h
|
engine_base.h
|
||||||
engine_func.h
|
engine_func.h
|
||||||
engine_gui.h
|
engine_gui.h
|
||||||
|
|
|
@ -5,26 +5,11 @@
|
||||||
#ifndef ENDIAN_FUNC_H
|
#ifndef ENDIAN_FUNC_H
|
||||||
#define ENDIAN_FUNC_H
|
#define ENDIAN_FUNC_H
|
||||||
|
|
||||||
|
#include "endian_type.hpp"
|
||||||
#include "bitmath_func.hpp"
|
#include "bitmath_func.hpp"
|
||||||
|
|
||||||
#if defined(ARM) || defined(__arm__) || defined(__alpha__)
|
|
||||||
#define OTTD_ALIGNMENT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Windows has always LITTLE_ENDIAN */
|
|
||||||
#if defined(WIN32) || defined(__OS2__) || defined(WIN64)
|
|
||||||
#define TTD_LITTLE_ENDIAN
|
|
||||||
#elif !defined(TESTING)
|
|
||||||
/* Else include endian[target/host].h, which has the endian-type, autodetected by the Makefile */
|
|
||||||
#if defined(STRGEN)
|
|
||||||
#include "endian_host.h"
|
|
||||||
#else
|
|
||||||
#include "endian_target.h"
|
|
||||||
#endif
|
|
||||||
#endif /* WIN32 || __OS2__ || WIN64 */
|
|
||||||
|
|
||||||
/* Setup alignment and conversion macros */
|
/* Setup alignment and conversion macros */
|
||||||
#if defined(TTD_BIG_ENDIAN)
|
#if TTD_ENDIAN == TTD_BIG_ENDIAN
|
||||||
#define FROM_BE16(x) (x)
|
#define FROM_BE16(x) (x)
|
||||||
#define FROM_BE32(x) (x)
|
#define FROM_BE32(x) (x)
|
||||||
#define TO_BE16(x) (x)
|
#define TO_BE16(x) (x)
|
||||||
|
@ -46,7 +31,7 @@
|
||||||
#define TO_LE16(x) (x)
|
#define TO_LE16(x) (x)
|
||||||
#define TO_LE32(x) (x)
|
#define TO_LE32(x) (x)
|
||||||
#define TO_LE32X(x) (x)
|
#define TO_LE32X(x) (x)
|
||||||
#endif /* TTD_BIG_ENDIAN */
|
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
|
||||||
|
|
||||||
static inline uint16 ReadLE16Aligned(const void *x)
|
static inline uint16 ReadLE16Aligned(const void *x)
|
||||||
{
|
{
|
||||||
|
@ -55,11 +40,11 @@ static inline uint16 ReadLE16Aligned(const void *x)
|
||||||
|
|
||||||
static inline uint16 ReadLE16Unaligned(const void *x)
|
static inline uint16 ReadLE16Unaligned(const void *x)
|
||||||
{
|
{
|
||||||
#ifdef OTTD_ALIGNMENT
|
#if OTTD_ALIGNMENT == 1
|
||||||
return ((const byte*)x)[0] | ((const byte*)x)[1] << 8;
|
return ((const byte*)x)[0] | ((const byte*)x)[1] << 8;
|
||||||
#else
|
#else
|
||||||
return FROM_LE16(*(const uint16*)x);
|
return FROM_LE16(*(const uint16*)x);
|
||||||
#endif
|
#endif /* OTTD_ALIGNMENT == 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* ENDIAN_FUNC_HPP */
|
#endif /* ENDIAN_FUNC_HPP */
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/** @file endian_type.hpp Definition of various endian-dependant macros. */
|
||||||
|
|
||||||
|
#ifndef ENDIAN_TYPE_H
|
||||||
|
#define ENDIAN_TYPE_H
|
||||||
|
|
||||||
|
#if defined(ARM) || defined(__arm__) || defined(__alpha__)
|
||||||
|
#define OTTD_ALIGNMENT 1
|
||||||
|
#else
|
||||||
|
#define OTTD_ALIGNMENT 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TTD_LITTLE_ENDIAN 0
|
||||||
|
#define TTD_BIG_ENDIAN 1
|
||||||
|
|
||||||
|
/* Windows has always LITTLE_ENDIAN */
|
||||||
|
#if defined(WIN32) || defined(__OS2__) || defined(WIN64)
|
||||||
|
#define TTD_ENDIAN TTD_LITTLE_ENDIAN
|
||||||
|
#elif !defined(TESTING)
|
||||||
|
/* Else include endian[target/host].h, which has the endian-type, autodetected by the Makefile */
|
||||||
|
#if defined(STRGEN)
|
||||||
|
#include "endian_host.h"
|
||||||
|
#else
|
||||||
|
#include "endian_target.h"
|
||||||
|
#endif
|
||||||
|
#endif /* WIN32 || __OS2__ || WIN64 */
|
||||||
|
|
||||||
|
#endif /* ENDIAN_TYPE_HPP */
|
|
@ -12,6 +12,21 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
/** Supported endian types */
|
||||||
|
enum Endian {
|
||||||
|
ENDIAN_LITTLE, ///< little endian
|
||||||
|
ENDIAN_BIG ///< big endian
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shortcut to printf("#define TTD_*_ENDIAN 0/1")
|
||||||
|
* @param endian endian type to define
|
||||||
|
*/
|
||||||
|
static inline void printf_endian(Endian endian)
|
||||||
|
{
|
||||||
|
printf("#define TTD_ENDIAN %s\n", endian == ENDIAN_LITTLE ? "TTD_LITTLE_ENDIAN" : "TTD_BIG_ENDIAN");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main call of the endian_check program
|
* Main call of the endian_check program
|
||||||
* @param argc argument count
|
* @param argc argument count
|
||||||
|
@ -30,23 +45,23 @@ int main (int argc, char *argv[])
|
||||||
printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n");
|
printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n");
|
||||||
|
|
||||||
if (force_LE == 1) {
|
if (force_LE == 1) {
|
||||||
printf("#define TTD_LITTLE_ENDIAN\n");
|
printf_endian(ENDIAN_LITTLE);
|
||||||
} else if (force_BE == 1) {
|
} else if (force_BE == 1) {
|
||||||
printf("#define TTD_BIG_ENDIAN\n");
|
printf_endian(ENDIAN_BIG);
|
||||||
} else if (force_PREPROCESSOR == 1) {
|
} else if (force_PREPROCESSOR == 1) {
|
||||||
/* Support for universal binaries on OSX
|
/* Support for universal binaries on OSX
|
||||||
* Universal binaries supports both PPC and x86
|
* Universal binaries supports both PPC and x86
|
||||||
* If a compiler for OSX gets this setting, it will always pick the correct endian and no test is needed
|
* If a compiler for OSX gets this setting, it will always pick the correct endian and no test is needed
|
||||||
*/
|
*/
|
||||||
printf("#ifdef __BIG_ENDIAN__\n");
|
printf("#ifdef __BIG_ENDIAN__\n");
|
||||||
printf("#define TTD_BIG_ENDIAN\n");
|
printf_endian(ENDIAN_BIG);
|
||||||
printf("#else\n");
|
printf("#else\n");
|
||||||
printf("#define TTD_LITTLE_ENDIAN\n");
|
printf_endian(ENDIAN_LITTLE);
|
||||||
printf("#endif\n");
|
printf("#endif\n");
|
||||||
} else if (*(short*)endian_test == 1 ) {
|
} else if (*(short*)endian_test == 1 ) {
|
||||||
printf("#define TTD_LITTLE_ENDIAN\n");
|
printf_endian(ENDIAN_LITTLE);
|
||||||
} else {
|
} else {
|
||||||
printf("#define TTD_BIG_ENDIAN\n");
|
printf_endian(ENDIAN_BIG);
|
||||||
}
|
}
|
||||||
printf("#endif\n");
|
printf("#endif\n");
|
||||||
|
|
||||||
|
|
|
@ -247,12 +247,12 @@ static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *user
|
||||||
sig_bit.gray = 8;
|
sig_bit.gray = 8;
|
||||||
png_set_sBIT(png_ptr, info_ptr, &sig_bit);
|
png_set_sBIT(png_ptr, info_ptr, &sig_bit);
|
||||||
|
|
||||||
#ifdef TTD_LITTLE_ENDIAN
|
#if TTD_ENDIAN == TTD_LITTLE_ENDIAN
|
||||||
png_set_bgr(png_ptr);
|
png_set_bgr(png_ptr);
|
||||||
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
|
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
|
||||||
#else
|
#else
|
||||||
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
||||||
#endif
|
#endif /* TTD_ENDIAN == TTD_LITTLE_ENDIAN */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* use by default 64k temp memory */
|
/* use by default 64k temp memory */
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "../debug.h"
|
#include "../debug.h"
|
||||||
#include "../driver.h"
|
#include "../driver.h"
|
||||||
#include "../mixer.h"
|
#include "../mixer.h"
|
||||||
#include "../core/endian_func.hpp"
|
#include "../core/endian_type.hpp"
|
||||||
|
|
||||||
#include "cocoa_s.h"
|
#include "cocoa_s.h"
|
||||||
|
|
||||||
|
@ -61,9 +61,9 @@ const char *SoundDriver_Cocoa::Start(const char * const *parm)
|
||||||
requestedDesc.mBitsPerChannel = 16;
|
requestedDesc.mBitsPerChannel = 16;
|
||||||
requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
|
requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
|
||||||
|
|
||||||
#ifdef TTD_BIG_ENDIAN
|
#if TTD_ENDIAN == TTD_BIG_ENDIAN
|
||||||
requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
|
requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
|
||||||
#endif
|
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
|
||||||
|
|
||||||
requestedDesc.mFramesPerPacket = 1;
|
requestedDesc.mFramesPerPacket = 1;
|
||||||
requestedDesc.mBytesPerFrame = requestedDesc.mBitsPerChannel * requestedDesc.mChannelsPerFrame / 8;
|
requestedDesc.mBytesPerFrame = requestedDesc.mBitsPerChannel * requestedDesc.mChannelsPerFrame / 8;
|
||||||
|
|
|
@ -1251,11 +1251,11 @@ bool ReadLanguagePack(int lang_index)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(TTD_BIG_ENDIAN)
|
#if TTD_ENDIAN == TTD_BIG_ENDIAN
|
||||||
for (i = 0; i != 32; i++) {
|
for (i = 0; i != 32; i++) {
|
||||||
lang_pack->offsets[i] = ReadLE16Aligned(&lang_pack->offsets[i]);
|
lang_pack->offsets[i] = ReadLE16Aligned(&lang_pack->offsets[i]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
|
||||||
|
|
||||||
tot_count = 0;
|
tot_count = 0;
|
||||||
for (i = 0; i != 32; i++) {
|
for (i = 0; i != 32; i++) {
|
||||||
|
|
Loading…
Reference in New Issue