Problem with xbasic compiler

Страница 1/4
| 2 | 3 | 4

By freedom711

Rookie (27)

Аватар пользователя freedom711

05-07-2021, 12:59

hi everyone!

I am new to MSX basic programming. and I have a problem that I can't solve... can you please help me?

The problem is this if i run this listing without xbasic everything works.
But as soon as i insert xbasic (call turbo on) i always have errors...
(Subscript put of range in 30)
the listing is this:

10 dim n$(4192)
20 n$="0":n$(4192)="0":n$(4192)=n$
25 call turbo on
30 for i=1 to 4192:if n$(i)="1" then 60
40 prime=i+i+1:cnt=cnt+1:k=i
50 k=k+prime:if k<4193 then n$(k)="1":goto 50
60 next i
65 call turbo off
70 print cnt

is a benchmark test...

Thanks for the reply ...

Для того, чтобы оставить комментарий, необходимо регистрация или !login

By [D-Tail]

Ascended (8247)

Аватар пользователя [D-Tail]

05-07-2021, 13:26

Your array index goes out of bounds, already in line 20 BTW. If you dim a string (or array for that matter) to X it goes from 0..X-1 (inclusive). So accessing member X is a programming error. It so happens that xbasic is not running at that moment and your violation goes unnoticed.

Lastly, consider using nestorbasic instead of xbasic. It comes with a lot of other niceties that xbasic cannot solve.

By Kai Magazine

Paragon (1406)

Аватар пользователя Kai Magazine

05-07-2021, 13:46

You also must state which variables will be sent inside the turbo_block:
if you do this:
10 A=7
20 CALL TURBO ON
30 PRINT A
40 CALL TURBO OFF
RUN
0
OK
The result will be zero because all variables are 0 every time you begin a turbo block, but they remain intact when you leave the turbo block:
10 A=7
20 CALL TURBO ON
30 PRINT A
40 CALL TURBO OFF
50 PRINT A
RUN
0
7
OK

In order to include an external variable's value inside a turbo block you must state it like this:

10 A=7
20 CALL TURBO ON (A)
30 PRINT A
40 CALL TURBO OFF
50 PRINT A
RUN
7
7
OK

To include several variables, just use a coma:
20 CALL TURBO ON (A,B,C)

But B and C must contain a value, otherwise it will give you an error:

10 A=7:B=0:C=0
20 CALL TURBO ON (A,B,C)

For dimensioned arrays it works like this:

10 DIM N$(25):A=7:B=0:C=0
20 CALL TURBO ON (N$(),A,B,C)

Anyway, having the variables duplicated (outside the turbo block and inside the turbo block) is usually a bad idea and it consumes twice the space AND can generate fatal errors and bugs when the CLEAR function is not used correctly, and it should only be used if those variables will be used by other turbo blocks or outside turbo blocks.
The usual approach would be:

10 CALL TURBO ON
20 A=7
30 PRINT A
40 CALL TURBO OFF
RUN
7
OK

Regarding NestorBasic, yes, it has a lot of features that makes your life easier (embeeded music player and sound player for example) but it requieres 128kb of RAM in order to work while Turbobasic/Xbasic/BasicKun only needs 64kb, so you should choose depending on your needs.

Another tip:
Adding DEFINT A-Z at the beginning of your listing speeds up the turbobasic code A LOT (it does not need to be inside the turbo-block).
If you need a variable not to be an integer you can always leave some for that pruppose:
DEFINT A-Y
Z will not be an integer, and you can define it any way you want.

By freedom711

Rookie (27)

Аватар пользователя freedom711

05-07-2021, 18:53

HI all....

I found that if I create a string variable Xbasic doesn't recognize it....

I made a simple program

10 defint a-z
20 c=0:b=7:a$="jjj"
30 call turbo on(a$,c,b)
40 for i=1 to 10
50 print a$,c,b
60 next i
70 call turbo off
80 end

... if I remove the string a$ everything works...

Most probably there will be a defint instruction to initialize the strings...

I've searched but I can't find documentation on xbasic...
Can someone help me?

By JohnHassink

Ambassador (5582)

Аватар пользователя JohnHassink

05-07-2021, 19:37

Have you tried writing line 30 as such:

CALL TURBO ON (A$(),C,B)

By freedom711

Rookie (27)

Аватар пользователя freedom711

05-07-2021, 21:26

Illegal fuction call 30 Evil Evil

By JohnHassink

Ambassador (5582)

Аватар пользователя JohnHassink

05-07-2021, 22:33

Oh, okay sorry. It must be too long ago for me. Smile
And if you try to put DIM A$(25) first (right after the DEFINT A-Z)?

By freedom711

Rookie (27)

Аватар пользователя freedom711

05-07-2021, 22:52

Is there no documentation?

I'm doing it in Turbo Pascal and it works just fine....

By Kai Magazine

Paragon (1406)

Аватар пользователя Kai Magazine

06-07-2021, 13:09

You can't include strings defined outside the turboblock, you need to define it inside the turboblock.
Also, take into consideration that the variable names are just 2 characters long, so if you write more than 2, only the first 2 will be taken into account:

-prime will be read as pr
-premature will be read as pr as well

This will cause you many issues. Just use 2 characters names (p1, p2...)

Here you can find how to use xbasic/turbobasic/basicKun and the differences between regular basic and xbasic (it is in spanish but you can google tranlate it):

https://www.konamiman.com/msx/msx2th/kunesp.txt

I found some more (in english):

https://konamiman.github.io/MSX2-Technical-Handbook/md/KunBA...

Just google:
-msx xbasic manual
-msx turbobasic manual
-msx basic kun manual

You will find plenty of stuff.

By NYYRIKKI

Enlighted (5843)

Аватар пользователя NYYRIKKI

06-07-2021, 13:09

Yes, strings are bit of a pain as they work very differently inside a turbo block... I don't suggest trying to transfer them, but if you really must...

10 DEFINT Z
20 A$="I don't know why I'm doing this"
30 Z=VARPTR(A$)
40 _TURBO ON (Z)
45 '#I 42,Z,17,A$,126,18,79,35,126,35,102,111,19,6,0,237,176
50 PRINT A$

By freedom711

Rookie (27)

Аватар пользователя freedom711

06-07-2021, 13:23

thanks a lot!!! Smile

Страница 1/4
| 2 | 3 | 4