Re: Pointer at the start of a BASIC line: what good is it?

From: Spiro Trikaliotis <ml-cbmhackers_at_trikaliotis.net>
Date: Wed, 27 Oct 2021 21:34:54 +0200
Message-ID: <YXmp3r2RyETy6jCm_at_hermes.local.trikaliotis.net>
Hello Ruud,

* On Wed, Oct 27, 2021 at 09:21:10PM +0200 ruud_at_baltissen.org wrote:
 
> 
> Still busy writing my own BASIC that should run on my Commodore PC20-III, I
> stumbled in something strange, again. I was sure that the first two bytes of
> a BASIC line were the length of it.

you were wrong. ;)

> That worked fine for a long time until I
> loaded a real C64 program and tried to edit it. Seeing the values and
> checking on Internet I learned it were pointers to the next line. Or better
> (IMHO worse), it points to the zero end byte at the end of the line. Why is
> this all?

No, it does not point to the zero at the end of the line, it points to
the next line (more precisely, to the 2 byte that point to the next
line again).

> Using only the length and having to delete or insert a line, I only had to
> move a block of bytes and that was it. Now I have to correct the pointer in
> every line after every move as well. The C64 does do it: see the routine at
> $A533.
> And why pointing to the zero end byte, why not to the start of the next
> line? Now I have to read this pointer and add one to it before I can use it.

Then, you have done a mistake. Load up a C64 emulator, type in 2 or 3
lines, and look at the memory dump: You will see that they always point
to the pointers of the next line.

> So my question: what good is it? Or can I only blame mr. Bill Gates for this
> behaviour?

The pointer helps you in GOTO and GOSUB, because you can traverse the
memory to find the correct line.

If it would be the length only, you would have to add that to the
current line, which takes more time.

Thus, this is using "typing-in-time" for the program to speed up the
execution of the program, in the same way that the tokenization takes
"typing-in-time" to speed up the execution.

BTW: For the length, it would have been enough to have one byte only,
because the BASIC does not have lines that are longer than 255 byte.


Regards,
Spiro

-- 
Spiro R. Trikaliotis
https://spiro.trikaliotis.net/
Received on 2021-10-27 22:05:57

Archive generated by hypermail 2.3.0.