Instruction manual

Value
Base
10
Hex
0
0
0
0
0
0
36
24
73
49
0
0
139
8B
0
0
0
0
0
0
0
0
0
0
36
24
There are several ways
to
do this.
One can
simply
POKE the correct values
into
the
pointer memory locations. This
works, but
if
you make a mistake the
PET
will
"go
away"
when you try
to
RUN
the program.
With
version I ROMs the
only
thing
you can
do
is turn the
PET
off.
There may
be
a good side
to
this ap-
proach;
it
can be used as a neat way
to
protect a program. Wi1hout some clever
PEEKing at
RAM
and
without
understan-
-ding how
to
set the pointers based upon
that PEEKing, the program
won't
run.
Another approach is
to
have a machine
language program do the required in-
itialization.
With
this approach several
shifted programs can
be
RUN
at once.
To
call a specific program you can use
the USER
(X)
or
SYS
commands. The
machine language program does the
rest. I'll give
an
example
of
a simple
routine like
this
in
the last section.
stores an image
of
the program as
it
ap-
pears in RAM. However, not all
of
the
pointer values are stored on the tape.
Since
PET
uses a compiled (not really
compiled like FORTRAN but actually
compacted) listing, it
must
also
store
the forward chain addresses along with
the compacted code. Each BASIC state-
ment has a forward chain address. This
forward chain address
points
to the for-
ward chain address
of
the next BASIC
statement. Therefore, the program must
be stored in exactly the same memory
location from which
it
originally
came.
Forward cahin addressing is absolute
rather than relative. If
PET
has reinitializ-
ed
its
pointers, the BASIC pointer is
pointing
to
the normal BASIC location.
Upon loading a BASIC program tape
under keyboard control the
SV,
AV,
AS
registers are loaded
with
data
from the
tape.
Unfortunately,
the
monitor
assumes BASIC programs
will
always
start at
.1025.
Therefore when
PET
is ask-
ed
to
RUN
or LIST, the
monitor
will start
looking at 1025. It
won't
find a program.
To
use a shifted program after it has
been
lOADed
back
into
the
PET
the
BASIC pointer must be changed.
Hex
Memory
location
Table 1: Pet BASIC InitiaHzation Values
1024
400
1-025
401
1026 402
1027
403
1028 404
1029
405
1030
406
1031
407
1032 408
1033 409
1034 40A
1035 40B
1036
40C
Base
10
2.st;~f=IE~J:~(
135
)+Pc.-E~«
134
.:'
2~>€*~'tt~~:.(.
12;.3
)+PEE:~::.(.
l.~::::
)
25S*PE~K(127)+PEEK(128)
regular BASIC programs. However,
if
the
monitor·has reinitialized memory, any at-
tempt
to
LIST or
RUN
a shifted program
will
fail. If a
shifted
program has been
SAVEd,
PET
turned
off
and back on, and
the
shifted
program is
relOADed
it
still
cannot
be LISTed or RUN.
How
come? I did
just
say
it
would
RUN
when entered from the keyboard.
Well,
it's
those seven pointers. When
PET
SAVEs a program, any program,
i1
+
+
+
·r
+
~~
+
+
T
+
I
+
F:
.;.
+
1
+
+
t'j
+
+
~_
..
~:;
+
+
+
.~'.
+
+
[I
+
+
C
+
+
Cl'~'
+
. ''':'''
+
+
+---------+
+---------+
+
8R:::IC
+
+
PF::DGF:Pt·i
+
+ +
+---------+
+---------+
Figure 1: Pet Memory
Map
and Pointer
Locations
E'OTTCL.<
:::TF:
I
f4
1
3':;
~'192
1t"'P
OF
r·1
::
,',1
0
~:;:
IT'
How
it
Works
Line 1 sets the
first
address for
cassette
#1.
Lines 2 and 3
set
the high(B)
and
low
(A)
bytes
of
the
start
address.
Lines 4 and 5 set, in a simi
liar
fashion,
set the end address
to
the
value
of
the
simple
variables
start
address. This ad-
dress is the same as the ·end
of
the
BASIC program.
Une
6 calls ·the SAVE
routine. There is one disadvantage-this
simple approach leaves
ttle
program
name undefined.
"$$$"
or"
"is
assign-
ed
as the file name.
Shifted
programs
can be l:OADed, and VERIFIED
just
iike
When SAVE is used from the keyboard
the routine initializes one
of
the cassette
buffer
pointers
to
1024. POKEing the
starting
address
of
the
shifted
program
doesn't
work (and finding
this
out
delayed this
article
several months-I was
SAVING all of memory from
1024
up)!
Fortunately there is a way around
this
problem.
IN
"Commodore
PET Users
Club
Newsletter",
Vol.
1,
Issue 4&5
there
is a program which
demonstrates
just
what
we need
to
trick
the
PET.
Table 2
lists the required lines. By using SYS
to
access the SAVE routine we can bypass
the initialization. The listed code can be
used either as
direct
commands
or as
part
of
a program.
--
,'"
--'
.:-
1025
8H'::IC
STpr:;:T
1022
~:
H"C'L~
I;}RRl1~8LE:3
+
+
+ $ +
l~~~
~UqILP8LE
+---------+
~~Hl~ + A
.+
~!~~I
+ A +
+
l:-~<
3)
+
1028
PPRPY
+---------+
'.)HH 1
Ht::Lt::;
19:26
MICRO
--
The 6502
Journal
December, 1979