How to start a SBASIC from other languages (e. g. C, ASM)

A place to discuss general QL issues.
User avatar
ql_freak
Gold Card
Posts: 353
Joined: Sun Jan 18, 2015 1:29 am

How to start a SBASIC from other languages (e. g. C, ASM)

Post by ql_freak »

How can a SBASIC job be started on QPC2?

I don't mean the SBASIC keyword (btw it is very limited), because that is only available from SuperBASIC not from other languages.

Is there something similar like Minervas "multib_exe", where it is possible to pass channels, CMD$, ...

This was very useful, one could do exciting things, if one passed eg. channels.

Peter


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: How to start a SBASIC from other languages (e. g. C, ASM

Post by pjw »

You will find that information in the QPC Keywords manual. Basically you can just use the EX* command family to execute an SBasic job just like any other. From the manual:
EX, EXEC
EW, EXEC_W
ET SMSQ/E
EX and EW will load a sequence of programs and execute them in parallel.
EX will return to the command processor after all processes have started execution, EW will
wait until all the processes have terminated before returning.
ET sets up the programs, but returns to SBASIC so that a debugger can be called to trace the
execution.
EXEC is the same as EX, and EXEC_W is the same as EW.
syntax: program := device
parameters := string_expression
file := filename, or channel_number
EX program [ *,file * ] [;parameters]
EX program [ *,file * ] [;parameters]
<..>
EX is designed to set up filters for processing streams of data.
<..>
the complete form of the EX command is
prog_spec := program [ *,file * ] [;parameters
EX [#channel TO] prog_spec [ * TO prog_spec * ] [TO #channel]
Each TO separator creates a pipe between Jobs
All the above applies to Sbasic _bas and _sav programs too. The job can use any supplied channels. The command line can be read from the variable CMD$. The name of the job can be set with JOB_NAME. It all works really well. I m not aware that executing Sbasic programs in this way has been implemented in other languages.

Per


Per
dont be happy. worry
- ?
User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: How to start a SBASIC from other languages (e. g. C, ASM

Post by tofro »

Peter,

starting an S*BASIC job/program from assembler isn't exactly trivial and depends a bit on the versions you have to work with.

On the standard QL, you would pull the single SuperBASIC into the foreground, locate #0's keyboard queue and feed a command to run your program in there. This is not going to work if SuperBASIC is busy.

In Minerva, you could actually use multib (or, in more actual versions "pipex") as you said to start a SuperBASIC job.

SMSQ/E doesn't have a dedicated executable you can load as a job to do that work. Instead you can
  • Revert back to the good old method with the keyboard queue and from there use the EX command that Per mentioned. You need to live with a single S*Basic job, however (Or start a new one using the stuffed command. You're still lost, however, if S*BASIC is busy).
  • Dig into Thing programming - There is a number of SMSQ/E Things that can help you here:
    • The HOTKEY SYSTEM 2: You can create a HOTKEY that contains a HOT_CMD item to EX an S*BASIC job, then HOT_DO it from assembler entirely
    • The FILE_INFO extensions (a "Thing" as well, from Thierry Godefroy and Wolfgang Lenerz) that can "Execute" files - One of the file types it executes are _bas files
    • SMSQ/E has an SBASIC thing that you can USE - Gives you a new S*BASIC job. Then stuff commands into this new one's keyboard queue
But, in the end, everything but the last one just boils down to stuffing something into S*BASIC's keyboard queue - The other methods don't do it much differently, just with a nice wrapper around it making programming a bit easier.

Why most of this stuff has been implemented into THINGS, however escapes me a bit (at least for SMSQ/E which is unique with its independent S*BASIC jobs). THINGS are elegant for extending the OS, but overly complicated to use in my opinion.

Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: How to start a SBASIC from other languages (e. g. C, ASM

Post by tofro »

...talking to myself again ;) :

THING programming (and actually, what sort of stuff you can do with specific THINGS) isn't overly well documented. The best source to start with would be the QDOS/SMS reference manual from here

http://kilgus.net/smsqe/QDOS%20SMS%20Re ... Manual.pdf

The standard THING implementations that actually come with SMSQ/E are best documented in the SMSQ/E source code on Wolfgang's site.

Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
ql_freak
Gold Card
Posts: 353
Joined: Sun Jan 18, 2015 1:29 am

Re: How to start a SBASIC from other languages (e. g. C, ASM

Post by ql_freak »

pjw wrote:You will find that information in the QPC Keywords manual. Basically you can just use the EX* command family to execute an SBasic job just like any other. From the manual:
OK, I knew that it is possible to start Basic file as job with ex. But I didn't know that channels and command strings are passed.

What are the channel numbers of the files/channels passed?

First channel/file: Channel no. ? (Minerva #0)
Second channel/file: Channel no. ? (Minerva #1)
Third channel/file: Channel no. ? (Minerva #3)

BTW: My web site wasn't reachable today (my provider changed something), but now it should be reachable again.


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: How to start a SBASIC from other languages (e. g. C, ASM

Post by pjw »

Tobias et al,

One of the reasons to use Things is that you can access systems facilities from any programming language. I dont know the details from c68, but in SBASIC you can do the following:

Code: Select all

EXEP "SBASIC"; 'LRUN "win1_myprog_bas"'
ie you feed the (inbuilt) SBASIC Thing with the command line to execute on startup, in this case the command to run myprog_bas as soon as it fires up. This can (somehow) be done from C as well, and probably from other languages where Thing handling is implemented, or with sufficient low-level wherewithall to do the implementing directly.

There are many other cool things you can do with SBASIC in this way. Here is a proof-of-concept program to torment an SBASIC interpreter:

Code: Select all

1 REMark Get an SBASIC job to work as
2 REMark a slave of another SBASIC.
3 REMark Expects to be run in standard
4 REMark SB 3 window confinguration.
5 :
6 REMark By pjwitte January 23rd 2001+
7 REMark V0.02
8 :
9 REMark Init
10 ch = 1: cu = 0: CLS#ch: CLS#cu
11 pip$ = 'pipe_p' & HEX$(DATE,32)
12 :
13 JOB_NAME 'Master'
14 :
15 REMark Plumb in SBAS slave
16 co = FOPEN(pip$ & 'o_2048'): ERT co
17 :
18 REMark lrun our command stream
19 cm$ = 'lrun "' & pip$ & 'o"'
20 :
21 REMark Start SBAS with command
22 EXEP 'SBASIC'; cm$
23 :
24 REMark We control command channel
25 PRINT#co; 'JOB_NAME "Slave"'
26 PRINT#co; 'ch = fopen(#1; "' & pip$ & 'i_1024")'
27 PRINT#co; 'ce = fopen(#2; "' & pip$ & 'e_1024")'
28 :
29 REMark Messages come out here
30 ci = FOP_IN(pip$ & 'i'): IF ci < 0: CLOSE: ERT ci
31 ce = FOP_IN(pip$ & 'e'): IF ce < 0: CLOSE: ERT ce
32 :
33 REMark Give slave some tools
34 LIST#co; 1000 TO
35 :
36 REMark Test
37 PRINT#co; 'echo "Hello": beep 2000, 2'
38 IF Answer < 0: CLOSE: STOP
39 :
40 REMark Torment!
41 CLS#cu: PRINT#cu; 'Type in your commands'
42 REPeat sb
43  INPUT#cu; '>'! cm$
44  IF cm$ = '' OR cm$ == 'quit': EXIT sb
45  PRINT#co; cm$
46  IF Answer < 0: EXIT sb
47 END REPeat sb
48 :
49 PRINT#co; 'beep 2000, 2: quit'
50 CLOSE
51 :
52 :
53 DEFine FuNction  Answer
54 LOCal il, ans%, k$(1), l$
55 ans% = 0
56 REPeat il
57  k$ = INKEY$(#ci; 20)
58  IF LEN(k$) = 0: EXIT il
59  INPUT#ci; l$: echo k$ & l$
60   ans% = 1
61 END REPeat il
62 IF EOF(#ci): ans% = -10
63 IF ans% = 0: echo 'no answer'
64 IF ans% < 0: echo 'Slave died'
65 RETurn ans%
66 END DEFine
67 :
1000 DEFine PROCedure echo(t$)
1001 PRINT t$
1002 END DEFine
1003 :
Of course the link is rather tenuous; should an error occur in the slave, SBASIC will open its own CONsole#0 to complain, cutting the master off from the command channel. I havent found a way around this yet, but then I havent spent much time playing with this.

Per


Per
dont be happy. worry
- ?
User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: How to start a SBASIC from other languages (e. g. C, ASM

Post by pjw »

Ah, the fix to the loosing control issue I mentioned above is:

Code: Select all

19 cm$ = 'ci = fop_in(#0; "' & pip$ & 'o")'
but then there are no error messages at all. There may well be other and better ways to do it..

Per


Per
dont be happy. worry
- ?
stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: How to start a SBASIC from other languages (e. g. C, ASM)

Post by stevepoole »

Hi,
II have written a program to multitask five basic programs, giving five active CON devices which communicate instantaneously without PIPEs.

First I ALCHP some memory in a BOOT, poke its address into the base and SBYTES the lot to a RAM1_ file called KEYHOLE.

All five programs then ALCHP some memory, and LBYTES the KEYHOLE file adress into it.

All five programs can then pass keycodes into their five heaps and back, using PEEK$ and POKE$.

So no need for PIPES, which are 'orribly complicated to communicate with !

RECHP the memory, when each job is quited in any order... via the KEYHOLE method.

TURBO manual mentions such direct memory exchanges, but gives no method of how to do it. The KEYHOLE method is fast and furious !

Best Wishes, Steve.


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

Re: How to start a SBASIC from other languages (e. g. C, ASM)

Post by NormanDunbar »

Hi Stephen,

That all sounds like fun. There's another possible way, which I admit to not using for some time, CSM (http://www.dilwyn.me.uk/tk/csm122.zip) described on Dilwyn's Emporium of Finest Software, at http://www.dilwyn.me.uk/tk/index.html, as:

Client Server Manager is a Thing that implements easy and robust messaging between jobs. It allows one-to-many links and makes adding scripting to programs, using BASIC as the scripting language, very easy.

See what you think.


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.
stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: How to start a SBASIC from other languages (e. g. C, ASM)

Post by stevepoole »

Hi Norm,
Yes, I studied the CSM instructions... all 15 pages of it. It is very comprehensive, but requires the THING system to be installed.

I have run the KEYHOLE METHOD on my SGC QL without a hitch, and under QPC2, but not Qemulator, which won't EXEC basic programs.

I exchange keys via PEEK$ and POKE$ fixed-length String$, where each character indicates '0' or a keycode. Simple !

With a fixed length string$, no risk of memory corruption... and easy to test for. ( For a 128ko QL, I wrote my own peek$ & poke$).

I have tried exchanging the entire ascii set, where all but one character pass OK, with a 254-char string$ allocated.

So you can print & input messages one char$ at a time instantly between all jobs, with no need for PIPEs or any clutter.

I thought this method may be useful for anyone needing simple key communications betwen any number of jobs.

Regards, Steve.


Post Reply