What is RetroPie?An open source project that transforms Raspberry Pi and other boards into gaming consoles.Github:https://github.com/RetroPie/RetroPie-SetupAt first glance, based on Shell, what’s so impressive about it?But upon reflection, a simple project achieving 9.4K stars must have its merits.The two most important things to achieve emulation of retro gaming consoles:1. An emulator that can simulate retro games.The most popular emulator is RetroArch.RetroArch itself does not emulate games but provides a unified framework for various lower-level emulators.RetroArch handles audio, display, and other basic functions while various emulator cores handle the actual game emulation.An emulator core can simulate a hardware platform, for example, mGBA can simulate the GBA handheld.2. A menu interface that allows users to select and launch games, known as a launcher.The most popular open-source launcher is EmulationStation.Another excellent open-source launcher is Pegasus:Pegasus is written in Qt, and if you’re interested, you can check its source code; the code quality is quite good.
Internal Implementation
I have read the source code of RetroPie for a while.The most profound feeling is: elegant and impressive.From a requirements perspective, the core functionality of RetroPie is to compile, install, and configure RetroArch, EmulationStation, and various emulator packages.For each package, RetroPie defines a set of functions:
function depends_${package}()
{
...
}
function sources_${package}()
{
...
}
function build_${package}()
{
...
}
function install_${package}()
{
...
}
function configure_${package}()
{
...
}
These correspond to the four steps of obtaining source code, compiling, installing, and configuring.Each package only needs to focus on implementing these four interfaces for the core layer of RetroPie to call.The core layer of RetroPie:system.sh, used to adapt to multiple hardware platforms.helpers.sh, contains various helper functions.packages.sh, related to the API for package management.When running RetroPie with retropie_setup.sh, all packages are first registered in the core layer and stored in an array.The relevant API is: rp_registerModule()When compiling and installing a package, for example, RetroArch, it will sequentially call the following functions in retroarch.sh through rp_callModule():
function depends_retroarch()
{
...
}
function sources_retroarch()
{
...
}
function build_retroarch()
{
...
}
function install_retroarch()
{
...
}
The core design of RetroPie consists of these elements, but the specific implementation involves many techniques worthy of our learning, which I will not elaborate on here.Additionally, the Shell coding style of RetroPie is excellent, and we can use it as a standard.I have written many shell scripts in my work, roughly categorized as:
Scripts for testing stability
Scripts for assisting in bug location
Automation scripts for daily work
Scripts for quickly building software prototypes
Internal company software
The most profound feeling is:Shell is a powerful tool; it’s fun to use, but be careful not to hurt yourself.
Conclusion:
RetroPie is an excellent open source project, and its functionality is not complex due to its outstanding design.What I learned from it:Doing simple functions well and stably is an impressive achievement.Many companies make boards, but only Raspberry Pi has achieved global popularity.Creating a good product is never just about ideas, abilities, or intelligence; it depends on whether you wholeheartedly consider the user and always start from the user’s perspective.References:https://retropie.org.uk/https://github.com/RetroPie/RetroPie-Setuphttps://www.retroarch.com/https://emulationstation.org/https://pegasus-frontend.org/ENDAuthor: Wu Weidong JackSource: Lao Wu EmbeddedCopyright belongs to the original author; if there is any infringement, please contact for deletion.▍Recommended ReadingDomestic MCU manufacturers are starting to compete…Sharing several high-star open-source projects related to embedded systems on GitHubTo become an embedded expert, you can’t miss these 100+ open-source hardware and software projects!→ Follow for more updates ←