home *** CD-ROM | disk | FTP | other *** search
/ Futura 5 / Futura_Issue_05_1993_01_NOSAUG_Side_A_BASIC.atr / protect.doc < prev    next >
Text File  |  2023-02-26  |  7KB  |  1 lines

  1. ¢DON'T YOU THINK YOU NEED A LITTLE PROTECTION?¢By Andre Willey, AU1/4.¢¢¢    One of the main problems with Basic, apart from its poor speed in comparison with machine code, is that once you've finished your masterpiece anyone can LIST it to the screen or printer and copy your ideas.  Luckily there are quite a few things you can do.¢¢    Let's take the points in order:¢¢    Break is perhaps the easiest of all to protect from.  It involves just two POKE instructions:¢¢        POKE 16,64¢        POKE 53774,64¢¢    To switch the Break key back on again, type:¢¢        POKE 16,192¢        POKE 53772,192¢¢    Unfortunately the GRAPHICS command will return Break to its normal use, so you must re-POKE the values after each GRAPHICS statement in your program.  A simple GOSUB to a subroutine is probably best.¢¢    System-Reset is far harder to protect because it was designed as an all purpose "get-out" key in case your program goes wrong.  As such it should function correctly regardless of whatever you have managed to type in.¢¢    Luckily there is one way to "capture" the Reset key.  One of the functions of Reset is to check that DOS or any cassette loaded program is still working correctly.¢¢    When a boot cassette or DOS disk loads in it will set three locations in memory to tell Reset what to do to re-initialise the program just loaded.¢¢    Location 9 will contain either a 1, for a disk program, or 2 for a cassette.  If it contains 0 then no program was booted.¢¢    The other two locations are used to tell the computer the address in memory of a small machine code routine to handle the job of checking the main booted program.¢¢    These locations are different for cassette and disk, but we will use the cassette ones, 2 and 3, as they are simpler.¢¢    So in order to trap System-Reset we must first POKE location 9 with 2 - for cassette boot - and locations 2 and 3 with the address of a machine code routine.¢¢    What?  You mean that some of you aren't machine-code programmers?  Okay, let's cheat.¢¢    Basic itself is really just one massive machine code program.  Normally you never have to think of it as such, because it is designed in such a way that you never really notice how it works.¢¢    If we could find a suitable section of Basic to "borrow", we wouldn't have to write any machine code ourselves.¢¢    The obvious routine to use would be RUN, so that the program would simply re-start if you pushed Reset.¢¢    But that may not be what you wanted.  You may want your program to go off and do something else rather than start from scratch.¢¢    Fine, let's use the GOTO statement then, but how to tell the computer where to go to?  Better still, let's use the TRAP command.¢¢    If we can convince Basic that an error has occured after pushing Reset it will jump to a TRAPped line, which may, for instance, disable the Break key again.  For instance, if you have typed:¢¢        TRAP 500¢¢the program would continue at line 500 after pressing System-Reset.  So where inside Basic is the TRAP handling routine?¢¢    Atari has so far released three versions of Basic, called, with great inspiration A, B and C.¢¢    Version A was shipped in cartridge form with all UK Atari 400 and 800 machines.  There were a few very minor problems with it so the new 600XL and 800XL machines had Revision B Basic built in.¢¢    Unfortunately one or two new bugs crept into this one also, so Revision C was born.  Available on cartridge for ✓9.95, this Basic is also built into the current XE range of computers.¢¢    The TRAP routine on Rev. A was located at 47424 ($B940), and on Revs. B and C at 47412 ($B934).  Thus you must POKE locations 2 and 3 with the correct values.¢¢    For Basic Rev. A - cartridge:¢¢        POKE 2,64¢        POKE 3,185¢¢    For Basic Revs. B and C - XL/XE range:¢¢        POKE 2,52¢        POKE 3,185¢¢    Don't, incidentally, forget to POKE 9,2 as well.¢¢    Program 1 shows Break and Reset protection in use.¢¢    This method will disable DOS after Reset is pushed.  If you are a disk user and you wisk to re-enable DOS, type POKE 9,1 and push System-Reset.  The system should then be returned to normal.¢¢    There are some rather nice little things you can do to stop your program being LISTed if it has been loaded but not RUN.¢¢    The first is to scramble any variable names so that garbage is printed out instead.  Program 2 will do this for you:¢¢10 REM PROGRAM LISTING 2¢20 REM SCRAMBLE VARIABLE NAMES¢30 REM DON'T FORGET TO SAVE YOUR PROGRAM FIRST!¢40 REM TYPE IN YOUR PROGRAM, THEN TYPE THE LINES BELOW¢50 REM TO RUN, TYPE:  GOTO 32000¢60 REM¢32000 FOR VAR=PEEK(130)+PEEK(131)*256 TO PEEK(132)+PEEK(133)*256¢32010 POKE VAR,155:REM OR ANY OTHER ASCII CHARACTER YOU WANT...¢32020 NEXT VAR¢¢    It should be typed in on a spare program line, say 32000, run with a GOTO statement, and then deleted.  Don't forget to save an original version because even you won't be able to read or alter your program once it's been scrambled.¢¢    Without going into too much technical detail, for which see "The Atari Basic Source Book", or "Mapping the Atari", both from Compute! Books, it works by putting a Return character instead of each variable name in the listing of the program, thus making it a little tricky to read.¢¢    Program 3 is even more dramatic:¢¢10 REM PROGRAM LISTING 3¢20 REM LOCK-UP COMMAND ENTRY MODE¢30 REM DON'T FORGET TO SAVE YOUR PROGRAM FIRST!¢40 REM TYPE IN YOUR PROGRAM THEN TYPE LINE 32030¢50 REM CHANGE SAVE"D:Filename.Ext" TO SAVE"C:" FOR CASSETTE¢60 REM DO NOT USE CSAVE!!!¢70 REM TO RUN, TYPE:  GOTO 32030¢80 REM CAN BE USED WITH, OR AFTER, PROGRAM 2 EXECUTION¢90 REM¢32030 POKE PEEK(138)+PEEK(139)*256+2,0: SAVE D"Filename.Ext": NEW¢¢    This one won't allow ANY commands to be typed in after the routine has been run, hence the SAVE command MUST be in the running portion of the program or you've lost it forever.¢¢    This also means that you can't LOAD, or CLOAD, then RUN the program.  You must RUN C: or RUN D:Filename.Ext.¢¢    Again, I won't go into technical details, but this version will make Basic fail to recognise any lines, either program or command, that you subsequently type in.  It effectively forgets where to store them.¢¢    Drastic, but quite effective.¢¢    One last tip to play about with.  Try this:¢¢        POKE 202,1¢¢    Put it as the first line of the program, and check that it is correct by LISTing it.  Try listing it again after you've RUN the program.¢¢    You'd better save the program before running that last one.  Have fun.¢¢End.¢¢¢¢Conversion to DOC file by S.J.Murray,¢North Of Scotland Atari User Group,¢¢Ed: Program 1 mentioned above is included on this Futura disk as PROTECT1.BAS.¢