video.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. //
  2. // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
  3. // All rights reserved.
  4. //
  5. // This file is part of SDLPAL.
  6. //
  7. // SDLPAL is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation, either version 3 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. //
  20. #include "main.h"
  21. // Screen buffer
  22. SDL_Surface *gpScreen = NULL;
  23. // Backup screen buffer
  24. SDL_Surface *gpScreenBak = NULL;
  25. // The real screen surface
  26. static SDL_Surface *gpScreenReal = NULL;
  27. #if (defined (__SYMBIAN32__) && !defined (__S60_5X__)) || defined (PSP) || defined (GEKKO)
  28. static BOOL bScaleScreen = FALSE;
  29. #else
  30. static BOOL bScaleScreen = TRUE;
  31. #endif
  32. // Initial screen size
  33. static WORD g_wInitialWidth = 640;
  34. static WORD g_wInitialHeight = 400;
  35. // Shake times and level
  36. static WORD g_wShakeTime = 0;
  37. static WORD g_wShakeLevel = 0;
  38. INT
  39. #ifdef GEKKO // Rikku2000: Crash on compile, allready define on WIISDK
  40. VIDEO_Init_GEKKO(
  41. #else
  42. VIDEO_Init(
  43. #endif
  44. WORD wScreenWidth,
  45. WORD wScreenHeight,
  46. BOOL fFullScreen
  47. )
  48. /*++
  49. Purpose:
  50. Initialze the video subsystem.
  51. Parameters:
  52. [IN] wScreenWidth - width of the screen.
  53. [IN] wScreenHeight - height of the screen.
  54. [IN] fFullScreen - TRUE to use full screen mode, FALSE to use windowed mode.
  55. Return value:
  56. 0 = success, -1 = fail to create the screen surface,
  57. -2 = fail to create screen buffer.
  58. --*/
  59. {
  60. g_wInitialWidth = wScreenWidth;
  61. g_wInitialHeight = wScreenHeight;
  62. //
  63. // Create the screen surface.
  64. //
  65. #if defined (NDS)
  66. gpScreenReal = SDL_SetVideoMode(293, 196, 8, SDL_SWSURFACE | SDL_FULLSCREEN);
  67. #elif defined (__SYMBIAN32__)
  68. #ifdef __S60_5X__
  69. gpScreenReal = SDL_SetVideoMode(640, 360, 8,
  70. SDL_SWSURFACE | (fFullScreen ? SDL_FULLSCREEN : 0));
  71. #else
  72. gpScreenReal = SDL_SetVideoMode(320, 240, 8,
  73. SDL_SWSURFACE | (fFullScreen ? SDL_FULLSCREEN : 0));
  74. #endif
  75. #elif defined (GEKKO)
  76. gpScreenReal = SDL_SetVideoMode(640, 480, 8,
  77. SDL_SWSURFACE | (fFullScreen ? SDL_FULLSCREEN : 0));
  78. #elif defined (PSP)
  79. gpScreenReal = SDL_SetVideoMode(320, 240, 8, SDL_SWSURFACE | SDL_FULLSCREEN);
  80. #else
  81. gpScreenReal = SDL_SetVideoMode(wScreenWidth, wScreenHeight, 8,
  82. SDL_HWSURFACE | SDL_RESIZABLE | (fFullScreen ? SDL_FULLSCREEN : 0));
  83. #endif
  84. if (gpScreenReal == NULL)
  85. {
  86. //
  87. // Fall back to 640x480 software mode.
  88. //
  89. gpScreenReal = SDL_SetVideoMode(640, 480, 8,
  90. SDL_SWSURFACE | (fFullScreen ? SDL_FULLSCREEN : 0));
  91. }
  92. //
  93. // Still fail?
  94. //
  95. if (gpScreenReal == NULL)
  96. {
  97. return -1;
  98. }
  99. //
  100. // Create the screen buffer and the backup screen buffer.
  101. //
  102. gpScreen = SDL_CreateRGBSurface(gpScreenReal->flags & ~SDL_HWSURFACE, 320, 200, 8,
  103. gpScreenReal->format->Rmask, gpScreenReal->format->Gmask,
  104. gpScreenReal->format->Bmask, gpScreenReal->format->Amask);
  105. gpScreenBak = SDL_CreateRGBSurface(gpScreenReal->flags & ~SDL_HWSURFACE, 320, 200, 8,
  106. gpScreenReal->format->Rmask, gpScreenReal->format->Gmask,
  107. gpScreenReal->format->Bmask, gpScreenReal->format->Amask);
  108. //
  109. // Failed?
  110. //
  111. if (gpScreen == NULL || gpScreenBak == NULL)
  112. {
  113. if (gpScreen != NULL)
  114. {
  115. SDL_FreeSurface(gpScreen);
  116. }
  117. if (gpScreenBak != NULL)
  118. {
  119. SDL_FreeSurface(gpScreenBak);
  120. }
  121. SDL_FreeSurface(gpScreenReal);
  122. return -2;
  123. }
  124. if (fFullScreen)
  125. {
  126. SDL_ShowCursor(FALSE);
  127. }
  128. return 0;
  129. }
  130. VOID
  131. VIDEO_Shutdown(
  132. VOID
  133. )
  134. /*++
  135. Purpose:
  136. Shutdown the video subsystem.
  137. Parameters:
  138. None.
  139. Return value:
  140. None.
  141. --*/
  142. {
  143. if (gpScreen != NULL)
  144. {
  145. SDL_FreeSurface(gpScreen);
  146. }
  147. gpScreen = NULL;
  148. if (gpScreenBak != NULL)
  149. {
  150. SDL_FreeSurface(gpScreenBak);
  151. }
  152. gpScreenBak = NULL;
  153. if (gpScreenReal != NULL)
  154. {
  155. SDL_FreeSurface(gpScreenReal);
  156. }
  157. gpScreenReal = NULL;
  158. }
  159. VOID
  160. VIDEO_UpdateScreen(
  161. const SDL_Rect *lpRect
  162. )
  163. /*++
  164. Purpose:
  165. Update the screen area specified by lpRect.
  166. Parameters:
  167. [IN] lpRect - Screen area to update.
  168. Return value:
  169. None.
  170. --*/
  171. {
  172. SDL_Rect srcrect, dstrect;
  173. short offset = 240 - 200;
  174. short screenRealHeight = gpScreenReal->h;
  175. short screenRealY = 0;
  176. //
  177. // Lock surface if needed
  178. //
  179. if (SDL_MUSTLOCK(gpScreenReal))
  180. {
  181. if (SDL_LockSurface(gpScreenReal) < 0)
  182. return;
  183. }
  184. if (!bScaleScreen)
  185. {
  186. screenRealHeight -= offset;
  187. screenRealY = offset / 2;
  188. }
  189. if (lpRect != NULL)
  190. {
  191. dstrect.x = (SHORT)((INT)(lpRect->x) * gpScreenReal->w / gpScreen->w);
  192. dstrect.y = (SHORT)((INT)(screenRealY + lpRect->y) * screenRealHeight / gpScreen->h);
  193. dstrect.w = (WORD)((DWORD)(lpRect->w) * gpScreenReal->w / gpScreen->w);
  194. dstrect.h = (WORD)((DWORD)(lpRect->h) * screenRealHeight / gpScreen->h);
  195. SDL_SoftStretch(gpScreen, (SDL_Rect *)lpRect, gpScreenReal, &dstrect);
  196. if (SDL_MUSTLOCK(gpScreenReal))
  197. {
  198. SDL_UnlockSurface(gpScreenReal);
  199. }
  200. SDL_UpdateRect(gpScreenReal, dstrect.x, dstrect.y, dstrect.w, dstrect.h);
  201. }
  202. else if (g_wShakeTime != 0)
  203. {
  204. //
  205. // Shake the screen
  206. //
  207. srcrect.x = 0;
  208. srcrect.y = 0;
  209. srcrect.w = 320;
  210. srcrect.h = 200 - g_wShakeLevel;
  211. dstrect.x = 0;
  212. dstrect.y = screenRealY;
  213. dstrect.w = 320 * gpScreenReal->w / gpScreen->w;
  214. dstrect.h = (200 - g_wShakeLevel) * screenRealHeight / gpScreen->h;
  215. if (g_wShakeTime & 1)
  216. {
  217. srcrect.y = g_wShakeLevel;
  218. }
  219. else
  220. {
  221. dstrect.y = (screenRealY + g_wShakeLevel) * screenRealHeight / gpScreen->h;
  222. }
  223. SDL_SoftStretch(gpScreen, &srcrect, gpScreenReal, &dstrect);
  224. if (g_wShakeTime & 1)
  225. {
  226. dstrect.y = (screenRealY + screenRealHeight - g_wShakeLevel) * screenRealHeight / gpScreen->h;
  227. }
  228. else
  229. {
  230. dstrect.y = screenRealY;
  231. }
  232. dstrect.h = g_wShakeLevel * screenRealHeight / gpScreen->h;
  233. SDL_FillRect(gpScreenReal, &dstrect, 0);
  234. if (SDL_MUSTLOCK(gpScreenReal))
  235. {
  236. SDL_UnlockSurface(gpScreenReal);
  237. }
  238. SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
  239. g_wShakeTime--;
  240. }
  241. else
  242. {
  243. dstrect.x = 0;
  244. dstrect.y = screenRealY;
  245. dstrect.w = gpScreenReal->w;
  246. dstrect.h = screenRealHeight;
  247. SDL_SoftStretch(gpScreen, NULL, gpScreenReal, &dstrect);
  248. if (SDL_MUSTLOCK(gpScreenReal))
  249. {
  250. SDL_UnlockSurface(gpScreenReal);
  251. }
  252. SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
  253. }
  254. }
  255. VOID
  256. VIDEO_SetPalette(
  257. SDL_Color rgPalette[256]
  258. )
  259. /*++
  260. Purpose:
  261. Set the palette of the screen.
  262. Parameters:
  263. [IN] rgPalette - array of 256 colors.
  264. Return value:
  265. None.
  266. --*/
  267. {
  268. SDL_SetPalette(gpScreenReal, SDL_LOGPAL | SDL_PHYSPAL, rgPalette, 0, 256);
  269. #if (defined (__SYMBIAN32__))
  270. {
  271. static UINT32 time = 0;
  272. if (SDL_GetTicks() - time > 50)
  273. {
  274. SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
  275. time = SDL_GetTicks();
  276. }
  277. }
  278. #endif
  279. }
  280. VOID
  281. VIDEO_Resize(
  282. INT w,
  283. INT h
  284. )
  285. /*++
  286. Purpose:
  287. This function is called when user resized the window.
  288. Parameters:
  289. [IN] w - width of the window after resizing.
  290. [IN] h - height of the window after resizing.
  291. Return value:
  292. None.
  293. --*/
  294. {
  295. DWORD flags;
  296. PAL_LARGE SDL_Color palette[256];
  297. int i;
  298. //
  299. // Get the original palette.
  300. //
  301. for (i = 0; i < gpScreenReal->format->palette->ncolors; i++)
  302. {
  303. palette[i] = gpScreenReal->format->palette->colors[i];
  304. }
  305. //
  306. // Create the screen surface.
  307. //
  308. flags = gpScreenReal->flags;
  309. SDL_FreeSurface(gpScreenReal);
  310. gpScreenReal = SDL_SetVideoMode(w, h, 8, flags);
  311. if (gpScreenReal == NULL)
  312. {
  313. #ifdef __SYMBIAN32__
  314. #ifdef __S60_5X__
  315. gpScreenReal = SDL_SetVideoMode(640, 360, 8, SDL_SWSURFACE);
  316. #else
  317. gpScreenReal = SDL_SetVideoMode(320, 240, 8, SDL_SWSURFACE);
  318. #endif
  319. #else
  320. //
  321. // Fall back to 640x480 software windowed mode.
  322. //
  323. gpScreenReal = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);
  324. #endif
  325. }
  326. SDL_SetPalette(gpScreenReal, SDL_PHYSPAL | SDL_LOGPAL, palette, 0, i);
  327. VIDEO_UpdateScreen(NULL);
  328. }
  329. SDL_Color *
  330. VIDEO_GetPalette(
  331. VOID
  332. )
  333. /*++
  334. Purpose:
  335. Get the current palette of the screen.
  336. Parameters:
  337. None.
  338. Return value:
  339. Pointer to the current palette.
  340. --*/
  341. {
  342. return gpScreenReal->format->palette->colors;
  343. }
  344. VOID
  345. VIDEO_ToggleScaleScreen(
  346. VOID
  347. )
  348. /*++
  349. Purpose:
  350. Toggle scalescreen mode.
  351. Parameters:
  352. None.
  353. Return value:
  354. None.
  355. --*/
  356. {
  357. #ifdef __SYMBIAN32__
  358. bScaleScreen = !bScaleScreen;
  359. VIDEO_Resize(320, 240);
  360. VIDEO_UpdateScreen(NULL);
  361. #endif
  362. }
  363. VOID
  364. VIDEO_ToggleFullscreen(
  365. VOID
  366. )
  367. /*++
  368. Purpose:
  369. Toggle fullscreen mode.
  370. Parameters:
  371. None.
  372. Return value:
  373. None.
  374. --*/
  375. {
  376. DWORD flags;
  377. PAL_LARGE SDL_Color palette[256];
  378. int i;
  379. //
  380. // Get the original palette.
  381. //
  382. for (i = 0; i < gpScreenReal->format->palette->ncolors; i++)
  383. {
  384. palette[i] = gpScreenReal->format->palette->colors[i];
  385. }
  386. //
  387. // Get the flags of the original screen surface
  388. //
  389. flags = gpScreenReal->flags;
  390. if (flags & SDL_FULLSCREEN)
  391. {
  392. //
  393. // Already in fullscreen mode. Remove the fullscreen flag.
  394. //
  395. flags &= ~SDL_FULLSCREEN;
  396. flags |= SDL_RESIZABLE;
  397. SDL_ShowCursor(TRUE);
  398. }
  399. else
  400. {
  401. //
  402. // Not in fullscreen mode. Set the fullscreen flag.
  403. //
  404. flags |= SDL_FULLSCREEN;
  405. SDL_ShowCursor(FALSE);
  406. }
  407. //
  408. // Free the original screen surface
  409. //
  410. SDL_FreeSurface(gpScreenReal);
  411. //
  412. // ... and create a new one
  413. //
  414. if (g_wInitialWidth == 640 && g_wInitialHeight == 400 && (flags & SDL_FULLSCREEN))
  415. {
  416. gpScreenReal = SDL_SetVideoMode(640, 480, 8, flags);
  417. }
  418. else if (g_wInitialWidth == 640 && g_wInitialHeight == 480 && !(flags & SDL_FULLSCREEN))
  419. {
  420. gpScreenReal = SDL_SetVideoMode(640, 400, 8, flags);
  421. }
  422. else
  423. {
  424. gpScreenReal = SDL_SetVideoMode(g_wInitialWidth, g_wInitialHeight, 8, flags);
  425. }
  426. VIDEO_SetPalette(palette);
  427. //
  428. // Update the screen
  429. //
  430. VIDEO_UpdateScreen(NULL);
  431. }
  432. VOID
  433. VIDEO_SaveScreenshot(
  434. VOID
  435. )
  436. /*++
  437. Purpose:
  438. Save the screenshot of current screen to a BMP file.
  439. Parameters:
  440. None.
  441. Return value:
  442. None.
  443. --*/
  444. {
  445. int iNumBMP = 0;
  446. FILE *fp;
  447. //
  448. // Find a usable BMP filename.
  449. //
  450. for (iNumBMP = 0; iNumBMP <= 9999; iNumBMP++)
  451. {
  452. fp = fopen(va("%sscrn%.4d.bmp", PAL_PREFIX, iNumBMP), "rb");
  453. if (fp == NULL)
  454. {
  455. break;
  456. }
  457. fclose(fp);
  458. }
  459. if (iNumBMP > 9999)
  460. {
  461. return;
  462. }
  463. //
  464. // Save the screenshot.
  465. //
  466. SDL_SaveBMP(gpScreenReal, va("%sscrn%.4d.bmp", PAL_PREFIX, iNumBMP));
  467. }
  468. VOID
  469. VIDEO_BackupScreen(
  470. VOID
  471. )
  472. /*++
  473. Purpose:
  474. Backup the screen buffer.
  475. Parameters:
  476. None.
  477. Return value:
  478. None.
  479. --*/
  480. {
  481. SDL_BlitSurface(gpScreen, NULL, gpScreenBak, NULL);
  482. }
  483. VOID
  484. VIDEO_RestoreScreen(
  485. VOID
  486. )
  487. /*++
  488. Purpose:
  489. Restore the screen buffer which has been saved with VIDEO_BackupScreen().
  490. Parameters:
  491. None.
  492. Return value:
  493. None.
  494. --*/
  495. {
  496. SDL_BlitSurface(gpScreenBak, NULL, gpScreen, NULL);
  497. }
  498. VOID
  499. VIDEO_ShakeScreen(
  500. WORD wShakeTime,
  501. WORD wShakeLevel
  502. )
  503. /*++
  504. Purpose:
  505. Set the screen shake time and level.
  506. Parameters:
  507. [IN] wShakeTime - how many times should we shake the screen.
  508. [IN] wShakeLevel - level of shaking.
  509. Return value:
  510. None.
  511. --*/
  512. {
  513. g_wShakeTime = wShakeTime;
  514. g_wShakeLevel = wShakeLevel;
  515. }
  516. VOID
  517. VIDEO_SwitchScreen(
  518. WORD wSpeed
  519. )
  520. /*++
  521. Purpose:
  522. Switch the screen from the backup screen buffer to the current screen buffer.
  523. NOTE: This will destroy the backup buffer.
  524. Parameters:
  525. [IN] wSpeed - speed of fading (the larger value, the slower).
  526. Return value:
  527. None.
  528. --*/
  529. {
  530. int i, j;
  531. const int rgIndex[6] = {0, 3, 1, 5, 2, 4};
  532. SDL_Rect dstrect;
  533. short offset = 240 - 200;
  534. short screenRealHeight = gpScreenReal->h;
  535. short screenRealY = 0;
  536. if (!bScaleScreen)
  537. {
  538. screenRealHeight -= offset;
  539. screenRealY = offset / 2;
  540. }
  541. wSpeed++;
  542. wSpeed *= 10;
  543. for (i = 0; i < 6; i++)
  544. {
  545. for (j = rgIndex[i]; j < gpScreen->pitch * gpScreen->h; j += 6)
  546. {
  547. ((LPBYTE)(gpScreenBak->pixels))[j] = ((LPBYTE)(gpScreen->pixels))[j];
  548. }
  549. //
  550. // Draw the backup buffer to the screen
  551. //
  552. dstrect.x = 0;
  553. dstrect.y = screenRealY;
  554. dstrect.w = gpScreenReal->w;
  555. dstrect.h = screenRealHeight;
  556. SDL_SoftStretch(gpScreenBak, NULL, gpScreenReal, &dstrect);
  557. SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
  558. UTIL_Delay(wSpeed);
  559. }
  560. }
  561. VOID
  562. VIDEO_FadeScreen(
  563. WORD wSpeed
  564. )
  565. /*++
  566. Purpose:
  567. Fade from the backup screen buffer to the current screen buffer.
  568. NOTE: This will destroy the backup buffer.
  569. Parameters:
  570. [IN] wSpeed - speed of fading (the larger value, the slower).
  571. Return value:
  572. None.
  573. --*/
  574. {
  575. int i, j, k;
  576. DWORD time;
  577. BYTE a, b;
  578. const int rgIndex[6] = {0, 3, 1, 5, 2, 4};
  579. SDL_Rect dstrect;
  580. short offset = 240 - 200;
  581. short screenRealHeight = gpScreenReal->h;
  582. short screenRealY = 0;
  583. //
  584. // Lock surface if needed
  585. //
  586. if (SDL_MUSTLOCK(gpScreenReal))
  587. {
  588. if (SDL_LockSurface(gpScreenReal) < 0)
  589. return;
  590. }
  591. if (!bScaleScreen)
  592. {
  593. screenRealHeight -= offset;
  594. screenRealY = offset / 2;
  595. }
  596. time = SDL_GetTicks();
  597. wSpeed++;
  598. wSpeed *= 10;
  599. for (i = 0; i < 12; i++)
  600. {
  601. for (j = 0; j < 6; j++)
  602. {
  603. PAL_ProcessEvent();
  604. while (SDL_GetTicks() <= time)
  605. {
  606. PAL_ProcessEvent();
  607. SDL_Delay(5);
  608. }
  609. time = SDL_GetTicks() + wSpeed;
  610. //
  611. // Blend the pixels in the 2 buffers, and put the result into the
  612. // backup buffer
  613. //
  614. for (k = rgIndex[j]; k < gpScreen->pitch * gpScreen->h; k += 6)
  615. {
  616. a = ((LPBYTE)(gpScreen->pixels))[k];
  617. b = ((LPBYTE)(gpScreenBak->pixels))[k];
  618. if (i > 0)
  619. {
  620. if ((a & 0x0F) > (b & 0x0F))
  621. {
  622. b++;
  623. }
  624. else if ((a & 0x0F) < (b & 0x0F))
  625. {
  626. b--;
  627. }
  628. }
  629. ((LPBYTE)(gpScreenBak->pixels))[k] = ((a & 0xF0) | (b & 0x0F));
  630. }
  631. //
  632. // Draw the backup buffer to the screen
  633. //
  634. if (g_wShakeTime != 0)
  635. {
  636. //
  637. // Shake the screen
  638. //
  639. SDL_Rect srcrect, dstrect;
  640. srcrect.x = 0;
  641. srcrect.y = 0;
  642. srcrect.w = 320;
  643. srcrect.h = 200 - g_wShakeLevel;
  644. dstrect.x = 0;
  645. dstrect.y = screenRealY;
  646. dstrect.w = 320 * gpScreenReal->w / gpScreen->w;
  647. dstrect.h = (200 - g_wShakeLevel) * screenRealHeight / gpScreen->h;
  648. if (g_wShakeTime & 1)
  649. {
  650. srcrect.y = g_wShakeLevel;
  651. }
  652. else
  653. {
  654. dstrect.y = (screenRealY + g_wShakeLevel) * screenRealHeight / gpScreen->h;
  655. }
  656. SDL_SoftStretch(gpScreenBak, &srcrect, gpScreenReal, &dstrect);
  657. if (g_wShakeTime & 1)
  658. {
  659. dstrect.y = (screenRealY + screenRealHeight - g_wShakeLevel) * screenRealHeight / gpScreen->h;
  660. }
  661. else
  662. {
  663. dstrect.y = screenRealY;
  664. }
  665. dstrect.h = g_wShakeLevel * screenRealHeight / gpScreen->h;
  666. SDL_FillRect(gpScreenReal, &dstrect, 0);
  667. SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
  668. g_wShakeTime--;
  669. }
  670. else
  671. {
  672. dstrect.x = 0;
  673. dstrect.y = screenRealY;
  674. dstrect.w = gpScreenReal->w;
  675. dstrect.h = screenRealHeight;
  676. SDL_SoftStretch(gpScreenBak, NULL, gpScreenReal, &dstrect);
  677. SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
  678. }
  679. }
  680. }
  681. if (SDL_MUSTLOCK(gpScreenReal))
  682. {
  683. SDL_UnlockSurface(gpScreenReal);
  684. }
  685. //
  686. // Draw the result buffer to the screen as the final step
  687. //
  688. VIDEO_UpdateScreen(NULL);
  689. }