News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_logiker

BASIC: Get line per length

Started by logiker, 14:39, 07 March 19

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

logiker

Hi!


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


Thanks

GeoffB17

#1
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

SRS

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

logiker

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.

Powered by SMFPacks Menu Editor Mod