From: notaz Date: Sun, 9 Jul 2023 15:57:54 +0000 (+0300) Subject: Merge pull request #292 from pcercuei/dfsound-big-endian X-Git-Tag: r24~262 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=commitdiff_plain;h=4d66d894c6563cbfb78fe8ccc0b374809fc44b0d;hp=5fa6cb1729bd2bc6c1d9d0d04c4acd611675518f Merge pull request #292 from pcercuei/dfsound-big-endian dfsound: Fix issues on big-endian systems --- diff --git a/plugins/dfsound/registers.c b/plugins/dfsound/registers.c index 2f577494..adc9c3a5 100644 --- a/plugins/dfsound/registers.c +++ b/plugins/dfsound/registers.c @@ -22,6 +22,7 @@ #include "externals.h" #include "registers.h" #include "spu_config.h" +#include "spu.h" static void SoundOn(int start,int end,unsigned short val); static void SoundOff(int start,int end,unsigned short val); @@ -127,7 +128,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val, break; //-------------------------------------------------// case H_SPUdata: - *(unsigned short *)(spu.spuMemC + spu.spuAddr) = val; + *(unsigned short *)(spu.spuMemC + spu.spuAddr) = HTOLE16(val); spu.spuAddr += 2; spu.spuAddr &= 0x7fffe; break; @@ -336,7 +337,7 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg) case H_SPUdata: { - unsigned short s = *(unsigned short *)(spu.spuMemC + spu.spuAddr); + unsigned short s = LE16TOH(*(unsigned short *)(spu.spuMemC + spu.spuAddr)); spu.spuAddr += 2; spu.spuAddr &= 0x7fffe; return s; diff --git a/plugins/dfsound/reverb.c b/plugins/dfsound/reverb.c index ec570fb3..de9b804a 100644 --- a/plugins/dfsound/reverb.c +++ b/plugins/dfsound/reverb.c @@ -20,6 +20,7 @@ ***************************************************************************/ #include "stdafx.h" +#include "spu.h" #define _IN_REVERB @@ -50,16 +51,16 @@ INLINE int rvb2ram_offs(int curr, int space, int iOff) // get_buffer content helper: takes care about wraps #define g_buffer(var) \ - ((int)(signed short)spu.spuMem[rvb2ram_offs(curr_addr, space, rvb->var)]) + ((int)(signed short)LE16TOH(spu.spuMem[rvb2ram_offs(curr_addr, space, rvb->var)])) // saturate iVal and store it as var #define s_buffer(var, iVal) \ ssat32_to_16(iVal); \ - spu.spuMem[rvb2ram_offs(curr_addr, space, rvb->var)] = iVal + spu.spuMem[rvb2ram_offs(curr_addr, space, rvb->var)] = HTOLE16(iVal) #define s_buffer1(var, iVal) \ ssat32_to_16(iVal); \ - spu.spuMem[rvb2ram_offs(curr_addr, space, rvb->var + 1)] = iVal + spu.spuMem[rvb2ram_offs(curr_addr, space, rvb->var + 1)] = HTOLE16(iVal) //////////////////////////////////////////////////////////////////////// diff --git a/plugins/dfsound/spu.h b/plugins/dfsound/spu.h index 0cef6520..334c6809 100644 --- a/plugins/dfsound/spu.h +++ b/plugins/dfsound/spu.h @@ -18,6 +18,14 @@ #ifndef __P_SPU_H__ #define __P_SPU_H__ +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define HTOLE16(x) __builtin_bswap16(x) +#define LE16TOH(x) __builtin_bswap16(x) +#else +#define HTOLE16(x) (x) +#define LE16TOH(x) (x) +#endif + void ClearWorkingState(void); void CALLBACK SPUplayADPCMchannel(xa_decode_t *xap, unsigned int cycle, int is_start); int CALLBACK SPUplayCDDAchannel(short *pcm, int bytes, unsigned int cycle, int is_start); diff --git a/plugins/dfsound/xa.c b/plugins/dfsound/xa.c index c7a84fd0..397ed592 100644 --- a/plugins/dfsound/xa.c +++ b/plugins/dfsound/xa.c @@ -16,6 +16,7 @@ ***************************************************************************/ #include "stdafx.h" +#include "spu.h" #define _IN_XA #include @@ -60,8 +61,8 @@ INLINE void MixXA(int *SSumLR, int ns_to, int decode_pos) SSumLR[ns++] += l; SSumLR[ns++] += r; - spu.spuMem[cursor] = v; - spu.spuMem[cursor + 0x400/2] = v >> 16; + spu.spuMem[cursor] = HTOLE16(v); + spu.spuMem[cursor + 0x400/2] = HTOLE16(v >> 16); cursor = (cursor + 1) & 0x1ff; } spu.XALastVal = v; @@ -80,8 +81,8 @@ INLINE void MixXA(int *SSumLR, int ns_to, int decode_pos) SSumLR[ns++] += l; SSumLR[ns++] += r; - spu.spuMem[cursor] = v; - spu.spuMem[cursor + 0x400/2] = v >> 16; + spu.spuMem[cursor] = HTOLE16(v); + spu.spuMem[cursor + 0x400/2] = HTOLE16(v >> 16); cursor = (cursor + 1) & 0x1ff; } spu.XALastVal = v;