Wednesday, 3 August 2016

ZX81 Kiosk Mode for Raspberry Pi / AZ15 (Part 1)


The final piece to the ZX81 keyboard puzzle is to get the Raspberry Pi / AZ15 to boot like it's 1981, arriving straight at the Sinclair "K" prompt after being switched on. Booting won't be measured in seconds (actually it comes in at about 20 seconds) as it was in 1981, after all 35 years of progress takes extra time. Though to be fair, the loading of software after booting up a ZX81 was measured in aeons.

There are many ways to boot a Pi into a Kiosk like mode, I've gone with one of the easiest, simply hijacking the pre-existing Openbox Xsession. The process outlined below is applied on top of a default Raspbian Jessie installation.

Installing the sz81 Emulator


Fist up you'll need a ZX81 emulator, I've been using various sz81 versions to test the AZ15, and have found the last official release, sz81-2.1.7,  the most stable for my purposes.

- Download the official sz81-2.1.7 release of sz81 from http://sz81.sourceforge.net/
- Alternatively, experiment with the unofficial updates provided at http://rullf2.xs4all.nl/sz81/

After downloading and decompressing the sz81-2.1.7-source.tar.gz file, edit the makefile in the source directory, and change the installation type to system wide. Full details can be found in the sz81 REAME file.


# Comment/uncomment these to choose an installation destination
# System wide installation
PREFIX?=/usr/local
BINDIR?=$(PREFIX)/bin
DOCDIR?=$(PREFIX)/share/doc/$(TARGET)
PACKAGE_DATA_DIR?=$(PREFIX)/share/$(TARGET)


Also, if not already installed grab, the SDL develpment libararies from the repositories, as these will be required before compiling the sz81 source.

sudo apt-get install libsdl1.2-dev

Then from the sz81 source directory, make and install sz81 itself.

make
sudo make install


Auto Login the PI User


Now that we have an emulator installed, we'll want it to execute on boot up.

If the Pi isn't already configured to Boot to the Desktop and / or Auto Login, you can access the graphical config utility using the “Preferences” > “Raspberry Pi Configuration” menu. Set the preferences as below:


If your Raspberry Pi wasn't previously configured to boot to the desktop, reboot it now before continuing, in order to test all is well so far.

Simple PI / ZX81 Emulator Kiosk


Raspbian Jessie ships with 3 pre-configured desktop environments:


  1. Default Xsession: An LDXE enironment using version 3 GTK+ of toolkit
  2. LDXE: An LDXE enironment using version 2 GTK+ of toolkit
  3. Openbox: Amazingly configurable Desktop


For our purposes we'll essentially hijack Openbox for auto logon and startup the sz81 emulator. Openbox is a very user configurable and we shall be ignoring most of that power co-opt it for our Kiosk style login.

Editing or create an OpenBox autostart file (using Geany or Nano from a console) in a sub-directory off the pi users home directory.

nano ~/.config/openbox/autostart


# *** Set some Openbox options ***
# Set a background colour to Black
BG=""
if which hsetroot >/dev/null; then
  BG=hsetroot
elif which esetroot >/dev/null; then
  BG=esetroot
elif which xsetroot >/dev/null; then
  BG=xsetroot
fi
test -z $BG || $BG -solid "#000000"

# *** Configure and Run the ZX81 emulator ***

# If you have ZX81 P files / Roms in a handy Dirctory, cd to it first.
# This obviously makes life easier later on.
cd ~/Files/emulation/zx81

#Set az15 keyboard options, if you haven't built a az15 the comment this out.
echo emulator bell beep off> /dev/ttyACM0

# Run the sz81 emulator in fullscreen mode
sz81 -f -1280x900

# *** On emulator Close exit Openbox ***

#Set az15 keyboard options, if you haven't built a az15 the comment this out.
echo standard bell beep on> /dev/ttyACM0

openbox --exit


Save the files and that's the basic kiosk like configuration completed.

Now log out of the default LXD environment. Once back to the logon screen, select Openbox from the drop down menu on the top left of the screen. If everything has gone to plan the sz81 emulator should startup.

If you now exit the sz81 emulator, you should once again be dropped back to the logon screen. This time select Restart from the power menu and the PI should boot directly into Openbox and open the emulator, as by default the last Desktop Environment will be selected on a system restart.

Retro Pixel Inducing Splash Screen

Setup a Splash Screen


Get into that 80s spirit with a Loading Screen. Technically there were no splash screens on a ZX81, unless you count the wavy lines that take over the screen when loading from tapes, but lets no spoil things. I've made up a rather retro and referential black and light grey image for the purpose, but use what ever image floats your boat.

Log onto the console and create a directory.

sudo mkdir /etc/images

Copy your chosen image into that directory, make sure your image is in the PNG format.

sudo cp /home/pi/"YOUR IMAGE".png /etc/images/az15-splash.png

Now we need a FrameBuffer Image viewer to run on boot.

sudo apt-get install fbi

Create a startup file and edit the contents.

sudo nano /etc/init.d/az15-splash-screen


#! /bin/sh
### BEGIN INIT INFO
# Provides:          az15-splash-screen
# Required-Start:
# Required-Stop:
# Should-Start:      
# Default-Start:     S
# Default-Stop:
# Short-Description: Show custom splashscreen
# Description:       Show custom splashscreen
### END INIT INFO

do_start () {
  /usr/bin/fbi -T 1 -noverbose -a /etc/images/az15-splash.png    
  exit 0
}

case "$1" in
  start|"")
    do_start
    ;;
  restart|reload|force-reload)
    echo "Error: argument '$1' not supported" >&2
    exit 3
    ;;
  stop)
    # No-op
    ;;
  status)
    exit 0
    ;;
  *)
    echo "Usage: az15-splash-screen [start|stop]" >&2
    exit 3
    ;;
esac

:


Now, make the file executable and get the system to recognise it as an init script.

sudo chmod a+x /etc/init.d/az15-splash-screen
sudo insserv /etc/init.d/az15-splash-screen

Reboot and you should have something very similar to the video clip below.


Credit Where It's Due Most


Much thanks to the following sites and blogs describing the exact or very similar processes, leading to an article that's boarding on plagiarism.

Run a ZX81 Emulator in "kiosk" mode on a Raspberry Pi
Building a Raspberry Pi Kiosk
Openbox Wiki Entry on Autostart