SBASIC maximum string length

Anything QL Software or Programming Related.
Post Reply
User avatar
ql_freak
Gold Card
Posts: 488
Joined: Sun Jan 18, 2015 1:29 am

SBASIC maximum string length

Post by ql_freak »

Because of my assembler project (I'm not sure, if I will succeed, it's more complicated, than I first thought) I have made some tests on QPC2 about maximum string length in SBASIC. First of all: It seems not possible to have a SBASIC string with the maximum SMS/Q/QDOS string length of 32767 characters.

for FILL$ the maximum is long$=FILL('x',32764)
To make a longer string you can use:
long2$=long$&'x' : REMark ...&'xx' will fail with arithmetic overflow

The longest string I was able to create is 32766 characters long, and was created with an INPUT statement, with the help of the following program:

Code: Select all

100 REMark Test input string$ with a string length of 32767
990 :
1000 fnam$='RAM1_test_txt'
1010 tmp$='AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789--'
1020 REMark LEN(tmp$)=64:64*511+63=32767
1090 :
1100 exists=FTEST(fnam$):IF NOT(exists=0 OR exists=-9)
1110   OPEN_NEW#4,fnam$
1120   FOR i=1TO 511
1130     PRINT#4,tmp$;
1140   END FOR i
1150   PRINT#4,tmp$(1TO 62); : REMark If the PRINTed string is longer than 62 chars
1160   :                       REMark    SBASIC may crash when INPUT (see line 2120)
1170   PRINT#4 :REMark print LF so that we can use INPUT veryLong$
1180   CLOSE#4
1190 ELSE
1200   PRINT"Using existing file ";fnam$
1210 END IF
1990 :
2000 rorre=FOP_IN(#4,fnam$):PRINT"FOP_IN()-Result=";rorre:IF rorre
2010   PRINT"Cannot open ";fnam$;", error:":REPORT#1,rorre
2020   GO TO 32756:REMark Exit program - STOP may cause problem on some QLs
2030 END IF
2090 :
2100 REMark Test INPUTting a string with maximum length:
2110 :
2120 INPUT#4,veryLong$
2130 CLOSE#4
2140 PRINT"veryLong$ has been read"\"LEN()=";LEN(veryLong$)
2150 PRINT"First 64 chars of veryLong$:"
2160 PRINT veryLong$(1TO 64)
2170 :
32755 :
32756 CLOSE#4
32757 REMark END OF PROGRAM -- do NOT use line numbers > 32757, may give problems
SAVE ALL YOUR WORK and try this program with line 1150 changed to ... tmp$(1to 63)

Peter


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
User avatar
janbredenbeek
Super Gold Card
Posts: 673
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands
Contact:

Re: SBASIC maximum string length

Post by janbredenbeek »

ql_freak wrote:Because of my assembler project (I'm not sure, if I will succeed, it's more complicated, than I first thought) I have made some tests on QPC2 about maximum string length in SBASIC. First of all: It seems not possible to have a SBASIC string with the maximum SMS/Q/QDOS string length of 32767 characters.

for FILL$ the maximum is long$=FILL('x',32764)
I guess it has something to do with the way S*BASIC stores strings (length word + string).
A string of 32765 characters needs 32766 bytes (since it must be word aligned on the RI stack), plus 2 for the length word = 32768 bytes. Now this can still be perfectly stored, but might break some code. For instance, this code to find the next entry on the RI stack:

Code: Select all

moveq   #3,d0
add.w   (a6,a1.l),d0  (total size of length word + string + padding)
bclr    #0,d0  (round to even length)
adda.w  d0,a1  (skipover string)
Now when the string length is 32765, after the second instruction D0 will be 32768, which will be sign-extended to -32768 so A1 will be decreased by 32768 instead of increased!

BTW, I tested this on JS and Minerva and where JS allowed strings of 32766 bytes, Minerva gave an error at 32765...

Jan.


stevepoole
Aurora
Posts: 889
Joined: Mon Nov 24, 2014 2:03 pm

Re: SBASIC maximum string length

Post by stevepoole »

Hi,
SuperBasic can address 16 bit words, that is 65536 array cells.
But half of these are negative numbers.
Superbasic cannot access negative offsets to addresses, so array addressing is limited to 32766 units.
If you want more cells, Peek_L and Poke_L into resrved memory.
Then the only limit is the computer's memory.
Steve Poole.


stevepoole
Aurora
Posts: 889
Joined: Mon Nov 24, 2014 2:03 pm

Re: SBASIC maximum string length

Post by stevepoole »

Hi,
I had a problem using QPC2 for writing a data input program.
Sometimes when INPUTing strings, if I happened to touch the mouse or touchpad, the program would stop with an error message.
Michael Bulford sent me the solution :
100 INPUT i$: if i$="": goto 100
This gets rid of the quirk in QPC2 completely. I always used this test, except in one subroutine which I had overlooked...
I had never realised that mouse or touchpad movements could get codes written into strings !
I thought this tip should be broadcast...
Best wishes,
Steve Poole.


Post Reply