PROTECTOR!
by Garetti [sic, s/b Gareth?] Johnson
from Big K #8, November 1984, page 54

A while back, reader GARETTI JOHNSON lent a home-grown Spectrum prog
to a "friend" - later he was miffed, to say the least, when he
discovered copies of the prog circulating locally at 1 a time.
Enraged, he sat down to figure out how This Could Never Happen Again
(he doesn't say what happened to the friend) ... and here's the result.


AFTER LENDING my latest masterpiece to a friend for a couple of days,
I was amazed and annoyed to find copies of it being sold for a pound
each. This caused me to wonder if there was a way that BASIC programs
could be safeguarded from copying.

Ploughing through several copies of the latest weekly and monthly
computer rags, I found to my surprise that not one article had been
written for the Spectrum about program protection. The only piece of
information I could find was that POKE 23659.0 would stop people
breaking into programs. "Great" I thought and rushed off to try it
... it didn't work. Why it didn't work will become clearer later.

On page 173 of the Spectrum manual you will find a complete list of
the system variables (these are used by the system to update various
pieces of information). Because these pieces of information need to
be updated and changed, the system variables are held in RAM and not
in ROM, therefore the programmer can also change them and this is
where the system variables are of use to us.

Address 23659 DF_SZ controls and keeps track of how many lines there
are in the bottom part of the screen. If we POKE 23659,0 (telling the
computer that there are no lines in the bottom part of the screen) we
can stop anyone from breaking into a program. Why? Because when
anyone presses the BREAK key and stops the program the computer tries
to print up a "L BREAK into program" message at the bottom part of
the screen. However, because we have told the computer that there are
no lines in the bottom part of the screen, it cannot print its
message and a system crash occurs, thus wiping the program from
memory. You can see what happens if you type out the short program in
Listing 1.

There is however a slight catch ... for this method to work an
auto-run is required (you can make any BASIC program auto-run by
SAVE-ing it in the form SAVE "PROG.NAME" LINE (first line number).
Most budding pirates know that MERGE-ing a program will prevent an
auto-run. Therefore we need a way of stopping or preventing the
MERGE-ing routine. When a program is MERGE-ed the computer
automatically places the lines with a number greater than 9999
(purists will point out that you cannot POKE any part of memory with
a number greater than 255 - to them I say go and look at chapter 24
of the Spectrum manual! We can cause a crash if the program does not
auto-run after being LOAD-ed. It does not matter if you do not fully
understand this ... If you want to find out more, take a look at page
166 of the Spectrum manual which shows how a line in a BASIC program
is stored. Anyway, the upshot of this is that the program cannot be
broken into "manually". Listing 2 shows what to do.

Next comes the problem of tape-copying programs. There is, however,
quite a simple solution to this problem ... since the tape-copying
program has to take up some part of memory, so if we can fill up ALL
of the memory, we will at some stage overwrite the tape copying
program and prevent it from copying all of the program. Listing 3
shows how to do this. Some tape-copying programs reside in the
printer buffer (you do not need to know what this is, but it is
basically a part of RAM that is reserved for use by the printer).
Listing 4 shows how to deal with such tape-copiers.

The last problem we have to deal with is that of tape-to-tape copying
Since the MoD has banned JCL DATA's tape-to-tape copying prevention
device, there seems to be no way of preventing the program being
copied. The way to get round this is to have a sheet of numbers
(preferably in colour, or a series of colours) that must be typed in
at the start of the program like at the beginning of JET SET WILLY.
(Incidentally this method of protection is copyright by Software
Projects.) If you are serious about protecting your programs then I'm
sure you can come up with your own system.

LISTING 1
10 POKE 23659,0
20 PRINT AT 0.0; "TRY AND STOP THIS": BORDER RND*7: GO TO 20

LISTING 2
1 POKE 23659,0. POKE 23801.0
2 REM The program must then continue at line 2
3 REM If you CLS or INPUT or do anything that involves the bottom part of
      the screen, you must first temporarily reset the value of 23659 ...
  eg. POKE 23659,2: CLS: POKE 23659,0
4 REM When SAVE-ing your program, SAVE it in the following way ...
      POKE 23801.255: SAVE "progname" LINE (first line number)

LISTING 3
   1 REM Fill up any spare line numbers like this -
5000 REM  xxxxxxxxxxxxxxxxxxxxxxx
          xxxxxxx (etc.)

LISTING 4
2 IF PEEK 23297<>0 THEN NEW:
  REM this should be in a loader program that loads in the main program
3 LOAD "": REM if BASIC or LOAD "" CODE if machine code.



