BASIC_INDEX%() and SBASIC/MultiBASIC

Anything QL Software or Programming Related.
User avatar
ql_freak
Gold Card
Posts: 354
Joined: Sun Jan 18, 2015 1:29 am

BASIC_INDEX%() and SBASIC/MultiBASIC

Post by ql_freak »

The SuperBASIC SBASCIC Reference Manual says there is TurboFix_bin to make the BASIC_INDEX% function compatible with SBASIC and MultiBASIC. Dilwyn's Download Page for Turbo states that TurboFix is no more needed for current versions of Turbo Toolkit. I have tried Turbo Toolkit v3.44 and the patched version in Turbo510 (also from Dilwyn's page), but both don't work in a second SBASIC job on QPC (-12 is returned). I use it in the following batch file (for moving the SBASIC with it's default windows. I call it via (which I have on a hotkey) "x_%=InsVal:y%=InsVal:DO'resetSB_bat'":

Code: Select all

IF BASIC_INDEX%("x_%")<0:PRINT#0,"x_% (or y_%) not set! Aborting":END_CMD
IF BASIC_INDEX%("y_%")<0:PRINT#0,"y_% (or x_%) not set! Aborting":END_CMD
IF x_%<0 OR x_%>512:PRINT#0,"x_% must be in range 0..512!":END_CMD:REMark x%=x_%
IF y_%<0 OR y_%>512:Print#0,"y_% must be in range 0..512!":END_CMD:REMark y%=y_%
PRINT#0,"Reset SuperBASIC origin to "&x_%&", "&y_%&"?";
CURSEN#0:a_$=INKEY$(#0,-1):CURDIS#0
IF a_$<>'y'AND a_$<>'Y':PRINT#0,"User abort":END_CMD
PAPER#2,0:PAPER#1,0:PAPER#0,0
BORDER#2,0:BORDER#1,0:BORDER#0,0:CLS#2:CLS#1:CLS#0
WINDOW#2,256,202,x_%,y_%:WINDOW#1,256,202,x_%+256,y_%:WINDOW#0,512,54,x_%,y_%+202
CLS#0:WINDOW#0,512,54,x_%,y_%+202
BORDER#2,1,255:BORDER#1,1,255:BORDER#0,1,255
PAPER#2,7:PAPER#1,2:PAPER#0,0:CLS#2:CLS#1:CLS#0
END_CMD
This works perfectly in job 0,0 but not in secondary SBASICs.

Must the current (v3.44) version of TurboToolkit be patched with TurboFix to support SBASIC secondary jobs or is it not possible to use BASIC_INDEX% in secondary SBASICs?

Is there a comparable function to test if a variable exists? Unfortunately I cannot use WHEN ERRor in a batch file and I don't want to make it a BASIC program, cause then when moving the SBASIC windows the currently loaded BASIC program will be lost.


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
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: BASIC_INDEX%() and SBASIC/MultiBASIC

Post by dilwyn »

Simple variable values will default to 0 in SBASIC anyway, so I'd be inclined to do something like this if it's only used on SBASIC (i.e. not SuperBASIC):

IF x_% = 0 THEN LET x_% = <some sensible default value>

The notes with TurboFix make no mention of patching BASIC_INDEX%().

Haven't tried it, but presumably there's no difference between TURBO_TK_CODE and TURBO_SMS_CODE in this respect? I've never tried using this for anything other than Job 0 I'm afraid.


martyn_hill
Aurora
Posts: 933
Joined: Sat Oct 25, 2014 9:53 am

Re: BASIC_INDEX%() and SBASIC/MultiBASIC

Post by martyn_hill »

Hi there!

Dilwyn's suggestion is probably the most elegant, relying on SBASICs peculiarity of accepting unknown names and effectively initialising them on first reference, rather than barfing...

Alternatively, if you can bare adding yet another TK to your setup, attached is a modified version of SnG's LOOKUP% function, which I adapted some years ago to allow it to check other SBASics. It will default to referring to the local job, whether that be a daughter SBASic job, or Job (0,0) - but wherever it is run, you can optionally specify a second parameter as the (32-bit, full) Job-ID of the target job you want to search.

Like BASIC_INDEX%, provide the name (in quotes) as the first/only parameter. It will return ERR_NF (-7) if not found in the target Job, or the (local) Name-index (0 or positive) if found therein.

As per the original LOOKUP% offering from Mr Goodwin, a few other functions are included (UPPER$, LOWER$ & NEWCHAN% - one of my favourites) - the other functions are left as per Simon's DIY TK original - my first QDOS/68k 'mentor' via the hallowed pages of QL World...

Caveat - I wrote this adaptation to LOOKUP% a long time ago - before I properly understood the correct use of the Maths Stack, so I suggest you use with care - and peruse the provide source _asm code to sanity check my efforts :-) I just tested it again in SMSQe v3.37 on QPC v5.00 and it did what it was designed to...
Attachments
Lookup2v7.zip
(9.01 KiB) Downloaded 32 times


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

Re: BASIC_INDEX%() and SBASIC/MultiBASIC

Post by pjw »

Im not quite sure what youre trying to achieve, ql_freak, but it seems like youre trying to move the SBASIC window to a predefined position? I have the following hotkey definition in my boot file, it puts the SBASIC window in the top right corner of the screen (which is where I like it) and restores all its attributes:

Code: Select all

500 ERT HOT_KEY('B', "OUTLN#0,512,256,SCR_XLIM-512,0:WINDOW#0;512,52,SCR_XLIM-512,204:PAPER#0;0:INK#0;4:BORDER#0;1,255:CLS#0:WINDOW 256,202,SCR_XLIM-256,0:PAPER 2:INK 7:BORDER 1,255:CLS:WINDOW#2,256,202,SCR_XLIM-512,0:PAPER#2;7:INK#2;2:BORDER#2;1,255:CLS#2" & CHR$(10))
Edit to taste. Of course, this doesnt work if a program is running in the interpreter, but it doesnt wipe any program that is loaded.
If you load the ptrmen_cde toolkit into your system as standard, as I do, you can also just type WMOV in any SBASIC command line to move the the whole 3-window console interactively. Or if you prefer a fixed position, add the following to a hotkey: "WMOV <xpos>, <ypos>" & CHR$(10) where <xpos> and <ypos> are some literal coordinates. The Qptr toolkit has a similar command, I believe.


Per
dont be happy. worry
- ?
User avatar
ql_freak
Gold Card
Posts: 354
Joined: Sun Jan 18, 2015 1:29 am

Re: BASIC_INDEX%() and SBASIC/MultiBASIC

Post by ql_freak »

Thanks pjw,
pjw wrote: Wed Jun 07, 2023 11:03 pm

Code: Select all

500 ERT HOT_KEY('B', "OUTLN#0,512,256,SCR_XLIM-512,0:WINDOW#0;512,52,SCR_XLIM-512,204:PAPER#0;0:INK#0;4:BORDER#0;1,255:CLS#0:WINDOW 256,202,SCR_XLIM-256,0:PAPER 2:INK 7:BORDER 1,255:CLS:WINDOW#2,256,202,SCR_XLIM-512,0:PAPER#2;7:INK#2;2:BORDER#2;1,255:CLS#2" & CHR$(10))
Edit to taste. Of course, this doesnt work if a program is running in the interpreter, but it doesnt wipe any program that is loaded.
If you load the ptrmen_cde toolkit into your system as standard, as I do, you can also just type WMOV in any SBASIC command line to move the the whole 3-window console interactively. Or if you prefer a fixed position, add the following to a hotkey: "WMOV <xpos>, <ypos>" & CHR$(10) where <xpos> and <ypos> are some literal coordinates. The Qptr toolkit has a similar command, I believe.
Does this program also work without a linenumber, i.e. in a QL batch file (S[uper])BASIC without line number{s])?


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: 1316
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: BASIC_INDEX%() and SBASIC/MultiBASIC

Post by pjw »

ql_freak wrote: Thu Jun 08, 2023 1:15 am Thanks pjw,
<>
Does this program also work without a linenumber, i.e. in a QL batch file (S[uper])BASIC without line number{s])?
The line number is just for the boot file, to set up the hotkey. The "program" is the bit in double quotes, and that could be made to work in a batch file.


Per
dont be happy. worry
- ?
User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: BASIC_INDEX%() and SBASIC/MultiBASIC

Post by dilwyn »

I remembered another option when I woke up at 3am this morning. When using SBASIC if you don't want to adjust the sizes of the windows (just locations) another option is to use the WMON and WTV commands with the additional origin parameters. Until fairly recently, I had a set of altkeys set up to reposition the windows in the 4 corners of my QPC2 window. Retyped from memory, so might need a correction:

ALTKEY '1','WMON ,0,0' & CHR$(10) : REM top left
ALTKEY '2','WMON ,SCR_XLIM-512,0' & CHR$(10) : REM top right
ALTKEY '3','WMON ,0,SCR_YLIM-256' & CHR$(10) : REM bottom left
ALTKEY '4','WMON ,SCR_XLIM-512,SCR_YLIM-256' & CHR$(10) : REM bottom right

Note that there is a single space between WMON and the first comma - no 'mode' parameter, just a blank one, so it should work in all modes without trying to change modes.

Pressing ALT 1 resets the window of the current SBASIC job to top left. ALT 2 to top right. ALT 3 to bottom left. ALT 4 to bottom right.

Should be possible to adapt to hotkeys or DO files I guess (not tried), or possibly adapt to use your x_% and y_% variables. I know that the WMON (and presumably WTV) work for the SBASIC window the altkey was pressed in, not just job 0.

Also, by happy coincidence, WMON and WTV in SBASIC seem to manage their own outlines so the BASIC windows can be moved outside their original top left position without needing OUTLN commands.

Can't remember why I stopped using these, maybe I'm not using as many SBASICs as I used to.

When you end up with a screen layout like this in 1024x512 display in QPC2, it gets confusing after a while when you happen to have 3 SBASIC jobs along with the original Job 0 SBASIC!
WMON on ALTKEY with SBASICs
WMON on ALTKEY with SBASICs
wmons2.jpg (6.6 KiB) Viewed 1469 times


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

Re: BASIC_INDEX%() and SBASIC/MultiBASIC

Post by pjw »

Nice one, Dilwyn! I must not have got the memo on that particular use of WMON.
So now Ive changed my hotkey (as above) to:

Code: Select all

500 ERT HOT_KEY('B', "PAPER#0;0:INK#0;4:PAPER 2:INK 7:PAPER#2;7:INK#2;2:WMON ,SCR_XLIM-512,0:CLS#0:CLS:CLS#2" & CHR$(10))
which cuts the length in about half ;)
This restores the windows to their original shape and colour, and in my case, moves the whole lot to the top right.
It seems WMON takes care of window sizes and borders, but not paper or ink. The CLSs at the end are needed in case any paper colours were changed.


Per
dont be happy. worry
- ?
User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: BASIC_INDEX%() and SBASIC/MultiBASIC

Post by dilwyn »

pjw wrote: Thu Jun 08, 2023 10:55 am Nice one, Dilwyn! I must not have got the memo on that particular use of WMON.
So now Ive changed my hotkey (as above) to:

Code: Select all

500 ERT HOT_KEY('B', "PAPER#0;0:INK#0;4:PAPER 2:INK 7:PAPER#2;7:INK#2;2:WMON ,SCR_XLIM-512,0:CLS#0:CLS:CLS#2" & CHR$(10))
which cuts the length in about half ;)
This restores the windows to their original shape and colour, and in my case, moves the whole lot to the top right.
It seems WMON takes care of window sizes and borders, but not paper or ink. The CLSs at the end are needed in case any paper colours were changed.
Great, Per!
Could do the same thing with my ALTKEYs - adding the PAPER/INK/CLS to them. HOT_KEY is probably better on modern systems though. I use the 'B' hotkey to PICK basic on my system, so I think I'll go back to setting up the ALTKEYs on keys 1 to 4. One of my better ideas!
Hope it helps Peter too.


User avatar
ql_freak
Gold Card
Posts: 354
Joined: Sun Jan 18, 2015 1:29 am

Re: BASIC_INDEX%() and SBASIC/MultiBASIC

Post by ql_freak »

Didn't know about the origin parameter for WMON, good hint.

But back to topic about BASIC_INDEX% which may be used for other useful things. Can it be fixed with TurboFix or is there a similar command which works with SBASIC or MultiBASIC (BTW: I have not yet tested it with MultBASIC) jobs other than 0,0?


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 :-)
Post Reply