Run a SuperBasic program from Assembler?

Anything QL Software or Programming Related.
User avatar
t0nyt
Gold Card
Posts: 384
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Run a SuperBasic program from Assembler?

Post by t0nyt »

I'm trying to find a way to run a SuperBasic program from within assembler code

The only 2 things I can think of, but I don't know how to do either, is to be able to do an equivalent to LRUN from within the assembler or send keystrokes to the console

I'm pretty sure both of these should be possible (especially the latter as it's like the F-Key utility)

Could anyone point me in the direction of some sample assembler code at all please?

Many thanks


User avatar
janbredenbeek
Super Gold Card
Posts: 633
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: Run a SuperBasic program from Assembler?

Post by janbredenbeek »

It's different depending on which system you're running.

QDOS: No easy way, you could try stuffing an LRUN command into channel 0's keyboard queue (this of course only works when SB is idle since it cannot multitask).
Minerva: Start an instance of MultiBASIC. The details are in the Minerva manual.
SMSQ/E: Start an instance of the SBASIC Thing, like the EXEP 'SBASIC' command. I haven't yet figured out how to do this from a job running machine code.


User avatar
t0nyt
Gold Card
Posts: 384
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Run a SuperBasic program from Assembler?

Post by t0nyt »

janbredenbeek wrote: Fri Mar 29, 2024 12:48 am It's different depending on which system you're running.

QDOS: No easy way, you could try stuffing an LRUN command into channel 0's keyboard queue (this of course only works when SB is idle since it cannot multitask).
Minerva: Start an instance of MultiBASIC. The details are in the Minerva manual.
SMSQ/E: Start an instance of the SBASIC Thing, like the EXEP 'SBASIC' command. I haven't yet figured out how to do this from a job running machine code.
Thanks. It's for QDOS and would only need to work when idle.

So stuffing channel 0's keyboard buffer would do, will see if I can find some sample "stuffing" code

Many thanks


User avatar
t0nyt
Gold Card
Posts: 384
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Run a SuperBasic program from Assembler?

Post by t0nyt »

t0nyt wrote: Fri Mar 29, 2024 7:20 am
janbredenbeek wrote: Fri Mar 29, 2024 12:48 am It's different depending on which system you're running.

QDOS: No easy way, you could try stuffing an LRUN command into channel 0's keyboard queue (this of course only works when SB is idle since it cannot multitask).
Minerva: Start an instance of MultiBASIC. The details are in the Minerva manual.
SMSQ/E: Start an instance of the SBASIC Thing, like the EXEP 'SBASIC' command. I haven't yet figured out how to do this from a job running machine code.
Thanks. It's for QDOS and would only need to work when idle.

So stuffing channel 0's keyboard buffer would do, will see if I can find some sample "stuffing" code

Many thanks
Just found IO.QIN and tk3 qin source


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

Re: Run a SuperBasic program from Assembler?

Post by tofro »

t0nyt wrote: Thu Mar 28, 2024 8:29 pm I'm trying to find a way to run a SuperBasic program from within assembler code

The only 2 things I can think of, but I don't know how to do either, is to be able to do an equivalent to LRUN from within the assembler or send keystrokes to the console

I'm pretty sure both of these should be possible (especially the latter as it's like the F-Key utility)

Could anyone point me in the direction of some sample assembler code at all please?

Many thanks
Programmatically injecting an LRUN into the interpreter from an external program is basically impossible - SBASIC doesn't have an external interface that would allow you to execute BASIC keywords. SBASIC to your assembly program is an independantly running external job that doesn't have any accessible API.

Using the keyboard queue to inject text commands into the interpreter is a bit tricky. You need to find the #0 BASIC channel (that would mean running through the BASIC channel table, then find #0, then connect the keyboard queue to #0, then push bytes into the keyboard queue (which can be found by the system variable SV_KEYQ and would invole messing with that queue from the outside). This needs to have the interpreter at idle, otherwise it won't succeed.

The most simple method I can imagine to connect SBASIC and assembly is indeed having a BASIC program running before you start the assembly program, listening on a pipe for messages from there and run BASIC subroutines based on these commands. An assembly program would then get the pipe channel on the command line and simply write commands to that pipe. I would follow this part, because it creates the least mess in the system.

Obviously, the very best is use SMSQ/E and the SBASIC thing. But that wouldn't be possible on bare QDOS.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
t0nyt
Gold Card
Posts: 384
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Run a SuperBasic program from Assembler?

Post by t0nyt »

Thanks Tofro

Basically I have a menu (in assembler) and as that can’t do LRUN I wrap it in a basic routine that deletes a temporary file, runs the menu, and then runs the temporary file created by the assembly

That all works good and is launched at the end of my boot file

But to relaunch I have to type “lrun win1_menu_bat” (or whatever) but I want to just be able to type “menu” which is where the resident assembly procedure idea comes in

Not having much luck so far though


User avatar
pjw
QL Wafer Drive
Posts: 1316
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Run a SuperBasic program from Assembler?

Post by pjw »

Turbo Tookit's TYPE_IN, COMMAND_LINE, END_CMD do just that. You could try disassembling them to see how its done. Job#0's channel #0 always has the channel ID $00000000 (unless someone's really messed around!) so no need hunting through S*BASIC's channels tables etc.

The main difficulty may be to ensure job#0 is listening out for commands. If a BASIC program is running it wont hear you, and in some scenarios the job will be buried and therefore be unresponsive. In some scenarios this implies your command will go astray and end up in some other job's queue with unknown consequences.

Been there; done that, albeit a long time ago..


Per
dont be happy. worry
- ?
User avatar
t0nyt
Gold Card
Posts: 384
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Run a SuperBasic program from Assembler?

Post by t0nyt »

I was wondering if anyone could spot why, when I assemble & exec this code, it returns to qdos for a very short while and then q-emulator reports an exception please? I mean it's not as if it's doing anything other than returning

I can't get my head around this

Code: Select all

         TITLE    Show Menu

;         INCLUDE  'win2_dev_quanta_QDOS1_IN'
;         INCLUDE  'win2_dev_quanta_MACRO_LIB'

BP_INIT  equ      $110
IO_QIN   equ      $E0

         SECTION CODE

start    lea      define,a1
         move.w   BP_INIT,a2
         jsr         (a2)  ; have also tried jmp as per first part of Normans example
         rts

define   dc.w     1
         dc.w     siri-*
         dc.b     4,'SIRI'
         dc.w     0

         dc.w     0
         dc.w     0

SIRI     moveq    #0,d0
         rts

         END
Many thanks


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

Re: Run a SuperBasic program from Assembler?

Post by tofro »

Simple answer: You can't just return from an executing job - The system doesn't know where to return to. (Or did you "CALL" that code from BASIC?)

The proper way to end a job is to call MT.FRJB with -1 as job id (Which basically tells QDOS "kill me"). Although that code doesn't look at all like an executable job.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
t0nyt
Gold Card
Posts: 384
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Run a SuperBasic program from Assembler?

Post by t0nyt »

tofro wrote: Fri Mar 29, 2024 3:20 pm Simple answer: You can't just return from an executing job - The system doesn't know where to return to. (Or did you "CALL" that code from BASIC?)

The proper way to end a job is to call MT.FRJB with -1 as job id (Which basically tells QDOS "kill me"). Although that code doesn't look at all like an executable job.
Hi Tofro

It’s example code from Norman’s book to extend basic, but I’ve taken out all the stuff that does anything (maybe I’ve taken out too much)

But I think you’ve just solved the problem I had with a test program I gave up on!

Many thanks


Post Reply