### Custom Profiling with gprof Runtime Functions Source: https://github.com/pspdev/pspsdk/blob/master/src/samples/gprof/custom/README.md This example demonstrates how to profile specific sections of your code. It involves stopping default profiling (if any) using `gprof_stop(NULL, false)`, starting custom profiling with `gprof_start()`, and then stopping it with `gprof_stop("gmon_custom.out", true)` to save results to a specified file. The `true` parameter ensures the output is written upon program termination. ```c gprof_stop(NULL, false); // ... code to discard initial profiling data ... gprof_start(); // ... your specific code section to profile ... gprof_stop("gmon_custom.out", true); ``` -------------------------------- ### Enabling gprof Profiling with Compiler Flags Source: https://github.com/pspdev/pspsdk/blob/master/src/samples/gprof/custom/README.md To enable the gprof profiling feature, you need to add the `-g` and `-pg` flags to both your CFLAGS (compiler flags) and LDFLAGS (linker flags) when building your project. This ensures that profiling information is collected during execution. ```makefile CFLAGS += -g -pg LDFLAGS += -g -pg ``` -------------------------------- ### Analyzing gprof Output with psp-gprof Source: https://github.com/pspdev/pspsdk/blob/master/src/samples/gprof/custom/README.md After your program has run and generated the profiling data file (e.g., `gmon_custom.out`), you can analyze it using the `psp-gprof` binary. This command-line tool takes the compiled ELF binary and the generated output file as arguments. The `-b` flag provides a flat profile view. ```bash psp-gprof -b {binary.elf} {gmon_custom.out} # Example: psp-gprof -b gprofcustom.elf gmon_custom.out ``` -------------------------------- ### Create and Manage Threads (C) Source: https://context7.com/pspdev/pspsdk/llms.txt Demonstrates creating and managing threads in the PSP environment. This includes setting up a callback thread for system events (like exiting the game) and starting a worker thread for background processing. Proper stack sizes and priorities are important for thread stability. ```c #include #include int done = 0; // Exit callback function int exitCallback(int arg1, int arg2, void *common) { done = 1; sceKernelExitGame(); return 0; } // Callback thread that waits for system callbacks int callbackThread(SceSize args, void *argp) { int cbid; // Create and register exit callback cbid = sceKernelCreateCallback("Exit Callback", exitCallback, NULL); sceKernelRegisterExitCallback(cbid); // Sleep until callback is triggered sceKernelSleepThreadCB(); return 0; } int setupCallbacks(void) { int thid; // Create callback thread with priority 0x11 thid = sceKernelCreateThread("callback_thread", callbackThread, 0x11, // Priority 0xFA0, // Stack size 0, // Attributes 0); // Options if (thid >= 0) { sceKernelStartThread(thid, 0, 0); } return thid; } // Worker thread example int workerThread(SceSize args, void *argp) { while (!done) { // Perform background work processData(); // Delay for 16ms (~60fps) sceKernelDelayThread(16000); } return 0; } void startWorkerThread(void) { int thid = sceKernelCreateThread("worker", workerThread, 0x18, // Lower priority 0x10000, // 64KB stack THREAD_ATTR_USER, NULL); if (thid >= 0) { sceKernelStartThread(thid, 0, NULL); } } ``` -------------------------------- ### Initialize Network and Make HTTP Request (C) Source: https://context7.com/pspdev/pspsdk/llms.txt Initializes the PSP's network stack and performs HTTP GET requests. Requires network modules like pspnet and psphttp. Takes a URL and buffer for response, returning bytes read or an error code. ```c #include #include #include #include #include int initNetwork(void) { int err; // Load network modules sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON); sceUtilityLoadNetModule(PSP_NET_MODULE_INET); // Initialize network err = sceNetInit(128*1024, 42, 4*1024, 42, 4*1024); if (err < 0) return err; err = sceNetInetInit(); if (err < 0) return err; err = sceNetApctlInit(0x10000, 48); if (err < 0) return err; // Connect to access point err = sceNetApctlConnect(1); // Connection config 1 if (err < 0) return err; // Wait for connection int state; do { err = sceNetApctlGetState(&state); sceKernelDelayThread(50000); } while (state != PSP_NET_APCTL_STATE_GOT_IP); return 0; } int httpGetRequest(const char* url, char* buffer, int bufSize) { int err, tmpl, conn, req; unsigned int contentLength = 0; // Initialize HTTP sceHttpInit(20000); // Create template tmpl = sceHttpCreateTemplate("PSP HTTP Client", 1, 1); // Create connection conn = sceHttpCreateConnectionWithURL(tmpl, url, 0); // Create request req = sceHttpCreateRequestWithURL(conn, PSP_HTTP_METHOD_GET, url, 0); // Send request err = sceHttpSendRequest(req, NULL, 0); if (err < 0) goto cleanup; // Get content length sceHttpGetContentLength(req, &contentLength); // Read response int bytesRead = sceHttpReadData(req, buffer, bufSize - 1); if (bytesRead > 0) { buffer[bytesRead] = '\0'; } cleanup: sceHttpDeleteRequest(req); sceHttpDeleteConnection(conn); sceHttpDeleteTemplate(tmpl); sceHttpEnd(); return bytesRead; } ``` -------------------------------- ### Monitor and Control Power State (C) Source: https://context7.com/pspdev/pspsdk/llms.txt Provides functions to display battery information and set power management settings on the PSP. It utilizes psppower and pspdisplay libraries to access battery status and control clock frequencies. Functions include getting battery percentage, life time, temperature, and controlling CPU/bus speeds. ```c #include #include void displayBatteryInfo(void) { int batteryPercent, batteryLifeTime, batteryTemp; int pluggedIn, batteryCharging, batteryLowBattery; // Get battery percentage (0-100) batteryPercent = scePowerGetBatteryLifePercent(); // Get remaining battery time in minutes batteryLifeTime = scePowerGetBatteryLifeTime(); // Get battery temperature in degrees Celsius batteryTemp = scePowerGetBatteryTemp(); // Check power status pluggedIn = scePowerIsPowerOnline(); batteryCharging = scePowerIsBatteryCharging(); batteryLowBattery = scePowerIsLowBattery(); pspDebugScreenPrintf("Battery: %d%%\n", batteryPercent); pspDebugScreenPrintf("Time remaining: %d mins\n", batteryLifeTime); pspDebugScreenPrintf("Temperature: %d C\n", batteryTemp); pspDebugScreenPrintf("Status: %s%s\n", pluggedIn ? "Plugged In " : "", batteryCharging ? "Charging" : ""); } void setPowerSettings(void) { // Set CPU and bus clock speeds (MHz) // Default: 222 MHz CPU, 111 MHz Bus // Max: 333 MHz CPU, 166 MHz Bus scePowerSetClockFrequency(333, 333, 166); // Set CPU speed alone (bus speed adjusted automatically) scePowerSetCpuClockFrequency(266); // Lock power switch to prevent accidental sleep scePowerLock(0); // Unlock when done scePowerUnlock(0); // Request standby mode // scePowerRequestStandby(); // Request suspend mode // scePowerRequestSuspend(); } ``` -------------------------------- ### PSP Build Tool: Package Application to PBP Source: https://context7.com/pspdev/pspsdk/llms.txt Uses pack-pbp to create EBOOT.PBP executable packages. This command bundles various application assets, including metadata, icons, and the main executable, into the PSP's executable format. The unpack-pbp command can be used to extract files from an existing PBP archive. ```bash # Pack application into EBOOT.PBP format pack-pbp EBOOT.PBP \ PARAM.SFO \ ICON0.PNG \ NULL \ PIC1.PNG \ NULL \ NULL \ EBOOT.ELF \ NULL # EBOOT.PBP structure: # - PARAM.SFO: Application metadata # - ICON0.PNG: Icon displayed in XMB (144x80) # - ICON1.PMF: Animated icon (optional) # - PIC0.PNG: Background image (480x272) (optional) # - PIC1.PNG: Preview image (480x272) # - SND0.AT3: Background music (optional) # - DATA.PSP: Data file (optional) # - EBOOT.ELF: Compiled executable (required) # - DATA.PSAR: Additional data archive (optional) # Extract files from existing PBP: unpack-pbp EBOOT.PBP ``` -------------------------------- ### PSP Build Tool: Create SFO Metadata Source: https://context7.com/pspdev/pspsdk/llms.txt Generates PARAM.SFO files required for PSP applications using the mksfo or mksfoex tool. These files contain essential metadata such as application title, category, disc ID, and required firmware version. ```bash # Create SFO with application title mksfo "My PSP Game" PARAM.SFO # The generated PARAM.SFO contains metadata: # - TITLE: Application name shown in XMB # - CATEGORY: MG (Memory Stick Game) # - DISC_ID: Application identifier # - BOOTABLE: Set to 1 # - PSP_SYSTEM_VER: Required firmware version # For more control over SFO parameters, use mksfoex: mksfoex -d MEMSIZE=1 \ -d DISC_ID=UCJS10041 \ -d DISC_VERSION=1.00 \ -d PSP_SYSTEM_VER=3.52 \ "My Game Title" \ PARAM.SFO ``` -------------------------------- ### PRIM - Primitive Kick Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Kicks off primitive rendering with specified vertex count and type. ```APIDOC ## PRIM - Primitive Kick ### Description Primitive Kick. Initiates the rendering of primitives with a specified number of vertices and primitive type. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **argument** (integer) - Required - 0-15: Number of vertices to kick (0-65535) - 16-18: Primitive Type: - 000: Points - 001: Lines - 010: Line Strips - 011: Triangles - 100: Triangle Strips - 101: Triangle Fans - 110: Sprites (2D Rectangles) ``` -------------------------------- ### GE Command Format Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Explains the structure of GE commands, which consist of an 8-bit command and a 24-bit argument. ```APIDOC ## GE Command Format Each command word is divided into two parts: an 8-bit command and a 24-bit argument. The command is in the upper part of the word, and the argument is in the lower. ### GE Floats Floats processed in the command-stream are 24 bits instead of the 32 bits used by the CPU. Conversion from 32 to 24 bits is done by shifting the value down 8 bits, losing the least significant bits of the mantissa. ### Pointers Some pointers use a shared register when loading addresses called BASE. This register must be written BEFORE you write to the designated register. All these registers are marked with (BASE) after the summary. Other pointers only use 28 bits of information, and their top bits are referred to as the '4 most significant bits' in pointer, which reflects bits 24-27, not 28-31 which could perhaps be believed from common terminology. ### Enabling Registers Any command or bit that has 'Enable' in the name implies that setting the first bit (or the bit itself) enables the feature, and no ON/OFF-states are documented. **DISCLAIMER:** Names and bitsets are all derived from reverse engineering, available PS2 documentation and educated guesses. Nothing has been derived using illegal methods. ``` -------------------------------- ### BEZIER - Bezier Patch Kick Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Initiates Bezier patch rendering with U and V counts. ```APIDOC ## BEZIER - Bezier Patch Kick ### Description Bezier Patch Kick. Initiates the rendering of Bezier patches. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **argument** (integer) - Required - 0-7: U Count - 8-15: V Count ``` -------------------------------- ### PSP Build Tool: Build PRX Relocatable Modules Source: https://context7.com/pspdev/pspsdk/llms.txt Creates PRX (Plugin Relocatable Executable) modules, which can be loaded dynamically or used as shared libraries by PSP applications. This process involves compiling with specific flags, linking, generating the PRX file, fixing imports to optimize the module, and optionally building an exports table for library usage. ```bash # Compile with PRX flags psp-gcc -c module.c -o module.o -G0 # Link as PRX psp-gcc -o module.elf module.o \ -Wl,-q,-T$(psp-config --pspsdk-path)/lib/linkfile.prx \ -specs=$(psp-config --pspsdk-path)/lib/prxspecs # Generate PRX file psp-prxgen module.elf module.prx # Fix imports to remove unused functions psp-fixup-imports module.prx # Build exports table for library PRX psp-build-exports -b module.c > exports.exp ``` -------------------------------- ### Initialize Graphics Utility (GU) and Draw Primitives Source: https://context7.com/pspdev/pspsdk/llms.txt Initializes the PSP's Graphics Utility (GU) library for rendering 2D and 3D graphics. It sets up display buffers, viewports, and enables features like blending and depth testing. This function also demonstrates drawing basic colored triangles. ```c #include #include #include #include #define BUF_WIDTH 512 #define SCR_WIDTH 480 #define SCR_HEIGHT 272 static unsigned int __attribute__((aligned(16))) list[262144]; static void *fbp0 = (void*)(0x40000000 | 0); static void *fbp1 = (void*)(0x40000000 | (BUF_WIDTH * SCR_HEIGHT * 2)); static void *zbp = (void*)(0x40000000 | (BUF_WIDTH * SCR_HEIGHT * 4)); typedef struct { float u, v; unsigned int color; float x, y, z; } Vertex; void initGU(void) { // Initialize GU system sceGuInit(); // Setup display buffers sceGuStart(GU_DIRECT, list); sceGuDrawBuffer(GU_PSM_8888, fbp0, BUF_WIDTH); sceGuDispBuffer(SCR_WIDTH, SCR_HEIGHT, fbp1, BUF_WIDTH); sceGuDepthBuffer(zbp, BUF_WIDTH); // Set viewport and offset sceGuOffset(2048 - (SCR_WIDTH/2), 2048 - (SCR_HEIGHT/2)); sceGuViewport(2048, 2048, SCR_WIDTH, SCR_HEIGHT); sceGuDepthRange(65535, 0); // Set scissor region sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT); sceGuEnable(GU_SCISSOR_TEST); // Enable depth test sceGuDepthFunc(GU_GEQUAL); sceGuEnable(GU_DEPTH_TEST); // Setup blending for transparency sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuFinish(); sceGuSync(0, 0); sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); } void renderFrame(void) { sceGuStart(GU_DIRECT, list); // Clear screen sceGuClearColor(0xff554433); sceGuClearDepth(0); sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT); // Draw triangles Vertex vertices[3] = { {0, 0, 0xffff0000, 100, 100, 0}, // Red vertex {0, 0, 0xff00ff00, 200, 100, 0}, // Green vertex {0, 0, 0xff0000ff, 150, 200, 0} // Blue vertex }; sceGuDrawArray(GU_TRIANGLES, GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 3, 0, vertices); sceGuFinish(); sceGuSync(0, 0); sceDisplayWaitVblankStart(); sceGuSwapBuffers(); } ``` -------------------------------- ### SPLINE - Spline Surface Kick Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Initiates Spline surface rendering with U/V counts and edge settings. ```APIDOC ## SPLINE - Spline Surface Kick ### Description Spline Surface Kick. Initiates the rendering of Spline surfaces. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **argument** (integer) - Required - 0-7: U Count - 8-15: V Count - 16-17: U Edges: - 00: Close/Close - 01: Open/Close - 10: Close/Open - 11: Open/Open - 18-19: V Edges: - 00: Close/Close - 01: Open/Close - 10: Close/Open - 11: Open/Open ``` -------------------------------- ### PSP File Operations: Read, Write, and List Directories Source: https://context7.com/pspdev/pspsdk/llms.txt Performs file operations using the PSP file I/O API. Includes functions for reading file content into a buffer, writing data from a buffer to a file, and listing directory contents with file/directory differentiation. Requires pspiofilemgr.h, pspkernel.h, and string.h. ```c #include #include #include int readFile(const char* path, void* buffer, int maxSize) { int fd, bytesRead; // Open file for reading fd = sceIoOpen(path, PSP_O_RDONLY, 0777); if (fd < 0) { return -1; // Error opening file } // Read file contents bytesRead = sceIoRead(fd, buffer, maxSize); // Close file sceIoClose(fd); if (bytesRead < 0) { return -1; // Error reading } return bytesRead; } int writeFile(const char* path, const void* data, int size) { int fd, bytesWritten; // Open file for writing (create if doesn't exist) fd = sceIoOpen(path, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); if (fd < 0) { return -1; } // Write data bytesWritten = sceIoWrite(fd, data, size); sceIoClose(fd); return bytesWritten; } int listDirectory(const char* path) { int dfd; SceIoDirent entry; // Open directory dfd = sceIoDopen(path); if (dfd < 0) { return -1; } // Read directory entries memset(&entry, 0, sizeof(SceIoDirent)); while (sceIoDread(dfd, &entry) > 0) { if (FIO_S_ISDIR(entry.d_stat.st_mode)) { // Entry is a directory pspDebugScreenPrintf("[DIR] %s\n", entry.d_name); } else { // Entry is a file pspDebugScreenPrintf("[FILE] %s (%d bytes)\n", entry.d_name, (int)entry.d_stat.st_size); } memset(&entry, 0, sizeof(SceIoDirent)); } sceIoDclose(dfd); return 0; } ``` -------------------------------- ### Load and Display Textures Source: https://context7.com/pspdev/pspsdk/llms.txt Loads texture data from a file and applies it to rendered geometry. It configures texture parameters such as mode, image, function, filtering, and wrapping. This snippet demonstrates rendering a textured quad. ```c #include #include #include void* loadTexture(const char* filename, int* width, int* height) { // Texture must be aligned to 16 bytes void* texture = memalign(16, 256 * 256 * 4); // Load texture data from file (simplified) FILE* fp = fopen(filename, "rb"); if (fp) { fread(texture, 1, 256 * 256 * 4, fp); fclose(fp); *width = 256; *height = 256; } return texture; } void renderTexturedQuad(void* texture, int texWidth, int texHeight) { typedef struct { float u, v; float x, y, z; } TexVertex; sceGuStart(GU_DIRECT, list); // Setup texture sceGuTexMode(GU_PSM_8888, 0, 0, 0); // Format, max mipmaps, multiclut, swizzle sceGuTexImage(0, texWidth, texHeight, texWidth, texture); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); // Texture function and components sceGuTexFilter(GU_LINEAR, GU_LINEAR); // Min/mag filter sceGuTexWrap(GU_REPEAT, GU_REPEAT); // U/V wrap mode sceGuEnable(GU_TEXTURE_2D); // Define textured quad vertices TexVertex vertices[2] = { {0, 0, 100, 100, 0}, // Top-left with UV (0,0) {1, 1, 300, 300, 0} // Bottom-right with UV (1,1) }; sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, vertices); sceGuDisable(GU_TEXTURE_2D); sceGuFinish(); sceGuSync(0, 0); } ``` -------------------------------- ### PSP Build Tool: Convert Binary Data to C Arrays Source: https://context7.com/pspdev/pspsdk/llms.txt Converts binary files into C source code arrays, enabling direct embedding of assets like textures or data into your PSP application. Supports conversion to C arrays with size variables, object files, or assembly code. The generated code can then be referenced using 'extern' declarations. ```bash # Convert binary file to C source bin2c texture.png texture.c texture_name # Generated texture.c contains: # unsigned char texture_name[] = { 0x89, 0x50, 0x4E, 0x47, ... }; # size_t texture_name_size = 12345; # Convert to object file directly: bin2o image.jpg image.o image_data # Convert to assembly: bin2s data.bin data.s data_array # Usage in your code: # extern unsigned char texture_name[]; # extern size_t texture_name_size; ``` -------------------------------- ### FINISH - Complete Rendering Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Completes the current rendering operation and provides a finish signal argument. ```APIDOC ## FINISH - Complete Rendering ### Description Complete Rendering. Signals the completion of the current rendering process and can include a finish signal argument. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **argument** (integer) - Required - 0-15: Finish signal argument. ``` -------------------------------- ### Reserve Audio Channel and Output PCM Data (C) Source: https://context7.com/pspdev/pspsdk/llms.txt Reserves a hardware audio channel, generates PCM audio samples for a sine wave, and outputs them. It handles channel reservation, sample generation, blocking output, and channel release. Ensure sample buffer size matches SAMPLE_COUNT. ```c #include #include #include #include #define SAMPLE_COUNT 1024 #define SAMPLE_RATE 44100 typedef struct { short left; short right; } StereoSample; int setupAudio(void) { // Reserve audio channel // Returns channel number (0-7) or error code int channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, SAMPLE_COUNT, PSP_AUDIO_FORMAT_STEREO); if (channel < 0) { // Error: failed to reserve channel return -1; } return channel; } void playAudioSamples(int channel) { // Allocate sample buffer (must be sample_count size) StereoSample* samples = (StereoSample*)malloc(SAMPLE_COUNT * sizeof(StereoSample)); if (!samples) { return; } // Generate 440Hz sine wave float frequency = 440.0f; for (int i = 0; i < SAMPLE_COUNT; i++) { float time = (float)i / SAMPLE_RATE; float amplitude = sinf(2.0f * 3.14159f * frequency * time); short sample = (short)(amplitude * 16000); // Scale to 16-bit range samples[i].left = sample; samples[i].right = sample; } // Output audio (blocking - waits until samples are played) int result = sceAudioOutputBlocking(channel, PSP_AUDIO_VOLUME_MAX, samples); if (result < 0) { // Error occurred } free(samples); } void cleanupAudio(int channel) { // Release audio channel when done sceAudioChRelease(channel); } ``` -------------------------------- ### JUMP - Jump To New Address Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Jumps execution to a new address. Requires BASE register to be set first. ```APIDOC ## JUMP - Jump To New Address ### Description Jump To New Address (BASE). Transfers execution to a specified address. The BASE register must be written before this command. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **argument** (integer) - Required - 0-23: 24 least significant bits of the pointer. ``` -------------------------------- ### BBOX - Bounding Box Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Sets the bounding box for conditional rendering. ```APIDOC ## BBOX - Bounding Box ### Description Bounding Box. Sets the number of vertices to test for conditional rendering. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **argument** (integer) - Required - 0-15: Number of vertices to test for conditional rendering (0-65535). ``` -------------------------------- ### Variable Sample Rate Audio Output (C) Source: https://context7.com/pspdev/pspsdk/llms.txt Utilizes an SRC (Sample Rate Conversion) channel for flexible audio playback rates. This function reserves an SRC channel with a specified sample rate and allows for non-blocking audio output. Supported sample rates are listed in the documentation. ```c #include int setupFlexibleAudio(int sampleRate) { // Reserve SRC channel with custom sample rate // Supported rates: 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11050, 8000 int result = sceAudioSRCChReserve(512, sampleRate, 2); if (result < 0) { return -1; // Error codes defined in SCE_AUDIO_ERROR_* } return 0; } void playFlexibleAudio(void* pcmData) { // Output audio with volume control (0 to PSP_AUDIO_VOLUME_MAX) int volume = PSP_AUDIO_VOLUME_MAX / 2; // 50% volume sceAudioSRCOutputBlocking(volume, pcmData); } void cleanupFlexibleAudio(void) { sceAudioSRCChRelease(); } ``` -------------------------------- ### Read PSP Controller Button State with PSPSDK Source: https://context7.com/pspdev/pspsdk/llms.txt This code snippet demonstrates how to read the current state of PSP controller buttons and analog stick positions using the sceCtrl API within PSPSDK. It initializes the controller, reads data in a loop, and prints analog stick values and button presses to the debug screen. Dependencies include pspkernel.h, pspctrl.h, and pspdebug.h. ```c #include #include #include PSP_MODULE_INFO("CONTROLTEST", 0, 1, 1); PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU); int main(void) { SceCtrlData pad; pspDebugScreenInit(); // Initialize controller with analog mode sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); while(1) { // Read controller data sceCtrlReadBufferPositive(&pad, 1); // Check analog stick positions (0-255 range, centered at ~128) pspDebugScreenSetXY(0, 0); pspDebugScreenPrintf("Analog X: %3d Y: %3d\n", pad.Lx, pad.Ly); // Check button presses using bitwise operations if (pad.Buttons & PSP_CTRL_CROSS) { pspDebugScreenPrintf("Cross button pressed\n"); } if (pad.Buttons & PSP_CTRL_TRIANGLE) { pspDebugScreenPrintf("Triangle button pressed\n"); } if (pad.Buttons & PSP_CTRL_LTRIGGER) { pspDebugScreenPrintf("L-Trigger pressed\n"); } sceDisplayWaitVblankStart(); } sceKernelExitGame(); return 0; } ``` -------------------------------- ### BJUMP - Conditional Jump Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Conditionally jumps execution to a new address. Requires BASE register to be set first. ```APIDOC ## BJUMP - Conditional Jump ### Description Conditional Jump (BASE). Transfers execution to a specified address if a condition is met. The BASE register must be written before this command. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **argument** (integer) - Required - 0-23: 24 least significant bits of the pointer. ``` -------------------------------- ### Detect PSP Button State Changes with Latch using PSPSDK Source: https://context7.com/pspdev/pspsdk/llms.txt This C code snippet utilizes the `sceCtrlReadLatch` function from PSPSDK to detect precise button press and release transitions. It differentiates between buttons being newly pressed (`uiMake`), currently held down (`uiPress`), newly released (`uiBreak`), or currently released (`uiRelease`). This allows for distinct actions on button events rather than just continuous state checks. Dependencies include pspkernel.h, pspctrl.h, and pspdisplay.h. ```c #include #include #include int main(void) { SceCtrlLatch latchData; sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); while(1) { // Read latch data to detect state transitions sceCtrlReadLatch(&latchData); // Check if Cross button was just pressed (transition: released -> pressed) if (latchData.uiMake & PSP_CTRL_CROSS) { // Execute action once on button press performAction(); } // Check if button is currently held down if (latchData.uiPress & PSP_CTRL_SQUARE) { // Execute action while button is held continuousAction(); } // Check if Triangle was just released (transition: pressed -> released) if (latchData.uiBreak & PSP_CTRL_TRIANGLE) { // Execute action once on button release onRelease(); } // Check if Circle is currently released if (latchData.uiRelease & PSP_CTRL_CIRCLE) { // Button is not pressed } sceDisplayWaitVblankStart(); } return 0; } ``` -------------------------------- ### NOP - No Operation Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt The NOP command performs no operation. ```APIDOC ## NOP - No Operation ### Description No Operation. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "command": 0, "argument": 0 } ``` ### Response #### Success Response (200) None (operation is null) #### Response Example None ``` -------------------------------- ### RET - Return From Call Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Returns from a subroutine call. ```APIDOC ## RET - Return From Call ### Description Return From Call. Resumes execution at the address following the last CALL instruction. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ``` -------------------------------- ### VTYPE - Vertex Type Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Defines the data formats for vertex attributes like texture, color, normal, position, and weight. ```APIDOC ## VTYPE - Vertex Type ### Description Vertex Type. Configures the data formats for various vertex attributes, including texture coordinates, color, normals, positions, and weights. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **argument** (integer) - Required - 0-1: Texture Format (ST/UV): - 00: Not present in vertex - 01: 8-bit fixed - 10: 16-bit fixed - 11: 32-bit floats - 2-4: Color Format: - 000: Not present in vertex - 100: 16-bit BGR-5650 - 101: 16-bit ABGR-5551 - 110: 16-bit ABGR-4444 - 111: 32-bit ABGR-8888 - 5-6: Normal Format (XYZ): - 00: Not present in vertex - 01: 8-bit fixed - 10: 16-bit fixed - 11: 32-bit floats - 7-8: Position Format (XYZ): - 00: Not present in vertex - 01: 8-bit fixed - 10: 16-bit fixed - 11: 32-bit floats - 9-10: Weight Format: - 00: Not present in vertex - 01: 8-bit fixed - 10: 16-bit fixed - 11: 32-bit floats ``` -------------------------------- ### CALL - Call Address Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Calls a subroutine at a specified address. Requires BASE register to be set first. ```APIDOC ## CALL - Call Address ### Description Call Address (BASE). Transfers execution to a specified subroutine address, with a return address being saved. The BASE register must be written before this command. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **argument** (integer) - Required - 0-23: 24 least significant bits of the pointer. ``` -------------------------------- ### BASE - Base Address Register Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Sets the BASE address register, used for pointer operations. ```APIDOC ## BASE - Base Address Register ### Description Base Address Register. Sets the base address used in pointer operations. This register must be written before commands that use (BASE). ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **argument** (integer) - Required - 16-20: 4 most significant bits for address (resulting in a 28-bit address). ``` -------------------------------- ### VADDR - Vertex Address Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Sets the vertex address for subsequent operations. Requires BASE register to be set first. ```APIDOC ## VADDR - Vertex Address ### Description Vertex Address (BASE). Sets the starting address for vertex data. The BASE register must be written before this command. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **argument** (integer) - Required - 0-23: 24 least significant bits of the pointer. ``` -------------------------------- ### END - Stop Execution Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Stops the execution of commands. ```APIDOC ## END - Stop Execution ### Description Stop execution. Terminates the processing of the current command stream. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ``` -------------------------------- ### SIGNAL - Raise Signal Interrupt Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Raises a signal interrupt with a specified argument and index. ```APIDOC ## SIGNAL - Raise Signal Interrupt ### Description Raise Signal Interrupt. Triggers a signal interrupt with a specific argument and index. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **argument** (integer) - Required - 0-15: Argument to pass to the signal handler. - 16-23: Signal index to trigger. ``` -------------------------------- ### IADDR - Index Address Source: https://github.com/pspdev/pspsdk/blob/master/src/gu/doc/commands.txt Sets the index buffer address for subsequent operations. Requires BASE register to be set first. ```APIDOC ## IADDR - Index Address ### Description Index Address (BASE). Sets the starting address for index buffer data. The BASE register must be written before this command. ### Method Not Applicable (Command Word) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **argument** (integer) - Required - 0-23: 24 least significant bits of the pointer. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.