Instruction manual

Data Statement Generator
If you have ever had trouble getting those pesky DATA
statements at the end of your BASIC program correct,
then you
will
appreciate this program which
"writes"
its
own DATA statements! Written for APPLESOFT,
it
should be adaptable
to
other BASICs.
Virginia Lee Brady
0·3 Arthur Ct., Apt.
453
Salisbury,
MO
21801
( )
I had just finished adding several
new
data
statements to a sewing pro-
gram of mine that
utilized a number
of
data statements, and now I was reading
the information into
their respective ar·
rays. "BEEP," said the Apple, "
••
·SYN·
TAX
ERROR."
I found the offending line;
I'd left out one
of
the elements and Ap-
plesoft would not accept
"RED"
as a
value for "YARDS." I entered the line
again and this time I typed the wrong
line number and erased my previous line.
There ought
to
be
a way, I decided,
to
let
the Apple keep track
of
these things. I
experimented with
input statements,
and while these
allowe~
me to update
the arrays, I couldn't
save the informa-
tion.
Using the information from Jim But-
terfield's article
on
"Pe~
Basic" and the
information in the ApPlesoft Manual, I
developed a program that
"writes"
its
own data statements. This routine
automatically'
increments
the
line
numbers and inputs the data elements
in response
to
appropri*te
prompts.
It's
all poked into place anq becomes a per-
manent part of the
program.
It is first
necessar~
to
understand
how
ROM
Applesoft is stored. The basic
program begins at
$801
(2049
decimal)
and there are only
two
bytes between
the end of the program
a,nd
the start
of
the simple variable table which begins at
LOMEM:.
Anytime
a Basic line is
entered, altered, or
dele~ed,
the value
of
LOMEM: is changed and the program
must
be
rerun to incorporate
this
new
value. Therefore, LOMEM: must be set at
December, 1979
some value past the end
of
the program
to
allow for expansion
of
the program
without writing on top
of
the variable
table.
To use this routine it is also
necessary to recognize the following
locations
of
a data statement in Ap·
plesoft:
2
bytes-pointer
to next line
of
Basic (to next pointer)
2
bytes-hex
equivalent
of
the line number
1
byte-"83"
-token
for
"DATA"
N
bytes-ASCII
equivalents
of the program line
1
byte-"OO"-indicates
the
end of the line
Then the sequence starts again until
there are
two
bytes of "00" in the first
two positions (total of three
"00"
bytes
in a row.)
The program uses the fact that the
locations $AF.BO
(175-176
decimal) hold
the value of the location where the next
line number would go; or put another
way, two less than this is where the
"pointer
to
next line" would go. Call
this
PSN
(for position). Thus the values to
be
poked into
PSN
and
PSN
+1 are the low
and high order bytes
of
the hex
equivalent
of
LINE number. Then the
DATA token
(131
in decimal) is placed in
PSN
+
2.
Since this program was design-
ed
to handle several elements in one
data statement, a series of strings is
next input as one string array. (It could
just
as easily have been d6ne as several
MICRO
--
The
6502
Journal
19:5