Padctrl. cpp
# Include <pspkernel. h>
# Include <pspdebug. h>
# Include <pspdisplay. h>
# Include <pspctrl. h>
# Include <iostream>
Psp_module_info ("Hello World", 0, 1, 1 );
# Define printf pspdebugscreenprintf
Using namespace STD;
/* Exit callback */
Int exit_callback (INT arg1, int arg2, void * Common ){
Scekernelexitgame ();
Return 0;
}
/* Callback thread */
Int callbackthread (scesize ARGs, void * argp ){
Int CBID;
// Create callback
CBID = scekernelcreatecallback ("Exit callback", exit_callback, null );
Scekernelregisterexitcallback (CBID );
// Sleep thread but service any callbacks as necessary.
Scekernelsleepthreadcb ();
Return 0;
}
/* Sets up the callback thread and returns its thread ID */
Int setupcallbacks (){
Int thid = 0;
// Create a thread.
Thid = scekernelcreatethread ("update_thread", callbackthread, 0x11, 0xfa0, 0, 0 );
If (thid> = 0 ){
// Start a created thread.
Scekernelstartthread (thid, 0, 0 );
}
Return thid;
}
Int main (INT argc, char ** argv)
{
// Initialise the debug screen.
Pspdebugscreeninit ();
// Setup callback;
Setupcallbacks ();
// Press the struct button.
Scectrldata pad;
Printf ("Press [x] to start the timer ");
While (1)
{
// Read buffer positive.
Scectrlreadbufferpositive (& pad, 1 );
If (pad. Buttons & psp_ctrl_cross)
{
Printf ("You pressed X ");
Break;
}
// Clear screen
Pspdebugscreenclear ();
}
// Sleep thread
Scekernelsleepthread ();
Return 0;
}
Makefile
Target = padctrl
Objs = padctrl. o
Build_prx = 1
Psp_fw_version = 371
# C compiler Parameters
Cflags =-O2-G0-wall
# C ++ compiler Parameters
Cxxflags = $ (cflags)-fno-exceptions-fno-rtti
# Compile compiler Parameters
Asflags = $ (cflags)
# Reference Library-l stdc ++
Libs =-lstdc ++
Extra_targets = eboot. pbp
Psp_eboot_title = pad Control
Pspsdk = $ (shell PSP-config -- pspsdk-path)
Include $ (pspsdk)/lib/build. Mak
Button Enumeration
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_home |
Home button. |
Psp_ctrl_hold |
Hold button. |
Psp_ctrl_note |
Music note button. |
A while (1) button is required to receive system events.
Then, use scectrlreadbufferpositive (& pad, 1); To read the key content.