Call SuperBASIC from M/C

Anything QL Software or Programming Related.
Post Reply
tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Call SuperBASIC from M/C

Post by tcat »

Hi,

I have done some basic assembly coding for the QL, suited for the CALL command from within SBASIC program. Now I may face writing a SBASIC extension, something I have not done before, though there are some nice examples to draw on here in the forum, also QL Technical Guide gives essential info.

I will probably need to make use of COPY command from within the extension. Question is, how I can chain a call to SBASIC, and return back to assembly code?

Many thanks in advance.
Tomas


RWAP
RWAP Master
Posts: 2834
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom
Contact:

Re: Call SuperBASIC from M/C

Post by RWAP »

I don't believe that you can under QDOS other than stuffing a string into the SuperBASIC command line (see EDLINE$ from DIY Toolkit).

You could potentially use the multiple BASICs code in SMSQ/e and Mnerva (and even possibly the MultiBASIC code in DIY Toolkit) to generate a new instance of SuperBASIC and execute a command.

However, you are probably best looking at some of the TRAP calls to open a channel to an existing file and then buffer the contents and write it out to a channel opened to the new file (remembering to handle the posittion if the new file already exists).


User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Call SuperBASIC from M/C

Post by NormanDunbar »

Hi Tomas,

I don't think that what you want to do is possible. Sorry.

However, I'm willing to be corrected!


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Call SuperBASIC from M/C

Post by tofro »

That could probably work - At least on a QL with TK2, COPY is a machine code extension. Such extension's addresses are collectable from the name table. I would assume the same in SBASIC on SMSQ/E. I am not sure what's the situation with plain QDOS.

You should, in theory, be able to pull that start address from the name table, push two strings and a separator onto a simulated math stack and probably be able to call the BASIC extension.

I am, however, even if it might possibly work [quite some "probably", "possibly" and "in theory"s in my sentences, aren't they?], pretty sure it wouldn't be any simpler than IO.OPEN, IO.FSTRG and IO.SSTRG in a loop and IO.CLOSE, which is actually pretty straightforward... In case the file to copy fits into available memory, you could even use FS.LOAD and FS.SAVE to load and save it in one go.

Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
janbredenbeek
Super Gold Card
Posts: 629
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: Call SuperBASIC from M/C

Post by janbredenbeek »

tofro wrote:That could probably work - At least on a QL with TK2, COPY is a machine code extension. Such extension's addresses are collectable from the name table. I would assume the same in SBASIC on SMSQ/E. I am not sure what's the situation with plain QDOS.

You should, in theory, be able to pull that start address from the name table, push two strings and a separator onto a simulated math stack and probably be able to call the BASIC extension.
Tobias
It's not really the math stack but the parameters at the end of the name table which the original command routine expects. These are pointed to by (A6,A3.L) (first one) to -8(A6,A5.L) (last one). You could fiddle around with extra parameters and adjust A3 and/or A5 before calling the COPY command routine, but it expects at least one parameter to be evaluated as a string (or name). You cannot just put something on the math stack since all S*BASIC command routines have nothing on the stack when they are called. They need to evaluate the parameters first (using CA.GTINT/GTFP/GTSTR/GTLIN).

Jan.


User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Call SuperBASIC from M/C

Post by tofro »

Jan,

You're absolutely right, forgot that. Long time since I tried to write my last Basic extension.

Doesn't make it any easier, though. I'd still go for programming my own COPY...

Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Post Reply