Red Alert 2 on Raspberry Pi 400

Guide on how to run Red Alert 2 on a Raspberry pi 400

Posted by J├╝rgen on 9 October 2022

What?

The Raspberry Pi 4/400 is a rather capable little board (in case of the 400, encased in a keyboard housing, akin to the home computers we used to love). With its 4 ARM cores and increased amount of memory, it can be used for a multitude of tasks. One of those tasks I'd like to investigate, is running a 20+ years old RTS which was available for Windows PC's.

Why?

I bought a Raspberry Pi 400 for light programming tasks; some python in Thonny, Arduino coding and later programming the Pi Pico. After I got Minecraft working on the device, I decided to give my kids (ages 5 and 7 at that time) each a Pi 400 with Minecraft preinstalled, so we could mess around in our own server. After my oldest kid got the taste of multiplayer C&C: Remastered, I took it on myself to get C&C working on the Pi's, this so my wife and I could reclaim our gaming laptops. At first I used DosBox and my old C&C: Tiberium Dawn CDs, and had a separate DosBox on my server which opened up and IPX server. While this did indeed work, I had forgotten how low-res the DOS version of C&C was, and how limited the multiplayer experience was.

So after this attempt I went to RA2, that one being one of my favorite RTS-es of all time, so my kids and I could multiplayer Red Alert 2.

How?

That's the question. I'll be using a 64 bit installation of Raspberry Pi OS, 64 bit since this is what I used for my Minecraft installation, and I'd like to keep using that. Comparison between the Pi and RA2:

Pi offers

  • 64 bit
  • Linux
  • ARM architecture

RA2 requires

  • 32 bit
  • Windows
  • x86 architecture

So nothing matches. In this guide I'll describe how to bridge those gaps, and get the game to run at acceptable performance.

Software

First a description of packages/technology I'll be using:

schroot

schroot is a chroot jailing environment, I'll be using this to create a 32 bit (armhf) environment within my 64 bit (arm64) OS. This is required to run 32 bit software, since a 64 bit Pi OS is purely 64 bit, and I did not feel like Frankenstein-ing my install into a hybrid system. This is the environment in which wine will be started. Some compiling for 32 bit is needed, so a complete 32 bit toolchain needs to be set up.

wine

Wine Is Not an Emulator. This the go-to way to run windows software on linux-based systems. This is required to run Red Alert 2, which is windows program. 32 bit wine is required to run 32 bit windows software.

box86

Although wine can be used to run windows programs, since it is not an x86 emulator itself, it will need some layer to translate between x86 and armhf. After evaluating qemu it became apparent something more performant was needed, enter box86. box86 does just that, translate instructions. box86 needs to run on a 32 bit subsystem. Performance can be reached by including the DynaRec re-compiler in the binary.

Installation

schroot


sudo apt install schroot debootstrap
sudo mkdir -p /srv/chroot/debian-armhf
sudo debootstrap --arch armhf --foreign buster /srv/chroot/debian-armhf/
sudo chroot /srv/chroot/debian-armhf/ /debootstrap/debootstrap --second-stage
sudo vim /etc/schroot/chroot.d/debian-armhf.conf

Note that for <user> the non-root user should be used that's normally used for the desktop.


[debian-armhf]
description=Debian Armhf chroot
aliases=debian-armhf
type=directory
directory=/srv/chroot/debian-armhf
profile=desktop
personality=linux
preserve-environment=true

To add the current user to the users allow to start the chroot:


echo users=$(whoami) | sudo tee -a /etc/schroot/chroot.d/debian-armhf.conf

box86

In a root chroot:


sudo schroot -c debian-armhf
apt update && apt upgrade
apt install -y git wget cmake build-essential python3 gcc-arm-linux-gnueabihf libtinfo5 libpng16-16 libfreetype6 libxinerama1 libxxf86vm1 libxrender1 libxcomposite1 libxi6 libxcursor1 libfontconfig1 libxrandr2 libvulkan1 libgl1 libmpg123-0 libasound2 libpulse0

mkdir -p ~/GIT
cd ~/GIT
git clone https://github.com/ptitSeb/box86

schroot -c debian-armhf
echo DISPLAY=:0 >> ~/.bashrc
cd ~/GIT/box86
mkdir build
cd build
cmake .. -DARM_DYNAREC=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
make -j6

Note, DYNAREC, the dynamic re-compiler, is required for a performance boost.

Wine


schroot -c debian-armhf
cd
wget https://twisteros.com/wine.tgz
tar xvzf wine.tgz
rm wine.tgz

Some tweaks for pulseaudio


echo /run/user/1000 /run/user/1000 none rw,bind 0 0 | sudo tee -a /etc/schroot/desktop/fstab
echo machine-id | sudo tee -a /etc/schroot/desktop/copyfiles

Install Red Alert 2

If you need access to removable media


echo /media/<user>/<uuid>/ /media/ none rw,bind 0 0 | sudo tee -a /etc/schroot/desktop/fstab

This will add a directory to the chroot environment. Remember to remove this line from the fstab when you're done, and don't need the medium anymore.

Installation


schroot -c debian-armhf ~/GIT/box86/build/box86 ~/wine/bin/wine explorer

This will start a Windows file explorer, from here you can navigate to your installation files and begin installing Red Alert 2 like you would on a normal Windows machine. After completing the installation, you'll need to remove any external media added to the /etc/schroot/desktop/fstab. Note: For this instance I've downloaded a repackaged installer of RA2, even though I have the original disks. This is mainly because of the lack of CD-ROM player for the Pi and the laziness of me, not wanting to bypass copy-protection in order to create an ISO.

Red Alert 2 installer

Setting up a launcher

First of all, create a script to run the game. In this script, a few lines are added to switch between resolutions, to prevent the game from having some weird behavior. You can try to run the game without the xrandr lines. Let's name the script ~/run-ra2.sh. You'll note the xrandr lines are repeated twice, each for HDMI-1 and HDMI-2, this is because the Pi 400 has 2 HDMI ports. If you're using 2 screens, remove the one which does not need to switch resolutions. Also, the resolutions are tweakable, but the ones below are mostly defaults.


#!/usr/bin/bash

xrandr --output HDMI-1 --mode 800x600
xrandr --output HDMI-2 --mode 800x600

/usr/bin/schroot -c debian-armhf ~/GIT/box86/build/box86 ~/wine/bin/wine "c:\\Program Files\\<..Red Alert 2 Path..>\\Red Alert 2.exe"

xrandr --output HDMI-2 --mode 1920x1080
xrandr --output HDMI-1 --mode 1920x1080

# The line below is to kill every wine-like process afterwards, since some processes remain.
ps aux | grep "\.exe" | awk '{ print $2 }' | xargs kill

Using the main menu launcher, create a launcher in Games:

Launcher

Performance

Edit the ddraw.ini and set singlecpu to false to enable multi-core performance. And set renderer to opengl to benefit from hardware rendering. launch winecfg and set ddraw.dll to native.


schroot -c debian-armhf ~/GIT/box86/build/box86 ~/wine/bin/wine winecfg

WineCFG

For this install, the same overclock settings are used as stated in the minecraft article. Summarized below:


arm_freq=2147
over_voltage=8
gpu_freq=750

Final thoughts

I'm really happy with this. Being able to play a game of which I have fond memories on a relatively cheap machine. And to top it off, I can share this with my children.

References

switchroot.org - For reference on setting up an Armhf root.