changeset 397:b523312b6b0d trunk

[svn] Fix endian issues on ppc32.
author hansmi
date Sat, 23 Dec 2006 14:46:28 -0800
parents d3071c7bb046
children 7e4e672de0dc
files ChangeLog src/modplug/load_psm.cxx
diffstat 2 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Dec 22 15:34:37 2006 -0800
+++ b/ChangeLog	Sat Dec 23 14:46:28 2006 -0800
@@ -1,3 +1,10 @@
+2006-12-22 23:34:37 +0000  Tony Vroon <chainsaw@gentoo.org>
+  revision [868]
+  Portability fix for PPC64 (64-bit userland).
+  trunk/src/modplug/stdafx.h |    4 ++--
+  1 file changed, 2 insertions(+), 2 deletions(-)
+
+
 2006-12-22 02:23:33 +0000  William Pitcock <nenolod@nenolod.net>
   revision [866]
   - oh wait, yaz fixed this already
--- a/src/modplug/load_psm.cxx	Fri Dec 22 15:34:37 2006 -0800
+++ b/src/modplug/load_psm.cxx	Sat Dec 23 14:46:28 2006 -0800
@@ -85,6 +85,10 @@
 	BYTE samplemap[MAX_SAMPLES];
 	UINT nPatterns;
 
+	pfh->id = bswapLE32(pfh->id);
+	pfh->len = bswapLE32(pfh->len);
+	pfh->listid = bswapLE32(pfh->listid);
+
 	// Chunk0: "PSM ",filesize,"FILE"
 	if (dwMemLength < 256) return FALSE;
 	if (pfh->id == PSM_ID_OLD)
@@ -109,6 +113,11 @@
 	while (dwMemPos+8 < dwMemLength)
 	{
 		PSMCHUNK *pchunk = (PSMCHUNK *)(lpStream+dwMemPos);
+
+		pchunk->id = bswapLE32(pchunk->id);
+		pchunk->len = bswapLE32(pchunk->len);
+		pchunk->listid = bswapLE32(pchunk->listid);
+
 		if ((pchunk->len >= dwMemLength - 8) || (dwMemPos + pchunk->len + 8 > dwMemLength)) break;
 		dwMemPos += 8;
 		PUCHAR pdata = (PUCHAR)(lpStream+dwMemPos);
@@ -142,6 +151,13 @@
 				m_nSamples++;
 				MODINSTRUMENT *pins = &Ins[m_nSamples];
 				PSMSAMPLE *psmp = (PSMSAMPLE *)pdata;
+
+				psmp->smpid = bswapLE32(psmp->smpid);
+				psmp->length = bswapLE32(psmp->length);
+				psmp->loopstart = bswapLE32(psmp->loopstart); 
+				psmp->loopend = bswapLE32(psmp->loopend);
+				psmp->samplerate = bswapLE32(psmp->samplerate);
+
 				smpnames[m_nSamples] = psmp->smpid;
 				memcpy(m_szNames[m_nSamples], psmp->samplename, 31);
 				m_szNames[m_nSamples][31] = 0;
@@ -193,6 +209,11 @@
 		while (dwMemPos + 8 < dwSongEnd)
 		{
 			PSMCHUNK *pchunk = (PSMCHUNK *)(lpStream+dwMemPos);
+
+			pchunk->id = bswapLE32(pchunk->id);
+			pchunk->len = bswapLE32(pchunk->len);
+			pchunk->listid = bswapLE32(pchunk->listid);
+
 			dwMemPos += 8;
 			if ((pchunk->len > dwSongEnd) || (dwMemPos + pchunk->len > dwSongEnd)) break;
 			PUCHAR pdata = (PUCHAR)(lpStream+dwMemPos);
@@ -251,6 +272,11 @@
 	for (UINT nPat=0; nPat<nPatterns; nPat++)
 	{
 		PSMPATTERN *pPsmPat = (PSMPATTERN *)(lpStream+patptrs[nPat]+8);
+
+		pPsmPat->size = bswapLE32(pPsmPat->size);
+		pPsmPat->name = bswapLE32(pPsmPat->name);
+		pPsmPat->rows = bswapLE16(pPsmPat->rows);
+
 		ULONG len = *(DWORD *)(lpStream+patptrs[nPat]+4) - 12;
 		UINT nRows = pPsmPat->rows;
 		if (len > pPsmPat->size) len = pPsmPat->size;