ending.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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. if (wChunkNum != 49)
  123. {
  124. PAL_FBPBlitToSurface(buf, gpScreen);
  125. }
  126. VIDEO_UpdateScreen(NULL);
  127. }
  128. VOID
  129. PAL_ScrollFBP(
  130. WORD wChunkNum,
  131. WORD wScrollSpeed,
  132. BOOL fScrollDown
  133. )
  134. /*++
  135. Purpose:
  136. Scroll up an FBP picture to the screen.
  137. Parameters:
  138. [IN] wChunkNum - number of chunk in fbp.mkf file.
  139. [IN] wScrollSpeed - scrolling speed of showing the picture.
  140. [IN] fScrollDown - TRUE if scroll down, FALSE if scroll up.
  141. Return value:
  142. None.
  143. --*/
  144. {
  145. SDL_Surface *p;
  146. PAL_LARGE BYTE buf[320 * 200];
  147. PAL_LARGE BYTE bufSprite[320 * 200];
  148. int i, l;
  149. SDL_Rect rect, dstrect;
  150. if (PAL_MKFDecompressChunk(buf, 320 * 200, wChunkNum, gpGlobals->f.fpFBP) <= 0)
  151. {
  152. return;
  153. }
  154. if (g_wCurEffectSprite != 0)
  155. {
  156. PAL_MKFDecompressChunk(bufSprite, 320 * 200, g_wCurEffectSprite, gpGlobals->f.fpMGO);
  157. }
  158. p = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
  159. gpScreen->format->Rmask, gpScreen->format->Gmask,
  160. gpScreen->format->Bmask, gpScreen->format->Amask);
  161. if (p == NULL)
  162. {
  163. return;
  164. }
  165. #if SDL_VERSION_ATLEAST(2, 0, 0)
  166. SDL_SetSurfacePalette(p, gpScreen->format->palette);
  167. #else
  168. SDL_SetPalette(p, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  169. #endif
  170. VIDEO_BackupScreen();
  171. PAL_FBPBlitToSurface(buf, p);
  172. if (wScrollSpeed == 0)
  173. {
  174. wScrollSpeed = 1;
  175. }
  176. rect.x = 0;
  177. rect.w = 320;
  178. dstrect.x = 0;
  179. dstrect.w = 320;
  180. for (l = 0; l < 220; l++)
  181. {
  182. i = l;
  183. if (i > 200)
  184. {
  185. i = 200;
  186. }
  187. if (fScrollDown)
  188. {
  189. rect.y = 0;
  190. dstrect.y = i;
  191. rect.h = 200 - i;
  192. dstrect.h = 200 - i;
  193. }
  194. else
  195. {
  196. rect.y = i;
  197. dstrect.y = 0;
  198. rect.h = 200 - i;
  199. dstrect.h = 200 - i;
  200. }
  201. SDL_BlitSurface(gpScreenBak, &rect, gpScreen, &dstrect);
  202. if (fScrollDown)
  203. {
  204. rect.y = 200 - i;
  205. dstrect.y = 0;
  206. rect.h = i;
  207. dstrect.h = i;
  208. }
  209. else
  210. {
  211. rect.y = 0;
  212. dstrect.y = 200 - i;
  213. rect.h = i;
  214. dstrect.h = i;
  215. }
  216. SDL_BlitSurface(p, &rect, gpScreen, &dstrect);
  217. PAL_ApplyWave(gpScreen);
  218. if (g_wCurEffectSprite != 0)
  219. {
  220. int f = SDL_GetTicks() / 150;
  221. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufSprite, f % PAL_SpriteGetNumFrames(bufSprite)),
  222. gpScreen, PAL_XY(0, 0));
  223. }
  224. VIDEO_UpdateScreen(NULL);
  225. if (gpGlobals->fNeedToFadeIn)
  226. {
  227. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
  228. gpGlobals->fNeedToFadeIn = FALSE;
  229. #if SDL_VERSION_ATLEAST(2, 0, 0)
  230. SDL_SetSurfacePalette(p, gpScreen->format->palette);
  231. #else
  232. SDL_SetPalette(p, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  233. #endif
  234. }
  235. UTIL_Delay(800 / wScrollSpeed);
  236. }
  237. SDL_BlitSurface(p, NULL, gpScreen, NULL);
  238. SDL_FreeSurface(p);
  239. VIDEO_UpdateScreen(NULL);
  240. }
  241. VOID
  242. PAL_EndingAnimation(
  243. VOID
  244. )
  245. /*++
  246. Purpose:
  247. Show the ending animation.
  248. Parameters:
  249. None.
  250. Return value:
  251. None.
  252. --*/
  253. {
  254. LPBYTE buf;
  255. LPBYTE bufGirl;
  256. SDL_Surface *pUpper;
  257. SDL_Surface *pLower;
  258. SDL_Rect srcrect, dstrect;
  259. int yPosGirl = 180;
  260. int i;
  261. buf = (LPBYTE)UTIL_calloc(1, 64000);
  262. bufGirl = (LPBYTE)UTIL_calloc(1, 6000);
  263. pUpper = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
  264. gpScreen->format->Rmask, gpScreen->format->Gmask,
  265. gpScreen->format->Bmask, gpScreen->format->Amask);
  266. pLower = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
  267. gpScreen->format->Rmask, gpScreen->format->Gmask,
  268. gpScreen->format->Bmask, gpScreen->format->Amask);
  269. #if SDL_VERSION_ATLEAST(2, 0, 0)
  270. SDL_SetSurfacePalette(pUpper, gpScreen->format->palette);
  271. SDL_SetSurfacePalette(pLower, gpScreen->format->palette);
  272. #else
  273. SDL_SetPalette(pUpper, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  274. SDL_SetPalette(pLower, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  275. #endif
  276. #ifdef PAL_WIN95
  277. PAL_MKFDecompressChunk(buf, 64000, 69, gpGlobals->f.fpFBP);
  278. PAL_FBPBlitToSurface(buf, pUpper);
  279. PAL_MKFDecompressChunk(buf, 64000, 70, gpGlobals->f.fpFBP);
  280. PAL_FBPBlitToSurface(buf, pLower);
  281. #else
  282. PAL_MKFDecompressChunk(buf, 64000, 61, gpGlobals->f.fpFBP);
  283. PAL_FBPBlitToSurface(buf, pUpper);
  284. PAL_MKFDecompressChunk(buf, 64000, 62, gpGlobals->f.fpFBP);
  285. PAL_FBPBlitToSurface(buf, pLower);
  286. #endif
  287. PAL_MKFDecompressChunk(buf, 64000, 571, gpGlobals->f.fpMGO);
  288. PAL_MKFDecompressChunk(bufGirl, 6000, 572, gpGlobals->f.fpMGO);
  289. srcrect.x = 0;
  290. dstrect.x = 0;
  291. srcrect.w = 320;
  292. dstrect.w = 320;
  293. gpGlobals->wScreenWave = 2;
  294. for (i = 0; i < 400; i++)
  295. {
  296. //
  297. // Draw the background
  298. //
  299. srcrect.y = 0;
  300. srcrect.h = 200 - i / 2;
  301. dstrect.y = i / 2;
  302. dstrect.h = 200 - i / 2;
  303. SDL_BlitSurface(pLower, &srcrect, gpScreen, &dstrect);
  304. srcrect.y = 200 - i / 2;
  305. srcrect.h = i / 2;
  306. dstrect.y = 0;
  307. dstrect.h = i / 2;
  308. SDL_BlitSurface(pUpper, &srcrect, gpScreen, &dstrect);
  309. PAL_ApplyWave(gpScreen);
  310. //
  311. // Draw the beast
  312. //
  313. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 0), gpScreen, PAL_XY(0, -400 + i));
  314. #ifdef PAL_WIN95
  315. PAL_RLEBlitToSurface(buf + 0x8444, gpScreen, PAL_XY(0, -200 + i));
  316. #else
  317. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 1), gpScreen, PAL_XY(0, -200 + i));
  318. #endif
  319. //
  320. // Draw the girl
  321. //
  322. yPosGirl -= i & 1;
  323. if (yPosGirl < 80)
  324. {
  325. yPosGirl = 80;
  326. }
  327. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufGirl, (SDL_GetTicks() / 50) % 4),
  328. gpScreen, PAL_XY(220, yPosGirl));
  329. //
  330. // Update the screen
  331. //
  332. VIDEO_UpdateScreen(NULL);
  333. if (gpGlobals->fNeedToFadeIn)
  334. {
  335. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
  336. gpGlobals->fNeedToFadeIn = FALSE;
  337. #if SDL_VERSION_ATLEAST(2, 0, 0)
  338. SDL_SetSurfacePalette(pUpper, gpScreen->format->palette);
  339. SDL_SetSurfacePalette(pLower, gpScreen->format->palette);
  340. #else
  341. SDL_SetPalette(pUpper, SDL_LOGPAL | SDL_PHYSPAL, VIDEO_GetPalette(), 0, 256);
  342. SDL_SetPalette(pLower, SDL_LOGPAL | SDL_PHYSPAL, VIDEO_GetPalette(), 0, 256);
  343. #endif
  344. }
  345. UTIL_Delay(50);
  346. }
  347. gpGlobals->wScreenWave = 0;
  348. SDL_FreeSurface(pUpper);
  349. SDL_FreeSurface(pLower);
  350. free(buf);
  351. free(bufGirl);
  352. }
  353. #ifdef PAL_WIN95
  354. VOID
  355. PAL_EndingScreen(
  356. VOID
  357. )
  358. {
  359. RIX_Play(0x1a, TRUE, 0);
  360. PAL_RNGPlay(gpGlobals->iCurPlayingRNG, 110, 150, 7);
  361. PAL_RNGPlay(gpGlobals->iCurPlayingRNG, 151, 999, 9);
  362. PAL_FadeOut(2);
  363. RIX_Play(0x19, TRUE, 0);
  364. PAL_ShowFBP(75, 0);
  365. PAL_FadeIn(5, FALSE, 1);
  366. PAL_ScrollFBP(74, 0xf, TRUE);
  367. PAL_FadeOut(1);
  368. SDL_FillRect(gpScreen, NULL, 0);
  369. PAL_SetPalette(4, FALSE);
  370. gpGlobals->fNeedToFadeIn = TRUE;
  371. PAL_EndingAnimation();
  372. gpGlobals->wNumPalette = 4;
  373. RIX_Play(0, FALSE, 2);
  374. PAL_ColorFade(7, 15, FALSE);
  375. if (!SOUND_PlayCDA(2))
  376. {
  377. RIX_Play(0x11, TRUE, 0);
  378. }
  379. SDL_FillRect(gpScreen, NULL, 0);
  380. PAL_SetPalette(0, FALSE);
  381. PAL_RNGPlay(0xb, 0, 999, 7);
  382. PAL_FadeOut(2);
  383. SDL_FillRect(gpScreen, NULL, 0);
  384. PAL_SetPalette(8, FALSE);
  385. PAL_RNGPlay(10, 0, 999, 6);
  386. PAL_EndingSetEffectSprite(0);
  387. PAL_ShowFBP(77, 10);
  388. VIDEO_BackupScreen();
  389. PAL_EndingSetEffectSprite(0x27b);
  390. PAL_ShowFBP(76, 7);
  391. PAL_SetPalette(5, FALSE);
  392. PAL_ShowFBP(73, 7);
  393. PAL_ScrollFBP(72, 0xf, TRUE);
  394. PAL_ShowFBP(71, 7);
  395. PAL_ShowFBP(68, 7);
  396. PAL_EndingSetEffectSprite(0);
  397. PAL_ShowFBP(68, 6);
  398. PAL_WaitForKey(0);
  399. RIX_Play(0, FALSE, 1);
  400. UTIL_Delay(500);
  401. if (!SOUND_PlayCDA(13))
  402. {
  403. RIX_Play(9, TRUE, 0);
  404. }
  405. PAL_ScrollFBP(67, 0xf, TRUE);
  406. PAL_ScrollFBP(66, 0xf, TRUE);
  407. PAL_ScrollFBP(65, 0xf, TRUE);
  408. PAL_ScrollFBP(64, 0xf, TRUE);
  409. PAL_ScrollFBP(63, 0xf, TRUE);
  410. PAL_ScrollFBP(62, 0xf, TRUE);
  411. PAL_ScrollFBP(61, 0xf, TRUE);
  412. PAL_ScrollFBP(60, 0xf, TRUE);
  413. PAL_ScrollFBP(59, 0xf, TRUE);
  414. RIX_Play(0, FALSE, 6);
  415. PAL_FadeOut(3);
  416. }
  417. #endif