PageRenderTime 25ms CodeModel.GetById 2ms app.highlight 17ms RepoModel.GetById 2ms app.codeStats 0ms

/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/*
 26 * History:
 27 * ================================================================
 28 * 2010-03-11 Tao Yu <yut616@gmail.com> created.
 29 *
 30 */
 31#include <signal.h>
 32#include "ftk_typedef.h"
 33#include "ftk_psp.h"
 34#include "ftk_log.h"
 35
 36static char g_work_dir[FTK_MAX_PATH+1] = {0};
 37static char g_data_dir[FTK_MAX_PATH+1] = {0};
 38static char g_testdata_dir[FTK_MAX_PATH+1] = {0};
 39
 40/* Define the module info section */
 41PSP_MODULE_INFO("FTK", 0, 1, 1);
 42
 43/* Define the main thread's attribute value (optional) */
 44PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
 45
 46/* Exit callback */
 47static int exit_callback(int arg1, int arg2, void *common) 
 48{
 49	sceKernelExitGame();
 50	return 0;
 51}
 52
 53/* Callback thread */
 54static int CallbackThread(SceSize args, void *argp) 
 55{
 56	int cbid;
 57
 58	cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
 59	sceKernelRegisterExitCallback(cbid);
 60	sceKernelSleepThreadCB();
 61	return 0;
 62}
 63
 64/* Sets up the callback thread and returns its thread id */
 65static int SetupCallbacks(void) 
 66{
 67	int thid = 0;
 68	thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
 69	if(thid >= 0) 
 70		sceKernelStartThread(thid, 0, 0);
 71	return thid;
 72}
 73
 74char* ftk_get_root_dir(void)
 75{
 76	return g_work_dir;
 77}
 78
 79char* ftk_get_data_dir(void)
 80{
 81	return g_data_dir;
 82}
 83
 84char* ftk_get_testdata_dir(void)
 85{
 86	return g_testdata_dir;
 87}
 88
 89static Ret psp_init(int argc, char** argv)
 90{
 91	char *p = NULL;
 92	char *cmd = argv[0];
 93	pspDebugScreenInit();
 94	SetupCallbacks();
 95
 96	sceCtrlSetSamplingCycle(0);
 97	sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
 98
 99	if(cmd) 
100	{
101		ftk_logd("%s: cmd: %s\n", __func__, cmd);
102		p = strrchr(cmd, '/');
103		if(p != NULL)
104		{
105			*p = '\0';
106			ftk_snprintf(g_work_dir, FTK_MAX_PATH, "%s", cmd);
107			ftk_snprintf(g_data_dir, FTK_MAX_PATH, "%s/data", g_work_dir);
108			ftk_snprintf(g_testdata_dir, FTK_MAX_PATH, "%s/testdata", g_work_dir);
109		}
110	}
111	ftk_logd("%s: work dir: %s\n", __func__, g_work_dir);
112	return RET_OK;
113}
114
115size_t ftk_get_relative_time(void)
116{
117	struct timeval now = {0};
118	sceKernelLibcGettimeofday(&now, NULL);
119
120	return now.tv_sec*1000 + now.tv_usec/1000;
121}
122
123int ftk_platform_init(int argc, char** argv)
124{
125	return psp_init(argc, argv);
126}
127
128void ftk_platform_deinit(void)
129{
130	return;
131}
132
133char *ftk_getcwd(char *buf, size_t size)
134{
135	return_val_if_fail(buf != NULL, NULL);
136	snprintf(buf, size, "%s", g_work_dir);
137	return buf;
138}