ending.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
  2. //
  3. // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
  4. // All rights reserved.
  5. //
  6. // This file is part of SDLPAL.
  7. //
  8. // SDLPAL is free software: you can redistribute it and/or modify
  9. // it under the terms of the GNU General Public License as published by
  10. // the Free Software Foundation, either version 3 of the License, or
  11. // (at your option) any later version.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU General Public License
  19. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. //
  21. #include "main.h"
  22. static WORD g_wCurEffectSprite = 0;
  23. VOID
  24. PAL_EndingSetEffectSprite(
  25. WORD wSpriteNum
  26. )
  27. /*++
  28. Purpose:
  29. Set the effect sprite of the ending.
  30. Parameters:
  31. [IN] wSpriteNum - the number of the sprite.
  32. Return value:
  33. None.
  34. --*/
  35. {
  36. g_wCurEffectSprite = wSpriteNum;
  37. }
  38. VOID
  39. PAL_ShowFBP(
  40. WORD wChunkNum,
  41. WORD wFade
  42. )
  43. /*++
  44. Purpose:
  45. Draw an FBP picture to the screen.
  46. Parameters:
  47. [IN] wChunkNum - number of chunk in fbp.mkf file.
  48. [IN] wFade - fading speed of showing the picture.
  49. Return value:
  50. None.
  51. --*/
  52. {
  53. PAL_LARGE BYTE buf[320 * 200];
  54. PAL_LARGE BYTE bufSprite[320 * 200];
  55. const int rgIndex[6] = {0, 3, 1, 5, 2, 4};
  56. SDL_Surface *p;
  57. int i, j, k;
  58. BYTE a, b;
  59. if (PAL_MKFDecompressChunk(buf, 320 * 200, wChunkNum, gpGlobals->f.fpFBP) <= 0)
  60. {
  61. memset(buf, 0, sizeof(buf));
  62. }
  63. if (g_wCurEffectSprite != 0)
  64. {
  65. PAL_MKFDecompressChunk(bufSprite, 320 * 200, g_wCurEffectSprite, gpGlobals->f.fpMGO);
  66. }
  67. if (wFade)
  68. {
  69. wFade++;
  70. wFade *= 10;
  71. p = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
  72. gpScreen->format->Rmask, gpScreen->format->Gmask,
  73. gpScreen->format->Bmask, gpScreen->format->Amask);
  74. #if SDL_VERSION_ATLEAST(2, 0, 0)
  75. SDL_SetSurfacePalette(p, gpScreen->format->palette);
  76. #else
  77. SDL_SetPalette(p, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  78. #endif
  79. PAL_FBPBlitToSurface(buf, p);
  80. VIDEO_BackupScreen();
  81. for (i = 0; i < 16; i++)
  82. {
  83. for (j = 0; j < 6; j++)
  84. {
  85. //
  86. // Blend the pixels in the 2 buffers, and put the result into the
  87. // backup buffer
  88. //
  89. for (k = rgIndex[j]; k < gpScreen->pitch * gpScreen->h; k += 6)
  90. {
  91. a = ((LPBYTE)(p->pixels))[k];
  92. b = ((LPBYTE)(gpScreenBak->pixels))[k];
  93. if (i > 0)
  94. {
  95. if ((a & 0x0F) > (b & 0x0F))
  96. {
  97. b++;
  98. }
  99. else if ((a & 0x0F) < (b & 0x0F))
  100. {
  101. b--;
  102. }
  103. }
  104. ((LPBYTE)(gpScreenBak->pixels))[k] = ((a & 0xF0) | (b & 0x0F));
  105. }
  106. SDL_BlitSurface(gpScreenBak, NULL, gpScreen, NULL);
  107. if (g_wCurEffectSprite != 0)
  108. {
  109. int f = SDL_GetTicks() / 150;
  110. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufSprite, f % PAL_SpriteGetNumFrames(bufSprite)),
  111. gpScreen, PAL_XY(0, 0));
  112. }
  113. VIDEO_UpdateScreen(NULL);
  114. UTIL_Delay(wFade);
  115. }
  116. }
  117. SDL_FreeSurface(p);
  118. }
  119. //
  120. // HACKHACK: to make the ending show correctly
  121. //
  122. #ifdef PAL_WIN95
  123. if (wChunkNum != 68)
  124. #else
  125. if (wChunkNum != 49)
  126. #endif
  127. {
  128. PAL_FBPBlitToSurface(buf, gpScreen);
  129. }
  130. VIDEO_UpdateScreen(NULL);
  131. }
  132. VOID
  133. PAL_ScrollFBP(
  134. WORD wChunkNum,
  135. WORD wScrollSpeed,
  136. BOOL fScrollDown
  137. )
  138. /*++
  139. Purpose:
  140. Scroll up an FBP picture to the screen.
  141. Parameters:
  142. [IN] wChunkNum - number of chunk in fbp.mkf file.
  143. [IN] wScrollSpeed - scrolling speed of showing the picture.
  144. [IN] fScrollDown - TRUE if scroll down, FALSE if scroll up.
  145. Return value:
  146. None.
  147. --*/
  148. {
  149. SDL_Surface *p;
  150. PAL_LARGE BYTE buf[320 * 200];
  151. PAL_LARGE BYTE bufSprite[320 * 200];
  152. int i, l;
  153. SDL_Rect rect, dstrect;
  154. if (PAL_MKFDecompressChunk(buf, 320 * 200, wChunkNum, gpGlobals->f.fpFBP) <= 0)
  155. {
  156. return;
  157. }
  158. if (g_wCurEffectSprite != 0)
  159. {
  160. PAL_MKFDecompressChunk(bufSprite, 320 * 200, g_wCurEffectSprite, gpGlobals->f.fpMGO);
  161. }
  162. p = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
  163. gpScreen->format->Rmask, gpScreen->format->Gmask,
  164. gpScreen->format->Bmask, gpScreen->format->Amask);
  165. if (p == NULL)
  166. {
  167. return;
  168. }
  169. #if SDL_VERSION_ATLEAST(2, 0, 0)
  170. SDL_SetSurfacePalette(p, gpScreen->format->palette);
  171. #else
  172. SDL_SetPalette(p, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  173. #endif
  174. VIDEO_BackupScreen();
  175. PAL_FBPBlitToSurface(buf, p);
  176. if (wScrollSpeed == 0)
  177. {
  178. wScrollSpeed = 1;
  179. }
  180. rect.x = 0;
  181. rect.w = 320;
  182. dstrect.x = 0;
  183. dstrect.w = 320;
  184. for (l = 0; l < 220; l++)
  185. {
  186. i = l;
  187. if (i > 200)
  188. {
  189. i = 200;
  190. }
  191. if (fScrollDown)
  192. {
  193. rect.y = 0;
  194. dstrect.y = i;
  195. rect.h = 200 - i;
  196. dstrect.h = 200 - i;
  197. }
  198. else
  199. {
  200. rect.y = i;
  201. dstrect.y = 0;
  202. rect.h = 200 - i;
  203. dstrect.h = 200 - i;
  204. }
  205. SDL_BlitSurface(gpScreenBak, &rect, gpScreen, &dstrect);
  206. if (fScrollDown)
  207. {
  208. rect.y = 200 - i;
  209. dstrect.y = 0;
  210. rect.h = i;
  211. dstrect.h = i;
  212. }
  213. else
  214. {
  215. rect.y = 0;
  216. dstrect.y = 200 - i;
  217. rect.h = i;
  218. dstrect.h = i;
  219. }
  220. SDL_BlitSurface(p, &rect, gpScreen, &dstrect);
  221. PAL_ApplyWave(gpScreen);
  222. if (g_wCurEffectSprite != 0)
  223. {
  224. int f = SDL_GetTicks() / 150;
  225. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufSprite, f % PAL_SpriteGetNumFrames(bufSprite)),
  226. gpScreen, PAL_XY(0, 0));
  227. }
  228. VIDEO_UpdateScreen(NULL);
  229. if (gpGlobals->fNeedToFadeIn)
  230. {
  231. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
  232. gpGlobals->fNeedToFadeIn = FALSE;
  233. #if SDL_VERSION_ATLEAST(2, 0, 0)
  234. SDL_SetSurfacePalette(p, gpScreen->format->palette);
  235. #else
  236. SDL_SetPalette(p, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  237. #endif
  238. }
  239. UTIL_Delay(800 / wScrollSpeed);
  240. }
  241. SDL_BlitSurface(p, NULL, gpScreen, NULL);
  242. SDL_FreeSurface(p);
  243. VIDEO_UpdateScreen(NULL);
  244. }
  245. VOID
  246. PAL_EndingAnimation(
  247. VOID
  248. )
  249. /*++
  250. Purpose:
  251. Show the ending animation.
  252. Parameters:
  253. None.
  254. Return value:
  255. None.
  256. --*/
  257. {
  258. LPBYTE buf;
  259. LPBYTE bufGirl;
  260. SDL_Surface *pUpper;
  261. SDL_Surface *pLower;
  262. SDL_Rect srcrect, dstrect;
  263. int yPosGirl = 180;
  264. int i;
  265. buf = (LPBYTE)UTIL_calloc(1, 64000);
  266. bufGirl = (LPBYTE)UTIL_calloc(1, 6000);
  267. pUpper = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
  268. gpScreen->format->Rmask, gpScreen->format->Gmask,
  269. gpScreen->format->Bmask, gpScreen->format->Amask);
  270. pLower = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
  271. gpScreen->format->Rmask, gpScreen->format->Gmask,
  272. gpScreen->format->Bmask, gpScreen->format->Amask);
  273. #if SDL_VERSION_ATLEAST(2, 0, 0)
  274. SDL_SetSurfacePalette(pUpper, gpScreen->format->palette);
  275. SDL_SetSurfacePalette(pLower, gpScreen->format->palette);
  276. #else
  277. SDL_SetPalette(pUpper, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  278. SDL_SetPalette(pLower, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  279. #endif
  280. #ifdef PAL_WIN95
  281. PAL_MKFDecompressChunk(buf, 64000, 69, gpGlobals->f.fpFBP);
  282. PAL_FBPBlitToSurface(buf, pUpper);
  283. PAL_MKFDecompressChunk(buf, 64000, 70, gpGlobals->f.fpFBP);
  284. PAL_FBPBlitToSurface(buf, pLower);
  285. #else
  286. PAL_MKFDecompressChunk(buf, 64000, 61, gpGlobals->f.fpFBP);
  287. PAL_FBPBlitToSurface(buf, pUpper);
  288. PAL_MKFDecompressChunk(buf, 64000, 62, gpGlobals->f.fpFBP);
  289. PAL_FBPBlitToSurface(buf, pLower);
  290. #endif
  291. PAL_MKFDecompressChunk(buf, 64000, 571, gpGlobals->f.fpMGO);
  292. PAL_MKFDecompressChunk(bufGirl, 6000, 572, gpGlobals->f.fpMGO);
  293. srcrect.x = 0;
  294. dstrect.x = 0;
  295. srcrect.w = 320;
  296. dstrect.w = 320;
  297. gpGlobals->wScreenWave = 2;
  298. for (i = 0; i < 400; i++)
  299. {
  300. //
  301. // Draw the background
  302. //
  303. srcrect.y = 0;
  304. srcrect.h = 200 - i / 2;
  305. dstrect.y = i / 2;
  306. dstrect.h = 200 - i / 2;
  307. SDL_BlitSurface(pLower, &srcrect, gpScreen, &dstrect);
  308. srcrect.y = 200 - i / 2;
  309. srcrect.h = i / 2;
  310. dstrect.y = 0;
  311. dstrect.h = i / 2;
  312. SDL_BlitSurface(pUpper, &srcrect, gpScreen, &dstrect);
  313. PAL_ApplyWave(gpScreen);
  314. //
  315. // Draw the beast
  316. //
  317. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 0), gpScreen, PAL_XY(0, -400 + i));
  318. #ifdef PAL_WIN95
  319. PAL_RLEBlitToSurface(buf + 0x8444, gpScreen, PAL_XY(0, -200 + i));
  320. #else
  321. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 1), gpScreen, PAL_XY(0, -200 + i));
  322. #endif
  323. //
  324. // Draw the girl
  325. //
  326. yPosGirl -= i & 1;
  327. if (yPosGirl < 80)
  328. {
  329. yPosGirl = 80;
  330. }
  331. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufGirl, (SDL_GetTicks() / 50) % 4),
  332. gpScreen, PAL_XY(220, yPosGirl));
  333. //
  334. // Update the screen
  335. //
  336. VIDEO_UpdateScreen(NULL);
  337. if (gpGlobals->fNeedToFadeIn)
  338. {
  339. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
  340. gpGlobals->fNeedToFadeIn = FALSE;
  341. #if SDL_VERSION_ATLEAST(2, 0, 0)
  342. SDL_SetSurfacePalette(pUpper, gpScreen->format->palette);
  343. SDL_SetSurfacePalette(pLower, gpScreen->format->palette);
  344. #else
  345. SDL_SetPalette(pUpper, SDL_LOGPAL | SDL_PHYSPAL, VIDEO_GetPalette(), 0, 256);
  346. SDL_SetPalette(pLower, SDL_LOGPAL | SDL_PHYSPAL, VIDEO_GetPalette(), 0, 256);
  347. #endif
  348. }
  349. UTIL_Delay(50);
  350. }
  351. gpGlobals->wScreenWave = 0;
  352. SDL_FreeSurface(pUpper);
  353. SDL_FreeSurface(pLower);
  354. free(buf);
  355. free(bufGirl);
  356. }
  357. #ifdef PAL_WIN95
  358. VOID
  359. PAL_EndingScreen(
  360. VOID
  361. )
  362. {
  363. RIX_Play(0x1a, TRUE, 0);
  364. PAL_RNGPlay(gpGlobals->iCurPlayingRNG, 110, 150, 7);
  365. PAL_RNGPlay(gpGlobals->iCurPlayingRNG, 151, 999, 9);
  366. PAL_FadeOut(2);
  367. RIX_Play(0x19, TRUE, 0);
  368. PAL_ShowFBP(75, 0);
  369. PAL_FadeIn(5, FALSE, 1);
  370. PAL_ScrollFBP(74, 0xf, TRUE);
  371. PAL_FadeOut(1);
  372. SDL_FillRect(gpScreen, NULL, 0);
  373. gpGlobals->wNumPalette = 4;
  374. gpGlobals->fNeedToFadeIn = TRUE;
  375. PAL_EndingAnimation();
  376. RIX_Play(0, FALSE, 2);
  377. PAL_ColorFade(7, 15, FALSE);
  378. if (!SOUND_PlayCDA(2))
  379. {
  380. RIX_Play(0x11, TRUE, 0);
  381. }
  382. SDL_FillRect(gpScreen, NULL, 0);
  383. PAL_SetPalette(0, FALSE);
  384. PAL_RNGPlay(0xb, 0, 999, 7);
  385. PAL_FadeOut(2);
  386. SDL_FillRect(gpScreen, NULL, 0);
  387. gpGlobals->wNumPalette = 8;
  388. gpGlobals->fNeedToFadeIn = TRUE;
  389. PAL_RNGPlay(10, 0, 999, 6);
  390. PAL_EndingSetEffectSprite(0);
  391. PAL_ShowFBP(77, 10);
  392. VIDEO_BackupScreen();
  393. PAL_EndingSetEffectSprite(0x27b);
  394. PAL_ShowFBP(76, 7);
  395. PAL_SetPalette(5, FALSE);
  396. PAL_ShowFBP(73, 7);
  397. PAL_ScrollFBP(72, 0xf, TRUE);
  398. PAL_ShowFBP(71, 7);
  399. PAL_ShowFBP(68, 7);
  400. PAL_EndingSetEffectSprite(0);
  401. PAL_ShowFBP(68, 6);
  402. PAL_WaitForKey(0);
  403. RIX_Play(0, FALSE, 1);
  404. UTIL_Delay(500);
  405. if (!SOUND_PlayCDA(13))
  406. {
  407. RIX_Play(9, TRUE, 0);
  408. }
  409. PAL_ScrollFBP(67, 0xf, TRUE);
  410. PAL_ScrollFBP(66, 0xf, TRUE);
  411. PAL_ScrollFBP(65, 0xf, TRUE);
  412. PAL_ScrollFBP(64, 0xf, TRUE);
  413. PAL_ScrollFBP(63, 0xf, TRUE);
  414. PAL_ScrollFBP(62, 0xf, TRUE);
  415. PAL_ScrollFBP(61, 0xf, TRUE);
  416. PAL_ScrollFBP(60, 0xf, TRUE);
  417. PAL_ScrollFBP(59, 0xf, TRUE);
  418. RIX_Play(0, FALSE, 6);
  419. PAL_FadeOut(3);
  420. }
  421. #endif