main_PSP.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // Copyright (c) 2009, Pal_Bazzi.
  3. //
  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 <pspkernel.h>
  22. #include <pspdebug.h>
  23. #include <pspsdk.h>
  24. #include <psppower.h>
  25. #include <pspthreadman.h>
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #define PSP_HEAP_MEMSIZE 12288
  29. PSP_MODULE_INFO("SDLPAL", 0, 1, 1);
  30. PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
  31. PSP_HEAP_SIZE_KB(PSP_HEAP_MEMSIZE);
  32. //
  33. //Exit callback
  34. //
  35. int PSPExitCallback(int arg1, int arg2, void *common)
  36. {
  37. exit(0);
  38. return 0;
  39. }
  40. //
  41. //Reopen MKF files when resume from suspend
  42. //
  43. int PSPSuspendCallback(int arg1, int arg2, void *common)
  44. {
  45. if (pwrflags & PSP_POWER_CB_RESUME_COMPLETE)
  46. {
  47. gpGlobals->f.fpFBP = UTIL_OpenRequiredFile("fbp.mkf");
  48. gpGlobals->f.fpDATA = UTIL_OpenRequiredFile("data.mkf");
  49. gpGlobals->f.fpFIRE = UTIL_OpenRequiredFile("fire.mkf");
  50. gpGlobals->f.fpSSS = UTIL_OpenRequiredFile("sss.mkf");
  51. gpGlobals->lpObjectDesc = PAL_LoadObjectDesc(va("%s%s", PAL_PREFIX, "desc.dat"));
  52. SOUND_Reload_VOC();
  53. }
  54. int cbid;
  55. cbid = sceKernelCreateCallback("suspend Callback", PSPSuspendCallback, NULL);
  56. scePowerRegisterCallback(0, cbid);
  57. return 0;
  58. }
  59. //
  60. //setup callbacks thread
  61. //
  62. int PSPRegisterCallbackThread(SceSize args, void *argp)
  63. {
  64. int cbid;
  65. cbid = sceKernelCreateCallback("Exit Callback", PSPExitCallback, NULL);
  66. sceKernelRegisterExitCallback(cbid);
  67. cbid = sceKernelCreateCallback("suspend Callback", PSPSuspendCallback, NULL);
  68. scePowerRegisterCallback(0, cbid);
  69. sceKernelSleepThreadCB();
  70. return 0;
  71. }
  72. //
  73. //setup exit callback
  74. //
  75. int PSPSetupCallbacks(void)
  76. {
  77. int thid = 0;
  78. thid = sceKernelCreateThread("update_thread", PSPRegisterCallbackThread, 0x11, 0xFA0, 0, 0);
  79. if(thid >= 0)
  80. sceKernelStartThread(thid, 0, 0);
  81. return thid;
  82. }
  83. //
  84. //Init on PSP
  85. //
  86. void sdlpal_psp_init(void)
  87. {
  88. // Init Debug Screen
  89. pspDebugScreenInit();
  90. // PSP set callbacks
  91. PSPSetupCallbacks();
  92. // Register sceKernelExitGame() to be called when we exit
  93. atexit(sceKernelExitGame);
  94. // set PSP CPU clock
  95. scePowerSetClockFrequency(333 , 333 , 166);
  96. }