Sunday, 28 August 2016

AZ15 Raspberry PI 3 Upgrade

I've taken the opportunity to upgrade the heart of the AZ15 to a Raspberry PI 3, up from a PI 2. The neat thing about the last few models of PIs' has been the unchanging form factor with increasing capabilities.

There has been a noticeable speed boost between the PI 2 and PI 3, this has been most evident when using the ZEsarUX emulator. Previously ZEsarUX has seemed somewhat sluggish on the PI 2, leaving SZ81 as my emulator of choice. With the performance improvements on the PI 3, the choice of emulator is now wide open, a nice change indeed.

Also  the PI 3s' addition of baked in Bluetooth and WIFI has meant that a number of the USB ports formerly dedicated to these tasks are suddenly free. With the PI 2, I had dedicated one of the internal (to the AZ15) USB ports to a WIFI dongle, with the advent of the PI 3 new found connectivity option, I've instead inserted a small in stature and capacity USB flash drive for ZX81 ''P" file storage. Additionally with Bluetooth now available, wireless mice in particular are easy to add.

AZ15 With Bluetooth Mouse and WIFI

AZ15 Concept Image

A What's in the Box Shot


All the nice additions to the PI 3 bring the whole AZ15 project pretty damn close to the original concept image; thanks to the addition of a Bluetoooth mouse and the ever unseen WIFI.

So now it's time for a new glory shot, a shot which I've taken at as close to the same angles and lighting conditions as manageable.

What do you think?


Sunday, 21 August 2016

Brand New Version ZX81 Arduino Keyboard Sketches

This week brings major changes to the Arduino sketch, so big I'm calling this latest modification version 2.

The last update still left me somewhat dissatisfied with the keyboards performance in some emulators. The deficiencies were particularly apparent when playing games, where the keyboard would not respond smoothly and in a timely fashion. To remedy the response time problems, I went back and re-examined how the code was first put together.


When Originally written, I'd relied on the Keyboard.print function to send key presses, which worked fine during initial testing. Unfortunately that didn't work so well when incorporate the shift, graphics and function modes into the keyboard. Using the Ardunio keyboard Keyboard.press functionality solved that issue and all seemed to be okay for a while. There were still some problems that become noticeable in various emulators, and these I addressed with some debouncing routines (which culminated in the last code release).

To cut it all short the debouning routines were the completely wrong solution to the problem and as it turned out I'd completely overlooked a decent Keyboard.release method. After a mild dose of head scratching in the effort to remedy past errors, I'm releasing what I'm calling version 2 of the sketches.

The Version 2 removes the kludge of keyboard debouncing, and now thankfully we have a keyboard that functions just as well as that on any self respecting ZX81.

The command line / serial switches have, thanks to the changes, slimmed back down. The need for extra commands to set extended emulation behavior have been removed.


Command Line, Mode and Options Selection
BELLSound the LeoStick Piezo. Could be used to forward audio system notifications etc. 
BEEP OFFTurn off Keyboard Sounds. Sounds are off by default.
BEEP ONTurn on Keyboard Sounds. Similar to the keyboard clicks made by ZX Spectrum when typing. The keyboard only emits clicks in Standard mode. In Emulation mode sound is always off.
DEVICEReturns message "ZX81_KEYS" to the console. Useful if unsure you have the correct serial port. You must be monitoring incoming streams to get the return message. eg cat /dev/ttyACM0
EMULATORSwitch the keyboard into emulator mode.
STANDARDSwitch the keyboard into standard mode.

All versions of the keyboard sketches are avaliable from the Project Files page.

Sunday, 14 August 2016

Arduino Sketch Updates for Keyboard Debounce Timimgs

I've made some minor changes to the Arduino sketches over the weekend. The alterations affect the debounce timings, where I've hopefully improved keyboard response while in EMULATOR modes. The latest Code can be downloaded from Project Files page.

A new switch DBEM ON / OFF, for piping to the Arduino serial console, has been added. The switch is designed to set the STANDARD mode debounce timimgs to those use in EMULATOR mode. This is particularly useful if the emulator frequently requires the keyboard to be switched to STANDARD mode. I found that in particular ZEsarUX requires STANDARD mode to be set quite often to load files or change options etc.

The below example  sets the keyboard to EMULATOR mode, sounds the BELL and turns DBEM ON.

echo emulator bell dbem on> /dev/ttyACM0

Setting DBEM ON will also negate the use of the BEEP ON option. For more extra information on switches see the earlier blog entry AZ15 and A Tale of Two Features.


Command Line, Mode and Options Selection
BELLSound the LeoStick Piezo. Could be used to forward audio system notifications etc. 
BEEP OFFTurn off Keyboard Sounds. Sounds are off by default.
BEEP ONTurn on Keyboard Sounds. Similar to the keyboard clicks made by ZX Spectrum when typing. The keyboard only emits clicks in Standard mode. In Emulation mode sound is always off.
DBEM OFFUse normal STANDARD mode debounce timings. This is the default option.
DBEM ONUse EMULATOR keyboard debounce timings in STANDARD mode. Good to set if switching to STANDARD mode frequently while using an Emulator. Switch was added with ZEsarUX in mind in particular. Default if off.
DEVICEReturns message "ZX81_KEYS" to the console. Useful if unsure you have the correct serial port. You must be monitoring incoming streams to get the return message. eg cat /dev/ttyACM0
EMULATORSwitch the keyboard into emulator mode.
STANDARDSwitch the keyboard into standard mode.


Saturday, 13 August 2016

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


In Part 1, we setup the AZ15 to boot into a kiosk mode that relied on X11. This is all well and good, but why use an X11 windows manager when we don't really need to.

All the major ZX81 Emulators available for use on the Raspberry Pi have SDL versions available, and SDL dosn't require an X11 windows manager. Booting right into an emulator will speed up the startup process and get us "programming" our ZX81 in not time at all.

All the hard work such as installing the sz81 emulator was covered in Part 1. This time around we only need to make some minor alterations.

Auto Login the PI User to the CLI


First off, a couple of minor config changes from the last blog entry. We need to set auto login to the CLI instead of the Desktop. From the X11 desktop (startx if you need to), access the graphical config utility using the “Preferences” > “Raspberry Pi Configuration” menu. Set the options as below:


Auto Run the ZX81 Emulator at Login


Next up add the following Code to the end of your /home/pi/.bashrc file.


# Run if tty1
if [ $(tty) == /dev/tty1 ]; then
 # *** 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 dbem on> /dev/ttyACM0

 # Run the sz81 emulator in fullscreen mode
 sz81 -f -1024x768

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


That's it, we can now boot right on into the emulator after the next "reboot".

A Little Extra Visual Config Enhancement


Normally when the Pi boots up a whole load of logging and informational messages scroll down the screen. While this is all very useful information (depending on your perspective), it's not exactly helping generate that 80s mircro-computer vibe.

So let's hide the information overload by adding some extra switches into the Raspberries "cmdline.txt" file.

sudo nano /boot/cmdline.txt

All the configuration options will be on the first line of the file, change the following details.

Find:
console=tty1

Change to:
console=tty3

Next, add the following commands to the end of the line.

loglevel=3 logo.nologo

If you reboot now, having made the above changes in combination with Part 1's instructions, then you should see something very similar to the video clip below. (You'll probably also notice I changed the Splash Screen).



Now the AZ15 has booted up, we're ready to do some serious programming, or the somewhat more likely scenario, play the excellent "Crozxy Road" from Bobs Stuff.
 



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