mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-21 19:45:10 +00:00
tools: make some stuff endianness-aware
This commit is contained in:
parent
2e03057182
commit
f02c1cab49
7 changed files with 34 additions and 14 deletions
|
@ -19,11 +19,19 @@ typedef unsigned int u32;
|
||||||
typedef unsigned long long u64;
|
typedef unsigned long long u64;
|
||||||
typedef float f32;
|
typedef float f32;
|
||||||
|
|
||||||
#define bswap16(x) __builtin_bswap16(x)
|
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||||
#define bswap32(x) __builtin_bswap32(x)
|
# define bswap16(x) (x)
|
||||||
#define BSWAP16(x) x = __builtin_bswap16(x)
|
# define bswap32(x) (x)
|
||||||
#define BSWAP32(x) x = __builtin_bswap32(x)
|
# define BSWAP16(x)
|
||||||
#define BSWAP16_MANY(x, n) for (s32 _i = 0; _i < n; _i++) BSWAP16((x)[_i])
|
# define BSWAP32(x)
|
||||||
|
# define BSWAP16_MANY(x, n)
|
||||||
|
#else
|
||||||
|
# define bswap16(x) __builtin_bswap16(x)
|
||||||
|
# define bswap32(x) __builtin_bswap32(x)
|
||||||
|
# define BSWAP16(x) x = __builtin_bswap16(x)
|
||||||
|
# define BSWAP32(x) x = __builtin_bswap32(x)
|
||||||
|
# define BSWAP16_MANY(x, n) for (s32 _i = 0; _i < n; _i++) BSWAP16((x)[_i])
|
||||||
|
#endif
|
||||||
|
|
||||||
#define NORETURN __attribute__((noreturn))
|
#define NORETURN __attribute__((noreturn))
|
||||||
#define UNUSED __attribute__((unused))
|
#define UNUSED __attribute__((unused))
|
||||||
|
|
|
@ -15,8 +15,13 @@ typedef int s32;
|
||||||
typedef unsigned char u8;
|
typedef unsigned char u8;
|
||||||
typedef unsigned int u32;
|
typedef unsigned int u32;
|
||||||
|
|
||||||
#define BSWAP16(x) x = __builtin_bswap16(x)
|
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||||
#define BSWAP32(x) x = __builtin_bswap32(x)
|
# define BSWAP16(x)
|
||||||
|
# define BSWAP32(x)
|
||||||
|
#else
|
||||||
|
# define BSWAP16(x) x = __builtin_bswap16(x)
|
||||||
|
# define BSWAP32(x) x = __builtin_bswap32(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define NORETURN __attribute__((noreturn))
|
#define NORETURN __attribute__((noreturn))
|
||||||
#define UNUSED __attribute__((unused))
|
#define UNUSED __attribute__((unused))
|
||||||
|
|
|
@ -4,7 +4,7 @@ libaudiofile.a: audiofile.o
|
||||||
ar rcs libaudiofile.a audiofile.o
|
ar rcs libaudiofile.a audiofile.o
|
||||||
|
|
||||||
audiofile.o: audiofile.cpp audiofile.h aupvlist.h
|
audiofile.o: audiofile.cpp audiofile.h aupvlist.h
|
||||||
$(CXX) -O2 -I. -c audiofile.cpp
|
$(CXX) -std=c++11 -O2 -I. -c audiofile.cpp
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f audiofile.o libaudiofile.a
|
rm -f audiofile.o libaudiofile.a
|
||||||
|
|
|
@ -5075,7 +5075,7 @@ bool ModuleState::fileModuleHandlesSeeking() const
|
||||||
|
|
||||||
status ModuleState::setup(AFfilehandle file, Track *track)
|
status ModuleState::setup(AFfilehandle file, Track *track)
|
||||||
{
|
{
|
||||||
AFframecount fframepos = llrint(track->nextvframe * track->f.sampleRate / track->v.sampleRate);
|
AFframecount fframepos = std::llrint((long double)track->nextvframe * track->f.sampleRate / track->v.sampleRate);
|
||||||
bool isReading = file->m_access == _AF_READ_ACCESS;
|
bool isReading = file->m_access == _AF_READ_ACCESS;
|
||||||
|
|
||||||
if (!track->v.isUncompressed())
|
if (!track->v.isUncompressed())
|
||||||
|
@ -5146,11 +5146,11 @@ status ModuleState::setup(AFfilehandle file, Track *track)
|
||||||
if (track->totalfframes == -1)
|
if (track->totalfframes == -1)
|
||||||
track->totalvframes = -1;
|
track->totalvframes = -1;
|
||||||
else
|
else
|
||||||
track->totalvframes = llrint(track->totalfframes *
|
track->totalvframes = std::llrint((long double)track->totalfframes *
|
||||||
(track->v.sampleRate / track->f.sampleRate));
|
(track->v.sampleRate / track->f.sampleRate));
|
||||||
|
|
||||||
track->nextfframe = fframepos;
|
track->nextfframe = fframepos;
|
||||||
track->nextvframe = llrint(fframepos * track->v.sampleRate / track->f.sampleRate);
|
track->nextvframe = std::llrint((long double)fframepos * track->v.sampleRate / track->f.sampleRate);
|
||||||
|
|
||||||
m_isDirty = false;
|
m_isDirty = false;
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,13 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define BSWAP32(x) ((((x) >> 24) & 0xff) | (((x) >> 8) & 0xff00) | (((x) << 8) & 0xff0000) | (((x) << 24) & 0xff000000U))
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||||
#define BSWAP16(x) ((((x) >> 8) & 0xff) | (((x) << 8) & 0xff00))
|
# define BSWAP32(x) ((((x) >> 24) & 0xff) | (((x) >> 8) & 0xff00) | (((x) << 8) & 0xff0000) | (((x) << 24) & 0xff000000U))
|
||||||
|
# define BSWAP16(x) ((((x) >> 8) & 0xff) | (((x) << 8) & 0xff00))
|
||||||
|
#else
|
||||||
|
# define BSWAP32(x) (x)
|
||||||
|
# define BSWAP16(x) (x)
|
||||||
|
#endif
|
||||||
|
|
||||||
const char* OUTPUT_FILE = "assets.json";
|
const char* OUTPUT_FILE = "assets.json";
|
||||||
const size_t CHUNK_SIZE = 16;
|
const size_t CHUNK_SIZE = 16;
|
||||||
|
|
|
@ -14,7 +14,7 @@ typedef unsigned long long u64;
|
||||||
typedef float f32;
|
typedef float f32;
|
||||||
typedef double f64;
|
typedef double f64;
|
||||||
|
|
||||||
#ifdef __sgi
|
#if defined(__sgi) || (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||||
# define BSWAP16(x)
|
# define BSWAP16(x)
|
||||||
# define BSWAP32(x)
|
# define BSWAP32(x)
|
||||||
# define BSWAP16_MANY(x, n)
|
# define BSWAP16_MANY(x, n)
|
||||||
|
|
|
@ -387,7 +387,9 @@ void combine_skybox(const char *input, const char *output) {
|
||||||
uint32_t table[W*H];
|
uint32_t table[W*H];
|
||||||
if (fread(table, sizeof(table), 1, file) != 1) goto fail;
|
if (fread(table, sizeof(table), 1, file) != 1) goto fail;
|
||||||
|
|
||||||
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||||
reverse_endian((unsigned char *) table, W*H*4);
|
reverse_endian((unsigned char *) table, W*H*4);
|
||||||
|
#endif
|
||||||
|
|
||||||
uint32_t base = table[0];
|
uint32_t base = table[0];
|
||||||
for (int i = 0; i < W*H; i++) {
|
for (int i = 0; i < W*H; i++) {
|
||||||
|
|
Loading…
Reference in a new issue