|
Post by 6502bitrider on Aug 2, 2015 21:01:20 GMT
Wow, I just stumbled across this site. I thought it had gone away for good. I used to lurk at the original site a lot. Good to see it's alive again, just wished I would have found it earlier !
I have a question. I'm trying to get the contents of the directory off of a 1541 drive using commands like OPEN, INPUT# or GET#. I know it can be done, but for the life of me I can't find/remember any examples of how to do this. Does anybody know how this is done or have some example code ?
Thanks !
|
|
|
Post by hydrophilic on Aug 4, 2015 7:38:49 GMT
Great question... well there are 3 options: - Use DIRECTORY to print list of files to the screen (easy, but no program control of number of lines... only BASIC v3.5+)
- Use GET# in a loop using channel (secondary address) 0
- Use GET# in a loop using channel (secondary address) 2 ~ 14
If you just want to display a list of filenames, and then ask the user to type in one of them, option 1 is the easiest (hopefully the user will know they can press SCROLL LOCK on the C128 to pause the listing if it is very long).
Options 2 and 3 give you more control, but they are slower... GET# in BASIC is *much* slower than INPUT#... and INPUT# can not be used (or if it can, I don't know how).
Option 2 is probably the best (if Option 1 is not suitable). So this method returns a directory just like the classic LOAD"$",8 command. The way I do it is to DIM a few (3 or 5) arrays, and then use GET# to read them... below is a real example... But first, some definitions: - N$() holds the filename
- FB() holds the (file size) number of Blocks (you may omit this, but most users find it useful)
- TY() [or TY$()] holds the filetype (you may omit this, but most users find it useful)
- FT() Sholds the starting track (recommended you may omit this)
- FS() holds the starting sector (recommended you may omit this)
Also my sample program assumes 1541/71 disk drive which has a maximum of 144 files... this is not true of 1581 or CMD or uIEC... however these rarely have more than 144 files!
0 input "disk unit";u:if u<8 or u>11 then stop 10 dim n$(144),fb(144),ty$(144) 20 open u,u,0,"$" 25 i=0 :rem file index 30 get#u,q$,q$: rem ignore load address 40 do 50 :get#u,q$,q$: rem line-link (ignore) 60 :get#u,q$: s=asc(q$): rem low byte 70 :get#u,q$: s=s+256*asc(q$): rem high byte 75 :fb(i)=s: remember file size 80 :do: get#u,q$: loop until asc(q$)=34 or asc(q$)=0: rem until quote or null 85 :if asc(q$)=0 then exit: rem null 90 :get#u,q$ 100 :do: n$(i)=n$(i)+q$: rem build name 110 ::get#u,q$: rem next char 120 :loop until asc(q$)=34:rem until end quote 130 :get#u,q$ 140 :do while asc(q$) 150 ::ty$(i)=ty$(i)+q$ 160 ::get#u,q$ 170 :loop :rem compile file type 180 :i=i+1: rem one file entry saved 190 loop: rem each file in directory 195 close u 200 rem *display* 210 for n=1 to i-1 220 print fb(n) chr$(9) n$(n) tab(24) ty$(n) 230 next
Note that CHR$(9) is a "physical tab"... the keyword "tab(24)" is a program tab... sorry for any/all confusion...
In particular, line 210 is "FOR N=1 TO I-1"... this is because I-1 includes only real filenames... the last entry (I-0) contains the "BLOCKS FREE"... and I hope you agree that "file name" (really "blocks free") and file type (null) for this final line is *not* real file-info!!
I hope that code will help you... Test.d64 (170.75 KB)
Please note that code above is "Option 2"... the final "Option 3" digs deeper into BAM and Track/Sectors... way too complex for a simple forum post... (but if you persist in asking me, I will reveal what I know)
FINALLY, note that code is pure BASIC... it is slow... the best method (my opinion) is to mix BASIC and ML (fast!)... a real-life example is my Media Player 128, but it will probably confuse more than help you!! (Most of the code deals with audio/video playback, only a few lines deal with disk directory.)
|
|
|
Post by 6502bitrider on Aug 11, 2015 0:23:29 GMT
Thanks ! That was exactly what I as looking for.
|
|
|
Post by hydrophilic on Aug 11, 2015 5:45:05 GMT
Glad to help... I don't know what you are working on, but I hope you share your final result with all of us
|
|