Author Topic: BASIC: Get line per length  (Read 951 times)

0 Members and 1 Guest are viewing this topic.

Offline logiker

  • CPC464
  • **
  • Posts: 33
  • Country: sc
  • Liked: 23
  • Likes Given: 4
BASIC: Get line per length
« on: 15:39, 07 March 19 »
Hi!


Is there an easy way to get the length per line (tokens, not letters) of a basic program?


Thanks

Offline GeoffB17

  • 6128 Plus
  • ******
  • Posts: 765
  • Country: gb
  • PCW since '85
  • Liked: 163
  • Likes Given: 9
Re: BASIC: Get line per length
« Reply #1 on: 18:21, 07 March 19 »
First of all, I'd not be sure that there is a reliably standard method for doing the conversion from a text program line to the tokenised version, so each implementation of BASIC could be different.

You don't specify which version of BASIC you're talking about.

Usually, keywords are converted.   Literal text, i.e. strings, may be in the nine as literal, but a variable may be actually stored somewhere else.   Numeric variable, I'm not sure.   How would you count these?

You may need to investigate, and work it out.

Does your BASIC allow the return of the address of a variable, even a $?

You may need to create a line of code with a $ at the start and finish, then get the address of the two marker $, then display the RAM contents from before the first to after the last marker and see just what is there, how your BASIC stores the data, and the full line.

Or does the manual for your BASIC define any of the details already?

Edit:  You might find some useful info here, although this relates to GW-BASIC.   While the details may be different, many of the general principles may be similar.

http://www.chebucto.ns.ca/~af380/GW-BASIC-tokens.html

Geoff
« Last Edit: 19:54, 07 March 19 by GeoffB17 »

Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 620
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 612
  • Likes Given: 350
Re: BASIC: Get line per length
« Reply #2 on: 23:27, 07 March 19 »
I'm not sure what you are looking for .. this ?
A BASIC program is stored in a tokenised format. Here the keywords are represented by 1 or 2 byte unique sequences.
Each line of the BASIC program has the form:
 
OffsetSizeDescription
02Length of line data in bytes (note 1)
2216-bit decimal integer line number (note 2)
4nBASIC line encoded into tokens (note 3)
n+11"0" the end of line marker (note 4)
Notes:
  • This 16-bit value has two functions:
    • if "0" it signals the end of the BASIC program. In this case, there is no furthur BASIC program lines or data.
    • otherwise, this value defines the length of the tokenised BASIC program line in bytes, and includes the 2 bytes defining this value, the 2 bytes defining the program line number, and the end of line marker. This number is stored in little endian notation with low byte followed by high byte.
  • This 16-bit value defines the line number and exists if the length of line data in bytes is not "0". A line number is a integer number in the range 1-65535. This number is stored in little endian notation with low byte followed by high byte.
  • This data defines the tokenised BASIC program line and exists if the length of line data in bytes is not "0". The length is dependant on the BASIC program line contents.
  • This value defines the end of the tokenised BASIC line data and exists if the length of line data in bytes is not "0". The BASIC interpreter looks for this token during the processing of this line, and if found, will stop execution and continue to the next line.
So peek(&170)+256*peek(&171) gives you length of first line

Offline logiker

  • CPC464
  • **
  • Posts: 33
  • Country: sc
  • Liked: 23
  • Likes Given: 4
Re: BASIC: Get line per length
« Reply #3 on: 15:28, 10 March 19 »
Thanks for your replies.
I wanted to calculate the size of a line for the BASIC10Liners Compo. Now I found out, that only the "typed" characters count. Therefor this question is obsolet to me. Now the new question would be, how do I count the minimum required characters for typing. But that's another topic.