Browse Source

Change SWAPxx into SDL's built-in SDL_SwapLExx.

louyihua 8 years ago
parent
commit
e5ac3699f1
13 changed files with 105 additions and 69 deletions
  1. 8 15
      common.h
  2. 1 1
      global.c
  3. 1 1
      main_PSP.h
  4. 2 2
      map.c
  5. 1 1
      mp3play.c
  6. 9 9
      palcommon.c
  7. 5 5
      rngplay.c
  8. 0 1
      sdlpal.vcxproj
  9. 57 20
      sound.c
  10. 7 0
      sound.h
  11. 2 2
      text.c
  12. 2 2
      uigame.c
  13. 10 10
      yj1.c

+ 8 - 15
common.h

@@ -66,14 +66,6 @@ extern "C"
 
 #endif
 
-#if SDL_BYTEORDER == SDL_LIL_ENDIAN
-#define SWAP16(X)    (X)
-#define SWAP32(X)    (X)
-#else
-#define SWAP16(X)    SDL_Swap16(X)
-#define SWAP32(X)    SDL_Swap32(X)
-#endif
-
 #ifndef max
 #define max(a, b)    (((a) > (b)) ? (a) : (b))
 #endif
@@ -139,12 +131,6 @@ FILE *MY_fopen(const char *path, const char *mode);
 #else
 #define PAL_HAS_SDLCD         0
 #endif
-#if !defined (CYGWIN) && !defined (DINGOO) && !defined (GPH) && !defined (GEKKO) && !defined (__WINPHONE__)
-#define PAL_HAS_MP3           1
-#endif
-#endif
-#define PAL_HAS_OGG           1
-#define PAL_HAS_MAME          1   /* Should not be enabled for now, until M.A.M.E goes open source licenses */
 
 #ifndef PAL_PREFIX
 #define PAL_PREFIX            "./"
@@ -155,8 +141,15 @@ FILE *MY_fopen(const char *path, const char *mode);
 
 #endif
 
+#if !defined (CYGWIN) && !defined (DINGOO) && !defined (GPH) && !defined (GEKKO) && !defined (__WINPHONE__)
+#define PAL_HAS_MP3           1
+#endif
+#endif
+#define PAL_HAS_OGG           1
+#define PAL_HAS_MAME          1   /* Should not be enabled for now, until M.A.M.E goes open source licenses */
+
 #ifndef SDL_INIT_CDROM
-#define SDL_INIT_CDROM        0
+#define SDL_INIT_CDROM        0	  /* Compatibility with SDL 1.2 */
 #endif
 
 #ifdef _WIN32

+ 1 - 1
global.c

@@ -35,7 +35,7 @@ extern BOOL g_fUseMidi;
       int i;                                                     \
       for (i = 0; i < (size) / 2; i++)                           \
       {                                                          \
-         ((LPWORD)(buf))[i] = SWAP16(((LPWORD)(buf))[i]);        \
+         ((LPWORD)(buf))[i] = SDL_SwapLE16(((LPWORD)(buf))[i]);  \
       }                                                          \
    } while(0)
 #endif

+ 1 - 1
main_PSP.h

@@ -63,7 +63,7 @@ int PSPSuspendCallback(int arg1, int pwrflags, void *common)
     gpGlobals->f.fpFIRE = UTIL_OpenRequiredFile("fire.mkf");
     gpGlobals->f.fpSSS = UTIL_OpenRequiredFile("sss.mkf");
     gpGlobals->lpObjectDesc = PAL_LoadObjectDesc(va("%s%s", PAL_PREFIX, "desc.dat"));
-    SOUND_ReloadVOC();
+    SOUND_Reload();
   }
   int cbid;
   cbid = sceKernelCreateCallback("suspend Callback", PSPSuspendCallback, NULL);

+ 2 - 2
map.c

@@ -119,8 +119,8 @@ PAL_LoadMap(
    {
       for (j = 0; j < 64; j++)
       {
-         map->Tiles[i][j][0] = SWAP32(map->Tiles[i][j][0]);
-         map->Tiles[i][j][1] = SWAP32(map->Tiles[i][j][1]);
+         map->Tiles[i][j][0] = SDL_SwapLE32(map->Tiles[i][j][0]);
+         map->Tiles[i][j][1] = SDL_SwapLE32(map->Tiles[i][j][1]);
       }
    }
 

+ 1 - 1
mp3play.c

@@ -156,4 +156,4 @@ MP3_Init(
 	}
 }
 
-#endif
+#endif

+ 9 - 9
palcommon.c

@@ -675,7 +675,7 @@ PAL_MKFGetChunkCount(
    fseek(fp, 0, SEEK_SET);
    fread(&iNumChunk, sizeof(INT), 1, fp);
 
-   iNumChunk = (SWAP32(iNumChunk) - 4) / 4;
+   iNumChunk = (SDL_SwapLE32(iNumChunk) - 4) / 4;
    return iNumChunk;
 }
 
@@ -721,8 +721,8 @@ PAL_MKFGetChunkSize(
    fseek(fp, 4 * uiChunkNum, SEEK_SET);
    fread(&uiOffset, sizeof(UINT), 1, fp);
    fread(&uiNextOffset, sizeof(UINT), 1, fp);
-   uiOffset = SWAP32(uiOffset);
-   uiNextOffset = SWAP32(uiNextOffset);
+   uiOffset = SDL_SwapLE32(uiOffset);
+   uiNextOffset = SDL_SwapLE32(uiNextOffset);
 
    //
    // Return the length of the chunk.
@@ -785,8 +785,8 @@ PAL_MKFReadChunk(
    fseek(fp, 4 * uiChunkNum, SEEK_SET);
    fread(&uiOffset, 4, 1, fp);
    fread(&uiNextOffset, 4, 1, fp);
-   uiOffset = SWAP32(uiOffset);
-   uiNextOffset = SWAP32(uiNextOffset);
+   uiOffset = SDL_SwapLE32(uiOffset);
+   uiNextOffset = SDL_SwapLE32(uiNextOffset);
 
    //
    // Get the length of the chunk.
@@ -857,7 +857,7 @@ PAL_MKFGetDecompressedSize(
    //
    fseek(fp, 4 * uiChunkNum, SEEK_SET);
    fread(&uiOffset, 4, 1, fp);
-   uiOffset = SWAP32(uiOffset);
+   uiOffset = SDL_SwapLE32(uiOffset);
 
    //
    // Read the header.
@@ -866,15 +866,15 @@ PAL_MKFGetDecompressedSize(
    if (gpGlobals->fIsWIN95)
    {
       fread(buf, sizeof(DWORD), 1, fp);
-      buf[0] = SWAP32(buf[0]);
+      buf[0] = SDL_SwapLE32(buf[0]);
 
       return (INT)buf[0];
    }
    else
    {
       fread(buf, sizeof(DWORD), 2, fp);
-      buf[0] = SWAP32(buf[0]);
-      buf[1] = SWAP32(buf[1]);
+      buf[0] = SDL_SwapLE32(buf[0]);
+      buf[1] = SDL_SwapLE32(buf[1]);
 
       return (buf[0] != 0x315f4a59) ? -1 : (INT)buf[1];
    }

+ 5 - 5
rngplay.c

@@ -83,8 +83,8 @@ PAL_RNGReadFrame(
    fseek(fpRngMKF, 4 * uiRngNum, SEEK_SET);
    fread(&uiOffset, sizeof(UINT), 1, fpRngMKF);
    fread(&uiNextOffset, sizeof(UINT), 1, fpRngMKF);
-   uiOffset = SWAP32(uiOffset);
-   uiNextOffset = SWAP32(uiNextOffset);
+   uiOffset = SDL_SwapLE32(uiOffset);
+   uiNextOffset = SDL_SwapLE32(uiNextOffset);
 
    //
    // Get the length of the chunk.
@@ -103,7 +103,7 @@ PAL_RNGReadFrame(
    // Get the number of sub chunks.
    //
    fread(&uiChunkCount, sizeof(UINT), 1, fpRngMKF);
-   uiChunkCount = (SWAP32(uiChunkCount) - 4) / 4;
+   uiChunkCount = (SDL_SwapLE32(uiChunkCount) - 4) / 4;
    if (uiFrameNum >= uiChunkCount)
    {
       return -1;
@@ -115,8 +115,8 @@ PAL_RNGReadFrame(
    fseek(fpRngMKF, uiOffset + 4 * uiFrameNum, SEEK_SET);
    fread(&uiSubOffset, sizeof(UINT), 1, fpRngMKF);
    fread(&uiNextOffset, sizeof(UINT), 1, fpRngMKF);
-   uiSubOffset = SWAP32(uiSubOffset);
-   uiNextOffset = SWAP32(uiNextOffset);
+   uiSubOffset = SDL_SwapLE32(uiSubOffset);
+   uiNextOffset = SDL_SwapLE32(uiNextOffset);
 
    //
    // Get the length of the sub chunk.

+ 0 - 1
sdlpal.vcxproj

@@ -53,7 +53,6 @@
       </HeaderFileName>
     </Midl>
     <ClCompile>
-      <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
       <AdditionalIncludeDirectories>..\SDL2-2.0.3\include;.\liboggvorbis\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>WIN32;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <StringPooling>true</StringPooling>

+ 57 - 20
sound.c

@@ -511,6 +511,51 @@ SOUND_FillAudio(
    SDL_mutexV(gSndPlayer.mtx);
 }
 
+static VOID
+SOUND_LoadMKF(
+	VOID
+	)
+/*++
+  Purpose:
+
+    Load MKF contents into memory.
+
+  Parameters:
+
+    None.
+
+  Return value:
+
+    None.
+
+--*/
+{
+	char *mkfs[2];
+	FNLoadSoundData func[2];
+	int i;
+
+	if (gpGlobals->fIsWIN95)
+	{
+		mkfs[0] = "sounds.mkf"; func[0] = SOUND_LoadWAVEData;
+		mkfs[1] = "voc.mkf"; func[1] = SOUND_LoadVOCData;
+	}
+	else
+	{
+		mkfs[0] = "voc.mkf"; func[0] = SOUND_LoadVOCData;
+		mkfs[1] = "sounds.mkf"; func[1] = SOUND_LoadWAVEData;
+	}
+
+	for (i = 0; i < 2; i++)
+	{
+		gSndPlayer.mkf = UTIL_OpenFile(mkfs[i]);
+		if (gSndPlayer.mkf)
+		{
+			gSndPlayer.LoadSoundData = func[i];
+			break;
+		}
+	}
+}
+
 INT
 SOUND_OpenAudio(
    VOID
@@ -548,26 +593,7 @@ SOUND_OpenAudio(
    //
    // Load the MKF file.
    //
-   if (gpGlobals->fIsWIN95)
-   {
-	   mkfs[0] = "sounds.mkf"; func[0] = SOUND_LoadWAVEData;
-	   mkfs[1] = "voc.mkf"; func[1] = SOUND_LoadVOCData;
-   }
-   else
-   {
-	   mkfs[0] = "voc.mkf"; func[0] = SOUND_LoadVOCData;
-	   mkfs[1] = "sounds.mkf"; func[1] = SOUND_LoadWAVEData;
-   }
-
-   for (i = 0; i < 2; i++)
-   {
-	   gSndPlayer.mkf = UTIL_OpenFile(mkfs[i]);
-	   if (gSndPlayer.mkf)
-	   {
-		   gSndPlayer.LoadSoundData = func[i];
-		   break;
-	   }
-   }
+   SOUND_LoadMKF();
    if (gSndPlayer.mkf == NULL)
    {
       return -2;
@@ -1049,3 +1075,14 @@ SOUND_PlayCDA(
 
    return ret;
 }
+
+#ifdef PSP
+void
+SOUND_Reload(
+	void
+	)
+{
+	fclose(gSndPlayer.mkf);
+	SOUND_LoadMKF();
+}
+#endif

+ 7 - 0
sound.h

@@ -73,6 +73,13 @@ SOUND_PlayCDA(
    INT    iNumTrack
 );
 
+#ifdef PSP
+VOID
+SOUND_Reload(
+	VOID
+);
+#endif
+
 #ifdef PAL_CLASSIC
 extern int g_iCurrChannel;
 #define SOUND_Play(i) SOUND_PlayChannel((i), (g_iCurrChannel ^= 1))

+ 2 - 2
text.c

@@ -194,7 +194,7 @@ PAL_InitText(
    // Split messages and do code page conversion here
    for (i = 0, wlen = 0; i < g_TextLib.nMsgs; i++)
    {
-	   wlen += PAL_MultiByteToWideChar(temp + SWAP32(offsets[i]), SWAP32(offsets[i + 1]) - SWAP32(offsets[i]), NULL, 0) + 1;
+	   wlen += PAL_MultiByteToWideChar(temp + SDL_SwapLE32(offsets[i]), SDL_SwapLE32(offsets[i + 1]) - SDL_SwapLE32(offsets[i]), NULL, 0) + 1;
    }
    g_TextLib.lpMsgBuf = (LPWSTR*)malloc(g_TextLib.nMsgs * sizeof(LPWSTR));
    tmp = (LPWSTR)malloc(wlen * sizeof(WCHAR));
@@ -202,7 +202,7 @@ PAL_InitText(
    {
 	   int l;
 	   g_TextLib.lpMsgBuf[i] = tmp + wpos;
-	   l = PAL_MultiByteToWideChar(temp + SWAP32(offsets[i]), SWAP32(offsets[i + 1]) - SWAP32(offsets[i]), g_TextLib.lpMsgBuf[i], wlen - wpos);
+	   l = PAL_MultiByteToWideChar(temp + SDL_SwapLE32(offsets[i]), SDL_SwapLE32(offsets[i + 1]) - SDL_SwapLE32(offsets[i]), g_TextLib.lpMsgBuf[i], wlen - wpos);
 	   g_TextLib.lpMsgBuf[i][l] = 0;
 	   wpos += l + 1;
    }

+ 2 - 2
uigame.c

@@ -198,7 +198,7 @@ PAL_SaveSlotMenu(
       else
       {
          fread(&wSavedTimes, sizeof(WORD), 1, fp);
-         wSavedTimes = SWAP16(wSavedTimes);
+         wSavedTimes = SDL_SwapLE16(wSavedTimes);
          fclose(fp);
       }
 
@@ -601,7 +601,7 @@ PAL_SystemMenu(
                WORD wSavedTimes;
                fread(&wSavedTimes, sizeof(WORD), 1, fp);
                fclose(fp);
-               wSavedTimes = SWAP16(wSavedTimes);
+               wSavedTimes = SDL_SwapLE16(wSavedTimes);
                if ((int)wSavedTimes > iSavedTimes)
                {
                   iSavedTimes = wSavedTimes;

+ 10 - 10
yj1.c

@@ -121,10 +121,10 @@ static unsigned short
 		if (yj1_get_bits(src, bitptr, 1))
 			return yj1_get_bits(src, bitptr, header->LZSSRepeatCodeLengthTable[temp - 1]);
 		else
-			return SWAP16(header->LZSSRepeatTable[temp]);
+			return SDL_SwapLE16(header->LZSSRepeatTable[temp]);
 	}
 	else
-		return SWAP16(header->LZSSRepeatTable[0]);
+		return SDL_SwapLE16(header->LZSSRepeatTable[0]);
 }
 
 INT
@@ -142,9 +142,9 @@ INT
 
 	if (Source == NULL)
 		return -1;
-	if (SWAP32(hdr->Signature) != 0x315f4a59)
+	if (SDL_SwapLE32(hdr->Signature) != 0x315f4a59)
 		return -1;
-	if (SWAP32(hdr->UncompressedLength) > (unsigned int)DestSize)
+	if (SDL_SwapLE32(hdr->UncompressedLength) > (unsigned int)DestSize)
 		return -1;
 
 	do
@@ -176,16 +176,16 @@ INT
 
 	dest = (unsigned char *)Destination;
 
-	for (i = 0; i < SWAP16(hdr->BlockCount); i++)
+	for (i = 0; i < SDL_SwapLE16(hdr->BlockCount); i++)
 	{
 		unsigned int bitptr;
 		PYJ_1_BLOCKHEADER header;
 
 		header = (PYJ_1_BLOCKHEADER)src;
 		src += 4;
-		if (!SWAP16(header->CompressedLength))
+		if (!SDL_SwapLE16(header->CompressedLength))
 		{
-			unsigned short hul = SWAP16(header->UncompressedLength);
+			unsigned short hul = SDL_SwapLE16(header->UncompressedLength);
 			while (hul--)
 			{
 				*dest++ = *src++;
@@ -229,11 +229,11 @@ INT
 				}
 			}
 		}
-		src = ((unsigned char *)header) + SWAP16(header->CompressedLength);
+		src = ((unsigned char *)header) + SDL_SwapLE16(header->CompressedLength);
 	}
 	free(root);
 
-	return SWAP32(hdr->UncompressedLength);
+	return SDL_SwapLE32(hdr->UncompressedLength);
 }
 
 /* ============================================================================================================================================= */
@@ -375,7 +375,7 @@ INT
 	if (!yj2_build_tree(&tree))
 		return -1;
 
-	Length = SWAP32(*((unsigned int*)Source));
+	Length = SDL_SwapLE32(*((unsigned int*)Source));
 	if (Length > DestSize)
 		return -1;
 	dest = (unsigned char*)Destination;