void PspSpeedTests::semaphoreManyThreadSpeed() { // create 4 threads for (int i=0; i<4; i++) { int thid = sceKernelCreateThread("my_thread", PspSpeedTests::threadFunc, 0x18, 0x10000, THREAD_ATTR_USER, NULL); sceKernelStartThread(thid, 0, 0); } PSP_INFO_PRINT("main thread. created threads\n"); uint32 threads = _sem.numOfWaitingThreads(); while (threads < 4) { threads = _sem.numOfWaitingThreads(); PSP_INFO_PRINT("main thread: waiting threads[%d]\n", threads); } PSP_INFO_PRINT("main: semaphore value[%d]\n", _sem.getValue()); PSP_INFO_PRINT("main thread: waiting threads[%d]\n", _sem.numOfWaitingThreads()); _sem.give(4); }
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) { SceKernelThreadInfo info; int priority = 32; /* Set priority of new thread to the same as the current thread */ info.size = sizeof(SceKernelThreadInfo); if (sceKernelGetThreadInfo(sceKernelGetThreadId(), &info) == 0) { priority = info.currentPriority; } thread->handle = sceKernelCreateThread("SDL thread", ThreadEntry, priority, 0x10000, 0, 0, NULL); if (thread->handle < 0) { return SDL_SetError("sceKernelCreateThread() failed"); } sceKernelStartThread(thread->handle, 4, &args); return 0; }
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) { SceKernelThreadInfo status; int priority = 32; /* Set priority of new thread to the same as the current thread */ status.size = sizeof(SceKernelThreadInfo); if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) { priority = status.currentPriority; } thread->handle = sceKernelCreateThread("SDL thread", ThreadEntry, priority, 0x8000, PSP_THREAD_ATTR_VFPU, NULL); if (thread->handle < 0) { return SDL_SetError("sceKernelCreateThread() failed"); } sceKernelStartThread(thread->handle, 4, &args); return 0; }
int MP3ME_Load(char * path){ MP3ME_filePos = 0; MP3ME_isPlaying = 0; MP3ME_playingTime = 0; strcpy(MP3ME_Name, path); // Needed for decode thread releaseAudio(); if (setAudioFrequency(OUTPUT_BUFFER_SIZE/4, 44100, 2) < 0){ MP3ME_Stop(); return ERROR_INVALID_SAMPLE_RATE; } MP3ME_eof = 0; MP3ME_thid = sceKernelCreateThread("decodeThread", decodeThread, THREAD_PRIORITY, 0x10000, PSP_THREAD_ATTR_USER, NULL); if(MP3ME_thid < 0) return ERROR_CREATE_THREAD; sceKernelStartThread(MP3ME_thid, 0, NULL); return OPENING_OK; }
void testMsgPipeWithThreads() { int n; msgpipe = sceKernelCreateMsgPipe("MSGPIPE", 2, 0, sizeof(Message) * msgpipe_capacity, NULL); { // Create acceptor threads, that will receive messages. for (n = 0; n < msgpipe_threadcount; n++) { current_thread_id = n; sceKernelStartThread(sceKernelCreateThread("MSGPIPE_thread", (void *)&testMsgPipeWithThreads_thread, 0x12, 0x10000, 0, NULL), 0, NULL); } // Write all the messages. Message message = {1, 2, -1}; int messageSize; int result; for (n = 0; n < msgpipe_writecount; n++) { message.index = n; result = sceKernelSendMsgPipe(msgpipe, &message, sizeof(Message), 0, &messageSize, NULL); printf("SEND[%d] : %08X, %d, %d, %d\n", n, result, message.value1, message.value2, message.index); } } sceKernelDeleteMsgPipe(msgpipe); }
int module_start(SceSize args, void *argp) { __sceCtrlPeekBufferPositive = NULL; __sceImposeGetParam = NULL; system_buttons = 0; main_volume = -1; thread_active = 0; sysbutton_thread = sceKernelCreateThread( "System Button Thread", SystemButtonsThread, 0x11, 0x200, 0, NULL ); if (sysbutton_thread >= 0) sceKernelStartThread(sysbutton_thread, 0, 0); return 0; }
int main(int argc, char *argv[]) { SceUID thid; save_argv0 = strdup(argv[0]); SetupCallbacks(); #ifdef DEBUG pspDebugScreenInit(); #endif if(pspSdkLoadInetModules() < 0) return 1; thid = sceKernelCreateThread("python_thread", main_thread, 0x18, 0x10000, PSP_THREAD_ATTR_USER|PSP_THREAD_ATTR_VFPU, NULL); sceKernelStartThread(thid, 0, NULL); sceKernelExitDeleteThread(0); return 0; }
void exit_reset(void) { psplinkSetK1(0); if(g_context.resetonexit) { /* Create a new thread to do the reset */ SceUID thid; thid = sceKernelCreateThread("PspLinkReset", reset_thread, 8, 4*1024, 0, NULL); if(thid >= 0) { sceKernelStartThread(thid, 0, NULL); } } else { SHELL_PRINT("\nsceKernelExitGame caught!\n"); /* Kill the thread, bad idea to drop back to the program */ } sceKernelExitThread(0); }
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); }
/*---------------------------------------------------------------------- | NPT_PSPThread::Start +---------------------------------------------------------------------*/ NPT_Result NPT_PSPThread::Start() { if (m_ThreadId > 0) { NPT_Debug(NPT_LOG_LEVEL_1, ":: NPT_PSPThread::Start already started !\n"); return NPT_FAILURE; } NPT_Debug(NPT_LOG_LEVEL_1, ":: NPT_PSPThread::Start - creating thread\n"); char thread_name[32]; sprintf(thread_name, "thread_%d", (int)NPT_System::GetSystem()->GetRandomInteger()); // create the native thread m_ThreadId = (SceUID) sceKernelCreateThread( thread_name, EntryPoint, SCE_KERNEL_USER_LOWEST_PRIORITY, 1024 * 16, 0, NULL); if (m_ThreadId <= 0) { // failed return NPT_FAILURE; } NPT_PSPThread* thread = this; int ret = sceKernelStartThread( m_ThreadId, sizeof(thread), &thread); if (ret != SCE_KERNEL_ERROR_OK) { return NPT_FAILURE; } return NPT_SUCCESS; }
/* psp_timer_init: * Installs the PSP timer thread. */ static int psp_timer_init(void) { /* Get the PSP ticks per second */ psp_tick_resolution = sceRtcGetTickResolution(); psp_timer_on = TRUE; timer_thread_UID = sceKernelCreateThread("psp_timer_thread",(void *)&psp_timer_thread, 0x18, 0x10000, 0, NULL); if (timer_thread_UID < 0) { ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Cannot create timer thread")); psp_timer_exit(); return -1; } if (sceKernelStartThread(timer_thread_UID, 0, NULL) != 0) { ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Cannot start timer thread")); psp_timer_exit(); return -1; } return 0; }
void SoundInit(void) { if(soundInited) SoundTerm(); if (!soundInited) { if(snd.sample_rate) { //Wait the old thread to be deleted SoundWaitTerm(); memset(audioOut, 0, 2*2048*sizeof(sample_t)); soundRunning = 1; sndThid = sceKernelCreateThread("SoundThread", SoundThread, 0x11, 0xFA0, 0, 0); if(sndThid<0) return; sceKernelStartThread(sndThid,0,0); soundInited = 1; } } }
int mp3_thread_start(void) { mp3_handle = -1; mp3_thread = -1; mp3_active = 0; mp3_status = MP3_STOP; mp3_running = 0; mp3_sleep = 0; mp3_newfile = 0; mp3_volume = 0; memset(mp3_out[0], 0, MP3_BUFFER_SIZE); memset(mp3_out[1], 0, MP3_BUFFER_SIZE); mp3_handle = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, MP3_SAMPLES, PSP_AUDIO_FORMAT_STEREO); if (mp3_handle < 0) { fatalerror(TEXT(COULD_NOT_RESERVE_AUDIO_CHANNEL_FOR_MP3)); return 0; } mp3_active = 1; mp3_thread = sceKernelCreateThread("MP3 thread", MP3Thread, 0x8, 0x40000, 0, NULL); if (mp3_thread < 0) { fatalerror(TEXT(COULD_NOT_START_MP3_THREAD)); sceAudioChRelease(mp3_handle); return 0; } sceKernelStartThread(mp3_thread, 0, 0); return 1; }
int ThreadManForKernel_446d8de6(const char *threadName, u32 entry, u32 prio, int stacksize, u32 attr, u32 optionAddr) { WARN_LOG(SCEKERNEL,"ThreadManForKernel_446d8de6:Not support this patcher"); return sceKernelCreateThread(threadName, entry, prio, stacksize, attr, optionAddr); }
int main(int argc, char *argv[]) { int result, data; SceCtrlData pad_data[128]; SceCtrlLatch latch; schedulingLogPos = schedulingLog; SceUID thread = sceKernelCreateThread("preempt", &testThread, sceKernelGetThreadCurrentPriority() - 1, 0x500, 0, NULL); sceKernelStartThread(thread, 0, 0); schedulingLogPos += sprintf(schedulingLogPos, "BEFORE sceCtrlSetSamplingMode 1\n"); didPreempt = 0; result = sceCtrlSetSamplingMode(1); schedulingLogPos += sprintf(schedulingLogPos, "AFTER sceCtrlSetSamplingMode 1: %08x preempt:%d\n", result, didPreempt); sceKernelDelayThread(300); schedulingLogPos += sprintf(schedulingLogPos, "BEFORE sceCtrlSetSamplingMode 0\n"); didPreempt = 0; result = sceCtrlSetSamplingMode(0); schedulingLogPos += sprintf(schedulingLogPos, "AFTER sceCtrlSetSamplingMode 0: %08x preempt:%d\n", result, didPreempt); sceKernelDelayThread(300); schedulingLogPos += sprintf(schedulingLogPos, "BEFORE sceCtrlSetSamplingCycle 0\n"); didPreempt = 0; result = sceCtrlSetSamplingCycle(0); schedulingLogPos += sprintf(schedulingLogPos, "AFTER sceCtrlSetSamplingCycle 0: %08x preempt:%d\n", result, didPreempt); sceKernelDelayThread(300); schedulingLogPos += sprintf(schedulingLogPos, "BEFORE sceCtrlGetSamplingMode\n"); didPreempt = 0; result = sceCtrlGetSamplingMode(&data); schedulingLogPos += sprintf(schedulingLogPos, "VALUE: %08x\n", data); schedulingLogPos += sprintf(schedulingLogPos, "AFTER sceCtrlGetSamplingMode: %08x preempt:%d\n", result, didPreempt); sceKernelDelayThread(300); schedulingLogPos += sprintf(schedulingLogPos, "BEFORE sceCtrlReadBufferPositive 1\n"); didPreempt = 0; result = sceCtrlReadBufferPositive(&pad_data[0], 1); outputPadData(result, &pad_data[0]); schedulingLogPos += sprintf(schedulingLogPos, "AFTER sceCtrlReadBufferPositive 1: %08x preempt:%d\n", result, didPreempt); sceKernelDelayThread(300); schedulingLogPos += sprintf(schedulingLogPos, "BEFORE sceCtrlReadBufferPositive 64\n"); didPreempt = 0; result = sceCtrlReadBufferPositive(&pad_data[0], 64); outputPadData(result, &pad_data[0]); schedulingLogPos += sprintf(schedulingLogPos, "AFTER sceCtrlReadBufferPositive 64: %08x preempt:%d\n", result, didPreempt); sceKernelDelayThread(300); schedulingLogPos += sprintf(schedulingLogPos, "BEFORE sceCtrlPeekBufferPositive 64\n"); didPreempt = 0; result = sceCtrlPeekBufferPositive(&pad_data[0], 64); outputPadData(result, &pad_data[0]); schedulingLogPos += sprintf(schedulingLogPos, "AFTER sceCtrlPeekBufferPositive 64: %08x preempt:%d\n", result, didPreempt); sceKernelDelayThread(300); schedulingLogPos += sprintf(schedulingLogPos, "BEFORE sceCtrlReadBufferPositive 96\n"); didPreempt = 0; result = sceCtrlReadBufferPositive(&pad_data[0], 96); outputPadData(result, &pad_data[0]); schedulingLogPos += sprintf(schedulingLogPos, "AFTER sceCtrlReadBufferPositive 96: %08x preempt:%d\n", result, didPreempt); sceKernelDelayThread(300); schedulingLogPos += sprintf(schedulingLogPos, "BEFORE sceCtrlPeekLatch\n"); didPreempt = 0; result = sceCtrlPeekLatch(&latch); // Result is # of reads, which won't match headless. result = result >= 1 ? 1 : 0; outputLatchData(result, &latch); schedulingLogPos += sprintf(schedulingLogPos, "AFTER sceCtrlPeekLatch: %08x preempt:%d\n", result, didPreempt); sceKernelDelayThread(300); schedulingLogPos += sprintf(schedulingLogPos, "BEFORE sceCtrlReadLatch\n"); didPreempt = 0; result = sceCtrlReadLatch(&latch); // Result is # of reads, which won't match headless. result = result >= 1 ? 1 : 0; outputLatchData(result, &latch); schedulingLogPos += sprintf(schedulingLogPos, "AFTER sceCtrlReadLatch: %08x preempt:%d\n", result, didPreempt); sceKernelDelayThread(300); schedulingLogPos += sprintf(schedulingLogPos, "BEFORE sceCtrlPeekLatch\n"); didPreempt = 0; result = sceCtrlPeekLatch(&latch); outputLatchData(result, &latch); schedulingLogPos += sprintf(schedulingLogPos, "AFTER sceCtrlPeekLatch: %08x preempt:%d\n", result, didPreempt); sceKernelDelayThread(300); sceKernelTerminateDeleteThread(thread); sceKernelDelayThread(300); printf("%s", schedulingLog); return 0; }
void runReferTests() { SceKernelThreadInfo2 info; int i; SceUID delayThread = sceKernelCreateThread("delay", &delayFunc, sceKernelGetThreadCurrentPriority(), 0x1000, PSP_THREAD_ATTR_VFPU, NULL); SceUID deletedThread = sceKernelCreateThread("deleted", &delayFunc, sceKernelGetThreadCurrentPriority(), 0x1000, 0, NULL); sceKernelDeleteThread(deletedThread); info.size = sizeof(info); checkpointNext("Thread IDs:"); checkpoint(" NULL: %08x", sceKernelReferThreadStatus(0, &info)); checkpoint(" Current: %08x", sceKernelReferThreadStatus(sceKernelGetThreadId(), &info)); checkpoint(" Deleted: %08x", sceKernelReferThreadStatus(deletedThread, &info)); checkpoint(" Invalid: %08x", sceKernelReferThreadStatus(0xDEADBEEF, &info)); // Crashes. //checkpointNext("sceKernelReferThreadStatus info ptr:"); //checkpoint(" NULL info: %08x", sceKernelReferThreadStatus(0, NULL)); checkpointNext("Sizes:"); int sizes[] = {-1, 0, 1, 2, 3, 4, 5, 8, 16, 32, 64, 80, 82, 108, 128, 1024}; for (i = 0; i < ARRAY_SIZE(sizes); ++i) { memset(&info, 0xff, sizeof(info)); info.size = sizes[i]; int result = sceKernelReferThreadStatus(0, &info); checkpoint(" %d: %08x => %d (exit: %x)", sizes[i], result, info.size, info.exitStatus); } info.size = sizeof(info); sceKernelStartThread(delayThread, 0, NULL); sceKernelReferThreadStatus(delayThread, &info); checkpointNext("Values:"); schedfThreadInfo(&info, &delayFunc); SceUID slumberThread = sceKernelCreateThread("slumber", &slumberFunc, sceKernelGetThreadCurrentPriority() - 1, 0x1000, 0, NULL); checkpoint(" slumber before start:"); sceKernelReferThreadStatus(slumberThread, &info); schedfThreadInfo(&info, &slumberFunc); sceKernelStartThread(slumberThread, 0, NULL); checkpoint(" started slumber"); checkpoint(" slumber after start:"); sceKernelReferThreadStatus(slumberThread, &info); schedfThreadInfo(&info, &slumberFunc); sceKernelTerminateThread(slumberThread); checkpoint(" terminated slumber"); checkpoint(" slumber after terminate:"); sceKernelReferThreadStatus(slumberThread, &info); schedfThreadInfo(&info, &slumberFunc); sceKernelStartThread(slumberThread, 0, NULL); checkpoint(" started slumber"); checkpoint(" slumber after start:"); sceKernelReferThreadStatus(slumberThread, &info); schedfThreadInfo(&info, &slumberFunc); checkpoint(" woke slumber: %08x", sceKernelWakeupThread(slumberThread)); checkpoint(" slumber after wake:"); sceKernelReferThreadStatus(slumberThread, &info); schedfThreadInfo(&info, &slumberFunc); sceKernelTerminateDeleteThread(slumberThread); checkpoint(" terminated and deleted slumber"); // TODO: Test more cases. flushschedf(); }
int pspAudioInit() { int i,ret; int failed=0; char str[32]; audio_terminate=0; audio_ready=0; for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) { AudioStatus[i].handle = -1; AudioStatus[i].threadhandle = -1; AudioStatus[i].volumeright = PSP_VOLUME_MAX; AudioStatus[i].volumeleft = PSP_VOLUME_MAX; AudioStatus[i].callback = 0; AudioStatus[i].pdata = 0; ChannelFree[i] = 1; } for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) { if ((AudioStatus[i].handle = sceAudioChReserve(-1,PSP_NUM_AUDIO_SAMPLES,0))<0) failed=1; } if (failed) { for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) { if (AudioStatus[i].handle != -1) sceAudioChRelease(AudioStatus[i].handle); AudioStatus[i].handle = -1; } return -1; } audio_ready = 1; strcpy(str,"audiot0"); for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) { str[6]='0'+i; AudioStatus[i].threadhandle = sceKernelCreateThread(str,(void*)&AudioChannelThread,0x12,0x10000,0,NULL); if (AudioStatus[i].threadhandle < 0) { AudioStatus[i].threadhandle = -1; failed=1; break; } ret=sceKernelStartThread(AudioStatus[i].threadhandle,sizeof(i),&i); if (ret!=0) { failed=1; break; } } if (failed) { audio_terminate=1; for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) { if (AudioStatus[i].threadhandle != -1) { //sceKernelWaitThreadEnd(AudioStatus[i].threadhandle,NULL); sceKernelDeleteThread(AudioStatus[i].threadhandle); } AudioStatus[i].threadhandle = -1; } audio_ready=0; return -1; } return 0; }
int main(int argc, char *argv[]) { SceUID thid; int error; void *data; pspDebugScreenInit(); if (argc > 0) { printf("Bootpath: %s\n", argv[0]); } SetupCallbacks(); /* Create a messagebox */ myMessagebox = sceKernelCreateMbx("pspSDK-testMBX", 0, 0); printf("MAIN: created messagebox %08x\n", myMessagebox); /* Create a task that will post in the messagebox */ thid = sceKernelCreateThread("subthread", SubThread, 17, 8192, THREAD_ATTR_USER, 0); sceKernelStartThread(thid, 0, NULL); printf("MAIN: started task %08x\n", thid); /* Wait for a message */ printf("MAIN: waiting for message\n"); error = sceKernelReceiveMbx(myMessagebox, &data, NULL); if(error < 0) printf("MAIN: ERROR %08x\n", error); else printf("MAIN: got message: \"%s\"\n", ((MyMessage *)data)->text); /* Wait for a message with timeout */ printf("MAIN: waiting with timeout (will fail the first couple of times)\n"); for(;;) { SceUInt timeout = 300000; /* microseconds */ error = sceKernelReceiveMbx(myMessagebox, &data, &timeout); if(error < 0) printf("MAIN: ERROR %08x\n", error); else { printf("MAIN: got message: \"%s\" (timeout remaining %d us)\n", ((MyMessage *)data)->text, timeout); break; } } /* Poll for messages */ printf("MAIN: polling for message (non-blocking)\n"); for(;;) { error = sceKernelPollMbx(myMessagebox, &data); if(error < 0) { printf("MAIN: ERROR %08x\n", error); /* Sleep for a little while to give the message a chance to arrive */ sceKernelDelayThread(300000); } else { printf("MAIN: got message: \"%s\"\n", ((MyMessage *)data)->text); break; } } /* This call to sceKernelReceiveMbx() will be interrupted by the sub task without a message being sent */ printf("MAIN: waiting for a message that will not arrive\n"); error = sceKernelReceiveMbx(myMessagebox, &data, NULL); if(error < 0) printf("MAIN: ERROR %08x\n", error); else printf("MAIN: got message: \"%s\"\n", ((MyMessage *)data)->text); /* Prepare to shutdown */ printf("MAIN: waiting for sub task to exit\n"); sceKernelWaitThreadEnd(thid, NULL); printf("MAIN: sub task exited, deleting messagebox\n"); error = sceKernelDeleteMbx(myMessagebox); if(error < 0) printf("MAIN: ERROR %08x\n", error); else printf("MAIN: all done\n"); sceKernelSleepThread(); return 0; }
static int server_thread(SceSize args, void *argp) { int ret; UNUSED(ret); SceNetSockaddrIn serveraddr; DEBUG("Server thread started!\n"); /* Create server socket */ server_sockfd = sceNetSocket("FTPVita_server_sock", PSP2_NET_AF_INET, PSP2_NET_SOCK_STREAM, 0); DEBUG("Server socket fd: %d\n", server_sockfd); /* Fill the server's address */ serveraddr.sin_family = PSP2_NET_AF_INET; serveraddr.sin_addr.s_addr = sceNetHtonl(PSP2_NET_INADDR_ANY); serveraddr.sin_port = sceNetHtons(FTP_PORT); /* Bind the server's address to the socket */ ret = sceNetBind(server_sockfd, (SceNetSockaddr *)&serveraddr, sizeof(serveraddr)); DEBUG("sceNetBind(): 0x%08X\n", ret); /* Start listening */ ret = sceNetListen(server_sockfd, 128); DEBUG("sceNetListen(): 0x%08X\n", ret); while (1) { /* Accept clients */ SceNetSockaddrIn clientaddr; int client_sockfd; unsigned int addrlen = sizeof(clientaddr); DEBUG("Waiting for incoming connections...\n"); client_sockfd = sceNetAccept(server_sockfd, (SceNetSockaddr *)&clientaddr, &addrlen); if (client_sockfd >= 0) { DEBUG("New connection, client fd: 0x%08X\n", client_sockfd); /* Get the client's IP address */ char remote_ip[16]; sceNetInetNtop(PSP2_NET_AF_INET, &clientaddr.sin_addr.s_addr, remote_ip, sizeof(remote_ip)); INFO("Client %i connected, IP: %s port: %i\n", number_clients, remote_ip, clientaddr.sin_port); /* Create a new thread for the client */ char client_thread_name[64]; sprintf(client_thread_name, "FTPVita_client_%i_thread", number_clients); SceUID client_thid = sceKernelCreateThread( client_thread_name, client_thread, 0x10000100, 0x10000, 0, 0, NULL); DEBUG("Client %i thread UID: 0x%08X\n", number_clients, client_thid); /* Allocate the ClientInfo struct for the new client */ ClientInfo *client = malloc(sizeof(*client)); client->num = number_clients; client->thid = client_thid; client->ctrl_sockfd = client_sockfd; client->data_con_type = FTP_DATA_CONNECTION_NONE; sprintf(client->cur_path, "%s%s", FTP_DEFAULT_PREFIX, FTP_DEFAULT_PATH); memcpy(&client->addr, &clientaddr, sizeof(client->addr)); /* Add the new client to the client list */ client_list_add(client); /* Start the client thread */ sceKernelStartThread(client_thid, sizeof(*client), client); number_clients++; } else { /* if sceNetAccept returns < 0, it means that the listening * socket has been closed, this means that we want to * finish the server thread */ DEBUG("Server socket closed, 0x%08X\n", client_sockfd); break; } } DEBUG("Server thread exiting!\n"); sceKernelExitDeleteThread(0); return 0; }
/* Sets up the callback thread and returns its thread id */ int SetupCallbacks(void) { int thid = 0; thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, THREAD_ATTR_USER, 0); if(thid >= 0) sceKernelStartThread(thid, 0, 0); return thid; }
int test_psp_setup_callbacks(void) { int thid = 0; thid = sceKernelCreateThread("update_thread", test_psp_callback_thread, 0x11, 0xFA0, 0, 0); if (thid >= 0) sceKernelStartThread(thid, 0, 0); return thid; }
int main(int argc, char *argv[]) { int i; char temp[128]; setup(); testAlloc("Normal", PSP_MEMORY_PARTITION_USER, "test", 0, 0x10, NULL); printf("\nNames:\n"); testAlloc(" NULL name", PSP_MEMORY_PARTITION_USER, NULL, 0, 0x1000, NULL); testAlloc(" Blank name", PSP_MEMORY_PARTITION_USER, "", 0, 0x1000, NULL); testAlloc(" Long name", PSP_MEMORY_PARTITION_USER, "1234567890123456789012345678901234567890123456789012345678901234", 0, 0x1000, NULL); printf("\nPartitions:\n"); int parts[] = {-5, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; for (i = 0; i < sizeof(parts) / sizeof(parts[0]); ++i) { sprintf(temp, " Partition %d", parts[i]); testAlloc(temp, parts[i], "part", 0, 0x1000, NULL); } printf("\nTypes:\n"); unsigned int types[] = {-5, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; for (i = 0; i < sizeof(types) / sizeof(types[0]); ++i) { sprintf(temp, " Type %d", types[i]); testAlloc(temp, PSP_MEMORY_PARTITION_USER, "type", types[i], 0x1000, NULL); } printf("\nSizes:\n"); unsigned int sizes[] = { -1, 0, 1, 0x10, 0x20, 0x2F, 0x30, 0x31, 0x32, 0x36, 0x38, 0x39, 0x3A, 0x131, 0x136, 0x139, 0x1000, 0x10000, 0x100000, 0x1000000, 0x10000000, 0x1800000, 0x2000000, }; for (i = 0; i < sizeof(sizes) / sizeof(sizes[0]); ++i) { sprintf(temp, " Size 0x%08X", sizes[i]); testAlloc(temp, PSP_MEMORY_PARTITION_USER, "size", 0, sizes[i], NULL); } printf("\nPositions:\n"); testAlloc(" Wrong type", PSP_MEMORY_PARTITION_USER, "pos", 0, 0x1000, high - 0x1000); testAlloc(" Below low", PSP_MEMORY_PARTITION_USER, "pos", 2, 0x1000, low - 0x1000); testAlloc(" At low", PSP_MEMORY_PARTITION_USER, "pos", 2, 0x1000, low); testAlloc(" Above low", PSP_MEMORY_PARTITION_USER, "pos", 2, 0x1000, low + 0x1000); testAlloc(" Near high", PSP_MEMORY_PARTITION_USER, "pos", 2, 0x1000, high - 0x1000); testAlloc(" At high", PSP_MEMORY_PARTITION_USER, "pos", 2, 0x1000, high); testAlloc(" Above high", PSP_MEMORY_PARTITION_USER, "pos", 2, 0x1000, high + 0x1000); SceUID posPart1 = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part1", 2, 0x1000, low); char *pos1 = (char *)sceKernelGetBlockHeadAddr(posPart1); testAlloc(" Second at low", PSP_MEMORY_PARTITION_USER, "part2", 2, 0x1000, low); char *pos2 = testAlloc(" Second type low", PSP_MEMORY_PARTITION_USER, "part2", 0, 0x1000, low); printf(" Difference: %X\n", pos2 - pos1); sceKernelFreePartitionMemory(posPart1); printf("\nAlignment:\n"); SceUID alignbase[0x1000]; int alignbaseCount; for (alignbaseCount = 0; alignbaseCount < 0x1000; ++alignbaseCount) { alignbase[alignbaseCount] = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "alignbase", 0, 0x1, NULL); char *base = (char *)sceKernelGetBlockHeadAddr(alignbase[alignbaseCount]); if (((u32)base & 0xFFF) == 0xF00) break; } SceUID alignLowID = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part1", 3, 0x1000, (void *)0x1000); SceUID alignHighID = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part2", 4, 0x1000, (void *)0x1000); char *alignLow = (char *)sceKernelGetBlockHeadAddr(alignLowID); char *alignHigh = (char *)sceKernelGetBlockHeadAddr(alignHighID); unsigned int aligns[] = { -5, -1, 0, 1, 2, 3, 4, 7, 8, 0x10, 0x11, 0x20, 0x2F, 0x40, 0x60, 0x80, 0x100, 0x1000, 0x2000, 0x1000000, 0x4000000, 0x40000000, 0x80000000, }; for (i = 0; i < sizeof(aligns) / sizeof(aligns[0]); ++i) { sprintf(temp, " Align 0x%08X low", aligns[i]); testAllocDiff(temp, PSP_MEMORY_PARTITION_USER, "part2", 3, 0x1000, (char *)aligns[i], 0, alignLow); sprintf(temp, " Align 0x%08X high", aligns[i]); testAllocDiff(temp, PSP_MEMORY_PARTITION_USER, "part2", 4, 0x1000, (char *)aligns[i], 1, alignHigh); } sceKernelFreePartitionMemory(alignLowID); while (alignbaseCount >= 0) { sceKernelFreePartitionMemory(alignbase[alignbaseCount--]); } sceKernelFreePartitionMemory(alignHighID); printf("\n"); SceUID part1 = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part1", 0, 0x1, NULL); SceUID part2 = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part2", 0, 0x1, NULL); if (part1 > 0 && part2 > 0) { printf("Two with same name: OK\n"); } else { printf("Two with same name: Failed (%08X, %08X)\n", part1, part2); } char *part1Pos = (char *)sceKernelGetBlockHeadAddr(part1); char *part2Pos = (char *)sceKernelGetBlockHeadAddr(part2); printf("Minimum difference: %x\n", part2Pos - part1Pos); sceKernelFreePartitionMemory(part1); sceKernelFreePartitionMemory(part2); part1 = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part1", 3, 0x101, (void *)1); part2 = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part2", 3, 0x101, (void *)1); part1Pos = (char *)sceKernelGetBlockHeadAddr(part1); part2Pos = (char *)sceKernelGetBlockHeadAddr(part2); printf("Offset difference: %x\n", part2Pos - part1Pos); sceKernelFreePartitionMemory(part1); sceKernelFreePartitionMemory(part2); SceUID reschedThread = sceKernelCreateThread("resched", &reschedFunc, sceKernelGetThreadCurrentPriority(), 0x1000, 0, NULL); sceKernelStartThread(reschedThread, 0, NULL); SceUID reschedPart = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part", 0, 0x1000, NULL); sceKernelGetBlockHeadAddr(reschedPart); sceKernelFreePartitionMemory(reschedPart); sceKernelTerminateDeleteThread(reschedThread); printf("Reschedule: %s\n", didResched ? "yes" : "no"); SceUID allocs[1024]; int result = 0; for (i = 0; i < 1024; i++) { allocs[i] = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "create", 0, 0x100, NULL); if (allocs[i] < 0) { result = allocs[i]; break; } } if (result != 0) printf("Create 1024: Failed at %d (%08X)\n", i, result); else printf("Create 1024: OK\n"); while (--i >= 0) sceKernelFreePartitionMemory(allocs[i]); printf("Get deleted: %08X\n", (unsigned int)sceKernelGetBlockHeadAddr(reschedPart)); printf("Get NULL: %08X\n", (unsigned int)sceKernelGetBlockHeadAddr(0)); printf("Get invalid: %08X\n", (unsigned int)sceKernelGetBlockHeadAddr(0xDEADBEEF)); printf("Free deleted: %08X\n", sceKernelFreePartitionMemory(reschedPart)); printf("Free NULL: %08X\n", sceKernelFreePartitionMemory(0)); printf("Free invalid: %08X\n", sceKernelFreePartitionMemory(0xDEADBEEF)); return 0; }
int main(int argc, char *argv[]) { SceCtrlData pad; int oldButtons = 0; #define SECOND 1000000 #define REPEAT_START (1 * SECOND) #define REPEAT_DELAY (SECOND / 5) struct timeval repeatStart; struct timeval repeatDelay; repeatStart.tv_sec = 0; repeatStart.tv_usec = 0; repeatDelay.tv_sec = 0; repeatDelay.tv_usec = 0; pspDebugScreenInit(); pspDebugScreenPrintf("Press Cross to start the Task Scheduler Test\n"); pspDebugScreenPrintf("Press Circle to start the CpuSuspendIntr/CpuResumeIntr Test\n"); pspDebugScreenPrintf("Press Square to start the Task with thread of same priority\n"); pspDebugScreenPrintf("Press Left to start the Task Dispatcher Test\n"); pspDebugScreenPrintf("Press Triangle to Exit\n"); while(!done) { sceCtrlReadBufferPositive(&pad, 1); int buttonDown = (oldButtons ^ pad.Buttons) & pad.Buttons; if (pad.Buttons == oldButtons) { struct timeval now; gettimeofday(&now, NULL); if (repeatStart.tv_sec == 0) { repeatStart.tv_sec = now.tv_sec; repeatStart.tv_usec = now.tv_usec; repeatDelay.tv_sec = 0; repeatDelay.tv_usec = 0; } else { long usec = (now.tv_sec - repeatStart.tv_sec) * SECOND; usec += (now.tv_usec - repeatStart.tv_usec); if (usec >= REPEAT_START) { if (repeatDelay.tv_sec != 0) { usec = (now.tv_sec - repeatDelay.tv_sec) * SECOND; usec += (now.tv_usec - repeatDelay.tv_usec); if (usec >= REPEAT_DELAY) { repeatDelay.tv_sec = 0; } } if (repeatDelay.tv_sec == 0) { buttonDown = pad.Buttons; repeatDelay.tv_sec = now.tv_sec; repeatDelay.tv_usec = now.tv_usec; } } } } else { repeatStart.tv_sec = 0; } if (buttonDown & PSP_CTRL_CROSS) { SceUID lowThid = sceKernelCreateThread("Low Prio Thread", threadLowPrio, 0x70, 0x1000, 0, 0); SceUID mediumThid = sceKernelCreateThread("Medium Prio Thread", threadMediumPrio, 0x30, 0x1000, 0, 0); SceUID highThid = sceKernelCreateThread("High Prio Thread", threadHighPrio, 0x10, 0x1000, 0, 0); SceUID busyThid = sceKernelCreateThread("Busy Thread", threadBusy, 0x30, 0x1000, 0, 0); testDone = 0; highPrioCounter = 0; mediumPrioCounter = 0; lowPrioCounter = 0; sceKernelStartThread(lowThid, 0, 0); sceKernelStartThread(mediumThid, 0, 0); sceKernelStartThread(busyThid, 0, 0); sceKernelStartThread(highThid, 0, 0); int totalDelay = 5000000; sceKernelDelayThread(totalDelay); testDone = 1; sceKernelWaitThreadEnd(busyThid, NULL); sceKernelWaitThreadEnd(mediumThid, NULL); sceKernelWaitThreadEnd(highThid, NULL); sceKernelWaitThreadEnd(lowThid, NULL); pspDebugScreenPrintf("Counters: high=%d (%d us), medium=%d, low=%d\n", highPrioCounter, (totalDelay / highPrioCounter), mediumPrioCounter, lowPrioCounter); } if (buttonDown & PSP_CTRL_CIRCLE) { msg = buffer; strcpy(msg, ""); SceUID sleepingThid = sceKernelCreateThread("Sleeping Thread", sleepingThread, 0x10, 0x1000, 0, 0); sceKernelStartThread(sleepingThid, 0, 0); sceKernelDelayThread(100000); int intr = sceKernelCpuSuspendIntr(); sceKernelWakeupThread(sleepingThid); strcat(msg, "Main Thread with disabled interrupts\n"); sceKernelCpuResumeIntr(intr); strcat(msg, "Main Thread with enabled interrupts\n"); pspDebugScreenPrintf("%s", msg); } if (buttonDown & PSP_CTRL_SQUARE) { msg = buffer; strcpy(msg, ""); // Two threads having the same priority SceUID thread1 = sceKernelCreateThread("Thread 1", threadPrio_1, sceKernelGetThreadCurrentPriority(), 0x1000, 0, 0); SceUID thread2 = sceKernelCreateThread("Thread 2", threadPrio_2, sceKernelGetThreadCurrentPriority(), 0x1000, 0, 0); // Test that thread1 will be scheduled before thread2 sceKernelStartThread(thread1, 0, 0); sceKernelStartThread(thread2, 0, 0); strcat(msg, "1 "); sceKernelDelayThread(10000); strcat(msg, "4"); sceKernelWaitThreadEnd(thread1, NULL); sceKernelWaitThreadEnd(thread2, NULL); pspDebugScreenPrintf("Starting 2 threads at same priority: %s\n", msg); // Now with a different order for create & start strcpy(msg, ""); SceUID thread3 = sceKernelCreateThread("Thread 3", threadPrio_3, sceKernelGetThreadCurrentPriority(), 0x1000, 0, 0); SceUID thread4 = sceKernelCreateThread("Thread 4", threadPrio_4, sceKernelGetThreadCurrentPriority(), 0x1000, 0, 0); // Test that thread4 will be scheduled before thread3 sceKernelStartThread(thread4, 0, 0); sceKernelStartThread(thread3, 0, 0); strcat(msg, "1 "); sceKernelDelayThread(10000); strcat(msg, "4"); sceKernelWaitThreadEnd(thread3, NULL); sceKernelWaitThreadEnd(thread4, NULL); pspDebugScreenPrintf("Starting 2 threads with a different order create/start: %s\n", msg); } if (buttonDown & PSP_CTRL_LEFT) { msg = buffer; strcpy(msg, ""); int state = sceKernelSuspendDispatchThread(); // High priority thread SceUID thread = sceKernelCreateThread("Thread 1", threadHello, 0x10, 0x1000, 0, 0); strcat(msg, "1 "); // sceKernelStartThread resumes the thread dispatcher sceKernelStartThread(thread, 0, 0); strcat(msg, "2 "); sceKernelDelayThread(10000); strcat(msg, "3 "); sceKernelResumeDispatchThread(state); sceKernelWaitThreadEnd(thread, NULL); pspDebugScreenPrintf("Starting high prio thread with a disabled dispatcher (state=0x%X): %s\n", state, msg); msg = buffer; strcpy(msg, ""); state = sceKernelSuspendDispatchThread(); // Low priority thread thread = sceKernelCreateThread("Thread 1", threadHello, 0x70, 0x1000, 0, 0); strcat(msg, "1 "); // sceKernelStartThread resumes the thread dispatcher sceKernelStartThread(thread, 0, 0); strcat(msg, "2 "); sceKernelDelayThread(10000); strcat(msg, "3 "); sceKernelResumeDispatchThread(state); sceKernelWaitThreadEnd(thread, NULL); pspDebugScreenPrintf("Starting low prio thread with a disabled dispatcher (state=0x%X): %s\n", state, msg); } if (buttonDown & PSP_CTRL_TRIANGLE) { done = 1; } oldButtons = pad.Buttons; } sceGuTerm(); sceKernelExitGame(); return 0; }
int MP3_Load (const char *name){ if ( !mp3_codec_flag ) return -1; mp3_file_handle = sceIoOpen(name, PSP_O_RDONLY, 0777); if ( !mp3_file_handle ) return -1; if ( sceIoRead( mp3_file_handle, mp3_header_buffer, 4 ) != 4 ) { sceIoClose(mp3_file_handle); return -2; } while(1) { if ( mp3_header_buffer[0] == 'I' && mp3_header_buffer[1] == 'D' && mp3_header_buffer[2] == '3' ) { unsigned char id3v2_buffer[6]; if ( sceIoRead( mp3_file_handle, id3v2_buffer, 6 ) != 6 ) { sceIoClose(mp3_file_handle); return -2; } int id3v2_size = (int)(id3v2_buffer[2] & 0x7F) << 21 | (int)(id3v2_buffer[3] & 0x7F) << 14 | (int)(id3v2_buffer[4] & 0x7F) << 7 | (int)(id3v2_buffer[5] & 0x7F); sceIoLseek32(mp3_file_handle, id3v2_size, PSP_SEEK_CUR); if ( sceIoRead( mp3_file_handle, mp3_header_buffer, 4 ) != 4 ) { sceIoClose(mp3_file_handle); return -2; } continue; } unsigned int mp3_header = mp3_header_buffer[0]; mp3_header = (mp3_header<<8) | mp3_header_buffer[1]; mp3_header = (mp3_header<<8) | mp3_header_buffer[2]; mp3_header = (mp3_header<<8) | mp3_header_buffer[3]; if ( (mp3_header & 0xFFFE0000) != 0xFFFA0000) { sceIoLseek32(mp3_file_handle, -3, PSP_SEEK_CUR); if ( sceIoRead( mp3_file_handle, mp3_header_buffer, 4 ) != 4 ) { sceIoClose(mp3_file_handle); return -2; } continue; } mp3_samplerate = (mp3_header & 0x0C00) >> 10; if ( mp3_samplerate != 0 && mp3_samplerate != 1 ) { sceIoClose(mp3_file_handle); return -3; } mp3_samplerate = (mp3_samplerate == 0)?44100:48000; mp3_channels = (mp3_header & 0x00C0) >> 6; mp3_channels = (mp3_channels == 3)?1:2; mp3_data_start = sceIoLseek32(mp3_file_handle, -4, PSP_SEEK_CUR); break; } mp3_audio_channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, MP3_SAMPLE_COUNT, PSP_AUDIO_FORMAT_STEREO); if ( mp3_audio_channel < 0 ) { sceIoClose(mp3_file_handle); return -4; } mp3_audio_thread = sceKernelCreateThread("mp3_audio_thread",MP3OutputThread,0x12,0x10000,0,NULL); if ( mp3_audio_thread < 0 ) { sceAudioChRelease(mp3_audio_channel); sceIoClose(mp3_file_handle); return -5; } return 1; }
int humanvspsp(Player *p1, Player *p2) { BITMAP* buffer_field_game = create_bitmap(MAX_WIDTH, MAX_HEIGTH); BITMAP* buffer_border_and_info = create_bitmap(SCREEN_WIDTH, SCREEN_HEIGTH); int koniec = -1; reset_player(p1, 136, 230, 2); reset_player(p2, 136, 245, 3); clear_to_color(buffer_field_game, makecol(0, 0, 0)); rysuj_obramowanie(buffer_border_and_info, p1, p2); blit(buffer_border_and_info, screen, 0, 0, 0, 0, buffer_border_and_info->w, buffer_border_and_info->h); clear_keybuf(); odliczanie(); blit(buffer_border_and_info, screen, 0, 0, 0, 0, buffer_border_and_info->w, buffer_border_and_info->h); clear_key(); blit(buffer_field_game, buffer_border_and_info, 0, 0, 1, 1, buffer_field_game->w, buffer_field_game->h); blit(buffer_border_and_info, screen, 0, 0, 0, 0, buffer_border_and_info->w, buffer_border_and_info->h); p1_speed = 0; p2_speed = 0; speed = 25; install_int_ex(p1_speed_func, MSEC_TO_TIMER(speed)); install_int_ex(p2_speed_func, MSEC_TO_TIMER(speed)); install_int_ex(speed_func, SECS_TO_TIMER(1)); while(TRUE) { ai_run(p2, buffer_field_game); if((p1->x == p2->x) && (p1->y == p2->y)) { koniec = 0; break; } switch(p1->direction) { case UP: if(getpixel(buffer_field_game, p1->y, p1->x-1) != makecol(0, 0, 0)) { koniec = 1; } break; case DOWN: if(getpixel(buffer_field_game, p1->y, p1->x+1) != makecol(0, 0, 0)) { koniec = 1; } break; case LEFT: if(getpixel(buffer_field_game, p1->y-1, p1->x) != makecol(0, 0, 0)) { koniec = 1; } break; case RIGHT: if(getpixel(buffer_field_game, p1->y+1, p1->x) != makecol(0, 0, 0)) { koniec = 1; } break; } switch(p2->direction) { case UP: if(getpixel(buffer_field_game, p2->y, p2->x-1) != makecol(0, 0, 0)) { if(koniec == 1) { koniec = 0; break; } else { koniec = 2; } } break; case DOWN: if(getpixel(buffer_field_game, p2->y, p2->x+1) != makecol(0, 0, 0)) { if(koniec == 1) { koniec = 0; break; } else { koniec = 2; } } break; case LEFT: if(getpixel(buffer_field_game, p2->y-1, p2->x) != makecol(0, 0, 0)) { if(koniec == 1) { koniec = 0; break; } else { koniec = 2; } } break; case RIGHT: if(getpixel(buffer_field_game, p2->y+1, p2->x) != makecol(0, 0, 0)) { if(koniec == 1) { koniec = 0; break; } else { koniec = 2; } } break; } putpixel(buffer_field_game, p1->y, p1->x, makecol(255, 255, 255)); putpixel(buffer_field_game, p2->y, p2->x, makecol(86, 160, 222)); if(p1->x < MIN_HEIGTH || p1->x > MAX_HEIGTH-1 || p1->y < MIN_WIDTH || p1->y > MAX_WIDTH-1) { koniec = 1; } if(p2->x < MIN_HEIGTH || p2->x > MAX_HEIGTH-1 || p2->y < MIN_WIDTH || p2->y > MAX_WIDTH-1) { if(koniec == 1) { koniec = 0; break; } else { koniec = 2; } } blit(buffer_field_game, screen, 0, 0, 1, 1, buffer_field_game->w, buffer_field_game->h); if(koniec != -1) break; if(key[KEY_ESC]) break; if(key[KEY_ENTER]) { pause_game(0, p1, p2); odliczanie(); } #ifdef PSP if(key[KEY_RSHIFT]) { thid = sceKernelCreateThread("Screenshotpsp", screenshotpsp, 0x11, 256 * 1024, PSP_THREAD_ATTR_USER, NULL); sceKernelStartThread(thid, 0, NULL); } #else if(key[KEY_M]) { screenshot(); } #endif #if PSP if(key[KEY_UP]) #else if(key[KEY_W]) #endif { if(p1->direction != DOWN) p1->direction = UP; } #if PSP else if(key[KEY_DOWN]) #else else if(key[KEY_S]) #endif { if(p1->direction != UP) p1->direction = DOWN; } #if PSP else if(key[KEY_LEFT]) #else else if(key[KEY_A]) #endif { if(p1->direction != RIGHT) p1->direction = LEFT; } #if PSP else if(key[KEY_RIGHT]) #else else if(key[KEY_D]) #endif { if(p1->direction != LEFT) p1->direction = RIGHT; } clear_keybuf(); keypressed(); while(p1_speed > 0) { switch(p1->direction) { case UP: p1->x--; break; case DOWN: p1->x++; break; case LEFT: p1->y--; break; case RIGHT: p1->y++; break; } p1_speed--; } while(p2_speed > 0) { switch(p2->direction) { case UP: p2->x--; break; case DOWN: p2->x++; break; case LEFT: p2->y--; break; case RIGHT: p2->y++; break; } p2_speed--; } } remove_int(p1_speed_func); remove_int(p2_speed_func); remove_int(speed_func); destroy_bitmap(buffer_field_game); destroy_bitmap(buffer_border_and_info); return koniec; }
int main(void) { SceCtrlData pad, lastpad; int maxchan = 128; BOOL outputEnabled; MODULE *mf = NULL; SAMPLE *sf = NULL; int voice = 0; int pan = 127; int vol = 127; int freq = 22000; pspDebugScreenInit(); SetupCallbacks(); sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(1); if (!MikMod_InitThreads()) { printf("MikMod thread init failed\n"); } MikMod_RegisterErrorHandler(my_error_handler); /* register all the drivers */ MikMod_RegisterAllDrivers(); /* register all the module loaders */ MikMod_RegisterAllLoaders(); /* initialize the library */ md_mode = DMODE_16BITS|DMODE_STEREO|DMODE_SOFT_SNDFX|DMODE_SOFT_MUSIC; md_reverb = 0; md_pansep = 128; if (MikMod_Init("")) { printf("Could not initialize sound, reason: %s\n", MikMod_strerror(MikMod_errno)); sceKernelExitGame(); return 0; } MikMod_SetNumVoices(-1, 8); /* get ready to play */ sf = Sample_Load("ms0:/sound.wav"); printf("Starting.\n"); MikMod_EnableOutput(); outputEnabled = 1; if ((mikModThreadID = sceKernelCreateThread("MikMod" ,(void*)&AudioChannelThread,0x12,0x10000,0,NULL)) > 0) { sceKernelStartThread(mikModThreadID, 0 , NULL); } else { printf("Play thread create failed!\n"); } sceCtrlReadBufferPositive(&lastpad, 1); do { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons != lastpad.Buttons) { if(pad.Buttons & PSP_CTRL_CROSS) { voice = Sample_Play(sf,0,0); Voice_SetPanning(voice, pan); } if(pad.Buttons & PSP_CTRL_SQUARE) { outputEnabled = !outputEnabled; if(outputEnabled) MikMod_EnableOutput(); else MikMod_DisableOutput(); } if(pad.Buttons & PSP_CTRL_CIRCLE) { mf = Player_Load("ms0:/MUSIC.XM", maxchan, 0); if (NULL != mf) { mf->wrap = 1; Player_Start(mf); } } if(pad.Buttons & PSP_CTRL_TRIANGLE) { if (NULL != mf) { Player_Stop(); Player_Free(mf); /* To stop the song for real, it needs to be freed. I know, weird... */ mf = NULL; } } if(pad.Buttons & PSP_CTRL_SELECT) printf("Player is %s\n", Player_Active()?"On":"Off"); lastpad = pad; } if(pad.Buttons & PSP_CTRL_LTRIGGER) { Voice_SetPanning(voice, (pan<2)?pan:--pan); printf("pan is %d\n", pan); } if(pad.Buttons & PSP_CTRL_RTRIGGER) { Voice_SetPanning(voice, (pan>254)?pan:++pan); printf("pan is %d\n", pan); } if(pad.Buttons & PSP_CTRL_UP) { Voice_SetVolume(voice, (vol>254)?vol:++vol); printf("vol is %d\n", vol); } if(pad.Buttons & PSP_CTRL_DOWN) { Voice_SetVolume(voice, (vol<2)?vol:--vol); printf("vol is %d\n", vol); } if(pad.Buttons & PSP_CTRL_LEFT) { Voice_SetFrequency(voice, (freq<1001)?freq:(freq -=1000)); printf("freq is %d\n", freq); } if(pad.Buttons & PSP_CTRL_RIGHT) { Voice_SetFrequency(voice, (freq>44000)?freq:(freq +=1000)); printf("freq is %d\n", freq); } sceDisplayWaitVblankStart(); } while(!((pad.Buttons & PSP_CTRL_START) || done)); printf("Stopping.\n"); /* allow audio thread to terminate cleanly */ done = 1; if (mikModThreadID > 0) { SceUInt timeout = 100000; sceKernelWaitThreadEnd(mikModThreadID, &timeout); /* not 100% sure if this is necessary after a clean exit, * but just to make sure any resources are freed: */ sceKernelDeleteThread(mikModThreadID); } Player_Stop(); Player_Free(mf); MikMod_Exit(); sceKernelExitGame(); return 0; }
/*** * Initializes the audio buffers and a callback thread for each channel. */ int setup_audio() { int i, j, failed; stop_audio = 0; for (i = 0; i < AUDIO_CHANNELS; i++) { audio_status[i].Handle = -1; audio_status[i].ThreadHandle = -1; audio_status[i].LeftVolume = PSP_AUDIO_MAX_VOLUME; audio_status[i].RightVolume = PSP_AUDIO_MAX_VOLUME; audio_status[i].Callback = NULL; audio_status[i].Userdata = NULL; for (j = 0; j < 2; j++) { audio_buffer[i][j] = NULL; audio_buffer_samples[i][j] = 0; } } /* Initialize buffers */ for (i = 0; i < AUDIO_CHANNELS; i++) { for (j = 0; j < 2; j++) { if (!(audio_buffer[i][j] = (short*)malloc(AUDIO_SAMPLE_COUNT * sizeof(PspStereoSample)))) { printf("Couldn't initialize audio buffer for channel %i, bailing.", i); free_buffers(); sceKernelExitProcess(0); return 0; } audio_buffer_samples[i][j] = AUDIO_SAMPLE_COUNT; } } /* Initialize channels */ for (i = 0, failed = 0; i < AUDIO_CHANNELS; i++) { audio_status[i].Handle = sceAudioOutOpenPort(SCE_AUDIO_OUT_PORT_TYPE_VOICE, AUDIO_SAMPLE_COUNT, AUDIO_OUTPUT_RATE, SCE_AUDIO_OUT_MODE_STEREO); if (audio_status[i].Handle < 0) { failed = 1; break; } } if (failed) { for (i = 0; i < AUDIO_CHANNELS; i++) { if (audio_status[i].Handle != -1) { sceAudioOutReleasePort(audio_status[i].Handle); audio_status[i].Handle = -1; } } printf("Couldn't open audio port for the device, bailing."); free_buffers(); sceKernelExitProcess(0); return 0; } char label[16]; strcpy(label, "audiotX"); for (i = 0; i < AUDIO_CHANNELS; i++) { label[6] = '0' + i; audio_status[i].ThreadHandle = sceKernelCreateThread(label, (void*)&audio_channel_thread, 0x10000100, 0x10000, 0, 0, NULL); if (audio_status[i].ThreadHandle < 0) { audio_status[i].ThreadHandle = -1; failed = 1; break; } if (sceKernelStartThread(audio_status[i].ThreadHandle, sizeof(i), &i) != 0) { failed = 1; break; } } if (failed) { stop_audio = 1; for (i = 0; i < AUDIO_CHANNELS; i++) { if (audio_status[i].ThreadHandle != -1) { sceKernelDeleteThread(audio_status[i].ThreadHandle); } audio_status[i].ThreadHandle = -1; } printf("Couldn't initialize audio callback thread. Bailing."); sceKernelExitProcess(0); return 0; } // initialize the buffer our libretro audio callback will fill with data as it's available retro_audio_callback_buffer = (int16_t*)malloc(sizeof(int16_t) * AUDIO_SAMPLE_COUNT * 4); if (!retro_audio_callback_buffer) { printf("Couldn't initialize retro_audio_callback_buffer. Bailing."); sceKernelExitProcess(0); } curr_buffer_frames = 0; // setup our callbacks set_audio_channel_callback(0, audio_callback, 0); // initialize the audio buffer mutex audio_mutex = sceKernelCreateMutex("AudioMutex", 0, 1, 0); return AUDIO_SAMPLE_COUNT; }
int module_start(int args, void* argp){ return sceKernelStartThread(sceKernelCreateThread("load", load, 0x18, 0x10000, PSP_THREAD_ATTR_USER, NULL), args, argp); }
/** * Setup Matching Threads for Context * @param context Matching Context * @param event_th_prio Event Caller Thread Priority * @param event_th_stack Event Caller Thread Stack Size * @param input_th_prio IO Handler Thread Priority * @param input_th_stack IO Handler Thread Stack Size * @return 0 on success or... -1 */ int _setupMatchingThreads(SceNetAdhocMatchingContext * context, int event_th_prio, int event_th_stack, int input_th_prio, int input_th_stack) { // Fix Input Thread Stack Size input_th_stack = 50 * 1024; // Thread Name Buffer char threadname[128]; // Create Event Thread Name sprintf(threadname, "matching_ev%d", context->id); // Create Event Thread context->event_thid = sceKernelCreateThread(threadname, _matchingEventThread, event_th_prio, event_th_stack, 0, NULL); // Created Event Thread if(context->event_thid > 0) { // Started Event Thread if(sceKernelStartThread(context->event_thid, sizeof(context), &context) == 0) { // Create IO Thread Name sprintf(threadname, "matching_io%d", context->id); // Create IO Thread context->input_thid = sceKernelCreateThread(threadname, _matchingInputThread, input_th_prio, input_th_stack, 0, NULL); // Created IO Thread if(context->input_thid > 0) { // Started Input Thread if(sceKernelStartThread(context->input_thid, sizeof(context), &context) == 0) { // Setup Success return 0; } // Delete IO Thread sceKernelDeleteThread(context->input_thid); // Delete IO Thread Reference context->input_thid = 0; } // Clean Event Thread Shutdown context->event_thid = -1; // Wait for Shutdown while(context->event_thid != 0) sceKernelDelayThread(10000); // Return Generic Error return -1; } // Delete Event Thread sceKernelDeleteThread(context->event_thid); // Delete Event Thread Reference context->event_thid = 0; } // Return Generic Error return -1; }
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); }