Channels & Things

Anything QL Software or Programming Related.
Post Reply
User avatar
Giorgio Garabello
Gold Card
Posts: 299
Joined: Tue Jun 30, 2015 8:39 am
Location: Turin, Italy
Contact:

Channels & Things

Post by Giorgio Garabello »

Do you know a way to find out (via Superbasic) which channels and things are used by a given job?
Basically to do what the QPAC2 channels menu does but via Superbasic.

Giorgio


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

Re: Channels & Things

Post by tofro »

You need to walk the channel table (SV_CHBAS points to it, SV_CHTOP points to its end, SV_CHMAX indicates the number of actually used entries) and each entry is a long pointer to a channel definition block. The long word at $8 of the channel definition block is the owner job ID.

Code: Select all

1000 SV_BAS =VER$(-2)
1010 PRINT "System Variables:",HEX$(SV_BAS,32)
1020 SV_CHBAS = PEEK_L(SV_BAS + $78) : sv_chmax = PEEK_W (SV_BAS + $72) : SV_CHTOP = PEEK_L(SV_BAS + $7C)
1030 numChannels = (SV_CHTOP - SV_CHBAS)/4
1040 PRINT "SV_CHBAS:", HEX$(SV_CHBAS, 32), "SV_CHTOP:", HEX$(SV_CHTOP, 32), "NumChannels:",sv_chmax
1050 :
1060 FOR i = SV_CHBAS TO SV_CHTOP STEP 4
1070   chNum = (i - SV_CHBAS) / 4
1080   IF chNum > sv_chmax : EXIT i
1090   CHDB = PEEK_L (i)
1100   chLen = PEEK_L (CHDB + 0)
1110   chDriver = PEEK_L (CHDB + 4)
1120   chOwner = PEEK_L (CHDB + 8)
1130   chTag = PEEK_L (CHDB + $10)
1140   PRINT "Channel:", chNum, "ID: ", HEX$(i,16) & HEX$(chTag, 16), "Owner:", HEX$(chOwner, 32)
1150   PAUSE(-1)
1160 END FOR i
Getting the file/device name for a channel ID is "a bit non-trivial" (i.e., a mystery to me) and needs peeking through system internals. I don't know of anything that documents this. TT as an application writer must have done what Microsoft was sued for decades later (using his system knowledge in applications) :)


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
Giorgio Garabello
Gold Card
Posts: 299
Joined: Tue Jun 30, 2015 8:39 am
Location: Turin, Italy
Contact:

Re: Channels & Things

Post by Giorgio Garabello »

Damn! I don't think I can understand anything. :-(
First of all, thanks for your program! I'll archive it in my documentation.

Thanks


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

Re: Channels & Things

Post by tofro »

Don't give up so fast!

It's actually quite easy:
SV_CHBASE (one entry in the system variables) holds the address of a table in memory that contains SV_CHMAX longwords.
Each of this longwords is the address of a channel definition block.
A channel definition block looks like that

Code: Select all

CH_LEN  	$00 long 	length of definition block
CH_DRIVR 	$04 long	address of driver
CH_OWNER 	$08 long	owner job
CH_RFLAG 	$0C long	address to be set when space released
CH_TAG 		$10 word	channel tag
CH_STAT 	$12 byte	status - 0 OK, negative waiting
					-1 A1 abs, $80 A1 rel A6
CH_ACTN 	$13 byte	stored action for waiting job ID
CH_JOBWT 	$14 long	of job waiting on IO

and describes the properties of this specific channel.

And the code above simply follows these pointers to retrieve CH_OWNER (the channel owner job ID) from these entries.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
Giorgio Garabello
Gold Card
Posts: 299
Joined: Tue Jun 30, 2015 8:39 am
Location: Turin, Italy
Contact:

Re: Channels & Things

Post by Giorgio Garabello »

Thank you very much for your help, I will try to do some tests over the weekend


Post Reply