## More than a game: the Game of Life

Conway’s Game of Life has long fascinated me. Thirty years ago I wrote some Z80 machine code to run it on a Sinclair ZX80 and when I wrote BINSIC, my reimplentation of Sinclair ZX81 BASIC, Life was the obvious choice for a demonstration piece of BASIC (and I had to rewrite it from scratch when I discovered that the version in Basic Computer Games was banjaxed).

But Life is much more than a game – it continues to be the foundation of ongoing research into computability and geometry – as the linked article in the New Scientist reports.

For me, it’s just fun though. When I wrote my first version of it back in 1981 I merely used the rubric in Basic Computer Games – there was no description of gliders or any of the other fascinating patterns that the game throws up – so in a sense I “discovered” them independently, with all the excitement that implies: it is certainly possible to spend hours typing in patterns to see what results they produce and to keep coming back for more.

• “Life.bas” should run on any system that will support the Java SDK – for instance it will run on a Raspberry Pi – follow the instructions on the BINSIC page. A more up to date version may be available in the Github repository at any given time (for instance, at the time of writing, the version in Git supports graphics plotting, the version in the JAR file on the server only supports text plotting). On the other hand, at any given time the version in Git may not work at all: thems the breaks. If you need assistance then just comment here or email me adrianmcmenamin at gmail.

## Relive the ZX81 experience on your desktop

BINSIC – my reimplementation of ZX80 or ZX81 (Timex Sinclair 1000 or 1500 for US readers) BASIC is now available for download in binary form – look at the page on the site: Binsic Is Not Sinclair Instruction Code.

It comes with Conway’s Game of Life for the authentic black and white text based feel too.

(Source code is also available here)

## Progress with BINSIC

BINSIC – Binsic Is Not Sinclair Instruction Code – my effort to re-implement Sinclair ZX80/ZX81 BASIC as a domain specific language via Groovy (and eventually a runnable Java JAR file), is making more progress.

Right now it supports:

IF ... THEN ... ELSE
GOTO
GOSUB ... RETURN
LET
FOR ... TO ... STEP ... NEXT
DIM A(x, y, z) (and array derefencing)
CLS
PRINT

Still one or two difficult areas to get through and I have had to make one compromise – unlike on the ZX80 one cannot have a variable and an array with the same letter designation – just too difficult to implement on Java/Groovy.

But, it’s getting there…

## Just like 1980

There have been (conservatively) 16 “Moore generations” since 1980 – that is to say computing speed should have increased by $2^{16}$ – approximately 4 million times.

But computation requirements grow to fill the computing power available and BINSIC now runs at about the same speed, when executing the same code, as my ZX80 did when hacking its way through BASIC programs 32 years ago.

It’s a strange sight to see, because it is so evocative of that period.

The code runs slowly largely, I think, because of the way that I have chosen to handle GOTO statements (not that I could think of any other way) – essentially the whole or at least a substantial part, of the program is reparsed every time a GOTO is issued.

Anyway, it adds to the sense of realism!

## And a tougher regular expression problem

So, here’s a tougher regular expressionproblem – one I have not yet worked out myself.

BASIC‘s essential looping structure is a FOR (STEP) ... NEXT loop. In ZX80/ZX81 BASIC (the dialect I am aiming to emulate with the BINSIC DSL) this is of the form FOR v = num TO num STEP num... NEXT v, where v is a single letter counter variable and num a valid numerical expression.

Groovy does not implement a FOR loop as such but it is not difficult to cover the simple and common case of a STEP 1 loop (though other values might be more difficult), but the tricky bit is that BASIC FOR ... NEXT loops can be nested. So what regular expression will grab the insides of a loop?

Update: The best thing about blogging is that sometimes it helps to clarify the problem. And it has done so here even as I wrote this. I don’t need to worry about the nested loops at all – all I need to do is substitute some code for the FOR statement and replace the NEXT with a }. This has the added advantage of saving poor BASIC coders from disordering their  NEXT  statements.

## Back from the dead (almost)

The graphic you can see here is the partially recovered code of a program I wrote thirty years ago – “hexmon” – to display chunks of ZX80 memory in hexadecimal format (at least I think that’s what it did).

I am determined to fully recover it – but as you can see it works well so far and the machine code string in the middle looks particularly good – especially as I can see it ends with C9 which I know is the Z80 “return” command.

## First bit of assembler

According to my diary for 22 March 1981 – this is the first piece of working assembler (actually it was Z80 machine code as there was no assembler program) I wrote:

LD IX(400Ch) INC IX LD HL, 402Bh LD B, 0Ah LD A (HL) LD (IX + 0), A INC HL INC IX DJNZ RET

I think it became part of a bigger “Hexmon” program to display chunks of internal memory on screen.

## Thirty years ago today…

According to my diary I spent my spare time mucking about coding: loading the BASIC version of “Lunar Lander” – from Basic Computer Games – on to my ZX80. So much for putting away childish things.

## More computing nostalgia

I stumbled across this collection of covers of “Practical Computing” – or as they styled it Practical Comp$\mu$ting – a really great magazine from the early days of “microcomputers” in the UK.

It used to have articles which were a bit more scientific and investigatory than others – I particularly remember one talking about how to describe n-dimensional space in a program.

I particularly remember these covers/issues – some of which still look great to me today, thirty years on. I desperately wanted to run the US presidential election program here too, but it used elements of the BASIC language that I simply could not work out how to substitute for from the ZX80’s limited vocabulary (back then most things were targeted at the variety of BASIC found on a Commodore PET).

(NB as I recall the junior minister was Kenneth Baker).

Hmmm… Fast Fourier Transforms….

And finally – I remember thinking this was a stunning image: