[comp.sys.apple2] Weird Applesoft/CHAIN bug

dreuben@eagle.wesleyan.edu (06/26/91)

Hi...

A bit of an odd/escoteric question:

I wrote an Applesoft program that uses the CHAIN utility. This is the program
Apple provides that allows programs on the Apple // series (and I guess
the Apple /// as well) to load a program in and out of memory while
retaining all the variables, even when a new program is loaded in.

Anyhow, my program is quite large, and uses the CHAIN routine. 

Everyting worked fine until recently I noticed a little bug. I have
my Apple dial (via modem) an array of numbers. It starts with the first number,
and procedes down the array till it hits a blank (empty) space.

Thus, if I did a : "FOR A=1 TO 5: ?DOUG$(A): NEXT A", I would get something
like:

1 415 860 7626P
1 415 860 7626 
1 212 847 7626P
1 212 847 7626

Ok, great. So the I then have the program chain to the "dialing section", 
which dials fine, and everthing is OK. 

BUT....when I have a need to chain back to the "array input" section, 
the instant I CHAIN back (ie, right after the program loads), if I issue the
same command as above (to see the array), I get:

1 415 860 7626P
1 415 860 7626
1 212 847 7626P
1 415 860 7626P <----- This is the problem!

For some reason, CHAIN seems to reorganize the array and makes a copy of the
FIRST element and places it as the LAST one, overwriting what was previously
there!

Now this is simple to write around so it is not a problem (e.g.: ignore the 
last variable in the array, or something like that), but I am just 
wondering why does this happen?

NONE of my other arrays are affected, and the change occurs solely due to
CHAIN: I have *no* significant code which could alter it in this way, and
certainly none of it is used between the time the "good" results come out
(the first set out numbers), and right after CHAIN finishes loading the
"array input" program when the "bad" results come out. 

Anyone have any ideas? 

I have plenty of "X=fre(0)" statements there, and have checked and am 
pretty sure that I am not overwriting anything (like binary routines, 
etc.) I am using up most of the Apple's memory, but like I said, NOTHING
else is affected.

Thanks,

-Doug

dreuben@eagle.wesleyan.edu
dreuben@wesleyan.bitnet