void PspSpeedTests::tickSpeed() { uint32 ticksPerSecond = sceRtcGetTickResolution(); PSP_INFO_PRINT("ticksPerSecond[%d]\n", ticksPerSecond); uint32 currentTicks1[2]; uint32 currentTicks2[2]; sceRtcGetCurrentTick((u64 *)currentTicks1); sceRtcGetCurrentTick((u64 *)currentTicks2); PSP_INFO_PRINT("current tick[%x %x][%u %u]\n", currentTicks1[0], currentTicks1[1], currentTicks1[0], currentTicks1[1]); PSP_INFO_PRINT("current tick[%x %x][%u %u]\n", currentTicks2[0], currentTicks2[1], currentTicks2[0], currentTicks2[1]); pspTime time; sceRtcSetTick(&time, (u64 *)currentTicks2); PSP_INFO_PRINT("current tick in time, year[%d] month[%d] day[%d] hour[%d] minutes[%d] seconds[%d] us[%d]\n", time.year, time.month, time.day, time.hour, time.minutes, time.seconds, time.microseconds); pspTime time1; pspTime time2; sceRtcGetCurrentClockLocalTime(&time1); sceRtcGetCurrentClockLocalTime(&time2); PSP_INFO_PRINT("time1, year[%d] month[%d] day[%d] hour[%d] minutes[%d] seconds[%d] us[%d]\n", time1.year, time1.month, time1.day, time1.hour, time1.minutes, time1.seconds, time1.microseconds); PSP_INFO_PRINT("time2, year[%d] month[%d] day[%d] hour[%d] minutes[%d] seconds[%d] us[%d]\n", time2.year, time2.month, time2.day, time2.hour, time2.minutes, time2.seconds, time2.microseconds); }
void DisplayFPS() { uint64_t currentTick = 0; int result = sceRtcGetCurrentTick(¤tTick); if (result != 0) { printf("sceRtcGetCurrentTick : 0x%x\n", currentTick); } uint64_t difference = currentTick - lastTick; lastTick = currentTick; int fps = sceRtcGetTickResolution() / (int) difference; fpsTimes[fpsIndex] = fps; if (++fpsIndex == FPS_TIMES_COUNT) { fpsIndex = 0; } fps = 0; int i; for (i = 0; i < FPS_TIMES_COUNT; ++i) { fps += fpsTimes[i]; } fps /= FPS_TIMES_COUNT; PSP2_Video_FillScreen(SCREEN_W * 200); sprintf(fpstext, "FPS: %d", fps); mh_print(5, 5, fpstext, RGBA8(0, 255, 0, 255), 0, 0); }
/* 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; }
// Main function int main(int argc, char **argv) { int battimeout = 0; char fpstxt[16]; // Open debug files PokeDebugFOut = fopen("dbg_stdout.txt", "w"); PokeDebugFErr = fopen("dbg_stderr.txt", "w"); // Init video PokeDPrint(POKEMSG_OUT, "%s\n\n", AppName); PokeMini_InitDirs(argv[0], NULL); CommandLineInit(); CommandLine.low_battery = 2; // PSP can report battery status CommandLineConfFile("pokemini.cfg", "pokemini_psp.cfg", CustomConf); JoystickSetup("PSP", 0, 30000, PSP_KeysNames, 16, PSP_KeysMapping); // PSP Init and set screen PSP_Init(); setup_screen(); // Create emulator and load test roms PokeDPrint(POKEMSG_OUT, "Starting emulator...\n"); PokeMini_Create(POKEMINI_GENSOUND | POKEMINI_AUTOBATT, 0); // Setup palette and LCD mode PokeMini_VideoPalette_Init(PokeMini_RGB16, 1); PokeMini_VideoPalette_Index(CommandLine.palette, CommandLine.custompal, CommandLine.lcdcontrast, CommandLine.lcdbright); PokeMini_ApplyChanges(); // Load stuff PokeMini_UseDefaultCallbacks(); if (!PokeMini_LoadFromCommandLines("Using FreeBIOS", "EEPROM data will be discarded!")) { UI_Status = UI_STATUS_MENU; } // Enable sound & init UI PokeDPrint(POKEMSG_OUT, "Running emulator...\n"); UIMenu_Init(); enablesound(CommandLine.sound); sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); // Emulator's loop u64 tickcurr; u64 fpsticknext,fpstickres = (u64)sceRtcGetTickResolution(); u64 frmticknext, frmtickres = (u64)sceRtcGetTickResolution() / 36; sceRtcGetCurrentTick(&tickcurr); fpsticknext = tickcurr + fpstickres; frmticknext = tickcurr + frmtickres; int fps = 72, fpscnt = 0; strcpy(fpstxt, ""); while (emurunning) { // Emulate 2 frames PokeMini_EmulateFrame(); PokeMini_EmulateFrame(); if (RequireSoundSync) { while (MinxAudio_SyncWithAudio()) sceKernelDelayThread(1000); } else { do { sceRtcGetCurrentTick(&tickcurr); sceKernelDelayThread(1000); } while (tickcurr < frmticknext); frmticknext = tickcurr + frmtickres; // Aprox 36 times per sec } // Screen rendering PSP_ClearDraw(); if (PokeMini_Rumbling) { PokeMini_VideoBlit((uint16_t *)PSP_DrawVideo + pm_offset + PokeMini_GenRumbleOffset(512), 512); } else { PokeMini_VideoBlit((uint16_t *)PSP_DrawVideo + pm_offset, 512); } LCDDirty = 0; // Display FPS counter if (clc_displayfps) { sceRtcGetCurrentTick(&tickcurr); if (tickcurr >= fpsticknext) { fpsticknext = tickcurr + fpstickres; fps = fpscnt; fpscnt = 0; sprintf(fpstxt, "%i FPS", fps); } else fpscnt++; UIDraw_String_16((uint16_t *)PSP_DrawVideo, 512, 4, 4, 10, fpstxt, UI_Font1_Pal16); } // Handle keys HandleKeys(); // Menu if (UI_Status == UI_STATUS_MENU) menuloop(); // Wait VSync & Render (72 Hz) PSP_Flip(); // Check battery if (battimeout <= 0) { PokeMini_LowPower(scePowerIsLowBattery()); battimeout = 600; } else battimeout--; } // Stop sound & free UI enablesound(0); UIMenu_Destroy(); // Save Stuff PokeMini_SaveFromCommandLines(1); // Terminate... PokeDPrint(POKEMSG_OUT, "Shutdown emulator...\n"); PokeMini_VideoPalette_Free(); PokeMini_Destroy(); // Close debug files fclose(PokeDebugFOut); fclose(PokeDebugFErr); // PSP Quit PSP_Quit(); return 0; }
int main(int argc, char** argv) { sceRtcGetCurrentTick( &fpsTickLast ); tickResolution = sceRtcGetTickResolution(); Gamepad gamepad; App_Initialize(); timerTest.start(); float nextUpdate = 0; while(1) { timerTest.update(); (*mySceneMotion).evaluate(timerTest.getSeconds()); App_Render(); if(gamepad.Poll()) { if(gamepad.ButtonDown(PSP_CTRL_TRIANGLE)) { timerTest.paused(true); } if(gamepad.ButtonDown(PSP_CTRL_SQUARE)) { timerTest.paused(false); } if(timerTest.paused()) { if(fabs(gamepad.AnalogX()) > 0.1) { if(gamepad.ButtonDown(PSP_CTRL_RTRIGGER)) { if(timerTest.getSeconds() - 0.5f > 0 || gamepad.AnalogX() > 0) timerTest.setSeconds(timerTest.getSeconds() + (gamepad.AnalogX() * 0.5)); } else { if(timerTest.getSeconds() - 0.1f > 0 || gamepad.AnalogX() > 0) timerTest.setSeconds(timerTest.getSeconds() + (gamepad.AnalogX() * 0.1)); } } } if(gamepad.ButtonDown(PSP_CTRL_LEFT)) { if(gamepad.ButtonDown(PSP_CTRL_RTRIGGER)) { if(timerTest.getSeconds() - 0.1f > 0) timerTest.setSeconds(timerTest.getSeconds() - 0.1); } else { if(timerTest.getSeconds() - 0.01f > 0) timerTest.setSeconds(timerTest.getSeconds() - 0.01); } } if(gamepad.ButtonDown(PSP_CTRL_RIGHT)) { if(gamepad.ButtonDown(PSP_CTRL_RTRIGGER)) { timerTest.setSeconds(timerTest.getSeconds() + 0.1); } else { timerTest.setSeconds(timerTest.getSeconds() + 0.01); } } } } App_Shutdown(); return 0; }
int main(int argc, char **argv) { SceCtrlData pad; int oldButtons = 0; int useVblank = 1; pspDebugScreenInit(); if (argc > 0) { printf("Bootpath: %s\n", argv[0]); } printf("Triangle - Exit\n"); printf("Square - Toggle vblank (60 fps limit)\n"); printf("\n"); SetupCallbacks(); sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); sceRtcGetCurrentTick( &fpsTickLast ); tickResolution = sceRtcGetTickResolution(); printGetDayOfWeek(); printf("\n"); printGetDaysInMonth(); printf("\n"); printSetTick(); printf("\n"); printGetTick(); printf("\n"); printf("sceRtcGetTickResolution: %d", (int)tickResolution); while(!done) { sceCtrlPeekBufferPositive(&pad, 1); int buttonDown = (oldButtons ^ pad.Buttons) & pad.Buttons; if (buttonDown & PSP_CTRL_SQUARE) { useVblank ^= 1; } if (buttonDown & PSP_CTRL_TRIANGLE) done = 1; oldButtons = pad.Buttons; updateDrawFPS(); if (useVblank) sceDisplayWaitVblankStart(); fbp0 = sceGuSwapBuffers(); } sceKernelExitGame(); // Quits Application return 0; }
void JGE::Run() { static const int keyCodeList[] = { PSP_CTRL_SELECT, // Select button. PSP_CTRL_START, // Start button. PSP_CTRL_UP, // Up D-Pad button. PSP_CTRL_RIGHT, // Right D-Pad button. PSP_CTRL_DOWN, // Down D-Pad button. PSP_CTRL_LEFT, // Left D-Pad button. PSP_CTRL_LTRIGGER, // Left trigger. PSP_CTRL_RTRIGGER, // Right trigger. PSP_CTRL_TRIANGLE, // Triangle button. PSP_CTRL_CIRCLE, // Circle button. PSP_CTRL_CROSS, // Cross button. PSP_CTRL_SQUARE, // Square button. PSP_CTRL_HOLD, // Hold button. }; u64 curr; long long int nextInput = 0; u64 lastTime; u32 oldButtons; u32 veryOldButtons; u32 gTickFrequency = sceRtcGetTickResolution(); sceRtcGetCurrentTick(&lastTime); oldButtons = veryOldButtons = 0; while (!mDone) { if (!mPaused) { sceRtcGetCurrentTick(&curr); float dt = (curr - lastTime) / (float)gTickFrequency; mDeltaTime = dt; sceCtrlPeekBufferPositive(&gCtrlPad, 1); for (signed int i = sizeof(keyCodeList)/sizeof(keyCodeList[0]) - 1; i >= 0; --i) { if (keyCodeList[i] & gCtrlPad.Buttons) { if (!(keyCodeList[i] & oldButtons)) HoldKey(keyCodeList[i]); } else if (keyCodeList[i] & oldButtons) ReleaseKey(keyCodeList[i]); } oldButtons = gCtrlPad.Buttons; Update(dt); Render(); if (mDebug) { if (strlen(mDebuggingMsg)>0) { pspDebugScreenSetXY(0, 0); pspDebugScreenPrintf(mDebuggingMsg); } } veryOldButtons = gCtrlPad.Buttons; } else sceKernelDelayThread(1); lastTime = curr; } }
//#Is required before calls to getDeltaTime() void initTimer() { sceRtcGetCurrentTick( &timeLastAsk ); sceRtcGetCurrentTick( &timeLastFPS ); tickResolution = sceRtcGetTickResolution(); }
int main (int argc, char **argv) { #if WRITE_LOG FILE *log = NULL; #endif u32 ticks_per_s; int oldtime; SetupCallbacks(); #if WRITE_LOG // Wipe log file. log = fopen("log.txt", "w"); if (log != NULL) { fputs("LOG START\n\n", log); fclose(log); log = NULL; } #endif // Calculate the clock resolution. sceRtcGetCurrentTick(&first_ticks); ticks_per_s = sceRtcGetTickResolution(); ticks_per_ms = ticks_per_s / 1000.0; // TODO Move elsewhere. sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); // Initialise Quake. Qcommon_Init (argc, argv); oldtime = Sys_Milliseconds(); // Run the main loop. while (go) { SceCtrlData pad; curtime = Sys_Milliseconds(); sys_frame_time = curtime; if (curtime < oldtime) { Sys_Error("curtime (%d) < oldtime (%d)\n", curtime, oldtime); } sceCtrlPeekBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_CROSS) { go = false; } if (curtime != oldtime) { Qcommon_Frame(curtime - oldtime); oldtime = curtime; } } sceKernelExitGame(); return 0; }
int pspCtrlPollControls(SceCtrlData *pad) { int stat; /* Simulate button autorepeat */ if (PollingMode == PSP_CTRL_AUTOREPEAT) { SceCtrlData p; int stat, i; u64 tick; u32 tick_res; /* Poll the controls */ if (!(stat = sceCtrlPeekBufferPositive(&p, 1))) return stat; /* Get current tick count */ sceRtcGetCurrentTick(&tick); tick_res = sceRtcGetTickResolution(); /* Check each button */ for (i = 0; i < PSP_CTRL_BUTTONS; i++) { if (p.Buttons & ButtonMap[i]) { if (!PushTime[i] || tick >= PushTime[i]) { /* Button was pushed for the first time, or time to repeat */ pad->Buttons |= ButtonMap[i]; /* Compute next press time */ PushTime[i] = tick + ((PushTime[i]) ? PSP_CTRL_THRESHOLD : PSP_CTRL_DELAY) * (tick_res / 1000); } else { /* No need to repeat yet */ pad->Buttons &= ~ButtonMap[i]; } } else { /* Button was released */ pad->Buttons &= ~ButtonMap[i]; PushTime[i] = 0; } } /* Copy analog stick status */ pad->Lx = p.Lx; pad->Ly = p.Ly; /* Unset the analog stick bits */ pad->Buttons &= ~(PSP_CTRL_ANALUP | PSP_CTRL_ANALDOWN | PSP_CTRL_ANALLEFT | PSP_CTRL_ANALRIGHT); /* Set the bits based on analog stick status */ if (pad->Ly < 32) pad->Buttons |= PSP_CTRL_ANALUP; else if (pad->Ly >= 224) pad->Buttons |= PSP_CTRL_ANALDOWN; if (pad->Lx < 32) pad->Buttons |= PSP_CTRL_ANALLEFT; else if (pad->Lx >= 224) pad->Buttons |= PSP_CTRL_ANALRIGHT; return stat; } /* Default is normal behavior */ if (!(stat = sceCtrlPeekBufferPositive(pad, 1))) return stat; /* Unset the analog stick bits */ pad->Buttons &= ~(PSP_CTRL_ANALUP | PSP_CTRL_ANALDOWN | PSP_CTRL_ANALLEFT | PSP_CTRL_ANALRIGHT); /* Set the bits based on analog stick status */ if (pad->Ly < 32) pad->Buttons |= PSP_CTRL_ANALUP; else if (pad->Ly >= 224) pad->Buttons |= PSP_CTRL_ANALDOWN; if (pad->Lx < 32) pad->Buttons |= PSP_CTRL_ANALLEFT; else if (pad->Lx >= 224) pad->Buttons |= PSP_CTRL_ANALRIGHT; return stat; }
CTimer::CTimer( void ) { sceRtcGetCurrentTick( &timeLastAsk ); tickResolution = sceRtcGetTickResolution(); }
Clock::Clock() { sceRtcGetCurrentTick( &timeLastAsk ); tickResolution = sceRtcGetTickResolution(); }