 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
jcyuan
Joined: 21 Jan 2010 Posts: 4
|
Posted: Mon Jan 25, 2010 6:48 pm Post subject: hello everyone, i have a problem on thread. |
|
|
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. :( _________________ oops |
|
| Back to top |
|
 |
anmabagima
Joined: 01 Oct 2009 Posts: 96
|
Posted: Mon Jan 25, 2010 7:56 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Tue Jan 26, 2010 2:08 am Post subject: |
|
|
| 20000ms is a little high. You'll miss some button presses. Use sceDisplayWaitVblankStart(). |
|
| Back to top |
|
 |
jcyuan
Joined: 21 Jan 2010 Posts: 4
|
Posted: Tue Jan 26, 2010 12:30 pm Post subject: |
|
|
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:
| Code: |
#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;
}
|
as you can see, there is a lot of similar code there (i marked them with bold). _________________ oops |
|
| Back to top |
|
 |
jcyuan
Joined: 21 Jan 2010 Posts: 4
|
Posted: Tue Jan 26, 2010 12:32 pm Post subject: |
|
|
sorry, it seems that bold font can't be shown in [code] section. _________________ oops |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|