Renumbering An Appended Routine Only
Elizabeth Deal Malvern, PA
There is a way to append a program to another in the PET even if the line numbers are out of order. It will be shown here for the upgrade ROM tape system. It should work on other PETs. The scheme uses the Toolkit™ or its equivalents.
Suppose that program A exists in the PET and that its line numbers range from 100 to 2000. Suppose, further, that we would like to append a program B with line numbers which are lower than (or overlap) those of program A: for instance 15 to 340. As long as program B contains no GOTOs and no GOSUBs, one renumbering of the entire A-plus-B package will set the line numbers in order. Consequently, target addresses in program A will remain meaningful.
When, however, program B contains GOTOs and GOSUBs, we are in violation of the "appended program must have higher line numbers" rule. And that means save one piece, put the other one in, renumber it, save again, load again … ad infinitum. Disk people can do it in a jiffy. It's tough for tape owners though.
Some rules just beg to be broken and this is one of them. A simple solution consists of temporarily hiding program A from PET's view by swapping some pointers around. Just before loading program B we tell the PET that the BASIC area begins at the end of program A or exactly two (2) bytes back from the start of variables pointer (42-43). We do this carefully by use of the Machine Language Monitor where we replace contents of $28-29 with contents of $2A-2B minus 2. Or by these direct BASIC commands:
AD = (PEEK(42) + PEEK(43))-2 : AH% = AD/256 POKE40, AD-AH%*256 : POKE41, AH%
This has to be entered correctly the first time or things get somewhat messy.
At this point we can append program B. It will be placed, in the usual manner, at address AD. We can list this program. And we can RENUMBER it, for instance, with 3000, 10 parameters sent to the TOOLKIT.
To finish the process we reset the start of BASIC pointer to its original value, decimal 1025, hex $0401, or whatever other number we have jotted down in case of being in a partition. In BASIC, the reset can be done by:
Using the Monitor, the reset to 1025 decimal is done by putting $01 into $0028 and $04 into $0029.
Program A reappears on the scene and the entire package is ready for use.
|Pointer addresses for various releases:|
|Original||Upgrade and 4.0|
|Start of Basic low byte||122||$7A||40||$28|
|Start of variables low byte||124||$7C||42||$2A|