int main(void) { // Check errors on purpose testSysSemaphoreErrors(); // Create the global semaphore sys_semaphore_attribute_t attr; sys_semaphore_attribute_initialize(attr); if (sys_semaphore_create(&g_sem, &attr, 2, 2)) { printf("[!] sys_semaphore_create: Something went wrong!\n"); exit(-1); } // Decrement semaphore: 2 -> 1 -> 0 sys_semaphore_value_t val; printf("\n[*] Testing sys_semaphore_get_value and sys_semaphore_(try)wait:\n"); sys_semaphore_get_value(g_sem, &val); printf("sys_semaphore_get_value: 0x%x\n", val); createThreadAndJoin(semWait, 0ULL); sys_semaphore_get_value(g_sem, &val); printf("sys_semaphore_get_value: 0x%x\n", val); createThreadAndJoin(semTrywait); sys_semaphore_get_value(g_sem, &val); printf("sys_semaphore_get_value: 0x%x\n", val); // Create 3 threads and wake 1 of them after 1 second printf("\n[*] Testing sys_semaphore_post and sys_semaphore_wait:\n"); createThread(semWaitCheck, 0); createThread(semWaitCheck, 0); createThread(semWaitCheck, 900000000ULL); // 15 min timeout createThreadAndJoin(semPost, 1); sys_timer_sleep(2); sys_semaphore_get_value(g_sem, &val); printf("sys_semaphore_get_value: 0x%x\n", val); // Wake the 2 remaining threads after 1 second createThreadAndJoin(semPost, 2); sys_timer_sleep(2); sys_semaphore_get_value(g_sem, &val); printf("sys_semaphore_get_value: 0x%x\n", val); // Create 1 threads and post 30 to the semaphore after 1 second (it shouldn't wake up) createThread(semWaitCheck, 0); createThreadAndJoin(semPost, 30); sys_timer_sleep(2); sys_semaphore_get_value(g_sem, &val); printf("sys_semaphore_get_value: 0x%x\n", val); // TODO: Repeat the tests, but now modifying sys_semaphore_attribute_t members. return 0; }
void semPost(uint64_t arg) { sys_timer_sleep(1); if (sys_semaphore_post(g_sem, arg) & ~0x8001000A) { printf("[!] sys_semaphore_post: Something went wrong!\n"); exit(-1); } sys_ppu_thread_exit(0); }
void CreateFolder(char* folders) { if(mkdir(folders,0777)) { gl_dprintf(0.09f,0.05f,Emulator_GetFontSize(),"ERROR - Could not create folder: %s \nPlease check your GenesisConf.ini\n",folders); sys_timer_sleep(5); sys_process_exit(0); } }
/* * Function: art_process() * File: main.c * Project: ArtemisPS3-PRX * Description: Processes an entire codelist once * Arguments: * forceWrite: whether the user activated Artemis (1) or a constant write (0) * Return: void */ static void art_process(int forceWrite) { int fd = 0; if (attachedPID) { doForceWrite = forceWrite; //Force load userCodes on forceWrite if (forceWrite && userCodes) { reset_heap(); userCodes = NULL; } if (!userCodes) { int fileSize = getFileSize("/dev_hdd0/tmp/art.txt"); userCodes = (char *)mem_alloc(fileSize + 2); memset(userCodes, 0, fileSize + 2); if(cellFsOpen("/dev_hdd0/tmp/art.txt", CELL_FS_O_RDONLY, &fd, NULL, 0) == CELL_FS_SUCCEEDED) { u64 read_e = 0, pos; cellFsLseek(fd, 0, CELL_FS_SEEK_SET, &pos); cellFsRead(fd, (void *)userCodes, fileSize, &read_e); cellFsClose(fd); } userCodes[fileSize] = '\n'; } if (attachedPID != NULL && attachedPID != 0) { ConvertCodes(attachedPID, userCodes); sys_timer_sleep(0.1); } } doForceWrite = 0; }
/*********************************************************************** * plugin main ppu thread ***********************************************************************/ static void vsh_menu_thread(uint64_t arg) { #ifdef DEBUG dbg_init(); dbg_printf("programstart:\n"); #endif uint16_t oldpad = 0, curpad = 0; CellPadData pdata; // wait for XMB, feedback sys_timer_sleep(13); //vshtask_notify("sprx running..."); play_rco_sound("system_plugin", "snd_trophy"); #ifdef HAVE_STARFIELD init_once(/* stars */); #endif // custom bg_color init a = GET_A(bg_color_menu[1]); r = GET_R(bg_color_menu[1]); g = GET_G(bg_color_menu[1]); b = GET_B(bg_color_menu[1]); while(1) { // if VSH Menu is running, we get pad data over our MyPadGetData() // else, we use the vsh pad_data struct if(menu_running) MyPadGetData(0, &pdata); else VSHPadGetData(&pdata); // if pad_data and we are in XMB(vshmain_EB757101() == 0) if((pdata.len > 0) && (vshmain_EB757101() == 0) ) { curpad = (pdata.button[2] | (pdata.button[3] << 8)); if((curpad & PAD_SELECT) && (curpad != oldpad)) { switch(menu_running) { // VSH Menu not running, start VSH Menu case 0: // main view and start on first entry view = line = 0; // pause_RSX_rendering(); // create VSH Menu heap memory from memory container 1("app") create_heap(64); // 64 MB // initialize VSH Menu graphic (init drawing context, alloc buffers, blah, blah, blah...) init_graphic(); // stop vsh pad start_stop_vsh_pad(0); // set menu_running menu_running = 1; break; // VSH Menu is running, stop VSH Menu case 1: stop_VSH_Menu(); // restart vsh pad start_stop_vsh_pad(1); break; } oldpad = 0; sys_timer_usleep(300000); } // VSH Menu is running, draw menu / check pad if(menu_running) { #ifdef DEBUG dbg_printf("%p\n", pdata); #endif draw_frame(&pdata); flip_frame(); if(curpad != oldpad) { if(curpad & PAD_UP) { if(line <= 0){ line = 0; }else{ line--; play_rco_sound("system_plugin", "snd_cursor"); } } if(curpad & PAD_DOWN) { if(line >= max_menu[view]-1){ line = max_menu[view]-1; }else{ line++; play_rco_sound("system_plugin", "snd_cursor"); } } if(curpad & PAD_LEFT || curpad & PAD_RIGHT) do_leftright_action(curpad); if(curpad & PAD_CROSS) do_menu_action(); } // ... sys_timer_usleep(30); } // end VSH Menu is running oldpad = curpad; }else{ oldpad = 0; } } #ifdef DEBUG dbg_fini(); #endif sys_ppu_thread_exit(0); }
/*********************************************************************** * execute a menu action, based on line(current selected menu entry) ***********************************************************************/ static void do_menu_action(void) { switch(view) { case 0: // main menu view switch(line) { case 0: // "1: Make a single beep" buzzer(1); break; case 1: // "2: Make a double beep" buzzer(2); break; case 2: // "3: Enter second menu view" view = 1; // change menu view line = 0; // on start entry break; case 3: // "4: Enter third menu view" view = 2; // change menu view line = 0; // on start entry break; case 4: // "5: Play trophy sound" play_rco_sound("system_plugin", "snd_trophy"); break; case 5: // "6: Make screenshot" screenshot(0); // xmb only play_rco_sound("system_plugin", "snd_system_ok"); break; case 6: // "7: Make screenshot with menu" screenshot(1); // play_rco_sound("system_plugin", "snd_system_ok"); break; case 7: // "8: Reset PS3" stop_VSH_Menu(); delete_turnoff_flag(); sys_timer_sleep(1); shutdown_reset(2); break; case 8: // "9: Shutdown PS3" stop_VSH_Menu(); delete_turnoff_flag(); sys_timer_sleep(1); shutdown_reset(1); break; } break; case 1: // second menu view switch(line) { case 0: // 1: Back to main view" view = line = 0; break; case 1: // 2: screenshot screenshot(1); break; case 2: // 3: Alpha //... break; case 3: // 4: Red //... break; case 4: // 5: Green //... break; case 5: // 6: Blue //... break; case 6: // 7: test break; } break; case 2: // third menu view switch(line) { case 0: // "1: Back to main view" view = line = 0; break; case 1: // "2: test string..." //... break; case 2: // "3: test string..." //... break; case 3: // "4: test string..." //... break; case 4: // "5: test string..." //... break; } break; } }
/* * Function: art_thread() * File: main.c * Project: ArtemisPS3-PRX * Description: Artemis PRX Thread start * Interprets user input and calls art_process() * Arguments: * arg: * Return: void */ static void art_thread(uint64_t arg) { int GameProcessID = 0, lastGameProcessID = 0; printf("Artemis PS3 :::: Thread Started!\n"); sys_timer_sleep(10); sys_ppu_thread_yield(); CellPadData data; CellPadInfo2 info; int delay = 0, delay2 = 0, hasDisplayed = 0, fd = 0; while (1) { if (exitThread) { destroy_heap(); exitThread = 0; { sys_ppu_thread_exit(0); } { return; } } GameProcessID = GetGameProcessID(); if (GameProcessID != 0) { if (!check_turnoff()) //exit { printf("Artemis PS3 :::: Process Exited\n"); destroy_heap(); attachedPID = 0; } else { if (GameProcessID != lastGameProcessID) { for (int x = 0; x < (10 * 100); x++) //10 second delay { sys_timer_usleep(10000); sys_ppu_thread_yield(); } show_msg((char *)"Artemis PS3\nStart To Attach"); } cellPadGetInfo2(&info); if (info.port_status[0] && (cellPadGetData(0, &data) | 1) && data.len > 0) { uint32_t pad = data.button[2] | (data.button[3] << 8); if (attachedPID) // Run codes { art_process(0); } if (pad & PAD_START) { attachedPID = GameProcessID; if (attachedPID) { show_msg((char *)"Artemis PS3\nAttached and Wrote"); printf("Artemis PS3 :::: Attached to 0x%08X\n", attachedPID); if (get_heap() == 0) create_heap(1); check_syscall_api(); art_process(1); while ((cellPadGetData(0, &data) | 1) && data.len > 0) { if (!((data.button[2] | (data.button[3] << 8)) & PAD_START)) break; sys_timer_usleep(1000000); sys_ppu_thread_yield(); } } else { show_msg((char *)"Artemis PS3\nFailed to Attach"); } } else if (pad & PAD_SELECT && attachedPID) { show_msg((char *)"Artemis PS3\nDetached"); reset_heap(); attachedPID = 0; } } sys_timer_usleep(100 * 1000); //0.1 second delay } } else { if (attachedPID) // Disconnect { printf("Artemis PS3 :::: Process Exited\n"); destroy_heap(); attachedPID = 0; } else sys_timer_usleep(3 * 1000 * 1000); //3 second delay } lastGameProcessID = GameProcessID; sys_timer_usleep(1668); sys_ppu_thread_yield(); } destroy_heap(); sys_ppu_thread_exit(0); }