Page 1 of 6

COLON algorithm

Posted: Sun Jan 19, 2025 12:42 pm
by Popopo
Hi all!

Overview

All times I asked, I got same answer: It is not possible in QL to know from where a software was launching, MDV1, MDV2, FLP1, WIN... whatever. It is so annoying that before to dig deeper in OS and System vars, I decided to create an algorithm that shows "from where" the software was launched.

Actually, what it does is to tells where it is. So anyone can using this algorithm or the code that I am going to release soon to create software that can be launch from any device post-release. You don't need any more to ask to the user which unit is the main one to launch the software. It does it by itself.

Does it work with previos software? No directly. The software would need some modification in order to use the program or implement the algorithm. But it doesn't mean that could be impossible because on the same way the launched unit could be virtualized (something that I discovered reading about Minerva) by software thanks to the algorithm and that would allow to also use it.

State of the algorithm
Now the algorithm is being implementing in SuperBasic (for prototype purpose) before compile it.

The code in SuperBasic is plain and very very general, so it should work with any ROM and ROM version. No needs to use particular TKII, Minerva, JM, J... whatever.
Last night I was testing it in QEmulator and that worked fine. Just left last part to handle exceptions, and getting info about it.

How does it work?
The diagram will be posted here but in some words.
  1. It use a TOKEN to ID the unit that store the rest of the program.
  2. The algorithm explore in a determinate order (can be set by the programmer/user) the units searching for the TOKEN
  3. When a unit is not present, ignores it and process the next one.
  4. If a unit contains its disk or cartridge but not token, ignore and process the next one
  5. When a unit contains its device and has a token but it is not the right one, ignore and process the next one
  6. When it is found, the unit is stored into a var accessible from QDOS named unit$.
  7. If not matching token was found, assign to the var unit$ the value of 'none'
  8. Now the rest of the software (Boot, loading program) can use this var to reference the loading unit$_myprogram_bas or whatever.
  9. The TOKEN ID is just a text file with a number that the programmer decide and the searching algorithm use to match the searching.
  10. When the TOKEN is in the same support than the calling program, it results in finding itself and identified the origin device from where it was launched.
  11. From this point, the programmer can use this var instead absolute references in his code. Allowing from then on, to run it freely from any source (floppy, mdv, win, ramdisk, etc)
  12. It can be modified as please.
This implementation of the algorithm is under little consideration like:
  • To use a user define system var instead a basic var. But need time due my lack of QL programming experience.
  • Accept parameters in order to make it more modular
  • To use OPEN function instead of Merge (mandatory) in order to manage in a better way the exceptions
  • Expert explorations of the units instead scalar order (MDV1, FLP1, WIN1, MDV2, FLP2, WIN2, MDV3,MDV4...) instead of (MDV1...MDV8, FLP1...FLP8, so on)
  • Add a last function that once the unit is found, if the user desire it set that unit as another one by software, what gives a lot of retrocompatibility.
The main point is do it easy, small and general to be compatible with any ROM. So no particular function are used (from TKII or Minerva or any other).

More
As always, I am very easy trigger XD so I forwarded before finish it (my style to encourage myself to finish it and don't loose the interest about it), and before to loose the interesting in this solved puzzle.

Why did I name it Colon?
There are two + 2 reasons:
  1. Because always the answer was that it is impossible.
  2. Due to its simplicity, same than the Egg demonstration of Colon (Columbus)
I will continue writing this post with more information and the demo tonight if my other duties allows me.

Credits:
Special thanks to Andrei for his support debugging in SuperBasic where I am completely new.

Code demostration

Code: Select all

10 REMark @Copyright Silverio M. Rosales Santana 2025
20 CLS : CLEAR
30 CTOKEN = 1234 :     REMark Token value verification ID
40 NToken$ = '_TOKEN': REMark File token name
50 CheckF = 800 :      REMark Line for checking procedure
60 unit$ = 'none'
70 NEXT_BUCLE = 220 :  REMark Address for the next part to use in seeking
80 MAIN_BUCLE = 130 :  REMark Base for calling the main bucle
90 AT 0,6 : PRINT "Demo of algorithm, COLON"
95 AT 4,0 : PRINT "The variable unit$ stores the result"
97 AT 6,6 : PRINT "Otherwise unit$ is none"
100 AT 10,6 : PRINT "press any key to proceed"
110 PAUSE
120 unit$ = 'mdv'
130 REMark Bucle for MDV units
140 i = 1
150   unitAux$ = unit$ & i
160   REMark PRINT unitAux$
170   MERGE unitAux$ & NToken$
180   GO SUB CheckF
190   i = i + 1
200   IF i > 8 THEN GO TO NEXT_BUCLE
210 GO TO 150
220 REMark Bucle for FLP units
230 unit$ = 'flp'
240 NEXT_BUCLE = 260
250 GO TO MAIN_BUCLE
260 REMark bucle for WIN units
270 unit$ = 'win'
275 NEXT_BUCLE = 290
280 GO TO MAIN_BUCLE
290 PRINT "Not found, END"
300 REMark set none and stop
310 unit$ = 'none' : STOP
320 REMark if not before STOP should clear and free mem
800 TOKEN = 12345
900 IF CTOKEN = TOKEN THEN 
905   CLS
910   AT 8,8 : PRINT "Token"! CTOKEN ; " in >"! unitAux$
915   unit$ = unitAux$ : STOP
935 END IF 
940 RETurn 

Download demo

Attached file contains an MDV image with a basic demonstration.
Pay attemption the TOKEN must match the patter into the code. Later version will allows to pass it as a parameter to do it even more general.
With a compiled and basic version.
You can download a demo about how it works. It is not finished yet as I would like but...with my free version of QEmulator and my QLs with only MDPs I cannot test for demonstration purpose more than is shown :)
Demo Colon algorithm by Popopo.zip
(6.54 KiB) Downloaded 88 times
You may find some errors, the code doesn't pretend to be a stable version but the implementation of COLON. For that purpose what I do is to set the code in the MDV1 and in the MDV2 the right TOKEN, but you can put it another place, just keep in mind that since I didn't implement the exception manager (or OPEN function) yet, those units must be with something inside (not empty). :) I am sure you know better than I how to use OPEN or TRAPs better than I and can implement it.

Basic is fine, C much easier and faster. ASM no idea :)

Re: COLON algorithm

Posted: Sun Jan 19, 2025 12:55 pm
by RalfR
Hmm, why not use the "Home Thing"? Also available for QDOS.

"The Home Thing

The Home Thing implements "home directories". A home directory in this context is defined as meaning the directory from which an executable file was executed. A home filename is also supplied by the HOME thing, which is the combination of the filename and the home directory. Once set up, the home directory and home filename may not be changed (with the sole exception of the SBASIC interpreter, which can load BASIC programs from more than one location, or with different filenames).

The Home Thing also implements a "current directory". This is inherited from the job that is setting up the home directory (in most cases the parent job). If the calling job does not have a current directory, a copy of the home directory is used instead."

Re: COLON algorithm

Posted: Sun Jan 19, 2025 1:23 pm
by desin
QDOS home thing
QDOS home thing.png
Greetings from Switzerland
Markus

Re: COLON algorithm

Posted: Sun Jan 19, 2025 1:35 pm
by RalfR
Is this with the version from Dilwyn's site?

Re: COLON algorithm

Posted: Sun Jan 19, 2025 1:56 pm
by Mark Swift
Hi Popopo,

That's so weird. This is exactly what I'm working on at the moment too.
RalfR wrote: Sun Jan 19, 2025 12:55 pm Hmm, why not use the "Home Thing"? Also available for QDOS.
The main objective is to know what device was booted from whilst remaining compatible with the most minimal of systems. And you cannot load any toolkits without first knowing where the toolkits are located.

So to keep it compatible with an unexpanded 128K QL it's important to make no assumptions about the existence of any extra toolkits. It shouldn't use any TKII commands or any SMSQ/E specific HOME_DIR THING at BOOT time.

I have a proof of concept too.
It's been slow progress but this post just spurred me on.
I feel some late-night coding ahead.

Re: COLON algorithm

Posted: Sun Jan 19, 2025 1:58 pm
by desin
Yep
had a conversation with Wolfgang Lenerz at Dormagen last year ...

Greetings from Switzerland
Markus

Re: COLON algorithm

Posted: Sun Jan 19, 2025 2:17 pm
by pjw
desin wrote: Sun Jan 19, 2025 1:23 pm QDOS home thing
QDOS home thing.png

Greetings from Switzerland
Markus
Yeah, the Qdos version seems buggy. Pity. I hope it can be fixed.

And I hope that any alternatives will be compatible with the Home Thing implementation in SMSQ/E. We hardly need yet another standard, viz the mess with the Qdos executable header.. Each their own "standard" = no standards.

Re: COLON algorithm

Posted: Sun Jan 19, 2025 3:25 pm
by Popopo
Mark Swift wrote: Sun Jan 19, 2025 1:56 pm Hi Popopo,

That's so weird. This is exactly what I'm working on at the moment too.
RalfR wrote: Sun Jan 19, 2025 12:55 pm Hmm, why not use the "Home Thing"? Also available for QDOS.
The main objective is to know what device was booted from whilst remaining compatible with the most minimal of systems. And you cannot load any toolkits without first knowing where the toolkits are located.

So to keep it compatible with an unexpanded 128K QL it's important to make no assumptions about the existence of any extra toolkits. It shouldn't use any TKII commands or any SMSQ/E specific HOME_DIR THING at BOOT time.

I have a proof of concept too.
It's been slow progress but this post just spurred me on.
I feel some late-night coding ahead.
Me too!
I was sleeping when I got the idea and yesterday in the afternoon to start to code the algorithm.
So I will share the basic code later. Just left the exception management or to use Open function (universal as far as I know) to check and explore each device in order.
My code is universal and full compatible if it helps you.

I don't take any assumption about any existence, that is why it explore looking for the TOKEN, also considering that there could be more cartridge placed or disks, that is why the TOKEN must be individual for each program and it relies on the programmer or owner to give a particular ID.

Well the algorithm is explained now. :) everyone can implement as pleased.
Sure some will do it in a more elegant way than an inexperience user like me can do.

Re: COLON algorithm

Posted: Sun Jan 19, 2025 3:27 pm
by Popopo
pjw wrote: Sun Jan 19, 2025 2:17 pm And I hope that any alternatives will be compatible with the Home Thing implementation in SMSQ/E. We hardly need yet another standard, viz the mess with the Qdos executable header.. Each their own "standard" = no standards.
My algorithm works everywhere you want to implement.
It is pretty basic basic :)
So no need a particular routine, command nor ROM, system... whatetver you want, you can use.
It is an algorithm, so you can implement it in any way you want.

Re: COLON algorithm

Posted: Sun Jan 19, 2025 4:24 pm
by Popopo
Here is an implementation of the algorithm in SBasic.

It requires some changes to improve it, but the purpose is not to do it perfect, it is to show how it works. :)
I let the task to do it perfect in the hands of better coders.

Code: Select all

10 REMark @Copyright Silverio M. Rosales Santana 2025
20 CLS : CLEAR
30 CTOKEN = 1234 :     REMark Token value verification ID
40 NToken$ = '_TOKEN': REMark File token name
50 CheckF = 800 :      REMark Line for checking procedure
60 unit$ = 'none'
70 NEXT_BUCLE = 220 :  REMark Address for the next part to use in seeking
80 MAIN_BUCLE = 130 :  REMark Base for calling the main bucle
90 AT 0,6 : PRINT "Demo of algorithm, COLON"
95 AT 4,0 : PRINT "The variable unit$ stores the result"
97 AT 6,6 : PRINT "Otherwise unit$ is none"
100 AT 10,6 : PRINT "press any key to proceed"
110 PAUSE
120 unit$ = 'mdv'
130 REMark Bucle for MDV units
140 i = 1
150   unitAux$ = unit$ & i
160   REMark PRINT unitAux$
170   MERGE unitAux$ & NToken$
180   GO SUB CheckF
190   i = i + 1
200   IF i > 8 THEN GO TO NEXT_BUCLE
210 GO TO 150
220 REMark Bucle for FLP units
230 unit$ = 'flp'
240 NEXT_BUCLE = 260
250 GO TO MAIN_BUCLE
260 REMark bucle for WIN units
270 unit$ = 'win'
275 NEXT_BUCLE = 290
280 GO TO MAIN_BUCLE
290 PRINT "Not found, END"
300 REMark set none and stop
310 unit$ = 'none' : STOP
320 REMark if not before STOP should clear and free mem
800 TOKEN = 12345
900 IF CTOKEN = TOKEN THEN 
905   CLS
910   AT 8,8 : PRINT "Token"! CTOKEN ; " in >"! unitAux$
915   unit$ = unitAux$ : STOP
935 END IF 
940 RETurn 
Easy, isn't it?

The TOKEN demo and so on will be posted in the main message for testing purporse.
Since I have not more than a stock QL without floppy, hard disks, Vmaps, 8 mdvs, and so on... I only tested it in my real QL and Qemulator with the limitations that it has.

Another application of my algorithm COLON is that if you develop a software that requires more than 1 MDVs or DISK, you can assing more tokens to ID each source find it and use them.
For example a program that requires 2 MDVs, but you have 8 MDVs (internal and external) or Floppies... you can set on MDV in the first place and second in another place (MDV, FLP, whatever), and the algoritm will find it and using it without bothering about where is it any more.

Moreover, you can with some specific ROMS (also) to find the unit (in case the old software where you cannot modify the source code) and asing to its loading source unit antother virtual unit (as some ROMs can do, and that's all :) you could run it from another localization from where it was till now forced to (unless you have a virtual mapping solution by hardware).

Later I will probably change MERGE routine for OPEN in order to manage exceptions when try to access to a unit what doesn't exist or is not present. I couldn't find docs about exceptions when using MERGE/LOAD or similar.

it makes you free from hardware issues to visualizer or to use only with.
:) hope it is useful for someone :)