Conversion Tips

Author(s): David Nowotnik
Publication: LISTing Newsletter
Date: September 1990
Pages: 8-9

A guide to ZX81/Spectrum program conversions from David Nowotnik.

The versions of BASIC offered by the two ZX computers are so similar that many programs for one can be used by the other. The ZX81 has only two commands which are not present on the Spectrum, SCROLL and UNPLOT, and these should cause you few problems when converting ZX81 programs to the Spectrum (see Table 1).

There are quite a lot of commands and functions on the Spectrum which are not available on the ZX81. A list of these appears in Table 4. The stars indicate those commands and functions for which there is no simple translation to ZX81 BASIC. Those for colour and sound can be ommitted; but you will have to find some alternative for the high resolution and file I/O commands.

The command PLOT appears on both computers, but the effect is quite different, so beware! Another tip: PEEK and POKE should be used with caution. In conversion, addresses will almost certainly have to be changed. Some of those changes appear in the tables. A command such as POKE USR “a”…. on the Spectrum indicates User Defined Graphics; ZX81 users don’t have this facility, so you’ll have to omit this and use a standard character instead.

ZX81        Spectrum                 Comments

SCROLL      RANDOMISE USR 3582       If the program uses random numbers, they
                 or                  could become rather predictable with the first
            LET t=USR 3582           option. If so, use the second, using a variable (in this
                                     case t) which is otherwise not used.
PLOT Y,X    PRINT AT 21-Y/2,X/2;     Print the appropriate quarter square graphics
                                     character.
UNPLOT Y,X  PRINT AT 21-Y/2,X/2;     Print a space, or the appropriate quarter square
                                     graphics character.

Table 1 ZX81 to Spectrum conversions.
Spectrum             ZX81                          Comments

BIN                                                BIN allows the represen-
eg LET y=BIN         LET y=(decimal no.)           tation of a number in
   10010101          Conversion to decimal:        binary. On the ZX81 use the
                     10010101=149                  decimal equivalent, but
                                                   beware; BIN is often
                     128 64 32 16 8 4 2 1          used with User Defined
                     Add these numbers together    Graphics, which are not
                     when a 1 appears at the       available on the ZX81.
                     appropriate position in
                     binary.

READ/DATA            LET                           READ and DATA are
eg READ x,y          LET X=50                      used to store a lot of
   DATA 50,60        LET Y=60                      information in a program. Use
                                                   LET instead.

DEF FN and FN                                      The defined function can
eg DEF a(x)=SQR x    LET X$="SQR X"                appear in a string. Use
   LET t=FN a(i)     LET X=I                       the keyword for built-in
                     LET T= VAL X$                 functions (eg SQR). The
                                                   equivalent of FN may need 2
                                                   lines, as shown.

PLOT                 no equivalent

SCREEN$
eg LET a=SCREEN$ x,y LET A=PEEK(PEEK 16396         Used in interactive games
                     +256*PEEK 16397+1+Y+33*X)     to detect characters in the
                                                   display file. Note - this
                                                   formula only works when a
                                                   RAM pack is fitted.

Table 2 Spectrum to ZX81 conversions.
ZX81                   Spectrum                        Comments

1 FRAMES
POKE 16436,255         POKE 23672,0:POKE 23673,0       Both computers have a counter
POKE 16437,255                                         which accurately varies by 50
                       LET t=(PEEK 23672+256*          every second. In the example,
LET T=(65535-PEEK      PEEK 23673)/50                  use the first line to start the
16436-256*PEEK 16437)                                  'clock'. The variable T will
/50                    For times greater than 10       have the time in seconds after
                       minutes, you can use byte       the start. The counter can
                       23674 as well.                  only be used for 10 minutes.

2 Line number zero
                                                       Converts the first line of a
POKE 16510,0           POKE 23756,0                    program to line number zero.
                       (As the start of BASIC can      which cannot be edited, and
                       move, eg with microdrives)      so is protected.
                       use with caution.

3 RAMTOP
POKE 16388,X-256*INT   CLEAR x                         Creates a safe area at the
(X/256)                                                top of RAM starting at address
POKE 16389, INT (X/256)                                x, for storing data, machine
                                                       code etc.

Table 3 General interconversion hints.
BEEP     *     FORMAT    *     ATTR      *
BORDER   *     INK       *     BIN
BRIGHT   *     INVERSE         FN
CAT      *     MERGE     *     IN        *
CIRCLE   *     MOVE      *     OVER      *
CLOSE    *     OPEN      *     POINT     *
DATA           OUT       *     SCREEN$
DEF FN         PAPER     *     VAL$      *
DRAW     *     READ
ERASE    *     RESTORE   *
FLASH    *     VERIFY    *

Table 4 Spectrum functions not available on the ZX81.