Page 1 of 2
TK2 and file manipulation
Posted: Tue Feb 11, 2025 10:57 am
by Tinyfpga
Firstly, does the TK2 documentation that can be found on Dilwyn's website contain
descriptions of all the TK2 instructions? For example; is Kilgus's " TK2 The sequel" documented?
Secondly, although I have read TT's TK2 documentation and the tk2_a4.pdf and have tried to write a program to test Byte I/O using BPUT and BGET, I realise that I do not understand how they work.
Can anyone translate TT's description (12.1) into something more comprehensible?
Possibly with a coded example.
Re: TK2 and file manipulation
Posted: Tue Feb 11, 2025 1:53 pm
by tofro
BGET does three things:
- It positions the file pointer to a certain position in the file
- It reads a single byte each from the current (or re-positioned) file pointer into supplied variables
- It updates an optionally supplied file pointer variable with the actual position
Updates
var with the byte from the file at the current file position
Code: Select all
BGET [#ch\position,] [item *[,item*]*,.... itemn]
Positions the file pointer to
position.
Reads n bytes to the list of (byte) variables
item to
itemn
updates
position with the new file pointer (one after the last byte read)
All the optional parts can be left off, so
positions the file pointer to 100, and
reads one byte into byte from current file pointer
When you're stuck with the TT instructions, you might want to have look at
https://superbasic-manual.readthedocs.i ... eword.html , whose explanations are often easier to understand.
Marcel's TK2 releases are a superset of the "old" TK2 (all what used to be in there is, EXF, EX_M, FET, FEW, FEX, FEX_M, HGET, HPUT, JOBID, LGET, LPUT, UPUT, WGET and WPU have been added) and differently built (as part of SMSQ/E sources) and packaged. See SMSQ/E docs for additional commands or the above link.
Re: TK2 and file manipulation
Posted: Wed Feb 12, 2025 11:00 am
by Tinyfpga
Thanks for your reply. I have finally managed to get BGET to work in a test program. I do read "the docs" but don't find it much easier to understand. I write test programs to really try to understand a particular Keyword and then test it to destruction. I normally takes me but a short time to fail, but from the failure I begin to understand what a Keyword does.
In the case of BGET, even with your help, it took me a while to realise how important the backslash was!
I am now trying to get BPUT to work, so far I have not succeded. It has ,though, brought to the fore a number of questions as follows.
Can two independant programs share a file?
How big can an array be?.
Can it be stored on a storage device? I assume that an array is normally stored in memory.
Does anyone know how QD stores its data before it is saved to a file?
I have not fully understood how one writes and reads integers and floating point numbers in a file. Once I have BPUT working I will try to do this.
Re: TK2 and file manipulation
Posted: Wed Feb 12, 2025 11:28 am
by RalfR
Tinyfpga wrote: Wed Feb 12, 2025 11:00 am
Can it be stored on a storage device? I assume that an array is normally stored in memory.
Does anyone know how QD stores its data before it is saved to a file?
For manipulating arrays, look here:
https://www.wlenerz.com/qlstuff/#outptr
QD stores its data in double linked lists in memory. I don't think you can access it directly, maybe via the option you have via F10, the QD Thing.
Re: TK2 and file manipulation
Posted: Wed Feb 12, 2025 12:16 pm
by tofro
Tinyfpga wrote: Wed Feb 12, 2025 11:00 am
Can two independant programs share a file?
Yes. Multiple programs can
read the same file concurrently. (You would use OPEN_IN to signal to QDOS that you want to open the file in read-only mode). If any other sort of OPEN (that would allow writing) is used on that same file, you'll get an
in Use error.
Tinyfpga wrote: Wed Feb 12, 2025 11:00 am
How big can an array be?.
Array indices in S*BASIC are two-byte words, meaning an array cannot grow beyond 32767 (on some SuperBASIC versions due to ROM bugs a bit less) elements.
Tinyfpga wrote: Wed Feb 12, 2025 11:00 am
I have not fully understood how one writes and reads integers and floating point numbers in a file. Once I have BPUT working I will try to do this.
You have to decide whether you want a binary or ASCII file first. If your file uses ASCII representations (i.e. writing/reading numbers as text, which is probably easier for beginners), you can use PRINT and INPUT (or INKEY$ for single-character reads), just like to/from the screen. Otherwise, you'll need at least Toolkit 2 to read and write binary data - And you would probably best use GET and PUT for that (or BGET and BPUT if you want to read/write only single bytes)
Re: TK2 and file manipulation
Posted: Wed Feb 12, 2025 7:21 pm
by Tinyfpga
Thank you to both RalfR and tofro for your replies They have been helpful.
I have finally got my BPUT program to work. I am not surprised that so few application programs for HD SMSQE are currently published. Programming is not an easy thing to do.
"Double linked list in memory". I had to lookup what the meant and found a vaguely comprehensible article on Wikipedia.
Has anyone created coding infrastructure to support this for SMSQE?
From "Read the docs"
BGET [#ch\position,] [item *[,item]*..]
Each item to be fetched must therefore be either an integer or a floating point variable.
"must therefore"!
Does this mean " is either etc.......... depending on whether item is stored as
a or a%." The result looks same except that the variable a is stored internally as a floating point number in the range 0..255
"Current versions of the Turbo and Supercharge compilers are not able to compile programs which use BGET."
This seems like one reason not to use them?
Re: TK2 and file manipulation
Posted: Wed Feb 12, 2025 8:26 pm
by tofro
Tinyfpga wrote: Wed Feb 12, 2025 7:21 pm
"Current versions of the Turbo and Supercharge compilers are not able to compile programs which use BGET."
This seems like one reason not to use them?
"Current" as of "current by the time of writing". This has been no longer true for quite some years. Turbo has been supporting call by reference machine code extensions (like BGET) for like 10 years now, thanks to some work done by the late George Gwilt.
To my knowledge, here's only one rather esoteric single feature of S*BASIC left not supported by Turbo that most people don't even know is supported by S*BASIC..... (and some rather odd things like
calculated DATA values...)
Re: TK2 and file manipulation
Posted: Wed Feb 12, 2025 10:13 pm
by ql_freak
tofro wrote: Wed Feb 12, 2025 8:26 pm
"Current" as of "current by the time of writing". This has been no longer true for quite some years. Turbo has been supporting call by reference machine code extensions (like BGET) for like 10 years now, thanks to some work done by the late George Gwilt.
Didn't know that! Does Turbo also support this (passing arguments as reference to MACHINE CODE functions) on BBQL or only on SMSQ/E and/or Minerva? This (and the next question, but not so important) would make life a lot more easier. I've never used GET, BGET, ... but the GET functions from TK II becuse of this Turbo restriction.
And does Turbo now also support WHEN ERRor (JS+ versions)?
To my knowledge, here's only one rather esoteric single feature of S*BASIC left not supported by Turbo that most people don't even know is supported by S*BASIC..... (and some rather odd things like calculated DATA values...)
What is this "esoteric feature"?
Re: TK2 and file manipulation
Posted: Wed Feb 12, 2025 10:41 pm
by tofro
ql_freak wrote: Wed Feb 12, 2025 10:13 pm
Didn't know that! Does Turbo also support this (passing arguments as reference to MACHINE CODE functions) on BBQL or only on SMSQ/E and/or Minerva? This (and the next question, but not so important) would make life a lot more easier. I've never used GET, BGET, ... but the GET functions from TK II becuse of this Turbo restriction.
Yes, it does - There is, however, a significant difference between old QDOS and SMSQ/E: One-dimensional strings on QDOS will always be passed by value.
ql_freak wrote: Wed Feb 12, 2025 10:13 pm
And does Turbo now also support WHEN ERRor (JS+ versions)?
WHEN (sic) the ROM supports it, Turbo will happily compile, with the result code even running on older ROMs (obviously, you cannot test with the interpreter there). If not, you can replace it with Turbo's own WHEN_ERROR mechanism that comes with Turbo Toolkit.
To my knowledge, here's only one rather esoteric single feature of S*BASIC left not supported by Turbo that most people don't even know is supported by S*BASIC..... (and some rather odd things like calculated DATA values...)
ql_freak wrote: Wed Feb 12, 2025 10:13 pm
What is this "esoteric feature"?
I knew someone would ask

That esoteric feature is typeless parameters in FuNctions and PROCedures, that is, you can write functions that will work on all possible data types (like a function that sorts strings, integers, characters,.... ). QLiberator can compile this, Turbo cannot (and compiler writers tend to flee in horror if you explain this to them...). I've yet to find such functions in the wild - The only example I know is in one of the QLiberator example programs (guess why...).
Re: TK2 and file manipulation
Posted: Wed Feb 12, 2025 10:46 pm
by martyn_hill
Hi Peter
As I've come to understand it, the pass-by-reference to/from MC procedures is supported in Turbo-compiled progs for fixed-length scalers across QDOS/Minerva and SMSQe.
However, only SMSQe provides for variable-length strings to be passed-by reference from MC procedures - and only if the Turbo compiler directive TURBO_ref is enabled.
If you attempt to run a Turbo-compiled prog with TURBO_ref enabled on QDOS/Minerva, it will stall at start-up with an error 'Not implemented.'
Good luck!