This month Simon Goodwin sifts through the accumulated post and checks out the first book about Spectrum Plus Two machine code programming.
The Spectrum manuals explain how to program in BASIC, but tell you next to nothing about machine code — the language used to program most commercial games. This month I’ve looked at a new book from Melbourne House which promises to teach machine code to the ‘absolute beginner’.
Last month I reviewed Hisoft’s BASIC compiler — a program that translates BASIC into machine code, the fastest code the Spectrum can handle and the code used for virtually all commercial games. Compilers will speed up BASIC, but they don’t let you add much to the language, and — at least on the Z80 — they rarely produce code as quickly or concisely as a human can. So there’s still a market for human beings who can write machine-code to order, and anyway it’s great fun it you’ve got time to learn. Machine code programming also teaches you a lot about the ‘inner workings’ of the computer.
Spectrum Plus Two Machine Language for the Absolute Beginner is the first ‘Plus Two’ book I’ve received for review. The publishers say the book will suit experienced Spectrum coders as well as beginners, because it details the special features of the new model. Contrary to the impression given by the title though, this is not a book for those with no programming experience. The introduction says that it is aimed at people who can already program in BASIC. I would not advise anyone to learn machine code as a first computer language.
There are 16 chapters, which split into three sections. The first part introduces the ideas which underlie machine code programming. Then come five chapters that list the ‘instructions’ which the Z80 processor can recognise. The last seven chapters are, to my mind, the best in the book — they deal with specific ‘concepts’ like sound, interrupts, the display, and so on. The one and a half page index is totally inadequate — it doesn’t mention the LDIR instruction, or the RS-232 interface, for example.
The first chapter is by far the worst , but luckily it’s also the most dispensable. It’s a mixture of patronising waffle and a bare minimum of ‘hard facts’. Memory is referred to as ‘boxes’ and registers are called ‘hands’ and ‘feet’. By the end of Chapter One, we know that the computer has a ‘CPU’ — a two inch piece of black plastic with 40 metal legs — plus a number of ‘hands’ and ‘feet’, where two ‘hands’ equals one ‘foot'; a ‘foot’ has sixteen ‘toes’ and a ‘hand’ has 8 fingers! Besides the processor, the computer contains a mysterious ‘spike’ called a stack, which the CPU can push with two ‘hands’ — it’s a good job most readers will already know what this chapter sets out to explain.
Chapter One is the only part of the book which makes specific reference to the Plus Two — other sections refer to the Spectrum 128, and it seems certain that the book was originally written for users of the original (pre-Amstrad) 128. That doesn’t matter much, as the differences between the two are almost entirely cosmetic, from the point of view of the machine code programmer at least. There is one annoying section however, that witters on about ‘the EAR and MIC sockets of the tape interface’, which don’t appear on the Amstrad Spectrum.
The second chapter is a vast improvement — a clear explanation of the ‘binary’ and ‘hexadecimal’ numbering systems used by machine code programmers. Binary numbers are printed with a zero at the start to distinguish them from decimal; hexadecimal numbers start with an ampersand when they crop up in the text, but a hash when they appear in programs. According to the text, some values are marked with a trailing ‘H’, but — thankfully — I couldn’t find any of those. Once numbers have been dealt with, the ‘background’ part of the book ends with a useful chapter about the inter-relation between machine code and BASIC.
The next section is quite well-written, but very unimaginatively planned. One chapter introduces all of the Z80’s ‘registers’ and ‘addressing modes’, then 70 humdrum pages are used to introduce every instruction Zilog the chipmakers own up to. There’s no mention of the hundred or so ‘undocumented’ instructions which work, but are not part of the machine’s official specification.
Joe Pritchard follows the manufacturer’s reference material faithfully, even though the resultant sequence of instructions mak es it hard to write meaningful examples. The information is collected by category, as a processor-designer would see it, so you have to read half-way through the book, past all the complicated and esoteric instructions for shifting, binary coded decimal, logic and so forth before you find out about ‘jumps’ — the simple, essential machine code equivalents of IF and GO TO!
If you struggle through the strange sequence you’ll find that all the instructions are helpfully and accurately described, but the examples are uniformly trivial and do not build on the previous material, arbitrary as it is.
To a great extent, the last sixty pages of the book are its saviour. They consist of seven essays, with examples, dealing with ‘real world’ subjects. The first essay, on interrupts, gets into a bit of a mess — one paragraph covers more than a page and says that interrupt mode 2 needs a 256 (not 257) byte vector table. The next paragraph runs to three quarters of page, and gets fairly confusing. The information is there — you just get a feeling that the author’s grasp of it is not as firm as it might be.
The data about the sound facilities seems complete, but again it is presented in the manufacturer’s sequence, rather than as a tutorial. A lot of this information has appeared, in rather condensed form, in recent TECH TIPS columns, but the book is a good source of further information if you still don’t know everything about 128 sound and RAM paging that you would like to.
Joe Pritchard documents quite a few machine code routines built in to the Spectrum ROM, but it refers you to another Melbourne House book, Ian Logan’s Complete Spectrum ROM disassembly, for further information. Logan’s ROM disassembly is just that — a line-by-line commentary on the code — and doesn’t contain enough of an ‘overview’ to guide a beginner. Yet another Melbourne House book, Understanding Your Spectrum, does better in this regard, but unfortunately it duplicates a lot of the information in Pritchard’s book.
Joe gives you the bare minimum — for instance he explains how to plot individual points on the screen, but not how to draw lines, even though there’s a simple routine in the ROM to do that. He tells us how to read individual characters from the keyboard, but not how to read the joystick or check for combinations of keys — vital for games! There’s absolutely no information about the second 16K ROM in the Plus 2 — the ‘editor’ ROM — and nothing about writing to the MIDI and Serial port. These subjects deserve attention: after all, the book sets out to be specific to the Plus Two.
I’ve made a lot of criticisms of this book, but they should be taken in perspective. Spectrum Plus Two Machine Language for the Absolute Beginner contains lots of information, defines all the terms it uses, and is a better-than-average introduction to a complicated subject. It’s a shame that it wasn’t planned and edited more carefully.