//----------------------------------------------------------------------------- // Purpose: Tell the game engine to sleep for a bit if needed to limit frame rate. You must keep // calling this repeatedly until it returns false. If it returns true it's slept a little, but more // time may be needed. //----------------------------------------------------------------------------- bool CGameEnginePS3::BSleepForFrameRateLimit( uint32 ulMaxFrameRate ) { // Frame rate limiting float flDesiredFrameMilliseconds = 1000.0f/ulMaxFrameRate; uint64 ulGameTickCount = cell::fios::FIOSAbstimeToMilliseconds( cell::fios::FIOSGetCurrentTime() ); float flMillisecondsElapsed = (float)(ulGameTickCount - m_ulGameTickCount); if ( flMillisecondsElapsed < flDesiredFrameMilliseconds ) { // If enough time is left sleep, otherwise just keep spinning so we don't go over the limit... if ( flDesiredFrameMilliseconds - flMillisecondsElapsed > 3.0f ) { sys_timer_usleep( 2000 ); } else { // Just return right away so we busy loop, don't want to sleep too long and go over } return true; } else { return false; } }
void Emulator_ToggleSound() { LOG_DBG("Emulator_ToggleSound()\n"); if(CellAudio) { delete CellAudio; } if((Settings.RSoundEnabled) && (strlen(Settings.RSoundServerIPAddress) > 0)) { CellAudio = new Audio::RSound<int16_t>(Settings.RSoundServerIPAddress, 2, SAMPLERATE_48KHZ); // If we couldn't connect, fall back to normal audio... if (!CellAudio->alive()) { delete CellAudio; CellAudio = new Audio::AudioPort<int16_t>(2, SAMPLERATE_48KHZ); Settings.RSoundEnabled = false; Graphics->Clear(); cellDbgFontPuts(0.09f, 0.4f, 1.0f, 0xffffffff, "Couldn't connect to RSound server.\nFalling back to regular audio..."); Graphics->FlushDbgFont(); Graphics->Swap(); sys_timer_usleep(3000000); } } else { CellAudio = new Audio::AudioPort<int16_t>(2, SAMPLERATE_48KHZ); } }
static void testplugin_thread(uint64_t arg) { DPRINTF("Hello VSH\n"); while (!done) { CellPadData data; if (cellPadGetData(0, &data) == CELL_PAD_OK && data.len > 0) { if ((data.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_PAD_CTRL_L3) && (data.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_R2)) { if (data.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_CROSS) { // power off vshmain_87BB0001(1); break; } else if (data.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_CIRCLE) { // reboot vshmain_87BB0001(2); break; } } } sys_timer_usleep(70000); } DPRINTF("Exiting main thread!\n"); sys_ppu_thread_exit(0); }
error_code sys_timer_sleep(ppu_thread& ppu, u32 sleep_time) { vm::temporary_unlock(ppu); sys_timer.trace("sys_timer_sleep(sleep_time=%d) -> sys_timer_usleep()", sleep_time); return sys_timer_usleep(ppu, sleep_time * u64{1000000}); }
void OsSleep(unsigned int millisecs) { #if defined(WIN32) Sleep(millisecs); #elif defined(__CELLOS_LV2__) sys_timer_usleep( (millisecs) * 1000 ); #endif // defined(WIN32) }
void MDFND_Sleep(unsigned int time) { #if defined(_WIN32) Sleep(time); #elif defined(__CELLOS_LV2__) sys_timer_usleep(time * 1000); #else usleep(time * 1000); #endif }
void Sys_Sleep(void) { #if defined(_WIN32) Sleep(1 * 1000); #elif defined(__CELLOS_LV2__) sys_timer_usleep(1); #else usleep(1); #endif }
static int if_up_with(int index) { (void)index; #ifdef __CELLOS_LV2__ int timeout_count = 10; int state; int ret; ret = cellNetCtlInit(); if (ret < 0) { printf("cellNetCtlInit() failed(%x)\n", ret); return -1; } for (;;) { ret = cellNetCtlGetState(&state); if (ret < 0) { printf("cellNetCtlGetState() failed(%x)\n", ret); return -1; } if (state == CELL_NET_CTL_STATE_IPObtained) break; sys_timer_usleep(500 * 1000); timeout_count--; if (index && timeout_count < 0) { printf("if_up_with(%d) timeout\n", index); return 0; } } #elif defined(GEKKO) char t[16]; if (if_config(t, NULL, NULL, TRUE) < 0) { return -1; } #endif sock=socket(AF_INET, SOCK_DGRAM, 0); target.sin_family = AF_INET; target.sin_port = htons(PC_DEVELOPMENT_UDP_PORT); #ifdef GEKKO target.sin_len = 8; #endif inet_pton(AF_INET, PC_DEVELOPMENT_IP_ADDRESS, &target.sin_addr); return 0; }
int art_stop(void) { //if (userCodes) // _free(userCodes); finalize_module(); exitThread = 1; while (exitThread) { sys_timer_usleep(1668); sys_ppu_thread_yield(); } _sys_ppu_thread_exit(0); return SYS_PRX_STOP_OK; }
float GetOrWait(float deltams, bool update) { float ret, towait; #if defined __linux__ || defined __APPLE__ struct timeval tv; gettimeofday(&tv, NULL); ret = 1e-3f * (tv.tv_usec - tv0.tv_usec) + 1e3f * (tv.tv_sec - tv0.tv_sec); if (update) tv0 = tv; towait = deltams - ret; if (towait > 0.0f) usleep((int)(towait * 1e3f)); #elif defined _WIN32 LARGE_INTEGER cycles; QueryPerformanceCounter(&cycles); static float ms_per_cycle = GetMsPerCycle(); ret = ms_per_cycle * (cycles.QuadPart - cycles0.QuadPart); if (update) cycles0 = cycles; towait = deltams - ret; if (towait > 5e-4f) Sleep((int)(towait + 0.5f)); #elif defined __CELLOS_LV2__ uint64_t cycles; SYS_TIMEBASE_GET(cycles); static float ms_per_cycle = GetMsPerCycle(); ret = ms_per_cycle * (cycles - cycles0); if (update) cycles0 = cycles; towait = deltams - ret; if (towait > 0.0f) sys_timer_usleep((int)(towait * 1e3f)); #else /* The crappy SDL fallback */ Uint32 ticks = SDL_GetTicks(); ret = ticks - ticks0; if (update) ticks0 = ticks; towait = deltams - ret; if (towait > 0.5f) SDL_Delay((int)(towait + 0.5f)); #endif return ret; }
/* POSIX timer thread. */ static void *profile_thread(ProfileState *ps) { int interval = ps->interval; #if !LJ_TARGET_PS3 struct timespec ts; ts.tv_sec = interval / 1000; ts.tv_nsec = (interval % 1000) * 1000000; #endif while (1) { #if LJ_TARGET_PS3 sys_timer_usleep(interval * 1000); #else nanosleep(&ts, NULL); #endif if (ps->abort) break; profile_trigger(ps); } return NULL; }
void SDL_Delay (Uint32 ms) { sys_timer_usleep(ms * 1000); }
void thread_FileCopy(uint64_t /*arg*/) { gamePKG->nStatus = STATUS_COPY_START; FILE *filer = NULL; FILE *filew = NULL; uint64_t numr = 0; // elements read uint64_t numw = 0; // elements wrote uint64_t nTotalRead = 0; double nCopyPct = 0.0f; double nTotDelta = 0.0f; uint32_t nApproxTotDelta = 0; char *buffer = NULL; buffer = (char*)malloc(BUFF_SIZE); filer = fopen(gamePKG->pkglst[gamePKG->nSelectedPKG].path,"rb"); char szFileOut[256] =""; sprintf( szFileOut, "/dev_hdd0/vsh/game_pkg/%d/%s", gamePKG->pkglst[gamePKG->nSelectedPKG].nPKGID, gamePKG->pkglst[gamePKG->nSelectedPKG].title ); filew = fopen(szFileOut, "wb"); if(filer != NULL && filew != NULL) { bool bCopyError = false; while(feof(filer) == 0) { // read if((numr = fread(buffer, 1, BUFF_SIZE, filer)) != BUFF_SIZE) { if(ferror(filer) != 0) { bCopyError = true; break; } else if(feof(filer) != 0) { // ... } } // write if((numw = fwrite(buffer, 1, numr, filew)) != numr) { bCopyError = true; break; } nTotalRead += numr; nCopyPct = (double)(((double)numr / (double)gamePKG->pkglst[gamePKG->nSelectedPKG].nSize) * 100.0f); double nTotalPct = (double)((double)nTotalRead / (double)gamePKG->pkglst[gamePKG->nSelectedPKG].nSize) * 100.0f; nTotDelta += nCopyPct; nApproxTotDelta += (uint32_t)round(nCopyPct); if((double)nApproxTotDelta < nTotalPct) { // Compensate loss of float/double data, as for example: approx 70% vs. precise 95% nApproxTotDelta += (uint32_t)(nTotalPct - (double)nApproxTotDelta); nCopyPct += (nTotalPct - (double)nApproxTotDelta); } cellMsgDialogProgressBarInc(CELL_MSGDIALOG_PROGRESSBAR_INDEX_SINGLE, (uint32_t)nCopyPct); char msg[256] = ""; sprintf( msg, //"%.2f %s / %.2f %s (%.1f %%)(delta: %d %%)", "%.2f %s / %.2f %s", GetByteUnit(nTotalRead), GetByteUnitStr(nTotalRead), GetByteUnit(gamePKG->pkglst[gamePKG->nSelectedPKG].nSize), GetByteUnitStr(gamePKG->pkglst[gamePKG->nSelectedPKG].nSize) //, //nTotalPct, //nApproxTotDelta ); cellMsgDialogProgressBarSetMsg(CELL_MSGDIALOG_PROGRESSBAR_INDEX_SINGLE, msg); } nCopyPct = (double)(((double)numr / (double)gamePKG->pkglst[gamePKG->nSelectedPKG].nSize) * 100.0f); double nTotalPct = (double)((double)nTotalRead / (double)gamePKG->pkglst[gamePKG->nSelectedPKG].nSize) * 100.0f; nTotDelta += nCopyPct; nApproxTotDelta += (uint32_t)round(nCopyPct); if((double)nApproxTotDelta < nTotalPct) { // Compensate loss of float/double data, as for example: approx 70% vs. precise 95% nApproxTotDelta += (uint32_t)(nTotalPct - (double)nApproxTotDelta); nCopyPct += (nTotalPct - (double)nApproxTotDelta); } cellMsgDialogProgressBarInc(CELL_MSGDIALOG_PROGRESSBAR_INDEX_SINGLE, (uint32_t)nCopyPct); char msg[256] = ""; sprintf( msg, //"%.2f %s / %.2f %s (%.1f %%)(delta: %d %%)", "%.2f %s / %.2f %s", GetByteUnit(nTotalRead), GetByteUnitStr(nTotalRead), GetByteUnit(gamePKG->pkglst[gamePKG->nSelectedPKG].nSize), GetByteUnitStr(gamePKG->pkglst[gamePKG->nSelectedPKG].nSize) //, //nTotalPct, //nApproxTotDelta ); cellMsgDialogProgressBarSetMsg(CELL_MSGDIALOG_PROGRESSBAR_INDEX_SINGLE, msg); if(filer) fclose(filer); if(filew) fclose(filew); if(bCopyError) { cellFsUnlink(szFileOut); // delete file gamePKG->nStatus = STATUS_COPY_ERROR; sys_ppu_thread_exit(0); return; } } else { if(buffer) free(buffer); buffer = NULL; if(filer) fclose(filer); if(filew) { fclose(filew); cellFsUnlink(szFileOut); // delete file } gamePKG->nStatus = STATUS_COPY_ERROR; sys_ppu_thread_exit(0); return; } if(buffer) { free(buffer); buffer = NULL; } sys_timer_usleep(1000000); // wait 1 second gamePKG->nStatus = STATUS_COPY_OK; sys_ppu_thread_exit(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); }
/* * 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); }
void FceuGraphics::Sleep(uint64_t usec) const { sys_timer_usleep(usec); }