### Install Project Targets and Headers Source: https://github.com/batocera-linux/batocera.linux/blob/master/package/batocera/utils/imgui/CMakeLists.txt Defines the installation rules for the compiled library and associated header files. This ensures that the library can be correctly deployed and consumed by other projects. ```cmake install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}_target ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin) if(NOT IMGUI_SKIP_HEADERS) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/imgui.h ${CMAKE_CURRENT_SOURCE_DIR}/imconfig.h ${CMAKE_CURRENT_SOURCE_DIR}/imgui_internal.h DESTINATION include) endif() ``` -------------------------------- ### Installation Rules Source: https://github.com/batocera-linux/batocera.linux/blob/master/package/batocera/emulators/sugarbox/CMakeLists.txt Configures the installation of the 'Sugarbox' executable and related files. It specifies runtime destinations for the executable, configuration files, ROMs, and other resource directories. ```cmake # Ready-to-use configuration install ( TARGETS Sugarbox RUNTIME DESTINATION .) install ( FILES "${PROJECT_SOURCE_DIR}/Sugarbox.ini" DESTINATION .) install ( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/ROM" DESTINATION .) install ( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/CART" DESTINATION .) install ( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/CONF" DESTINATION .) install ( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Resources" DESTINATION .) ``` -------------------------------- ### MSVC CPACK Qt DLLs Installation (CMake) Source: https://github.com/batocera-linux/batocera.linux/blob/master/package/batocera/emulators/sugarbox/CMakeLists.txt This CMake script installs Qt DLLs for MSVC builds. It uses the `windeployqt` tool to identify and copy necessary DLLs based on the build configuration (Debug, Release, etc.). The process involves executing `windeployqt` with specific arguments to list the files, then copying them to the installation directory. ```cmake IF(MSVC) install (CODE " set (_outpath ${CMAKE_INSTALL_PREFIX}) set (_file ${CMAKE_CURRENT_BINARY_DIR}/$<$:Debug>$<$:Release>$<$:RelWithDebInfo>$<$:MinSizeRel>/Sugarbox.exe) set ( rel_or_debug $<$:--debug>$<$:--release>$<$:--release>$<$:--release> ) execute_process( COMMAND "${CMAKE_COMMAND}" -E env PATH="${_qt_bin_dir}" "${WINDEPLOYQT_EXECUTABLE}" --dry-run --no-compiler-runtime --list mapping ``` -------------------------------- ### Configure and Install ImGui Package Configuration (CMake) Source: https://github.com/batocera-linux/batocera.linux/blob/master/package/batocera/utils/imgui/CMakeLists.txt Configures and installs the ImGui package configuration file ('imgui-config.cmake') and target export file. This enables other projects to find and use the installed ImGui library. ```cmake include(CMakePackageConfigHelpers) configure_package_config_file(imgui-config.cmake.in imgui-config.cmake INSTALL_DESTINATION share/imgui) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/imgui-config.cmake DESTINATION share/imgui) install( EXPORT ${PROJECT_NAME}_target NAMESPACE ${PROJECT_NAME}:: FILE ${PROJECT_NAME}-targets.cmake DESTINATION share/${PROJECT_NAME} ) ``` -------------------------------- ### Install ImGui Backend Headers (CMake) Source: https://github.com/batocera-linux/batocera.linux/blob/master/package/batocera/utils/imgui/CMakeLists.txt Conditionally installs ImGui backend header files to the 'include' directory based on defined CMake build flags. This allows for modular inclusion of different ImGui backends. ```cmake if(IMGUI_BUILD_ALLEGRO5_BINDING) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_allegro5.h DESTINATION include) endif() if(IMGUI_BUILD_DX9_BINDING) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_dx9.h DESTINATION include) endif() if(IMGUI_BUILD_DX10_BINDING) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_dx10.h DESTINATION include) endif() if(IMGUI_BUILD_DX11_BINDING) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_dx11.h DESTINATION include) endif() if(IMGUI_BUILD_DX12_BINDING) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_dx12.h DESTINATION include) endif() if(IMGUI_BUILD_GLFW_BINDING) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_glfw.h DESTINATION include) endif() if(IMGUI_BUILD_GLUT_BINDING) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_glut.h DESTINATION include) endif() if(IMGUI_BUILD_METAL_BINDING) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_metal.h DESTINATION include) endif() if(IMGUI_BUILD_OPENGL2_BINDING) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_opengl2.h DESTINATION include) endif() if(IMGUI_BUILD_OPENGL3_BINDING) install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_opengl3.h ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_opengl3_loader.h DESTINATION include ) endif() if(IMGUI_BUILD_OSX_BINDING) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_osx.h DESTINATION include) endif() if(IMGUI_BUILD_SDL2_BINDING) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_sdl.h DESTINATION include) endif() if(IMGUI_BUILD_SDL2_RENDERER_BINDING) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_sdlrenderer.h DESTINATION include) endif() if(IMGUI_BUILD_VULKAN_BINDING) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_vulkan.h DESTINATION include) endif() if(IMGUI_BUILD_WIN32_BINDING) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_win32.h DESTINATION include) endif() if(IMGUI_FREETYPE) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/misc/freetype/imgui_freetype.h DESTINATION include) endif() endif() ``` -------------------------------- ### Configure FDT in uEnv.txt for Booting Source: https://github.com/batocera-linux/batocera.linux/blob/master/board/batocera/amlogic/s905gen3/tvbox-gen3/boot/README.txt This snippet shows how to configure the FDT (Device Tree Blob) setting within the uEnv.txt file. This is crucial for ensuring the system boots correctly with the appropriate hardware configuration. The example provided is for HK1/Vontar X3/H96 max devices. ```text FDT=/boot/meson-sm1-h96-max.dtb ``` -------------------------------- ### Custom Emulator Generator Source: https://context7.com/batocera-linux/batocera.linux/llms.txt Example of creating a custom emulator generator by inheriting from the base Generator class. ```APIDOC ## Custom Emulator Generator ### Description This section provides an example of how to create a custom emulator generator by inheriting from the `Generator` base class. It demonstrates how to implement the `generate()` method to produce launch commands for a specific emulator, including handling system configurations, ROM paths, controller inputs, and game metadata. ### Method N/A (Python Class Definition) ### Endpoint N/A ### Parameters #### Class Parameters (within `generate` method) - **system** (object) - Required - Emulator configuration object containing settings from batocera.conf. - **rom** (Path) - Required - Path to the ROM file to be launched. - **playersControllers** (list) - Required - List of configured controllers for the current game session. - **metadata** (object) - Required - Game metadata parsed from EmulationStation. - **guns** (list) - Required - List of detected light guns. - **wheels** (list) - Required - List of detected steering wheels. - **gameResolution** (dict) - Required - Dictionary containing the current display resolution (e.g., `{"width": 1920, "height": 1080}`). #### Class Methods - **generate()**: Abstract method to be implemented by subclasses to return a `Command` object. - **getHotkeysContext()**: Returns a dictionary defining hotkey mappings for the emulator. - **supportsInternalBezels()**: Returns a boolean indicating if the emulator supports internal bezels. - **getInGameRatio()**: Returns the default aspect ratio for games run by this emulator. ### Request Example ```python from configgen.generators.Generator import Generator from configgen.Command import Command from pathlib import Path class MyEmulatorGenerator(Generator): def generate( self, system, rom: Path, playersControllers, metadata, guns, wheels, gameResolution, ) -> Command: args = ["/usr/bin/myemulator"] args.append(str(rom)) if system.config.get_bool('fullscreen', True): args.append("--fullscreen") if system.config.get('videomode') != 'default': args.extend(["--resolution", f"{gameResolution['width']}x{gameResolution['height']}"]) return Command(args, env={ "SDL_GAMECONTROLLERCONFIG": controller_config, "HOME": "/userdata/system" }) def getHotkeysContext(self): return { "name": "myemulator", "keys": { "exit": ["KEY_LEFTSHIFT", "KEY_ESC"], "menu": ["KEY_LEFTSHIFT", "KEY_F1"], "save_state": ["KEY_LEFTSHIFT", "KEY_F3"], "restore_state": ["KEY_LEFTSHIFT", "KEY_F4"] } } def supportsInternalBezels(self) -> bool: return False def getInGameRatio(self, config, gameResolution, rom) -> float: return 4/3 ``` ### Response N/A (Python Class Definition) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### CMake Minimum Version and Project Setup Source: https://github.com/batocera-linux/batocera.linux/blob/master/package/batocera/emulators/sugarbox/CMakeLists.txt Sets the minimum required CMake version based on the compiler (MSVC or others) and initializes the project named 'Sugarbox'. It also enables automatic inclusion of current directory headers and sets the C++ standard to 17. ```cmake IF(MSVC) cmake_minimum_required(VERSION 3.14) else() cmake_minimum_required(VERSION 3.10) endif() project(Sugarbox) # Find includes in the build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_CXX_STANDARD 17) ``` -------------------------------- ### Custom Boot Script Template Source: https://github.com/batocera-linux/batocera.linux/blob/master/package/batocera/core/batocera-userdatainit/datainit/system/template-custom.txt A template script for Batocera that executes tasks during the boot process. It includes conditional logic to ensure the script only runs during the 'start' phase and demonstrates how to set system timezones. ```bash #!/bin/bash logfile=/tmp/scriptlog.txt if test "$1" != "start" then exit 0 fi TZ=Europe/Paris hwclock --systz --localtime echo "$1" > $logfile echo "$1" >> $logfile ``` -------------------------------- ### Bash Script for Game Event Logging Source: https://github.com/batocera-linux/batocera.linux/blob/master/package/batocera/core/batocera-userdatainit/datainit/system/scripts/template-game-start-stop.txt This Bash script serves as a template for custom game start and stop scripts in Batocera Linux. It logs the event type ('START' or 'END') and any arguments passed to a specified log file. Ensure the script is executable by running 'chmod +x'. ```bash #!/bin/bash # This is a template for the game start/stop custom script that will be # launched on game watch event. The first line here # is the shebang; the binary that should be called to execute it. # Rename this file to script01.sh and run # "chmod +x /userdata/system/scripts/script01.sh" to give it the executable bit # to use it. Any valid filename is usable. # This is an example file how Events on START or STOP can be used. # Set logfile location and filename logfile=/tmp/scriptlog.txt # Case selection for first parameter parsed, writing to a log file on game # watch events (starting and stopping a game): case $1 in gameStart) echo "START" > $logfile echo "$@" >> $logfile ;; gameStop) echo "END" >> $logfile ;; esac ``` -------------------------------- ### Initialize Emulator Configuration Source: https://context7.com/batocera-linux/batocera.linux/llms.txt Demonstrates how to load emulator settings using the Emulator class, which merges configuration from multiple sources based on a defined precedence hierarchy. It shows how to access typed configuration values and check for specific options. ```python from configgen.Emulator import Emulator system = Emulator(args, rom) print(system.name) print(system.config.emulator) print(system.config.core) smooth = system.config.get_bool('smooth', default=False) ratio = system.config.get_str('ratio', default='auto') if 'rewind' in system.config: rewind_enabled = system.config.get_bool('rewind') ``` -------------------------------- ### Define Boot Command Source: https://github.com/batocera-linux/batocera.linux/blob/master/board/batocera/amlogic/s905/tvbox/boot/s905_autoscript.txt Sets up the primary boot command using the 'bootm' utility, which loads the kernel, initrd, and device tree from their specified memory addresses. ```shell setenv boot_start "bootm ${kernel_addr} ${initrd_addr} ${dtb_mem_addr}" ``` -------------------------------- ### Load Boot Configuration from USB (Device 0) Source: https://github.com/batocera-linux/batocera.linux/blob/master/board/batocera/amlogic/s905/tvbox/boot/s905_autoscript.txt Attempts to load the 'uEnv.txt' configuration file from the first partition of a USB drive. If successful, it imports environment variables and proceeds to load the kernel, initrd, and device tree if they exist. ```shell if fatload usb 0 ${env_addr} uEnv.txt; then env import -t ${env_addr} ${filesize}; setenv bootargs ${APPEND}; if fatload usb 0 ${kernel_addr} ${LINUX}; then if fatload usb 0 ${initrd_addr} ${INITRD}; then if fatload usb 0 ${dtb_mem_addr} ${FDT}; then run boot_start; fi; fi; fi; fi; ``` -------------------------------- ### Load Boot Configuration from USB (Device 1) Source: https://github.com/batocera-linux/batocera.linux/blob/master/board/batocera/amlogic/s905/tvbox/boot/s905_autoscript.txt Attempts to load the 'uEnv.txt' configuration file from the second partition of a USB drive. If successful, it imports environment variables and proceeds to load the kernel, initrd, and device tree if they exist. ```shell if fatload usb 1 ${env_addr} uEnv.txt; then env import -t ${env_addr} ${filesize}; setenv bootargs ${APPEND}; if fatload usb 1 ${kernel_addr} ${LINUX}; then if fatload usb 1 ${initrd_addr} ${INITRD}; then if fatload usb 1 ${dtb_mem_addr} ${FDT}; then run boot_start; fi; fi; fi; fi; ``` -------------------------------- ### Emulator Launcher Configuration and Arguments (Python) Source: https://context7.com/batocera-linux/batocera.linux/llms.txt Demonstrates the Python-based emulator launcher entry point used by Batocera Linux. It outlines the command-line arguments accepted for launching games, configuring controllers, managing video modes, and integrating with other system features. ```python # Example emulator launch from EmulationStation (internal call) # emulatorlauncher -system snes -rom /userdata/roms/snes/game.sfc \ # -p1index 0 -p1guid 03000000... -p1name "Xbox Controller" \ # -p1devicepath /dev/input/event0 -gameinfoxml /tmp/game.xml from configgen.emulatorlauncher import launch # The launcher handles: # 1. Controller detection and configuration # 2. Video mode switching (resolution management) # 3. Emulator/core selection based on batocera.conf # 4. Bezel/overlay configuration # 5. Light gun and wheel detection/configuration # 6. External script hooks (gameStart/gameStop) # 7. HUD/MangoHUD integration # Command line arguments parser.add_argument("-system", help="select the system to launch", type=str, required=True) parser.add_argument("-rom", help="rom absolute path", type=Path, required=True) parser.add_argument("-emulator", help="force emulator", type=str, required=False) parser.add_argument("-core", help="force emulator core", type=str, required=False) parser.add_argument("-netplaymode", help="host/client", type=str, required=False) parser.add_argument("-lightgun", help="configure lightguns", action="store_true") parser.add_argument("-wheel", help="configure wheel", action="store_true") ``` -------------------------------- ### Initialize WebSocket and UI - JavaScript Source: https://github.com/batocera-linux/batocera.linux/blob/master/package/batocera/emulationstation/batocera-es-web-ui/web/index.html Sets up the initial page load, fetching system data to display the system carousel and establishing a WebSocket connection for real-time updates. It handles incoming WebSocket messages to update the currently displayed game information and manages connection errors. ```javascript var PREVDATA = null; $(document).ready(function() { fetch('/systems') .then(response => response.json()) .then(data => { showSystems(data); }); var latestOutput = document.getElementById("jumbo"); // Construct the WebSocket URL based on the current location of the web page var wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:'; var wsHost = location.host; wsHost = wsHost.split(':')[0]+":8080" var wsUrl = wsProtocol + '//' + wsHost + '/'; var ws = new WebSocket(wsUrl); ws.onmessage = function(event) { var d = event.data; if (PREVDATA != d) { var dd = JSON.parse(d); latestOutput.innerHTML = describe(dd); PREVDATA = d; } }; ws.onclose = function() { var message = { "msg": "ERROR" }; latestOutput.innerHTML = describe(message); }; }); ``` -------------------------------- ### Load Boot Configuration from MMC (Device 0) Source: https://github.com/batocera-linux/batocera.linux/blob/master/board/batocera/amlogic/s905/tvbox/boot/s905_autoscript.txt Attempts to load the 'uEnv.txt' configuration file from the first partition of an MMC (e.g., SD card) device. If successful, it imports environment variables and proceeds to load the kernel, initrd, and device tree if they exist. ```shell if fatload mmc 0 ${env_addr} uEnv.txt; then env import -t ${env_addr} ${filesize}; setenv bootargs ${APPEND}; if fatload mmc 0 ${kernel_addr} ${LINUX}; then if fatload mmc 0 ${initrd_addr} ${INITRD}; then if fatload mmc 0 ${dtb_mem_addr} ${FDT}; then run boot_start; fi; fi; fi; fi; ``` -------------------------------- ### Setup Infinite Scroll Observer Source: https://github.com/batocera-linux/batocera.linux/blob/master/package/batocera/emulationstation/batocera-es-web-ui/web/index.html Configures an Intersection Observer to detect when a loading indicator element enters the viewport. When triggered, it calls `loadMoreGames` to fetch and display the next batch of games, implementing the infinite scrolling behavior. Includes a small delay to prevent rapid firing and checks loading states. ```javascript function setupInfiniteScroll() { const loadingDiv = document.createElement('div'); loadingDiv.id = 'loading-indicator'; loadingDiv.className = 'col-12 text-center p-3'; loadingDiv.innerHTML = '
Loading more games...

Loading more games...

'; const gameContainer = document.getElementById("gameContainer"); const rowContainer = gameContainer.parentElement; rowContainer.appendChild(loadingDiv); gameScrollObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting && !isLoading && !loadingCancelled && currentBatch * GAMES_PER_BATCH < currentGames.length) { setTimeout(() => { if (!isLoading && !loadingCancelled && currentBatch * GAMES_PER_BATCH < currentGames.length) { loadMoreGames(); } }, 100); } }); }, { root: null, rootMargin: '100px', threshold: 0.1 }); gameScrollObserver.observe(loadingDiv); } ``` -------------------------------- ### Build Batocera Linux System Images (Bash) Source: https://context7.com/batocera-linux/batocera.linux/llms.txt Commands to build complete system images for various hardware platforms using the Makefile and Buildroot. This includes listing targets, building specific architectures, and generating configurations. ```bash make vars make x86_64-build make bcm2711-build make bcm2712-build make h616-build make x86_64-config make x86_64-source ``` -------------------------------- ### Manage Controller Input and SDL Mapping Source: https://context7.com/batocera-linux/batocera.linux/llms.txt Shows how to load controller configurations, access device attributes, and generate SDL_GAMECONTROLLERCONFIG strings for external applications. ```python from configgen.controller import Controller, write_sdl_controller_db controllers = Controller.load_for_players(max_players=8, args=args) controller = controllers[0] sdl_config = controller.generate_sdl_game_db_line() write_sdl_controller_db(controllers, "/tmp/gamecontrollerdb.txt") relaxed = controller.get_mapping_axis_relaxed_values() ``` -------------------------------- ### Configure Dear ImGui CMake Project Source: https://github.com/batocera-linux/batocera.linux/blob/master/package/batocera/utils/imgui/CMakeLists.txt Initializes the CMake project for Dear ImGui, sets the C++ standard, and defines the core library targets. It includes necessary source files and sets up include directories for public access. ```cmake cmake_minimum_required(VERSION 3.16) project(imgui CXX) add_library(${PROJECT_NAME} "") target_include_directories(${PROJECT_NAME} PUBLIC $ $) target_sources(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/imgui.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imgui_demo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imgui_draw.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imgui_tables.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imgui_widgets.cpp) target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11) ``` -------------------------------- ### Generate EmulationStation Systems Source: https://context7.com/batocera-linux/batocera.linux/llms.txt Shows the entry point for generating the es_systems.cfg file from internal YAML system definitions. ```python from batocera_es_system.es_systems import _system_dict_to_xml ``` -------------------------------- ### Configure U-Boot Boot Environment Variables Source: https://github.com/batocera-linux/batocera.linux/blob/master/board/batocera/amlogic/s905gen3/tvbox-gen3/boot/aml_autoscript.txt Sets the boot order, defines autoscript search paths for USB and MMC devices, and persists the configuration to non-volatile storage. This ensures the system attempts to load boot scripts from external media before proceeding to the primary storage. ```U-Boot setenv bootfromnand 0 setenv bootcmd "run start_autoscript; run storeboot;" setenv start_autoscript "if usb start ; then run start_usb_autoscript; fi; if mmcinfo; then run start_mmc_autoscript; fi;" setenv start_mmc_autoscript "if fatload mmc 0 1020000 s905_autoscript; then autoscr 1020000; fi;" setenv start_usb_autoscript "if fatload usb 0 1020000 s905_autoscript; then autoscr 1020000; fi; if fatload usb 1 1020000 s905_autoscript; then autoscr 1020000; fi; if fatload usb 2 1020000 s905_autoscript; then autoscr 1020000; fi; if fatload usb 3 1020000 s905_autoscript; then autoscr 1020000; fi;" setenv upgrade_step "0" saveenv sleep 1 reboot ``` -------------------------------- ### Implement Custom Emulator Generator Source: https://context7.com/batocera-linux/batocera.linux/llms.txt Demonstrates how to inherit from the Generator base class to define launch commands, hotkeys, and aspect ratios for custom emulators. ```python from configgen.generators.Generator import Generator from configgen.Command import Command from pathlib import Path class MyEmulatorGenerator(Generator): def generate(self, system, rom: Path, playersControllers, metadata, guns, wheels, gameResolution) -> Command: args = ["/usr/bin/myemulator"] args.append(str(rom)) if system.config.get_bool('fullscreen', True): args.append("--fullscreen") if system.config.get('videomode') != 'default': args.extend(["--resolution", f"{gameResolution['width']}x{gameResolution['height']}"]) return Command(args, env={"SDL_GAMECONTROLLERCONFIG": controller_config, "HOME": "/userdata/system"}) def getHotkeysContext(self): return {"name": "myemulator", "keys": {"exit": ["KEY_LEFTSHIFT", "KEY_ESC"], "menu": ["KEY_LEFTSHIFT", "KEY_F1"], "save_state": ["KEY_LEFTSHIFT", "KEY_F3"], "restore_state": ["KEY_LEFTSHIFT", "KEY_F4"]}} def supportsInternalBezels(self) -> bool: return False def getInGameRatio(self, config, gameResolution, rom) -> float: return 4/3 ``` -------------------------------- ### Qt6 Dependency and Resource Handling Source: https://github.com/batocera-linux/batocera.linux/blob/master/package/batocera/emulators/sugarbox/CMakeLists.txt This snippet finds the necessary Qt6 components (Widgets, WebSockets, OpenGLWidgets) and adds Qt resources defined in 'resources.qrc' to the build. It also includes platform-specific logic for handling 'windeployqt.exe' on Windows. ```cmake find_package(Qt6 COMPONENTS Widgets WebSockets OpenGLWidgets REQUIRED) qt6_add_resources(QRCS resources.qrc) if(Qt6_FOUND AND WIN32 AND TARGET Qt6::qmake AND NOT TARGET Qt6::windeployqt) get_target_property(_qt6_qmake_location Qt6::qmake IMPORTED_LOCATION) execute_process( COMMAND "${_qt6_qmake_location}" -query QT_INSTALL_PREFIX RESULT_VARIABLE return_code OUTPUT_VARIABLE qt6_install_prefix OUTPUT_STRIP_TRAILING_WHITESPACE ) set(imported_location "${qt6_install_prefix}/bin/windeployqt.exe") if(EXISTS ${imported_location}) add_executable(Qt6::windeployqt IMPORTED) set_target_properties(Qt6::windeployqt PROPERTIES IMPORTED_LOCATION ${imported_location} ) endif() endif() get_target_property(_qmake_executable Qt6::qmake IMPORTED_LOCATION) get_filename_component(_qt_bin_dir "${_qmake_executable}" DIRECTORY) find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${_qt_bin_dir}") ``` -------------------------------- ### Configure U-Boot Boot Environment Variables Source: https://github.com/batocera-linux/batocera.linux/blob/master/board/batocera/amlogic/s905gen3/khadas-vim3l/boot/aml_autoscript.txt Sets the boot order and defines the autoscript logic for MMC and USB devices. This configuration ensures the system checks for boot scripts on multiple storage interfaces before proceeding to the main boot command. ```U-Boot setenv bootfromnand 0 setenv bootcmd "run start_autoscript; run storeboot;" setenv start_autoscript "if mmcinfo; then run start_mmc_autoscript; fi; if usb start ; then run start_usb_autoscript; fi;" setenv start_mmc_autoscript "if fatload mmc 0 1020000 s905_autoscript; then setenv autoscript_source mmc; autoscr 1020000; fi;" setenv start_usb_autoscript "if fatload usb 0 1020000 s905_autoscript; then setenv autoscript_source usb; autoscr 1020000; fi; if fatload usb 1 1020000 s905_autoscript; then setenv autoscript_source usb; autoscr 1020000; fi; if fatload usb 2 1020000 s905_autoscript; then setenv autoscript_source usb; autoscr 1020000; fi; if fatload usb 3 1020000 s905_autoscript; then setenv autoscript_source usb; autoscr 1020000; fi;" setenv upgrade_step "0" saveenv sleep 1 reboot ``` -------------------------------- ### Batocera Linux Boot Script - Environment and Kernel Loading Source: https://github.com/batocera-linux/batocera.linux/blob/master/board/batocera/amlogic/s905/fun-r1/boot/s905_autoscript.txt This script defines memory addresses for kernel, initrd, and environment variables. It then attempts to load the uEnv.txt configuration file from USB or MMC devices, imports its settings, and conditionally loads the kernel, initrd, and device tree blob (FDT) before initiating the boot process. It supports booting from both USB drives and MMC/SD cards. ```shell setenv kernel_addr "0x11000000" setenv initrd_addr "0x13000000" setenv env_addr "0x1040000" setenv boot_start "bootm ${kernel_addr} ${initrd_addr} ${dtb_mem_addr}" if fatload usb 0 ${env_addr} uEnv.txt; then env import -t ${env_addr} ${filesize}; setenv bootargs ${APPEND}; if fatload usb 0 ${kernel_addr} ${LINUX}; then if fatload usb 0 ${initrd_addr} ${INITRD}; then if fatload usb 0 ${dtb_mem_addr} ${FDT}; then run boot_start; fi; fi; fi; fi; if fatload usb 1 ${env_addr} uEnv.txt; then env import -t ${env_addr} ${filesize}; setenv bootargs ${APPEND}; if fatload usb 1 ${kernel_addr} ${LINUX}; then if fatload usb 1 ${initrd_addr} ${INITRD}; then if fatload usb 1 ${dtb_mem_addr} ${FDT}; then run boot_start; fi; fi; fi; fi; if fatload mmc 0 ${env_addr} uEnv.txt; then env import -t ${env_addr} ${filesize}; setenv bootargs ${APPEND}; if fatload mmc 0 ${kernel_addr} ${LINUX}; then if fatload mmc 0 ${initrd_addr} ${INITRD}; then if fatload mmc 0 ${dtb_mem_addr} ${FDT}; then run boot_start; fi; fi; fi; fi; ``` -------------------------------- ### Read and Write Unix Settings Source: https://context7.com/batocera-linux/batocera.linux/llms.txt Provides methods to interact with Batocera's key=value configuration files. It covers loading settings, retrieving system-specific or global configurations, iterating through keys, and saving modifications. ```python from configgen.settings.unixSettings import UnixSettings from configgen.batoceraPaths import BATOCERA_CONF settings = UnixSettings(BATOCERA_CONF) snes_settings = settings.get_all('snes') for key, value in settings.get_all_iter('controllers', keep_name=True): print(f"{key} = {value}") settings.save('snes.shader', 'crt/crt-geom') settings.write() ``` -------------------------------- ### Define System and Emulator Configuration in Python Source: https://context7.com/batocera-linux/batocera.linux/llms.txt This snippet demonstrates the Python dictionary structures used to define system metadata and emulator availability within Batocera. These structures are used by the configgen system to map game systems to their respective emulator backends. ```python system_data = { "name": "Super Nintendo Entertainment System", "manufacturer": "Nintendo", "release": "1990", "hardware": "console", "path": "snes", "extensions": ["sfc", "smc", "fig", "swc", "zip", "7z"], "platform": "snes", "group": "nintendo" } emulator_data = { "libretro": { "snes9x": {"default": True}, "bsnes": {"default": False}, "mesen-s": {"default": False, "incompatible_extensions": ["zip"]} }, "mednafen": { "snes": {"default": False} } } ``` -------------------------------- ### Automated U-Boot Boot Sequence Source: https://github.com/batocera-linux/batocera.linux/blob/master/board/batocera/amlogic/s905gen3/tvbox-gen3/boot/boot.scr.txt This script automates the boot process by scanning for uEnv.txt on multiple storage devices. It dynamically sets boot arguments, including MAC addresses, and loads the necessary kernel components into memory for execution. ```U-Boot Script echo "start mainline u-boot" setenv loadaddr "0x44000000" setenv l_mmc "0 1 2 3" for devtype in "usb mmc" ; do if test "${devtype}" = "mmc"; then setenv l_mmc "1" fi for devnum in ${l_mmc} ; do if test -e ${devtype} ${devnum} uEnv.txt; then load ${devtype} ${devnum} ${loadaddr} uEnv.txt env import -t ${loadaddr} ${filesize} setenv bootargs ${APPEND} if printenv mac; then setenv bootargs ${bootargs} mac=${mac} elif printenv eth_mac; then setenv bootargs ${bootargs} mac=${eth_mac} fi if load ${devtype} ${devnum} ${kernel_addr_r} ${LINUX}; then if load ${devtype} ${devnum} ${ramdisk_addr_r} ${INITRD}; then if load ${devtype} ${devnum} ${fdt_addr_r} ${FDT}; then fdt addr ${fdt_addr_r} booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} fi fi fi fi done done ``` -------------------------------- ### Configure Light Gun Support Source: https://context7.com/batocera-linux/batocera.linux/llms.txt Handles detection and pre-calibration of light gun hardware. It allows checking for specific gun requirements like crosshairs or borders and integrates with system-specific calibration data. ```python from configgen.gun import Gun, guns_need_crosses guns = Gun.get_all() for gun in guns: print(gun.name) guns = Gun.get_and_precalibrate_all(system, rom) if guns_need_crosses(guns): pass ``` -------------------------------- ### Define Controller Input Mappings Source: https://context7.com/batocera-linux/batocera.linux/llms.txt Demonstrates the Input class usage for defining specific button, axis, and hat mappings for controllers. ```python from configgen.input import Input button_input = Input(name="a", type="button", id="0", value="1", code="304") axis_input = Input(name="joystick1left", type="axis", id="0", value="-1", code="0") hat_input = Input(name="up", type="hat", id="0", value="1") ``` -------------------------------- ### Emulator Configuration Management Source: https://context7.com/batocera-linux/batocera.linux/llms.txt The Emulator class manages configuration merging from multiple sources including global settings, system-specific overrides, and game-specific settings. ```APIDOC ## Emulator Configuration Class ### Description Handles the loading and merging of emulator settings based on a strict precedence hierarchy, ranging from system defaults to specific game overrides. ### Usage ```python from configgen.Emulator import Emulator system = Emulator(args, rom) # Access configuration via system.config ``` ### Configuration Precedence 1. configgen-defaults.yml 2. configgen-defaults-arch.yml 3. batocera.conf global settings 4. batocera.conf system settings 5. batocera.conf folder settings 6. batocera.conf game settings 7. Command line arguments ``` -------------------------------- ### Generate System Compatibility Table with jQuery Source: https://github.com/batocera-linux/batocera.linux/blob/master/package/batocera/emulationstation/batocera-es-system/batocera_systemsReport.html This function retrieves system data from a JSON source and iterates through architectures, emulators, and cores to build a comprehensive compatibility matrix. It uses jQuery to manipulate the DOM and integrates the Tippy.js library for interactive tooltips. ```javascript $(function() { $.getJSON("batocera_systemsReport.json", function(data) { var tab = ""; tab += ""; $.each(data, function(arch, arch_data) { tab += ""; }); tab += ""; var one_arch = Object.keys(data)[0]; $.each(data[one_arch], function(system, one_arch_system_data) { var n = 1; $.each(one_arch_system_data["emulators"], function(one_emulator, one_arch_emulator_data) { $.each(one_arch_emulator_data, function(one_core, one_arch_core_data) { tab += ""; if(n == 1) { tab += ""; } tab += ""; $.each(data, function(arch, arch_data) { $.each(arch_data[system].emulators, function(emulator, emulator_data) { $.each(emulator_data, function(core, core_data) { if(emulator == one_emulator && core == one_core) { if(core_data.enabled) { tab += ""; } else { tab += ""; } } }); }); }); tab += ""; n++; }); }); }); tab += "
SystemEmulator" + arch + "
" + one_arch_system_data.name + "" + (one_emulator == one_core ? one_emulator : one_emulator + "/" + one_core) + ""; if(core_data.default && arch_data[system].nb_all_variants != 1) tab += ""; if(core_data.explanation) tab += "."; else tab += ""; $.each(core_data.flags, function(n, flag) { tab += "" + flag + ""; }); tab += "
"; $("#id_table").html(tab); tippy('[data-tippy-content]'); }); }); ``` -------------------------------- ### Controller Configuration Source: https://context7.com/batocera-linux/batocera.linux/llms.txt Details on how controllers are detected, mapped, and configured using the Controller class and SDL. ```APIDOC ## Controller Configuration ### Description This section covers the controller handling within Batocera Linux. It explains how controllers are automatically detected, mapped using the `Controller` class, and how to generate SDL-compatible controller configuration strings. It also details the structure of input mappings for buttons, axes, and hats. ### Controller Class #### Description The `Controller` class is responsible for managing detected game controllers. It automatically maps inputs based on the SDL2 game controller database and provides attributes for controller identification, player number, device path, and input mappings. The `write_sdl_controller_db` function helps in creating a database file for SDL applications. ### Method N/A (Python Class Definition) ### Endpoint N/A ### Parameters #### Controller Class Attributes - **name** (string) - The name of the controller (e.g., "Xbox 360 Controller"). - **guid** (string) - The unique GUID of the controller. - **player_number** (int) - The player number assigned to the controller (1-indexed). - **device_path** (string) - The system path to the controller device (e.g., "/dev/input/event0"). - **inputs** (dict) - A dictionary mapping input names (e.g., "a", "b", "joystick1left") to `Input` objects. #### Controller Class Methods - **load_for_players(max_players, args)**: Static method to load controllers for a specified number of players. - **generate_sdl_game_db_line()**: Generates a string formatted for the SDL_GAMECONTROLLERCONFIG environment variable. - **get_mapping_axis_relaxed_values()**: Retrieves calibration data for analog axes. #### Utility Function - **write_sdl_controller_db(controllers, filepath)**: Writes the controller database to a specified file. ### Request Example ```python from configgen.controller import Controller, write_sdl_controller_db # Load controllers for up to 8 players controllers = Controller.load_for_players(max_players=8, args=args) # Access controller attributes controller = controllers[0] print(controller.name) print(controller.guid) print(controller.player_number) print(controller.device_path) print(controller.inputs) # Generate SDL configuration string sdl_config = controller.generate_sdl_game_db_line() # Write controller database file write_sdl_controller_db(controllers, "/tmp/gamecontrollerdb.txt") # Get axis calibration data relaxed = controller.get_mapping_axis_relaxed_values() ``` ### Response N/A (Python Class Definition) #### Success Response (200) N/A #### Response Example ``` # Example output for controller.name: "Xbox 360 Controller" # Example output for controller.guid: "030000005e0400008e02000014010000" # Example output for sdl_config: "030000005e0400008e02000014010000,Xbox 360 Controller,platform:Linux,a:b0,b:b1,..." ``` ### Controller Input Mapping #### Description Input objects represent individual controller inputs like buttons, axes, or hats. They are loaded from EmulationStation's input configuration files (`es_input.cfg`). #### Input Object Attributes - **name** (string) - The logical name of the input (e.g., "a", "joystick1left", "up"). - **type** (string) - The type of input: "button", "axis", or "hat". - **id** (string) - The identifier for the input (often "0" for simple inputs). - **value** (string) - The current value or state of the input (e.g., "1" for pressed button, "-1" for negative axis direction). - **code** (string, optional) - The underlying Linux input code (e.g., "304" for BTN_SOUTH on buttons, "0" for ABS_X on axes). #### Request Example ```python from configgen.input import Input # Button input example button_input = Input( name="a", type="button", id="0", value="1", code="304" # Linux input code BTN_SOUTH ) # Axis input example axis_input = Input( name="joystick1left", type="axis", id="0", value="-1", # Negative direction code="0" # ABS_X ) # Hat (D-pad) input example hat_input = Input( name="up", type="hat", id="0", value="1" ) ``` ``` -------------------------------- ### Access Standard Batocera Paths Source: https://context7.com/batocera-linux/batocera.linux/llms.txt Demonstrates the use of standard path constants defined in batoceraPaths.py and utility functions for filesystem operations like directory creation and safe file opening. ```python from configgen.batoceraPaths import SAVES, CONFIGS, mkdir_if_not_exists, ensure_parents_and_open mkdir_if_not_exists(SAVES / "myemulator") with ensure_parents_and_open(CONFIGS / "myemu" / "config.ini", "w") as f: f.write("[Settings]\nfullscreen=true\n") ``` -------------------------------- ### Configure FDT in uEnv.txt for Batocera Linux Source: https://github.com/batocera-linux/batocera.linux/blob/master/board/batocera/amlogic/s905/fun-r1/boot/README.txt This configuration snippet shows how to specify the Device Tree Blob (FDT) file within the uEnv.txt file for Batocera Linux. This is crucial for booting on specific hardware, such as the TX3 Mini, by pointing to the correct kernel device tree. Ensure the path to the .dtb file is accurate for your hardware. ```text FDT=/boot/meson-gxl-s905x-p212.dtb ``` -------------------------------- ### Light Gun Support Source: https://context7.com/batocera-linux/batocera.linux/llms.txt API for detecting, configuring, and pre-calibrating light gun hardware. ```APIDOC ## Light Gun Configuration ### Description Handles automatic detection of light guns and provides access to hardware properties like mouse index, button maps, and calibration data. ### Key Functions - **Gun.get_all()**: Returns a list of connected light gun devices. - **Gun.get_and_precalibrate_all(system, rom)**: Retrieves guns with pre-applied calibration data. - **guns_need_crosses(guns)**: Boolean check to determine if crosshair overlays are required. ``` -------------------------------- ### Build Individual Packages for Batocera Linux (Bash) Source: https://context7.com/batocera-linux/batocera.linux/llms.txt Commands for rebuilding specific packages within the Batocera Linux build system without compiling the entire image. This is useful for development and debugging individual components like RetroArch or the kernel. ```bash make x86_64-pkg PKG=retroarch make x86_64-pkg PKG=linux make x86_64-pkg PKG=batocera-configgen make x86_64-shell make x86_64-shell CMD="ls /build/output" ```