__MAIN_TEXT__

Page 1

FR NL O W AR DO J AN M

NEW RASPBERRY Pi PICO

D .2 EE OA 20

Full review of the all-new, custom silicon Pi model: 1 Arm Cortex-M0 2 Costs $4 3 Microcontroller design

PLUS!

HOW TO…

UP YOUR CHESS GAME EMULATE THE BBC MICRO USE THE ZFS FILE SYSTEM

The #1 open source mag

BETTER VIRTUAL

MACHINES Effortlessly orchestrate your many VMs with the ultimate open source solutions

pages of tutorials & features

67

Decoding weather satellite radio signals Mind map your projects with open source tools

Get started with low-level assembly

Quickly build a maze runner game in Python

LXF March 2021

Pi MACHINE CODE AMAZING GAME CODE

Deploy Active Directory with Debian and Samba


WELCOME

WHO WE ARE This issue we’re orchestrating our many virtual machines. How many VMs do you have stacked up on your work system and what are you using them for? Jonni Bidwell I lost many a brave (and broken) virtual machines in the great RAID reformat of 2021, but new ones are starting to re-establish themselves. Mostly I like to have lots of Mint and Ubuntu VMs around to remind me how much easier my life would be if I didn’t use Arch.

Nick Peer I have VMs coming out of my ears on Mac, Windows and Linux machines running, er, Linux, Mac and Windows VMs. They’re used primarily for research, experimenting and – gulp – stress-testing security products. Also a good option for isolated BitTorrent clients running over VPNs…

Les Pounder Right now I don’t have any virtual machines in the traditional sense. I do have an Atari ST, Amiga 1200, BBC Micro, Commodore 64, Amstrad CPC464 and a Speccy hidden in there, though. Oh and I have a System 7.5 Mac emulated in JavaScript.

Orchestral Manoeuvres in the Docker Jonni’s been arguing with me this issue – he thinks Linux Format readers don’t need virtual machine orchestration. Of course, as always, he’s right, but I’ve never let being wrong stop me before… Just because you don’t actually “need” something doesn’t mean you don’t want to learn about it or try it out! Virtualisation has become such a common thing that it’s easy to take it for granted, but this also means there are better ways of managing your many virtual machines. Storing VMs on your local machine is fine, but it can become messy in terms of space and the numbers that can build up in your VirtualBox list, as an example. So this issue Jonni’s taking us through the virtual machine basics and then moving on to look at XCP-ng a network XenServer management system. It’s overkill for home users, but works a treat and is so easy to set up it seems wrong not to at least cover it. After reading our crammed feature you should have a better knowledge of how virtualisation works in general, but a better knowledge of how to manage your many, many virtual machines. It’s almost as bad as having children to home school! In the rest of the packed magazine we’ve got a collection of cool projects, tools and coding guides. Sean Conway outlines using a Pi to control dioramas, Neil Bothwick explores using the ZFS to better store your files, Nick Peers is looking into the Freeplane mind-map planner and John Schwartzman finishes his guide to assembly coding on the Raspberry Pi. Finally, Les Pounder brings us another breaking Raspberry Pi Pico review. We managed to sneak the review into the issue just as we were going to press. The Pi Foundation does it again cramming so many features into a $4 device. This microcontroller in many ways is better for smaller projects that the main Pi was still being used for. We’re sure we’ll be seeing much more of it in the future, so I hope you enjoy!

Mayank Sharma I use VMs for testing new distros and development releases, and discard them pretty often. The most I’ve had was when I needed to create a virtual lab (with about six VMs) for an article on mass deployment and cloning, and another time for testing gateway distros.

Neil Mohr Editor neil.mohr@futurenet.com

Shashank Sharma VMs are like cups of coffee. No such thing as too many. I’m kidding, of course. I get rid of the disk-space hogging VMs soon as I’m done with them. If only I was just as mercenary with my bookmarks…

Subscribe & save! NEW GIFT

www.techradar.com/pro/linux

On digital and print – see p24

March 2021 LXF273     3


Contents

PLUS!

REVIEWS

AMD Ryzen 5 5600X 

17

As Alan Dexter discovers, this chip may be the runt of the Zen 3 family, but it delivers where it counts most: gaming.

SUBSCRIBE NOW! Page 24

BETTER VIRTUAL

MACHINES Slackel 7.4 

18

Before he couldn’t work with Arch, he couldn’t work with Slackware, which is why Mayank Sharma jumps at everything that mentions the venerable distro.

RebornOS 2020.12.28 

19

The constant deluge of Arch-based distros can put anyone to sleep, but this one makes Mayank Sharma wake up from his slumber.

Rescuezilla 2.1 

20

With perennial fat fingers, Mayank Sharma has been messing with hard disks long enough to know that good rescue tools are worth their weight in gold.

Garuda Linux 210101 

21

Mayank Sharma has enjoyed one Archbased distribution this month, but will lightning strike twice or has he been taken in by the distro’s tall claims?

Wasteland 3 

Jonni Bidwell effortlessly orchestrates your many VMs with the ultimate open source solutions. More on page 32. ROUNDUP

IN-DEPTH

22

Management hates weirdos and snow, so this is a bad time of year for them and they’re taking it out on Jody Macgregor.

Game engines 

26

There’s never been a better time to take your first steps in to video game development on Linux. Michael Reed puts five capable engines under the microscope.

4     LXF273 March 2021

The Linux Gambit 

40

Jonni Bidwell once again sets a graphics card on fire, this time calculating winning positions as he prepares to take on open source chess engines…

www.linuxformat.com


CONTENTS ON YOUR FREE DVD

Pi USER Raspberry Pi news 

Manjaro 20.2 GeckoLinux 15 2 See page 96

45

Pi Foundation provides curriculum-level coding resources for home schooling, and a novel cooling solution for your Pi projects!

Raspberry Pi Pico 

46

An excitable Les Pounder gets up close and personal with the Raspberry Pi Pico!

Magic 8-ball project 

48

DVD pages 

50

Jonni Bidwell puts the popular Arch-based distro Manjaro 20.2 on the LXFDVD, along with the Cinnamon release of GeckoLinux, which has its roots in openSUSE.

Les Pounder shows how a versatile HAT board can answer all your questions.

Pi-powered helicopter diorama 

96

Sean Conway uses a helicopter model to demonstrate how lighting, sound and motion can be accomplished using a Raspberry Pi.

Connect and use gamepads 

TUTORIALS

54

Planning some Raspberry Pi gaming? Christian Cawley sets up a game controller both natively and with an emulator.

TERMINAL: Multiple window manager  56 Shashank Sharma uses the mouse and runs multiple windows in a text environment.

FREEPLANE: Construct mind maps  58

CODING ACADEMY Coding 64-bit assembly language 

Nick Peers reveals how you can manage all of your thoughts – from simple ideas to fully formed projects – with this free tool.

87

John Schwartzman writes 64-bit assembly code for the Pi, that calls on Linux kernel services and the C run-time library.

ZFS: Filesystem management 

Make a maze runner game in Python  92 One way in, and only one way out… video game aficionado Calvin Robinson reveals how to create a vintage maze runner-style game using Python.

EMULATION: Run a BBC Micro 

REGULARS AT A GLANCE 6

WhatsApp’s new privacy policy causes its users to desert the app, Linus Torvalds tears into Intel over ECC memory, and an affordable RISC-V PC arrives!

Kernel watch 

10

Jon Masters has the latest developments.

Mailserver 

12

A new PC errors when running distros in memory, a reader wonders if we can cover VPNs while another laments Ubuntu Software’s user-unfriendliness.

Answers  A home server suddenly won’t wake up, troubles with an old laptop reading discs, and accessing completed print jobs.

www.techradar.com/pro/linux

66

Les Pounder remembers the time when he caused a core meltdown in a nuclear reactor, then flew away in a spaceship.

RADIO: Weather satellites 

News 

62

Neil Bothwick takes a deep dive into this advanced volume manager and Swiss Army Knife of filesystems.

14

70

Weather satellites transmit signals that you can receive and decode to generate images of the Earth. Mike Bedford shows you how.

Subscriptions 

24

Overseas subscriptions 

44

Back issues 

74

SAMBA: Active Directory 

82

Stuart Burns takes you through the process of setting up a Linux-based Active Directory infrastructure and how to use it.

Get hold of previous Linux Format editions – but watch out, they’re selling out fast!

HotPicks 

75

Alexander Tolstoy tears himself away from the 24-hour news feeds, rolls up his sleeves and brings you more hot FOSS, including EiskaltDC++, TabFS, TuxPaint, Chipmunk, Darktable, EasyLogic Studio, Zenith, Tux vs. Yeti, Invasion, Qsnapstore and Dify.

DVD pages 

96

Next month 

98 March 2021 LXF273     5


Newsdesk

THIS ISSUE: Exodus from WhatsApp Intel under fire from Torvalds Affordable RISC-V computer Linux boots on Apple

PRIVACY

Is online privacy the hot topic for 2021? Users alarmed by WhatsApp’s new terms flock to alternative messaging tools offering better privacy. hatsApp’s loss is Signal and Telegram’s gain, after an influx of new users abandoned the Facebook-linked messaging app after a change to its terms and conditions raised awareness on the information they’re sharing when using the app. A new pop-up has appeared for the majority of WhatsApp users (though not in the UK and Europe), informing them that they must allow the app to share data with Facebook if they want to continue to use it. If they don’t accept the new terms by 15 May then they won’t be able to use the app or service. The data to be shared is phone numbers (both the users’ and from their address book), profile names and pictures, status messages and information about when a user was last online, as well as diagnostic information. You can read the the privacy policy at http://bit. ly/LXF273WhatsAppPrivacy. This change has worried a lot of users, especially those who had joined WhatsApp because of its end-to-end encryption, which promised greater privacy than some rival messaging services at the time. While the WhatsApp team go to great lengths to allay concerns, claiming that “respect for your privacy is coded into our DNA,” and promising that nothing you share in WhatsApp will be posted on Facebook. However, that hasn’t stopped people deciding to look for alternatives that better protect their privacy. A report by the BBC (http://bit.ly/ LXF273BBC) shows the impact of the change. Signal (https://signal.org), an alternative that

W

6     LXF273 March 2021

offers end-to-end encryptions, was downloaded 246,000 times globally the week before WhatsApp made the changes public (4 January). The week after, that number rose to 8.8 million. Telegram (https://web.telegram.org), another alternative, saw an even bigger leap, according to the BBC report, with global downloads of 6.5 million leaping to 11 million the week of the announcement. Meanwhile, WhatsApp’s global downloads dropped over the same period, from 11.3 million to 9.2 million. While we welcome the fact that more people are taking their privacy seriously and switching to more private apps, this won’t spell the end of WhatsApp, which remains popular – it’s been

WhatsApp’s changes to its T&Cs had led to users leaving the app.

“THIS CHANGE HAS WORRIED A LOT OF USERS, ESPECIALLY ONES WHO HAD JOINED WHATSAPP BECAUSE OF ITS END-TO-END ENCRYPTION” downloaded 5.6 billion times since it launched in 2014. And with the full privacy policy and terms of service running to over 8,000 words, many users may not fully appreciate what they’re agreeing to. What’s more, as the EFF points out (http://bit.ly/LXF273EFF), many of the most contentious changes happened four years ago with a previous privacy policy update. Still, as long as more people come to appreciate their privacy, at least it’s better late than never.

www.linuxformat.com


ANSWERS

Answers

Got a burning question about open source or the kernel? Whatever your level, email it to lxf.answers@futurenet.com server Q Sleepy I’ve upgraded my little home

server box to Ubuntu 20.04. It’s set to go into sleep mode and I use a phone-based Wake-on-LAN app to wake it up when I need it again. This used to work fine even when the system on rare occasion needed a reboot. But after the upgrade it no longer works after a reboot. I’ve followed a guide at http://bit. ly/lxf273wol to create a WOL systemd service, but it still won’t work after a reboot. I have to manually enable the WOL after which is fine until the next reboot. Any ideas? Neil Moore

A

Your systemd service isn’t starting up correctly. You can see this by running the following: $ systemctl status wol.service

You say it works when you enable Wakeon-LAN manually. I suspect that you mean you’re running the ethtool command given in the guide: $ ethtool -s INTERFACE wol g

where INTERFACE is the name of our ethernet interface. The Systemd unit from that guide is: [Unit] Description=Configure Wake On LAN [Service]

Type=oneshot ExecStart=/sbin/ethtool -s INTERFACE wol g [Install] WantedBy=basic.target

Ensure you’ve checked the spellings as always this is case sensitive. This may have worked with older distros, but Ubuntu 20.04 installs the ethtool executable in /usr/sbin not /sbin. If it looks like you need to change the path in your unit file to reflect this, you can check that it now works with: $ systemctl daemon-reload $ systemctl start wol.service $ systemctl status wol.service

The first command is needed any time you change a Systemd unit file as it caches these in memory when the system boots and won’t see any changes unless you force a reload of all unit files.

Q

Bootless DVDs

I’m trying to resurrect a Toshiba Satellite M45-5331 laptop. It has an Intel Pentium M 730 processor and 512MB of RAM. I’m able to boot various Linux distributions from CDs, but not any distribution that’s on a DVD, which I burned on my laptop. I can, however, boot from a Windows XP DVD and from several of the Linux Format DVDs.

Wake-on-LAN can be very useful, but it usually has to be enabled in your computer’s firmware menu and then again in software after booting.

14     LXF273 March 2021

Neil Bothwick is Dr Tux to you! Fixing all problems dead(ish)!

Incidentally, other computers are able to boot from the Linux DVDs that the Toshiba ignores. When I attempt to boot from a desktop-burned DVD there’s a message – “checking CD” – accompanied by suitable whirring and clicking from the drive. This persists for a minute or so, and then it moves on to boot from the hard drive (on which I’ve installed a Linux version contained on a CD). Is there a way to split the ISO between two or more CDs and boot from the combination, or some other clever workaround? Finally, why would the machine boot with “commercially prepared DVDs but not those burned using my desktop? I tried burning a DVD with a different computer, but got the same disappointing result. Richard Dawson

A

This is a rather old laptop, which could be at the root of your problem. Optical discs are read by reading the reflection of a laser from the surface of the disc, and there needs to be enough reflected light to obtain a reading. Anything that reduces this can cause issues. As hardware becomes older it can lose efficiency, meaning your drive’s laser may not be as powerful as it once was. Also, the lens used in the drive can gradually build up dirt, losing more light. There are drive cleaning discs that should clean the optics for you, but may be simpler to either replace the drive or use an external one. As to why the drive works with some discs and not others, that is the real clue to the problem. Commercial DVDs are pressed, using a completely different process to self-burned DVD-Rs. As a result, they’re more reflective, so your drive is able to cope with them even with reduced power. It’s also worth noting that DVD-RW discs have an even lower reflectivity than DVD-Rs, so if you are using rewritable discs, you may have more success using DVD-R or DVD+R (one shot) discs. Splitting an installation DVD between CDs is probably possible, and almost certainly a complex task: you’re basically

www.linuxformat.com


REVIEWS Linux distribution

Slackel 7.4 Before he couldn’t work with Arch, he couldn’t work with Slackware, which is why Mayank Sharma jumps at everything that mentions the venerable distro. IN BRIEF The distro is based on the Slackware project and borrows tools from the Salix distro, which is another Slackware derivative. However, unlike Salix, which follows stable Slackware releases, Slackel is based on Slackware’s -current development branch.

SPECS CPU: Pentium 2 and higher Memory: 512MB or at least 1GB for programs like LibreOffice and Firefox HDD: 10GB Build: Both 32and 64-bit

18     LXF273 March 2021

lackel is one of those few one-man distros that continues to be powered solely by the love and affection of its dedicated community of users. The distro’s Greek developer has just put out version 7.4, six months after the previous release. Slackel has multiple editions, each with a different desktop environment. However, as usual the first one out of the gate is the Openbox edition, with others to follow in due time. The distro mixes the best of both Slackware and Salix to create an interesting offering. For While Slackel defaults to GRUB, you can also install eLILO instead, which is something we haven’t seen Linux distributions offer for quite a while now. starters, Slackel is fully compatible with the repositories of both upstream distros, which gives it a far wider choice of and has textboxes to create a user and specify the programs than you’ll find in pure Slackware. password for the root user. Second, Slackel is based on Slackware’s The installer supports three installation modes. Core development branch (-current), rather than its stable installs without a desktop; Basic has a desktop and a release, which was last released back in 2016. Thanks to few programs; while Full installs a ready-to-use desktop. this, Slackel 7.4 includes the latest Linux kernel 5.10.4 Once installed, the distro looks and behaves like any LTS kernel along with various other recent updates. One other Openbox-wielding distro. It has all the usual tools of the highlights of this release is its support for 64-bit you’d expect in a desktop distro, along with a few extras. UEFI systems. Slackel is one of the few projects that still The distro uses the Gslapt package manager, which is a produces both 64- and 32-bit ISO images. Starting with Synaptic lookalike frontend to the slapt-get package this release, you can now use the 64-bit images to boot management system, which itself tries to emulate on EFI-equipped machines. Debian’s apt-get for Slackware. Slackel is available as a live installable isohybrid Thanks to Gslapt you can carry out a basic image that you can boot from optical media as well as installation and then pull in just the programs that USB devices. Interestingly, you can use Slackel from a you need to use for a streamlined installation. rewritable media like a USB drive, in a couple of ways. All things considered, the two things that attract us For starters, you can use the included graphical tool to about Slackel are the 32-bit image and USB installs. The write the ISO image to a USB disk. You can also use the distro can really do wonders on an old computer. If that tool to create a persistence partition, which can computer can boot from a USB then you’ll be blown optionally be encrypted as well. away by the performance of the distro. And the fact that This is a good option if you want to save files and you’re running Slackware underneath will do wonders to carry them along with the Live environment. However, your geek credentials. the developer suggests the Live environment loses its snappiness once you’ve installed a couple of VERDICT applications in the persistent partition. DEVELOPER: Dimitris Tzemos WEB: www.slackel.gr No slacker, this LICENCE: GPL and others The better option is to do a proper installation of the distribution on to an external drive. The process is slightly more involved and assumes that the USB is the FEATURES 8/10 EASE OF USE 7/10 second disk. You’ll have to adapt the process to get the PERFORMANCE 9/10 DOCUMENTATION 6/10 USB to boot on a computer that has multiple internal drives. But the performance advantages are worth Slackel combines the best of both Slackware and Salix, to jumping through the extra hoop. offer a unique distro that’ll work wonders on older machines. For a traditional hard disk install, the distro uses a minimalist installer that it’s borrowed from Salix. It fires Rating 7/10 up Gparted to enable you to make room for the distro

S

www.linuxformat.com


SUBSCRIBE Save money today!

SUBSCRIBE

Sign up today and get your

EarFun Air Wireless Earbuds

YOUR GIFT! H WORT9 £54.9s out,  

is Don’t m e now! subscrib

Product features

 uad-mic system for enhanced Q noise-canceling calls In-ear auto detection Custom-built cellulose drivers for enhanced audio IPX7 protection with Sweatshield technology Single earbud mode 35-hour total battery life: seven hours playtime plus 28 hours with charging case Fast wireless or USB-C charging

“A nicely built set of headphones that also boast excellent battery life, wireless charging support and an expansive listen.” What Hi-Fi? August 2020

SUBSCRIBE NOW!

www.magazinesdirect.com/lin/Earfun21 Call: 0330 333 1113 and quote EarFun 24     LXF273 March 2021

www.linuxformat.com


Save money today! SUBSCRIBE 1

1,000s of DRM-free  PDF back issues and articles! Get instant access back to issue 66 (May 2005) with tutorials, interviews, features and reviews.  At linuxformat.com

! DON’T MISS s ar ye Now with 5 & r se U x nu of Li Developer issues

CHOOSE YOUR PACKAGE! ANNUAL PRINT EDITION

ANNUAL PRINT + DIGITAL EDITION

PLUS! Only 22%

£65.00

13 issues of Linux Format in print over 12 months by Direct Debit

NOT FROM THE UK?

Turn to page 44 for more grea subscriber t deals!

DIGITAL EDITION

PLUS!

SAVE!

SAVE!

SAVE!

Only

60%

£70.00

13 issues of Linux Format over 12 months  in print and digital by Direct Debit

Only

44%

£50.00

13 issues of Linux Format in digital by Direct Debit

*Terms and conditions: Offer closes 31 March 2021. Offer open to new UK subscribers only. Pricing is guaranteed for the first 12 months and we will notify you in advance of any price changes. Please allow up to six weeks for delivery of your first subscription issue (up to eight weeks overseas). Your gift will be delivered separately within 60 days after your first payment has cleared. Gifts only available to subscribers on the UK mainland. Gift not available with a digital subscription. The full subscription rate is for 12 months (13 issues) and includes postage and packaging. If the magazine ordered changes frequency per annum, we will honour the number of issues paid for, not the term of the subscription. For full terms and conditions, visit www.magazinesdirect.com/terms. For enquiries please call: +44 (0) 330 333 1113. Lines are open Monday- Friday 9am- 5pm UK Time or e-mail: help@magazinesdirect.com. Calls to 0330 numbers will be charged at no more than a national landline call, and may be included in your phone provider’s call bundle.

www.techradar.com/pro/linux

1) Only available to www.magazinesdirect.com subscribers

PLUS: Exclusive access to the Linux Format subs area!

March 2021 LXF273     25


ROUNDUP Game engines WE COMPARE TONS OF STUFF SO YOU DON’T HAVE TO!

Roundup Unreal Engine Godot Unity Engine GDevelop jMonkeyEngine

Michael Reed has been a Linux nerd since the winter of 1996 when he had only a 386DX/25 to warm himself.

Game engines There’s never been a better time to get into game development on Linux. Michael Reed puts five capable engines under the microscope.

HOW WE TESTED… Perhaps you’re a complete beginner, and you’re wondering where to start with game development on Linux? In terms of the computer kit that you need, you should be keeping an eye out for a hardware setup that can handle the type of game that you’d like to create. However, if you’re starting with something simple, don’t worry about needing a multicore monster of a computer with oodles of RAM just to get a few ideas up on screen – you don’t. Bear in mind, though, that even if you’re working on a 2D game, you generally need a fully working (and fully Linuxsupported) 3D graphics card. Consider a reasonable Nvidia or AMD card, rather than hoping that dated integrated graphics will be enough – disappointment lies that way. As for yourself, you’d be welladvised to have at least a bit of programming knowledge under your belt before you start. If you’re thinking of getting into an engine that uses Java, for example, it might be a good idea to know a bit of Java.

26     LXF273 March 2021

o, you may ask, what is a game engine? Generally speaking, it’s an integrated environment that enables you to – you’ve guessed it – make video games. If you’ve ever wanted to produce your own game then this might be the best period in history to give it a go, thanks to all the free tools that are available. And as luck would have it, Linux has most of the major game engines available for it. One thing to get out of the way from the start is that, although all of the game engines that we’re looking at are extremely good, they do have individual strengths and weaknesses.

S

One game engine might be a powerhouse when it comes to cutting-edge 3D rendering but less optimised for making a 2D game such as a platformer or an overhead shooter. So, which game engine you choose might depend on what you intend to do (and how you intend to go about it). Another thing to consider when choosing an engine is that some engines are more beginner-friendly than others. However, don’t give up hope if you’re not yet a programming wizard, because playing around with a game engine might be your ticket into learning computer programming.

www.linuxformat.com


Game engines ROUNDUP

How free is it? There are different kinds of free… ll of the game engines that we’re looking at can be downloaded and used without paying any money, but as we all know, when it comes to software there’s more than one aspect to freedom; even the term “open source” can mean different things to different people. Take Godot, for example. It’s free to download and use, and the project also makes the source code available under the MIT licence, meaning that you can examine it, modify it and distribute it. So, you could figure out a troublesome feature by looking at the source code or even become a contributor to the project (or distribute your own version). With Unreal Engine and Unity Engine, you’re not allowed to redistribute them and there are limits on how you can modify them, but you are permitted to download and examine the source code. Apart from being able to use and to examine the source code, there’s another concept to consider when we’re talking about game engine freedom: the freedom to distribute the software that you create using the engine. Think about that for a moment: you’d be quite surprised if the makers of a music creation program or a video-editing suite placed limits on what you can do with your artistic creations (or demanded a cut of the profits). However, we’re not bashing the engine makers who use a model based on those restrictions. By and large, they’re making a professionalgrade, game-creation suite available to the end-user at no initial cost. If you make it big, and start turning a substantial profit, some of them insist that you pay them a small share of those profits. That said, it’s a point in favour of engines like Godot or

A

Look at the FAQs and the Publisher EULA on the Unreal Engine website to see what the limitations are.

JMonkeyEngine, because their licences permit you to do anything you like with the finished product. When considering which engine to adopt for your project, read the FAQs on the engine website to find out what the current licence actually stipulates. Of course, when your game becomes a hit, you might consider sending a few quid along to the writers at Linux Format – particularly if it was us that put you on to a winner!

VERDICT UNREAL ENGINE 5/10 GDEVELOP 9/10 GODOT 9/10 JMONKEYENGINE 9/10 UNITY ENGINE 5/10 Your choice might come down to your own personal values in terms of software freedom.

Community and support

Unity Engine has dozens of YouTube channels dedicated to it, and these can be quite inspirational.

A game engine is useless without a way of learning how to use it. ecause game engines are so complex, it isn’t practical to learn how to use one through simple trial-and-error discovery, and this means that they need a good support system to be useful. This support can either exist in the form of the official documentation and tutorial material, or support from the computing community. As well as featuring extensive documentation and learning materials created by Unity Technologies itself, Unity Engine probably has the most vibrant community surrounding it. As a result, there are dozens of amazing YouTube channels devoted to it, and you’d have to be extremely unlucky to run into a problem that you couldn’t find the answer to with a visit to websites such as the official Unity forums or Stack Overflow. Furthermore, there are tutorials floating around the web that cover practically every approach to game-making with Unity that you could think of. Godot is decent in this regard, but it’s not in the same league as Unity, probably because it doesn’t have as many users. The might of Epic’s backing means that you’ll rarely run into dead ends when

B

www.techradar.com/pro/linux

trying to figure things out with Unreal Engine, and it too has a good-sized community around it. GDevelop isn’t exactly a household name, but searching YouTube, for example, reveals plenty of up-to-date tutorials, particularly for beginners. Unfortunately, this is jMonkeyEngine’s main weakness. It has a good official forum, but most of the tutorials you’ll find are old and there aren’t as many as for the other engines we’ve looked at.

VERDICT UNREAL ENGINE 7/10 GDEVELOP GODOT 7/10 JMONKEYENGINE UNITY ENGINE 10/10 A good community is a source of both instruction and inspiration.

7/10 5/10

March 2021 LXF273     27


BETTER VIRTUAL

MACHINES Forget about the draconian confines of reality and immerse yourself (well, your computing) in a virtual world. Jonni Bidwell’s here with a machines-inside-machines extravaganza.

irtual machines – where would we be without them? Since the late 2000s they’ve taken over great swathes of the internet, as data centre beancounters realised that it was much more efficient for one server to host a bunch of VMs than be dedicated to a single workload. And thanks to the underlying tech, workloads remain isolated and can be easily shifted to new hardware. They’re big business, too. It wasn’t too long ago when Amazon sold books, but now by far its biggest market is web hosting and a great deal of this rapid

V

32     LXF273 March 2021

scaling has been due to virtual machinery. If you want to try your hand at running a remote server, there’s no shortage of companies offering modestly spec’d VPSes (Virtual Private Servers) for as   little as $5/month. Virtual machines are also the safest way to try out new Linux distributions, because you can install them without touching whatever operating system you’re currently running. And if you’re new to Linux we’ll get you up and running with VirtualBox in three easy steps. It’s entirely possible to run a Windows guest on a Linux host too, and if you have

a spare graphics card you can – through the magic of VFIO – dedicate it to the Windows VM and enjoy gaming at nearnative speeds. Who knows, this might be the key to finally being able to ditch that Windows install? We’d be hard pushed to make a DVD every month (at least one that worked) without them. And our poor contributors would likely have awfully messy systems, what with installing complex software stacks and never having time to tidy up before installing the next. You too can benefit from them. And over the next few pages we’re going to show you how.

www.linuxformat.com


Better virtual machines

A virtual history Datacentres are full of VMs, but why and how did they get that way? irtual machines have been around for a long time, and any computer antiquarian will tell you the programs that ran concurrently on the mainframes of the 60s were much more akin to operating systems (they had to manage the valve- and bulb-based hardware themselves), and were known as ‘supervisors’. And it’s from these ancient roots we get the modern-sounding (and vaguely menacing) term ‘hypervisor’, being the one looking down on all this middle management. Emulation has always been a popular past time. It enables all kinds of retro-gaming diversions (stop playing Stunt Car Racer on the Amiga emulator and finish the curs’d cover feature – Ed), but there’s an important distinction between emulators and VMs. Today’s virtualisation is enabled by the CPU extensions that AMD and Intel introduced, known as VT and AMD-V, starting around 2006. These provide a virtual ring -1, to complement rings 0 and 3 used by traditional x86 code, so that virtual machines can run native code directly on the CPU. There’s no emulation layer to translate instructions from another architecture, so things can go much faster. Older hardware lacking the VT extensions can still run most virtualisation software, but it’ll in fact be emulating, and will give you a warning to this effect. If you look in the flags section of /proc/cpuinfo and find vmx (Intel) or svm (AMD) then you’re good to go. If not perhaps VT is disabled in the BIOS. For GPU passthrough (or other virtual GPU trickery, see in a couple of pages), you also need IOMMU support which is present on most 64-bit

We got SuperTuxKart running at 60fps with all the detail cranked up to 11 in an Ubuntu virtual machine, and it was glorious.

V

desktop CPUs made in the past decade. You can’t easily nest VT instructions, so if you try and do your best inception impression, for example running VirtualBox inside QEMU inside another VirtualBox, then you’ll be emulating after the second ‘inside’. There are lots of technologies that are analogous to virtualisation without technically being such. Containers are a prime example and we’ll look at those later in this article. There’s also the Windows Subsystem for Linux, which now runs a Linux kernel straight on the hardware. We won’t look at that later, but you can run Windows 10 in a VM if you want. Or you can do as we did in the screenshot (above) and run Ubuntu inside Arch, using VirtIO graphics to run Super Tux Kart at near-native speed. It’s amazingly simple to get a virtual machine up and running, no matter what your current operating system. Just grab an ISO of a Linux distro you’ve always wanted to try and follow our guide below.

VIRTUAL LINUX IN SECONDS

1

Get VirtualBox

VirtualBox is easy to find in Ubuntu’s Software Centre, or in your distro’s repos. If you’re running Windows or macOS, grab it from https://virtualbox.org and install it. Fire it up and click the New button in the toolbar. Come up with a name for your VM and tell VirtualBox what kind of Linux it is you’re virtualising.

www.techradar.com/pro/linux

2

Assign resources

Choose a decent amount of RAM for your VM. In general it’s best to assign more than half of the host’s memory to the guest, but you also need enough to run whatever you’re planning on running. Next choose the second option, ‘Create a virtual hard disk now’. For flexibility, choose the dynamic sizing option.

3

Activate the machine

Go to your virtual machine’s settings and in the Storage section find the Optical drive. Click the disk icon to the right and select Choose a disk file. Point the dialog box to the ISO of your choosing (it’s possible to use an actual DVD too), exit the settings and hit the Start button. Behold! An OS inside an OS. Great work.

March 2021 LXF273     33


IN-DEPTH The Linux gambit

THE LINUX

GAMBIT Jonni Bidwell once again sets a graphics card on fire, this time calculating chess positions…

etflix’s hit show The Queen’s Gambit has opened more people’s eyes to the fascinating world of chess. The characters in that show may be fictional, but chess aficionados will know only too well that the ancient game has seen more than its share of colourful personalities. Ever since a machine beat Garry Kasparov in 1992, chess engines have garnered significant interest. Today, the open source Stockfish engine is considered one of the best in the world, and it regularly beats grand masters. So it was a little shocking when Deepmind announced its neural-network based AlphaZero engine – which had trained itself (albeit on terribly expensive custom hardware) in a mere four hours – had decidedly trounced Stockfish. Stockfish uses complex heuristics created by chess dons

N

40     LXF273 March 2021

together with brute force (on modern hardware it has no trouble analysing some   20 moves ahead), whereas, pre-training, AlphaZero ‘knew’ only the basic rules of chess and that its goal was to win. A few of these games were released to the public, and they showcase an imaginative playing style that reminds one of Russian chess champion Mikhail Tal. AlphaZero didn’t care about losing material so long as there was adequate compensation (which wasn’t at all obvious even to a keen player). The inner workings of AlphaZero will remain a secret, but it’s inspired an open source effort, Leela Chess Zero (lc0), which can also beat Stockfish. Crucially though, it enables Linux users to train their own chess models or contribute computing time to develop other models (or just enjoy some good ol’ fashioned humility by being beaten).

www.linuxformat.com


The Linux gambit IN-DEPTH hen Richard Stallman sat down to start GNU, he wanted to get the important bits right. So the first projects to appear were the Emacs text editor and the GNU Compiler Collection. But besides dreaming in Lisp dialects and contemplating compiler conundra, Stallman had also been collaborating with Stuart Cracraft on a chess engine. That engine was GNU Chess. And it’s been part of GNU since 1984. A stable Hurd kernel release, by comparison, has yet to see the light of day. GNU Chess has been rewritten many times by many people, but to the untrained eye it’s still just a terminal program that plays chess. Just like the early days, you can still connect it to the venerable XBoard frontend if you want graphics. In fact, all serious modern engines maintain this distinction from the GUI, but there are lots of modern frontends to choose from. The popular Arena Chess now has a Linux build – see www.playwitharena.de. The current 6.x series of GNU Chess is based on the Fruit 2.1 chess engine and is almost certainly in your distro’s repositories. On Ubuntu you can install it and the modern Gnome Chess frontend with a simple $ sudo apt install gnuchess gnome-chess Gnome Chess is also available on Flathub, and as an added bonus pulls in the (according to the man page) “not-so-very-strong” HoiChess engine. Indeed, if you look at the DEB package, it suggests a whole bunch of other engines including Fruit and Stockfish. These myriad engines can all talk to each other and their graphical frontends thanks to the UCI (Universal Chess Interface), so you can pit machine against machine in a CPU-cycle guzzling battle to the death. It’s also easy to import games and positions into the engine of your choosing using the universally understood PGN (Portable Game Notation) format. We covered running Stockfish in the terminal in LXF264. And we also covered the remarkable Sunfish engine (https://github.com/thomasahle/sunfish), written in 100ish lines of Python, back in LXF206.

W

Xboard’s interface for adding engines is, admittedly, a little rough and ready, but you get the idea.

www.techradar.com/pro/linux

If you’re not familiar with algebraic notation then running Gnu Chess straight from the terminal is probably not the easiest way to learn it. Instead, if you just want to play chess against a machine fire up Gnome Chess from the Activities Menu or Applications Grid on Gnome-based distros (for example, Ubuntu) or whatever contraption your desktop uses to launch applications elsewhere. In the Settings menu you should see Gnu Chess selected as the default opponent. Try setting the difficulty to hard and to see just how potent GNU Chess is. Also in the Opponents menu, you’ll see HoiChess and if you install Stockfish (it’s in the Ubuntu repos) then you’ll see that too. See if you can spot differences between the playing styles, or incredible CPU usage spikes as the engine ponders how to thwart your fiendish attack.

There’s a Snap of GnuChess in Ubuntu’s store, but we couldn’t get it to work with the GUI promised in the description.

BEYOND CHESS AlphaZero’s predecessor, AlphaGo, became the first AI to defeat elite players of the ancient game of Go in 2016. Go is in a sense ‘simpler’ than chess, since there aren’t different pieces to worry about (it’s played with black and white counters). Besides chess and Go, AlphaZero can also destroy opponents at Shogi, sometimes known as Japanese Chess, and perhaps more complicated because it’s played on a bigger board with more pieces. Deepmind’s latest offering, MuZero, takes things beyond the board. Introduced in a December 2019 paper in the journal Nature, this latest effort adds vintage Atari games into the machine’s repertoire. Even if you think old games are simple (which they’re not – R-Type is still hard) it’s easy to see this is a significant evolution for machine intelligence. AIs have battled games before, often with interesting results (such as exploiting a previously unknown timing bug in QBert to achieve astronomical scores), but the systems have used modelfree learning, which roughly means they just try and make the best of the current situation without thought or consequence. MuZero goes the other route, and learns a model for the game’s environment in the same way as its forebears modelled board game strategies.

March 2021 LXF273     41


UK subs turn to p24

READING IN THE USA?

SUBSCRIBE!

Don’t wait for the latest issue to reach your local store – subscribe today and let Linux Format come straight to you. Faster, cheaper and with DRM-free archive access!

3 GREAT WAYS TO SUBSCRIBE

Print, digita l-only, and print+d igital bundles!

USA

From $118.80 For 13 issues

REST OF THE WORLD From $123.30 For 13 issues

EUROPE

From $90.00 For 13 issues

IT’S EASY TO SUBSCRIBE!

Click: www.magazinesdirect.com/linux-format

Call: +44 0330 333 1113 Lines open Monday-Friday, 9am-5pm, UK time

44     LXF273 March 2021

www.linuxformat.com


REVIEWS Microcontroller

Raspberry Pi Pico In a break from the norm Les Pounder tests the latest Pi: a $4 microcontroller featuring the first ‘Pi Silicon’ created by Raspberry Pi. SPECS SoC: RP2040, dual-core Arm Cortex M0+ Clock: 133MHz Mem: 264Kb Flash: 2MB Comms: USB v1.1 GPIO: 26 multifunction pins, 2x SPI, 2x I2C, 2x UART, 3x 12-bit ADC, 16x PWM channels, 2x PIO (eightstate machines) Extras: Real time clock, temperature sensor Size: 51x21mm

You’ll need a soldering iron to make the most of the Raspberry Pi Pico.

aspberry Pi has a history of disrupting the status quo. In 2012, the first $35 Raspberry Pi offered a low-cost entry into a market of single-board computers that was dominated by boards costing in excess of $100. The Raspberry Pi Pico, the latest board in the range, disrupts a different part of the electronics market, taking on microcontroller boards like Arduino. Available for just $4, the Pico is powered by Raspberry Pi’s own custom silicon, the RP2040 SoC, which features an Arm Cortex M0+ processor running at up to 133MHz, with 264KB of SRAM and 2MB of onboard storage. It’s a great choice for robots, weather stations or other electronics projects. The board doesn’t run a full operating system, but instead launches programs you write in either MicroPython or C on a host computer (that could be a PC, a Mac or a regular Pi) and upload to it. Perhaps even more important than the Pico itself is Raspberry Pi Foundation’s first foray into making its own silicon. We wanted to learn more about the RP2040 and so we asked James Adams, chief operating officer at Raspberry Pi Trading to tell us how “Pi Silicon” was created. “We couldn’t see a way to offer something differentiated in the microcontroller space using existing third-party silicon, so we set out to build our own,” Adams said. “The RP2040 chip has been a long time in the making. We started initial work at the back end of 2016, and we had some test silicon in our hands in September 2018, which we then reworked into the final device we use on the Raspberry Pi Pico board. The RP2040 chips are fabricated at TSMC on their 40nm process.” Adams also outlined some of the advantages of the custom silicon: “We’re offering some really unique

R

The Raspberry Pi Foundation created a custom piece of silicon for the Pico’s chip.

features with the RP2040 chip: a dual core device (I’m not aware of other dualcore microcontrollers at this price point) coupled to a high-performance bus matrix, meaning you can get full performance on both cores concurrently, and plenty of high-bandwidth RAM.” Adams continued: “As well as the usual fixed peripherals (UARTs, I2C, SPI, etc.) we also have a special bit of hardware called the PIO (Programmable I/O) unit, which is basically a very small, specialised, programmable state machine that can do high-speed, cycle accurate ‘bit banging’ of I/O. This block can be used to offload many kinds of timing-critical pin-waggling tasks from the CPU. We’ve had it emulating interfaces such as SD card, VGA and driving WS2812B LEDs. We’ve also added other goodies like optimised floating-point libraries to the boot ROM, and a USB core which can be used in either master or slave mode.”

Pico vs Zero On paper the Raspberry Pi Pico isn’t even a rival for the Raspberry Pi Zero, which itself costs only $5, but the key difference between the two is that the Pico isn’t a Linux computer. Rather, it’s a microcontroller like Arduino and is better for many projects. It could even work in conjunction with a regular Pi. Just like the larger Raspberry Pis and newer Arduino boards, the Pico uses a 3.3V GPIO. The Raspberry Pi Pico is an efficient board for embedded projects. Compared to a typical Raspberry Pi, the Pico consumes much less current, although it’s a microcontroller with none of the overheads that a computer brings. In our test we powered a Raspberry Pi Pico running 12 Neopixel LEDS at full brightness from a 5V power supply. We recorded 140mA current draw, 0.7W! This is remarkable: a Raspberry Pi 4 running idle with nothing connected would run at between 4W and 5W. So compared to Raspberry Pi, the Pico sips power! Talking of power, we can power the Raspberry Pi Pico via the micro USB port, or we can use the VSYS GPIO pin

46     LXF273 March 2021

www.linuxformat.com


TUTORIALS Sense HAT

SENSEHAT

Turn a Pi HAT into a Magic 8-ball project Les Pounder blasts off with another tutorial showing how a versatile HAT board can answer all your questions, and even be run in space! he Raspberry Pi Foundation released its Sense HAT add-on back in 2015. Yet this board still packs a full scientific platform and an 8x8 RGB LED matrix for a little fun. In this tutorial we’ll introduce the board, show text on the LED matrix and learn how to read accelerometer data for a classic game of chance. Installing Sense HAT is straightforward. With the Raspberry Pi powered off, connect the Sense HAT to all of the GPIO pins, ensuring that the Sense HAT perfectly overlaps the Raspberry Pi. Use the included stand-offs to securely mount the SenseHAT. Now attach your keyboard, mouse, HDMI, micro SD and finally power to boot the Raspberry Pi to the desktop. Because we’re using the latest version of Raspberry Pi OS, there’s no need to install any software or Python packages.

T

OUR EXPERT Les Pounder is associate editor at Tom’s Hardware and a freelance creative technologist.

Project 1: Hello World The first project with any new piece of tech or software is “Hello World”. It proves that our kit is working, and that everything is ready for us to move further. The first project is a simple scrolling message that will prove our software and hardware works. In your preferred Python editor, Thonny, IDLE, Mu or a text editor create a new file and call it text_scroll.py. Remember to save often! Our first two lines of Python are an import that imports the sense_hat class from the SenseHat module. We then create an object that enables us to easily use the class. from sense_hat import SenseHat sense = SenseHat()

YOU NEED Any 40-pin Pi model SenseHAT Raspberry Pi OS Code: https:// github.com/ lesp/LXF273SenseHAT/ archive/main. zip

The next two lines are tuples – data storage structures which can be created and destroyed but never updated. These tuples store the RGB colour values for a particular colour, in this case red and white. red = (255, 0, 0) white = (255, 255, 255)

The message to scroll across the screen is stored as a string inside a variable called message. message = “Hello World”

We now enter a loop, and to start the process we start a try and except handler. Any code inside the try section of the loop is what our project will attempt to run. In this case it’ll launch an infinite loop.

48     LXF273 March 2021

try: while True:

Designed for all 40-pin models of Raspberry Pi, Sense HAT is an old board that’s still relevant in the classroom and space station!

Inside the loop we have a single line of code that will scroll our message, with red text and a white background. Each step in the scroll lasts 0.1 seconds. sense.show_message(message, text_colour=red, back_colour=white, scroll_speed=0.1) We now reach the except part of the code. This is an

exception handler that is activated if we press Ctrl+C to end the code. When that happens we instruct the Sense HAT board to clear: except KeyboardInterrupt: sense.clear()

Save the code and run via your Python editor. Thonny and Mu have a run/play button. IDLE uses F5 or via the Run menu. Hello world should now scroll across the LED matrix. When finished, press Ctrl+C – this clears the matrix.

Project 2: Magic 8-Ball The Magic 8-Ball is a classic child’s toy. Ask a question out loud (“Will my online delivery be left in the hedge again?”, “Am I the only one who can empty the dishwasher in this family?” or “Is there anything worth watching on TV tonight?”), then shake the 8-ball. In a few seconds a message floats to a viewing portal, ready to read. With the Sense HAT we can make a modern-day version, which uses raw data from the accelerometer to determine that the 8-ball has been ‘shaken’. Create a new Python project in your favourite editor, call the project 8ball.py and remember to save often.

www.linuxformat.com


TUTORIALS Build a diorama

PYTHON

Build a Pi-powered helicopter diorama Sean Conway uses a helicopter model to demonstrate how lighting, sound and motion can be accomplished using a Raspberry Pi. his tutorial takes us behind the scenes of a Raspberry Pi-powered diorama to explore the concept of concurrency. A diorama is a three-dimensional full-size or miniature model. For this exercise the diorama is a miniature helicopter complete with lighting sequence, engine run-up sounds, and blade motion. We’ll be using the computer power of the Pi to generate light, sound and motion animation to bring the model to life. The animation of light, sound and motion are added to the diorama through electronics attached to the Raspberry Pi general-purpose input and output (GPIO) pins. Four sets of LEDs provide cabin, strobe, navigation and landing lighting. The mp3 sounds of a turbine engine spooling up and whirring are generated to the Pi’s headphone jack. Finally, a stepper motor gradually speeds up to provide rotor action. The final product is a digital orchestra conducted by the Pi using Python code. We’ll assume that you have a basic understanding of the Raspberry Pi, including loading the operating system and installing software. A familiarity with using the command line interface (CLI) is recommended to explore the workings of the Python program.

T

OUR EXPERT Sean D. Conway as a former IT security specialist turned retired guy. He enjoys creating Raspberry Pi projects for model railroad sets.

Concurrency Key to this project’s design is concurrency, which means at the same time. While consecutive means one after the other in a series. It’s no surprise that criminals convicted of multiple crimes would prefer to serve concurrent terms as a sentence, instead of consecutive terms. The Pi in the helicopter diorama mixes both the concurrent and the consecutive operation of the lights,

Front View Cabin light

Cabin light (GPIO3)

(GPIO3) Nav light (right GPIO4)

Side View Nav light (left GPIO4)

Nav light (left GPIO4)

Landing light (GPIO2)

The model block diagram rising above the animation sequence.

50     LXF273 March 2021

Nav light (rear GPIO4)

Strobe lights (flashing GPIO27)

Speaker Motor (dir-GPIO 20, speed-GPIO21)

sound and motion to produce the animation. In the Gantt chart (facing page) there are three colours corresponding to the three types of animation. There are four sets of LEDs (the lights), coloured different shades of yellow that need to be activated consecutively over time. The cabin lights first come on, then the strobe lights flash. Finally the navigation lights and landing lights are activated in sequence. A delay between the lighting of each is added to draw the viewer’s attention to the change in the scene. When the light sequence activation is complete, the Pi runs the sound process (coloured blue). The sound mp3 file contains the audio for the start, run-up and shutdown of the helicopter engine. While the lights are activated and sound is produced, a motor (coloured green), is activated through a sequence of speeds to physically turn the rotor blade from slow speed through medium then fast and back to slow speed over the time period. The lights, sound and motion are consecutive: first light, then sound and motor action leading to a point in time that the animations are all running concurrently. The concept of concurrent and consecutive also applies to programming. What is concurrent programming? It’s when you’re doing more than one thing at the same time. Examples include multiple computers in a network, multiple applications running on one computer, multiple central processing units (CPUs) in a computer, multiple cores in CPUs and multiple programming threads in a core. Concurrency should not be confused with parallelism. Urban streets provides a useful analogy. When parallel vehicles move in adjacent traffic lanes at the same time across different roadways – there’s no interaction between the vehicles. In concurrent vehicle traffic some coordination is needed to avoid unwanted interaction between the vehicles.

Behind the scenes The Python script to support the diorama animation uses a number of modules to generate the concurrent animation. The python code causes the Pi to generate processing threads to enable the concurrency and consecutive play to happen. This project uses the Buster Lite version of the

www.linuxformat.com


TUTORIALS Gamepads

GAMING

Connect, configure and use gamepads Planning some Raspberry Pi gaming? Christian Cawley shows you how to set up a game controller either natively or with an emulator. lanning to play some games on your Raspberry Pi? Minecraft: Pi is far easier to play with a game controller, but you might have your eye on Doom (LXF268) or other shareware classics. Alternatively, you could be hooking up a controller to your Raspberry Pi-based retro gaming system. A good selection of game controllers can be connected to your Raspberry Pi using USB. Furthermore, some well-known controllers can also be linked up using Bluetooth. In theory, all controllers should work with a Raspberry Pi. This covers everything from generic USB joysticks and joypads to the latest Bluetooth devices. So, you can expect to be able to connect an Xbox One controller and a PS4 controller to your Raspberry Pi. Controllers designed for the PlayStation 3 and Xbox 360 will also work, as will Nintendo gamepads. Own a PlayStation 5? The new Sony console features a major revision of the much-loved game controller. But despite being fresh out of the box in 2020, the PS5 controller will easily connect to a Raspberry Pi over Bluetooth, just like its predecessor. Meanwhile, Xbox Series S and X controllers are backward compatible, and can be used on an Xbox One console. The new controller design should also work with the Raspberry Pi. In this tutorial, we’ll look at what you need to do to connect the most widely used game controllers to a Raspberry Pi: those intended for the Xbox One, PS4, Xbox 360 and PS3 consoles. We’ll begin with the Xbox One, which boasts one of the most popular game controllers available. Also compatible with PC games,

P

OUR EXPERT Christian Cawley A freelance writer and editor specialising in consumer electronics, who is still finding pine needles in his Raspberry Pi.

YOU NEED Raspberry Pi 3 or later Popular game controller Raspberry Pi OS USB cable

Most game controllers will connect to the Raspberry Pi using Bluetooth or USB. For wireless Xbox One controllers, however, you’ll need a USB receiver dongle.

54     LXF273 March 2021

Configure Bluetooth to accept connections from Bluetooth game controllers, then trust the MAC address to enable easy reconnection.

this is a well-designed, multi-purpose controller that can be easily connected to a Raspberry Pi, either using USB or Bluetooth. To connect the Xbox One controller to your Pi using USB, start by updating and upgrading Raspberry Pi OS: sudo apt update sudo apt upgrade

Next, connect the controller. Try it out with a game, perhaps Minecraft: Pi. The driver for Xbox One controllers should be built in – if not, use sudo apt install xboxdrv

Follow the instructions to install the driver, reboot the Raspberry Pi, and try again. Using a wireless Xbox One controller with the Raspberry Pi is a little more complicated. Two types of wireless Xbox One controller have been released. One uses wireless, while the second requires Bluetooth. How can you tell which is which? If your Xbox One controller has Wi-Fi, the plastic around the Xbox button is the same colour as the top of the controller where the triggers and shoulder/bumper buttons are. Bluetooth Xbox One controllers, meanwhile, have a single-coloured face. So, the plastic around the Xbox button is the same colour as the rest of the controller face. To go in-depth you can open the battery compartment. Here, the model number is listed: 1697 means it is a wireless controller, whereas 1708 indicates a Bluetooth model. If you have the 1697 wireless model, you’ll need to connect the official Microsoft Xbox Wireless Adapter to your Raspberry Pi. This is a standard USB dongle that should work out of the box. Simply hold the pairing buttons on the adapter and the Xbox One controller to sync, then start playing. For the 1708 Bluetooth controller, you’ll need the xboxdrv driver, as described earlier. You’ll also need to

www.linuxformat.com


TUTORIALS Create a mind-map Credit: www.freeplane.org

FREEPLANE

Construct your own mind-maps Nick Peers reveals how you can easily manage all of your thoughts – from simple ideas to fully formed projects – with this powerful free tool. ind-mapping tools are designed to bring order to chaotic thoughts. They can be used for anything from a simple means of jotting down a few random thoughts to full-blown project management. A mind-map is basically a series of interconnected thoughts represented as ‘nodes’, which can be placed anywhere on-screen and either left unconnected or joined to others in a hierarchy defined using styles and connecting lines, with a single oval-shaped ‘root’ at its centre indicating the mindmap’s subject. Freeplane does all this, of course, and more – it’s almost infinitely customisable and you can style things manually or use an automatic system to indicate what level in your chosen hierarchy items sit. Nodes can contain all kinds of information, represented by text, icon, image, hyperlink or scientific formula or calculation. You can customise your view on the fly as

M

OUR EXPERT Nick Peers wishes he had used Freeplane to plan this tutorial. This 11th-hour thinking is really starting to wind him up.

The anatomy of a node

1 2

4 3 5

6

Title Each node has its own title – double-click this to edit it or right-click it to format it via the Apply style section.

1

Icon 2 Choose View>Controls>Icons toolbar’, then click an icon on the toolbar to add it to the node. Details 3 This description appears beneath the node. Use the ^ button to its left to hide/show it.

58     LXF273 March 2021

Notes Once added, roll your mouse over the notes icon to reveal the note as a pop-up.

4

Image Select a node and choose Insert>Image> Add image… – resize it by clicking and dragging its bottom right-hand corner.

5

Attributes Attributes work in a similar way to fields in a database, enabling you to attach specific characteristics to individual nodes.

6

you see fit, and even assign tasks using deadlines and reminders to get them done. If all this sounds overwhelming, don’t worry – once installed, Freeplane opens with its own example mindmap in place to show you what it can do. Let’s crack on and get it set up. The app is written in Java, which means you’ll need to install a Java runtime to access it. Simply open the Terminal and type the following: $ sudo apt update && sudo apt install openjdk-8-jre

Once installed, head over to https://sourceforge. net/projects/freeplane/files/freeplane stable to download the latest stable version (1.8.10 at time of writing) as a .deb file. Versions can be found in Ubuntu Software Centre, but even the updated Snap version is way out of date. Instead, double-click the .deb file and follow the prompts – once installed, Freeplane can be opened using the App Launcher.

Free the plane Freeplane opens with the aforementioned example mind-map in place. It looks quite messy at first glance, but you’ll soon grasp the logic, thanks to its colourcoded sections. Basically, start with ‘Freeplane 1.2 Functions’ in the middle and work your way out. Place the cursor over this and after a short pause a pop-up window will appear, revealing a note connected to the item in question, that in turn demonstrates how to bring up the Note pane (View>Notes>Display note panel) where you can easily view – and edit – the notes of the currently selected item. From here, work your way around the diagram – as you roll over certain items you’ll see other pop-up tools appear (for example, click the – next to ‘1 in node core’ and you’ll hide, or collapse, the list to its left. Take the time to explore each section where you’ll get an idea of what kind of information you can record, and where to go in the Help file to read more about it. Double-click an item to rename it or click and drag on various items to see how easily they can be moved around the screen. Freeplane also supports undo via the usual Ctrl+Z key combo.

My first mind-map That example mind-map can be a bit overwhelming – the key thing to remember is that your own mind-map

www.linuxformat.com


TUTORIALS ZFS filesystem Credit: www.freenas.org/zfs

ZFS

Next-gen filesystem management ZFS is a lot more than a filesystem. Neil Bothwick tells all about this advanced volume manager and Swiss Army Knife of filesystems. ife used to be so much simpler. A typical desktop computer had one small – and expensive – hard drive with no more than four partitions using standard filesystems like ext2/3. Okay, so half the hardware out there wasn’t supported by Linux, but that just simplified things even further. Now we have huge hard disks, often more than one of them, and lots of data strewn across them. Simple partition schemes have been replaced with RAID arrays, volume management and multiple filesystem types. Then we start worrying about privacy and start throwing encryption into the mix, and that’s without considering backups. Thanks to the way in which Linux uses block devices, these multiple technologies can be layered on top of one another fairly easily, so we have filesystems on top of LVM volumes on top of LUKS-encrypted devices on top of a RAID array of several hard disks… and it all works well. It can be a bit of a management headache though, with each layer using a different set of software to manage it. Enter the latest generation filesystems that handle most of this with one software suite. Both ZFS and btrfs provide much of what has already been mentioned, although btrfs doesn’t handle encryption. ZFS was created by Sun and some years ago it released the source code, opening the way for ports to Linux and other OSes. The Linux port was called Zfsonlinux, but the various porting projects have pooled resources as OpenZFS. OpenZFS 2.0 was released recently and this does support encryption, so we now have an all-in-one solution. How does it work and is it right for you?

L

OUR EXPERT Neil Bothwick has been using and writing about Linux since before the first “This is the year of Linux on the Desktop”. His life is so full of excitement that he finds filesystems fascinating!.

While we haven’t shown it here, most of the commands should be run as root or prefixed with sudo. The only exceptions are commands that only retrieve information, such as zpool status or zfs list.

Diving in First, we need to install the ZFS software. This comes in two parts: the kernel modules and the userland tools. On an Ubuntu-ish distro you would do the following: $ sudo apt install zfs-dkms zfsutils-linux

Yes, you need to install the kernel modules separately, see the licencing boxout (opposite) for more information on the reasons behind this. There are two basic components to a ZFS system. A pool is one or more physical storage devices aggregated into a storage unit. A dataset is what an individual filesystems are called in ZFS – the equivalent of volumes in LVM or subvolumes in btrfs. Datasets are created within pools.

62     LXF273 March 2021

This systemd service file will prompt for your passphrase and load the keys for your encrypted datasets so they can be mounted at boot.

Pools are created and managed with the zpool command. At its simplest we can create a pool from a single disk partition with $ zpool create -o ashift=12 mypool /dev/sda2

There are a number of options you can give to zpool , usually the defaults suffice, but ashift is important. It makes sure that data is aligned correctly on disks using 4K data blocks. Without this option, you may suffer performance issues. If you have more than one device, you can use zpool to create a pool that’s a RAID array: $ zpool create -o ashift=12 mypool mirror /dev/sda2 / dev/sdb2 $ zpool create -o ashift=12 mypool raidz1 /dev/ sd{a,b,c,d}

The first creates a RAID1 mirrored array of two devices, the second creates a four-disk RAIDZ array, using whole disks. RAIDZ is equivalent to RAID5 but without the “write hole” problem. There are also RAIDZ2 and RAIDZ3, giving increasing levels of redundancy. One limitation of ZFS is that pools can’t easily be migrated from one format to another. You can add devices after creation but not remove them of change RAID levels, so decide what you need before you start. You can view details of your pools with the zpool status option: $ zpool status $ zpool status mypool

Once you have a pool you can create datasets on it using the zfs command – there are only these two

www.linuxformat.com


TUTORIALS BBC Micro Credit: www.mkw.me.uk/beebem

EMULATION

Run a classic BBC Micro under Ubuntu Les Pounder reminisces about that one time when he caused a core meltdown in a nuclear reactor, then flew away in a spaceship. he BBC Micro was a popular fixture in 1980s classrooms in the UK. It was developed by Acorn Computers after successfully winning the interest of the British Broadcasting Corporation’s (BBC) Computer Literacy project with its hastily created Acorn Proton computer. This catapulted Acorn’s fortunes and saw the BBC Micro become a popular, if expensive choice for home computing enthusiasts. The BBC Micro was also quickly adopted by educational bodies, and children (including us!) learnt programming via this machine. One of this author’s first encounters with a BBC Micro was controlling a simulated nuclear reactor that may have gone critical due to a careless mistake. The BBC Micro was powered by a MOS Technology 6502/6512 processor running at 2MHz. It came with a plethora of ports, some providing access to a GPIO of sorts: a 15-pin analogue port typically used in science experiments, and a user port which has a digital interface that can be used to control basic electronics. Initially, the BBC Micro had two “main” models: the 16KB Model A and the 32KB Model B. But future releases saw further models: the B+, Master and Plus 32. All of these models saw expanded memory options as well as additional ports and functionality while retaining compatibility with the core machines. Fans of the Raspberry Pi will recognise the “Model” names because the Raspberry Pi was directly influenced by the

T

OUR EXPERT Les Pounder is associate editor at Tom’s Hardware and a freelance creative technologist. He blogs about his retro tech discoveries at bigl.es.

The most accessible means of demonstrating the power of BBC BASIC and BBCEdit is via the good ol’ 10 PRINT.

The BBC Micro was a beast! Built to survive the rigours of school children and featuring a great keyboard, this machine was the business!

BBC Micro. Yet the legacy of the BBC Micro isn’t just limited to this. The BBC Micro was also used as the test bed for the ARM CPU architecture – a CPU architecture present in the myriad of portable devices that are now a massive part of our everyday lives. The BBC Micro lasted from 1981 to 1994, but its legacy has lived on and right now it’s enjoying a resurgence of interest, especially its fantastic BBC BASIC which is stored in ROM ready for use. Based upon the earlier Atom BASIC, BBC BASIC was developed by Sophie Wilson and colleagues at Cambridge University. BBC BASIC is simple to use, and “friendlier” to new users than many others of the era. The best way to learn more about this great machine is to get hands on, and in this tutorial we shall do just that. We’ll learn how to load games in an emulator, and write code in a dedicated BBC Micro code editor.

Emulating a BBC Micro To write code for our BBC Micro we chose to use BBC BASIC for SDL, available from www.bbcbasic.co.uk/ bbcsdl. We installed the version for 64-bit Linux on our test machine running Ubuntu 18.04. To install, download the BBC SDL archive and extract the contents to your computer. For Linux we need to install a few dependencies. Open a terminal and run the following commands: $ sudo apt install libsdl2-2.0-0 $ sudo apt install libsdl2-ttf-2.0-0 $ sudo apt install libsdl2-net-2.0-0

66     LXF273 March 2021

www.linuxformat.com


TUTORIALS Decode satellite signals Credit: https://noaa-apt.mbernardi.com.ar

SOFTWARE DEFINED RADIO

Decode signals from weather satellites

Weather satellites transmit signals that you can receive and decode to generate images of the Earth. Mike Bedford shows you how. atellite-based images of the Earth showing cloud cover have been a regular sight in TV weather broadcasts since the TIROS 1 satellite launched in 1960. Yet while the end result is familiar, the technology that brings us those images is much less well-appreciated. If you want to learn about the technology involved, though, it’s not too difficult to get a basic understanding. However, you can gain some hands-on experience, as we demonstrate here, and a practical approach is often one of the best ways of learning. So, we’ll show you how to receive the radio signals transmitted by these satellites and how to decode that data to generate pictures. In addition, we’ll also investigate some ways of image processing to improve that image and perhaps introduce some false colour into the inherently monochrome images transmitted by the satellites.

S

OUR EXPERT Mike Bedford is fascinated by receiving signals from weather satellites and processing the data to generate images.

NOAA satellites Since the NOAA polar orbiting satellites orbit at only 850km and you can easily receive their radio signals, you might wonder if you can see the NOAA polar orbiting satellites by looking at the sky. According to the NOAA, they are considered naked eye objects but only just. In practice, therefore, you’re only going to see them in dark rural areas.

Here we’re going to be looking at the so-called NOAA polar orbiting satellites – NOAA-15, NOAA-18 and NOAA19 – that are operated by America’s National Oceanic and Atmospheric Administration. We’ve chosen these satellites because they orbit the Earth at an altitude of just 850km. Since they aren’t too far above our heads, their radio signals are quite strong and easy to receive. If you’re wondering why the satellite numbers aren’t contiguous, all satellites from NOAA-6 have existed but

70     LXF273 March 2021

most are no longer operational, including NOAA-16 and NOAA-17 even though they were launched after NOAA15. However, NOAA-15 has been experiencing operational problems since 2019 so there are no guarantees that you’ll be able to receive and decode its transmissions, even though we had no difficulties. There’s also an NOAA-20, but this is the first of a new generation of polar orbiting satellites. It transmits on a much higher frequency which makes it significantly more difficult to receive. For that reason, decoding software probably won’t be too plentiful, although one offering is reportedly available at an alpha testing stage. The laws of gravity dictate that any Earth satellite has a velocity and hence also an orbital period, which depends on its altitude. This means that the launch and fine-tuning of its altitude is critical to ensuring that it orbits the Earth in the time that was intended by its designers. Specifically, the closer a satellite is to the surface of the Earth, the faster it orbits. Let’s take the example of a satellite at an altitude of 35,786km. It’ll orbit the Earth every 24 hours so, if it’s in an equatorial orbit, travelling in the same direction as the Earth’s rotation, it’ll appear to be stationary above a particular point on the planet. This is referred to as a geostationary orbit and there are geostationary weather satellites, for example NOAA’s GEOS-15, GEOS-16 and GEOS-17. Turning to our main theme of the polar orbiting NOAA satellites, their 850km altitude means that they orbit the Earth just over 14 times every 24 hours. As the name suggests, the orbits of these particular satellites take them over both the poles. However, most importantly, because the Earth is rotating below them, every orbit is shifted in such a way that it passes over a different swathe of the Earth’s surface compared to the previous orbit. This arrangement enables each satellite to obtain images from any point on the Earth’s surface twice each day: once during daylight and once at night.

Is it still raining?

Launched in 1998, NOAA-15 is still mostly operational, despite it having had a design lifetime of just two years. CREDIT: NASA

That’s enough background for now, so let’s take a look at how to receive signals from these satellites. Not too long ago you’d have needed to buy a radio receiver that covered the frequencies used by the NOAA polar orbiting satellites, but now you can use so-called Web SDRs, which are radio receivers hosted on the Web. Take a look

www.linuxformat.com


THE BEST NEW OPEN SOURCE SOFTWARE ON THE PLANET

HotPicks

Alexander Tolstoy imagines what the world would be like without his collection of exciting open source programs…

EiskaltDC++ TabFS TuxPaint Chipmunk Darktable EasyLogic Studio Zenith Tux vs. Yeti Invasion Qsnapstore Dify FILE-SHARING APPLICATION

EiskaltDC++ Version: 2.4 Web: https://github.com/ eiskaltdcpp/eiskaltdcpp espite the fact that the golden years of filesharing networks are long gone, the technology is still in use and has its own community. EiskaltDC++ 2.4 is the latest major release of this advanced and feature-packed client application for Direct Connect (DC) networks. Five years have passed since the last Git tag, so it’s interesting to see what’s changed since our last review of the program in LXF206. Of course, Direct Connect is still an important part of modern networking. The reason you might want to use it in 2021 can vary: Direct Connect enables very high upload and download speeds within your neighbourhood, and it’s very sociable, too. As an example, the central area of an EiskaltDC++ window is always dedicated to a live chat. To get in touch with others you just need is connect to at least one hub (lists of public hubs can be easily found online), share something on your Linux machine, and then make your way through a rather archaic (if straightforward) procedure for hub registration. DC hubs attract users who are looking for rare downloads. Furthermore, while the global web has evolved, hubs remained fragments of free speech and free file sharing. In the meantime, while existing EiskaltDC++ users are happy with a raft of new updates and fixes, the rest of us should definitely give it a try. The new version adds support for OpenSSL 1.1 and sports many UI improvements in its Qt5 interface, including a streamlined Settings dialog. EiskaltDC++ supports downloading from other people’s personal hubs and also handles Magnet links. To successfully connect to a hub while being behind a router, you’ll need to set up NAT rules for ports 3000 and 3001 (for both TCP and UDP). EiskaltDC++ doesn’t replace BitTorrent, but rather adds the alternative path of getting data from the Internet to your Linux box. Have fun getting in touch with other like-minded folk, enjoy high-speed file sharing and bear in mind possible copyright issues!

D

www.techradar.com/pro/linux

Connection details are crucial for Eiskaltdc++. Make sure your machine has the right TCP/UDP ports open.

Get to know the Eiskaltdc++ interface 1

2 4

3

5

Setup connection type and ports Eiskaltc++ works best when the Active connection type is set. You might need to set up NAT rules on the router to generate a successful connection.

1

Quick connection and favourites If you know the hub’s address, use the Quick Connect button. Adding the hub to favourites enables you to specify your nickname, encoding and the hub’s description.

2

3

Left-side menu See what hubs you’re connected to,

access downloads, search files and more. Many features here can also be accessed from the buttons on the main toolbar. The live chat Every hub is a good place to talk to other people. Get your nickname registered using the built-in chat menu and start socialising with like-minded users!

4

Hub members Browse through the list of nicknames, or search it using the field below. Right-click any nickname to see their shared files.

5

March 2021 LXF273     75


TUTORIALS Active Directory Credit: www.samba.org

SAMBA

Using Active Directory with Debian & Samba

Stuart Burns rolls up his sleeves and takes you through the process of setting up a Linux-based Active Directory infrastructure and how to use it. ike it or not, a lot of authentication uses Active Directory (AD) to manage users and resources. It’s a staple of the Windows world and until recently (Samba 4) there was no way to have a complete AD stack in FOSS to “talk proper AD”. Luckily, with SAMBA version 4.7 and later it’s possible to build an AD controller based completely on Debian and Samba. If you follow AD all the way back it’s just Microsoft’s take on LDAP with some extra secret sauce. This new capability is a great step forward. However, it’s important to note that while the authentication will work as expected, some items may not work. The message is, “Try this but be aware there may be some areas that present difficulties.” That said, authentication, print servers and SMB file shares should all work if correctly implemented. The home user among us may be thinking, “This does nothing for me” but even at home, for the techie types AD can be useful. Think of all those usernames and passwords across different systems that are all managed separately. If you could just use one across the entire breadth of your eco-system, wouldn’t that be great? AD makes this possible. One simple daily example is integrating AD management into FreeNAS so that you can log in using a centralised authentication. AD provides this, as well as being able to assign domainbased rights to SMB shares. A key part of setting up AD is its dependency on DNS. Whenever you set up an AD infrastructure in Windows for the first time it automatically installs a DNS server. Most new installations should select ‘Samba Internal’ for the DNS type. The DNS system comes as part of the AD system, but also provides standard DNS resolution. The walkthrough in this instance is being

L

OUR EXPERT Stuart Burns is a big Linux advocate and enjoys trying new things in Linux before sharing his findings with the world.

performed in a test lab. To follow along with this walkthrough the user will need a virtual machine with a static IP address. (For this example, the test AD server IP will be 192.168.1.10 with a netmask of 255.255.255. xxx and a gateway of 192.168.1.1.) The VM should also be able to download the installation packages that will be needed. For this walkthrough Debian 10 is used, but if you’re using Ubuntu it should be very similar. It’s crucial that the AD domain isn’t a real world one, or it’ll cause problems. For example, chose itburns.lab, which isn’t a real world domain. This is important because it’s not something that can be changed later. It’s vital to lay the groundwork, too. Ensuring accurate time is critical or it can cause problems in Active Directory. VirtualBox VMs (and others) get their time from the host they sit upon, but once other machines are added the time may not be in such accurate sync. For that reason alone, if expanding beyond virtual experimentation, use a time server and make sure all clients receive their time from it.

How does Active Directory work? It’s important to understand how AD and DNS interact and co-exist. Put simply, any AD-related requests have to be handled by the AD server. The AD server provides a number of key records that help servers locate required Windows specific information, such as which server to use to provide the desired service. Sometimes new administrators overlook this and block the requests internally, thinking standard DNS will provide the required data. But it won’t. Doing so can break AD so be careful. For now we’re going to have our AD controller service all our DNS-related requests and forward nonlocal DNS requests to our forwarding DNS server.

An example of what should be returned when checking that the SRV records are working.

82     LXF273 March 2021

www.linuxformat.com


CODING ACADEMY ASSEMBLY

Part Two!

Coding Arm 64-bit assembly language

Grab the last issue to get part one, see page 74!

Continue writing 64-bit assembly code for the Pi with John Schwartzman, who calls on Linux kernel services and the C run-time library. ast month we used assembly language to directly access the Raspberry Pi’s Linux kernel services. In this issue’s concluding instalment we’re going to use the C run-time library, glibc, instead of calling the kernel services directly. The glibc functions are in many cases thin wrappers around the Linux kernel services. But using the C library is the preferred way to access the kernel services. Kernel system calls are limited to six arguments, but that’s not enough for the C library. We use X0 through X7 for the first eight arguments, but any number of additional arguments can be passed on the stack. We populate the registers listed above with the arguments to the function in left to right order. We then PUSH the arguments on to the stack in right to left order and remove them from the stack after the C library function has executed. You’ll see an example of this in environment.asm. When using the kernel system calls we called a common location using the software interrupt instruction SYSCALL and passed the ID of the specific service in the X8 register. When using the C library we call the specific function we want by name. X0 (or sometimes W0, the lower half of X0) is used to return a result to the caller.

L

OUR EXPERT John Schwartzman is a long-time engineering consultant to business and government. He also teaches computer science at a local college.

Our next programs are cmdline.c and cmdline.asm (see screenshots below and on page 88). When a main function is invoked it can include arguments that the user types on the command line. If you type ./cmdline alpha beta goldfish at the command prompt, Linux will execute the program cmdline. The program will receive as parameters, argc, which is the total number of string arguments (four in this case) followed by an array of pointers to the strings on the command line that are in an array of arrays called argv[]. In this case, cmdline will receive as strings ./cmdline , alpha , beta and goldfish . Cmdline.c and cmdline.asm read and print argc and argv[]. Since this is Linux, you can guess how we receive these parameters. W0 will have the integer argc (the first argument), and X1 will have the vector of pointers, **argv. cmdline.c should be easy to understand. The prototype for main is int main(int argc, char* argv[]) . After printing argc, we use a for-loop to print each argument index i, followed by the array of string parameters argv[i]. That’s all there is to it. Execute ./a. out alpha beta goldfish . Now do the same thing for the assembly language program. Execute ./cmdline alpha beta goldfish .

Give your code a PUSH

Here, the command cmdline.c lists arguments to the c program.

www.techradar.com/pro/linux

Our main function calls printf so main is a caller of printf, but main itself is called by the C start-up code, so that main is also a callee. Therefore, main must save and restore any callee-saved registers that it uses. Notice that we PUSH them at the beginning of main and then POP them in reverse order at the finish label (line 45), before main returns. Our stack is restored and the RET instruction in line 48 restores the processor’s program counter register (PC) to the C startup code that invoked main. We MOVe X0 (first input parameter) into X20 and MOVe X1 (the second input parameter) into X21. X20 and X21 are callee-saved registers, so that when we call printf we can be sure that printf won’t change the values of these registers. If it uses them, it guarantees that it will save and restore them. We have a limited number of registers available, so we have to have rules

March 2021 LXF273     87


CODING ACADEMY Maze runner game

PYTHON

Write a maze runner game in Python One way in, and only one way out… video game aficionado Calvin Robinson reveals how to create a vintage maze runner-style game. his series of tutorials has seen us generate some fantastic replicas of retro video games, using Python. In past issues, we’ve create a lunar landing module game, a side-scrolling platformer, Pac-Man, Pong, the Game of Life, a bunny shooter, a racing game, and even an Angry Birds clone. Python is one of the most versatile programming languages around. It’s incredibly high level, making it very accessible, yet it can perform complex tasks. That’s why we’re able to recreate video games that would’ve taken a tremendous amount of processing power when they were first released, in just a few lines of code and using very few resources. This issue we’re going to create a maze runner. Maze runners were popular in the 1970s and 1980s, and tend to feature a player character, which usually consists of an oblong shape, traversing through a two-dimensional room of blockades and obstacles. Once the player reaches the other side of the maze, they’re transported to another room for a fresh challenge. This top-down maze approach was thought up in 1959, with Mouse in the Maze running on the original MIT TX-0 mainframe. With Atari creating the first commercial maze game Gotcha in 1973, though Head On (Sega, 1979) and Berzerk (Stern, 1980)are perhaps better remembered from this era. We’ll need Python3 installed for this project. Run sudo apt-get install python3 if you’re on a Debianbased distribution. Once installed, we can use Python IDLE to code our game. Remember to press File>New File upon opening it, and always code in the Script window. The Shell window opens by default, but no progress is saved when using this mode. When we want to save and/or test our game, at any point, we can just hit F5 and Python will take care of both saving and compiling our program. Of course, the first time we press F5 we’ll have to specify a save location. We’re not exclusively tied to Python IDLE. One of the great things about Python is its universal access. We can use any text editor to create a Python file, provided we save it with the extension .py, then type python3 filename.py in a terminal window to run the code. PyGame is a fantastic tool-set that comes with a

T

OUR EXPERT Calvin Robinson is a former assistant principal and computer science teacher and has a degree in Computer Games Design and Programming.

Introduce additional levels by creating additional room classes. Room4(Room) would make a new, fourth room, which inherits the properties of Room. Then it’s just a case of defining the ‘walls’ array.

92     LXF273 March 2021

Here we have our working, if basic at this stage, maze runner game.

whole host of physics and game-related programming methods that we can incorporate. As we always say, there’s no point re-inventing the wheel. Using PyGame enables us to focus on our game design, rather than spending a significant amount of time re-coding a rectangle in Python, so let’s make sure we have that installed, too: pip3 install pygame .

Programming our maze runner With everything installed, we can now begin programming our maze runner game. Let’s begin by importing the PyGame module and setting up our global variables by declaring and initialising them; import pygame BLACK = (0, 0, 0) WHITE = (255, 255, 255) BLUE = (0, 0, 255) GREEN = (0, 255, 0) RED = (255, 0, 0) PURPLE = (255, 0, 255)

We have gone with black, white, blue, green, red and purple colours, but of course these variables are completely arbitrary. It may be that we want to swap out purple with pink – all we’d need to do is change the

www.linuxformat.com


On the disc

DOWNLOAD YOUR DVD Get

code and DVD images at: www.linuxformat.com /archives

Discover the highlights from this month’s packed DVD!

START HERE USING THE LXFDVD

Using Linux for the first time can be very confusing. It’ll most likely be unlike anything that you’ve operated before, especially if you’re used to Microsoft Windows or Apple macOS. Generally our DVDs are designed to be run directly, which is to say that when you first power on your PC (or Mac, see below) it should ‘boot’ from the DVD – so before Windows or macOS even starts to load – with Linux running directly from the DVD. This trick is known as a Live Disc. It enables you to try out the various versions of Linux without having to install or change anything on your PC. Just remove the DVD, restart your PC and it’ll be exactly as you left it. While many systems will boot from a DVD when it finds one, many will not. See below for the standard process for enabling booting from a DVD on various desktops and laptop PCs. The alternative option is to locate the ISO file on the DVD and write this to your own USB thumb drive and attempt to run that. We recommend using Etcher from https://balena.io/etcher that’s available for Windows, macOS and Linux. Good luck!

XFCE DELIGHTS MIN SPECS: 1GHZ CPU >> 1GB RAM >> 30GB DISK

Manjaro 20.2 rch Linux is amazingly powerful, highly flexible and delightfully complex. So if you want to set up a no-nonsense OS for your desktop it’s more than capable, and you can choose exactly which bits to include and how to put them together. However, doing all that deciding and arranging takes time (and error messages). So there’s no shortage of “easy” Arch-based distros that offer such luxuries as a graphical installation process and a working desktop out of the box. Of these Manjaro is by far the most popular, and one of our favourites too. Last time it featured on the disc we showed you the new KDE Plasma flavour, but for this outing we’ve gone with the Xfce edition. The Xfce desktop is lighter and more traditional than your average Gnome, so this will work well on older systems and better serve people with more traditional desktop tastes. An exciting new Gnome edition is available too though. Manjaro is more or less Arch Linux under the hood, but they use their own repositories, and packages will lag behind Arch’s bleeding-edge offerings. Manjaro packages all undergo testing in a three-phase, Debian-like journey from Unstable to Testing to Stable, with

A

BOOT THE DISC

Many PCs should boot automatically if they’re turned on with a disc in the drive. If not, many offer an early Boot Menu accessed by tapping a key while powering up from cold: F9 (HP), F12 (Dell, Lenovo), F8 (Amibios) or F11 (Award BIOS). Alternatively, use the BIOS/UEFI to adjust the boot order to start with the optical drive. Again, this is accessed by tapping a key during power up, usually Del but sometimes F1 or F2. Some new UEFI PCs require access via Windows: holding Shift select its Restart option. If you’re still having problems using the DVD then visit www.linuxformat.com/ dvdsupport Mac owners: Hold the C key while powering on your system to boot from the disc.

96     LXF273 March 2021

64-bit most of the unstable packages coming straight from Arch’s repos. But Arch or no, you still inherit all that freedom and customisability. Furthermore, you gain the luxury of Manjaro’s hardware configuration wizard: a luxuriant Calamares installation experience and probably the finest Xfce desktop you’ve ever encountered. New in this release is a display dialog that will remember your multi-monitor configurations and now supports VSync for flickerfree gaming. There’s also all the fresh hardware support in the 5.9 kernel, support for encrypted boot partitions and all sorts of other things you can read about in places where they have bigger pages. If you want to install Snaps or Flatpaks it’s easy. Or it’s even easier to stick with the bundled Pamac package manager – a traditional graphical effort in the style of Synaptic. You’re also free to install packages from the Arch User Repository (AUR), with the caveat that they’re in no way guaranteed to work as smoothly as native Manjaro offerings. In response to overwhelming reader emails from Plague Island (formerly known as the UK), we’ve also strayed from our policy of not altering distros’ live media. So if you boot Manjaro from the DVD menu, it will now use the British keymap (here come the Yanks– Ed) and en_GB locale by default. You can choose anything else from the boot menu though, so don’t fret. It’s just we used to have an empire, you know.

The Arch Linux and Xfce combo is a winning one. Just look at these bold icons and business-meaning wallpaper.

IMPORTANT NOTICE!

DEFECTIVE DISCS: For basic help on running the disc or in the unlikely event of your Linux Format coverdisc being in any way defective, please visit our support site at www.linuxformat.com/dvdsupport. Unfortunately, we’re unable to offer advice on using the applications, your hardware or the operating system itself.

www.linuxformat.com


AND MORE! THE LXF LIBRARY  dvanced Bash A Scripting Guide Go further with shell scripting.

SUPER GECKO MUSCLES

 ash Guide for Beginners B Get to grips with the basics of Bash scripting.

GeckoLinux 152 ometimes it feels like openSUSE, and indeed its derivatives, don’t get enough attention. Surely having a gecko as a mascot (and being probably the second most successful Linux company in history) would be reason enough to hold space for them. To remedy this lack of gecko-based attention and affection, alongside Manjaro we’re featuring GeckoLinux. Like openSUSE, GeckoLinux comes in two forms: rolling and stable. We’ve gone with the stable (Static in Gecko parlance) version here, but if you’re feeling adventurous do try out the rolling branch (based on openSUSE Tumbleweed). There are also different desktop flavours for each branch, as well as a desktop-free minimal offering. Oh and there are “NEXT” releases, which feature bleeding-edge versions of each desktop. We’ve gone with the Cinnamon release here, and what a release it is. If you’ve ever been frustrated by Bluetooth headsets switching audio profiles mid-game then good news. The GeckoLinux team has got their distro to coerce PulseAudio into maintaining the higher-quality A2DP profile on supported hardware. GeckoLinux has long prided itself on its font rendering tweaks too, so if other distros have your characters and glyphs looking not quite perfect,

S

64-bit

then this is well worth checking out. Also, if you’ve tried openSUSE, but want something that’s a little more ready to roll, this is for you. Installation is much more simple, though you miss out on a few of openSUSE’s more advanced setup options. GeckoLinux uses the openSUSE repositories directly, so you have immediate access to a wealth of software. And you can enable third-party repos (such as those from Google or Skype) with a simple tick of a checkbox, enabling installation of specialist tools or patent encumbered bits. The popular Packman repository comes preconfigured, so all your favourite video codecs, games and other stuff that’s finicky to set up in openSUSE is blissfully simple here. The TLP power management suite is installed by default too, so your laptop will approve of these geckos. The YaST Tool (more traditional GUI package management) will make easy work of seeking and installing anything you like. But if you want a full-blown Software Centre you’d be best installing Gnome’s or KDE Discover. It’s nice to see Cinnamon being adopted by desktops other than Mint. After all, the Mint team designed it with portability in mind. So now you can have Cinnamon-flavoured Ubuntu, Arch and more. Likewise, it’s nice to see GeckoLinux offering Budgie, LXQt and (at least for the rolling edition) the Pantheon desktop from elementary OS. If you’ve never seen openSUSE before, then this is a great way to get an overview and learn the ropes.

 ourne Shell Scripting B First steps in shell scripting.  he Cathedral and T the Bazaar Eric S Raymond’s classic text explains the advantages of open development.  he Debian Book T Essential guide for sysadmins.  ive Into Python D Everything you need to know. I ntroduction to Linux A handy guide full of pointers for new Linux users.  inux Dictionary L The A-Z of everything to do with Linux. Linux Kernel in a Nutshell An introduction to the kernel written by master hacker Greg Kroah-Hartman.  he Linux System T Administrator’s Guide Take control of your system.  ools Summary T Overview of GNU tools.  NU Emacs Manual G Six hundred pages of essential information!  roducing Open P Source Software Everything you need to know.  rogramming from P the Ground Up Take your first steps.

Spice up your life with multiple extensions and applets that can be added to the Cinnamon desktop.

NEW TO LINUX? START HERE…

Never used a Linux before? Here are some handy resources: Read our quick-install guide http://bit.ly/LXFinstall Looking for an answer? https://askubuntu.com Want to delve more deeply? https://linuxjourney.com

www.techradar.com/pro/linux

March 2021 LXF273     97


9000

FORTRESS LINUX! The simple steps you can take to protect your kernel against intrusion and attack.

The #1 open source mag Future Publishing Limited, Quay House, The Ambury, Bath, BA1 1UA Email linuxformat@futurenet.com EDITORIAL Editor Neil “home schooling” Mohr Technically an editor Jonni Bidwell Art editor Efrain Hernandez-Mendoza Operations editor Cliff Hope Group editor in chief Graham Barlow Senior art editor Jo Gulliver Editorial contributors Mike Bedford, Neil Bothwick, Stuart Burns, Christian Cawley, Sean Conway, Alan Dexter, Matthew Hanson, Jon Masters, Nick Peers, Les Pounder, Michael Reed, Calvin Robinson, John Schwartzman, Mayank Sharma, Shashank Sharma, Alexander Tolstoy Cover illustration magictorch.com

Raspberry Pi is a trademark of the Raspberry Pi Foundation. Tux credit: Larry Ewing (lewing@isc.tamu.edu) and The GIMP. Ubuntu is a trademark of Canonical Limited. We are not endorsed by or affiliated with Canonical Limited or the Ubuntu project. Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc.

ADVERTISING Media packs are available on request Commercial sales director Clare Dove clare.dove@futurenet.com Senior advertising manager Lara Jaggon lara.jaggon@futurenet.com Head of commercial – Technology Dave Randall dave.randall@futurenet.com Account director Andrew Tilbury andrew.tilbury@futurenet.com INTERNATIONAL LICENSING Linux Format is available for licensing. Contact the Licensing team to discuss partnership opportunities. Head of Print Licensing Rachel Shaw licensing@futurenet.com NEW SUBSCRIPTIONS & BACK ISSUES Web www.magazinesdirect.com UK 0330 333 1113 World +44 (0) 330 333 1113 EXISTING SUBSCRIPTIONS Web www.mymagazine.co.uk UK 0330 333 4333 World +44 (0) 330 333 4333 CIRCULATION Head of newstrade Tim Mathers

LXF274

will be on sale Tuesday 9 March 2021

PRODUCTION AND DISTRIBUTION Head of production UK & US Mark Constance Production project manager Clare Scott Senior ad production manager Jo Crosby Digital editions controller Jason Hudson THE MANAGEMENT Chief audience and ecommerce officer Aaron Asadi MD, tech specialist Keith Walker Head of art & design Rodney Dive Commercial finance director Dan Jotcham Printed by Wyndeham Peterborough, Storey’s Bar Road, Peterborough, Cambridgeshire, PE1 5YS Distributed by Marketforce, 5 Churchill Place, Canary Wharf, London, E14 5HU www.marketforce.co.uk Tel: 0203 787 9001 Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries. GNU/Linux is abbreviated to Linux throughout for brevity. Where applicable code printed in this magazine is licensed under the GNU GPL v2 or later. See www.gnu. org/copyleft/gpl.html. All copyrights and trademarks are recognised and respected.

Window mangers Let’s get back to basics and pitch the best open source   window managers head-to-head. Seconds out, round one!

Raspberry Pi Pico voltmeter Do you have £3.60 burning a hole in your pocket? Then grab a Pico and follow our first Pi Pico project building a voltmeter.

PC GPIO GPIO isn’t just for the Raspberry Pi you know – we explore how your normal PC can interact with the outside world.

Disclaimer All contents © 2021 Future Publishing Limited or published under licence. All rights reserved. No part of this magazine may be used, stored, transmitted or reproduced in any way without the prior written permission of the publisher. Future Publishing Limited (company number 2008885) is registered in England and Wales. Registered office: Quay House, The Ambury, Bath BA1 1UA. All information contained in this publication is for information only and is, as far as we are aware, correct at the time of going to press. Future cannot accept any responsibility for errors or inaccuracies in such information. You are advised to contact manufacturers and retailers directly with regard to the price of products/ services referred to in this publication. Apps and websites mentioned in this publication are not under our control. We are not responsible for their contents or any other changes or updates to them. This magazine is fully independent and not affiliated in any way with the companies mentioned herein. If you submit material to us, you warrant that you own the material and/or have the necessary rights/permissions to supply the material and you automatically grant Future and its licensees a licence to publish your submission in whole or in part in any/all issues and/or editions of publications, in any format published worldwide and on associated websites, social media channels and associated products. Any material you submit is sent at your own risk and, although every care is taken, neither Future nor its employees, agents, subcontractors or licensees shall be liable for loss or damage. We assume all unsolicited material is for publication unless otherwise stated, and reserve the right to edit, amend, adapt all submissions. All contents in this magazine are used at your own risk. We accept no liability for any loss of data or damage to your systems, peripherals or software through the use of any guide. Notes: Here’s to having a better new year in 2022. We are committed to only using magazine paper which is derived from responsibly managed, certified forestry and chlorinefree manufacture. The paper in this magazine was sourced and produced from sustainable managed forests, conforming to strict environmental and socioeconomic standards. The manufacturing paper mill and printer hold full FSC and PEFC certification and accreditation.

Future is an award-winning international media group and leading digital business. We reach more than 57 million international consumers a month and create world-class content and advertising solutions for passionate consumers online, on tablet & smartphone and in print.

Black and white photos We fire up GIMP and explore the editing tricks and techniques you can use to take your B&W photography up a notch or two. Contents of future issues subject to change, depending on how much work gets done during home schooling.

98     LXF273 March 2021

Future plc is a public company quoted on the London Stock Exchange (symbol: FUTR) www.futureplc.com

Chief executive Zillah Byng-Thorne Non-executive chairman Richard Huntingford Chief financial officer Rachel Addison Tel +44 (0)1225 442244

Profile for Future PLC

Linux Format 273 (Sampler)  

You can subscribe to this magazine @ www.magazinesdirect.com

Linux Format 273 (Sampler)  

You can subscribe to this magazine @ www.magazinesdirect.com