[Coco] BASIC format questions

William Astle lost at l-w.ca
Tue Mar 14 23:31:10 EDT 2017


On 2017-03-14 09:08 PM, RETRO Innovations wrote:
> My assumption is that a "goto" will force the BASIC interpreter to look
> at it's current line.  if the goto line is more, it will start scanning
> line numbers from current line, but if less, it will scan from beginning
> of program.  If that is true, it would create implications on where one
> should place GOSUB routines and such.

That's basically right. However, it's a bit less efficient than that. It 
first has to scan to the end of the current line so it can find the line 
header information (pointer and line number) for the next line. Then it 
can scan forward. I think it does that even if it is going to start 
scanning at the start of the program, which it has to do even if the 
destination is the current line number because it doesn't save a pointer 
to the start of the current line. In other words, it can start the line 
number search from the start of the program or from the *next* line in 
the program.

> DATA statements are another issue where the non linear flow of the code
> will take a bit of thinking.  I wonder if the interpreter has to scan
> from the beginning of the program to find the first DATA statement when
> a READ is encountered, and then jump between two chunks of BASIC code
> all the time to read said DATA statements. Anyone privy to details
> before I go spelunking through the DECB source?

I'll save you going spelunking in the DECB code since I've already done 
it. The READ/INPUT code (which is the relevant chunk of code) is 
dreadfully complicated and the comments in unravelled are less than 
helpful. However, here's how it works:

A separate data pointer is maintained. It is set to the start of the 
program when a program is run. Each READ statement advances that 
pointer. If the pointer is at the end of a statement, a forward scan 
looking for a DATA statement is performed. Otherwise, the data at the 
current pointer is parsed. If that data pointer reaches the end of the 
program (no more DATA statements can be found), you get ?OD ERROR. 
RESTORE obviously resets the data pointer to the start of the program.



More information about the Coco mailing list