コード例 #1
0
ファイル: me_wrapper.c プロジェクト: esxgx/uofw
int initRpc()
{
	meRpc.mutex = sceKernelCreateMutex("SceMediaEngineRpc", 0x101, 0, 0);
	if (meRpc.mutex < 0)
		return meRpc.mutex;
	meRpc.sema = sceKernelCreateSema("SceMediaEngineAvcPower" , 0x101, 1, 1, 0);
	if (meRpc.sema < 0)
		return meRpc.sema;
	meRpc.event = sceKernelCreateEventFlag("SceMediaEngineRpcWait", 0x201, 0, 0);
	if (meRpc.event < 0)
		return meRpc.event;
	sceSysregIntrEnd();
	int ret = sceKernelRegisterIntrHandler(SCE_MECODEC_INT, 2, (void*)&interruptHandler, (void*)meRpc.event, 0);
	if (ret < 0)
		return ret;
	return sceKernelEnableIntr(SCE_MECODEC_INT);
}
コード例 #2
0
ファイル: MusicEngine.c プロジェクト: Oize/pspstacklesspython
int Init(int channel) {
	pspAudioInit();											// init the audio psp

	mad_stream_init(&stream);								// create the mad variables, streams etc.
	mad_frame_init(&frame); 
	mad_synth_init(&synth); 
	mad_timer_reset(&timer);
	pspAudioSetChannelCallback(channel, fillOutputBuffer, 0);		// set the callback to the function.
	mutex = sceKernelCreateSema("myMutexName", 0, 1, 1, 0);	// create the mutex for threading secure.
	pausesong = 1;											// set the variable to pause so no sound is played.
	started = 0;											// the mp3 has not yet started.
	file = 0;												// set the file to zero
	fileSize = 1;
	filePos = 0;
	printf("MusicEngine is initialized.\n");

	return 1;
};
コード例 #3
0
ファイル: SDL_syssem.c プロジェクト: GWRon/sdl.mod
/* Create a semaphore */
SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
{
    SDL_sem *sem;

    sem = (SDL_sem *) malloc(sizeof(*sem));
    if (sem != NULL) {
        /* TODO: Figure out the limit on the maximum value. */
        sem->semid = sceKernelCreateSema("SDL sema", 0, initial_value, 255, NULL);
        if (sem->semid < 0) {
            SDL_SetError("Couldn't create semaphore");
            free(sem);
            sem = NULL;
        }
    } else {
        SDL_OutOfMemory();
    }

    return sem;
}
コード例 #4
0
ファイル: mutex.c プロジェクト: Falaina/cspspemu
void multipleTest() {
	int threads[N_THREADS];
	int n;
	
	semaid = sceKernelCreateSema("sema1", 0, 0, 255, NULL);
	mutexid = sceKernelCreateMutex("mutex", PSP_MUTEX_ATTR_FIFO | PSP_MUTEX_ATTR_ALLOW_RECURSIVE, 0);
	{
		for (n = 0; n < N_THREADS; n++) {
			sceKernelStartThread(threads[n] = sceKernelCreateThread("multipleTestThread", (void *)&multipleTestThread, 0x12, 0x10000, 0, NULL), sizeof(int), &n);
		}

		sceKernelSignalSema(semaid, N_THREADS);
		
		for (n = 0; n < N_THREADS; n++) {
			sceKernelWaitThreadEnd(threads[n], NULL);
		}
	}
	sceKernelDeleteMutex(mutexid);
}
コード例 #5
0
int main(int argc, char **argv) {
	SceUID sema = sceKernelCreateSema("cancel", 0, 0, 1, NULL);

	CANCEL_TEST("Normal", sema, 1);
	CANCEL_TEST("Greater than max", sema, 3);
	CANCEL_TEST("Zero", sema, 0);
	CANCEL_TEST("Negative -3", sema, -3);
	CANCEL_TEST("Negative -1", sema, -1);

	CANCEL_TEST_WITH_WAIT("Normal", sema, 1);
	CANCEL_TEST_WITH_WAIT("Greater than max", sema, 3);
	CANCEL_TEST_WITH_WAIT("Zero", sema, 0);
	CANCEL_TEST_WITH_WAIT("Negative -3", sema, -3);
	CANCEL_TEST_WITH_WAIT("Negative -1", sema, -1);

	sceKernelDeleteSema(sema);

	TWO_STEP_SCHED_TEST("Cancel waited 0 then 1", 0, 1,
		result = 0;
		CANCEL_TEST_WITH_WAIT("To 0", sema1, 0);
	,
コード例 #6
0
ファイル: vblank.c プロジェクト: HomerSp/pspautotests
void basicUsage() {
	int value = 7;
	sema = sceKernelCreateSema("semaphore", 0, 0, 255, NULL);
	mainThreadId = sceKernelGetThreadId();

	//int cb = sceKernelCreateCallback("vblankCallback", vblankCallback, NULL);
	sceKernelRegisterSubIntrHandler(PSP_DISPLAY_SUBINT, 0, vblankCallback, &value);
	printf("beforeEnableVblankCallback\n");
	sceKernelEnableSubIntr(PSP_DISPLAY_SUBINT, 0);
	printf("afterEnableVblankCallback\n");
	
	sceKernelWaitSemaCB(sema, 1, NULL);
	//while (!vblankCalled) { sceKernelDelayThread(1000); }
	if (called) {
		printf("vblankCallback(%d):%d\n", *(int *)&value, (vblankCalledThread == mainThreadId));
	}
	
	sceKernelReleaseSubIntrHandler(PSP_DISPLAY_SUBINT, 0);
	//sceDisplayWaitVblank();
	
	printf("ended\n");
}
コード例 #7
0
ファイル: threads.c プロジェクト: mrcmunir/cspspemu
void testThreads() {
	int n;

	// Create a semaphore for waiting both threads to execute.
	semaphore = sceKernelCreateSema("Semaphore", 0, 0, 2, NULL);
	
	for (n = 0; n < 2; n++) {
		// Create and start a new thread passing a stack local variable as parameter.
		// When sceKernelStartThread, thread is executed immediately, so in a while it has access
		// to the unmodified stack of the thread that created this one and can access n,
		// before it changes its value.
		sceKernelStartThread(
			sceKernelCreateThread("Test Thread", (void *)&threadFunction, 0x12, 0x10000, 0, NULL),
			n, &n
		);
	}

	// Wait until semaphore have been signaled two times (both new threads have been executed).
	sceKernelWaitSema(semaphore, 2, NULL);

	// After both threads have been executed, we will emit a -1 to check that semaphores work fine.
	printf("%d\n", -1);
}
コード例 #8
0
ファイル: pmp_play.c プロジェクト: DavisDev/pmplayer-advance
char *pmp_play_open(struct pmp_play_struct *p, struct movie_file_struct *movie, int usePos, int pspType, int tvAspectRatio, int tvWidth, int tvHeight, int videoMode)
	{
	pmp_play_safe_constructor(p);
	p->subtitle = 0;
	p->subtitle_count = 0;

	
	char *result = pmp_decode_open(&p->decoder, movie->movie_file, pspType, tvAspectRatio, tvWidth, tvHeight, videoMode);
	if (result != 0)
		{
		pmp_play_close(p, 0, pspType);
		return(result);
		}

	if (subtitle_parse_search( movie, p->decoder.reader.file.header.video.rate, p->decoder.reader.file.header.video.scale, &p->subtitle_count)==0) p->subtitle = 1;
	
	if ( cooleyesAudioSetFrequency(sceKernelDevkitVersion(), p->decoder.reader.file.header.audio.rate) != 0)
		{
		pmp_play_close(p, 0, pspType);
		return("pmp_play_open: sceAudioSetFrequency failed");
		}
	p->audio_reserved = sceAudioChReserve(0, p->decoder.reader.file.header.audio.scale, PSP_AUDIO_FORMAT_STEREO);
	if (p->audio_reserved < 0)
		{
		pmp_play_close(p, 0, pspType);
		return("pmp_play_open: sceAudioChReserve failed");
		}


	p->semaphore_can_get = sceKernelCreateSema("can_get", 0, 0, p->decoder.number_of_frame_buffers, 0);
	if (p->semaphore_can_get < 0)
		{
		pmp_play_close(p, 0, pspType);
		return("pmp_play_open: sceKernelCreateSema failed on semaphore_can_get");
		}


	p->semaphore_can_put = sceKernelCreateSema("can_put", 0, p->decoder.number_of_frame_buffers, p->decoder.number_of_frame_buffers, 0);
	if (p->semaphore_can_put < 0)
		{
		pmp_play_close(p, 0, pspType);
		return("pmp_play_open: sceKernelCreateSema failed on semaphore_can_put");
		}


	p->semaphore_can_show = sceKernelCreateSema("can_show", 0, 0, 1, 0);
	if (p->semaphore_can_show < 0)
		{
		pmp_play_close(p, 0, pspType);
		return("pmp_play_open: sceKernelCreateSema failed on semaphore_can_show");
		}


	p->semaphore_show_done = sceKernelCreateSema("show_done", 0, 0, 1, 0);
	if (p->semaphore_show_done < 0)
		{
		pmp_play_close(p, 0, pspType);
		return("pmp_play_open: sceKernelCreateSema failed on semaphore_show_done");
		}




	p->output_thread = sceKernelCreateThread("output", pmp_output_thread, 0x8, 0x10000, 0, 0);
	if (p->output_thread < 0)
		{
		pmp_play_close(p, 0, pspType);
		return("pmp_play_open: sceKernelCreateThread failed on output_thread");
		}


	p->show_thread = sceKernelCreateThread("show", pmp_show_thread, 0x8, 0x10000, 0, 0);
	if (p->show_thread < 0)
		{
		pmp_play_close(p, 0, pspType);
		return("pmp_play_open: sceKernelCreateThread failed on show_thread");
		}




	p->return_request = 0;
	p->return_result  = 0;


	p->paused = 0;
	p->seek   = 0;


	p->audio_stream     = 0;
	//add by cooleyes 2007/02/01
	p->audio_channel    = 0;
	//add end
	p->volume_boost     = 3;
	p->aspect_ratio     = 0;
	p->zoom             = 100;
	p->luminosity_boost = 0;
	p->show_interface   = 0;
	p->loop             = 0;
	p->resume_pos		= 0;
	p->last_keyframe_pos= 0;
	p->subtitle_format  = (((gufont_haveflags&GU_FONT_HAS_UNICODE_CHARMAP))?1:0);
	p->subtitle_fontcolor = 0;
	p->subtitle_bordercolor = 0;
	
	memcpy(p->hash, movie->movie_hash, 16);
	
	if (usePos) pmp_stat_load( p );

	return(0);
	}
コード例 #9
0
ファイル: psp_sound.cpp プロジェクト: DarkSlim/unrealspeccyp
	eSimpleMutex(const char* name)
	{
		handle = sceKernelCreateSema(name, 0, 1, 1, 0);
	}
コード例 #10
0
ファイル: libmpeg.c プロジェクト: yne/js-psp
int createSema (int initVal, int maxVal,const char *name, int*ret){
	return (*ret=sceKernelCreateSema(name,0,initVal,maxVal,0))<0?0x80000041:*ret;
}
コード例 #11
0
ファイル: audio.cpp プロジェクト: 0nza1101/PSP-libpmfplayer
SceInt32 CPMFPlayer::InitAudio()
{
	int i = 0, fail = 0;

	Audio.m_AudioChannel = sceAudioChReserve(-1, 512, PSP_AUDIO_FORMAT_STEREO);
	if(Audio.m_AudioChannel < 0)
	{
		sprintf(m_LastError, "sceAudioChReserve() failed: 0x%08X", (int)Audio.m_AudioChannel);
		return -1;
	}

	sceAudioSetChannelDataLen(Audio.m_AudioChannel, m_MpegAtracOutSize / 4);

	Audio.m_ThreadID = sceKernelCreateThread("audio_thread", T_Audio, 0x3D, 0x10000, PSP_THREAD_ATTR_USER, NULL);
	if(Audio.m_ThreadID < 0)
	{
		sprintf(m_LastError, "sceKernelCreateThread() failed: 0x%08X", (int)Audio.m_ThreadID);
		goto exit0;
	}

	Audio.m_SemaphoreStart = sceKernelCreateSema("audio_start_sema",  0, 0, 1, NULL);
	if(Audio.m_SemaphoreStart < 0)
	{
		sprintf(m_LastError, "sceKernelCreateSema() failed: 0x%08X", (int)Audio.m_SemaphoreStart);
		goto exit1;
	}

	Audio.m_SemaphoreLock = sceKernelCreateSema("audio_lock_sema",  0, 1, 1, NULL);
	if(Audio.m_SemaphoreLock	< 0 )
	{
		sprintf(m_LastError, "sceKernelCreateSema() failed: 0x%08X", (int)Audio.m_SemaphoreLock);
		goto exit2;
	}

	Audio.m_iNumBuffers			= 4;
	Audio.m_iFullBuffers		= 0;
	Audio.m_iPlayBuffer			= 1;
	Audio.m_iDecodeBuffer		= 0;
	Audio.m_iAbort				= 0;
	Audio.m_LastError			= m_LastError;

	for(i = 0; i < Audio.m_iNumBuffers; i++)
	{
		Audio.m_pAudioBuffer[i] = NULL;
		Audio.m_iBufferTimeStamp[i] = 0;
	}

	for(i = 0; i < Audio.m_iNumBuffers; i++)
	{
		Audio.m_pAudioBuffer[i] = memalign(64, m_MpegAtracOutSize);
		if(Audio.m_pAudioBuffer[i] < 0) fail++;
	}

	if(fail > 0)
	{
		for(i = 0; i < Audio.m_iNumBuffers; i++)
		{
			if(Audio.m_pAudioBuffer[i] != NULL)
				free(Audio.m_pAudioBuffer[i]);
		}

		sprintf(m_LastError, "malloc() failed!");
		goto exit3;
	}

	return 0;

exit3:
	sceKernelDeleteSema(Audio.m_SemaphoreLock);
exit2:
	sceKernelDeleteSema(Audio.m_SemaphoreStart);
exit1:
	sceKernelDeleteThread(Audio.m_ThreadID);
exit0:
	sceAudioChRelease(Audio.m_AudioChannel);

	return -1;
}
コード例 #12
0
ファイル: main.c プロジェクト: bensaraceno/PSP
int main() {
	SceUID video_thid; //int xx, yy, nubspeed; 
	SetupCallbacks(); pspDebugScreenInit(); initGraphics();
	SceCtrlData pad, oldpad; oldpad.Buttons = 0xFFFFFFFF;
	sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

	// Start the video thread to draw objects to screen and manage video input.
	video_thid = sceKernelCreateThread("video_thread", video_thread, 0x12, 512 * 1024, 0, NULL);
	if (video_thid > 0) sceKernelStartThread(video_thid, 0, NULL);
	
	while (!connected) { sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons) connected = 1; }

	// Wait for camera to be aligned to playing area and for game to start.
	while (running && (!aligned || menu)) {
		// Uncomment the following lines to include analog stick and button input during alignment.
		/*sceCtrlPeekBufferPositive(&pad, 1);
		xx = pad.Lx - 128; yy = pad.Ly - 128;
		nubspeed = sqrt((xx * xx) + (yy * yy)) / (2 * sqrt(sqrt((xx * xx) + (yy * yy))));
		if (xx > 30) cursorx += nubspeed; else if (xx < -30) cursorx -= nubspeed;
		if (yy > 30) cursory += nubspeed; else if (yy < -30) cursory -= nubspeed;
		if (cursorx > 480) cursorx = 480; else if (cursorx < 0) cursorx = 0;
		if (cursory > 272) cursory = 272; else if (cursory < 0) cursory = 0;

		// Detect changes in button input.
		if (pad.Buttons != oldpad.Buttons) {
		}
		oldpad.Buttons = pad.Buttons;*/
		sceKernelDelayThread(50000);
	}

	int x;
	// Initialize global data.
	_highScore    = 0;
	_score        = 0;
	_ballCount    = 0;
	_resBalls     = START_RES_BALLS;
	_gameState    = GAME_RUNNING;
	_pauseSem     = sceKernelCreateSema("PauseSem", 0, 1, 1, 0);

	// Initialize array used to keep track of balls in play.
	for (x = 0; x < MAX_BALLS; x++) { _activeBalls[x] = 0; }

	// Initialize the paddle
	(&_paddle)->h       = 60;
	(&_paddle)->w       = 8;
	(&_paddle)->xPos    = 3;
	(&_paddle)->yPos    = 136;
	(&_paddle)->xPosOld = 250;
	(&_paddle)->yPosOld = 250;
	(&_paddle)->speed   = 10;
	(&_paddle)->dir     = 1;
	(&_paddle)->color   = COLOR_LIGHT_BLUE;

	while (running) {
		// Uncomment the following lines to include analog stick and button input.
		// Defeats the purpose as holding the PSP or touching it shakes the camera
		// and makes the laser pointer input very inaccurate. Could be useful with
		// the PSP remote control to allow games to be played using the remote
		// for D-Pad movement and the laser pointer for looking/aiming.
		/*sceCtrlPeekBufferPositive(&pad, 1);
		xx = pad.Lx - 128; yy = pad.Ly - 128;
		nubspeed = sqrt((xx * xx) + (yy * yy)) / (2 * sqrt(sqrt((xx * xx) + (yy * yy))));
		if (xx > 30) cursorx += nubspeed; else if (xx < -30) cursorx -= nubspeed;
		if (yy > 30) cursory += nubspeed; else if (yy < -30) cursory -= nubspeed;
		if (cursorx > 480) cursorx = 480; else if (cursorx < 0) cursorx = 0;
		if (cursory > 272) cursory = 272; else if (cursory < 0) cursory = 0;

		// Detect changes in button input.
		if (pad.Buttons != oldpad.Buttons) {
		}
		oldpad.Buttons = pad.Buttons;*/

		// Change sprite speeds, positions and behaviors here.
		CreateBall(); // Create a ball and put it in play.
		while (_gameState == GAME_RUNNING) { CheckUserInput(); }
		while (_gameState == GAME_CONTINUE) { sceKernelDelayThread(2000); }
		while (_gameState == GAME_OVER) { sceKernelDelayThread(2000); }

		sceKernelDelayThread(200);
		//CreateBall(); // Create a ball and put it in play.
	}

	StopApp();
	sceKernelExitGame();
	return 0;
}
コード例 #13
0
ファイル: NptPSPThreads.cpp プロジェクト: Avoidnf8/xbmc-fork
/*----------------------------------------------------------------------
|       NPT_PSPMutex::NPT_PSPMutex
+---------------------------------------------------------------------*/
NPT_PSPMutex::NPT_PSPMutex()
{
    char sema_name[256];
    sprintf(sema_name, "sema_%d", (int)NPT_System::GetSystem()->GetRandomInteger());
    m_semaphore = sceKernelCreateSema(sema_name, SCE_KERNEL_SA_THFIFO, 1, 1, NULL);
}
コード例 #14
0
ファイル: Memory.cpp プロジェクト: Fighter19/PSPMania
static void InitAlloc()
{
	g_Mutex = sceKernelCreateSema( "MemoyMutex", 0, 1, 1, NULL );
	g_MutexOwner = -1;
	g_TotalMemory = GetMemoryFreeSize( false );
}