static void hit_any_key(void) { SceCtrlData cpad; /* 離されるまで待つ */ while (1) { sceCtrlReadBufferPositive(&cpad, 1); if (0 == cpad.Buttons) { goto l_end1; // break; } } l_end1: ; /* 押されるまで待つ */ while (1) { sceCtrlReadBufferPositive(&cpad, 1); /* Any Key */ if (cpad.Buttons & (PSP_CTRL_SQUARE|PSP_CTRL_CROSS|PSP_CTRL_CIRCLE|PSP_CTRL_TRIANGLE) ) { goto l_end2; // break; } } l_end2: ; }
int ProcessInput(int maxOption, int *selectedOption) { SceCtrlData pad, oldpad; sceCtrlReadBufferPositive(&oldpad, 1); while(1) { sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons != 0) { if (!(oldpad.Buttons & PSP_CTRL_CROSS) && pad.Buttons & PSP_CTRL_CROSS) { return *selectedOption; } else if (!(oldpad.Buttons & PSP_CTRL_UP) && pad.Buttons & PSP_CTRL_UP && *selectedOption > 0) { *selectedOption = *selectedOption-1; return -1; } else if (!(oldpad.Buttons & PSP_CTRL_DOWN) && pad.Buttons & PSP_CTRL_DOWN && *selectedOption < maxOption-1) { *selectedOption = *selectedOption + 1; return -1; } } oldpad = pad; } }
//from ospbt by cory1492 void wait_release(unsigned int buttons) { SceCtrlData pad; sceCtrlReadBufferPositive(&pad, 1); while(pad.Buttons & buttons) sceCtrlReadBufferPositive(&pad, 1); }
int waitbutton(int mask) { SceCtrlData paddata; do { sceDisplayWaitVblankStart(); sceCtrlReadBufferPositive(&paddata, 1); } while((paddata.Buttons & mask)); do { sceDisplayWaitVblankStart(); sceCtrlReadBufferPositive(&paddata, 1); } while(!(paddata.Buttons & mask)); return paddata.Buttons; }
//from ospbt by cory1492 unsigned int wait_press(unsigned int buttons) { SceCtrlData pad; sceCtrlReadBufferPositive(&pad, 1); while(1) { if(pad.Buttons & buttons) return pad.Buttons & buttons; sceCtrlReadBufferPositive(&pad, 1); } return 0; }
void glutMainLoop (void) { if (glut_reshape_func) glut_reshape_func(width, height); sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); do { static unsigned int oldbuttons = 0; SceCtrlData pad; int i; if (glut_joystick_func) { struct SceCtrlData pad; sceCtrlReadBufferPositive(&pad, 1); glut_joystick_func(pad.Buttons, (pad.Lx * 2000L) / 256 - 1000, (pad.Ly * 2000L) / 256 - 1000, 0); } sceCtrlReadBufferPositive(&pad, 1); for (i=0; i<sizeof(keycode)/sizeof(keycode[0]); i++) { if (pad.Buttons & (1 << i)) { if (KEY_REPEAT(keycode[i])) { key(keycode[i], 1); } else { if (!(oldbuttons & (1 << i))) key(keycode[i], 1); } } else { if (oldbuttons & (1 << i)) key(keycode[i], 0); } } oldbuttons = pad.Buttons; if (glut_display_func && glut_redisplay_posted) { glut_redisplay_posted = 0; glut_display_func(); } if (glut_idle_func) glut_idle_func(); } while (1); }
/* Main core function */ void Core::Process() { // Read in current control info sceCtrlReadBufferPositive(&pad, 1); // Render the shell components Desktop::Render(); IconManager::Render(); PluginManager::Handle(); WindowManager::Render(); Taskbar::Render(); PopupTheme::Render(); // Handle the controller Cursor::Handle(&pad); Controller::Handle(&pad); if (!Controller::Handled) Taskbar::Handle(); if (!Controller::Handled) WindowManager::Handle(); if (!Controller::Handled) IconManager::Handle(); if (!Controller::Handled) Desktop::Handle(); // Update screen Graphics::WaitVblankStart(); Graphics::FlipScreen(); }
void proc_ctrl() { #ifdef FOR_PSP static int counter = 0; if(++counter % 4 == 0) { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons & PSP_CTRL_CROSS) { shiftdown(); } if(pad.Buttons & PSP_CTRL_SQUARE) shiftup(); if(pad.Buttons & PSP_CTRL_LEFT) moveleft(); if(pad.Buttons & PSP_CTRL_RIGHT) moveright(); if(pad.Buttons & PSP_CTRL_DOWN) movedown(); if(pad.Buttons & PSP_CTRL_LTRIGGER) rquad -= 0.5f; if(pad.Buttons & PSP_CTRL_RTRIGGER) rquad += 0.5f; if(pad.Buttons & PSP_CTRL_CIRCLE) r_quad += 0.5f; if(pad.Buttons & PSP_CTRL_TRIANGLE) r_quad -= 0.5f; } #endif }
char * langBrowse(const char * path) { folderScan(path); dirVars(); while (!osl_quit) { LowMemExit(); oslStartDrawing(); oslClearScreen(RGB(0,0,0)); oldpad = pad; sceCtrlReadBufferPositive(&pad, 1); langDisplay(); langControls(); //0 is to used for selecting a font if (strlen(returnMe) > 4) break; oslEndDrawing(); oslEndFrame(); oslSyncFrame(); } return returnMe; }
char * mp3Browse(const char * path) { folderScan(path); dirVars(); while (!osl_quit) { LowMemExit(); oslStartDrawing(); oslClearScreen(RGB(0,0,0)); oldpad = pad; sceCtrlReadBufferPositive(&pad, 1); mp3FileDisplay(); mp3Controls(); if (strlen(returnMe) > 4) break; oslEndDrawing(); oslEndFrame(); oslSyncFrame(); } return returnMe; }
void GWInput_UpdateInputState() { sceCtrlReadBufferPositive(&pad, 1); float x_val = (float)pad.Lx / 255.f; float y_val = (float)pad.Ly / 255.f; psp_axis[GW_PSPAXIS_LX] = GWInput_IsPSPAnalogInsideDeadZone(pad.Lx) ? 0.f : x_val * 2.f - 1.f; psp_axis[GW_PSPAXIS_LY] = GWInput_IsPSPAnalogInsideDeadZone(pad.Ly) ? 0.f : 1.f - y_val * 2.f; SetPSPBtnState(GW_PSPBTN_SQUARE, (pad.Buttons & PSP_CTRL_SQUARE) != 0); SetPSPBtnState(GW_PSPBTN_TRIANGLE, (pad.Buttons & PSP_CTRL_TRIANGLE) != 0); SetPSPBtnState(GW_PSPBTN_CIRCLE, (pad.Buttons & PSP_CTRL_CIRCLE) != 0); SetPSPBtnState(GW_PSPBTN_CROSS, (pad.Buttons & PSP_CTRL_CROSS) != 0); SetPSPBtnState(GW_PSPBTN_UP, (pad.Buttons & PSP_CTRL_UP) != 0); SetPSPBtnState(GW_PSPBTN_DOWN, (pad.Buttons & PSP_CTRL_DOWN) != 0); SetPSPBtnState(GW_PSPBTN_LEFT, (pad.Buttons & PSP_CTRL_LEFT) != 0); SetPSPBtnState(GW_PSPBTN_RIGHT, (pad.Buttons & PSP_CTRL_RIGHT) != 0); SetPSPBtnState(GW_PSPBTN_L, (pad.Buttons & PSP_CTRL_LTRIGGER) != 0); SetPSPBtnState(GW_PSPBTN_R, (pad.Buttons & PSP_CTRL_RTRIGGER) != 0); SetPSPBtnState(GW_PSPBTN_START, (pad.Buttons & PSP_CTRL_START) != 0); SetPSPBtnState(GW_PSPBTN_SELECT, (pad.Buttons & PSP_CTRL_SELECT) != 0); }
void testControllerTimmings() { u64 tick0, tick1; int n; SceCtrlData pad_data; SceCtrlLatch latch; // Test sceCtrlReadBufferPositive sceRtcGetCurrentTick(&tick0); for (n = 0; n < 5; n++) sceCtrlReadBufferPositive(&pad_data, 1); sceRtcGetCurrentTick(&tick1); printf("%d\n", (tick1 - tick0 > 5000)); // Test sceCtrlReadLatch sceRtcGetCurrentTick(&tick0); for (n = 0; n < 5; n++) sceCtrlReadLatch(&latch); sceRtcGetCurrentTick(&tick1); printf("%d\n", (tick1 - tick0 > 5000)); // Test sceCtrlPeekBufferPositive sceRtcGetCurrentTick(&tick0); for (n = 0; n < 5; n++) sceCtrlPeekBufferPositive(&pad_data, 1); sceRtcGetCurrentTick(&tick1); printf("%d\n", (tick1 - tick0 < 5000)); // Test sceCtrlPeekLatch /* sceRtcGetCurrentTick(&tick0); for (n = 0; n < 5; n++) sceCtrlPeekLatch(&pad_data, 1); sceRtcGetCurrentTick(&tick1); printf("%d\n", (tick1 - tick0 < 5000)); */ }
u32 ctrl_read(void) { SceCtrlData ctl; sceCtrlReadBufferPositive(&ctl, 1); if (ctl.Buttons == g_last_btn) { if (ctl.TimeStamp - g_deadzone_tick < CTRL_DEADZONE_DELAY) { return 0; } if (ctl.TimeStamp - g_last_tick < CTRL_DELAY) { return 0; } g_last_tick = ctl.TimeStamp; return g_last_btn; } g_last_btn = ctl.Buttons; g_deadzone_tick = g_last_tick = ctl.TimeStamp; return g_last_btn; }
int playerStart(char *path,pMalloc extern_malloc,pFree extern_free, int(*callback)(int)){ int ret,ch;MODFILE mod; if(!extern_malloc || !extern_free)return -1; if((ch=sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL,PSP_AUDIO_SAMPLE_ALIGN(768),PSP_AUDIO_FORMAT_STEREO))<0)return ch; myMalloc=extern_malloc; myFree =extern_free; MODFILE_Init(&mod); if((ret=MODFILE_Load(path, &mod))<0)return ret; mod.musicvolume = 255; mod.sfxvolume = 255; mod.callback = NULL;//callback; MODFILE_Start(&mod); MODFILE_SetFormat(&mod, 44100, 2,16,1/*unsigned*/); SceCtrlData pad; sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(1); for(int i=0;;i++){ sceCtrlReadBufferPositive(&pad,1); if(pad.Buttons&PSP_CTRL_START)break; mod.mixingbuf =(void*)out[i%2]; mod.mixingbuflen = 768*2*2; MODFILE_Player(&mod); sceAudioOutputBlocking(ch, PSP_AUDIO_VOLUME_MAX,out[i%2]); } MODFILE_Stop(&mod); MODFILE_Free(&mod); sceAudioChRelease(ch); return 0; }
// Handle keys void HandleKeys() { SceCtrlData pad; sceCtrlReadBufferPositive(&pad, 1); JoystickAxisEvent(0, ((int)pad.Lx - 128) * 256); JoystickAxisEvent(1, ((int)pad.Ly - 128) * 256); JoystickBitsEvent(pad.Buttons); }
static int Controls_read(lua_State *L) { int argc = lua_gettop(L); if(argc) return luaL_error(L, "Argument error: Controls.read() cannot be called from an instance."); Controls* pad = pushControls(L); sceCtrlReadBufferPositive(pad, 1); return 1; }
void kbd_wait_start(void) { while (1) { SceCtrlData c; sceCtrlReadBufferPositive(&c, 1); if (c.Buttons & PSP_CTRL_START) break; } }
void hcMiscWaitForAnyButton( void ) { int btn; SceCtrlData pad; sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL); btn=1; while( btn != 0 ) { sceCtrlReadBufferPositive( &pad, 1 ); btn = pad.Buttons & 0xFFFF; } btn=0; while( btn == 0 ) { sceCtrlReadBufferPositive( &pad, 1 ); btn = pad.Buttons & 0xFFFF; } }
void ExceptionHandler(PspDebugRegBlock * regs) { int i; SceCtrlData pad; pspDebugScreenInit(); pspDebugScreenSetBackColor(0x00FF0000); pspDebugScreenSetTextColor(0xFFFFFFFF); pspDebugScreenClear(); pspDebugScreenPrintf("Your PSP has just crashed!\n"); pspDebugScreenPrintf("Exception details:\n\n"); pspDebugScreenPrintf("Exception - %s\n", codeTxt[(regs->cause >> 2) & 31]); pspDebugScreenPrintf("EPC - %08X / %s.text + %08X\n", (int)regs->epc, module_info.modname, (unsigned int)(regs->epc-(int)&_ftext)); pspDebugScreenPrintf("Cause - %08X\n", (int)regs->cause); pspDebugScreenPrintf("Status - %08X\n", (int)regs->status); pspDebugScreenPrintf("BadVAddr - %08X\n", (int)regs->badvaddr); for(i=0; i<32; i+=4) pspDebugScreenPrintf("%s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int)regs->r[i], regName[i+1], (int)regs->r[i+1], regName[i+2], (int)regs->r[i+2], regName[i+3], (int)regs->r[i+3]); sceKernelDelayThread(1000000); pspDebugScreenPrintf("\n\nPress X to dump information on file exception.log and quit"); pspDebugScreenPrintf("\nPress O to quit"); for (;;){ sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_CROSS){ char filename[MAX_FILE]; sprintf(filename, "%s/exception.log", main_path); FILE *log = fopen(filename, "w"); if (log != NULL){ char testo[512]; sprintf(testo, "Exception details:\n\n"); fwrite(testo, 1, strlen(testo), log); sprintf(testo, "Exception - %s\n", codeTxt[(regs->cause >> 2) & 31]); fwrite(testo, 1, strlen(testo), log); sprintf(testo, "EPC - %08X / %s.text + %08X\n", (int)regs->epc, module_info.modname, (unsigned int)(regs->epc-(int)&_ftext)); fwrite(testo, 1, strlen(testo), log); sprintf(testo, "Cause - %08X\n", (int)regs->cause); fwrite(testo, 1, strlen(testo), log); sprintf(testo, "Status - %08X\n", (int)regs->status); fwrite(testo, 1, strlen(testo), log); sprintf(testo, "BadVAddr - %08X\n", (int)regs->badvaddr); fwrite(testo, 1, strlen(testo), log); for(i=0; i<32; i+=4){ sprintf(testo, "%s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int)regs->r[i], regName[i+1], (int)regs->r[i+1], regName[i+2], (int)regs->r[i+2], regName[i+3], (int)regs->r[i+3]); fwrite(testo, 1, strlen(testo), log); } fclose(log); } break; }else if (pad.Buttons & PSP_CTRL_CIRCLE){
// Print out an error message and quit after user input void error( char* msg ) { SceCtrlData pad; pspDebugScreenClear(); pspDebugScreenSetXY(0, 0); printf(msg); printf("Press X to quit.\n"); while (isrunning) { sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_CROSS) break; sceDisplayWaitVblankStart(); } sceKernelExitGame(); }
int kstuffGetKCtrl( void ) { int btn; SceCtrlData pad; int k; k = pspSdkSetK1(0); sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL); sceCtrlReadBufferPositive( &pad, 1 ); btn = pad.Buttons; pspSdkSetK1(k); return btn; }
unsigned int psp_pad_read(int blocking) { unsigned int buttons; SceCtrlData pad; if (blocking) sceCtrlReadBufferPositive(&pad, 1); else sceCtrlPeekBufferPositive(&pad, 1); buttons = pad.Buttons; // analog.. buttons &= ~(BTN_NUB_UP|BTN_NUB_DOWN|BTN_NUB_LEFT|BTN_NUB_RIGHT); if (pad.Lx < 128 - ANALOG_DEADZONE) buttons |= BTN_NUB_LEFT; if (pad.Lx > 128 + ANALOG_DEADZONE) buttons |= BTN_NUB_RIGHT; if (pad.Ly < 128 - ANALOG_DEADZONE) buttons |= BTN_NUB_UP; if (pad.Ly > 128 + ANALOG_DEADZONE) buttons |= BTN_NUB_DOWN; return buttons; }
void gbControl :: update() { SceCtrlData entry; sceCtrlReadBufferPositive(&entry, 1); if(entry.Buttons) pressed = 1; if(get) { if(entry.Buttons) { this->flush(); if(entry.Buttons & PSP_CTRL_CROSS) ctrl.cross = 1; if(entry.Buttons & PSP_CTRL_CIRCLE) ctrl.circle = 1; if(entry.Buttons & PSP_CTRL_SQUARE) ctrl.square = 1; if(entry.Buttons & PSP_CTRL_TRIANGLE) ctrl.triangle = 1; if(entry.Buttons & PSP_CTRL_LTRIGGER) ctrl.ltrigger = 1; if(entry.Buttons & PSP_CTRL_RTRIGGER) ctrl.rtrigger = 1; if(entry.Buttons & PSP_CTRL_START) ctrl.start = 1; if(entry.Buttons & PSP_CTRL_SELECT) ctrl.select = 1; if(entry.Buttons & PSP_CTRL_UP) ctrl.up = 1; if(entry.Buttons & PSP_CTRL_DOWN) ctrl.down = 1; if(entry.Buttons & PSP_CTRL_LEFT) ctrl.left = 1; if(entry.Buttons & PSP_CTRL_RIGHT) ctrl.right = 1; //pressed = 1; get = wait = 0; }; if(!entry.Buttons) { pressed = 0; get = 1; }; ctrl.xstick = entry.Lx; ctrl.ystick = entry.Ly; } else { if(wait<wait_time) { wait++; this->flush(); } else get = 1; if(!entry.Buttons) get = 1; }; };
//pauses the game // // // // void Pause(Image* theme0,Image* theme1) {SceCtrlData pad; int timer = 0; Color White = RGB(255, 255, 255); Color Black = RGB(0, 0, 0); while(1) { sceCtrlReadBufferPositive(&pad, 1); timer++; if (pad.Buttons & PSP_CTRL_START) { timer++; if (timer > 14) { break; } } if (pad.Buttons & PSP_CTRL_TRIANGLE) { timer++; if (timer > 14) { break; } } if (timer == 14) {timer = 0; } fillScreenRect(Black, 0, 0, 480, 272); blitAlphaImageToScreen(0, 0, 90, 272, theme0, 0, 0); blitAlphaImageToScreen(0, 0, 90, 272, theme1, 390, 0); if (timer < 7) { printTextScreen(210, 130, "PAUSE", White); } if (timer > 7) { printTextScreen(210, 130, "PAUSE", Black); } sceDisplayWaitVblankStart(); flipScreen(); }}
static int pad_read(void) { SceCtrlData pad; sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & SCE_CTRL_UP) { GameEngine::instance()->controls[2] = 1; }else{ GameEngine::instance()->controls[2] = 0; } if (pad.Buttons & SCE_CTRL_DOWN) { GameEngine::instance()->controls[3] = 1; }else{ GameEngine::instance()->controls[3] = 0; } if (pad.Buttons & SCE_CTRL_LEFT) { GameEngine::instance()->controls[0] = 1; }else{ GameEngine::instance()->controls[0] = 0; } if (pad.Buttons & SCE_CTRL_RIGHT) { GameEngine::instance()->controls[1] = 1; }else{ GameEngine::instance()->controls[1] = 0; } if (pad.Buttons & SCE_CTRL_CROSS) { GameEngine::instance()->controls[5] = 1; }else{ GameEngine::instance()->controls[5] = 0; } /*if (pad.Buttons & SCE_CTRL_CIRCLE) printf("You pressed circle\n"); if (pad.Buttons & SCE_CTRL_SQUARE) printf("You pressed square\n"); if (pad.Buttons & SCE_CTRL_TRIANGLE) printf("You pressed triangle\n");*/ if (pad.Buttons & SCE_CTRL_START) return 0; return 1; }
int main(int argc, char *argv[]) { SceCtrlData pad; char *dir, *slash; pspDebugScreenInit(); pspDebugScreenClear(); printf("Testing HBL\n\n"); testFreeRam(); testFrequencies(); testMd5(); dir = argv[0]; if (dir == NULL) { puts("error: argv[0] == NULL"); goto skipDread; } slash = strrchr(dir, '/'); if (slash == NULL) { printf("error: no slash in argv[0]: %s\n", dir); goto skipDread; } *slash = 0; testIoDread(dir); skipDread: printf("\nPress X to exit\n\n"); do { sceCtrlReadBufferPositive(&pad, 1); } while(!(pad.Buttons & PSP_CTRL_CROSS)); printf("Exiting...\n"); sceKernelExitGame(); return 0; }
int main(void) { SceCtrlData pad; pspDebugScreenInit(); SetupCallbacks(); /* Install our custom exception handler. If this was NULL then the default would be used */ pspDebugInstallErrorHandler(MyExceptionHandler); sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL); pspDebugScreenPrintf("Exception Sample\n\n"); pspDebugScreenPrintf("You have two choices, press O for a bus error or X for a breakpoint\n\n"); while(1) { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons & PSP_CTRL_CIRCLE) { /* Cause a bus error */ _sw(0, 0); } if(pad.Buttons & PSP_CTRL_CROSS) { /* Cause a break exception */ asm( "break\r\n" ); } sceDisplayWaitVblankStart(); } /* We will never end up here, hopefully */ printf("End\n"); sceKernelExitDeleteThread(0); return 0; }
void test_end() { fflush(stdout); fflush(stderr); fclose(stdout); fclose(stderr); if (!RUNNING_ON_EMULATOR) { SceCtrlData key; while (1) { sceCtrlReadBufferPositive(&key, 1); if (key.Buttons & PSP_CTRL_CROSS) break; } } //fclose(stdout); sceKernelExitGame(); exit(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; }
int main(int argc, char *argv[]) { SceCtrlData ctl; pspDebugScreenInit(); sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL); /* Copy our small program into the ME reset vector */ memcpy((void *)0xbfc00040, me_run, (int)(me_end - me_run)); sceKernelDcacheWritebackInvalidateAll(); sceSysregMeResetEnable(); sceSysregMeBusClockEnable(); sceSysregMeResetDisable(); sceSysregVmeResetDisable(); while(1) { volatile u32 *count = (u32*) 0xBFC00060; pspDebugScreenSetXY(0, 0); pspDebugScreenPrintf("ME Basic Example, press Home to exit\n"); sceKernelDcacheWritebackInvalidateAll(); pspDebugScreenPrintf("ME Counter: %08x\n", *count); sceCtrlReadBufferPositive(&ctl, 1); if(ctl.Buttons & PSP_CTRL_HOME) { sceKernelExitGame(); } sceDisplayWaitVblankStart(); } return 0; }