### Bash Script Template for Knulli Datainit Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/package/system/knulli-datainit/datainit/system/template-custom.txt This is a template for a custom script executed on boot and shutdown. It includes a shebang, logging setup, and conditional execution based on the script's argument. ```bash #!/bin/bash # This is a template for the custom script that will be launched on boot # and shutdown, after the gamelist has finished scanning. The first line here # is the shebang; the binary that should be called to execute it. # Rename this file to custom.sh to enable it. # This is an example file on changing the timezone. # Set logfile location and filename logfile=/tmp/scriptlog.txt # Test for the condition to avoid running the script after booting has succeeded. if test "$1" != "start" then exit 0 fi # Set the timezone. TZ=Europe/Paris hwclock --systz --localtime # Write to the log file, result should be a text file with three blank lines. echo "$1" > $logfile echo "$1" >> $logfile ``` -------------------------------- ### Patching Homebrew with DLDI Tool Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/board/rockchip/rk3566/fsoverlay/usr/share/drastic_aarch64/drastic_readme.txt Example command to patch a DLDI-compliant homebrew ROM using dlditool and an R4 DLDI file. ```bash dlditool r4ts.dldi ``` -------------------------------- ### Optimize JPGs with jpegoptim and jpegtran Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/package/emulationstation/knulli-es-system/roms/xash3d_fwgs/images/README.md Strips all metadata from JPG files and then optimizes them for progressive display. Ensure you have jpegoptim and jpegtran installed. ```sh jpegoptim --strip-all *.jpg for f in *.jpg; do jpegtran -progressive -copy none -outfile $f -optimize $f; done ``` -------------------------------- ### Example Custom Cheat File Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/board/rockchip/rk3566/fsoverlay/usr/share/drastic_aarch64/drastic_readme.txt An example of a custom cheat file for Mario Kart. The cheat code consists of multiple lines of hexadecimal values. ```text [Always Be Shyguy]+ 923cdd40 0000000c 023cdd40 00000001 d2000000 00000000 94000130 fffb0000 023cdd40 0000000c d2000000 00000000 ``` -------------------------------- ### Game Control Functions Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/package/emulationstation/knulli-es-web-ui/web/index.html Functions to interact with the game backend. Use `reloadGamelists` to refresh game data, `emuKill` to terminate the emulator process, and `launchGame` to start a specific game. ```javascript function reloadGamelists() { fetch('/reloadgames'); } function emuKill() { fetch('/emukill'); } function launchGame(game) { fetch('/launch', { method: 'POST', headers: {'Content-Type':'application/x-www-form-urlencoded'}, body: game }); } ``` -------------------------------- ### Initialize WebSocket and Load Systems Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/package/emulationstation/knulli-es-web-ui/web/index.html Sets up the document ready handler to fetch the list of systems and establish a WebSocket connection for real-time updates. It configures the WebSocket to parse incoming JSON data and update the display. ```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); console.log("WebSocket connection closed"); }; }); $('#myCarousel').carousel(); ``` -------------------------------- ### Bash Script for Game Start/Stop Events Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/package/system/knulli-datainit/datainit/system/scripts/template-game-start-stop.txt This script template is designed to be executed on game watch events. It logs the event type (gameStart or gameStop) and parameters to a log file. Rename to script01.sh and make executable to use. ```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 ``` -------------------------------- ### Creating a DLDI Image File on Linux Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/board/rockchip/rk3566/fsoverlay/usr/share/drastic_aarch64/drastic_readme.txt Commands to create a raw disk image file for DLDI patching. Replace with the desired size. ```bash dd if=/dev/zero of=drastic_dldi.img bs=1M count= of=drastic_dldi.img mkdosfs drastic_dldi.img ``` -------------------------------- ### Generate Systems Report Table with jQuery Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/scripts/linux/systemsReport.html Fetches system data from a JSON file and constructs an HTML table to display it. Use this to dynamically populate a table with system and emulator information. ```html Systems Report
``` -------------------------------- ### Ramdisk Boot Configuration Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/board/actions/atm7039/rg35xx/uEnv.txt Sets the operating system type to Linux and defines kernel boot arguments for ramdisk booting. ```shell uenvcmd=setenv os_type linux; bootargs=earlyprintk clk_ignore_unused selinux=0 init=/init ``` -------------------------------- ### Load Games via AJAX Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/package/emulationstation/knulli-es-web-ui/web/index.html Fetches game data for a given system name from the '/systems/:name/games' endpoint. It parses the JSON response, sorts the games by name using `getOrder`, and then displays them using `showGames`. ```javascript function loadGames(name) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var myArr = JSON.parse(this.responseText); myArr.sort(getOrder("name")); showGames(myArr); } }; xhr.open('GET', '/systems/' + name + '/games'); xhr.send(); } ``` -------------------------------- ### Mounting a DLDI Image File Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/board/rockchip/rk3566/fsoverlay/usr/share/drastic_aarch64/drastic_readme.txt Commands to mount the created DLDI image file for file transfer. Ensure the mount directory is empty. ```bash mkdir sudo mount -t vfat drastic_dldi.img -o loop ``` -------------------------------- ### Generate System Report Table Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/package/emulationstation/knulli-es-system/knulli_systemsReport.html This JavaScript code fetches system data from a JSON file and dynamically generates an HTML table to display system and emulator information, including status flags and details for each architecture. It uses jQuery for AJAX calls and DOM manipulation, and the tippy.js library for tooltips. ```javascript $(function() { $.getJSON("batocera_systemsReport.json", function(data) { var tab = "" // archs tab += "" tab += "" $.each(data, function(arch, arch_data) { tab += "" }) tab += "" tab += "" // systems var any_arch = "" $.each(data, function(arch, arch_data) { one_arch = arch }) tab += "" $.each(data[one_arch], function(system, one_arch_system_data) { // core 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) { // system var nb_system_cores = one_arch_system_data["nb_all_variants"] tab += "" } // core tab += "" // each arch core $.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) { if(arch_data[system].red_flag) { if(core_data.explanation) { tab += "" } else { if(arch_data[system].red_flag && !core_data.explanation) { tab += "" } else { tab += "" } } } }) }) }) tab += "" n++ }) }) }) tab += "" tab += "
SystemEmulator" tab += arch tab += "
``` ```javascript tab += one_arch_system_data.name tab += "" if(one_emulator == one_core) { tab += one_emulator } else { tab += one_emulator + "/" + one_core } tab += "" } else { tab += "" } } else { tab += "" } 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 += " ``` ```javascript switch(flag) { case "overclocking": tab += "" break; case "slow_games": tab += "" break; case "opengl3.0": tab += "" break; default: tab += flag } tab += "" }) tab += "
" $("#id_table").html(tab) tippy('\\[data-tippy-content\\]') }) }) ``` -------------------------------- ### Describe Game/System Information Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/package/emulationstation/knulli-es-web-ui/web/index.html Formats and displays detailed information about the currently running game or system, including images, system name, and game name. Handles cases where no game is running or the notification service is unreachable. ```javascript function describe(d) { var out = ""; var rlogo = null; if (d.msg) { if (d.msg == "NO GAME RUNNING") { out += '
No game running
'; return (out); } if (d.msg == "ERROR") { out += '
Notification service unreachable
'; return (out); } } out += '
'; if (d.image) { out += '
'; } else if (d.thumbnail) { out += '
'; } out += '
'; if (d.systemName) { var url = "/systems/" + d.systemName + "/logo"; fetch(url) .then( response => response.blob() ) .then((blob) => { const imgE = document.createElement('img'); const imgUrl = URL.createObjectURL(blob); imgE.src = imgUrl; imgE.style.height = "24pt"; const container = document.getElementById("sysName"); container.innerHTML=''; container.appendChild(imgE); }); out += '
' + d.systemName +'
'; } if (d.name) { out += '
' + d.name +'
'; } out += '
'; return (out); } ``` -------------------------------- ### Generate System List HTML Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/package/emulationstation/knulli-es-web-ui/web/index.html Generates the HTML string for displaying a list of systems, including logos and buttons, within a carousel structure. It handles pagination and dynamic content loading. ```javascript function showSystems(arr) { var nb_sys = 3; var out = ''; // carousel-item out += '' + // carousel-inner '' + '' + ''; // carousel-slide container document.getElementById("systemList").innerHTML = out; } ``` -------------------------------- ### Custom Cheat File Format Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/board/rockchip/rk3566/fsoverlay/usr/share/drastic_aarch64/drastic_readme.txt Defines the structure for custom cheat files. Ensure the cheat name ends with a '+' to be activated. Place these files in the appdata/DraStic/cheats directory. ```text [Cheat Name]+ ``` -------------------------------- ### Display Systems Carousel Source: https://github.com/knulli-cfw/knulli-linux/blob/knulli-main/package/emulationstation/knulli-es-web-ui/web/index.html Generates HTML for a carousel of system buttons. It filters out invisible systems, then creates carousel items, each containing a row of system buttons with logos and click handlers to load games. ```javascript function showSystems(arr) { const nb_sys = 6; var out = '