+bf2k+ Posted April 1, 2023 Share Posted April 1, 2023 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: and then this: 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. Quote Link to comment Share on other sites More sharing options...
vitoco Posted April 1, 2023 Share Posted April 1, 2023 (edited) 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 April 1, 2023 by vitoco Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted April 1, 2023 Share Posted April 1, 2023 One more thing, 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 Quote Link to comment Share on other sites More sharing options...
dmsc Posted April 2, 2023 Share Posted April 2, 2023 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: and then this: 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! Quote Link to comment Share on other sites More sharing options...
+bf2k+ Posted April 2, 2023 Author Share Posted April 2, 2023 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. Quote Link to comment Share on other sites More sharing options...
vitoco Posted April 2, 2023 Share Posted April 2, 2023 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. Quote Link to comment Share on other sites More sharing options...
+bf2k+ Posted April 2, 2023 Author Share Posted April 2, 2023 SIO $31, 1, $52, 64, &buf, 15, 128, 123, 0 ' Read sector 123 from drive 1 When I try to use the above, I get a Parse Error after the SIO Quote Link to comment Share on other sites More sharing options...
vitoco Posted April 2, 2023 Share Posted April 2, 2023 5 minutes ago, bf2k+ said: When I try to use the above, I get a Parse Error after the SIO SIO statement is not available in stable version 4.6. The parser fails because it thinks that SIO is a variable and a "=" is missing. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.