Conversion Tips ZX81/Spectrum

Author(s): David Nowotnik
Publication: LISTing Newsletter
Date: February 1994
Pages: 8-9

PROGRAMMING TIPS

Conversion tips

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
                                                      every second. In the example,
LET T=(65535-PEEK        LET t=(PEEK 23672+256*       use the first line to start the
16436-256*PEEK 16437)    PEEK 23673)/50               'clock'. The variable T will
/50                                                   have the time in seconds after
                         For times greater than 10    the start. The counter can
                         minutes, you can use byte    only be used for 10 minutes.
                         23674 as well.
2 Line number zero

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

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.

System Variables Conversion Table.

Variable          ZX81/      Spectrum/
                  T/S1000    TS2068

BREG              16414      23655
CDFLAG            16443      No Equivalent
CH ADD            16406      23645
COORDS            16438      23677
COORDS (Byte 2)   16439      23678
DEST              16402      23629
DF CC             16398      23684
D FILE            16396      No Equivalent
DF SZ             16418      23659
E LINE            16404      23641
ERR NR            16384      23610
E PPC             16294      23625
ERR SP            16386      23613
FLAGS             16385      23611
FLAGX             16429      23665
FRAMES            16436      23672
LAST K            16421      23560
MARGIN            16424      No Equivalent
MEM               16415      23656
MEMBOTT           16477      23698
MODE              16390      23617
NXTLIN            16425      23637
OLDPCC            16427      23662
PPC               16391      23621
PRBUFF            16444      23296
PR CC             16440      23680
RAMTOP            16388      23730
SEED              16434      23670
S PSN             16441      23688
S POSN (Byte 2)   16442      23689
STKBOT            16410      23651
STKEND            16412      23653
S TOP             16419      23660
STRLEN            16430      23666
T-ADDR            16432      23668
VARS              16400      23627
VERSN             16393      No Equivalent
X PTR             16408      23647

Also printed in LISTing September 1995.