main_PSP.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. //
  34. //Exit callback
  35. //
  36. int PSPExitCallback(int arg1, int arg2, void *common)
  37. {
  38. exit(0);
  39. return 0;
  40. }
  41. //
  42. //Reopen MKF files when resume from suspend
  43. //
  44. int PSPSuspendCallback(int arg1, int pwrflags, void *common)
  45. {
  46. if (pwrflags & PSP_POWER_CB_RESUME_COMPLETE)
  47. {
  48. UTIL_CloseFile(gpGlobals->f.fpFBP);
  49. UTIL_CloseFile(gpGlobals->f.fpMGO);
  50. UTIL_CloseFile(gpGlobals->f.fpBALL);
  51. UTIL_CloseFile(gpGlobals->f.fpDATA);
  52. UTIL_CloseFile(gpGlobals->f.fpF);
  53. UTIL_CloseFile(gpGlobals->f.fpFIRE);
  54. UTIL_CloseFile(gpGlobals->f.fpRGM);
  55. UTIL_CloseFile(gpGlobals->f.fpSSS);
  56. gpGlobals->f.fpFBP = UTIL_OpenRequiredFile("fbp.mkf");
  57. gpGlobals->f.fpDATA = UTIL_OpenRequiredFile("data.mkf");
  58. gpGlobals->f.fpFIRE = UTIL_OpenRequiredFile("fire.mkf");
  59. gpGlobals->f.fpSSS = UTIL_OpenRequiredFile("sss.mkf");
  60. gpGlobals->lpObjectDesc = PAL_LoadObjectDesc(va("%s%s", PAL_PREFIX, "desc.dat"));
  61. SOUND_Reload();
  62. }
  63. int cbid;
  64. cbid = sceKernelCreateCallback("suspend Callback", PSPSuspendCallback, NULL);
  65. scePowerRegisterCallback(0, cbid);
  66. return 0;
  67. }
  68. //
  69. //setup callbacks thread
  70. //
  71. int PSPRegisterCallbackThread(SceSize args, void *argp)
  72. {
  73. int cbid;
  74. cbid = sceKernelCreateCallback("Exit Callback", PSPExitCallback, NULL);
  75. sceKernelRegisterExitCallback(cbid);
  76. cbid = sceKernelCreateCallback("suspend Callback", PSPSuspendCallback, NULL);
  77. scePowerRegisterCallback(0, cbid);
  78. sceKernelSleepThreadCB();
  79. return 0;
  80. }
  81. //
  82. //setup exit callback
  83. //
  84. int PSPSetupCallbacks(void)
  85. {
  86. int thid = 0;
  87. thid = sceKernelCreateThread("update_thread", PSPRegisterCallbackThread, 0x11, 0xFA0, 0, 0);
  88. if(thid >= 0)
  89. sceKernelStartThread(thid, 0, 0);
  90. return thid;
  91. }
  92. //
  93. //Init on PSP
  94. //
  95. void sdlpal_psp_init(void)
  96. {
  97. // Init Debug Screen
  98. pspDebugScreenInit();
  99. // PSP set callbacks
  100. PSPSetupCallbacks();
  101. // Register sceKernelExitGame() to be called when we exit
  102. atexit(sceKernelExitGame);
  103. // set PSP CPU clock
  104. scePowerSetClockFrequency(333 , 333 , 166);
  105. }