### Build and Install LibXenon Toolchain Source: https://context7.com/free60project/libxenon/llms.txt Use this script to build and install the GCC cross-compiler, binutils, newlib, and the LibXenon core library. Environment variables can be set manually or via the xenon-env command. ```bash # Install the cross-compilation toolchain (GCC 9.2.0, binutils 2.32, newlib 3.1.0) ./toolchain/build-xenon-toolchain toolchain # Install LibXenon core library ./toolchain/build-xenon-toolchain libxenon # Install auxiliary libraries (zlib, libpng, bzip2, freetype, filesystems) ./toolchain/build-xenon-toolchain libs # Set up environment variables (add to ~/.bashrc) export DEVKITXENON="/usr/local/xenon" export PATH="${PATH:+${PATH}:}$DEVKITXENON/bin:$DEVKITXENON/usr/bin" # Or install the xenon-env command for quick setup ./toolchain/build-xenon-toolchain env-cmd xenon-env # Run this to enter a shell with proper paths ``` -------------------------------- ### Run LibXenon Docker Image Source: https://github.com/free60project/libxenon/blob/master/README.md Example of how to run the LibXenon Docker image and build a homebrew application within the container. Mounts the current directory to the container for persistent storage. ```bash host $ cd libxenon-homebrew-app/ host $ docker run -it -v $PWD:/app free60/libxenon:latest docker $ cd /app docker $ make ``` -------------------------------- ### Build Xenon Toolchain Source: https://github.com/free60project/libxenon/blob/master/README.md Command to build the LibXenon toolchain. Ensure all dependencies are installed prior to execution. ```bash ./build-xenon-toolchain toolchain ``` -------------------------------- ### Basic GPU Rendering with Xenos API Source: https://context7.com/free60project/libxenon/llms.txt Demonstrates initializing the Xenos GPU, setting up vertex and index buffers, and rendering a simple triangle. This example uses Direct3D-like concepts for graphics operations. ```c #include #include #include int main(void) { struct XenosDevice _xe, *xe = &_xe; // Initialize video and GPU xenos_init(VIDEO_MODE_AUTO); Xe_Init(xe); // Get and set the framebuffer as render target struct XenosSurface *fb = Xe_GetFramebufferSurface(xe); Xe_SetRenderTarget(xe, fb); // Define vertex buffer format static const struct XenosVBFFormat vbf = { 3, { {XE_USAGE_POSITION, 0, XE_TYPE_FLOAT3}, {XE_USAGE_COLOR, 0, XE_TYPE_UBYTE4}, {XE_USAGE_TEXCOORD, 0, XE_TYPE_FLOAT2}, } }; // Create vertex buffer float vertices[] = { // Position (x,y,z), Color (RGBA), TexCoord (u,v) -0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, }; struct XenosVertexBuffer *vb = Xe_CreateVertexBuffer(xe, sizeof(vertices)); void *v = Xe_VB_Lock(xe, vb, 0, sizeof(vertices), XE_LOCK_WRITE); memcpy(v, vertices, sizeof(vertices)); Xe_VB_Unlock(xe, vb); // Create index buffer unsigned short indices[] = { 0, 1, 2 }; struct XenosIndexBuffer *ib = Xe_CreateIndexBuffer(xe, sizeof(indices), XE_FMT_INDEX16); unsigned short *i = Xe_IB_Lock(xe, ib, 0, sizeof(indices), XE_LOCK_WRITE); memcpy(i, indices, sizeof(indices)); Xe_IB_Unlock(xe, ib); // Initialize EDRAM before first frame edram_init(xe); // Render loop while (1) { Xe_InvalidateState(xe); // Set render state Xe_SetClearColor(xe, 0x00000000); // Black background Xe_SetZEnable(xe, 1); Xe_SetCullMode(xe, XE_CULL_NONE); // Draw primitives Xe_SetStreamSource(xe, 0, vb, 0, 6 * sizeof(float)); Xe_SetIndices(xe, ib); Xe_DrawIndexedPrimitive(xe, XE_PRIMTYPE_TRIANGLELIST, 0, 0, 3, 0, 1); // Present frame Xe_Resolve(xe); Xe_Sync(xe); } // Cleanup Xe_DestroyVertexBuffer(xe, vb); Xe_DestroyIndexBuffer(xe, ib); return 0; } ``` -------------------------------- ### Set DEVKITXENON Environment Variable Source: https://github.com/free60project/libxenon/blob/master/README.md Example of how to set the DEVKITXENON environment variable and update the PATH for the Xenon toolchain. It's recommended to add these to your ~/.bashrc for persistence. ```bash DEVKITXENON="/usr/local/xenon" PATH="${PATH:+${PATH}:}"$DEVKITXENON"/bin:"$DEVKITXENON"/usr/bin ``` -------------------------------- ### Initialize Telnet Console for Network Debugging Source: https://context7.com/free60project/libxenon/llms.txt Sets up a telnet console server for remote debugging over the network. Networking must be initialized before starting the telnet console. Output is mirrored to both the screen and telnet clients. ```c #include #include int main(void) { // Initialize networking first if (network_init() == NETWORK_INIT_SUCCESS) { network_print_config(); // Start telnet console server telnet_console_init(); // Output will now also be sent to telnet clients printf("This message appears on screen and via telnet\n"); // Main loop with network polling while (1) { network_poll(); // Application logic... } telnet_console_close(); } return 0; } ``` -------------------------------- ### Initialize Network and Perform TCP Request in C Source: https://context7.com/free60project/libxenon/llms.txt Initializes the network stack with DHCP and performs a basic HTTP GET request. Requires calling network_poll in the main loop. ```c #include #include int main(void) { int result = network_init(); if (result == NETWORK_INIT_SUCCESS) { printf("Network initialized successfully\n"); network_print_config(); // Print IP, netmask, gateway // Create a TCP socket int sock = socket(AF_INET, SOCK_STREAM, 0); struct sockaddr_in server_addr; server_addr.sin_family = AF_INET; server_addr.sin_port = htons(80); inet_aton("192.168.1.100", &server_addr.sin_addr); if (connect(sock, (struct sockaddr*)&server_addr, sizeof(server_addr)) == 0) { const char *request = "GET / HTTP/1.0\r\n\r\n"; send(sock, request, strlen(request), 0); char buffer[1024]; int received = recv(sock, buffer, sizeof(buffer) - 1, 0); if (received > 0) { buffer[received] = '\0'; printf("Response: %s\n", buffer); } } close(sock); } else if (result == NETWORK_INIT_DHCP_FAILURE) { printf("DHCP failed\n"); } else { printf("Network initialization failed\n"); } // Main loop must poll network while (1) { network_poll(); // Application logic... } return 0; } ``` -------------------------------- ### Initialize Storage and Manage Files in C Source: https://context7.com/free60project/libxenon/llms.txt Demonstrates initializing USB and ATA devices, mounting FAT file systems, and performing basic file I/O operations. ```c #include #include #include #include #include int main(void) { // Initialize USB for external drives usb_init(); usb_do_poll(); // Initialize internal ATA (HDD) xenon_ata_init(); // Initialize ATAPI (DVD drive) xenon_atapi_init(); // Mount FAT file systems fatInitDefault(); // List directory contents DIR *d = opendir("uda:/"); // USB drive A if (d) { struct dirent *de; while ((de = readdir(d)) != NULL) { if (de->d_type & DT_DIR) { printf("[DIR] %s\n", de->d_name); } else { printf("[FILE] %s\n", de->d_name); } } closedir(d); } // Read a file FILE *f = fopen("uda:/config.txt", "rb"); if (f) { char buffer[256]; size_t bytes_read = fread(buffer, 1, sizeof(buffer) - 1, f); buffer[bytes_read] = '\0'; printf("File contents: %s\n", buffer); fclose(f); } // Write a file f = fopen("uda:/output.txt", "wb"); if (f) { fprintf(f, "Hello from LibXenon!\n"); fclose(f); } return 0; } ``` -------------------------------- ### Xe_Init and GPU Rendering Source: https://context7.com/free60project/libxenon/llms.txt Provides an interface for Direct3D-like rendering, including vertex buffers, index buffers, and frame synchronization. ```APIDOC ## Xe_Init ### Description Initializes the Xenos GPU device structure for rendering operations. ### Parameters - **xe** (struct XenosDevice*) - Required - Pointer to the device structure to initialize. ## Xe_DrawIndexedPrimitive ### Description Draws indexed primitives using the currently set vertex and index buffers. ### Parameters - **xe** (struct XenosDevice*) - Required - Pointer to the device structure. - **type** (enum) - Required - Primitive type (e.g., XE_PRIMTYPE_TRIANGLELIST). - **vbase** (int) - Required - Base vertex index. - **minv** (int) - Required - Minimum vertex index. - **numv** (int) - Required - Number of vertices. - **istart** (int) - Required - Start index in the index buffer. - **primcount** (int) - Required - Number of primitives to draw. ``` -------------------------------- ### LibXenon Docker Development Environment Source: https://context7.com/free60project/libxenon/llms.txt Utilize pre-built Docker images for a ready-to-use LibXenon development environment. Mount your project directory into the container to build and run applications. ```bash # Run LibXenon development environment using Docker cd libxenon-homebrew-app/ docker run -it -v $PWD:/app free60/libxenon:latest # Inside Docker container cd /app make ``` -------------------------------- ### Build LibXenon Library Source: https://github.com/free60project/libxenon/blob/master/README.md Command to build the LibXenon library itself. This should be run after the toolchain has been successfully built. ```bash ./build-xenon-toolchain libxenon ``` -------------------------------- ### Load and Execute ELF Binaries Source: https://context7.com/free60project/libxenon/llms.txt Functions for loading ELF binaries from disk or memory, including support for kernel booting with device trees. ```c #include #include void launch_application(const char *filename) { printf("Loading %s...\n", filename); // Run ELF directly from file system int result = elf_runFromDisk((char*)filename); // If we get here, loading failed printf("Failed to load ELF: %d\n", result); } void launch_from_memory(void *elf_data, int elf_size) { // Set command line arguments for the loaded program char *argv[] = {"program.elf", "--arg1", "--arg2"}; elf_setArgcArgv(3, argv); // Run ELF from memory buffer elf_runFromMemory(elf_data, elf_size); } void launch_linux_kernel(void *kernel, int kernel_size, void *initrd, int initrd_size, void *dtb, int dtb_size) { // Prepare initrd kernel_prepare_initrd(initrd, initrd_size); // Set kernel command line kernel_build_cmdline("console=tty root=/dev/ram0", "/dev/ram0"); // Boot with device tree elf_runWithDeviceTree(kernel, kernel_size, dtb, dtb_size); } ``` -------------------------------- ### Load and Apply Vertex and Pixel Shaders Source: https://context7.com/free60project/libxenon/llms.txt Demonstrates loading compiled HLSL shaders from memory and applying them to the graphics pipeline. Ensure shader binary data is correctly compiled and linked. ```c #include // Shader binary data (compiled HLSL) extern unsigned char my_vertex_shader[]; extern unsigned char my_pixel_shader[]; void setup_shaders(struct XenosDevice *xe, const struct XenosVBFFormat *vbf) { // Load shaders from memory struct XenosShader *vs = Xe_LoadShaderFromMemory(xe, my_vertex_shader); struct XenosShader *ps = Xe_LoadShaderFromMemory(xe, my_pixel_shader); // Instantiate shaders Xe_InstantiateShader(xe, vs, 0); Xe_InstantiateShader(xe, ps, 0); // Apply vertex fetch patches for the vertex buffer format Xe_ShaderApplyVFetchPatches(xe, vs, 0, vbf); // Set active shaders Xe_SetShader(xe, SHADER_TYPE_VERTEX, vs, 0); Xe_SetShader(xe, SHADER_TYPE_PIXEL, ps, 0); // Set shader constants float modelViewMatrix[16] = { /* ... */ }; Xe_SetVertexShaderConstantF(xe, 0, modelViewMatrix, 4); float lightDirection[] = {0.0f, 0.0f, -1.0f, 0.0f}; Xe_SetPixelShaderConstantF(xe, 0, lightDirection, 1); } ``` -------------------------------- ### xenos_init Source: https://context7.com/free60project/libxenon/llms.txt Initializes the Xenos GPU and sets the video output mode. This function must be called before any other graphics operations. ```APIDOC ## xenos_init ### Description Initializes the Xenos GPU and sets up the video output mode. Must be called before any graphics operations. ### Parameters #### Path Parameters - **mode** (enum) - Required - The video mode to initialize (e.g., VIDEO_MODE_AUTO, VIDEO_MODE_HDMI_720P, VIDEO_MODE_NTSC). ### Response #### Success Response (void) - **void** - Initializes the hardware state. ``` -------------------------------- ### Build Auxiliary Libraries Source: https://github.com/free60project/libxenon/blob/master/README.md Command to build auxiliary libraries required by LibXenon, including zlib, libpng, bzip2, freetype, and filesystems. ```bash ./build-xenon-toolchain libs ``` -------------------------------- ### Initialize and Use Text Console Source: https://context7.com/free60project/libxenon/llms.txt Initializes the text console for debug output, allowing for colored text, cursor positioning, and standard printf functionality. Remember to close the console before switching to graphics mode. ```c #include #include int main(void) { xenos_init(VIDEO_MODE_AUTO); console_init(); // Set console colors (background, foreground) console_set_colors(CONSOLE_COLOR_BLACK, CONSOLE_COLOR_WHITE); // Clear screen console_clrscr(); // Print with standard printf printf("Hello, Xbox 360!\n"); // Colored output macros PRINT_SUCCESS("Operation completed successfully\n"); PRINT_WARN("Warning: Low memory\n"); PRINT_ERR("Error: File not found\n"); // Custom colored output PRINT_COL(CONSOLE_COLOR_BLACK, CONSOLE_COLOR_YELLOW, "Yellow text\n"); // Get console dimensions unsigned int width, height; console_get_dimensions(&width, &height); printf("Console size: %u x %u\n", width, height); // Cursor positioning console_set_cursor(10, 5); printf("Text at position (10, 5)"); // Close console before switching to graphics mode console_close(); return 0; } ``` -------------------------------- ### Mount ISO9660 Disc in C Source: https://context7.com/free60project/libxenon/llms.txt Mounts a DVD drive using the ISO9660 file system to access disc contents. Requires atapi initialization. ```c #include #include int main(void) { xenon_atapi_init(); // Mount the DVD drive as ISO9660 if (ISO9660_Mount("dvd", &atapi)) { const char *label = ISO9660_GetVolumeLabel("dvd"); printf("Mounted disc: %s\n", label); // Access files on the disc FILE *f = fopen("dvd:/default.xex", "rb"); if (f) { // Read disc content... fclose(f); } ISO9660_Unmount("dvd"); } return 0; } ``` -------------------------------- ### Initialize Xenos GPU and Video Output Source: https://context7.com/free60project/libxenon/llms.txt Initializes the Xenos GPU and sets the video output mode. This function must be called before any graphics operations. Automatic mode detection is available, or specific modes like HDMI 720p, VGA, NTSC, or PAL can be specified. ```c #include #include int main(void) { // Initialize video with automatic mode detection xenos_init(VIDEO_MODE_AUTO); // Or specify a specific video mode: // xenos_init(VIDEO_MODE_HDMI_720P); // HDMI 720p // xenos_init(VIDEO_MODE_VGA_1280x720); // VGA 1280x720 // xenos_init(VIDEO_MODE_NTSC); // NTSC composite // xenos_init(VIDEO_MODE_PAL60); // PAL 60Hz // Check if initialization succeeded if (xenos_is_initialized()) { printf("Video initialized successfully\n"); } return 0; } ``` -------------------------------- ### Debugging Utilities Source: https://context7.com/free60project/libxenon/llms.txt Macros and functions for tracing variables, setting breakpoints, and inspecting memory or stack frames. ```c #include void debug_example(void) { // Trace macro - prints function name and line number TR; // Trace variables int value = 42; TRI(value); // Prints: [Trace int] value = 42(0x2a) at function(line) float fval = 3.14f; TRF(fval); // Prints: [Trace flt] fval = 3.140000 at function(line) char *str = "hello"; TRS(str); // Prints: [Trace str] str = hello at function(line) // Breakpoint - pauses and waits for input BP; // Dump memory buffer char buffer[64] = "test data"; buffer_dump(buffer, sizeof(buffer)); // Print stack trace (max 10 frames) stack_trace(10); // Hardware data breakpoint (reads from address, writes to address) int watched_var = 0; data_breakpoint(&watched_var, 1, 1); // Break on read or write } ``` -------------------------------- ### Control Controller Rumble in C Source: https://context7.com/free60project/libxenon/llms.txt Uses set_controller_rumble to trigger haptic feedback on controller motors. Requires input/input.h and mdelay for timing. ```c #include void rumble_example(void) { // Full rumble on both motors set_controller_rumble(0, 255, 255); mdelay(500); // Rumble for 500ms // Stop rumble set_controller_rumble(0, 0, 0); // Left motor only (heavy rumble) set_controller_rumble(0, 255, 0); mdelay(200); // Right motor only (light rumble) set_controller_rumble(0, 0, 255); mdelay(200); set_controller_rumble(0, 0, 0); } ``` -------------------------------- ### Manage CPU Threads Source: https://context7.com/free60project/libxenon/llms.txt Executes tasks on secondary CPU threads and manages thread states. ```c #include #include void worker_task(void) { printf("Running on secondary thread\n"); // Perform parallel work... } int main(void) { char stack[4096] __attribute__((aligned(16))); // Start task on thread 1 (threads 0-5 available) int thread_id = 1; xenon_run_thread_task(thread_id, stack + sizeof(stack), worker_task); // Check if thread is still running while (xenon_is_thread_task_running(thread_id)) { // Do other work on main thread... } // Put thread to sleep when done xenon_sleep_thread(thread_id); // Or switch to single-thread mode xenon_set_single_thread_mode(); return 0; } ``` -------------------------------- ### Timing and Delay Operations Source: https://context7.com/free60project/libxenon/llms.txt Provides blocking delay functions and high-precision timebase access for performance measurement. ```c #include