Questions about how much is the room for BASIC scripting.

Hacking multi-tool. Get one for $30, including worldwide shipping.

Questions about how much is the room for BASIC scripting.

Postby USBEprom » Tue Jan 31, 2017 2:46 pm

Hi guys.
I have some questions about BASIC that maybe somebody of you, I think Sjaak for sure, is in the position to answer.
I was able to build my own version of the firmware for the Bus Pirate v3 where all the features are unlocked, BASIC too (dangerousprototypes.com/forum/download/file.php?id=12196).
In order to reach the goal among the other things I had to switch #define PGMSIZE 1024 to #define PGMSIZE 512.
I do not understand some things.
I wanted to verify the exact amount of the space of RAM available in BASIC.
Seems to me that factory firmware v5.10 allows up 65535 lines for BASIC.
I have downloaded the factory firmware v5.10 into my Bus Pirate revision 3, then I switched to BASIC where I put in a simple sequence of REM in order to evaluate how much room should be avalaible to storage scripts in BASIC.
I was able to enter more than 700 program lines occupying 3kB into the RAM, but I could enter other lines apparently without any problem.
So apparently by reserving 1024 bytes for the BASIC should be possible to enter more than that quantity of bytes, that it sounds weird.
Indeed this does not match with the value 1024 that is used into #define PGMSIZE.
I have not gone over and I have updated my Bus Pirate with the firmware v7.0 that I built.
With it I was able to insert up 128 lines of program which are exactly 511 bytes, I could not go further.
This match with the value 512 that I put into #define PGMSIZE.
Now I know that although into both the firmwares v5.10 and the v7.0 that I built from myself BASIC was unlocked and command line up to 256 characters, the v7.0 that I built myself it has many unlocked features than v5.10, but I do not understand such a big gap based on using the value 1024 or its half.
So my question is, is there some way to predict the exact amount of available space for BASIC by evaluating the features unlocked into the firmware before build it?
Honestly I did not expect a real value of 32767 lines (half of 65535 lines), but not even a such big gap:

#define PGMSIZE 1024 (factory firmware v5.10) = over 3kB, I do not even know exactly what it actually is, I have not verified precisely.

#define PGMSIZE 512 (firmware v7.0 built by myself) = up 511 bytes, not one more.

Thanks.

Be seeing you.

U.Sb
USBEprom
Jr. Member
Jr. Member
 
Posts: 87
Joined: Wed Mar 14, 2012 4:09 pm

Re: Questions about how much is the room for BASIC scripting

Postby Graham242 » Wed Feb 01, 2017 11:51 am

Remember that the BASIC interpreter tokenizes, so it takes less space than the raw text. BASIC keywords are collapsed down to a single byte.

For example, a REM statement like
Code: Select all
100 REM A test

should take up 10 bytes in memory due to the tokenization that occurs, even though the text is 14 chars long. The format in memory is something like <0xE0 + length byte>,<line no high byte>,<line no low byte>, <line data>...
So the above REM line would look like the following in memory:
Code: Select all
0xE7, 0x00, 0x64, 0x87,'A',' ','t','e','s','t'


It's all in the basic.c file.
Graham242
Jr. Member
Jr. Member
 
Posts: 57
Joined: Wed Dec 14, 2011 3:57 am

Re: Questions about how much is the room for BASIC scripting

Postby USBEprom » Wed Feb 01, 2017 3:00 pm

Hi Graham242.
Thanks.
Ok, but what I mean is that seems to me weird that halving the parameter #define PGMSIZE then the available room changes from over 700 lines (3kB) to only 128 lines (511bytes) using the same program listing (1 REM, 2 REM, 3 REM..., n REM).
The tokens are the same both when #define PGMSIZE 1024 or #define PGMSIZE 512, so by using the latter there should be at least 350 lines (1500bytes), not only 128 lines (511bytes).
That is what I do not understand.

Be seeing you.

U.Sb
USBEprom
Jr. Member
Jr. Member
 
Posts: 87
Joined: Wed Mar 14, 2012 4:09 pm

Re: Questions about how much is the room for BASIC scripting

Postby Sjaak » Tue Feb 07, 2017 10:47 am

Remember there is an overhead for storing the line number (16 bits) and an extra byte for the length. this isn't by far efficient and will add up if the programspace is litte. I must admit it is an hack and was my try to write an interpreter from scratch :)

never thought It would be still a wanted feature :)
For my projects and failures see my blog: http://SMDprutser.nl/
User avatar
Sjaak
Fellow
Fellow
 
Posts: 3285
Joined: Sun Jan 03, 2010 2:45 pm
Location: Hiero


Return to Bus Pirate Support