On 7/21/2022 at 12:27 PM, ZeroByte said:
okay - so having followed the code in the kernal source, it appears that there's a concept I was not yet aware of...
I think LOAD is an exception to the rule, but in general, channel-related commands such as open/close/chkin/etc.... those all consider SA to be broken into two subcomponents:
high nybble = command, low nybble = channel.
The commands like open seem to manipulate the command portion of this.... having to do with talk / untalk / listen / unlisten - commands for the serial bus (or the CMDR-DOS pretending to be a serial device in the case of X16 on device 8.)
Man, this onion keeps having more layers. That's why I wasn't understanding what you were saying,
@TomXP411... I was thinking LFN was the channel, essentially. I know it means "logical file number" - but now I have a new question - can LFN be literally any byte the program wants to use? Could you use LFN = 72 if you want?
I'm also a little surprised, looking at this. It turns out that Position uses the Secondary Address, not the file number.
So this should work:
OPEN 1,8,2,"TEST FILE,S,R"
OPEN 15,8,15,"P"+CHR$(2)+CHR$(64)+CHR$(0)+CHR$(0)+CHR$(0)
This will
not work (using file number in the P command):
OPEN 1,8,2,"TEST FILE,S,R"
OPEN 15,8,15,"P"+CHR$(1)+CHR$(64)+CHR$(0)+CHR$(0)+CHR$(0)
and this will
not work (using device number in P command):
OPEN 1,8,2,"TEST FILE,S,R"
OPEN 15,8,15,"P"+CHR$(8)+CHR$(64)+CHR$(0)+CHR$(0)+CHR$(0)
So where we all got it wrong was assuming "channel" meant the LFN, or Logical FIle Number, aka the
lfn in OPEN
lfn, device, sa That is why you thought that the LFN and the SA needed to match: they did not need to match, but if you were using the LFN with the Position command, it would obviously not work.
Here is the test program I used to figure this out. It tests all permutations of LFN (up to 15) and SA. You can change the FOR loops to test other values and change the SA in 170 to LFN to see what happens when you try to use LFN in the P command.
10 OPEN 8,8,8,"TEST DATA,S,W"
20 FOR I=1 TO 255
30 PRINT#8,CHR$(I);
40 NEXT
50 CLOSE 8
100 PRINT "LFN","SA","TEST","GOT"
110 FOR SA = 2 TO 14
120 FOR LN = 1 TO 15 : REM CAN BE 1 TO 255, CAPPING AT 15 FOR BREVITY
140 PRINT " "," \X91"
150 PRINT LN,SA,
160 OPEN LN,8,SA,"TEST DATA,S,R"
170 OPEN LN+1,8,15,"P"+CHR$(SA)+CHR$(64)+CHR$(0)+CHR$(0)+CHR$(0)
180 GET#LN,A$
190 IF A$=CHR$(65) THEN PRINT "PASS\X91" : GOTO 210
200 PRINT "FAIL ", ASC(A$), : DOS
210 CLOSE LN
220 CLOSE LN+1
230 NEXT
240 NEXT