Jump to content
IGNORED

Fastbasic string questions


Recommended Posts

I recently started playing with FastBasic and I must admit I am really liking it... but I am having difficulty with FB strings since I am used to programming Atari Basic since 1981. So I decided I would take one of my working Atari Basic programs and convert it.  It is basically a disk read / comparison program. I have this 90% completed in FB, but am struggling a little.

 

In Atari Basic I use this:

 

DIM A$(2560), B$(2560)

and I know this is two strings of 2560 bytes each.  No problem reading and writing to it in AB.

 

In FB, is it correct that this would be two string arrays of 2560 bytes each?

 

If so, what is the correct way of writing to it? 

 

Or am I missing  it completely?

 

I know I may need to elaborate more since I read a sector from the disk by setting up a pointer into the string, performing some pokes in and around $300 and then using this:

image.png.130e301c47a0333573a39367c29e442c.png  and then this: image.png.e43d5b01a55961c3f3ff77759b530416.png

 

I suspect that I am not setting up the string (or string array) pointer correctly because it completely locks up Altirra changing the screen colors and requiring a hard reboot when the program tries to execute the USR call.

 

This program works perfectly in Atari Basic, MMG-compiled Atari basic, and Basic XE.

 

If I comment out the USR call, the program will execute normally except it will not do anything because it isn't reading the disks.  So I feel my supporting logic is OK except for my string/string-array differences...

 

Any ideas what I am missing?

 

BTW... the AB versions are in SpartaDOS 3.3a and 4.49 - developed in Altirra.

 

Link to comment
Share on other sites

Strings work differently in FastBasic.

 

Strings always use 256 bytes each, and they might have a max length of 255 bytes because the first byte says which is the current length of it.

 

For larger data you might use arrays of byte, and that requires to be DIMed.

 

About the USR, as the first byte of the string constant has the length, you must add 1 to the ADR function.

 

Edited by vitoco
Link to comment
Share on other sites

One more thing, image.png.130e301c47a0333573a39367c29e442c.png is PLA JMP $E456

I think you need to pass in the channel number *16 or

if you know which channel you have opened, just add (if it's channel 1)

LDX #$10

PLA

JMP $E456

 

else pass in the channel *16

e.g. x=USR(adr(SIO$)+1,16) for channel 1

 

PLA

PLA

PLA

TAX

JMP $E456

Link to comment
Share on other sites

Hi!

23 hours ago, bf2k+ said:

I recently started playing with FastBasic and I must admit I am really liking it... but I am having difficulty with FB strings since I am used to programming Atari Basic since 1981. So I decided I would take one of my working Atari Basic programs and convert it.  It is basically a disk read / comparison program. I have this 90% completed in FB, but am struggling a little.

 

In Atari Basic I use this:

 

DIM A$(2560), B$(2560)

and I know this is two strings of 2560 bytes each.  No problem reading and writing to it in AB.

 

In FB, is it correct that this would be two string arrays of 2560 bytes each?

As @vitoco already answered, in FastBasic strings don´t need DIM before use, but the have a limit of 255 characters maximum. The DIM above actually defines two *arrays*, each of 2560 strings.

 

23 hours ago, bf2k+ said:

I know I may need to elaborate more since I read a sector from the disk by setting up a pointer into the string, performing some pokes in and around $300 and then using this:

image.png.130e301c47a0333573a39367c29e442c.png  and then this: image.png.e43d5b01a55961c3f3ff77759b530416.png

The best way to define an assembly routine in FastBasic is with "DATA":

DATA SIO() BYTE = 76, 89, 228
X = USR( ADR(SIO) )

 

BUT... as FastBasic does not push the number of arguments to the stack before calling your assembly code, you can call SIO directly:

X = USR( $E459 )

 

Also, in the currently development version, FastBasic includes a SIO command, for example, to read a sector from the disk, you can do:

DIM buf(128) byte   ' Allocate a buffer of 128 bytes
SIO $31, 1, $52, 64, &buf, 15, 128, 123, 0    ' Read sector 123 from drive 1

 

Have Fun!

 

Link to comment
Share on other sites

9 hours ago, dmsc said:

Also, in the currently development version, FastBasic includes a SIO command, for example, to read a sector from the disk, you can do:

DIM buf(128) byte   ' Allocate a buffer of 128 bytes
SIO $31, 1, $52, 64, &buf, 15, 128, 123, 0    ' Read sector 123 from drive 1

 

Have Fun!

 

Lots of great info here guys.  Thank you all immensely!!!

 

 x could be equal to 128 or 256 or 512 (for the different sector sizes)

Will this work or must I use a constant in the DIM statement?

DIM buf(x) byte

 

I recognize the parameters in the SIO instruction as the POKES I make around $300 in my Atari Basic version.  I am using FB 4.6.

Link to comment
Share on other sites

1 hour ago, bf2k+ said:

x could be equal to 128 or 256 or 512 (for the different sector sizes)

Will this work or must I use a constant in the DIM statement?

DIM buf(x) byte

You can use variables as an argument to DIM, but take note that the reserved space is 1 byte larger that the specified argument. That is because of backward compatibility to Atari BASIC. DIM A(5) allows to query from A(0) to A(5), i.e. 6 values. If it's a WORD array, then it will be 1 word (2 bytes) larger.

 

Also note that in the previous example, A(6) in Atari BASIC triggers an ERROR 9, which does not happen in FastBasic, because there are no range validation.

 

This is powerful in FastBasic, because you must DIM to size 0 for a single element (byte or word) or even to size -1 for a 0 length array... Wait, WHAT!?!?!?

 

Yes... You can do the following:

X=127
DIM A(-1) BYTE, B(X)
? ADR(A), ADR(B)

In this case, both arrays will use the same segment of memory (one page), and you can access there by words or by bytes, and you don't need to use expressions to convert from lo-hi bytes to words and/or vice versa on data.

 

In the same way, you could use:

DIM A(-1), B(15), C(99), D(3)

and access B(), C() and D() secuentially from array A().

 

About USR, I forgot that FastBasic does not insert the number of parameters to the stack, so during a migration from Atari BASIC or TurboBasic XL, you must remove the initial "h" (PLA opcode) from the ATASCII string or add 2 to the ADR function instead of just 1.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...