P. 1
Commodore 128 Book 7 Peeks and Pokes

Commodore 128 Book 7 Peeks and Pokes

|Views: 414|Likes:
Published by CubemanPDX
Commodore Computer Book
Commodore Computer Book

More info:

Published by: CubemanPDX on May 13, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

05/19/2013

pdf

text

original

One of the most useful commands in BASIC 7.0 is RENUMBER. This
command can also be simulated in the C-64 mode.

As you learned in the last section, every program line begins with two
pointers. The first points to the beginning of the next line, the second really
isn't a pointer, it's actually the current program line number. If we add 2 to
the address of the pointer we get the address of the next line number. Using
this technique we can search for all of the line numbers and by using POKE
we can change these numbers. Here is a program to do this:

63900 BA=PEEK(43)+256*PEEK(44)
63910 INPUT "Start#";SA: INPUT "Step size"iSW
63920 HI=Sa/256: LO=SA AND 255
63930 A=PEEK(BA+2)+256*PEEK(BA+3)
63940 IF A>= 63900 THEN PRINT "OK!":END
63950 POKE BA+2,LO:POKE BA+3,HI
63960 BA=PEEK(BA)+256*PEEK(BA+1):
SA=SA+SW
63970 PRINT SA "=" A: GOTO 63920

This routine must be placed at the end of an already existing program, and
run with RUN 63900.

Line 63900 calculates the base address of the first line from the pointer to
the start of BASIC. Line 63910 allows the user to enter the new starting line
number for the program. If you want the program to start at line 10 and
have all line numbers separated by 10, you should enter a 10 twice.

Line 63920 calculates the high and low bytes of the new line number, line
63930 has the old line number from memory. If this number is greater than
or equal to 63900, then the renumbering program is ended, since this
routine will not renumber itself.

The next lines POKE the high and low bytes of the new line number into
memory.

151

Abacus Software

Commodore·128 Peeks & Pokes

Finally, the base address of the next line has to be calculated. The line
number is increased by the step size, and the numbering protocol is output.
This protocol points each new line number to the old equivalent. We use
this method so that the GOTO, GOSUB and other such jumping commands
inside of the program are not changed. If you own a printer I suggest that
you print this protocol, so that you can have it in black and white in front of
you. To do this put the following at the beginning of the routine:

OPEN 1,4: CMD 1

152

Abacus Software

Commodore-12S Peeks & Pokes

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->