I have found a bug in the Spectrum ROM which I have not come across before. The problem involves the SCREEN$ function, which is meant to return the code of a character on the screen.
Assume that the screen is blank and Q=2. When I type in PRINT Q=1 AND SCREEN$(5,5)<>”X”, I get the reply 9.1391161E-30. I have not yet comprehended the philosophical meaning of such an answer. As the statement is a logical expression, I expected the answer 0 or 1.
JS Youngman, Coltishall, Norfolk
This bug crops up very rarely and is easy to avoid — once you know about it. In general the Spectrum ROM is remarkably bug-free, mainly because it was directly adapted from ZX80 and ZX-81 Basic. SCREEN$ was a new function introduced on the Spectrum.
The problem occurs because, within ZX Basic, SCREEN$ returns two copies of the resultant character rather than one. The ‘spare’ character overwrites the result of the AND statement. The strange number you cite is the floating-point value corresponding to a space character!
There are two ways to avoid the bug. The first requires an EPROM programmer — copy the Spectrum’s ROM, changing the byte at location 9597 from 193 to 201.
Alternatively read the screen at the start of a statement, like this: PRINT SCREEN$(5,5)<>”X” AND Q=1, so that the extra character doesn’t continue to get in the way.
This bug appears on all versions of the Spectrum. Sinclair didn’t alter the ROM, although material was added for the Spectrum 128, which has preserved compatibility at the expense of retaining some small bugs. Microsoft has followed much the same policy with its Basic, whereas many other companies (Acorn, Oric, Atari) make frequent changes, both to fix serious bugs and add features. Unless a fault is major, changes tend to cause more problems than they solve.
The quirks of the Spectrum ROM are discussed in Ian Logan‘s book Understanding your Spectrum, published by Melbourne House.