diff --git a/global.h b/global.h index 26c3e2c07..0e1c4969f 100644 --- a/global.h +++ b/global.h @@ -360,4 +360,28 @@ extern DLL_EXPORT CLogger<5> tlog5; //gray - minor log info throw; \ } + +#if defined(linux) && defined(sparc) +/* SPARC does not support unaligned memory access. Let gcc know when + * to emit the right code. */ +struct unaligned_Uint16 { ui16 val __attribute__(( packed )); }; +struct unaligned_Uint32 { ui32 val __attribute__(( packed )); }; + +static inline ui16 read_unaligned_u16(const void *p) +{ + const struct unaligned_Uint16 *v = (const struct unaligned_Uint16 *)p; + return v->val; +} + +static inline ui32 read_unaligned_u32(const void *p) +{ + const struct unaligned_Uint32 *v = (const struct unaligned_Uint32 *)p; + return v->val; +} + +#else +#define read_unaligned_u16(p) (* reinterpret_cast(p)) +#define read_unaligned_u32(p) (* reinterpret_cast(p)) +#endif + #endif // __GLOBAL_H__ diff --git a/hch/CDefHandler.cpp b/hch/CDefHandler.cpp index dc062e4d7..f8e6fd8c4 100644 --- a/hch/CDefHandler.cpp +++ b/hch/CDefHandler.cpp @@ -97,7 +97,7 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name) SDefEntryBlock &block = * reinterpret_cast(p); unsigned int totalInBlock; - totalInBlock = SDL_SwapLE32(block.totalInBlock); + totalInBlock = SDL_SwapLE32(read_unaligned_u32(&block.totalInBlock)); for (unsigned int j=SEntries.size(); j(p)); - p += 4; + SEntries[totalEntries+j].offset = SDL_SwapLE32(read_unaligned_u32(p)); + p += 4; } //totalEntries+=totalInBlock; for(unsigned int hh=0; hh0) ftcp += LeftMargin; @@ -283,7 +283,8 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const unsigned char * FDef, co case 2: { - BaseOffset = BaseOffsetor + *reinterpret_cast( FDef + BaseOffsetor ); //was + RWEntries[0]; + BaseOffset = BaseOffsetor + SDL_SwapLE16(read_unaligned_u16(FDef + BaseOffsetor)); + for (unsigned int i=0;i0) ftcp += LeftMargin;