VOGONS


First post, by MasterShadrack

User metadata
Rank Newbie
Rank
Newbie

I was looking into using my G5 to run old games. By looking at the source code, I noticed that Endianess is handled with bit-shifting operations. However, the PowerPC architecture, from the beginning, supported Endian correction instructions. I changed "include/mem.h" to handle this particular case. I tought that an DosBox developper could integrate it into the product. Here my little modifications:

#ifdef WORDS_BIGENDIAN

INLINE Bit8u host_readb(HostPt off) {
return off[0];
};
INLINE Bit16u host_readw(HostPt off) {
#if defined(__ppc__) && defined(__GNUC__)
unsigned long result;
__asm__ volatile ("lhbrx %0, 0, %1"
/* outputs: */ : "=r" (result)
/* inputs: */ : "r" (off)
/* clobbers: */ : "memory");
return result;
#else
return off[0] | (off[1] << 8);
#endif
};
INLINE Bit32u host_readd(HostPt off) {
#if defined(__ppc__) && defined(__GNUC__)
unsigned long result;
__asm__ volatile ("lwbrx %0, 0, %1"
/* outputs: */ : "=r" (result)
/* inputs: */ : "r" (off)
/* clobbers: */ : "memory");
return result;
#else
return off[0] | (off[1] << 8) | (off[2] << 16) | (off[3] << 24);
#endif
};
INLINE void host_writeb(HostPt off,Bit8u val) {
off[0]=val;
};
INLINE void host_writew(HostPt off,Bit16u val) {
#if defined(__ppc__) && defined(__GNUC__)
__asm__ ("sthbrx %0, 0, %1" :
/* inputs: */ : "r" (val),
"r" (off)
/* clobbers: */ : "memory");
#else
off[0]=(Bit8u)(val);
off[1]=(Bit8u)(val >> 8);
#endif
};
INLINE void host_writed(HostPt off,Bit32u val) {
#if defined(__ppc__) && defined(__GNUC__)
__asm__ ("stwbrx %0, 0, %1" :
/* inputs: */ : "r" (val),
"r" (off)
/* clobbers: */ : "memory");
#else
off[0]=(Bit8u)(val);
off[1]=(Bit8u)(val >> 8);
off[2]=(Bit8u)(val >> 16);
off[3]=(Bit8u)(val >> 24);
#endif
};

#define MLEB(_MLE_VAL_) (_MLE_VAL_)

INLINE Bit16u MLEW(Bit16u val) {
Show last 29 lines
#if defined(__ppc__) && defined(__GNUC__)
unsigned long result;
__asm__ volatile ("lhbrx %0, 0, %1"
/* outputs: */ : "=r" (result)
/* inputs: */ : "r" (&val)
/* clobbers: */ : "memory");
return result;
#else
return (_MLE_VAL_ >> 8) | (_MLE_VAL_ << 8);
#endif
};

INLINE Bit32u MLED(Bit32u val) {
#if defined(__ppc__) && defined(__GNUC__)
unsigned long result;
__asm__ volatile ("lwbrx %0, 0, %1"
/* outputs: */ : "=r" (result)
/* inputs: */ : "r" (&val)
/* clobbers: */ : "memory");
return result;
#else
return ((_MLE_VAL_ >> 24)|((_MLE_VAL_ >> 8)&0xFF00)|((_MLE_VAL_ << 8)&0xFF0000)|((_MLE_VAL_ << 24)&0xFF000000));
#endif
};

#else
// Little-Endian empty translators
#endif

I played my old KQ3 games with those modification without any noticable bug. Hope that help.