© Liz Clark 2019
Liz ClarkPractical Tinker Boardhttps://doi.org/10.1007/978-1-4842-3826-4_7

7. Project 1: Build a Game Emulation System

Liz Clark1 
(1)
Boston, MA, USA
 

We’ve spent the last few chapters getting acquainted with the Tinker Board, covering all the basics from the architecture of its system on a chip (SoC) to running a full OS and finally running code that interfaces with electrical circuits attached to its GPIO pins. That’s a lot to go over, and we’ve only scratched the surface. Now it’s time to take what we’ve learned and apply it to projects that will take the Tinker Board to the next level as a practical tool. The first project that we’re going to look at has become an increasingly popular project among single-board computer users: a game emulation system.

What Is Emulation?

Game emulation is a software-based process that emulates the hardware characteristics of gaming systems or computer architectures. This allows your computer or other device to run games or other programs that would otherwise be incompatible. Single-board computers are great choices for emulator hardware because of their form factor, system specs, and ability to run Linux. This makes the Tinker Board and Tinker Board S especially appealing as emulation hardware with their higher-than-average SoC specs.

Even though game emulation is often targeted at hardware that is much older and underpowered compared to modern hardware, system specs do matter. You may think that if you’re trying to emulate a system that had utilized an 8-bit architecture you don’t have to worry about the speed of your CPU or amount of RAM, but because everything is software-based, system specs become a paramount concern and the higher the spec the better. An underpowered system can ruin an emulation experience and render the emulator and emulated program unusable.

There are many ways to emulate games, and often your final choice will come down to preference. For this project we’re going to look at a specialized Linux distribution option for gaming emulation called Lakka. We’ll walk through how to set up and navigate Lakka for the Tinker Board.

ROMs

Before we go any further, though, we need to address the elephant that always sneaks into the room during any discussion on game emulation: the legality of ROMs. ROM stands for read-only memory and is a reference to the chips found on old game cartridges that held the game data that would be read by the gaming system. Despite its hardware origin, the term ROM has come to be used for the digital files of these old games and programs.

There is a lot of debate and discussion surrounding the use of ROMs for off-the-shelf games that would have been purchased in cartridge form back in the day. Is their very existence legal, let alone their active use inside emulation software? These legal considerations vary based on your location and the original game publisher’s specifications for each game, so be sure to do your research.

There are games and other programs available that do not carry these considerations, though, such as games that exist in the public domain, open source projects, and games made by independent developers, often called homebrew games.

Lakka

The emulation OS that we’re going to use here is Lakka. As previously stated, Lakka is a specialized Linux distribution for retro gaming emulation. It’s a fork of another Linux distro called LibreELEC that we’ll also look at in the next chapter.

Lakka is built on top of RetroArch, which is an open source project for a front-end API that many emulators are based on. RetroArch has been ported to run on many platforms as a standalone program, from modern game consoles to desktop Windows computers. As a front-end, RetroArch controls the GUI, controller inputs, video settings, and similar settings for the emulators.

The actual emulation process takes place on the back end with what are called cores that are built with Libretro, an additional open source project that is built in tandem with RetroArch. Each core is a different game system or older hardware emulator that can be loaded into RetroArch to run corresponding ROMs. The cores take care of the processing and running the code behind the scenes, making Libretro and RetroArch a great pairing of software.

Lakka’s purpose in all of this is basically to load RetroArch upon boot. Instead of implementing the traditional Linux desktop or other GUI, Lakka has only the basics necessary to boot up and load RetroArch automatically. As a result, no other software can really be loaded onto Lakka. Its sole purpose is to run RetroArch. With this setup you are setting yourself up for the best possible emulation experience, since your hardware will not be tied up with any additional back-end processes aside from running the emulators.

Downloading and Installing Lakka

To download the Lakka disk image, we need to navigate to its main builds page at le.builds.lakka.tv, which is separate from the main Lakka web site. This page has every single build available for a multitude of different hardware, some of which would be considered beta or even alpha builds. As of the writing of this chapter, Lakka is not considered to be 100% stable for full release for the Tinker Board, which is why the Tinker Board’s build is located on this page.

Once you’ve navigated to le.builds.lakka.tv, scroll down the page to the Rockchip.Tinkerboard.arm/ link, as shown in Figure 7-1.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig1_HTML.jpg
Figure 7-1

The link to the Lakka builds for the Tinker Board

Click that link to access the different image files available for the Tinker Board. We want to use the most recent release with the img.gz file extension, which at the time of writing is the 2.1 release dated 22-Nov-2017 12:38 as shown in Figure 7-2. Click on that disk image to begin downloading.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig2_HTML.jpg
Figure 7-2

A list of the available Lakka disk images for the Tinker Board. Notice the version numbers, file extensions, and dates.

Next reformat your microSD card or the eMMC flash module on the Tinker Board S, following the directions in Chapter 3. As with any operating system install, it’s important to start with fresh media for best results.

Note

It’s recommended to use a storage device with a capacity of at least 16GB and a speed of at least 10Mbps. Otherwise, you may run into compatibility issues.

After a fresh reformat, open Etcher, the program we used in Chapter 3 to burn the TinkerOS and Android disk images. Select the newly downloaded Lakka disk image in Etcher and choose your microSD card or eMMC flash on the Tinker Board S as the targeted disk, and then flash the Lakka image, as shown in Figure 7-3.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig3_HTML.jpg
Figure 7-3

The Lakka disk image loaded into Etcher

First Boot

After flashing the Lakka image to your selected storage device, you can power up the Tinker Board for the first boot. Much as it does with other operating systems, the first boot takes a bit longer than subsequent boots. During Lakka’s first boot, the file system will be resized and then finally boot into the landing page for RetroArch.

Here will be a test of whether your chosen storage is too small or too slow. If Lakka seems to get stuck at all, that is probably the case. Again, it’s recommended to use a storage device that is at least 16GB and has speeds comparable to SDHC cards.

The landing page for RetroArch on Lakka has a light blue background with a swirling wave animation by default. Since Lakka is a gaming OS, you have a few choices for GUI navigation. You can stick with a keyboard and use the arrows, Enter, and backspace keys for navigation, or you can use a gamepad. This can be connected via either USB or Bluetooth (after you enable Bluetooth within Lakka, which we will go over shortly) . For navigation, there are tile icons at the top of the GUI for different setting categories. From left to right by default are the Main Menu, Settings, Favorites, History, Netplay Rooms and Import Content, as shown in Figure 7-4.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig4_HTML.jpg
Figure 7-4

The Lakka GUI

Navigating Lakka: the Main Menu

The Main Menu category allows you to quickly adjust the main functions in RetroArch. The Load Core menu lists all the cores available by default in Lakka, as shown in Figure 7-5. You can select different cores to use for different system emulations or check here if you upload a core that is not included by default.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig5_HTML.jpg
Figure 7-5

The Load Core menu. All of these cores are built with libretro.

Load Content allows you to load ROMs, media, and other files that you’ve added into Lakka’s file system. The Online Updater lets you update Lakka in case there is a new build available, making it basically a GUI version of sudo apt-get update and upgrade. The Thumbnails Updater has options to update the thumbnails for ROMs, and finally the Content Downloader offers other emulation engines and add-ons that are available and compatible with Lakka but for various reasons, such as storage space concerns or niche popularity, are not included by default in Lakka. You can choose any of these from the list to download and install, as shown in Figure 7-6.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig6_HTML.jpg
Figure 7-6

The Content Downloader menu

Note

In order for any options to appear in the Content Downloader menu, you need to have the Tinker Board connected to the Internet.

The Information tab has information available for the network, the system, databases, and search history. The Network Information basically houses your IP address, which we’ll be referencing shortly in this chapter. System Information shows information about the Lakka build version that you’re running and your system specs, as shown in Figure 7-7. The Database Manager shows the different emulation databases installed, and the Cursor Manager shows the system’s search history.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig7_HTML.jpg
Figure 7-7

The System Information for the Tinker Board in Lakka. Some of these specs will look quite familiar now.

The last three options on the Main menu are utilities for Lakka. Quit RetroArch exits the program (and then goes right back into it since there is nothing else to run on Lakka besides RetroArch), Reboot reboots the system, and Shutdown safely shuts everything down.

Settings

The Settings menu offers more detailed options for Lakka, such as Video, Audio and Interface settings. Under Video, you can fine-tune how your ROMs will run. This can be especially important with older games from the 1980s and early 90s that were meant to be played on CRT monitors, which displayed and processed video signals much differently than today’s LCD monitors. The games were often programmed to work with the CRT technologies, and this often translates poorly to modern displays. There are ways around this in software, though, and the cores take care of a lot of it; but retro gaming aficionados will have preferences that can be adjusted here, such as V-Sync, Integer Scale, and Aspect Ratio as shown in Figure 7-8.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig8_HTML.jpg
Figure 7-8

The Video Settings page

Audio settings allow you to mute or unmute audio, adjust the overall volume level, and choose your audio device. Input allows you to set up hotkeys for your chosen controller, and the User Interface has editable options for Lakka’s appearance. You can edit which items are available on the menu screen, set up kiosk mode, and customize the appearance of Lakka. Kiosk mode lets you run Lakka so that no one can edit the settings. This can be handy for setups where your device is going to be publicly available. For the Appearance options, you can set up a custom background image, change the icon theme, adjust the color theme, and change thumbnail options for ROMs as shown in Figure 7-9.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig9_HTML.jpg
Figure 7-9

Editable Appearance options for Lakka. Much like other operating systems we’ve looked at, the GUI has a lot of customization options.

Wi-Fi lets you connect to a wireless network. Simply select it from the menu, and Lakka will scan for available networks. Once yours appears, select it and enter your password. You’ll now be connected to Wi-Fi. You won’t need to be connected to the Internet to successfully use Lakka, but it can be useful for some tasks.

The Services tab allows you to toggle on and off SSH, Samba, and Bluetooth, as shown in Figure 7-10. SSH provides remote access to the command line. Since Lakka does not have an easily accessible terminal, this can be very handy. You’ll just need an SSH client on another computer to connect to the Tinker Board. Samba is open source software that enables file sharing across different platforms over a network. This means that Windows, Apple, and Linux systems can all share files with a lot of back-end work. By enabling Samba in Lakka, you can share files between your Lakka build on the Tinker Board and your main system. The final service is Bluetooth, which allows you to connect Bluetooth devices, in particular Bluetooth controllers.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig10_HTML.jpg
Figure 7-10

The Services menu. All three Services can be toggled on or off

Favorites, History, Netplay, and Import Content

Moving on to the last few menus, Favorites will eventually populate with ROMs that you mark as favorites and add to playlists as mentioned earlier. History will also populate after you play a few games, showing the most recently played in a list. Netplay is a feature of RetroArch that allows you to play multiplayer games between two different builds of Lakka. Import Content is the utility used to import any media, including ROMs, into your Lakka install. We’ll go over how to do this shortly.

Importing ROMs into Lakka

Now that we’ve toured Lakka’s GUI, we can start using it properly by first loading in some ROMs. There are a few methods for loading ROMs and other content into Lakka. We’ll go over two methods that are OS-agnostic, meaning that no matter which desktop operating system you’re using, whether Windows, macOS, or Linux, you’ll be able to follow these steps to load ROMs onto Lakka on the Tinker Board.

Loading ROMs over the Network

The first method we’ll discuss is loading ROMs over the network from your computer to the Tinker Board. To do this, both devices need to be on the same network, either wirelessly or wired. For Lakka, make sure you either enable and connect to Wi-Fi as discussed earlier in the chapter or connect an Ethernet cable to the Tinker Board.

Once the Tinker Board is online, go to your computer and open your file browser. Enter your Tinker Board’s IP address, which can be found under Main Menu ➤ Information ➤ Network Information in Lakka, at the top of your file directory’s window using the proper IP syntax for your operating system.

After connecting to the Tinker Board’s IP address, you’ll see Lakka’s file system as shown in Figure 7-11. You’ll be able to add, remove, or edit any of the files within Lakka using this method, but for now we’re going to stick with adding ROMs.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig11_HTML.jpg
Figure 7-11

Lakka’s file system viewed remotely

You’ve probably figured out by looking at Figure 7-11 that ROMs are stored in the ROMs folder in Lakka. Open that folder and then open a second file directory window on your computer to navigate to your locally stored ROMs that you want to transfer to the Tinker Board.

Next, inside Lakka’s ROMs folder, create a new folder for each system that your soon-to-be-transferred ROMs will run on, as shown in Figure 7-12.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig12_HTML.jpg
Figure 7-12

A new folder has been created in Lakka’s ROMs folder, and your locally stored ROMs are queued up

For example, if you have ROMs for NES, create an NES folder and if you have ROMs for MAME, create a MAME folder. After creating that folder, open it and then drag and drop your locally stored ROMs to their destination folders on Lakka. You should see them appear in the folders as shown in Figure 7-13.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig13_HTML.jpg
Figure 7-13

Locally stored ROMs successfully copied to Lakka’s ROMs folder

Moving back to the Tinker Board, navigate to the Import Content header and select Scan Directory from the drop-down. After scanning, you’ll see the folders for the different systems that were created. Enter one of the folders and then select <Scan This Directory> as shown in Figure 7-14.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig14_HTML.jpg
Figure 7-14

The directory scan function for Lakka’s local ROMs folder

Messages will flash at the bottom of the screen that the directory is being scanned and then that the scanning is complete. Nothing else will show-up here to let you know that the ROMs were loaded successfully. To verify this, navigate to the Main Menu and then select Load Content. Under Load Content, select Collections, which is where the scanned items will appear. After entering Collections, you should see your newly scanned folder available. Enter that folder and you’ll see your ROMs, as shown in Figure 7-15.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig15_HTML.jpg
Figure 7-15

A list of ROMs added via the network. Both of these games are homebrewed by independent developers and as a result are a part of the public domain.

Loading ROMs over USB

If you have an exceedingly large ROM collection or you don’t want to connect your Lakka system to your network, you also have the option to load ROMs from a USB drive. To do this we first need to format the USB drive to a compatible format for Lakka. The preferred formats are FAT, NTFS, and exFat.

After formatting, simply copy your ROM files to the USB drive and connect it to the Tinker Board. You can now either scan the USB drive’s directory or search for individual ROM files on the USB drive. The drive will show-up as a folder in the directory listings, as seen in Figure 7-16.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig16_HTML.jpg
Figure 7-16

The USB drive mounted in Lakka

After scanning, your ROMs will appear in the Collections folder under Load Content, just as the ROMs previously imported via network did after scanning. If you don’t want to add a ROM permanently to your collection, you can also access the ROM by going to the Start Directory folder under Load Content. The USB drive will appear as a folder there, as shown in Figure 7-17, and ROMs will be selectable for play.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig17_HTML.jpg
Figure 7-17

The USB drive is also accessible under the Main Menu

Playing Games

To play a ROM, select it from Collections, Favorites, or other preferred location in Lakka. After selecting it, you’ll be greeted with a menu with the options Run, Add to Favorites, and Information, as shown in Figure 7-18.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig18_HTML.jpg
Figure 7-18

The ROM menu

If your ROM collection is large, you may want to create a Favorites list where you can easily access frequently played games. Information lists the full file name of the ROM, and Run starts the game. Once inside the game, you’ll use your preferred controller to play just as you would if playing on the original hardware.

Once a game is running, the Quick Menu will appear under the Main Menu. In the Quick Menu, you can access save states and other in-game settings that are unique to Lakka. This allows you to save your progress in games created for systems that wouldn’t traditionally allow save states or load ROMs from these save states. This menu is only available when a ROM is running in the background. Once the ROM is exited or the system is rebooted, the Quick Menu will disappear.

Connecting via SSH

Even though Lakka has a detailed GUI that lets you access almost every setting, you may find yourself missing the command line. Although accessing the terminal is not possible on single-board computer builds of Lakka at this time, you can access it remotely from a desktop computer.

First enable SSH under Settings ➤ Services on Lakka. After that, move to your desktop system. If you’re using macOS or Linux, you can simply open a terminal to log in via SSH. Once you open a terminal, type in ssh root@ followed by the IP of the Tinker Board with no spaces. For example, if your IP was 111.111.1.1 you would type ssh [email protected] and then hit enter to connect. You’ll then be prompted for a password, which is root.

SSH is not a built-in feature on Windows. As a result, you’ll need a third-party SSH client. A popular and simple one to use is called PuTTY.1 After downloading and installing PuTTY, select SSH and enter Lakka’s IP address as shown in Figure 7-19.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig19_HTML.jpg
Figure 7-19

PuTTY’s GUI window. Notice that SSH is selected as the connection type. Also note that your IP address will be different.

Click Open to initiate the connection, which will open a terminal window. You’ll be asked for the username, which is root, followed by the password, which is also root. After that, a message will appear in the terminal showing that you’ve successfully connected, as in Figure 7-20.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig20_HTML.jpg
Figure 7-20

A successful login to the Tinker Board running Lakka via SSH

Once you’re connected you can use any Linux terminal command. A useful scenario would be to use ls to see a list of file directories, as shown in Figure 7-21.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig21_HTML.jpg
Figure 7-21

The results of the ls command

You can also use cd to change directories and view, for example, the file directory for the ROMs folder, as shown in Figure 7-22.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig22_HTML.jpg
Figure 7-22

The results of the ls command in the ROMs folder

There is no need to use sudo when accessing the command line in Lakka, as it’s a LibreELEC build of Linux and does not require that clearance. If you do use sudo, you’ll get an error message like the one in Figure 7-23. You can reboot and shut down via the terminal as well, just as with other Linux distros, as also shown in Figure 7-23.
../images/465130_1_En_7_Chapter/465130_1_En_7_Fig23_HTML.jpg
Figure 7-23

The sudo command is not necessary when using the terminal with Lakka

Note

If you shut down the Tinker Board or exit the terminal window, you’ll close your SSH connection to the Tinker Board and will have to reconnect.

Wrapping Things Up

Using your Tinker Board as an emulation system is a fun and simple project that goes beyond the basic desktop tasks that we’ve looked at in previous chapters. The developers of Lakka have done a great job in porting over a build for the Tinker Board, which is a testament to the open source community. Keep in mind that as an end user of open source software you can also contribute to open source projects by simply reporting bugs to developers and with some experience testing pre-release builds. For now, let’s look at some more specialized Linux distros for the Tinker Board to build additional projects in the upcoming chapters.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.61.142