Throwing the Baby Out With the Washwater?

Author(s): William J. Pedersen
Publication: LISTing Newsletter
Date: October 1987
Pages: 6-7

When the ZX81 appeared on the market, it was such a sensation that it didn’t matter that it had some less desirable features.

It is less satisfying to find that two of these questionable features remained in the SPECTRUM and the TS2068.

The features I am talking about sound fine to the perfectionist, but us common folk who make mistakes can be shattered when we accidentally enter NEW or CLEAR or RUN. All our good work… up in smoke! Let’s blame somebody! They deserve it! Really!

It would have been so simple to require verification when the user wants these functions. Think how much better you would be feeling if only you had the chance to correct your mistakes.

Though it is impossible to eliminate the accidents, something CAN be done to decrease their likelihood.

PURGE is the answer.

PURGE is a machine code utility which takes the place of CLEAR with certain unique differences.

Before explaining why it’s the cat’s meaow, let’s discuss some of the operating problems we run into.

1. The longer we work with a program, the more “garbage” we collect in the form of unused variables. They take up space.

2. CLEAR makes no distinction between what we want to keep, and what we would like to get rid of. It throws out the baby!

3. RUN, for some historic reason, also does a CLEAR! Why?

4. NEW does exactly what we want. It wipes out everything, except some system variables and data above RAMTOP. It is only its hair trigger that is bad.

Some will surely say,”That’s what we have DATA statements for, you dummy.”…Have you checked how wasteful of memory they are?

The ZX81 had no DATA statement, nor are any needed once you have PURGE.

PURGE was in fact written within two months of its appearance on the market. That is a few years back. It was designed to do the one thing you couldn’t do selectively.

You can delete an instruction line.

You can delete the entire program.

You can get rid of an array or a string variable by dimension- it to 0. This draws an error, but it works. ON ERR fixes that.

You CANNOT get rid of one single numeric variable without a total wash-out!

PURGE does exactly that. It CLEARS only numeric variables. It leaves strings and arrays (numeric arrays too) intact.

The significance of PURGE is startling. Old habits (because it has to be that way) can go by the wayside.

You can use DATA, or normal LET statements to define arrays, and then DELETE the statements! The variable now exists in the VARS section without being duplicated in BASIC. It is loaded and saved with the program, so it doesn’t have to be regenerated again–unless you hit RUN or CLEAR.

With PURGE, you will learn to NEVER, NEVER! use either of them again. This is what cuts down on the possibility of accident.

Sure, there are programs where it doesn’t matter. It is the habit that counts. You can always use GO TO 1 instead of RUN. It does not do a CLEAR. If you really want a CLEAR, do it; but get out of the habit of using RUN. Learn to deal with you variables the same way as you edit your program.

Often there are many smaller programs within your larger BASIC program. With each section using its own variables, there comes a time when they get in the way when they aren’t being used.

Most of these are defined in the routines; all if the program section is immune to RUN.

When another routine, with another whole set of variables, is running; then the others are useless overhead.

With PURGE, you can eliminate all variables but those currently in actual use. Say good-bye to most OUT OF MEMORY problems.

The program for generating PURGE anywhere is shown here. At the overhead of 131 bytes, it pays for itself in a hurry.

The code can be rewritten in as little as 120 bytes, but the code as it stands has been bug free for years.

As you learn how to use PURGE, you will find that you will be loading variables in strings and arrays instead of defining them each time. You will also make much more use of DELETE for one-shot routines like special graphics routines.

Have fun with this new dimension in BASIC programming.

©1986 William J. Pedersen

PURGE

6000 CLS : PRINT TAB 11;"""PURGE
""";AT 2,7;"Creation Program"''"
This program creates a pair of
machine code routines, which can
be joined in one space or in two
separate areas. ORG1 is the USR
address for execution. ORG2 is
the CALL address for the subrou-
line ""FIND_NEXT"". It is usabl
e by other variable manipulating
programs, which is why it wasn
'tincluded in ""PURGE""."
6003 PRINT INK 1'"LENGTH: ""PURG
E"" = 90 bytes, ""FI
ND_NEXT"" = 41 bytes.";TAB 22;"
__________";TAB 14;"TOTAL = 131
bytes"
6004 INPUT "Address for USR? ";O
RG1: PRINT AT 17,0;"ORG1=";ORG1;
6005 INPUT "Sections? 1 or 2 ";e
$: IF VAL e$=1 THEN LET ORG2=ORG
1+90: GO TO 6007
6006 PRINT '" end ";ORG1+89;: IN
PUT "Address for FIND_NEXT? ";OR
G2
6007 LET Wfn=INT (ORG2/256): PRI
NT '"ORG2=";ORG2'" end ";ORG2+40
;" PRESS ANY KEY ": PAUSE 0
6008 RESTORE 6008: DATA 42,75,92
,34,150,92,62,128,190,200,203,11
0,245,205
6009 DATA ORG2-256*Wfn,Wfn
6010 DATA 34,152,92,241,32,8,42,
152,92,34,150,92,24,232,42,150,9
2,237,91,152,92,213,175,237,82,2
35,42,101,92,25,34,101,92
6011 DATA 42,99,92,25,34,99,92,4
2,97,92,25,34,97,92,42,89,92,229
,25,34,89,92,225,209,175,237,82,
229,193,3,42,150,92,235,237,176,
42,150,92,24,172
6012 DATA 126,230,224,254,192,40
,12,48,17,254,128,40,6,48,16,254
,96,40,17,35,94,35,86,25,35,201
6013 DATA 17,19,0,25,201,35,203,
126,40,251,17,6,0,25,201
6014 FOR n=ORG1 TO ORG1+89: READ
Byte: POKE n,Byte: NEXT n
6015 FOR n=ORG2 TO ORG2+40: READ
Byte: POKE n,Byte: NEXT n
6016 CLS : PRINT AT 12,4;" RECOR
DING MACHINE CODE "
6017 SAVE "PURGE" CODE ORG1,90+(
41 AND VAL e$=1)
6018 IF VAL e$=2 THEN SAVE "FIN
D_NEXT" CODE ORG2,41
6020 PRINT AT 21,0;TAB 8;" JOB C
OMPETED "
6021 STOP
****************************************************************
* Bank#255 "PURGE" Length: 90 Bytes *
* EXTERNAL: *
* 0E "FIND_NEXT" 14 *
+--------------------------------------------------------------+
0 2A4B5C LD HL,(NN) 23627 *(VARS)
3 22965C LD (NN),HL 23702 *(HERE)
6 3E80 LD A,N 128 *END OF VARS MARKER
8 BE CP (HL) *DONE?
9 C8 RET Z *IF DONE
10 CB6E BIT 5,(HL) *DELETE?
12 F5 PUSH AF *SAVE STATUS
13 CD0000 CALL NN 0 *"FIND_NEXT"
16 22985C LD (NN),HL 23704 *(NEXT)
19 F1 POP AF *RECALL STATUS
20 2008 JR NZ,+10 30 *IF DELETE
22 2A985C LD HL,(NN) 23704 *(NEXT)
25 22965C LD (NN),HL 23702 *(HERE)
28 18E8 JR -22 6 *NEXT RECORD
* HERE IF DELETE
30 2A965C LD HL,(NN) 23702 *(HERE)
33 ED5B985C LD DE,(NN) 23704 *(NEXT)
37 D5 PUSH DE *SAVE NEXT
38 AF XOR A *RESET CY FLAG
39 ED52 SBC HL,DE *COMPUTE RECORD LENGTH
41 EB EX DE,HL *REG DE=RECORD LENGTH
* UPDATE SYSTEM VARIABLES
42 2A655C LD HL,(NN) 23653 *(STKEND)
45 19 ADD HL,DE
46 22655C LD (NN),HL 23653 *(STKEND)
49 2A635C LD HL,(NN) 23651 *(STKBOT)
52 19 ADD HL,DE
53 22635C LD (NN),HL 23651 *(STKBOT)
56 2A615C LD HL,(NN) 23649 *(WORKSP)
59 19 ADD HL,DE
60 22615C LD (NN),HL 23649 *(WORKSP)
63 2A595C LD HL,(NN) 23641 *(E_LINE)
66 E5 PUSH HL *SAVE OLD E_LINE
67 19 ADD HL,DE
68 22595C LD (NN),HL 23641 *(E_LINE)
* DELETE RECORD
71 E1 POP HL *RECALL OLD E_LINE
72 D1 POP DE *RECALL NEXT
73 AF XOR A *RESET CY FLAG
74 ED52 SBC HL,DE *COMPUTE BYTES TO MOVE
76 E5 PUSH HL *BYTE COUNT
77 C1 POP BC *REG BC=BYTE COUNT
78 03 INC BC *INCLUDE EOT MARKER
79 2A965C LD HL,(NN) 23702 *(HERE)
82 EB EX DE,HL *SWAP HERE AND NEXT
83 EDB0 LDIR *SLIDE VARS DOWN OVER RECORD
85 2A965C LD HL,(NN) 23702 *(HERE)
88 18AC JR -82 6 *NEXT RECORD
+==============================================================+

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.