int main(void) { //change clock rate to 333mhz scePowerSetClockFrequency(333, 333, 166); PowerManager::instance(); // Setup power manager SetupCallbacks(); static const char *argv[] = { "scummvm", NULL }; static int argc = sizeof(argv) / sizeof(char *) - 1; g_system = new OSystem_PSP(); assert(g_system); #ifdef DYNAMIC_MODULES PluginManager::instance().addPluginProvider(new PSPPluginProvider()); #endif /* unit/speed tests */ #if defined (PSP_ENABLE_UNIT_TESTS) || defined (PSP_ENABLE_SPEED_TESTS) PSP_INFO_PRINT("running tests\n"); psp_tests(); sceKernelSleepThread(); // that's it. That's all we're doing #endif int res = scummvm_main(argc, argv); g_system->quit(); // TODO: Consider removing / replacing this! PowerManager::destroy(); // get rid of PowerManager sceKernelSleepThread(); return res; }
void loadTheme() { int i, bytesRead; SceUID fp; fp = sceIoOpen("ms0:/lockdown.thm", PSP_O_RDONLY, 0777); if (fp < 0) { fp = sceIoOpen("flash0:/lockdown.thm", PSP_O_RDONLY, 0777); if (fp < 0) { printTextScreen(0, 0, "Error loading flash0:/lockdown.thm.", RGB(255, 0, 0)); printTextScreen(0, 8, "Place theme at ms0:/lockdown.thm to load from memory stick.", RGB(255, 0, 0)); sceDisplayWaitVblankStart(); flipScreen(); sceKernelSleepThread(); } } for (i = 0; i < NUMFILES; i++) { bytesRead = sceIoRead(fp, &images[i].hdr, sizeof(imagehdr)); if (bytesRead != sizeof(imagehdr)) { printTextScreen(0, 0, "Unexpected end of header.", RGB(255, 0, 0)); sceDisplayWaitVblankStart(); flipScreen(); sceKernelSleepThread(); } images[i].blockid = sceKernelAllocPartitionMemory(2, "block", 0, (sizeof(unsigned char) * images[i].hdr.size), NULL); if (images[i].blockid < 0) { printTextScreen(0, 0, "Memory allocation error.", RGB(255, 0, 0)); sceDisplayWaitVblankStart(); flipScreen(); sceKernelSleepThread(); } images[i].data = (unsigned char*) sceKernelGetBlockHeadAddr(images[i].blockid); bytesRead = sceIoRead(fp, images[i].data, images[i].hdr.size); if (bytesRead != images[i].hdr.size) { printTextScreen(0, 0, "Unexpected end of data.", RGB(255, 0, 0)); sceDisplayWaitVblankStart(); flipScreen(); sceKernelSleepThread(); } } sceIoClose(fp); }
int JNetwork::connect(const string& serverIP) { #ifdef NETWORK_SUPPORT int err; char buffer[4096]; if(netthread) return 0; sceUtilityLoadNetModule(1); sceUtilityLoadNetModule(3); if((err = pspSdkInetInit())) { sprintf(buffer, "JGE Error, could not initialise the network %08X", err); printf(buffer); printf("\n"); error = buffer; return err; } if(JNetwork::connect_to_apctl(1)) { JNetwork::serverIP = serverIP; /* Create a user thread to do the real work */ netthread = sceKernelCreateThread("net_thread", net_thread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, NULL); if(netthread < 0) { printf("Error, could not create thread\n"); sceKernelSleepThread(); } sceKernelStartThread(netthread, 0, NULL); return netthread; } #endif return 0; }
int sock_thread( SceSize args, void *argp ) { unsigned char buffer[block_size], running = 1; SocketOpts * opts = ( SocketOpts * )( *( unsigned int * )argp ); opts->buf = ( int * )buffer; opts->sema = sceKernelCreateSema( "sock_sema", 0, 0, 1, NULL ); while( running ) { sceKernelSleepThread(); switch ( opts->operation ) { case S_SEND: opts->res = sceNetInetSend( opts->server, opts->buf, opts->length, 0 ); log( "sent %d res %08x\n", opts->length, opts->res ); break; case S_RECV: opts->res = sceNetInetRecv( opts->server, opts->buf, opts->length, 0 ); break; case S_TERM: running = 0; break; } sceKernelSignalSema( opts->sema, 1 ); } sceKernelDeleteSema( opts->sema ); opts->sema = -1; opts->thid = -1; opts->buf = NULL; return sceKernelExitDeleteThread( 0 ); }
static int cpu_thread_entry(SceSize args, void* argp) { sceKernelSleepThread(); execute_arm_translate(reg[EXECUTE_CYCLES]); return 0; }
/* Simple thread */ int main_thread(SceSize args, void *argp) { initialise(args, argp); shellParseThread(0, NULL); sceKernelSleepThread(); return 0; }
int main() { SetupCallbacks(); initLanguage(); initLevel(); initGame(); initDisp(); sceKernelSleepThread(); return 0; }
int main(int argc, char *argv[]) { pspDebugScreenInit(); if (argc > 0) { printf("Bootpath: %s\n", argv[0]); } SetupCallbacks(); printf("\nMain Thread Status:\n"); dump_threadstatus(); sceKernelSleepThread(); return 0; }
int main(){ pspDebugScreenInit(); SetupCallbacks(); printf("I Love you Mariah!"); printf("I Love you Mariah!"); printf("I Love you Mariah!"); printf("I Love you Mariah!"); printf("I Love you Mariah!"); printf("I Love you Mariah!"); printf("I Love you Mariah!"); printf("I Love you Mariah!"); sceKernelSleepThread(); return 0; }
int main(int argc, char **argv) { int i; printf(WELCOME_MESSAGE); for(i = 0; i < argc; i++) { printf("Arg %d: %s\n", i, argv[i]); } sceKernelSleepThread(); return 0; }
void pspAudioSetChannelCallback(int channel, pspAudioCallback_t callback, void *pdata) { volatile psp_audio_channelinfo *pci = &AudioStatus[channel]; if (callback == 0) { deletingthread = sceKernelGetThreadId();; pci->callback = 0; sceKernelSleepThread(); } else { pci->callback=callback; sceKernelWakeupThread(pci->threadhandle); } }
static int MP3Thread(SceSize args, void *argp) { while (mp3_active) { sceKernelSleepThread(); if (mp3_newfile) { mp3_newfile = 0; mp3_running = 1; MP3Update(); mp3_running = 0; } } return 0; }
int main(int argc, char* argv[]) { SetupCallbacks(); #ifdef DEBUG usbStorage(); #endif strcpy(cwd,argv[0]); cwd[strlen(cwd)-strlen("/eboot.pbp")] = '\0'; configLoad(); initLanguage(); initAudio(); initLua(); initGame(); initDisp(); sceKernelSleepThread(); return 0; }
int receiveMbxThread(SceSize args, void *argp) { while (!done) { sceKernelSleepThread(); MyMessage *msg; int result = sceKernelReceiveMbx(mbxId, (void **) &msg, NULL); pspDebugScreenPrintf("sceKernelReceiveMbx = 0x%08X\n", result); if (result == 0) { pspDebugScreenPrintf(" msg = 0x%08X\n", (int) msg); pspDebugScreenPrintf(" msg.header.next = 0x%08X\n", (int) msg->header.next); pspDebugScreenPrintf(" msg.header.msgPriority = %d\n", msg->header.msgPriority); pspDebugScreenPrintf(" msg.header.dummy[3] = 0x%02X 0x%02X 0x%02X\n", msg->header.dummy[0], msg->header.dummy[1], msg->header.dummy[2]); pspDebugScreenPrintf(" msg.text = '%s'\n", msg->text); free(msg); printMbxStatus(mbxId); } } return 0; }
static int AudioChannelThread(int args, void *argp) { volatile int bufidx=0; int channel=*(int *)argp; while (audio_terminate==0) { void *bufptr=&audio_sndbuf[channel][bufidx]; pspAudioCallback_t callback; callback=AudioStatus[channel].callback; if (callback) { char*c = bufptr; c[0]='s'; c[1]='I'; c[2]='b'; c[3]='E'; callback(bufptr, PSP_NUM_AUDIO_SAMPLES, AudioStatus[channel].pdata); if (c[0] != 's'+10 || c[1] != 'I'+10 || c[2] != 'b'+10 || c[3] != 'E'+10 ) pspAudioOutBlocking(channel,AudioStatus[channel].volumeleft,AudioStatus[channel].volumeright,bufptr); } else { sceKernelWakeupThread(deletingthread); sceKernelSleepThread(); // pspAudioOutBlocking(channel,AudioStatus[channel].volumeleft,AudioStatus[channel].volumeright,audio_zerobuf); } bufidx=(bufidx?0:1); } sceKernelExitThread(0); return 0; }
int main(void) { unsigned char buffer[0x1e]; /* Buffer */ pspDebugScreenInit(); SetupCallbacks(); pspDebugScreenPrintf("Idstorage sample by harleyg\nThanks to Dark_AleX and Mathieulh\n\n"); /* Read idstorage key 0x050 (serial) */ sceIdStorageLookup(0x050, 0x0, buffer, 0x1e); /* key, offset, buffer, length */ /* Print the serial */ pspDebugScreenPrintf("Serial: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], buffer[8], buffer[9], buffer[10], buffer[11], buffer[12], buffer[13], buffer[14], buffer[15], buffer[16], buffer[17], buffer[18], buffer[19], buffer[20], buffer[21], buffer[22], buffer[23], buffer[24], buffer[25], buffer[26], buffer[27], buffer[28], buffer[29]); sceKernelSleepThread(); return 0; }
int main() { //call psp stuff pspDebugScreenInit(); SetupCallbacks(); initGraphics(); char bafer[200]; //Image definido no graphics.h Image* nossaImage; //joga caminho no bafer sprintf(bafer, "media/prince_ascii.png"); nossaImage = loadImage(bafer); //checar se imagem existe!! if (!nossaImage) { //Image load failed printf("Ta lah nao! \n"); } else { int x = 0; int y = 0; sceDisplayWaitVblankStart(); blitAlphaImageToScreen(0 ,0 , 480, 272, nossaImage, x, y); flipScreen(); } sceKernelSleepThread(); return 0; }
int main() { pspDebugScreenInit(); SetupCallbacks(); scePowerSetClockFrequency(333, 333, 166); pspAudioInit(); SceCtrlData pad; int i; tzset(); printf("Hello World\n"); time_t now; now = time(NULL); printf("Started %s\n", ctime(&now)); MP3_Init(1); MP3_Load("test.mp3"); MP3_Play(); while(1) { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons & PSP_CTRL_CROSS) { break; } else if(pad.Buttons & PSP_CTRL_CIRCLE) { MP3_Pause(); for(i=0; i<10; i++) { sceDisplayWaitVblankStart(); } } if (MP3_EndOfStream() == 1) { MP3_Stop(); } } MP3_Stop(); MP3_FreeTune(); sceKernelSleepThread(); return 0; }
void *orpGetValue(char *key, SceSize *key_size) { void *value = NULL; REGHANDLE rh; struct RegParam reg = { .regtype = 1, .namelen = strlen(SYSTEM_REGISTRY), .unk2 = 1, .unk3 = 1, }; strcpy(reg.name, SYSTEM_REGISTRY); int rc; if ((rc = sceRegOpenRegistry(®, 1, &rh)) < 0) { printf("Error opening registry.\n"); return value; } REGHANDLE cat; if ((rc = sceRegOpenCategory(rh, "/CONFIG/PREMO", 1, &cat)) < 0) { printf("Error opening: /CONFIG/PREMO\n"); goto _orpGetValue_exit1; } unsigned int key_type; if ((rc = sceRegGetKeyInfoByName(cat, key, &key_type, key_size)) < 0) printf("Key info failed: %s: %d\n", key, rc); else { // printf("%s: type: %d, size: %d\n", key, key_type, *key_size); value = malloc(*key_size); if ((rc = sceRegGetKeyValueByName(cat, key, value, *key_size)) < 0) { free(value); value = NULL; printf("Key look-up failed: %s\n", key); goto _orpGetValue_exit2; } } _orpGetValue_exit2: sceRegCloseCategory(cat); _orpGetValue_exit1: sceRegCloseRegistry(rh); return value; } int main() { pspDebugScreenInit(); SetupCallbacks(); printf("Open Remote Play Exporter!\n\n"); int rc; struct orpConfigRecord_t record; memset(&record, 0, sizeof(struct orpConfigRecord_t)); record.ps3_port = ORP_PORT; strcpy((char *)record.ps3_hostname, "0.0.0.0"); SceSize key_size; unsigned char *value; if ((value = orpGetValue("ps3_name", &key_size)) != NULL) { printf("%16s: %s\n", "Name", value); strncpy((char *)record.ps3_nickname, (const char *)value, ORP_NICKNAME_LEN); free(value); } else { printf("This PSP has not been registered for Remote Play!\n"); printf("\nPress HOME to quit.\n"); sceKernelSleepThread(); return 0; } if ((rc = sceUtilityGetSystemParamString(PSP_SYSTEMPARAM_ID_STRING_NICKNAME, (char *)record.psp_owner, ORP_NICKNAME_LEN)) == 0) { printf("%16s: %s\n", "PSP Owner", record.psp_owner); } if ((value = orpGetValue("ps3_mac", &key_size)) != NULL) { printf("%16s: ", "PS3 MAC Address"); int i; for (i = 0; i < key_size - 1; i++) printf("%02x:", value[i]); printf("%02x\n", value[key_size - 1]); memcpy(record.ps3_mac, value, ORP_MAC_LEN); free(value); } u8 mac[8]; if ((rc = sceWlanGetEtherAddr(mac)) == 0) { printf("%16s: ", "PSP MAC Address"); int i; memcpy(record.psp_mac, mac, ORP_MAC_LEN); for (i = 0; i < ORP_MAC_LEN - 1; i++) printf("%02x:", record.psp_mac[i]); printf("%02x\n", record.psp_mac[ORP_MAC_LEN - 1]); } PspOpenPSID psid; memset(&psid, 0, sizeof(psid)); if ((rc = sceOpenPSIDGetOpenPSID(&psid) == 0)) { printf("%16s: ", "PSP ID"); int i; for (i = 0; i < sizeof(psid.data) - 1; i++) printf("%02x", psid.data[i]); printf("%02x\n", psid.data[sizeof(psid.data) - 1]); memcpy(record.psp_id, psid.data, ORP_KEY_LEN); } if ((value = orpGetValue("ps3_key", &key_size)) != NULL) { printf("%16s: ", "Private Key"); int i; for (i = 0; i < key_size; i++) printf("%02x", value[i]); printf("\n"); memcpy(record.pkey, value, ORP_KEY_LEN); free(value); } char path[] = { "ms0:/export.orp" }; sceIoRemove(path); SceUID fd = sceIoOpen(path, PSP_O_WRONLY | PSP_O_CREAT, 0777); if (fd < 0) printf("\nUnable to open: %s\n", path); else { struct orpConfigHeader_t header; memset(&header, 0, sizeof(struct orpConfigHeader_t)); header.magic[0] = 'O'; header.magic[1] = 'R'; header.magic[2] = 'P'; header.version = ORP_CONFIG_VER; header.flags = ORP_CONFIG_EXPORT; sceIoWrite(fd, &header, sizeof(struct orpConfigHeader_t)); sceIoWrite(fd, &record, sizeof(struct orpConfigRecord_t)); sceIoClose(fd); printf("\nConfiguration saved to: %s\n", path); } printf("\nPress HOME to quit.\n"); sceKernelSleepThread(); return 0; }
static inline void switch_to_cpu_thread(void) { sceKernelWakeupThread(cpu_thread); sceKernelSleepThread(); }
int slumberFunc(SceSize argc, void *argv) { sceKernelSleepThread(); schedf(" ** slumber woke up\n"); return 8; }
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; }
int main_thread( SceSize args, void *argp ) { char ip[16], * argv[5]; int port, entry; parseArgs( argv, args, ( char * )argp ); //sceUtilityGetNetParam strcpy( ip, argv[1] ); port = atoi( argv[2] ); entry = atoi( argv[3] ); block_size = atoi( argv[4] ); log( "%s:%d entry %d\n", ip, port, entry ); /*ctrl_opts.inited = sceUtilityLoadNetModule( PSP_NET_MODULE_COMMON ); if ( ctrl_opts.inited != 0 ) { log( "Error loading Net modules (0x%08x)\n", ctrl_opts.inited ); goto net_term; } ctrl_opts.inited = sceUtilityLoadNetModule( PSP_NET_MODULE_INET ); if ( ctrl_opts.inited != 0 ) { log( "Error loading iNet module (0x%08x)\n", ctrl_opts.inited ); goto net_term; }*/ ctrl_opts.inited = sceNetInit( 0x10000, 0x20, 0x1000, 0x20, 0x1000 ); if ( ctrl_opts.inited != 0 ) { log( "Error Initing pspnet (0x%08x)\n", ctrl_opts.inited ); goto net_term; } ctrl_opts.inited = sceNetInetInit(); if ( ctrl_opts.inited != 0 ) { log( "Error initing Inet (0x%08x)\n", ctrl_opts.inited ); goto net_term; } ctrl_opts.inited = sceNetResolverInit(); if( ctrl_opts.inited != 0 ) { log( "Error initing Resolver (0x%08x)\n", ctrl_opts.inited ); goto net_term; } ctrl_opts.inited = sceNetApctlInit( 0x1400, 0x42 ); if ( ctrl_opts.inited != 0 ) { log( "Error initing Apctl (0x%08x)\n", ctrl_opts.inited ); goto net_term; } log( "pspnet init OK!\n" ); ctrl_opts.inited = connectApctl( entry ); if ( ctrl_opts.inited != 0 ) { log( "Error connecting Apctl (0x%08x)\n", ctrl_opts.inited ); goto net_term; } ctrl_opts.inited = connectSocket( ip, ( unsigned short )port ); if ( ctrl_opts.inited != 0 ) { log( "Error connecting Socket\n" ); goto net_term; } ctrl_opts.inited = 1; sceKernelSleepThread(); net_term: log( "stopping wifi...\n" ); disconnectSocket(); disconnectApctl(); sceNetApctlTerm(); sceNetResolverTerm(); sceNetInetTerm(); sceNetTerm(); //sceUtilityUnloadNetModule( PSP_NET_MODULE_INET ); //sceUtilityUnloadNetModule( PSP_NET_MODULE_COMMON ); ctrl_opts.thid = -1; ctrl_opts.inited = -1; return sceKernelExitDeleteThread( 0 ); }
int video_thread(SceSize args, void *argp) { // Pixel coordinates: first = first luminant pixel to breach threshhold, last = ..., mid = ... Coord first, last, mid; int bufsize; int threshold = 200; // Luminance threshold. int showvideo = 0; // Show the actual video input? 0: No, 1: Yes // Camera buffers. PspUsbCamSetupVideoParam videoparam; static u8 buffer[MAX_STILL_IMAGE_SIZE] __attribute__((aligned(64))); static u8 work[68*1024] __attribute__((aligned(64))); static u32 framebuffer[480*272] __attribute__((aligned(64))); // Startup cursor position. cursor.x = 237, cursor.y = 50; old.x = 237, old.y = 50; // Setup the screenmap size and position. screenmap.x = 20; screenmap.y = 200; screenmap.w = 60; screenmap.h = 60; screenmap.gridcolor = 0xFFC09090; screenmap.fillcolor = 0xFFF0F0F0; screenmap.selcolor = 0xFFC0FFFF; // Create a start button. Button btnStart; btnStart.x = 420; btnStart.y = 250; btnStart.w = 50; btnStart.h = 12; btnStart.fillcolor = 0xFF00FFFF; btnStart.textcolor = 0xFF000000; btnStart.bordercolor = 0xFF000000; btnStart.shadowcolor = 0xFF888888; btnStart.bordersize = 1; btnStart.borderbevel = 0; btnStart.shadowsize = 0; btnStart.shadowdistance = 0; strcpy(btnStart.text, "Start"); strcpy(btnStart.name, "btnStart"); // Wait for camera to be connected. while (!connected) { clearScreen(0xFFF0F0F0); printTextScreenCenter(132, "Please connect the camera and press any button.", 0xFF009900); flipScreen(); sceDisplayWaitVblankStart(); sceKernelDelayThread(20000); } // Load the camera modules and start the decoder. if (LoadModules() < 0) sceKernelSleepThread(); if (StartUsb() < 0) sceKernelSleepThread(); if (sceUsbActivate(PSP_USBCAM_PID) < 0) sceKernelSleepThread(); if (InitJpegDecoder() < 0) sceKernelSleepThread(); while (1) { if ((sceUsbGetState() & 0xF) == PSP_USB_CONNECTION_ESTABLISHED) break; sceKernelDelayThread(50000); } //Setup video parameters and start video capture. memset(&videoparam, 0, sizeof(videoparam)); videoparam.size = sizeof(videoparam); videoparam.resolution = PSP_USBCAM_RESOLUTION_480_272; videoparam.framerate = PSP_USBCAM_FRAMERATE_30_FPS; videoparam.wb = PSP_USBCAM_WB_INCANDESCENT; videoparam.saturation = 125; videoparam.brightness = 100; videoparam.contrast = 64; videoparam.sharpness = 0; videoparam.effectmode = PSP_USBCAM_EFFECTMODE_NORMAL; videoparam.framesize = MAX_VIDEO_FRAME_SIZE; videoparam.evlevel = PSP_USBCAM_EVLEVEL_0_0; if (sceUsbCamSetupVideo(&videoparam, work, sizeof(work)) < 0) sceKernelExitDeleteThread(0); sceUsbCamAutoImageReverseSW(1); if (sceUsbCamStartVideo() < 0) sceKernelExitDeleteThread(0); while (running) { int i, j, lum = 0, tracking = 0; first.x = 0; first.y = 0; last.x = 0; last.y = 0; mid.x = old.x; mid.y = old.y; clearScreen(0xFFFFFFFF); // Capture the camera image into the framebuffer. bufsize = sceUsbCamReadVideoFrameBlocking(buffer, MAX_VIDEO_FRAME_SIZE); if (bufsize > 0) sceJpegDecodeMJpeg(buffer, bufsize, framebuffer, 0); // Analyze the camera image. for (i = 0; i < 272; i++) { for (j = 0; j < 480; j++) { if (showvideo) putPixelScreen(framebuffer[i * CAM_LINE_SIZE + j], j, i); // Show video input. // Calculate luminance (brightness as perceived by the eye) and compare versus threshhold. lum = (299 * R(framebuffer[i * CAM_LINE_SIZE + j]) + 587 * G(framebuffer[i * CAM_LINE_SIZE + j]) + 114 * B(framebuffer[i * CAM_LINE_SIZE + j])) / 1000; if (lum > threshold) { tracking = 1; if (aligned) putPixelScreen(0xFF0000FF, j, i); if ((first.x == 0) || (j < first.x)) first.x = j; if ((first.y == 0) || (i < first.y)) first.y = i; if ((last.x == 0) || (j > last.x)) last.x = j; if ((last.y == 0) || (i > last.y)) last.y = i; } } } if (tracking) { // Calculate directional movement and determine cursor position. mid.x = first.x + (abs((last.x - first.x)) / 2); mid.y = first.y + (abs((last.y - first.y)) / 2); checkDirection(mid, old); switch (direction) { case 0: cursor.x = old.x; cursor.y = old.y; break; case 1: cursor.x = first.x; cursor.y = first.y + (abs((last.y - first.y)) / 2); break; case 2: cursor.x = first.x; cursor.y = first.y; break; case 3: cursor.x = first.x + (abs((last.x - first.x)) / 2); cursor.y = first.y; break; case 4: cursor.x = last.x; cursor.y = first.y; break; case 5: cursor.x = last.x; cursor.y = first.y + (abs((last.y - first.y)) / 2); break; case 6: cursor.x = last.x; cursor.y = last.y; break; case 7: cursor.x = first.x + (abs((last.x - first.x)) / 2); cursor.y = last.y; break; case 8: cursor.x = first.x; cursor.y = last.y; break; }; //Uncomment the following lines to draw 'directional' markers on screen. /*if ((abs(last.x - first.x) > 15) || (abs(last.y - first.y) > 15)) { if ((direction > 0) && (direction <= 4)) { drawLineScreen(first.x, first.y, last.x, last.y, 0xFFC0C0C0); } else { drawLineScreen(last.x, last.y, first.x, first.y, 0xFFC0C0C0); } switch (direction) { case 0: break; case 1: drawLineScreen(last.x, last.y + ((last.y - first.y) / 2), first.x, first.y + ((last.y - first.y) / 2), 0xFFC0C0C0); break; // W case 2: drawLineScreen(last.x, last.y, first.x, first.y, 0xFFC0C0C0); break; // NW case 3: drawLineScreen(first.x + ((last.x - first.x) / 2), last.y, first.x + ((last.x - first.x) / 2), first.y, 0xFFC0C0C0); break; // N case 4: drawLineScreen(first.x, last.y, last.x, first.y, 0xFFC0C0C0); break; // NE case 5: drawLineScreen(first.x, first.y + ((last.y - first.y) / 2), last.x, first.y + ((last.y - first.y) / 2), 0xFFC0C0C0); break; // E case 6: drawLineScreen(first.x, first.y, last.x, last.y, 0xFFC0C0C0); break; // SE case 7: drawLineScreen(first.x + ((last.x - first.x) / 2), first.y, first.x + ((last.x - first.x) / 2), last.y, 0xFFC0C0C0); break; // S case 8: drawLineScreen(last.x, first.y, first.x, last.y, 0xFFC0C0C0); break; // SW }; drawLineScreen((first.x > last.x) ? last.x : first.x, (first.y > last.y) ? last.y : first.y, (first.x < last.x) ? last.x : first.x, (first.y < last.y) ? last.y : first.y, 0xFFC0C0C0); } else { drawRectScreen(0xFFC0C0C0, first.x, first.y, last.x - first.x, last.y - first.y); }*/ } else { printTextScreenCenter(10, "Please return to the playing area.", 0xFF0000FF); if (lastdirection == 0) { cursor.x = old.x; cursor.y = old.y; } //if ((aligned) && (!menu) && (_gameState = GAME_RUNNING)) HandlePauseGame(); } if (!aligned) { showvideo = 1; // Alignment Screen: wait for camera to be aligned to the playing area. printTextScreenCenter(126, "Please align the camera to the playing area.", 0xFFFFFFFF); printTextScreenCenter(136, "Drag the cursor to the \"Start\" button to continue.", 0xFFFFFFFF); if (checkCoordButton(cursor, btnStart)) { btnStart.fillcolor = 0xFF00FF00; aligned = 1; menu = 1; } drawButtonScreen(btnStart); if (aligned) { btnStart.fillcolor = 0xFF00FFFF; btnStart.x = 240 - (btnStart.w / 2); btnStart.y = 200; } } else if (menu) { showvideo = 0; // Menu Screen: show a splash, logo, menu, etc. printTextScreenCenter(126, "eyePSP Pong", 0xFF009900); printTextScreenCenter(136, "Please press the \"Start\" button to continue.", 0xFFFF0000); if (checkCoordButton(cursor, btnStart)) { btnStart.fillcolor = 0xFFC0FFC0; menu = 0; } drawButtonScreen(btnStart); } else { // Draw any game objects here. if (_gameState == GAME_PAUSED) { printTextScreenCenter(100, "Game Paused", COLOR_RED); if (tracking) _gameState = GAME_RUNNING; } else if (_gameState == GAME_RUNNING) { DrawMainText(); // Draw main graphics and supporting text to the screen. DrawPaddle(&_paddle); // Draws the paddle to the screen } else if (_gameState == GAME_CONTINUE) { char sbuffer[50]; sprintf(sbuffer, "%d Ball%s Remaining...", _resBalls, (_resBalls == 1) ? "" : "s"); printTextScreenCenter(100, sbuffer, 0xFF000088); if (checkCoordButton(cursor, btnStart)) { btnStart.fillcolor = 0xFFC0FFC0; _gameState = GAME_RUNNING; } drawButtonScreen(btnStart); } else if (_gameState == GAME_OVER) { // Draws game over graphics and waits for user to continue DrawGameOverMenu(); if (checkCoordButton(cursor, btnStart)) { btnStart.fillcolor = 0xFFC0FFC0; _gameState = GAME_RUNNING; } drawButtonScreen(btnStart); } } // Draw cursor (within boundaries) . if (tracking) { for (i = cursor.y - 5; i <= cursor.y + 5; i++) { if ((i > 0) && (i < 272)) putPixelScreen(!tracking ? 0xFF0000FF : 0xFF009900, cursor.x, i); } // y-axis for (j = cursor.x - 5; j <= cursor.x + 5; j++) { if ((j > 0) && (j < 480)) putPixelScreen(!tracking ? 0xFF0000FF : 0xFF009900, j, cursor.y); } // x-axis } old.x = cursor.x; old.y = cursor.y; lastdirection = direction; flipScreen(); sceDisplayWaitVblankStart(); sceKernelDelayThread(2000); } sceKernelExitDeleteThread(0); return 0; }
void switch_to_main_thread(void) { sceKernelWakeupThread(main_thread); sceKernelSleepThread(); }
static void MP3Update(void) { int flip; UINT8 *GuardPtr; INT16 *OutputPtr, *OutputEnd; struct mad_stream Stream; struct mad_frame Frame; struct mad_synth Synth; mad_timer_t Timer; mad_stream_init(&Stream); mad_frame_init(&Frame); mad_synth_init(&Synth); mad_timer_reset(&Timer); OutputPtr = (INT16 *)mp3_out[0]; OutputEnd = (INT16 *)(mp3_out[0] + MP3_BUFFER_SIZE); GuardPtr = NULL; mp3_filepos = 0; mp3_frame = 0; flip = 0; cdda_command_ack = 1; while (mp3_active && mp3_status != MP3_STOP) { if (Stream.buffer == NULL || Stream.error == MAD_ERROR_BUFLEN) { UINT32 ReadSize, Remaining; UINT8 *ReadStart; if (Stream.next_frame != NULL) { Remaining = Stream.bufend - Stream.next_frame; ReadStart = mp3_in + Remaining; ReadSize = (2 * MP3_BUFFER_SIZE) - Remaining; memmove(mp3_in, Stream.next_frame, Remaining); } else { ReadSize = 2 * MP3_BUFFER_SIZE; ReadStart = mp3_in; Remaining = 0; } if (MP3SleepCheck()) break; ReadSize = sceIoRead(mp3_fd, ReadStart, ReadSize); mp3_filepos += ReadSize; if (mp3_filepos == mp3_fsize) { if (cdda_autoloop) { mp3_filepos = 0; sceIoLseek(mp3_fd, 0, PSP_SEEK_SET); } else { cdda_playing = CDDA_STOP; mp3_status = MP3_STOP; } } if (mp3_filepos == mp3_fsize) { GuardPtr = ReadStart + ReadSize; memset(GuardPtr, 0, MAD_BUFFER_GUARD); ReadSize += MAD_BUFFER_GUARD; } mad_stream_buffer(&Stream, mp3_in, ReadSize + Remaining); Stream.error = 0; } if (mad_frame_decode(&Frame, &Stream)) { if (MAD_RECOVERABLE(Stream.error)) { // if (Stream.error != MAD_ERROR_LOSTSYNC || Stream.this_frame != GuardPtr) continue; } else if (Stream.error == MAD_ERROR_BUFLEN) { continue; } else { ui_popup(TEXT(MP3_DECODE_ERROR)); mp3_status = MP3_STOP; break; } } mp3_frame++; mad_timer_add(&Timer, Frame.header.duration); mad_synth_frame(&Synth, &Frame); if (mp3_status == MP3_PLAY) { int i; for (i = 0; i < Synth.pcm.length; i++) { if (MAD_NCHANNELS(&Frame.header) == 2) { *OutputPtr++ = MP3Limit(Synth.pcm.samples[0][i]); *OutputPtr++ = MP3Limit(Synth.pcm.samples[1][i]); } else { INT16 data = MP3Limit(Synth.pcm.samples[0][i]); *OutputPtr++ = data; *OutputPtr++ = data; } if (OutputPtr == OutputEnd) { sceAudioOutputPannedBlocking(mp3_handle, mp3_volume, mp3_volume, mp3_out[flip]); flip ^= 1; OutputPtr = (INT16 *)mp3_out[flip]; OutputEnd = (INT16 *)(mp3_out[flip] + MP3_BUFFER_SIZE); } } } else if (mp3_status == MP3_SEEK) { if (mp3_frame >= mp3_start_frame) { mp3_start_frame = 0; mp3_status = MP3_SLEEP; sceKernelSleepThread(); } } } mad_synth_finish(&Synth); mad_frame_finish(&Frame); mad_stream_finish(&Stream); if (mp3_fd >= 0) { sceIoClose(mp3_fd); mp3_fd = -1; } }
int sleepingThread(SceSize args, void *argp) { sceKernelSleepThread(); strcat(msg, "Sleeping Thread\n"); return 0; }
int main_thread(SceSize args, void *argp) { sceKernelDelayThread(3000000); u32 keycombination; SceCtrlData pad; u32 oldButtons = 0; int extra = 0; keycombination = PSP_CTRL_RTRIGGER; //Button to start interpreter (Basic) u32 keycombination2 = PSP_CTRL_RTRIGGER + PSP_CTRL_LTRIGGER; // Button to start interpreter (Extra PSP Go) while(1){ oldButtons = pad.Buttons; if (go==0){ sceCtrlPeekBufferPositive(&pad, 1); if(oldButtons != pad.Buttons) { if(pad.Buttons & keycombination2) { pauseGame(thid1); go=1; extra=1; pspDebugScreenInit(); pspDebugScreenClear(); oldButtons = pad.Buttons; }else if(pad.Buttons & keycombination) { pauseGame(thid1); go=1; pspDebugScreenInit(); pspDebugScreenClear(); oldButtons = pad.Buttons; } } } if (go ==1){ pspDebugScreenSetXY(0,0); pspDebugScreenSetTextColor(0xffffff); int go2=1; SceUID id; if (((kuKernelGetModel() + 1) == 4) || ((kuKernelGetModel() + 1) == 5)){ if (extra==1){ id = sceIoDopen("ms0:/seplugins/script"); //PSP Go MS Support }else{ id = sceIoDopen("ef0:/seplugins/script"); //PSP Go Internal HD Support } }else{ id = sceIoDopen("ms0:/seplugins/script"); } SceIoDirent entry; int script_files = -2; memset(&entry, 0, sizeof(SceIoDirent)); while (sceIoDread(id, &entry) > 0) { script_files = script_files+1; memset(&entry, 0, sizeof(SceIoDirent)); } sceIoDclose(id); char script[256]; if (((kuKernelGetModel() + 1) == 4) || ((kuKernelGetModel() + 1) == 5)){ if (extra==1){ strcpy(script,"ms0:/seplugins/script/index.lua"); //PSP Go MS Support }else{ strcpy(script,"ef0:/seplugins/script/index.lua"); //PSP Go Internal HD Support } }else{ strcpy(script,"ms0:/seplugins/script/index.lua"); } while(go2==1) { const char *errMsg; if (script_files>1){ errMsg = runScript(extralibs, true); }else{ SceUID fp = sceIoOpen(script, PSP_O_RDONLY,0777); int size = sceIoLseek(fp, 0, SEEK_END); sceIoLseek(fp, 0, SEEK_SET); unsigned char *buffer; buffer = malloc((size+1) * sizeof (char)); sceIoRead(fp, buffer, size); buffer[size]=0; sceIoClose(fp); errMsg = runScript(buffer, true); free(buffer); } // System.restart sourcecode if (strstr(errMsg, "lpp_restart")){ go2=0; // End System.restart sources // Temp replacing for loadfile/dofile functions: System.protodofile }else if (strstr(errMsg, "lpp_open")){ char dum1[20], dum2[20], dum3[20]; char script_path2[256]; sscanf( errMsg, "%s %s %s %s", dum1, dum2, dum3, script_path2 ); strcpy(script,script_path2); script_files=1; // End System.protodofile sources }else if (strstr(errMsg, "resumeThread")){ go=0; go2=0; }else{ if (errMsg != NULL); { pspDebugScreenClear(); pspDebugScreenSetTextColor(0xffffff); debugOutput("\nError: %s\n", errMsg); } debugOutput("\nPress start to restart\nPress select to resume thread\n"); SceCtrlData pad; int restore = 0; while(restore==0){ sceCtrlPeekBufferPositive(&pad, 1); if (pad.Buttons&PSP_CTRL_START){ restore=1; go2=0; } if (pad.Buttons&PSP_CTRL_SELECT){ resumeGame(thid1); restore=1; go=0; go2=0; } } } } } sceDisplayWaitVblankStart(); } sceKernelSleepThread(); return 0; }