Browse Source

SDL 1.2.15 compatibility

EC2 Default User 9 years ago
parent
commit
d6035000dc
28 changed files with 13679 additions and 13660 deletions
  1. 1473 1469
      battle.c
  2. 239 239
      battle.h
  3. 1 1
      common.h
  4. 431 419
      ending.c
  5. 56 56
      ending.h
  6. 4973 4973
      fight.c
  7. 108 108
      fight.h
  8. 0 11
      input.c
  9. 433 433
      magicmenu.c
  10. 52 52
      magicmenu.h
  11. 635 626
      main.c
  12. 123 123
      midi.c
  13. 49 49
      midi.h
  14. 3 3
      private.c
  15. 430 430
      res.c
  16. 80 80
      res.h
  17. 878 878
      scene.c
  18. 67 67
      scene.h
  19. 48 48
      script.h
  20. 9 9
      sdlpal.cproj
  21. 735 735
      sound.c
  22. 87 87
      sound.h
  23. 4 0
      ui.c
  24. 1778 1778
      uibattle.c
  25. 153 153
      uibattle.h
  26. 573 573
      util.c
  27. 1 0
      video.c
  28. 260 260
      yj1.c

File diff suppressed because it is too large
+ 1473 - 1469
battle.c


+ 239 - 239
battle.h

@@ -1,239 +1,239 @@
-/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
-//
-// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
-// All rights reserved.
-//
-// This file is part of SDLPAL.
-//
-// SDLPAL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef BATTLE_H
-#define BATTLE_H
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include "global.h"
-#include "uibattle.h"
-
-#define       BATTLE_FPS               25
-#define       BATTLE_FRAME_TIME        (1000 / BATTLE_FPS)
-
-typedef enum tagBATTLERESULT
-{
-   kBattleResultWon        = 3,      // player won the battle
-   kBattleResultLost       = 1,      // player lost the battle
-   kBattleResultFleed      = 0xFFFF, // player fleed from the battle
-   kBattleResultTerminated = 0,      // battle terminated with scripts
-   kBattleResultOnGoing    = 1000,   // the battle is ongoing
-   kBattleResultPreBattle  = 1001,   // running pre-battle scripts
-   kBattleResultPause      = 1002,   // battle pause
-} BATTLERESULT;
-
-typedef enum tagFIGHTERSTATE
-{
-   kFighterWait,  // waiting time
-   kFighterCom,   // accepting command
-   kFighterAct,   // doing the actual move
-} FIGHTERSTATE;
-
-typedef enum tagBATTLEACTIONTYPE
-{
-   kBattleActionPass,          // do nothing
-   kBattleActionDefend,        // defend
-   kBattleActionAttack,        // physical attack
-   kBattleActionMagic,         // use magic
-   kBattleActionCoopMagic,     // use cooperative magic
-   kBattleActionFlee,          // flee from the battle
-   kBattleActionThrowItem,     // throw item onto enemy
-   kBattleActionUseItem,       // use item
-   kBattleActionAttackMate,    // attack teammate (confused only)
-} BATTLEACTIONTYPE;
-
-typedef struct tagBATTLEACTION
-{
-   BATTLEACTIONTYPE   ActionType;
-   WORD               wActionID;   // item/magic to use
-   SHORT              sTarget;     // -1 for everyone
-   FLOAT              flRemainingTime;  // remaining waiting time before the action start
-} BATTLEACTION;
-
-typedef struct tagBATTLEENEMY
-{
-   WORD               wObjectID;              // Object ID of this enemy
-   ENEMY              e;                      // detailed data of this enemy
-   WORD               rgwStatus[kStatusAll];  // status effects
-   FLOAT              flTimeMeter;            // time-charging meter (0 = empty, 100 = full).
-   POISONSTATUS       rgPoisons[MAX_POISONS]; // poisons
-   LPSPRITE           lpSprite;
-   PAL_POS            pos;                    // current position on the screen
-   PAL_POS            posOriginal;            // original position on the screen
-   WORD               wCurrentFrame;          // current frame number
-   FIGHTERSTATE       state;                  // state of this enemy
-
-   BOOL               fTurnStart;
-   BOOL               fFirstMoveDone;
-   BOOL               fDualMove;
-
-   WORD               wScriptOnTurnStart;
-   WORD               wScriptOnBattleEnd;
-   WORD               wScriptOnReady;
-
-   WORD               wPrevHP;              // HP value prior to action
-
-   INT                iColorShift;
-} BATTLEENEMY;
-
-// We only put some data used in battle here; other data can be accessed in the global data.
-typedef struct tagBATTLEPLAYER
-{
-   INT                iColorShift;
-   FLOAT              flTimeMeter;          // time-charging meter (0 = empty, 100 = full).
-   FLOAT              flTimeSpeedModifier;
-   WORD               wHidingTime;          // remaining hiding time
-   LPSPRITE           lpSprite;
-   PAL_POS            pos;                  // current position on the screen
-   PAL_POS            posOriginal;          // original position on the screen
-   WORD               wCurrentFrame;        // current frame number
-   FIGHTERSTATE       state;                // state of this player
-   BATTLEACTION       action;               // action to perform
-   BOOL               fDefending;           // TRUE if player is defending
-   WORD               wPrevHP;              // HP value prior to action
-   WORD               wPrevMP;              // MP value prior to action
-#ifndef PAL_CLASSIC
-   SHORT              sTurnOrder;           // turn order
-#endif
-} BATTLEPLAYER;
-
-typedef struct tagSUMMON
-{
-   LPSPRITE           lpSprite;
-   WORD               wCurrentFrame;
-} SUMMON;
-
-#define MAX_BATTLE_ACTIONS    256
-#define MAX_KILLED_ENEMIES    256
-
-#ifdef PAL_CLASSIC
-
-typedef enum tabBATTLEPHASE
-{
-   kBattlePhaseSelectAction,
-   kBattlePhasePerformAction
-} BATTLEPHASE;
-
-typedef struct tagACTIONQUEUE
-{
-   BOOL       fIsEnemy;
-   WORD       wDexterity;
-   WORD       wIndex;
-} ACTIONQUEUE;
-
-#define MAX_ACTIONQUEUE_ITEMS (MAX_PLAYERS_IN_PARTY + MAX_ENEMIES_IN_TEAM * 2)
-
-#endif
-
-typedef struct tagBATTLE
-{
-   BATTLEPLAYER     rgPlayer[MAX_PLAYERS_IN_PARTY];
-   BATTLEENEMY      rgEnemy[MAX_ENEMIES_IN_TEAM];
-
-   WORD             wMaxEnemyIndex;
-
-   SDL_Surface     *lpSceneBuf;
-   SDL_Surface     *lpBackground;
-
-   SHORT            sBackgroundColorShift;
-
-   LPSPRITE         lpSummonSprite;       // sprite of summoned god
-   PAL_POS          posSummon;
-   INT              iSummonFrame;         // current frame of the summoned god
-
-   INT              iExpGained;           // total experience value gained
-   INT              iCashGained;          // total cash gained
-
-   BOOL             fIsBoss;              // TRUE if boss fight
-   BOOL             fEnemyCleared;        // TRUE if enemies are cleared
-   BATTLERESULT     BattleResult;
-
-   FLOAT            flTimeChargingUnit;   // the base waiting time unit
-
-   BATTLEUI         UI;
-
-   LPBYTE           lpEffectSprite;
-
-   BOOL             fEnemyMoving;         // TRUE if enemy is moving
-
-   INT              iHidingTime;          // Time of hiding
-
-   WORD             wMovingPlayerIndex;   // current moving player index
-
-   int              iBlow;
-
-#ifdef PAL_CLASSIC
-   BATTLEPHASE      Phase;
-   ACTIONQUEUE      ActionQueue[MAX_ACTIONQUEUE_ITEMS];
-   int              iCurAction;
-   BOOL             fRepeat;              // TRUE if player pressed Repeat
-   BOOL             fForce;               // TRUE if player pressed Force
-   BOOL             fFlee;                // TRUE if player pressed Flee
-#endif
-} BATTLE;
-
-extern BATTLE g_Battle;
-
-VOID
-PAL_LoadBattleSprites(
-   VOID
-);
-
-VOID
-PAL_BattleMakeScene(
-   VOID
-);
-
-VOID
-PAL_BattleBackupScene(
-   VOID
-);
-
-VOID
-PAL_BattleFadeScene(
-   VOID
-);
-
-VOID
-PAL_BattleEnemyEscape(
-   VOID
-);
-
-VOID
-PAL_BattlePlayerEscape(
-   VOID
-);
-
-BATTLERESULT
-PAL_StartBattle(
-   WORD        wEnemyTeam,
-   BOOL        fIsBoss
-);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef BATTLE_H
+#define BATTLE_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "global.h"
+#include "uibattle.h"
+
+#define       BATTLE_FPS               25
+#define       BATTLE_FRAME_TIME        (1000 / BATTLE_FPS)
+
+typedef enum tagBATTLERESULT
+{
+   kBattleResultWon        = 3,      // player won the battle
+   kBattleResultLost       = 1,      // player lost the battle
+   kBattleResultFleed      = 0xFFFF, // player fleed from the battle
+   kBattleResultTerminated = 0,      // battle terminated with scripts
+   kBattleResultOnGoing    = 1000,   // the battle is ongoing
+   kBattleResultPreBattle  = 1001,   // running pre-battle scripts
+   kBattleResultPause      = 1002,   // battle pause
+} BATTLERESULT;
+
+typedef enum tagFIGHTERSTATE
+{
+   kFighterWait,  // waiting time
+   kFighterCom,   // accepting command
+   kFighterAct,   // doing the actual move
+} FIGHTERSTATE;
+
+typedef enum tagBATTLEACTIONTYPE
+{
+   kBattleActionPass,          // do nothing
+   kBattleActionDefend,        // defend
+   kBattleActionAttack,        // physical attack
+   kBattleActionMagic,         // use magic
+   kBattleActionCoopMagic,     // use cooperative magic
+   kBattleActionFlee,          // flee from the battle
+   kBattleActionThrowItem,     // throw item onto enemy
+   kBattleActionUseItem,       // use item
+   kBattleActionAttackMate,    // attack teammate (confused only)
+} BATTLEACTIONTYPE;
+
+typedef struct tagBATTLEACTION
+{
+   BATTLEACTIONTYPE   ActionType;
+   WORD               wActionID;   // item/magic to use
+   SHORT              sTarget;     // -1 for everyone
+   FLOAT              flRemainingTime;  // remaining waiting time before the action start
+} BATTLEACTION;
+
+typedef struct tagBATTLEENEMY
+{
+   WORD               wObjectID;              // Object ID of this enemy
+   ENEMY              e;                      // detailed data of this enemy
+   WORD               rgwStatus[kStatusAll];  // status effects
+   FLOAT              flTimeMeter;            // time-charging meter (0 = empty, 100 = full).
+   POISONSTATUS       rgPoisons[MAX_POISONS]; // poisons
+   LPSPRITE           lpSprite;
+   PAL_POS            pos;                    // current position on the screen
+   PAL_POS            posOriginal;            // original position on the screen
+   WORD               wCurrentFrame;          // current frame number
+   FIGHTERSTATE       state;                  // state of this enemy
+
+   BOOL               fTurnStart;
+   BOOL               fFirstMoveDone;
+   BOOL               fDualMove;
+
+   WORD               wScriptOnTurnStart;
+   WORD               wScriptOnBattleEnd;
+   WORD               wScriptOnReady;
+
+   WORD               wPrevHP;              // HP value prior to action
+
+   INT                iColorShift;
+} BATTLEENEMY;
+
+// We only put some data used in battle here; other data can be accessed in the global data.
+typedef struct tagBATTLEPLAYER
+{
+   INT                iColorShift;
+   FLOAT              flTimeMeter;          // time-charging meter (0 = empty, 100 = full).
+   FLOAT              flTimeSpeedModifier;
+   WORD               wHidingTime;          // remaining hiding time
+   LPSPRITE           lpSprite;
+   PAL_POS            pos;                  // current position on the screen
+   PAL_POS            posOriginal;          // original position on the screen
+   WORD               wCurrentFrame;        // current frame number
+   FIGHTERSTATE       state;                // state of this player
+   BATTLEACTION       action;               // action to perform
+   BOOL               fDefending;           // TRUE if player is defending
+   WORD               wPrevHP;              // HP value prior to action
+   WORD               wPrevMP;              // MP value prior to action
+#ifndef PAL_CLASSIC
+   SHORT              sTurnOrder;           // turn order
+#endif
+} BATTLEPLAYER;
+
+typedef struct tagSUMMON
+{
+   LPSPRITE           lpSprite;
+   WORD               wCurrentFrame;
+} SUMMON;
+
+#define MAX_BATTLE_ACTIONS    256
+#define MAX_KILLED_ENEMIES    256
+
+#ifdef PAL_CLASSIC
+
+typedef enum tabBATTLEPHASE
+{
+   kBattlePhaseSelectAction,
+   kBattlePhasePerformAction
+} BATTLEPHASE;
+
+typedef struct tagACTIONQUEUE
+{
+   BOOL       fIsEnemy;
+   WORD       wDexterity;
+   WORD       wIndex;
+} ACTIONQUEUE;
+
+#define MAX_ACTIONQUEUE_ITEMS (MAX_PLAYERS_IN_PARTY + MAX_ENEMIES_IN_TEAM * 2)
+
+#endif
+
+typedef struct tagBATTLE
+{
+   BATTLEPLAYER     rgPlayer[MAX_PLAYERS_IN_PARTY];
+   BATTLEENEMY      rgEnemy[MAX_ENEMIES_IN_TEAM];
+
+   WORD             wMaxEnemyIndex;
+
+   SDL_Surface     *lpSceneBuf;
+   SDL_Surface     *lpBackground;
+
+   SHORT            sBackgroundColorShift;
+
+   LPSPRITE         lpSummonSprite;       // sprite of summoned god
+   PAL_POS          posSummon;
+   INT              iSummonFrame;         // current frame of the summoned god
+
+   INT              iExpGained;           // total experience value gained
+   INT              iCashGained;          // total cash gained
+
+   BOOL             fIsBoss;              // TRUE if boss fight
+   BOOL             fEnemyCleared;        // TRUE if enemies are cleared
+   BATTLERESULT     BattleResult;
+
+   FLOAT            flTimeChargingUnit;   // the base waiting time unit
+
+   BATTLEUI         UI;
+
+   LPBYTE           lpEffectSprite;
+
+   BOOL             fEnemyMoving;         // TRUE if enemy is moving
+
+   INT              iHidingTime;          // Time of hiding
+
+   WORD             wMovingPlayerIndex;   // current moving player index
+
+   int              iBlow;
+
+#ifdef PAL_CLASSIC
+   BATTLEPHASE      Phase;
+   ACTIONQUEUE      ActionQueue[MAX_ACTIONQUEUE_ITEMS];
+   int              iCurAction;
+   BOOL             fRepeat;              // TRUE if player pressed Repeat
+   BOOL             fForce;               // TRUE if player pressed Force
+   BOOL             fFlee;                // TRUE if player pressed Flee
+#endif
+} BATTLE;
+
+extern BATTLE g_Battle;
+
+VOID
+PAL_LoadBattleSprites(
+   VOID
+);
+
+VOID
+PAL_BattleMakeScene(
+   VOID
+);
+
+VOID
+PAL_BattleBackupScene(
+   VOID
+);
+
+VOID
+PAL_BattleFadeScene(
+   VOID
+);
+
+VOID
+PAL_BattleEnemyEscape(
+   VOID
+);
+
+VOID
+PAL_BattlePlayerEscape(
+   VOID
+);
+
+BATTLERESULT
+PAL_StartBattle(
+   WORD        wEnemyTeam,
+   BOOL        fIsBoss
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 1 - 1
common.h

@@ -123,7 +123,7 @@ extern "C"
 #ifdef __cplusplus
 #include <cstdio>
 #endif
-
+
 FILE *MY_fopen(const char *path, const char *mode);
 #define fopen MY_fopen
 

+ 431 - 419
ending.c

@@ -1,419 +1,431 @@
-/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
-//
-// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
-// All rights reserved.
-//
-// This file is part of SDLPAL.
-//
-// SDLPAL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#include "main.h"
-
-static WORD g_wCurEffectSprite = 0;
-
-VOID
-PAL_EndingSetEffectSprite(
-   WORD         wSpriteNum
-)
-/*++
-  Purpose:
-
-    Set the effect sprite of the ending.
-
-  Parameters:
-
-    [IN]  wSpriteNum - the number of the sprite.
-
-  Return value:
-
-    None.
-
---*/
-{
-   g_wCurEffectSprite = wSpriteNum;
-}
-
-VOID
-PAL_ShowFBP(
-   WORD         wChunkNum,
-   WORD         wFade
-)
-/*++
-  Purpose:
-
-    Draw an FBP picture to the screen.
-
-  Parameters:
-
-    [IN]  wChunkNum - number of chunk in fbp.mkf file.
-
-    [IN]  wFade - fading speed of showing the picture.
-
-  Return value:
-
-    None.
-
---*/
-{
-   PAL_LARGE BYTE            buf[320 * 200];
-   PAL_LARGE BYTE            bufSprite[320 * 200];
-   const int                 rgIndex[6] = {0, 3, 1, 5, 2, 4};
-   SDL_Surface              *p;
-   int                       i, j, k;
-   BYTE                      a, b;
-
-   if (PAL_MKFDecompressChunk(buf, 320 * 200, wChunkNum, gpGlobals->f.fpFBP) <= 0)
-   {
-      memset(buf, 0, sizeof(buf));
-   }
-
-   if (g_wCurEffectSprite != 0)
-   {
-      PAL_MKFDecompressChunk(bufSprite, 320 * 200, g_wCurEffectSprite, gpGlobals->f.fpMGO);
-   }
-
-   if (wFade)
-   {
-      wFade++;
-      wFade *= 10;
-
-      p = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
-         gpScreen->format->Rmask, gpScreen->format->Gmask,
-         gpScreen->format->Bmask, gpScreen->format->Amask);
-#if SDL_VERSION_ATLEAST(2, 0, 0)
-      SDL_SetSurfacePalette(p, gpScreen->format->palette);
-#endif
-      PAL_FBPBlitToSurface(buf, p);
-      VIDEO_BackupScreen();
-
-      for (i = 0; i < 16; i++)
-      {
-         for (j = 0; j < 6; j++)
-         {
-            //
-            // Blend the pixels in the 2 buffers, and put the result into the
-            // backup buffer
-            //
-            for (k = rgIndex[j]; k < gpScreen->pitch * gpScreen->h; k += 6)
-            {
-               a = ((LPBYTE)(p->pixels))[k];
-               b = ((LPBYTE)(gpScreenBak->pixels))[k];
-
-               if (i > 0)
-               {
-                  if ((a & 0x0F) > (b & 0x0F))
-                  {
-                     b++;
-                  }
-                  else if ((a & 0x0F) < (b & 0x0F))
-                  {
-                     b--;
-                  }
-               }
-
-               ((LPBYTE)(gpScreenBak->pixels))[k] = ((a & 0xF0) | (b & 0x0F));
-            }
-
-            SDL_BlitSurface(gpScreenBak, NULL, gpScreen, NULL);
-
-            if (g_wCurEffectSprite != 0)
-            {
-               int f = SDL_GetTicks() / 150;
-               PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufSprite, f % PAL_SpriteGetNumFrames(bufSprite)),
-                  gpScreen, PAL_XY(0, 0));
-            }
-
-            VIDEO_UpdateScreen(NULL);
-            UTIL_Delay(wFade);
-         }
-      }
-
-      SDL_FreeSurface(p);
-   }
-
-   //
-   // HACKHACK: to make the ending show correctly
-   //
-   if (wChunkNum != 49)
-   {
-      PAL_FBPBlitToSurface(buf, gpScreen);
-   }
-
-   VIDEO_UpdateScreen(NULL);
-}
-
-VOID
-PAL_ScrollFBP(
-   WORD         wChunkNum,
-   WORD         wScrollSpeed,
-   BOOL         fScrollDown
-)
-/*++
-  Purpose:
-
-    Scroll up an FBP picture to the screen.
-
-  Parameters:
-
-    [IN]  wChunkNum - number of chunk in fbp.mkf file.
-
-    [IN]  wScrollSpeed - scrolling speed of showing the picture.
-
-    [IN]  fScrollDown - TRUE if scroll down, FALSE if scroll up.
-
-  Return value:
-
-    None.
-
---*/
-{
-   SDL_Surface          *p;
-   PAL_LARGE BYTE        buf[320 * 200];
-   PAL_LARGE BYTE        bufSprite[320 * 200];
-   int                   i, l;
-   SDL_Rect              rect, dstrect;
-
-   if (PAL_MKFDecompressChunk(buf, 320 * 200, wChunkNum, gpGlobals->f.fpFBP) <= 0)
-   {
-      return;
-   }
-
-   if (g_wCurEffectSprite != 0)
-   {
-      PAL_MKFDecompressChunk(bufSprite, 320 * 200, g_wCurEffectSprite, gpGlobals->f.fpMGO);
-   }
-
-   p = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
-      gpScreen->format->Rmask, gpScreen->format->Gmask,
-      gpScreen->format->Bmask, gpScreen->format->Amask);
-
-   if (p == NULL)
-   {
-      return;
-   }
-
-#if SDL_VERSION_ATLEAST(2, 0, 0)
-   SDL_SetSurfacePalette(p, gpScreen->format->palette);
-#endif
-
-   VIDEO_BackupScreen();
-   PAL_FBPBlitToSurface(buf, p);
-
-   if (wScrollSpeed == 0)
-   {
-      wScrollSpeed = 1;
-   }
-
-   rect.x = 0;
-   rect.w = 320;
-   dstrect.x = 0;
-   dstrect.w = 320;
-
-   for (l = 0; l < 220; l++)
-   {
-      i = l;
-      if (i > 200)
-      {
-         i = 200;
-      }
-
-      if (fScrollDown)
-      {
-         rect.y = 0;
-         dstrect.y = i;
-         rect.h = 200 - i;
-         dstrect.h = 200 - i;
-      }
-      else
-      {
-         rect.y = i;
-         dstrect.y = 0;
-         rect.h = 200 - i;
-         dstrect.h = 200 - i;
-      }
-
-      SDL_BlitSurface(gpScreenBak, &rect, gpScreen, &dstrect);
-
-      if (fScrollDown)
-      {
-         rect.y = 200 - i;
-         dstrect.y = 0;
-         rect.h = i;
-         dstrect.h = i;
-      }
-      else
-      {
-         rect.y = 0;
-         dstrect.y = 200 - i;
-         rect.h = i;
-         dstrect.h = i;
-      }
-
-      SDL_BlitSurface(p, &rect, gpScreen, &dstrect);
-
-      PAL_ApplyWave(gpScreen);
-
-      if (g_wCurEffectSprite != 0)
-      {
-         int f = SDL_GetTicks() / 150;
-         PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufSprite, f % PAL_SpriteGetNumFrames(bufSprite)),
-            gpScreen, PAL_XY(0, 0));
-      }
-
-      VIDEO_UpdateScreen(NULL);
-
-      if (gpGlobals->fNeedToFadeIn)
-      {
-         PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
-         gpGlobals->fNeedToFadeIn = FALSE;
-#if SDL_VERSION_ATLEAST(2, 0, 0)
-         SDL_SetSurfacePalette(p, gpScreen->format->palette);
-#endif
-      }
-
-      UTIL_Delay(800 / wScrollSpeed);
-   }
-
-   SDL_BlitSurface(p, NULL, gpScreen, NULL);
-   SDL_FreeSurface(p);
-   VIDEO_UpdateScreen(NULL);
-}
-
-VOID
-PAL_EndingAnimation(
-   VOID
-)
-/*++
-  Purpose:
-
-    Show the ending animation.
-
-  Parameters:
-
-    None.
-
-  Return value:
-
-    None.
-
---*/
-{
-   LPBYTE            buf;
-   LPBYTE            bufGirl;
-   SDL_Surface      *pUpper;
-   SDL_Surface      *pLower;
-   SDL_Rect          srcrect, dstrect;
-
-   int               yPosGirl = 180;
-   int               i;
-
-   buf = (LPBYTE)UTIL_calloc(1, 64000);
-   bufGirl = (LPBYTE)UTIL_calloc(1, 6000);
-
-   pUpper = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
-      gpScreen->format->Rmask, gpScreen->format->Gmask,
-      gpScreen->format->Bmask, gpScreen->format->Amask);
-
-   pLower = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
-      gpScreen->format->Rmask, gpScreen->format->Gmask,
-      gpScreen->format->Bmask, gpScreen->format->Amask);
-
-#if SDL_VERSION_ATLEAST(2, 0, 0)
-   SDL_SetSurfacePalette(pUpper, gpScreen->format->palette);
-   SDL_SetSurfacePalette(pLower, gpScreen->format->palette);
-#endif
-
-   PAL_MKFDecompressChunk(buf, 64000, 61, gpGlobals->f.fpFBP);
-   PAL_FBPBlitToSurface(buf, pUpper);
-
-   PAL_MKFDecompressChunk(buf, 64000, 62, gpGlobals->f.fpFBP);
-   PAL_FBPBlitToSurface(buf, pLower);
-
-   PAL_MKFDecompressChunk(buf, 64000, 571, gpGlobals->f.fpMGO);
-   PAL_MKFDecompressChunk(bufGirl, 6000, 572, gpGlobals->f.fpMGO);
-
-   srcrect.x = 0;
-   dstrect.x = 0;
-   srcrect.w = 320;
-   dstrect.w = 320;
-
-   gpGlobals->wScreenWave = 2;
-
-   for (i = 0; i < 400; i++)
-   {
-      //
-      // Draw the background
-      //
-      srcrect.y = 0;
-      srcrect.h = 200 - i / 2;
-
-      dstrect.y = i / 2;
-      dstrect.h = 200 - i / 2;
-
-      SDL_BlitSurface(pLower, &srcrect, gpScreen, &dstrect);
-
-      srcrect.y = 200 - i / 2;
-      srcrect.h = i / 2;
-
-      dstrect.y = 0;
-      dstrect.h = i / 2;
-
-      SDL_BlitSurface(pUpper, &srcrect, gpScreen, &dstrect);
-
-      PAL_ApplyWave(gpScreen);
-
-      //
-      // Draw the beast
-      //
-      PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 0), gpScreen, PAL_XY(0, -400 + i));
-      PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 1), gpScreen, PAL_XY(0, -200 + i));
-
-      //
-      // Draw the girl
-      //
-      yPosGirl -= i & 1;
-      if (yPosGirl < 80)
-      {
-         yPosGirl = 80;
-      }
-
-      PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufGirl, (SDL_GetTicks() / 50) % 4),
-         gpScreen, PAL_XY(220, yPosGirl));
-
-      //
-      // Update the screen
-      //
-      VIDEO_UpdateScreen(NULL);
-      if (gpGlobals->fNeedToFadeIn)
-      {
-         PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
-         gpGlobals->fNeedToFadeIn = FALSE;
-#if SDL_VERSION_ATLEAST(2, 0, 0)
-         SDL_SetSurfacePalette(pUpper, gpScreen->format->palette);
-         SDL_SetSurfacePalette(pLower, gpScreen->format->palette);
-#endif
-      }
-
-      UTIL_Delay(50);
-   }
-
-   gpGlobals->wScreenWave = 0;
-
-   SDL_FreeSurface(pUpper);
-   SDL_FreeSurface(pLower);
-
-   free(buf);
-   free(bufGirl);
-}
+/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include "main.h"
+
+static WORD g_wCurEffectSprite = 0;
+
+VOID
+PAL_EndingSetEffectSprite(
+   WORD         wSpriteNum
+)
+/*++
+  Purpose:
+
+    Set the effect sprite of the ending.
+
+  Parameters:
+
+    [IN]  wSpriteNum - the number of the sprite.
+
+  Return value:
+
+    None.
+
+--*/
+{
+   g_wCurEffectSprite = wSpriteNum;
+}
+
+VOID
+PAL_ShowFBP(
+   WORD         wChunkNum,
+   WORD         wFade
+)
+/*++
+  Purpose:
+
+    Draw an FBP picture to the screen.
+
+  Parameters:
+
+    [IN]  wChunkNum - number of chunk in fbp.mkf file.
+
+    [IN]  wFade - fading speed of showing the picture.
+
+  Return value:
+
+    None.
+
+--*/
+{
+   PAL_LARGE BYTE            buf[320 * 200];
+   PAL_LARGE BYTE            bufSprite[320 * 200];
+   const int                 rgIndex[6] = {0, 3, 1, 5, 2, 4};
+   SDL_Surface              *p;
+   int                       i, j, k;
+   BYTE                      a, b;
+
+   if (PAL_MKFDecompressChunk(buf, 320 * 200, wChunkNum, gpGlobals->f.fpFBP) <= 0)
+   {
+      memset(buf, 0, sizeof(buf));
+   }
+
+   if (g_wCurEffectSprite != 0)
+   {
+      PAL_MKFDecompressChunk(bufSprite, 320 * 200, g_wCurEffectSprite, gpGlobals->f.fpMGO);
+   }
+
+   if (wFade)
+   {
+      wFade++;
+      wFade *= 10;
+
+      p = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
+         gpScreen->format->Rmask, gpScreen->format->Gmask,
+         gpScreen->format->Bmask, gpScreen->format->Amask);
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+      SDL_SetSurfacePalette(p, gpScreen->format->palette);
+#else
+      SDL_SetPalette(p, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
+#endif
+      PAL_FBPBlitToSurface(buf, p);
+      VIDEO_BackupScreen();
+
+      for (i = 0; i < 16; i++)
+      {
+         for (j = 0; j < 6; j++)
+         {
+            //
+            // Blend the pixels in the 2 buffers, and put the result into the
+            // backup buffer
+            //
+            for (k = rgIndex[j]; k < gpScreen->pitch * gpScreen->h; k += 6)
+            {
+               a = ((LPBYTE)(p->pixels))[k];
+               b = ((LPBYTE)(gpScreenBak->pixels))[k];
+
+               if (i > 0)
+               {
+                  if ((a & 0x0F) > (b & 0x0F))
+                  {
+                     b++;
+                  }
+                  else if ((a & 0x0F) < (b & 0x0F))
+                  {
+                     b--;
+                  }
+               }
+
+               ((LPBYTE)(gpScreenBak->pixels))[k] = ((a & 0xF0) | (b & 0x0F));
+            }
+
+            SDL_BlitSurface(gpScreenBak, NULL, gpScreen, NULL);
+
+            if (g_wCurEffectSprite != 0)
+            {
+               int f = SDL_GetTicks() / 150;
+               PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufSprite, f % PAL_SpriteGetNumFrames(bufSprite)),
+                  gpScreen, PAL_XY(0, 0));
+            }
+
+            VIDEO_UpdateScreen(NULL);
+            UTIL_Delay(wFade);
+         }
+      }
+
+      SDL_FreeSurface(p);
+   }
+
+   //
+   // HACKHACK: to make the ending show correctly
+   //
+   if (wChunkNum != 49)
+   {
+      PAL_FBPBlitToSurface(buf, gpScreen);
+   }
+
+   VIDEO_UpdateScreen(NULL);
+}
+
+VOID
+PAL_ScrollFBP(
+   WORD         wChunkNum,
+   WORD         wScrollSpeed,
+   BOOL         fScrollDown
+)
+/*++
+  Purpose:
+
+    Scroll up an FBP picture to the screen.
+
+  Parameters:
+
+    [IN]  wChunkNum - number of chunk in fbp.mkf file.
+
+    [IN]  wScrollSpeed - scrolling speed of showing the picture.
+
+    [IN]  fScrollDown - TRUE if scroll down, FALSE if scroll up.
+
+  Return value:
+
+    None.
+
+--*/
+{
+   SDL_Surface          *p;
+   PAL_LARGE BYTE        buf[320 * 200];
+   PAL_LARGE BYTE        bufSprite[320 * 200];
+   int                   i, l;
+   SDL_Rect              rect, dstrect;
+
+   if (PAL_MKFDecompressChunk(buf, 320 * 200, wChunkNum, gpGlobals->f.fpFBP) <= 0)
+   {
+      return;
+   }
+
+   if (g_wCurEffectSprite != 0)
+   {
+      PAL_MKFDecompressChunk(bufSprite, 320 * 200, g_wCurEffectSprite, gpGlobals->f.fpMGO);
+   }
+
+   p = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
+      gpScreen->format->Rmask, gpScreen->format->Gmask,
+      gpScreen->format->Bmask, gpScreen->format->Amask);
+
+   if (p == NULL)
+   {
+      return;
+   }
+
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+   SDL_SetSurfacePalette(p, gpScreen->format->palette);
+#else
+   SDL_SetPalette(p, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
+#endif
+
+   VIDEO_BackupScreen();
+   PAL_FBPBlitToSurface(buf, p);
+
+   if (wScrollSpeed == 0)
+   {
+      wScrollSpeed = 1;
+   }
+
+   rect.x = 0;
+   rect.w = 320;
+   dstrect.x = 0;
+   dstrect.w = 320;
+
+   for (l = 0; l < 220; l++)
+   {
+      i = l;
+      if (i > 200)
+      {
+         i = 200;
+      }
+
+      if (fScrollDown)
+      {
+         rect.y = 0;
+         dstrect.y = i;
+         rect.h = 200 - i;
+         dstrect.h = 200 - i;
+      }
+      else
+      {
+         rect.y = i;
+         dstrect.y = 0;
+         rect.h = 200 - i;
+         dstrect.h = 200 - i;
+      }
+
+      SDL_BlitSurface(gpScreenBak, &rect, gpScreen, &dstrect);
+
+      if (fScrollDown)
+      {
+         rect.y = 200 - i;
+         dstrect.y = 0;
+         rect.h = i;
+         dstrect.h = i;
+      }
+      else
+      {
+         rect.y = 0;
+         dstrect.y = 200 - i;
+         rect.h = i;
+         dstrect.h = i;
+      }
+
+      SDL_BlitSurface(p, &rect, gpScreen, &dstrect);
+
+      PAL_ApplyWave(gpScreen);
+
+      if (g_wCurEffectSprite != 0)
+      {
+         int f = SDL_GetTicks() / 150;
+         PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufSprite, f % PAL_SpriteGetNumFrames(bufSprite)),
+            gpScreen, PAL_XY(0, 0));
+      }
+
+      VIDEO_UpdateScreen(NULL);
+
+      if (gpGlobals->fNeedToFadeIn)
+      {
+         PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
+         gpGlobals->fNeedToFadeIn = FALSE;
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+         SDL_SetSurfacePalette(p, gpScreen->format->palette);
+#else
+         SDL_SetPalette(p, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
+#endif
+      }
+
+      UTIL_Delay(800 / wScrollSpeed);
+   }
+
+   SDL_BlitSurface(p, NULL, gpScreen, NULL);
+   SDL_FreeSurface(p);
+   VIDEO_UpdateScreen(NULL);
+}
+
+VOID
+PAL_EndingAnimation(
+   VOID
+)
+/*++
+  Purpose:
+
+    Show the ending animation.
+
+  Parameters:
+
+    None.
+
+  Return value:
+
+    None.
+
+--*/
+{
+   LPBYTE            buf;
+   LPBYTE            bufGirl;
+   SDL_Surface      *pUpper;
+   SDL_Surface      *pLower;
+   SDL_Rect          srcrect, dstrect;
+
+   int               yPosGirl = 180;
+   int               i;
+
+   buf = (LPBYTE)UTIL_calloc(1, 64000);
+   bufGirl = (LPBYTE)UTIL_calloc(1, 6000);
+
+   pUpper = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
+      gpScreen->format->Rmask, gpScreen->format->Gmask,
+      gpScreen->format->Bmask, gpScreen->format->Amask);
+
+   pLower = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
+      gpScreen->format->Rmask, gpScreen->format->Gmask,
+      gpScreen->format->Bmask, gpScreen->format->Amask);
+
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+   SDL_SetSurfacePalette(pUpper, gpScreen->format->palette);
+   SDL_SetSurfacePalette(pLower, gpScreen->format->palette);
+#else
+   SDL_SetPalette(pUpper, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
+   SDL_SetPalette(pLower, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
+#endif
+
+   PAL_MKFDecompressChunk(buf, 64000, 61, gpGlobals->f.fpFBP);
+   PAL_FBPBlitToSurface(buf, pUpper);
+
+   PAL_MKFDecompressChunk(buf, 64000, 62, gpGlobals->f.fpFBP);
+   PAL_FBPBlitToSurface(buf, pLower);
+
+   PAL_MKFDecompressChunk(buf, 64000, 571, gpGlobals->f.fpMGO);
+   PAL_MKFDecompressChunk(bufGirl, 6000, 572, gpGlobals->f.fpMGO);
+
+   srcrect.x = 0;
+   dstrect.x = 0;
+   srcrect.w = 320;
+   dstrect.w = 320;
+
+   gpGlobals->wScreenWave = 2;
+
+   for (i = 0; i < 400; i++)
+   {
+      //
+      // Draw the background
+      //
+      srcrect.y = 0;
+      srcrect.h = 200 - i / 2;
+
+      dstrect.y = i / 2;
+      dstrect.h = 200 - i / 2;
+
+      SDL_BlitSurface(pLower, &srcrect, gpScreen, &dstrect);
+
+      srcrect.y = 200 - i / 2;
+      srcrect.h = i / 2;
+
+      dstrect.y = 0;
+      dstrect.h = i / 2;
+
+      SDL_BlitSurface(pUpper, &srcrect, gpScreen, &dstrect);
+
+      PAL_ApplyWave(gpScreen);
+
+      //
+      // Draw the beast
+      //
+      PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 0), gpScreen, PAL_XY(0, -400 + i));
+      PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 1), gpScreen, PAL_XY(0, -200 + i));
+
+      //
+      // Draw the girl
+      //
+      yPosGirl -= i & 1;
+      if (yPosGirl < 80)
+      {
+         yPosGirl = 80;
+      }
+
+      PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufGirl, (SDL_GetTicks() / 50) % 4),
+         gpScreen, PAL_XY(220, yPosGirl));
+
+      //
+      // Update the screen
+      //
+      VIDEO_UpdateScreen(NULL);
+      if (gpGlobals->fNeedToFadeIn)
+      {
+         PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
+         gpGlobals->fNeedToFadeIn = FALSE;
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+         SDL_SetSurfacePalette(pUpper, gpScreen->format->palette);
+         SDL_SetSurfacePalette(pLower, gpScreen->format->palette);
+#else
+         SDL_SetSurfacePalette(pUpper, SDL_LOGPAL | SDL_PHYSPAL, VIDEO_GetPalette(), 0, 256);
+         SDL_SetSurfacePalette(pLower, SDL_LOGPAL | SDL_PHYSPAL, VIDEO_GetPalette(), 0, 256);
+#endif
+      }
+
+      UTIL_Delay(50);
+   }
+
+   gpGlobals->wScreenWave = 0;
+
+   SDL_FreeSurface(pUpper);
+   SDL_FreeSurface(pLower);
+
+   free(buf);
+   free(bufGirl);
+}

+ 56 - 56
ending.h

@@ -1,56 +1,56 @@
-/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
-//
-// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
-// All rights reserved.
-//
-// This file is part of SDLPAL.
-//
-// SDLPAL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef ENDGAME_H
-#define ENDGAME_H
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-VOID
-PAL_EndingSetEffectSprite(
-   WORD         wSpriteNum
-);
-
-VOID
-PAL_ShowFBP(
-   WORD         wChunkNum,
-   WORD         wFade
-);
-
-VOID
-PAL_ScrollFBP(
-   WORD         wChunkNum,
-   WORD         wScrollSpeed,
-   BOOL         fScrollDown
-);
-
-VOID
-PAL_EndingAnimation(
-   VOID
-);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
+/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef ENDGAME_H
+#define ENDGAME_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+VOID
+PAL_EndingSetEffectSprite(
+   WORD         wSpriteNum
+);
+
+VOID
+PAL_ShowFBP(
+   WORD         wChunkNum,
+   WORD         wFade
+);
+
+VOID
+PAL_ScrollFBP(
+   WORD         wChunkNum,
+   WORD         wScrollSpeed,
+   BOOL         fScrollDown
+);
+
+VOID
+PAL_EndingAnimation(
+   VOID
+);
+
+#ifdef __cplusplus
+}
+#endif
+#endif

File diff suppressed because it is too large
+ 4973 - 4973
fight.c


+ 108 - 108
fight.h

@@ -1,108 +1,108 @@
-/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
-//
-// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
-// All rights reserved.
-//
-// This file is part of SDLPAL.
-//
-// SDLPAL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef FIGHT_H
-#define FIGHT_H
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-INT
-PAL_BattleSelectAutoTarget(
-   VOID
-);
-
-#ifndef PAL_CLASSIC
-
-VOID
-PAL_UpdateTimeChargingUnit(
-   VOID
-);
-
-FLOAT
-PAL_GetTimeChargingSpeed(
-   WORD           wDexterity
-);
-
-#endif
-
-VOID
-PAL_BattleUpdateFighters(
-   VOID
-);
-
-VOID
-PAL_BattlePlayerCheckReady(
-   VOID
-);
-
-VOID
-PAL_BattleStartFrame(
-   VOID
-);
-
-VOID
-PAL_BattleCommitAction(
-   BOOL         fRepeat
-);
-
-VOID
-PAL_BattlePlayerPerformAction(
-   WORD         wPlayerIndex
-);
-
-VOID
-PAL_BattleEnemyPerformAction(
-   WORD         wEnemyIndex
-);
-
-VOID
-PAL_BattleShowPlayerPreMagicAnim(
-   WORD         wPlayerIndex,
-   BOOL         fSummon
-);
-
-VOID
-PAL_BattleDelay(
-   WORD       wDuration,
-   WORD       wObjectID,
-   BOOL       fUpdateGesture
-);
-
-VOID
-PAL_BattleStealFromEnemy(
-   WORD           wTarget,
-   WORD           wStealRate
-);
-
-VOID
-PAL_BattleSimulateMagic(
-   SHORT      sTarget,
-   WORD       wMagicObjectID,
-   WORD       wBaseDamage
-);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
+/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef FIGHT_H
+#define FIGHT_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+INT
+PAL_BattleSelectAutoTarget(
+   VOID
+);
+
+#ifndef PAL_CLASSIC
+
+VOID
+PAL_UpdateTimeChargingUnit(
+   VOID
+);
+
+FLOAT
+PAL_GetTimeChargingSpeed(
+   WORD           wDexterity
+);
+
+#endif
+
+VOID
+PAL_BattleUpdateFighters(
+   VOID
+);
+
+VOID
+PAL_BattlePlayerCheckReady(
+   VOID
+);
+
+VOID
+PAL_BattleStartFrame(
+   VOID
+);
+
+VOID
+PAL_BattleCommitAction(
+   BOOL         fRepeat
+);
+
+VOID
+PAL_BattlePlayerPerformAction(
+   WORD         wPlayerIndex
+);
+
+VOID
+PAL_BattleEnemyPerformAction(
+   WORD         wEnemyIndex
+);
+
+VOID
+PAL_BattleShowPlayerPreMagicAnim(
+   WORD         wPlayerIndex,
+   BOOL         fSummon
+);
+
+VOID
+PAL_BattleDelay(
+   WORD       wDuration,
+   WORD       wObjectID,
+   BOOL       fUpdateGesture
+);
+
+VOID
+PAL_BattleStealFromEnemy(
+   WORD           wTarget,
+   WORD           wStealRate
+);
+
+VOID
+PAL_BattleSimulateMagic(
+   SHORT      sTarget,
+   WORD       wMagicObjectID,
+   WORD       wBaseDamage
+);
+
+#ifdef __cplusplus
+}
+#endif
+#endif

+ 0 - 11
input.c

@@ -993,9 +993,6 @@ PAL_InitInput(
    memset((void *)&g_InputState, 0, sizeof(g_InputState));
    g_InputState.dir = kDirUnknown;
    g_InputState.prevdir = kDirUnknown;
-#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION <= 2
-   SDL_SetEventFilter(PAL_EventFilter);
-#endif
 
    //
    // Check for joystick
@@ -1093,11 +1090,6 @@ PAL_PollEvent(
 
 --*/
 {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
-   //
-   // SDL2 changed the timing of event callback so we need to handle
-   // events manually when polled
-   //
    SDL_Event evt;
 
    int ret = SDL_PollEvent(&evt);
@@ -1112,7 +1104,4 @@ PAL_PollEvent(
    }
 
    return ret;
-#else
-   return SDL_PollEvent(event);
-#endif
 }

+ 433 - 433
magicmenu.c

@@ -1,433 +1,433 @@
-/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
-//
-// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
-// All rights reserved.
-//
-// This file is part of SDLPAL.
-//
-// SDLPAL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#include "main.h"
-
-static struct MAGICITEM
-{
-   WORD         wMagic;
-   WORD         wMP;
-   BOOL         fEnabled;
-} rgMagicItem[MAX_PLAYER_MAGICS];
-
-static int     g_iNumMagic = 0;
-static int     g_iCurrentItem = 0;
-static WORD    g_wPlayerMP = 0;
-
-WORD
-PAL_MagicSelectionMenuUpdate(
-   VOID
-)
-/*++
-  Purpose:
-
-    Update the magic selection menu.
-
-  Parameters:
-
-    None.
-
-  Return value:
-
-    The selected magic. 0 if cancelled, 0xFFFF if not confirmed.
-
---*/
-{
-   int         i, j, k;
-   BYTE        bColor;
-
-   //
-   // Check for inputs
-   //
-   if (g_InputState.dwKeyPress & kKeyUp)
-   {
-      g_iCurrentItem -= 3;
-   }
-   else if (g_InputState.dwKeyPress & kKeyDown)
-   {
-      g_iCurrentItem += 3;
-   }
-   else if (g_InputState.dwKeyPress & kKeyLeft)
-   {
-      g_iCurrentItem--;
-   }
-   else if (g_InputState.dwKeyPress & kKeyRight)
-   {
-      g_iCurrentItem++;
-   }
-   else if (g_InputState.dwKeyPress & kKeyPgUp)
-   {
-      g_iCurrentItem -= 3 * 5;
-   }
-   else if (g_InputState.dwKeyPress & kKeyPgDn)
-   {
-      g_iCurrentItem += 3 * 5;
-   }
-   else if (g_InputState.dwKeyPress & kKeyMenu)
-   {
-      return 0;
-   }
-
-   //
-   // Make sure the current menu item index is in bound
-   //
-   if (g_iCurrentItem < 0)
-   {
-      g_iCurrentItem = 0;
-   }
-   else if (g_iCurrentItem >= g_iNumMagic)
-   {
-      g_iCurrentItem = g_iNumMagic - 1;
-   }
-
-   //
-   // Create the box.
-   //
-   PAL_CreateBox(PAL_XY(10, 42), 4, 16, 1, FALSE);
-
-   if (gpGlobals->lpObjectDesc == NULL)
-   {
-      //
-      // Draw the cash amount.
-      //
-      PAL_CreateSingleLineBox(PAL_XY(0, 0), 5, FALSE);
-      PAL_DrawText(PAL_GetWord(CASH_LABEL), PAL_XY(10, 10), 0, FALSE, FALSE);
-      PAL_DrawNumber(gpGlobals->dwCash, 6, PAL_XY(49, 14), kNumColorYellow, kNumAlignRight);
-
-      //
-      // Draw the MP of the selected magic.
-      //
-      PAL_CreateSingleLineBox(PAL_XY(215, 0), 5, FALSE);
-      PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH),
-         gpScreen, PAL_XY(260, 14));
-      PAL_DrawNumber(rgMagicItem[g_iCurrentItem].wMP, 4, PAL_XY(230, 14),
-         kNumColorYellow, kNumAlignRight);
-      PAL_DrawNumber(g_wPlayerMP, 4, PAL_XY(265, 14), kNumColorCyan, kNumAlignRight);
-   }
-   else
-   {
-      char szDesc[512], *next;
-      const char *d = PAL_GetObjectDesc(gpGlobals->lpObjectDesc, rgMagicItem[g_iCurrentItem].wMagic);
-
-      //
-      // Draw the magic description.
-      //
-      if (d != NULL)
-      {
-         k = 3;
-         strcpy(szDesc, d);
-         d = szDesc;
-
-         while (TRUE)
-         {
-            next = strchr(d, '*');
-            if (next != NULL)
-            {
-               *next = '\0';
-               next++;
-            }
-
-            PAL_DrawText(d, PAL_XY(100, k), DESCTEXT_COLOR, TRUE, FALSE);
-            k += 16;
-
-            if (next == NULL)
-            {
-               break;
-            }
-
-            d = next;
-         }
-      }
-
-      //
-      // Draw the MP of the selected magic.
-      //
-      PAL_CreateSingleLineBox(PAL_XY(0, 0), 5, FALSE);
-      PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH),
-         gpScreen, PAL_XY(45, 14));
-      PAL_DrawNumber(rgMagicItem[g_iCurrentItem].wMP, 4, PAL_XY(15, 14),
-         kNumColorYellow, kNumAlignRight);
-      PAL_DrawNumber(g_wPlayerMP, 4, PAL_XY(50, 14), kNumColorCyan, kNumAlignRight);
-   }
-
-   //
-   // Draw the texts of the current page
-   //
-   i = g_iCurrentItem / 3 * 3 - 3 * 2;
-   if (i < 0)
-   {
-      i = 0;
-   }
-
-   for (j = 0; j < 5; j++)
-   {
-      for (k = 0; k < 3; k++)
-      {
-         bColor = MENUITEM_COLOR;
-
-         if (i >= g_iNumMagic)
-         {
-            //
-            // End of the list reached
-            //
-            j = 5;
-            break;
-         }
-
-         if (i == g_iCurrentItem)
-         {
-            if (rgMagicItem[i].fEnabled)
-            {
-               bColor = MENUITEM_COLOR_SELECTED;
-            }
-            else
-            {
-               bColor = MENUITEM_COLOR_SELECTED_INACTIVE;
-            }
-         }
-         else if (!rgMagicItem[i].fEnabled)
-         {
-            bColor = MENUITEM_COLOR_INACTIVE;
-         }
-
-         //
-         // Draw the text
-         //
-         PAL_DrawText(PAL_GetWord(rgMagicItem[i].wMagic),
-            PAL_XY(35 + k * 87, 54 + j * 18), bColor, TRUE, FALSE);
-
-         //
-         // Draw the cursor on the current selected item
-         //
-         if (i == g_iCurrentItem)
-         {
-            PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_CURSOR),
-               gpScreen, PAL_XY(60 + k * 87, 64 + j * 18));
-         }
-
-         i++;
-      }
-   }
-
-   if (g_InputState.dwKeyPress & kKeySearch)
-   {
-      if (rgMagicItem[g_iCurrentItem].fEnabled)
-      {
-         j = g_iCurrentItem % 3;
-         k = (g_iCurrentItem < 3 * 2) ? (g_iCurrentItem / 3) : 2;
-
-         j = 35 + j * 87;
-         k = 54 + k * 18;
-
-         PAL_DrawText(PAL_GetWord(rgMagicItem[g_iCurrentItem].wMagic), PAL_XY(j, k),
-            MENUITEM_COLOR_CONFIRMED, FALSE, TRUE);
-
-         return rgMagicItem[g_iCurrentItem].wMagic;
-      }
-   }
-
-   return 0xFFFF;
-}
-
-VOID
-PAL_MagicSelectionMenuInit(
-   WORD         wPlayerRole,
-   BOOL         fInBattle,
-   WORD         wDefaultMagic
-)
-/*++
-  Purpose:
-
-    Initialize the magic selection menu.
-
-  Parameters:
-
-    [IN]  wPlayerRole - the player ID.
-
-    [IN]  fInBattle - TRUE if in battle, FALSE if not.
-
-    [IN]  wDefaultMagic - the default magic item.
-
-  Return value:
-
-    None.
-
---*/
-{
-   WORD       w;
-   int        i, j;
-
-   g_iCurrentItem = 0;
-   g_iNumMagic = 0;
-
-   g_wPlayerMP = gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole];
-
-   //
-   // Put all magics of this player to the array
-   //
-   for (i = 0; i < MAX_PLAYER_MAGICS; i++)
-   {
-      w = gpGlobals->g.PlayerRoles.rgwMagic[i][wPlayerRole];
-      if (w != 0)
-      {
-         rgMagicItem[g_iNumMagic].wMagic = w;
-
-         w = gpGlobals->g.rgObject[w].magic.wMagicNumber;
-         rgMagicItem[g_iNumMagic].wMP = gpGlobals->g.lprgMagic[w].wCostMP;
-
-         rgMagicItem[g_iNumMagic].fEnabled = TRUE;
-
-         if (rgMagicItem[g_iNumMagic].wMP > g_wPlayerMP)
-         {
-            rgMagicItem[g_iNumMagic].fEnabled = FALSE;
-         }
-
-         w = gpGlobals->g.rgObject[rgMagicItem[g_iNumMagic].wMagic].magic.wFlags;
-         if (fInBattle)
-         {
-            if (!(w & kMagicFlagUsableInBattle))
-            {
-               rgMagicItem[g_iNumMagic].fEnabled = FALSE;
-            }
-         }
-         else
-         {
-            if (!(w & kMagicFlagUsableOutsideBattle))
-            {
-               rgMagicItem[g_iNumMagic].fEnabled = FALSE;
-            }
-         }
-
-         g_iNumMagic++;
-      }
-   }
-
-   //
-   // Sort the array
-   //
-   for (i = 0; i < g_iNumMagic - 1; i++)
-   {
-      BOOL fCompleted = TRUE;
-
-      for (j = 0; j < g_iNumMagic - 1 - i; j++)
-      {
-         if (rgMagicItem[j].wMagic > rgMagicItem[j + 1].wMagic)
-         {
-            struct MAGICITEM t = rgMagicItem[j];
-            rgMagicItem[j] = rgMagicItem[j + 1];
-            rgMagicItem[j + 1] = t;
-
-            fCompleted = FALSE;
-         }
-      }
-
-      if (fCompleted)
-      {
-         break;
-      }
-   }
-
-   //
-   // Place the cursor to the default item
-   //
-   for (i = 0; i < g_iNumMagic; i++)
-   {
-      if (rgMagicItem[i].wMagic == wDefaultMagic)
-      {
-         g_iCurrentItem = i;
-         break;
-      }
-   }
-}
-
-WORD
-PAL_MagicSelectionMenu(
-   WORD         wPlayerRole,
-   BOOL         fInBattle,
-   WORD         wDefaultMagic
-)
-/*++
-  Purpose:
-
-    Show the magic selection menu.
-
-  Parameters:
-
-    [IN]  wPlayerRole - the player ID.
-
-    [IN]  fInBattle - TRUE if in battle, FALSE if not.
-
-    [IN]  wDefaultMagic - the default magic item.
-
-  Return value:
-
-    The selected magic. 0 if cancelled.
-
---*/
-{
-   WORD            w;
-   int             i;
-   DWORD           dwTime;
-
-   PAL_MagicSelectionMenuInit(wPlayerRole, fInBattle, wDefaultMagic);
-   PAL_ClearKeyState();
-
-   dwTime = SDL_GetTicks();
-
-   while (TRUE)
-   {
-      PAL_MakeScene();
-
-      w = 45;
-
-      for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
-      {
-         PAL_PlayerInfoBox(PAL_XY(w, 165), gpGlobals->rgParty[i].wPlayerRole, 100,
-            TIMEMETER_COLOR_DEFAULT, FALSE);
-         w += 78;
-      }
-
-      w = PAL_MagicSelectionMenuUpdate();
-      VIDEO_UpdateScreen(NULL);
-
-      PAL_ClearKeyState();
-
-      if (w != 0xFFFF)
-      {
-         return w;
-      }
-
-      PAL_ProcessEvent();
-      while (SDL_GetTicks() < dwTime)
-      {
-         PAL_ProcessEvent();
-         if (g_InputState.dwKeyPress != 0)
-         {
-            break;
-         }
-         SDL_Delay(5);
-      }
-
-      dwTime = SDL_GetTicks() + FRAME_TIME;
-   }
-
-   return 0; // should not really reach here
-}
+/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include "main.h"
+
+static struct MAGICITEM
+{
+   WORD         wMagic;
+   WORD         wMP;
+   BOOL         fEnabled;
+} rgMagicItem[MAX_PLAYER_MAGICS];
+
+static int     g_iNumMagic = 0;
+static int     g_iCurrentItem = 0;
+static WORD    g_wPlayerMP = 0;
+
+WORD
+PAL_MagicSelectionMenuUpdate(
+   VOID
+)
+/*++
+  Purpose:
+
+    Update the magic selection menu.
+
+  Parameters:
+
+    None.
+
+  Return value:
+
+    The selected magic. 0 if cancelled, 0xFFFF if not confirmed.
+
+--*/
+{
+   int         i, j, k;
+   BYTE        bColor;
+
+   //
+   // Check for inputs
+   //
+   if (g_InputState.dwKeyPress & kKeyUp)
+   {
+      g_iCurrentItem -= 3;
+   }
+   else if (g_InputState.dwKeyPress & kKeyDown)
+   {
+      g_iCurrentItem += 3;
+   }
+   else if (g_InputState.dwKeyPress & kKeyLeft)
+   {
+      g_iCurrentItem--;
+   }
+   else if (g_InputState.dwKeyPress & kKeyRight)
+   {
+      g_iCurrentItem++;
+   }
+   else if (g_InputState.dwKeyPress & kKeyPgUp)
+   {
+      g_iCurrentItem -= 3 * 5;
+   }
+   else if (g_InputState.dwKeyPress & kKeyPgDn)
+   {
+      g_iCurrentItem += 3 * 5;
+   }
+   else if (g_InputState.dwKeyPress & kKeyMenu)
+   {
+      return 0;
+   }
+
+   //
+   // Make sure the current menu item index is in bound
+   //
+   if (g_iCurrentItem < 0)
+   {
+      g_iCurrentItem = 0;
+   }
+   else if (g_iCurrentItem >= g_iNumMagic)
+   {
+      g_iCurrentItem = g_iNumMagic - 1;
+   }
+
+   //
+   // Create the box.
+   //
+   PAL_CreateBox(PAL_XY(10, 42), 4, 16, 1, FALSE);
+
+   if (gpGlobals->lpObjectDesc == NULL)
+   {
+      //
+      // Draw the cash amount.
+      //
+      PAL_CreateSingleLineBox(PAL_XY(0, 0), 5, FALSE);
+      PAL_DrawText(PAL_GetWord(CASH_LABEL), PAL_XY(10, 10), 0, FALSE, FALSE);
+      PAL_DrawNumber(gpGlobals->dwCash, 6, PAL_XY(49, 14), kNumColorYellow, kNumAlignRight);
+
+      //
+      // Draw the MP of the selected magic.
+      //
+      PAL_CreateSingleLineBox(PAL_XY(215, 0), 5, FALSE);
+      PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH),
+         gpScreen, PAL_XY(260, 14));
+      PAL_DrawNumber(rgMagicItem[g_iCurrentItem].wMP, 4, PAL_XY(230, 14),
+         kNumColorYellow, kNumAlignRight);
+      PAL_DrawNumber(g_wPlayerMP, 4, PAL_XY(265, 14), kNumColorCyan, kNumAlignRight);
+   }
+   else
+   {
+      char szDesc[512], *next;
+      const char *d = PAL_GetObjectDesc(gpGlobals->lpObjectDesc, rgMagicItem[g_iCurrentItem].wMagic);
+
+      //
+      // Draw the magic description.
+      //
+      if (d != NULL)
+      {
+         k = 3;
+         strcpy(szDesc, d);
+         d = szDesc;
+
+         while (TRUE)
+         {
+            next = strchr(d, '*');
+            if (next != NULL)
+            {
+               *next = '\0';
+               next++;
+            }
+
+            PAL_DrawText(d, PAL_XY(100, k), DESCTEXT_COLOR, TRUE, FALSE);
+            k += 16;
+
+            if (next == NULL)
+            {
+               break;
+            }
+
+            d = next;
+         }
+      }
+
+      //
+      // Draw the MP of the selected magic.
+      //
+      PAL_CreateSingleLineBox(PAL_XY(0, 0), 5, FALSE);
+      PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH),
+         gpScreen, PAL_XY(45, 14));
+      PAL_DrawNumber(rgMagicItem[g_iCurrentItem].wMP, 4, PAL_XY(15, 14),
+         kNumColorYellow, kNumAlignRight);
+      PAL_DrawNumber(g_wPlayerMP, 4, PAL_XY(50, 14), kNumColorCyan, kNumAlignRight);
+   }
+
+   //
+   // Draw the texts of the current page
+   //
+   i = g_iCurrentItem / 3 * 3 - 3 * 2;
+   if (i < 0)
+   {
+      i = 0;
+   }
+
+   for (j = 0; j < 5; j++)
+   {
+      for (k = 0; k < 3; k++)
+      {
+         bColor = MENUITEM_COLOR;
+
+         if (i >= g_iNumMagic)
+         {
+            //
+            // End of the list reached
+            //
+            j = 5;
+            break;
+         }
+
+         if (i == g_iCurrentItem)
+         {
+            if (rgMagicItem[i].fEnabled)
+            {
+               bColor = MENUITEM_COLOR_SELECTED;
+            }
+            else
+            {
+               bColor = MENUITEM_COLOR_SELECTED_INACTIVE;
+            }
+         }
+         else if (!rgMagicItem[i].fEnabled)
+         {
+            bColor = MENUITEM_COLOR_INACTIVE;
+         }
+
+         //
+         // Draw the text
+         //
+         PAL_DrawText(PAL_GetWord(rgMagicItem[i].wMagic),
+            PAL_XY(35 + k * 87, 54 + j * 18), bColor, TRUE, FALSE);
+
+         //
+         // Draw the cursor on the current selected item
+         //
+         if (i == g_iCurrentItem)
+         {
+            PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_CURSOR),
+               gpScreen, PAL_XY(60 + k * 87, 64 + j * 18));
+         }
+
+         i++;
+      }
+   }
+
+   if (g_InputState.dwKeyPress & kKeySearch)
+   {
+      if (rgMagicItem[g_iCurrentItem].fEnabled)
+      {
+         j = g_iCurrentItem % 3;
+         k = (g_iCurrentItem < 3 * 2) ? (g_iCurrentItem / 3) : 2;
+
+         j = 35 + j * 87;
+         k = 54 + k * 18;
+
+         PAL_DrawText(PAL_GetWord(rgMagicItem[g_iCurrentItem].wMagic), PAL_XY(j, k),
+            MENUITEM_COLOR_CONFIRMED, FALSE, TRUE);
+
+         return rgMagicItem[g_iCurrentItem].wMagic;
+      }
+   }
+
+   return 0xFFFF;
+}
+
+VOID
+PAL_MagicSelectionMenuInit(
+   WORD         wPlayerRole,
+   BOOL         fInBattle,
+   WORD         wDefaultMagic
+)
+/*++
+  Purpose:
+
+    Initialize the magic selection menu.
+
+  Parameters:
+
+    [IN]  wPlayerRole - the player ID.
+
+    [IN]  fInBattle - TRUE if in battle, FALSE if not.
+
+    [IN]  wDefaultMagic - the default magic item.
+
+  Return value:
+
+    None.
+
+--*/
+{
+   WORD       w;
+   int        i, j;
+
+   g_iCurrentItem = 0;
+   g_iNumMagic = 0;
+
+   g_wPlayerMP = gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole];
+
+   //
+   // Put all magics of this player to the array
+   //
+   for (i = 0; i < MAX_PLAYER_MAGICS; i++)
+   {
+      w = gpGlobals->g.PlayerRoles.rgwMagic[i][wPlayerRole];
+      if (w != 0)
+      {
+         rgMagicItem[g_iNumMagic].wMagic = w;
+
+         w = gpGlobals->g.rgObject[w].magic.wMagicNumber;
+         rgMagicItem[g_iNumMagic].wMP = gpGlobals->g.lprgMagic[w].wCostMP;
+
+         rgMagicItem[g_iNumMagic].fEnabled = TRUE;
+
+         if (rgMagicItem[g_iNumMagic].wMP > g_wPlayerMP)
+         {
+            rgMagicItem[g_iNumMagic].fEnabled = FALSE;
+         }
+
+         w = gpGlobals->g.rgObject[rgMagicItem[g_iNumMagic].wMagic].magic.wFlags;
+         if (fInBattle)
+         {
+            if (!(w & kMagicFlagUsableInBattle))
+            {
+               rgMagicItem[g_iNumMagic].fEnabled = FALSE;
+            }
+         }
+         else
+         {
+            if (!(w & kMagicFlagUsableOutsideBattle))
+            {
+               rgMagicItem[g_iNumMagic].fEnabled = FALSE;
+            }
+         }
+
+         g_iNumMagic++;
+      }
+   }
+
+   //
+   // Sort the array
+   //
+   for (i = 0; i < g_iNumMagic - 1; i++)
+   {
+      BOOL fCompleted = TRUE;
+
+      for (j = 0; j < g_iNumMagic - 1 - i; j++)
+      {
+         if (rgMagicItem[j].wMagic > rgMagicItem[j + 1].wMagic)
+         {
+            struct MAGICITEM t = rgMagicItem[j];
+            rgMagicItem[j] = rgMagicItem[j + 1];
+            rgMagicItem[j + 1] = t;
+
+            fCompleted = FALSE;
+         }
+      }
+
+      if (fCompleted)
+      {
+         break;
+      }
+   }
+
+   //
+   // Place the cursor to the default item
+   //
+   for (i = 0; i < g_iNumMagic; i++)
+   {
+      if (rgMagicItem[i].wMagic == wDefaultMagic)
+      {
+         g_iCurrentItem = i;
+         break;
+      }
+   }
+}
+
+WORD
+PAL_MagicSelectionMenu(
+   WORD         wPlayerRole,
+   BOOL         fInBattle,
+   WORD         wDefaultMagic
+)
+/*++
+  Purpose:
+
+    Show the magic selection menu.
+
+  Parameters:
+
+    [IN]  wPlayerRole - the player ID.
+
+    [IN]  fInBattle - TRUE if in battle, FALSE if not.
+
+    [IN]  wDefaultMagic - the default magic item.
+
+  Return value:
+
+    The selected magic. 0 if cancelled.
+
+--*/
+{
+   WORD            w;
+   int             i;
+   DWORD           dwTime;
+
+   PAL_MagicSelectionMenuInit(wPlayerRole, fInBattle, wDefaultMagic);
+   PAL_ClearKeyState();
+
+   dwTime = SDL_GetTicks();
+
+   while (TRUE)
+   {
+      PAL_MakeScene();
+
+      w = 45;
+
+      for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
+      {
+         PAL_PlayerInfoBox(PAL_XY(w, 165), gpGlobals->rgParty[i].wPlayerRole, 100,
+            TIMEMETER_COLOR_DEFAULT, FALSE);
+         w += 78;
+      }
+
+      w = PAL_MagicSelectionMenuUpdate();
+      VIDEO_UpdateScreen(NULL);
+
+      PAL_ClearKeyState();
+
+      if (w != 0xFFFF)
+      {
+         return w;
+      }
+
+      PAL_ProcessEvent();
+      while (SDL_GetTicks() < dwTime)
+      {
+         PAL_ProcessEvent();
+         if (g_InputState.dwKeyPress != 0)
+         {
+            break;
+         }
+         SDL_Delay(5);
+      }
+
+      dwTime = SDL_GetTicks() + FRAME_TIME;
+   }
+
+   return 0; // should not really reach here
+}

+ 52 - 52
magicmenu.h

@@ -1,52 +1,52 @@
-/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
-//
-// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
-// All rights reserved.
-//
-// This file is part of SDLPAL.
-//
-// SDLPAL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef MAGICMENU_H
-#define MAGICMENU_H
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-WORD
-PAL_MagicSelectionMenuUpdate(
-   VOID
-);
-
-VOID
-PAL_MagicSelectionMenuInit(
-   WORD         wPlayerRole,
-   BOOL         fInBattle,
-   WORD         wDefaultMagic
-);
-
-WORD
-PAL_MagicSelectionMenu(
-   WORD         wPlayerRole,
-   BOOL         fInBattle,
-   WORD         wDefaultMagic
-);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
+/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef MAGICMENU_H
+#define MAGICMENU_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+WORD
+PAL_MagicSelectionMenuUpdate(
+   VOID
+);
+
+VOID
+PAL_MagicSelectionMenuInit(
+   WORD         wPlayerRole,
+   BOOL         fInBattle,
+   WORD         wDefaultMagic
+);
+
+WORD
+PAL_MagicSelectionMenu(
+   WORD         wPlayerRole,
+   BOOL         fInBattle,
+   WORD         wDefaultMagic
+);
+
+#ifdef __cplusplus
+}
+#endif
+#endif

File diff suppressed because it is too large
+ 635 - 626
main.c


+ 123 - 123
midi.c

@@ -1,123 +1,123 @@
-/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
-//
-// Copyright (c) 2011, Wei Mingzhi <whistler_wmz@users.sf.net>.
-// All rights reserved.
-//
-// This file is part of SDLPAL.
-//
-// SDLPAL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#include "main.h"
-
-#if !defined (CYGWIN) && !defined (DINGOO) &&  !defined (GEKKO) && !defined (GPH)
-
-static INT iMidCurrent = -1;
-static BOOL fMidLoop = FALSE;
-
-static NativeMidiSong *g_pMid = NULL;
-
-VOID
-MIDI_Play(
-   INT       iNumRIX,
-   BOOL      fLoop
-)
-/*++
-  Purpose:
-
-    Start playing the specified music in MIDI format.
-
-  Parameters:
-
-    [IN]  iNumRIX - number of the music. 0 to stop playing current music.
-
-    [IN]  fLoop - Whether the music should be looped or not.
-
-  Return value:
-
-    None.
-
---*/
-{
-   FILE            *fp;
-   unsigned char   *buf;
-   int              size;
-   SDL_RWops       *rw;
-
-   if (g_pMid != NULL && iNumRIX == iMidCurrent && native_midi_active())
-   {
-      return;
-   }
-
-   SOUND_PlayCDA(-1);
-   native_midi_freesong(g_pMid);
-   g_pMid = NULL;
-   iMidCurrent = -1;
-
-   if (g_fNoMusic || iNumRIX <= 0)
-   {
-      return;
-   }
-
-   fp = UTIL_OpenFile("midi.mkf");
-   if (fp == NULL)
-   {
-      return;
-   }
-
-   if (iNumRIX > PAL_MKFGetChunkCount(fp))
-   {
-      fclose(fp);
-      return;
-   }
-
-   size = PAL_MKFGetChunkSize(iNumRIX, fp);
-   if (size <= 0)
-   {
-      fclose(fp);
-      return;
-   }
-
-   buf = (unsigned char *)UTIL_malloc(size);
-
-   PAL_MKFReadChunk((LPBYTE)buf, size, iNumRIX, fp);
-   fclose(fp);
-
-   rw = SDL_RWFromConstMem((const void *)buf, size);
-
-   g_pMid = native_midi_loadsong_RW(rw);
-   if (g_pMid != NULL)
-   {
-      native_midi_start(g_pMid);
-
-      iMidCurrent = iNumRIX;
-      fMidLoop = fLoop;
-   }
-
-   SDL_RWclose(rw);
-   free(buf);
-}
-
-VOID
-MIDI_CheckLoop(
-   VOID
-)
-{
-   if (fMidLoop && g_pMid != NULL && !native_midi_active())
-   {
-      MIDI_Play(iMidCurrent, TRUE);
-   }
-}
-
-#endif
+/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2011, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include "main.h"
+
+#if !defined (CYGWIN) && !defined (DINGOO) &&  !defined (GEKKO) && !defined (GPH)
+
+static INT iMidCurrent = -1;
+static BOOL fMidLoop = FALSE;
+
+static NativeMidiSong *g_pMid = NULL;
+
+VOID
+MIDI_Play(
+   INT       iNumRIX,
+   BOOL      fLoop
+)
+/*++
+  Purpose:
+
+    Start playing the specified music in MIDI format.
+
+  Parameters:
+
+    [IN]  iNumRIX - number of the music. 0 to stop playing current music.
+
+    [IN]  fLoop - Whether the music should be looped or not.
+
+  Return value:
+
+    None.
+
+--*/
+{
+   FILE            *fp;
+   unsigned char   *buf;
+   int              size;
+   SDL_RWops       *rw;
+
+   if (g_pMid != NULL && iNumRIX == iMidCurrent && native_midi_active())
+   {
+      return;
+   }
+
+   SOUND_PlayCDA(-1);
+   native_midi_freesong(g_pMid);
+   g_pMid = NULL;
+   iMidCurrent = -1;
+
+   if (g_fNoMusic || iNumRIX <= 0)
+   {
+      return;
+   }
+
+   fp = UTIL_OpenFile("midi.mkf");
+   if (fp == NULL)
+   {
+      return;
+   }
+
+   if (iNumRIX > PAL_MKFGetChunkCount(fp))
+   {
+      fclose(fp);
+      return;
+   }
+
+   size = PAL_MKFGetChunkSize(iNumRIX, fp);
+   if (size <= 0)
+   {
+      fclose(fp);
+      return;
+   }
+
+   buf = (unsigned char *)UTIL_malloc(size);
+
+   PAL_MKFReadChunk((LPBYTE)buf, size, iNumRIX, fp);
+   fclose(fp);
+
+   rw = SDL_RWFromConstMem((const void *)buf, size);
+
+   g_pMid = native_midi_loadsong_RW(rw);
+   if (g_pMid != NULL)
+   {
+      native_midi_start(g_pMid);
+
+      iMidCurrent = iNumRIX;
+      fMidLoop = fLoop;
+   }
+
+   SDL_RWclose(rw);
+   free(buf);
+}
+
+VOID
+MIDI_CheckLoop(
+   VOID
+)
+{
+   if (fMidLoop && g_pMid != NULL && !native_midi_active())
+   {
+      MIDI_Play(iMidCurrent, TRUE);
+   }
+}
+
+#endif

+ 49 - 49
midi.h

@@ -1,49 +1,49 @@
-/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
-//
-// Copyright (c) 2011, Wei Mingzhi <whistler_wmz@users.sf.net>.
-// All rights reserved.
-//
-// This file is part of SDLPAL.
-//
-// SDLPAL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef PAL_MIDI_H
-#define PAL_MIDI_H
-
-#include "common.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include "native_midi/native_midi.h"
-
-VOID
-MIDI_Play(
-   INT       iNumRIX,
-   BOOL      fLoop
-);
-
-VOID
-MIDI_CheckLoop(
-   VOID
-);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2011, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef PAL_MIDI_H
+#define PAL_MIDI_H
+
+#include "common.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "native_midi/native_midi.h"
+
+VOID
+MIDI_Play(
+   INT       iNumRIX,
+   BOOL      fLoop
+);
+
+VOID
+MIDI_CheckLoop(
+   VOID
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 3 - 3
private.c

@@ -1,3 +1,3 @@
-#ifdef CYGWIN
-	SDLPAL_ICON ICON DISCARDABLE "sdlpal.ico"
-#endif
+#ifdef CYGWIN
+	SDLPAL_ICON ICON DISCARDABLE "sdlpal.ico"
+#endif

+ 430 - 430
res.c

@@ -1,430 +1,430 @@
-/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
-//
-// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
-// All rights reserved.
-//
-// This file is part of SDLPAL.
-//
-// SDLPAL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#include "main.h"
-
-typedef struct tagRESOURCES
-{
-   BYTE             bLoadFlags;
-
-   LPPALMAP         lpMap;                                      // current loaded map
-   LPSPRITE        *lppEventObjectSprites;                      // event object sprites
-   int              nEventObject;                               // number of event objects
-
-   LPSPRITE         rglpPlayerSprite[MAX_PLAYERS_IN_PARTY + 1]; // player sprites
-} RESOURCES, *LPRESOURCES;
-
-static LPRESOURCES gpResources = NULL;
-
-static VOID
-PAL_FreeEventObjectSprites(
-   VOID
-)
-/*++
-  Purpose:
-
-    Free all sprites of event objects on the scene.
-
-  Parameters:
-
-    None.
-
-  Return value:
-
-    None.
-
---*/
-{
-   int i;
-
-   if (gpResources->lppEventObjectSprites != NULL)
-   {
-      for (i = 0; i < gpResources->nEventObject; i++)
-      {
-         free(gpResources->lppEventObjectSprites[i]);
-      }
-
-      free(gpResources->lppEventObjectSprites);
-
-      gpResources->lppEventObjectSprites = NULL;
-      gpResources->nEventObject = 0;
-   }
-}
-
-static VOID
-PAL_FreePlayerSprites(
-   VOID
-)
-/*++
-  Purpose:
-
-    Free all player sprites.
-
-  Parameters:
-
-    None.
-
-  Return value:
-
-    None.
-
---*/
-{
-   int i;
-
-   for (i = 0; i < MAX_PLAYERS_IN_PARTY + 1; i++)
-   {
-      free(gpResources->rglpPlayerSprite[i]);
-      gpResources->rglpPlayerSprite[i] = NULL;
-   }
-}
-
-VOID
-PAL_InitResources(
-   VOID
-)
-/*++
-  Purpose:
-
-    Initialze the resource manager.
-
-  Parameters:
-
-    None.
-
-  Return value:
-
-    None.
-
---*/
-{
-   gpResources = (LPRESOURCES)UTIL_calloc(1, sizeof(RESOURCES));
-}
-
-VOID
-PAL_FreeResources(
-   VOID
-)
-/*++
-  Purpose:
-
-    Free all loaded resources.
-
-  Parameters:
-
-    None.
-
-  Return value:
-
-    None.
-
---*/
-{
-   if (gpResources != NULL)
-   {
-      //
-      // Free all loaded sprites
-      //
-      PAL_FreePlayerSprites();
-      PAL_FreeEventObjectSprites();
-
-      //
-      // Free map
-      //
-      PAL_FreeMap(gpResources->lpMap);
-
-      //
-      // Delete the instance
-      //
-      free(gpResources);
-   }
-
-   gpResources = NULL;
-}
-
-VOID
-PAL_SetLoadFlags(
-   BYTE       bFlags
-)
-/*++
-  Purpose:
-
-    Set flags to load resources.
-
-  Parameters:
-
-    [IN]  bFlags - flags to be set.
-
-  Return value:
-
-    None.
-
---*/
-{
-   if (gpResources == NULL)
-   {
-      return;
-   }
-
-   gpResources->bLoadFlags |= bFlags;
-}
-
-VOID
-PAL_LoadResources(
-   VOID
-)
-/*++
-  Purpose:
-
-    Load the game resources if needed.
-
-  Parameters:
-
-    None.
-
-  Return value:
-
-    None.
-
---*/
-{
-   int                i, index, l, n;
-   WORD               wPlayerID, wSpriteNum;
-
-   if (gpResources == NULL || gpResources->bLoadFlags == 0)
-   {
-      return;
-   }
-
-   //
-   // Load scene
-   //
-   if (gpResources->bLoadFlags & kLoadScene)
-   {
-      FILE              *fpMAP, *fpGOP;
-
-      fpMAP = UTIL_OpenRequiredFile("map.mkf");
-      fpGOP = UTIL_OpenRequiredFile("gop.mkf");
-
-      if (gpGlobals->fEnteringScene)
-      {
-         gpGlobals->wScreenWave = 0;
-         gpGlobals->sWaveProgression = 0;
-      }
-
-      //
-      // Free previous loaded scene (sprites and map)
-      //
-      PAL_FreeEventObjectSprites();
-      PAL_FreeMap(gpResources->lpMap);
-
-      //
-      // Load map
-      //
-      i = gpGlobals->wNumScene - 1;
-      gpResources->lpMap = PAL_LoadMap(gpGlobals->g.rgScene[i].wMapNum,
-         fpMAP, fpGOP);
-
-      if (gpResources->lpMap == NULL)
-      {
-         fclose(fpMAP);
-         fclose(fpGOP);
-
-         TerminateOnError("PAL_LoadResources(): Fail to load map #%d (scene #%d) !",
-            gpGlobals->g.rgScene[i].wMapNum, gpGlobals->wNumScene);
-      }
-
-      //
-      // Load sprites
-      //
-      index = gpGlobals->g.rgScene[i].wEventObjectIndex;
-      gpResources->nEventObject = gpGlobals->g.rgScene[i + 1].wEventObjectIndex;
-      gpResources->nEventObject -= index;
-
-      if (gpResources->nEventObject > 0)
-      {
-         gpResources->lppEventObjectSprites =
-            (LPSPRITE *)UTIL_calloc(gpResources->nEventObject, sizeof(LPSPRITE));
-      }
-
-      for (i = 0; i < gpResources->nEventObject; i++, index++)
-      {
-         n = gpGlobals->g.lprgEventObject[index].wSpriteNum;
-         if (n == 0)
-         {
-            //
-            // this event object has no sprite
-            //
-            gpResources->lppEventObjectSprites[i] = NULL;
-            continue;
-         }
-
-         l = PAL_MKFGetDecompressedSize(n, gpGlobals->f.fpMGO);
-
-         gpResources->lppEventObjectSprites[i] = (LPSPRITE)UTIL_malloc(l);
-
-         if (PAL_MKFDecompressChunk(gpResources->lppEventObjectSprites[i], l,
-            n, gpGlobals->f.fpMGO) > 0)
-         {
-            gpGlobals->g.lprgEventObject[index].nSpriteFramesAuto =
-               PAL_SpriteGetNumFrames(gpResources->lppEventObjectSprites[i]);
-         }
-      }
-
-      gpGlobals->partyoffset = PAL_XY(160, 112);
-
-      fclose(fpGOP);
-      fclose(fpMAP);
-   }
-
-   //
-   // Load player sprites
-   //
-   if (gpResources->bLoadFlags & kLoadPlayerSprite)
-   {
-      //
-      // Free previous loaded player sprites
-      //
-      PAL_FreePlayerSprites();
-
-      for (i = 0; i <= (short)gpGlobals->wMaxPartyMemberIndex; i++)
-      {
-         wPlayerID = gpGlobals->rgParty[i].wPlayerRole;
-         assert(wPlayerID < MAX_PLAYER_ROLES);
-
-         //
-         // Load player sprite
-         //
-         wSpriteNum = gpGlobals->g.PlayerRoles.rgwSpriteNum[wPlayerID];
-
-         l = PAL_MKFGetDecompressedSize(wSpriteNum, gpGlobals->f.fpMGO);
-
-         gpResources->rglpPlayerSprite[i] = (LPSPRITE)UTIL_malloc(l);
-
-         PAL_MKFDecompressChunk(gpResources->rglpPlayerSprite[i], l, wSpriteNum,
-            gpGlobals->f.fpMGO);
-      }
-
-      if (gpGlobals->nFollower > 0)
-      {
-         //
-         // Load the follower sprite
-         //
-         wSpriteNum = gpGlobals->rgParty[i].wPlayerRole;
-
-         l = PAL_MKFGetDecompressedSize(wSpriteNum, gpGlobals->f.fpMGO);
-
-         gpResources->rglpPlayerSprite[i] = (LPSPRITE)UTIL_malloc(l);
-
-         PAL_MKFDecompressChunk(gpResources->rglpPlayerSprite[i], l, wSpriteNum,
-            gpGlobals->f.fpMGO);
-      }
-   }
-
-   //
-   // Clear all of the load flags
-   //
-   gpResources->bLoadFlags = 0;
-}
-
-LPPALMAP
-PAL_GetCurrentMap(
-   VOID
-)
-/*++
-  Purpose:
-
-    Get the current loaded map.
-
-  Parameters:
-
-    None.
-
-  Return value:
-
-    Pointer to the current loaded map. NULL if no map is loaded.
-
---*/
-{
-   if (gpResources == NULL)
-   {
-      return NULL;
-   }
-
-   return gpResources->lpMap;
-}
-
-LPSPRITE
-PAL_GetPlayerSprite(
-   BYTE      bPlayerIndex
-)
-/*++
-  Purpose:
-
-    Get the player sprite.
-
-  Parameters:
-
-    [IN]  bPlayerIndex - index of player in party (starts from 0).
-
-  Return value:
-
-    Pointer to the player sprite.
-
---*/
-{
-   if (gpResources == NULL || bPlayerIndex > MAX_PLAYERS_IN_PARTY)
-   {
-      return NULL;
-   }
-
-   return gpResources->rglpPlayerSprite[bPlayerIndex];
-}
-
-LPSPRITE
-PAL_GetEventObjectSprite(
-   WORD      wEventObjectID
-)
-/*++
-  Purpose:
-
-    Get the sprite of the specified event object.
-
-  Parameters:
-
-    [IN]  wEventObjectID - the ID of event object.
-
-  Return value:
-
-    Pointer to the sprite.
-
---*/
-{
-   wEventObjectID -= gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wEventObjectIndex;
-   wEventObjectID--;
-
-   if (gpResources == NULL || wEventObjectID >= gpResources->nEventObject)
-   {
-      return NULL;
-   }
-
-   return gpResources->lppEventObjectSprites[wEventObjectID];
-}
+/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include "main.h"
+
+typedef struct tagRESOURCES
+{
+   BYTE             bLoadFlags;
+
+   LPPALMAP         lpMap;                                      // current loaded map
+   LPSPRITE        *lppEventObjectSprites;                      // event object sprites
+   int              nEventObject;                               // number of event objects
+
+   LPSPRITE         rglpPlayerSprite[MAX_PLAYERS_IN_PARTY + 1]; // player sprites
+} RESOURCES, *LPRESOURCES;
+
+static LPRESOURCES gpResources = NULL;
+
+static VOID
+PAL_FreeEventObjectSprites(
+   VOID
+)
+/*++
+  Purpose:
+
+    Free all sprites of event objects on the scene.
+
+  Parameters:
+
+    None.
+
+  Return value:
+
+    None.
+
+--*/
+{
+   int i;
+
+   if (gpResources->lppEventObjectSprites != NULL)
+   {
+      for (i = 0; i < gpResources->nEventObject; i++)
+      {
+         free(gpResources->lppEventObjectSprites[i]);
+      }
+
+      free(gpResources->lppEventObjectSprites);
+
+      gpResources->lppEventObjectSprites = NULL;
+      gpResources->nEventObject = 0;
+   }
+}
+
+static VOID
+PAL_FreePlayerSprites(
+   VOID
+)
+/*++
+  Purpose:
+
+    Free all player sprites.
+
+  Parameters:
+
+    None.
+
+  Return value:
+
+    None.
+
+--*/
+{
+   int i;
+
+   for (i = 0; i < MAX_PLAYERS_IN_PARTY + 1; i++)
+   {
+      free(gpResources->rglpPlayerSprite[i]);
+      gpResources->rglpPlayerSprite[i] = NULL;
+   }
+}
+
+VOID
+PAL_InitResources(
+   VOID
+)
+/*++
+  Purpose:
+
+    Initialze the resource manager.
+
+  Parameters:
+
+    None.
+
+  Return value:
+
+    None.
+
+--*/
+{
+   gpResources = (LPRESOURCES)UTIL_calloc(1, sizeof(RESOURCES));
+}
+
+VOID
+PAL_FreeResources(
+   VOID
+)
+/*++
+  Purpose:
+
+    Free all loaded resources.
+
+  Parameters:
+
+    None.
+
+  Return value:
+
+    None.
+
+--*/
+{
+   if (gpResources != NULL)
+   {
+      //
+      // Free all loaded sprites
+      //
+      PAL_FreePlayerSprites();
+      PAL_FreeEventObjectSprites();
+
+      //
+      // Free map
+      //
+      PAL_FreeMap(gpResources->lpMap);
+
+      //
+      // Delete the instance
+      //
+      free(gpResources);
+   }
+
+   gpResources = NULL;
+}
+
+VOID
+PAL_SetLoadFlags(
+   BYTE       bFlags
+)
+/*++
+  Purpose:
+
+    Set flags to load resources.
+
+  Parameters:
+
+    [IN]  bFlags - flags to be set.
+
+  Return value:
+
+    None.
+
+--*/
+{
+   if (gpResources == NULL)
+   {
+      return;
+   }
+
+   gpResources->bLoadFlags |= bFlags;
+}
+
+VOID
+PAL_LoadResources(
+   VOID
+)
+/*++
+  Purpose:
+
+    Load the game resources if needed.
+
+  Parameters:
+
+    None.
+
+  Return value:
+
+    None.
+
+--*/
+{
+   int                i, index, l, n;
+   WORD               wPlayerID, wSpriteNum;
+
+   if (gpResources == NULL || gpResources->bLoadFlags == 0)
+   {
+      return;
+   }
+
+   //
+   // Load scene
+   //
+   if (gpResources->bLoadFlags & kLoadScene)
+   {
+      FILE              *fpMAP, *fpGOP;
+
+      fpMAP = UTIL_OpenRequiredFile("map.mkf");
+      fpGOP = UTIL_OpenRequiredFile("gop.mkf");
+
+      if (gpGlobals->fEnteringScene)
+      {
+         gpGlobals->wScreenWave = 0;
+         gpGlobals->sWaveProgression = 0;
+      }
+
+      //
+      // Free previous loaded scene (sprites and map)
+      //
+      PAL_FreeEventObjectSprites();
+      PAL_FreeMap(gpResources->lpMap);
+
+      //
+      // Load map
+      //
+      i = gpGlobals->wNumScene - 1;
+      gpResources->lpMap = PAL_LoadMap(gpGlobals->g.rgScene[i].wMapNum,
+         fpMAP, fpGOP);
+
+      if (gpResources->lpMap == NULL)
+      {
+         fclose(fpMAP);
+         fclose(fpGOP);
+
+         TerminateOnError("PAL_LoadResources(): Fail to load map #%d (scene #%d) !",
+            gpGlobals->g.rgScene[i].wMapNum, gpGlobals->wNumScene);
+      }
+
+      //
+      // Load sprites
+      //
+      index = gpGlobals->g.rgScene[i].wEventObjectIndex;
+      gpResources->nEventObject = gpGlobals->g.rgScene[i + 1].wEventObjectIndex;
+      gpResources->nEventObject -= index;
+
+      if (gpResources->nEventObject > 0)
+      {
+         gpResources->lppEventObjectSprites =
+            (LPSPRITE *)UTIL_calloc(gpResources->nEventObject, sizeof(LPSPRITE));
+      }
+
+      for (i = 0; i < gpResources->nEventObject; i++, index++)
+      {
+         n = gpGlobals->g.lprgEventObject[index].wSpriteNum;
+         if (n == 0)
+         {
+            //
+            // this event object has no sprite
+            //
+            gpResources->lppEventObjectSprites[i] = NULL;
+            continue;
+         }
+
+         l = PAL_MKFGetDecompressedSize(n, gpGlobals->f.fpMGO);
+
+         gpResources->lppEventObjectSprites[i] = (LPSPRITE)UTIL_malloc(l);
+
+         if (PAL_MKFDecompressChunk(gpResources->lppEventObjectSprites[i], l,
+            n, gpGlobals->f.fpMGO) > 0)
+         {
+            gpGlobals->g.lprgEventObject[index].nSpriteFramesAuto =
+               PAL_SpriteGetNumFrames(gpResources->lppEventObjectSprites[i]);
+         }
+      }
+
+      gpGlobals->partyoffset = PAL_XY(160, 112);
+
+      fclose(fpGOP);
+      fclose(fpMAP);
+   }
+
+   //
+   // Load player sprites
+   //
+   if (gpResources->bLoadFlags & kLoadPlayerSprite)
+   {
+      //
+      // Free previous loaded player sprites
+      //
+      PAL_FreePlayerSprites();
+
+      for (i = 0; i <= (short)gpGlobals->wMaxPartyMemberIndex; i++)
+      {
+         wPlayerID = gpGlobals->rgParty[i].wPlayerRole;
+         assert(wPlayerID < MAX_PLAYER_ROLES);
+
+         //
+         // Load player sprite
+         //
+         wSpriteNum = gpGlobals->g.PlayerRoles.rgwSpriteNum[wPlayerID];
+
+         l = PAL_MKFGetDecompressedSize(wSpriteNum, gpGlobals->f.fpMGO);
+
+         gpResources->rglpPlayerSprite[i] = (LPSPRITE)UTIL_malloc(l);
+
+         PAL_MKFDecompressChunk(gpResources->rglpPlayerSprite[i], l, wSpriteNum,
+            gpGlobals->f.fpMGO);
+      }
+
+      if (gpGlobals->nFollower > 0)
+      {
+         //
+         // Load the follower sprite
+         //
+         wSpriteNum = gpGlobals->rgParty[i].wPlayerRole;
+
+         l = PAL_MKFGetDecompressedSize(wSpriteNum, gpGlobals->f.fpMGO);
+
+         gpResources->rglpPlayerSprite[i] = (LPSPRITE)UTIL_malloc(l);
+
+         PAL_MKFDecompressChunk(gpResources->rglpPlayerSprite[i], l, wSpriteNum,
+            gpGlobals->f.fpMGO);
+      }
+   }
+
+   //
+   // Clear all of the load flags
+   //
+   gpResources->bLoadFlags = 0;
+}
+
+LPPALMAP
+PAL_GetCurrentMap(
+   VOID
+)
+/*++
+  Purpose:
+
+    Get the current loaded map.
+
+  Parameters:
+
+    None.
+
+  Return value:
+
+    Pointer to the current loaded map. NULL if no map is loaded.
+
+--*/
+{
+   if (gpResources == NULL)
+   {
+      return NULL;
+   }
+
+   return gpResources->lpMap;
+}
+
+LPSPRITE
+PAL_GetPlayerSprite(
+   BYTE      bPlayerIndex
+)
+/*++
+  Purpose:
+
+    Get the player sprite.
+
+  Parameters:
+
+    [IN]  bPlayerIndex - index of player in party (starts from 0).
+
+  Return value:
+
+    Pointer to the player sprite.
+
+--*/
+{
+   if (gpResources == NULL || bPlayerIndex > MAX_PLAYERS_IN_PARTY)
+   {
+      return NULL;
+   }
+
+   return gpResources->rglpPlayerSprite[bPlayerIndex];
+}
+
+LPSPRITE
+PAL_GetEventObjectSprite(
+   WORD      wEventObjectID
+)
+/*++
+  Purpose:
+
+    Get the sprite of the specified event object.
+
+  Parameters:
+
+    [IN]  wEventObjectID - the ID of event object.
+
+  Return value:
+
+    Pointer to the sprite.
+
+--*/
+{
+   wEventObjectID -= gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wEventObjectIndex;
+   wEventObjectID--;
+
+   if (gpResources == NULL || wEventObjectID >= gpResources->nEventObject)
+   {
+      return NULL;
+   }
+
+   return gpResources->lppEventObjectSprites[wEventObjectID];
+}

+ 80 - 80
res.h

@@ -1,80 +1,80 @@
-/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
-//
-// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
-// All rights reserved.
-//
-// This file is part of SDLPAL.
-//
-// SDLPAL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef RES_H
-#define RES_H
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-typedef enum tagLOADRESFLAG
-{
-   kLoadScene          = (1 << 0),    // load a scene
-   kLoadPlayerSprite   = (1 << 1),    // load player sprites
-} LOADRESFLAG, *LPLOADRESFLAG;
-
-VOID
-PAL_InitResources(
-   VOID
-);
-
-VOID
-PAL_FreeResources(
-   VOID
-);
-
-VOID
-PAL_SetLoadFlags(
-   BYTE       bFlags
-);
-
-VOID
-PAL_LoadResources(
-   VOID
-);
-
-LPPALMAP
-PAL_GetCurrentMap(
-   VOID
-);
-
-LPSPRITE
-PAL_GetPlayerSprite(
-   BYTE      bPlayerIndex
-);
-
-LPSPRITE
-PAL_GetBattleSprite(
-   BYTE      bPlayerIndex
-);
-
-LPSPRITE
-PAL_GetEventObjectSprite(
-   WORD      wEventObjectID
-);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef RES_H
+#define RES_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef enum tagLOADRESFLAG
+{
+   kLoadScene          = (1 << 0),    // load a scene
+   kLoadPlayerSprite   = (1 << 1),    // load player sprites
+} LOADRESFLAG, *LPLOADRESFLAG;
+
+VOID
+PAL_InitResources(
+   VOID
+);
+
+VOID
+PAL_FreeResources(
+   VOID
+);
+
+VOID
+PAL_SetLoadFlags(
+   BYTE       bFlags
+);
+
+VOID
+PAL_LoadResources(
+   VOID
+);
+
+LPPALMAP
+PAL_GetCurrentMap(
+   VOID
+);
+
+LPSPRITE
+PAL_GetPlayerSprite(
+   BYTE      bPlayerIndex
+);
+
+LPSPRITE
+PAL_GetBattleSprite(
+   BYTE      bPlayerIndex
+);
+
+LPSPRITE
+PAL_GetEventObjectSprite(
+   WORD      wEventObjectID
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

File diff suppressed because it is too large
+ 878 - 878
scene.c


+ 67 - 67
scene.h

@@ -1,67 +1,67 @@
-/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
-//
-// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
-// All rights reserved.
-//
-// This file is part of SDLPAL.
-//
-// SDLPAL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef _SCENE_H
-#define	_SCENE_H
-
-#ifdef	__cplusplus
-extern "C"
-{
-#endif
-
-VOID
-PAL_ApplyWave(
-   SDL_Surface    *lpSurface
-);
-
-VOID
-PAL_MakeScene(
-   VOID
-);
-
-BOOL
-PAL_CheckObstacle(
-   PAL_POS         pos,
-   BOOL            fCheckEventObjects,
-   WORD            wSelfObject
-);
-
-VOID
-PAL_UpdatePartyGestures(
-   BOOL             fWalking
-);
-
-VOID
-PAL_UpdateParty(
-   VOID
-);
-
-VOID
-PAL_NPCWalkOneStep(
-   WORD          wEventObjectID,
-   INT           iSpeed
-);
-
-#ifdef	__cplusplus
-}
-#endif
-
-#endif
+/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef _SCENE_H
+#define	_SCENE_H
+
+#ifdef	__cplusplus
+extern "C"
+{
+#endif
+
+VOID
+PAL_ApplyWave(
+   SDL_Surface    *lpSurface
+);
+
+VOID
+PAL_MakeScene(
+   VOID
+);
+
+BOOL
+PAL_CheckObstacle(
+   PAL_POS         pos,
+   BOOL            fCheckEventObjects,
+   WORD            wSelfObject
+);
+
+VOID
+PAL_UpdatePartyGestures(
+   BOOL             fWalking
+);
+
+VOID
+PAL_UpdateParty(
+   VOID
+);
+
+VOID
+PAL_NPCWalkOneStep(
+   WORD          wEventObjectID,
+   INT           iSpeed
+);
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif

+ 48 - 48
script.h

@@ -1,48 +1,48 @@
-/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
-//
-// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
-// All rights reserved.
-//
-// This file is part of SDLPAL.
-//
-// SDLPAL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef SCRIPT_H
-#define SCRIPT_H
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-WORD
-PAL_RunTriggerScript(
-   WORD           wScriptEntry,
-   WORD           wEventObjectID
-);
-
-WORD
-PAL_RunAutoScript(
-   WORD           wScriptEntry,
-   WORD           wEventObjectID
-);
-
-extern BOOL       g_fScriptSuccess;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef SCRIPT_H
+#define SCRIPT_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+WORD
+PAL_RunTriggerScript(
+   WORD           wScriptEntry,
+   WORD           wEventObjectID
+);
+
+WORD
+PAL_RunAutoScript(
+   WORD           wScriptEntry,
+   WORD           wEventObjectID
+);
+
+extern BOOL       g_fScriptSuccess;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 9 - 9
sdlpal.cproj

@@ -73,11 +73,11 @@
     <None Include="util.h" />
     <None Include="video.h" />
     <None Include="adplug\binfile.h" />
-    <None Include="adplug\binio.h" />
-    <None Include="adplug\demuopl.h" />
-    <None Include="adplug\dosbox_opl.h" />
-    <None Include="adplug\emuopl.h" />
-    <None Include="adplug\fmopl.h" />
+    <None Include="adplug\binio.h" />
+    <None Include="adplug\demuopl.h" />
+    <None Include="adplug\dosbox_opl.h" />
+    <None Include="adplug\emuopl.h" />
+    <None Include="adplug\fmopl.h" />
     <None Include="adplug\fprovide.h" />
     <None Include="adplug\opl.h" />
     <None Include="adplug\player.h" />
@@ -132,10 +132,10 @@
     <Compile Include="yj1.c" />
     <Compile Include="rixplay.cpp" />
     <Compile Include="adplug\binfile.cpp" />
-    <Compile Include="adplug\binio.cpp" />
-    <Compile Include="adplug\dosbox_opl.cpp" />
-    <Compile Include="adplug\emuopl.cpp" />
-    <Compile Include="adplug\fmopl.c" />
+    <Compile Include="adplug\binio.cpp" />
+    <Compile Include="adplug\dosbox_opl.cpp" />
+    <Compile Include="adplug\emuopl.cpp" />
+    <Compile Include="adplug\fmopl.c" />
     <Compile Include="adplug\fprovide.cpp" />
     <Compile Include="adplug\player.cpp" />
     <Compile Include="adplug\rix.cpp" />

File diff suppressed because it is too large
+ 735 - 735
sound.c


+ 87 - 87
sound.h

@@ -1,87 +1,87 @@
-/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
-//
-// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
-// All rights reserved.
-//
-// This file is part of SDLPAL.
-//
-// SDLPAL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef SOUND_H
-#define SOUND_H
-
-#include "common.h"
-
-#ifndef PAL_SAMPLE_RATE
-#define PAL_SAMPLE_RATE     44100 /*49716*/
-#endif
-
-#ifndef PAL_CHANNELS
-#define PAL_CHANNELS        1
-#endif
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-INT
-SOUND_OpenAudio(
-   VOID
-);
-
-VOID
-SOUND_CloseAudio(
-   VOID
-);
-
-VOID
-SOUND_PlayChannel(
-   INT    iSoundNum,
-   INT    iChannel
-);
-
-#ifdef __SYMBIAN32__
-VOID
-SOUND_AdjustVolume(
-   INT    iDirectory
-);
-#endif
-
-VOID
-PAL_PlayMUS(
-   INT       iNumRIX,
-   BOOL      fLoop,
-   FLOAT     flFadeTime
-);
-
-BOOL
-SOUND_PlayCDA(
-   INT    iNumTrack
-);
-
-#define SOUND_Play(i) SOUND_PlayChannel((i), 0)
-
-extern BOOL       g_fNoSound;
-extern BOOL       g_fNoMusic;
-#ifdef PAL_HAS_NATIVEMIDI
-extern BOOL       g_fUseMidi;
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef SOUND_H
+#define SOUND_H
+
+#include "common.h"
+
+#ifndef PAL_SAMPLE_RATE
+#define PAL_SAMPLE_RATE     44100 /*49716*/
+#endif
+
+#ifndef PAL_CHANNELS
+#define PAL_CHANNELS        1
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+INT
+SOUND_OpenAudio(
+   VOID
+);
+
+VOID
+SOUND_CloseAudio(
+   VOID
+);
+
+VOID
+SOUND_PlayChannel(
+   INT    iSoundNum,
+   INT    iChannel
+);
+
+#ifdef __SYMBIAN32__
+VOID
+SOUND_AdjustVolume(
+   INT    iDirectory
+);
+#endif
+
+VOID
+PAL_PlayMUS(
+   INT       iNumRIX,
+   BOOL      fLoop,
+   FLOAT     flFadeTime
+);
+
+BOOL
+SOUND_PlayCDA(
+   INT    iNumTrack
+);
+
+#define SOUND_Play(i) SOUND_PlayChannel((i), 0)
+
+extern BOOL       g_fNoSound;
+extern BOOL       g_fNoMusic;
+#ifdef PAL_HAS_NATIVEMIDI
+extern BOOL       g_fUseMidi;
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 4 - 0
ui.c

@@ -184,6 +184,8 @@ PAL_CreateBox(
 
 #if SDL_VERSION_ATLEAST(2,0,0)
       SDL_SetSurfacePalette(save, gpScreen->format->palette);
+#else
+      SDL_SetPalette(save, SDL_LOGPAL | SDL_PHYSPAL, VIDEO_GetPalette(), 0, 256);
 #endif
       SDL_BlitSurface(gpScreen, &rect, save, NULL);
 
@@ -298,6 +300,8 @@ PAL_CreateSingleLineBox(
 
 #if SDL_VERSION_ATLEAST(2,0,0)
       SDL_SetSurfacePalette(save, gpScreen->format->palette);
+#else
+      SDL_SetPalette(save, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
 #endif
       SDL_BlitSurface(gpScreen, &rect, save, NULL);
 

File diff suppressed because it is too large
+ 1778 - 1778
uibattle.c


+ 153 - 153
uibattle.h

@@ -1,153 +1,153 @@
-/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
-//
-// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
-// All rights reserved.
-//
-// This file is part of SDLPAL.
-//
-// SDLPAL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef UIBATTLE_H
-#define UIBATTLE_H
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include "ui.h"
-
-typedef enum tagBATTLEUISTATE
-{
-   kBattleUIWait,
-   kBattleUISelectMove,
-   kBattleUISelectTargetEnemy,
-   kBattleUISelectTargetPlayer,
-   kBattleUISelectTargetEnemyAll,
-   kBattleUISelectTargetPlayerAll,
-} BATTLEUISTATE;
-
-typedef enum tagBATTLEMENUSTATE
-{
-   kBattleMenuMain,
-   kBattleMenuMagicSelect,
-   kBattleMenuUseItemSelect,
-   kBattleMenuThrowItemSelect,
-   kBattleMenuMisc,
-   kBattleMenuMiscItemSubMenu,
-} BATTLEMENUSTATE;
-
-typedef enum tagBATTLEUIACTION
-{
-   kBattleUIActionAttack,
-   kBattleUIActionMagic,
-   kBattleUIActionCoopMagic,
-   kBattleUIActionMisc,
-} BATTLEUIACTION;
-
-#define SPRITENUM_BATTLEICON_ATTACK      40
-#define SPRITENUM_BATTLEICON_MAGIC       41
-#define SPRITENUM_BATTLEICON_COOPMAGIC   42
-#define SPRITENUM_BATTLEICON_MISCMENU    43
-
-#define SPRITENUM_BATTLE_ARROW_CURRENTPLAYER           69
-#define SPRITENUM_BATTLE_ARROW_CURRENTPLAYER_RED       68
-
-#define SPRITENUM_BATTLE_ARROW_SELECTEDPLAYER          67
-#define SPRITENUM_BATTLE_ARROW_SELECTEDPLAYER_RED      66
-
-#define BATTLEUI_LABEL_ITEM              5
-#define BATTLEUI_LABEL_DEFEND            58
-#define BATTLEUI_LABEL_AUTO              56
-#define BATTLEUI_LABEL_INVENTORY         57
-#define BATTLEUI_LABEL_FLEE              59
-#define BATTLEUI_LABEL_STATUS            60
-
-#define BATTLEUI_LABEL_USEITEM           23
-#define BATTLEUI_LABEL_THROWITEM         24
-
-#define TIMEMETER_COLOR_DEFAULT          0x1B
-#define TIMEMETER_COLOR_SLOW             0x5B
-#define TIMEMETER_COLOR_HASTE            0x2A
-
-#define BATTLEUI_MAX_SHOWNUM             16
-
-typedef struct tagSHOWNUM
-{
-   WORD             wNum;
-   PAL_POS          pos;
-   DWORD            dwTime;
-   NUMCOLOR         color;
-} SHOWNUM;
-
-typedef struct tagBATTLEUI
-{
-   BATTLEUISTATE    state;
-   BATTLEMENUSTATE  MenuState;
-
-   CHAR             szMsg[256];           // message to be shown on the screen
-   CHAR             szNextMsg[256];       // next message to be shown on the screen
-   DWORD            dwMsgShowTime;        // the end time of showing the message
-   WORD             wNextMsgDuration;     // duration of the next message
-
-   WORD             wCurPlayerIndex;      // index of the current player
-   WORD             wSelectedAction;      // current selected action
-   WORD             wSelectedIndex;       // current selected index of player or enemy
-   WORD             wPrevEnemyTarget;     // previous enemy target
-
-   WORD             wActionType;          // type of action to be performed
-   WORD             wObjectID;            // object ID of the item or magic to use
-
-   BOOL             fAutoAttack;          // TRUE if auto attack
-
-   SHOWNUM          rgShowNum[BATTLEUI_MAX_SHOWNUM];
-} BATTLEUI;
-
-VOID
-PAL_PlayerInfoBox(
-   PAL_POS         pos,
-   WORD            wPlayerRole,
-   INT             iTimeMeter,
-   BYTE            bTimeMeterColor,
-   BOOL            fUpdate
-);
-
-VOID
-PAL_BattleUIShowText(
-   LPCSTR        lpszText,
-   WORD          wDuration
-);
-
-VOID
-PAL_BattleUIPlayerReady(
-   WORD          wPlayerIndex
-);
-
-VOID
-PAL_BattleUIUpdate(
-   VOID
-);
-
-VOID
-PAL_BattleUIShowNum(
-   WORD           wNum,
-   PAL_POS        pos,
-   NUMCOLOR       color
-);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
+/* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef UIBATTLE_H
+#define UIBATTLE_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ui.h"
+
+typedef enum tagBATTLEUISTATE
+{
+   kBattleUIWait,
+   kBattleUISelectMove,
+   kBattleUISelectTargetEnemy,
+   kBattleUISelectTargetPlayer,
+   kBattleUISelectTargetEnemyAll,
+   kBattleUISelectTargetPlayerAll,
+} BATTLEUISTATE;
+
+typedef enum tagBATTLEMENUSTATE
+{
+   kBattleMenuMain,
+   kBattleMenuMagicSelect,
+   kBattleMenuUseItemSelect,
+   kBattleMenuThrowItemSelect,
+   kBattleMenuMisc,
+   kBattleMenuMiscItemSubMenu,
+} BATTLEMENUSTATE;
+
+typedef enum tagBATTLEUIACTION
+{
+   kBattleUIActionAttack,
+   kBattleUIActionMagic,
+   kBattleUIActionCoopMagic,
+   kBattleUIActionMisc,
+} BATTLEUIACTION;
+
+#define SPRITENUM_BATTLEICON_ATTACK      40
+#define SPRITENUM_BATTLEICON_MAGIC       41
+#define SPRITENUM_BATTLEICON_COOPMAGIC   42
+#define SPRITENUM_BATTLEICON_MISCMENU    43
+
+#define SPRITENUM_BATTLE_ARROW_CURRENTPLAYER           69
+#define SPRITENUM_BATTLE_ARROW_CURRENTPLAYER_RED       68
+
+#define SPRITENUM_BATTLE_ARROW_SELECTEDPLAYER          67
+#define SPRITENUM_BATTLE_ARROW_SELECTEDPLAYER_RED      66
+
+#define BATTLEUI_LABEL_ITEM              5
+#define BATTLEUI_LABEL_DEFEND            58
+#define BATTLEUI_LABEL_AUTO              56
+#define BATTLEUI_LABEL_INVENTORY         57
+#define BATTLEUI_LABEL_FLEE              59
+#define BATTLEUI_LABEL_STATUS            60
+
+#define BATTLEUI_LABEL_USEITEM           23
+#define BATTLEUI_LABEL_THROWITEM         24
+
+#define TIMEMETER_COLOR_DEFAULT          0x1B
+#define TIMEMETER_COLOR_SLOW             0x5B
+#define TIMEMETER_COLOR_HASTE            0x2A
+
+#define BATTLEUI_MAX_SHOWNUM             16
+
+typedef struct tagSHOWNUM
+{
+   WORD             wNum;
+   PAL_POS          pos;
+   DWORD            dwTime;
+   NUMCOLOR         color;
+} SHOWNUM;
+
+typedef struct tagBATTLEUI
+{
+   BATTLEUISTATE    state;
+   BATTLEMENUSTATE  MenuState;
+
+   CHAR             szMsg[256];           // message to be shown on the screen
+   CHAR             szNextMsg[256];       // next message to be shown on the screen
+   DWORD            dwMsgShowTime;        // the end time of showing the message
+   WORD             wNextMsgDuration;     // duration of the next message
+
+   WORD             wCurPlayerIndex;      // index of the current player
+   WORD             wSelectedAction;      // current selected action
+   WORD             wSelectedIndex;       // current selected index of player or enemy
+   WORD             wPrevEnemyTarget;     // previous enemy target
+
+   WORD             wActionType;          // type of action to be performed
+   WORD             wObjectID;            // object ID of the item or magic to use
+
+   BOOL             fAutoAttack;          // TRUE if auto attack
+
+   SHOWNUM          rgShowNum[BATTLEUI_MAX_SHOWNUM];
+} BATTLEUI;
+
+VOID
+PAL_PlayerInfoBox(
+   PAL_POS         pos,
+   WORD            wPlayerRole,
+   INT             iTimeMeter,
+   BYTE            bTimeMeterColor,
+   BOOL            fUpdate
+);
+
+VOID
+PAL_BattleUIShowText(
+   LPCSTR        lpszText,
+   WORD          wDuration
+);
+
+VOID
+PAL_BattleUIPlayerReady(
+   WORD          wPlayerIndex
+);
+
+VOID
+PAL_BattleUIUpdate(
+   VOID
+);
+
+VOID
+PAL_BattleUIShowNum(
+   WORD           wNum,
+   PAL_POS        pos,
+   NUMCOLOR       color
+);
+
+#ifdef __cplusplus
+}
+#endif
+#endif

File diff suppressed because it is too large
+ 573 - 573
util.c


+ 1 - 0
video.c

@@ -546,6 +546,7 @@ VIDEO_SetPalette(
    VIDEO_UpdateScreen(NULL);
 #else
    SDL_SetPalette(gpScreen, SDL_LOGPAL | SDL_PHYSPAL, rgPalette, 0, 256);
+   SDL_SetPalette(gpScreenBak, SDL_LOGPAL | SDL_PHYSPAL, rgPalette, 0, 256);
    SDL_SetPalette(gpScreenReal, SDL_LOGPAL | SDL_PHYSPAL, rgPalette, 0, 256);
 #if (defined (__SYMBIAN32__))
    {

+ 260 - 260
yj1.c

@@ -24,12 +24,12 @@
 
 // Ported to C from C++ and modified for compatibility with Big-Endian
 // by Wei Mingzhi <whistler@openoffice.org>.
-
-// TODO: fix YJ_2 for big-endian
+
+// TODO: fix YJ_2 for big-endian
 
 #include "common.h"
-
-#ifndef PAL_WIN95
+
+#ifndef PAL_WIN95
 
 typedef struct _TreeNode
 {
@@ -237,259 +237,259 @@ Decompress(
 
    return SWAP32(hdr->UncompressedLength);
 }
-
-#else
-
-typedef struct _TreeNode
-{
-   unsigned short      weight;
-   unsigned short      value;
-   struct _TreeNode*   parent;
-   struct _TreeNode*   left;
-   struct _TreeNode*   right;
-} TreeNode;
-
-typedef struct _Tree
-{
-   TreeNode*   node;
-   TreeNode**   list;
-} Tree;
-
-static unsigned char data1[0x100] =
-{
-0x3f,0x0b,0x17,0x03,0x2f,0x0a,0x16,0x00,0x2e,0x09,0x15,0x02,0x2d,0x01,0x08,0x00,
-0x3e,0x07,0x14,0x03,0x2c,0x06,0x13,0x00,0x2b,0x05,0x12,0x02,0x2a,0x01,0x04,0x00,
-0x3d,0x0b,0x11,0x03,0x29,0x0a,0x10,0x00,0x28,0x09,0x0f,0x02,0x27,0x01,0x08,0x00,
-0x3c,0x07,0x0e,0x03,0x26,0x06,0x0d,0x00,0x25,0x05,0x0c,0x02,0x24,0x01,0x04,0x00,
-0x3b,0x0b,0x17,0x03,0x23,0x0a,0x16,0x00,0x22,0x09,0x15,0x02,0x21,0x01,0x08,0x00,
-0x3a,0x07,0x14,0x03,0x20,0x06,0x13,0x00,0x1f,0x05,0x12,0x02,0x1e,0x01,0x04,0x00,
-0x39,0x0b,0x11,0x03,0x1d,0x0a,0x10,0x00,0x1c,0x09,0x0f,0x02,0x1b,0x01,0x08,0x00,
-0x38,0x07,0x0e,0x03,0x1a,0x06,0x0d,0x00,0x19,0x05,0x0c,0x02,0x18,0x01,0x04,0x00,
-0x37,0x0b,0x17,0x03,0x2f,0x0a,0x16,0x00,0x2e,0x09,0x15,0x02,0x2d,0x01,0x08,0x00,
-0x36,0x07,0x14,0x03,0x2c,0x06,0x13,0x00,0x2b,0x05,0x12,0x02,0x2a,0x01,0x04,0x00,
-0x35,0x0b,0x11,0x03,0x29,0x0a,0x10,0x00,0x28,0x09,0x0f,0x02,0x27,0x01,0x08,0x00,
-0x34,0x07,0x0e,0x03,0x26,0x06,0x0d,0x00,0x25,0x05,0x0c,0x02,0x24,0x01,0x04,0x00,
-0x33,0x0b,0x17,0x03,0x23,0x0a,0x16,0x00,0x22,0x09,0x15,0x02,0x21,0x01,0x08,0x00,
-0x32,0x07,0x14,0x03,0x20,0x06,0x13,0x00,0x1f,0x05,0x12,0x02,0x1e,0x01,0x04,0x00,
-0x31,0x0b,0x11,0x03,0x1d,0x0a,0x10,0x00,0x1c,0x09,0x0f,0x02,0x1b,0x01,0x08,0x00,
-0x30,0x07,0x0e,0x03,0x1a,0x06,0x0d,0x00,0x19,0x05,0x0c,0x02,0x18,0x01,0x04,0x00
-};
-static unsigned char data2[0x10] =
-{
-0x08,0x05,0x06,0x04,0x07,0x05,0x06,0x03,0x07,0x05,0x06,0x04,0x07,0x04,0x05,0x03
-};
-
-static void adjust_tree(Tree tree, unsigned short value)
-{
-   TreeNode* node = tree.list[value];
-   TreeNode tmp;
-   TreeNode* tmp1;
-   TreeNode* temp;
-   while(node->value != 0x280)
-   {
-      temp = node + 1;
-      while(node->weight == temp->weight)
-         temp++;
-      temp--;
-      if (temp != node)
-      {
-         tmp1 = node->parent;
-         node->parent = temp->parent;
-         temp->parent = tmp1;
-         if (node->value > 0x140)
-         {
-            node->left->parent = temp;
-            node->right->parent = temp;
-         }
-         else
-            tree.list[node->value] = temp;
-         if (temp->value > 0x140)
-         {
-            temp->left->parent = node;
-            temp->right->parent = node;
-         }
-         else
-            tree.list[temp->value] = node;
-         tmp = *node; *node = *temp; *temp = tmp;
-         node = temp;
-      }
-      node->weight++;
-      node = node->parent;
-   }
-   node->weight++;
-}
-
-static int build_tree(Tree *tree)
-{
-   int i, ptr;
-   TreeNode** list;
-   TreeNode* node;
-   if ((tree->list = list = (TreeNode **)malloc(sizeof(TreeNode*) * 321)) == NULL)
-      return 0;
-   if ((tree->node = node = (TreeNode *)malloc(sizeof(TreeNode) * 641)) == NULL)
-   {
-      free(list);
-      return 0;
-   }
-   memset(list, 0, 321 * sizeof(TreeNode*));
-   memset(node, 0, 641 * sizeof(TreeNode));
-   for(i = 0; i <= 0x140; i++)
-      list[i] = node + i;
-   for(i = 0; i <= 0x280; i++)
-   {
-      node[i].value = i;
-      node[i].weight = 1;
-   }
-   tree->node[0x280].parent = tree->node + 0x280;
-   for(i = 0, ptr = 0x141; ptr <= 0x280; i += 2, ptr++)
-   {
-      node[ptr].left = node + i;
-      node[ptr].right = node + i + 1;
-      node[i].parent = node[i + 1].parent = node + ptr;
-      node[ptr].weight = node[i].weight + node[i + 1].weight;
-   }
-   return 1;
-}
-
-#pragma pack(1)
-typedef struct _BitField
-{
-   unsigned char   b0:   1;
-   unsigned char   b1:   1;
-   unsigned char   b2:   1;
-   unsigned char   b3:   1;
-   unsigned char   b4:   1;
-   unsigned char   b5:   1;
-   unsigned char   b6:   1;
-   unsigned char   b7:   1;
-} BitField;
-#pragma pack()
-
-static int bt(const void* data, unsigned int pos)
-{
-   BitField* bit = (BitField*)((unsigned char*)data + (pos >> 3));
-   switch(pos & 0x7)
-   {
-   case 0:   return bit->b0;
-   case 1:   return bit->b1;
-   case 2:   return bit->b2;
-   case 3:   return bit->b3;
-   case 4:   return bit->b4;
-   case 5:   return bit->b5;
-   case 6:   return bit->b6;
-   case 7:   return bit->b7;
-   }
-   return 0;
-}
-
-static void bit(void* data, unsigned int pos, int set)
-{
-   BitField* bit = (BitField*)((unsigned char*)data + (pos >> 3));
-   switch(pos & 0x7)
-   {
-   case 0:
-      bit->b0 = set;
-      break;
-   case 1:
-      bit->b1 = set;
-      break;
-   case 2:
-      bit->b2 = set;
-      break;
-   case 3:
-      bit->b3 = set;
-      break;
-   case 4:
-      bit->b4 = set;
-      break;
-   case 5:
-      bit->b5 = set;
-      break;
-   case 6:
-      bit->b6 = set;
-      break;
-   case 7:
-      bit->b7 = set;
-      break;
-   }
-}
-
-INT
-Decompress(
-   LPCVOID       Source,
-   LPVOID        Destination,
-   INT           DestSize
-)
-{
-   unsigned int len = 0, ptr = 0, Length = 0;
-   unsigned char* src = (unsigned char*)Source + 4;
-   unsigned char* dest;
-   Tree tree;
-   TreeNode* node;
-
-   if (Source == NULL)
-      return -1;
-
-   if (!build_tree(&tree))
-      return -1;
-
-   Length = SWAP32(*((unsigned int*)Source));
-   if (Length > DestSize)
-      return -1;
-   dest = (unsigned char*)Destination;
-
-   while (1)
-   {
-      unsigned short val;
-      node = tree.node + 0x280;
-      while(node->value > 0x140)
-      {
-         if (bt(src, ptr))
-            node = node->right;
-         else
-            node = node->left;
-         ptr++;
-      }
-      val = node->value;
-      if (tree.node[0x280].weight == 0x8000)
-      {
-         int i;
-         for(i = 0; i < 0x141; i++)
-            if (tree.list[i]->weight & 0x1)
-               adjust_tree(tree, i);
-         for(i = 0; i <= 0x280; i++)
-            tree.node[i].weight >>= 1;
-      }
-      adjust_tree(tree, val);
-      if (val > 0xff)
-      {
-         int i;
-         unsigned int temp, tmp, pos;
-         unsigned char* pre;
-         for(i = 0, temp = 0; i < 8; i++, ptr++)
-            temp |= (unsigned int)bt(src, ptr) << i;
-         tmp = temp & 0xff;
-         for(; i < data2[tmp & 0xf] + 6; i++, ptr++)
-            temp |= (unsigned int)bt(src, ptr) << i;
-         temp >>= data2[tmp & 0xf];
-         pos = (temp & 0x3f) | ((unsigned int)data1[tmp] << 6);
-         if (pos == 0xfff)
-            break;
-         pre = dest - pos - 1;
-         for(i = 0; i < val - 0xfd; i++)
-            *dest++ = *pre++;
-         len += val - 0xfd;
-      }
-      else
-      {
-         *dest++ = (unsigned char)val;
-         len++;
-      }
-   }
-
-   free(tree.list);
-   free(tree.node);
-   return Length;
-}
-
-#endif
+
+#else
+
+typedef struct _TreeNode
+{
+   unsigned short      weight;
+   unsigned short      value;
+   struct _TreeNode*   parent;
+   struct _TreeNode*   left;
+   struct _TreeNode*   right;
+} TreeNode;
+
+typedef struct _Tree
+{
+   TreeNode*   node;
+   TreeNode**   list;
+} Tree;
+
+static unsigned char data1[0x100] =
+{
+0x3f,0x0b,0x17,0x03,0x2f,0x0a,0x16,0x00,0x2e,0x09,0x15,0x02,0x2d,0x01,0x08,0x00,
+0x3e,0x07,0x14,0x03,0x2c,0x06,0x13,0x00,0x2b,0x05,0x12,0x02,0x2a,0x01,0x04,0x00,
+0x3d,0x0b,0x11,0x03,0x29,0x0a,0x10,0x00,0x28,0x09,0x0f,0x02,0x27,0x01,0x08,0x00,
+0x3c,0x07,0x0e,0x03,0x26,0x06,0x0d,0x00,0x25,0x05,0x0c,0x02,0x24,0x01,0x04,0x00,
+0x3b,0x0b,0x17,0x03,0x23,0x0a,0x16,0x00,0x22,0x09,0x15,0x02,0x21,0x01,0x08,0x00,
+0x3a,0x07,0x14,0x03,0x20,0x06,0x13,0x00,0x1f,0x05,0x12,0x02,0x1e,0x01,0x04,0x00,
+0x39,0x0b,0x11,0x03,0x1d,0x0a,0x10,0x00,0x1c,0x09,0x0f,0x02,0x1b,0x01,0x08,0x00,
+0x38,0x07,0x0e,0x03,0x1a,0x06,0x0d,0x00,0x19,0x05,0x0c,0x02,0x18,0x01,0x04,0x00,
+0x37,0x0b,0x17,0x03,0x2f,0x0a,0x16,0x00,0x2e,0x09,0x15,0x02,0x2d,0x01,0x08,0x00,
+0x36,0x07,0x14,0x03,0x2c,0x06,0x13,0x00,0x2b,0x05,0x12,0x02,0x2a,0x01,0x04,0x00,
+0x35,0x0b,0x11,0x03,0x29,0x0a,0x10,0x00,0x28,0x09,0x0f,0x02,0x27,0x01,0x08,0x00,
+0x34,0x07,0x0e,0x03,0x26,0x06,0x0d,0x00,0x25,0x05,0x0c,0x02,0x24,0x01,0x04,0x00,
+0x33,0x0b,0x17,0x03,0x23,0x0a,0x16,0x00,0x22,0x09,0x15,0x02,0x21,0x01,0x08,0x00,
+0x32,0x07,0x14,0x03,0x20,0x06,0x13,0x00,0x1f,0x05,0x12,0x02,0x1e,0x01,0x04,0x00,
+0x31,0x0b,0x11,0x03,0x1d,0x0a,0x10,0x00,0x1c,0x09,0x0f,0x02,0x1b,0x01,0x08,0x00,
+0x30,0x07,0x0e,0x03,0x1a,0x06,0x0d,0x00,0x19,0x05,0x0c,0x02,0x18,0x01,0x04,0x00
+};
+static unsigned char data2[0x10] =
+{
+0x08,0x05,0x06,0x04,0x07,0x05,0x06,0x03,0x07,0x05,0x06,0x04,0x07,0x04,0x05,0x03
+};
+
+static void adjust_tree(Tree tree, unsigned short value)
+{
+   TreeNode* node = tree.list[value];
+   TreeNode tmp;
+   TreeNode* tmp1;
+   TreeNode* temp;
+   while(node->value != 0x280)
+   {
+      temp = node + 1;
+      while(node->weight == temp->weight)
+         temp++;
+      temp--;
+      if (temp != node)
+      {
+         tmp1 = node->parent;
+         node->parent = temp->parent;
+         temp->parent = tmp1;
+         if (node->value > 0x140)
+         {
+            node->left->parent = temp;
+            node->right->parent = temp;
+         }
+         else
+            tree.list[node->value] = temp;
+         if (temp->value > 0x140)
+         {
+            temp->left->parent = node;
+            temp->right->parent = node;
+         }
+         else
+            tree.list[temp->value] = node;
+         tmp = *node; *node = *temp; *temp = tmp;
+         node = temp;
+      }
+      node->weight++;
+      node = node->parent;
+   }
+   node->weight++;
+}
+
+static int build_tree(Tree *tree)
+{
+   int i, ptr;
+   TreeNode** list;
+   TreeNode* node;
+   if ((tree->list = list = (TreeNode **)malloc(sizeof(TreeNode*) * 321)) == NULL)
+      return 0;
+   if ((tree->node = node = (TreeNode *)malloc(sizeof(TreeNode) * 641)) == NULL)
+   {
+      free(list);
+      return 0;
+   }
+   memset(list, 0, 321 * sizeof(TreeNode*));
+   memset(node, 0, 641 * sizeof(TreeNode));
+   for(i = 0; i <= 0x140; i++)
+      list[i] = node + i;
+   for(i = 0; i <= 0x280; i++)
+   {
+      node[i].value = i;
+      node[i].weight = 1;
+   }
+   tree->node[0x280].parent = tree->node + 0x280;
+   for(i = 0, ptr = 0x141; ptr <= 0x280; i += 2, ptr++)
+   {
+      node[ptr].left = node + i;
+      node[ptr].right = node + i + 1;
+      node[i].parent = node[i + 1].parent = node + ptr;
+      node[ptr].weight = node[i].weight + node[i + 1].weight;
+   }
+   return 1;
+}
+
+#pragma pack(1)
+typedef struct _BitField
+{
+   unsigned char   b0:   1;
+   unsigned char   b1:   1;
+   unsigned char   b2:   1;
+   unsigned char   b3:   1;
+   unsigned char   b4:   1;
+   unsigned char   b5:   1;
+   unsigned char   b6:   1;
+   unsigned char   b7:   1;
+} BitField;
+#pragma pack()
+
+static int bt(const void* data, unsigned int pos)
+{
+   BitField* bit = (BitField*)((unsigned char*)data + (pos >> 3));
+   switch(pos & 0x7)
+   {
+   case 0:   return bit->b0;
+   case 1:   return bit->b1;
+   case 2:   return bit->b2;
+   case 3:   return bit->b3;
+   case 4:   return bit->b4;
+   case 5:   return bit->b5;
+   case 6:   return bit->b6;
+   case 7:   return bit->b7;
+   }
+   return 0;
+}
+
+static void bit(void* data, unsigned int pos, int set)
+{
+   BitField* bit = (BitField*)((unsigned char*)data + (pos >> 3));
+   switch(pos & 0x7)
+   {
+   case 0:
+      bit->b0 = set;
+      break;
+   case 1:
+      bit->b1 = set;
+      break;
+   case 2:
+      bit->b2 = set;
+      break;
+   case 3:
+      bit->b3 = set;
+      break;
+   case 4:
+      bit->b4 = set;
+      break;
+   case 5:
+      bit->b5 = set;
+      break;
+   case 6:
+      bit->b6 = set;
+      break;
+   case 7:
+      bit->b7 = set;
+      break;
+   }
+}
+
+INT
+Decompress(
+   LPCVOID       Source,
+   LPVOID        Destination,
+   INT           DestSize
+)
+{
+   unsigned int len = 0, ptr = 0, Length = 0;
+   unsigned char* src = (unsigned char*)Source + 4;
+   unsigned char* dest;
+   Tree tree;
+   TreeNode* node;
+
+   if (Source == NULL)
+      return -1;
+
+   if (!build_tree(&tree))
+      return -1;
+
+   Length = SWAP32(*((unsigned int*)Source));
+   if (Length > DestSize)
+      return -1;
+   dest = (unsigned char*)Destination;
+
+   while (1)
+   {
+      unsigned short val;
+      node = tree.node + 0x280;
+      while(node->value > 0x140)
+      {
+         if (bt(src, ptr))
+            node = node->right;
+         else
+            node = node->left;
+         ptr++;
+      }
+      val = node->value;
+      if (tree.node[0x280].weight == 0x8000)
+      {
+         int i;
+         for(i = 0; i < 0x141; i++)
+            if (tree.list[i]->weight & 0x1)
+               adjust_tree(tree, i);
+         for(i = 0; i <= 0x280; i++)
+            tree.node[i].weight >>= 1;
+      }
+      adjust_tree(tree, val);
+      if (val > 0xff)
+      {
+         int i;
+         unsigned int temp, tmp, pos;
+         unsigned char* pre;
+         for(i = 0, temp = 0; i < 8; i++, ptr++)
+            temp |= (unsigned int)bt(src, ptr) << i;
+         tmp = temp & 0xff;
+         for(; i < data2[tmp & 0xf] + 6; i++, ptr++)
+            temp |= (unsigned int)bt(src, ptr) << i;
+         temp >>= data2[tmp & 0xf];
+         pos = (temp & 0x3f) | ((unsigned int)data1[tmp] << 6);
+         if (pos == 0xfff)
+            break;
+         pre = dest - pos - 1;
+         for(i = 0; i < val - 0xfd; i++)
+            *dest++ = *pre++;
+         len += val - 0xfd;
+      }
+      else
+      {
+         *dest++ = (unsigned char)val;
+         len++;
+      }
+   }
+
+   free(tree.list);
+   free(tree.node);
+   return Length;
+}
+
+#endif