2024-05-05 CoCo line number limits and RENUM causing corruption

From Wikistix

More retro-computing on a Tandy Colour Computer, and another ROM bug. While hacking some BASIC using T-S Edit, I accidentally managed to join a couple of lines, one ending in something like GOTO 450, and the following line starting 330 'COMMENT, crucially forming GOTO 450330. The line wrapped perfectly on the edge in T-S Edit, so I didn't notice. I loaded the edited program into BASIC, and ran RENUM, which returned a ?SN ERROR. A syntax error? From RENUM? Running LIST, I saw most of my program was completely garbled, full of random BASIC tokens and random other characters.

After a little mucking around, I noticed the joined lines, fixed that and later came back to investigate the corruption a little more.

I knew that line numbers were represented as unsigned 16 bit integers, and had thought that defined their range; I was wrong. Looking at Unravelled, MAXLIN is used to check the high byte of line numbers in various points, and is &HFA, meaning that the maximum line number is actually &F9FF == 63999.

After a little experimentation, I found a simple reproduction of the corruption:

CoCo RENUM bug
LIST
0 GOTO 1
1 GOTO 64000
OK
RENUM
?SN ERROR
OK
LIST
0 GOTO
256 &
OK

See Also