main_PSP.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
  2. //
  3. // Copyright (c) 2009, Pal_Bazzi.
  4. //
  5. // All rights reserved.
  6. //
  7. // This file is part of SDLPAL.
  8. //
  9. // SDLPAL is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation, either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. //
  22. #include <pspkernel.h>
  23. #include <pspdebug.h>
  24. #include <pspsdk.h>
  25. #include <psppower.h>
  26. #include <pspthreadman.h>
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #define PSP_HEAP_MEMSIZE 12288
  30. PSP_MODULE_INFO("SDLPAL", 0, 1, 1);
  31. PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
  32. PSP_HEAP_SIZE_KB(PSP_HEAP_MEMSIZE);
  33. void
  34. SOUND_Reload(
  35. void
  36. )
  37. {
  38. fclose(gSndPlayer.mkf);
  39. SOUND_LoadMKF();
  40. }
  41. //
  42. //Exit callback
  43. //
  44. int PSPExitCallback(int arg1, int arg2, void *common)
  45. {
  46. exit(0);
  47. return 0;
  48. }
  49. //
  50. //Reopen MKF files when resume from suspend
  51. //
  52. int PSPSuspendCallback(int arg1, int pwrflags, void *common)
  53. {
  54. if (pwrflags & PSP_POWER_CB_RESUME_COMPLETE)
  55. {
  56. UTIL_CloseFile(gpGlobals->f.fpFBP);
  57. UTIL_CloseFile(gpGlobals->f.fpMGO);
  58. UTIL_CloseFile(gpGlobals->f.fpBALL);
  59. UTIL_CloseFile(gpGlobals->f.fpDATA);
  60. UTIL_CloseFile(gpGlobals->f.fpF);
  61. UTIL_CloseFile(gpGlobals->f.fpFIRE);
  62. UTIL_CloseFile(gpGlobals->f.fpRGM);
  63. UTIL_CloseFile(gpGlobals->f.fpSSS);
  64. gpGlobals->f.fpFBP = UTIL_OpenRequiredFile("fbp.mkf");
  65. gpGlobals->f.fpDATA = UTIL_OpenRequiredFile("data.mkf");
  66. gpGlobals->f.fpFIRE = UTIL_OpenRequiredFile("fire.mkf");
  67. gpGlobals->f.fpSSS = UTIL_OpenRequiredFile("sss.mkf");
  68. gpGlobals->lpObjectDesc = PAL_LoadObjectDesc(va("%s%s", PAL_PREFIX, "desc.dat"));
  69. SOUND_Reload();
  70. }
  71. int cbid;
  72. cbid = sceKernelCreateCallback("suspend Callback", PSPSuspendCallback, NULL);
  73. scePowerRegisterCallback(0, cbid);
  74. return 0;
  75. }
  76. //
  77. //setup callbacks thread
  78. //
  79. int PSPRegisterCallbackThread(SceSize args, void *argp)
  80. {
  81. int cbid;
  82. cbid = sceKernelCreateCallback("Exit Callback", PSPExitCallback, NULL);
  83. sceKernelRegisterExitCallback(cbid);
  84. cbid = sceKernelCreateCallback("suspend Callback", PSPSuspendCallback, NULL);
  85. scePowerRegisterCallback(0, cbid);
  86. sceKernelSleepThreadCB();
  87. return 0;
  88. }
  89. //
  90. //setup exit callback
  91. //
  92. int PSPSetupCallbacks(void)
  93. {
  94. int thid = 0;
  95. thid = sceKernelCreateThread("update_thread", PSPRegisterCallbackThread, 0x11, 0xFA0, 0, 0);
  96. if(thid >= 0)
  97. sceKernelStartThread(thid, 0, 0);
  98. return thid;
  99. }
  100. //
  101. //Init on PSP
  102. //
  103. void sdlpal_psp_init(void)
  104. {
  105. // Init Debug Screen
  106. pspDebugScreenInit();
  107. // PSP set callbacks
  108. PSPSetupCallbacks();
  109. // Register sceKernelExitGame() to be called when we exit
  110. atexit(sceKernelExitGame);
  111. // set PSP CPU clock
  112. scePowerSetClockFrequency(333 , 333 , 166);
  113. }