i'm newbie here, i have a question and need your help.
while(1)
{
SceCtrlData ctl;
do {
sceKernelDelayThread(20000);
sceCtrlPeekBufferPositive(&ctl, 1);
} while((ctl.Buttons & 0xF0FFFF) != PSP_CTRL_XXX);
//do something
}
i don't quite understand of 'sceKernelDelayThread' (red above), if i call this, will this thread be suspended? or?
if suspended, when press any button on psp, will the system awake this thread automatically then?
if not, what does this code mean here? i guess it will block the thread so if i press any button the thread will don't have any response?
thanks in advance.
hope you're clear on this, my English is not very good, sorry. :(
hello everyone, i have a problem on thread.
-
- Posts: 87
- Joined: Thu Oct 01, 2009 8:43 pm
Hi,
this will just make the thread do nothing for the specified time.
It has nothing to do with sleep mode of PSP. There is a thread dealing with sleep mode, check out this one...
http://forums.ps2dev.org/viewtopic.php?t=12766
this will just make the thread do nothing for the specified time.
It has nothing to do with sleep mode of PSP. There is a thread dealing with sleep mode, check out this one...
http://forums.ps2dev.org/viewtopic.php?t=12766
thanks for your reply.
this code is part of the CheatMaster v0.7 source code, i think it's absolutely useful there.
this is the whole source code:
as you can see, there is a lot of similar code there (i marked them with bold).
this code is part of the CheatMaster v0.7 source code, i think it's absolutely useful there.
this is the whole source code:
Code: Select all
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspctrl_kernel.h>
#include <pspsdk.h>
#include <pspdisplay.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ctrl.h"
#include "graphic.h"
#include "menu.h"
#include "util.h"
#include "screenshot.h"
PSP_MODULE_INFO("SCEP_CM", 0x1000, 1, 2);
PSP_MAIN_THREAD_ATTR(0);
#define MAX_THREAD 64
static int thread_count_start, thread_count_now, pauseuid = -1;
static SceUID thread_buf_start[MAX_THREAD], thread_buf_now[MAX_THREAD], thid1 = -1, thid2 = -1;
static void pause_game(SceUID thid)
{
if(pauseuid >= 0)
return;
pauseuid = thid;
sceKernelGetThreadmanIdList(SCE_KERNEL_TMID_Thread, thread_buf_now, MAX_THREAD, &thread_count_now);
int x, y, match;
for(x = 0; x < thread_count_now; x++)
{
match = 0;
SceUID tmp_thid = thread_buf_now[x];
for(y = 0; y < thread_count_start; y++)
{
if((tmp_thid == thread_buf_start[y]) || (tmp_thid == thid1) || (tmp_thid == thid2))
{
match = 1;
break;
}
}
if(match == 0)
sceKernelSuspendThread(tmp_thid);
}
}
static void resume_game(SceUID thid)
{
if(pauseuid != thid)
return;
pauseuid = -1;
int x, y, match;
for(x = 0; x < thread_count_now; x++)
{
match = 0;
SceUID tmp_thid = thread_buf_now[x];
for(y = 0; y < thread_count_start; y++)
{
if((tmp_thid == thread_buf_start[y]) || (tmp_thid == thid1) || (tmp_thid == thid2))
{
match = 1;
break;
}
}
if(match == 0)
sceKernelResumeThread(tmp_thid);
}
}
int ss_main_thread(SceSize args, void *argp) {
thid2 = sceKernelGetThreadId();
screenshot_init();
[b]while(1)
{
SceCtrlData ctl;
do {
sceKernelDelayThread(20000);
sceCtrlPeekBufferPositive(&ctl, 1);
} while((ctl.Buttons & 0xF0FFFF) != PSP_CTRL_VOLDOWN);
Screenshot();
}[/b]
return 0;
}
void start_ssthread()
{
thid2 = sceKernelCreateThread("Screenshot main_thread", ss_main_thread, 47, 0x1000, 0, NULL);
if(thid2 >= 0)
sceKernelStartThread(thid2, 0, 0);
}
void stop_ssthread()
{
sceKernelTerminateThread(thid2);
thid2 = -1;
}
int main_thread(SceSize args, void *argp)
{
while(!sceKernelFindModuleByName("sceKernelLibrary"))
[b]sceKernelDelayThread(1000000);[/b]
scm_option * scm = loadscm();
[b]sceKernelDelayThread(5000000);[/b]
getGameInfo();
ctrl_module_start(0, 0);
setrskey(scm->rskey, getrskey());
SceCtrlData ctl;
while(1)
{
do {
[b]sceKernelDelayThread(20000);
sceCtrlPeekBufferPositive(&ctl, 1);
} while( (ctl.Buttons & scm->hotkey) != scm->hotkey);
thid1 = sceKernelGetThreadId();
pause_game(thid1);
if (initGraphic(scm->com_mode))
{
setflag(0);
start_ssthread();
drawMainMenu();
flipScreen();
stop_ssthread();
setflag(1);
}
freeGraphic();
resume_game(thid1);
}[/b]
return sceKernelExitDeleteThread(0);
}
int module_start(SceSize args, void *argp)
{
thid1 = thid2 = -1;
sceKernelGetThreadmanIdList(SCE_KERNEL_TMID_Thread, thread_buf_start, MAX_THREAD, &thread_count_start);
thid1 = sceKernelCreateThread("SCM_thread", main_thread, 47, 0x1000, 0, NULL);
if(thid1 >= 0)
sceKernelStartThread(thid1, 0, 0);
return 0;
}
int module_stop(SceSize args, void *argp)
{
return 0;
}
int module_reboot_before(SceSize args, void *argp)
{
return 0;
}
oops