/src/os/psp/ftk_psp.c

http://ftk.googlecode.com/ · C · 138 lines · 85 code · 19 blank · 34 comment · 5 complexity · 41b352128bfa65feb5d62b4a3c7c957c MD5 · raw file

  1. /*
  2. * File: ftk_psp.c
  3. * Author: Tao Yu <yut616@gmail.com>
  4. * Brief: psp specific functions.
  5. *
  6. * Copyright (c) 2009 - 2010 Li XianJing <xianjimli@hotmail.com>
  7. *
  8. * Licensed under the Academic Free License version 2.1
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. /*
  25. * History:
  26. * ================================================================
  27. * 2010-03-11 Tao Yu <yut616@gmail.com> created.
  28. *
  29. */
  30. #include <signal.h>
  31. #include "ftk_typedef.h"
  32. #include "ftk_psp.h"
  33. #include "ftk_log.h"
  34. static char g_work_dir[FTK_MAX_PATH+1] = {0};
  35. static char g_data_dir[FTK_MAX_PATH+1] = {0};
  36. static char g_testdata_dir[FTK_MAX_PATH+1] = {0};
  37. /* Define the module info section */
  38. PSP_MODULE_INFO("FTK", 0, 1, 1);
  39. /* Define the main thread's attribute value (optional) */
  40. PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
  41. /* Exit callback */
  42. static int exit_callback(int arg1, int arg2, void *common)
  43. {
  44. sceKernelExitGame();
  45. return 0;
  46. }
  47. /* Callback thread */
  48. static int CallbackThread(SceSize args, void *argp)
  49. {
  50. int cbid;
  51. cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
  52. sceKernelRegisterExitCallback(cbid);
  53. sceKernelSleepThreadCB();
  54. return 0;
  55. }
  56. /* Sets up the callback thread and returns its thread id */
  57. static int SetupCallbacks(void)
  58. {
  59. int thid = 0;
  60. thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
  61. if(thid >= 0)
  62. sceKernelStartThread(thid, 0, 0);
  63. return thid;
  64. }
  65. char* ftk_get_root_dir(void)
  66. {
  67. return g_work_dir;
  68. }
  69. char* ftk_get_data_dir(void)
  70. {
  71. return g_data_dir;
  72. }
  73. char* ftk_get_testdata_dir(void)
  74. {
  75. return g_testdata_dir;
  76. }
  77. static Ret psp_init(int argc, char** argv)
  78. {
  79. char *p = NULL;
  80. char *cmd = argv[0];
  81. pspDebugScreenInit();
  82. SetupCallbacks();
  83. sceCtrlSetSamplingCycle(0);
  84. sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
  85. if(cmd)
  86. {
  87. ftk_logd("%s: cmd: %s\n", __func__, cmd);
  88. p = strrchr(cmd, '/');
  89. if(p != NULL)
  90. {
  91. *p = '\0';
  92. ftk_snprintf(g_work_dir, FTK_MAX_PATH, "%s", cmd);
  93. ftk_snprintf(g_data_dir, FTK_MAX_PATH, "%s/data", g_work_dir);
  94. ftk_snprintf(g_testdata_dir, FTK_MAX_PATH, "%s/testdata", g_work_dir);
  95. }
  96. }
  97. ftk_logd("%s: work dir: %s\n", __func__, g_work_dir);
  98. return RET_OK;
  99. }
  100. size_t ftk_get_relative_time(void)
  101. {
  102. struct timeval now = {0};
  103. sceKernelLibcGettimeofday(&now, NULL);
  104. return now.tv_sec*1000 + now.tv_usec/1000;
  105. }
  106. int ftk_platform_init(int argc, char** argv)
  107. {
  108. return psp_init(argc, argv);
  109. }
  110. void ftk_platform_deinit(void)
  111. {
  112. return;
  113. }
  114. char *ftk_getcwd(char *buf, size_t size)
  115. {
  116. return_val_if_fail(buf != NULL, NULL);
  117. snprintf(buf, size, "%s", g_work_dir);
  118. return buf;
  119. }