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).
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.
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.
There have been (conservatively) 16 “Moore generations” since 1980 – that is to say computing speed should have increased by – 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.
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.
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.
I stumbled across this collection of covers of “Practical Computing” – or as they styled it Practical Compting – 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:
Not everything about computing is on the internet.
Sometime around this point thirty years ago my brother and I went to a computer exhibition in London – “Breadboard 81”
There are a couple of references to it findable through Google. But not much.
It was a fantastic experience – but perhaps also the end of an era: the computer that feature most of all was the “UK 101” – a kit based effort with a real keyboard (unlike the ZX80 Conor and I were using).
It is impossible to describe the thrill one could get from being able to see, use and program (in either BASIC or assembler/machine code) any of these devices: everyone was a pioneer and everyone was equal. (Though this book this book captures the feel of the era that was dying even as it peaked.)
Perhaps there are others who will read this who were also there and who can share their memories of this moment… reminding me of where it even was would be a start? Olympia?