Vice vs. sd2iec directory

Modding and Technical Issues

Moderator: Moderators

Post Reply
User avatar
vicist
Vic 20 Afficionado
Posts: 352
Joined: Tue Oct 09, 2012 5:26 am
Location: Sheffield, UK

Vice vs. sd2iec directory

Post by vicist »

Not sure if this belongs here or 'Programming'.

I recently needed to read the files from a disk and display just the names.
I used this:

Code: Select all

10 open2,8,0,"$"
20 get#2,a$,b$
30 if st<>0 then close2:end
40 get#2,a$,b$
50 if a$="" and b$="" then close2:end
60 get#2,a$
70 if a$<>"" then 90
80 goto 30
90 if a$=chr$(34) then b=b+1:goto 60
100 if b=2 then b=0:print
110 if b=1 then print a$;
120 goto 60
Lines 90-120 strip away the quotation marks and display the file names.

While this works fine in Vice (2.4), the code fails miserably when run on a real Vic.
Somehow, the first set of quotes - the ones before the disk name - are missing, so the code picks up the second quotes as the first ones and the display is all wrong.

Change these lines and run in Vice to see the effect you get on a real Vic.

Code: Select all

100 if b=3 then b=1:print
110 if b=2 then print a$;
Not just a problem with the sd2iec though. This also happens on a real 1541 disk drive.

I also notice that when listing a directory in Vice (load"$",8), the first character printed is a '0' before the disk name. On sd2iec/1541 it is a '1'.

Can someone please explain what is going on?
User avatar
Mike
Herr VC
Posts: 4845
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Vice vs. sd2iec directory

Post by Mike »

vicist wrote:Not sure if this belongs here or 'Programming'.
Most probably, yes.

Between the drive number and device name and ID in the first line, and the block count and file names in the following lines, there are a variant number of spaces to pad out different digit counts. You can't rely on a fixed position of the file name string within a directory line. A more robust method is to scan for the quotes themselves.

You might want to compare your routine against another implementation of a directory scan that I used to copy an entire floppy with a file based method:

Code: Select all

10 POKE55,195:POKE56,28:CLR:GOTO19
11 GET#4,A$,B$,C$,D$:F=1
12 GET#4,A$:IFA$=""THENRETURN
13 IFA$<>CHR$(34)THEN12
14 N$="":T$="":F=0
15 GET#4,A$:IFA$<>CHR$(34)THENN$=N$+A$:GOTO15
16 GET#4,A$:IFA$=""THENRETURN
17 IFA$>="A"ANDA$<="Z"THENT$=T$+A$
18 GOTO16
19 FORT=0TO60:READA:POKE7363+T,A:NEXT:POKE5,0:POKE6,29
20 INPUT"SRC DEV.";SD:INPUT"DST DEV.";DD
21 OPEN4,SD,0,"$":GET#4,A$,B$:GOSUB11
22 GOSUB11:ONFGOTO25:IFNOT(T$="PRG"ORT$="SEQ"ORT$="USR")THEN22
23 F$=N$+","+LEFT$(T$,1):PRINTF$:OPEN2,SD,2,F$+",R"
24 OPEN3,DD,3,F$+",W":SYS7363:CLOSE2:CLOSE3:GOTO22
25 CLOSE4:POKE55,PEEK(643):POKE56,PEEK(644):CLR:END
26 DATA 162,2,32,198,255,160,0,132,3,32,207,255,72,165,144,201,1
27 DATA 104,164,3,145,5,200,132,3,176,2,208,236,8,32,204,255,162
28 DATA 3,32,201,255,160,0,177,5,132,4,32,210,255,164,4,200,196
29 DATA 3,208,242,32,204,255,40,144,196,96
(download)

See lines 11 to 18. Line 21 reads in the fake load address and then throws away the header line before proceeding with all file names.
I also notice that when listing a directory in Vice (load"$",8), the first character printed is a '0' before the disk name. On sd2iec/1541 it is a '1'.
As I wrote above, this is the drive number you're reading. If you get a '1' on a 1541, *that* would be rather strange, as the 1541 is a single drive and is supposed to only return 0 there. A 8250 dual drive for example can return either 0 or 1, depending which drive is being read (and you can explicitly ask for the directory of a certain drive by loading "$0" or "$1").
User avatar
vicist
Vic 20 Afficionado
Posts: 352
Joined: Tue Oct 09, 2012 5:26 am
Location: Sheffield, UK

Post by vicist »

Thanks for the info on the directory structure Mike. I really must read more technical offerings on the hardware before trying to program it to do anything useful.

I thought that I was testing to see if the character was a quote in line 90!
This method works as expected in Vice but not on sd2iec.

Just wondered why? :roll:
User avatar
Mike
Herr VC
Posts: 4845
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

O.K., after some more intensive reading I grokked your program: you're employing some kind of state machine with B=1 to indicate "within quotes".

Actually, your program fails to recognize the line number field of each line. Just add the following line:

Code: Select all

55 GET#2,A$,B$
...which reads the line number that immediately follows the link pointer. Should one byte of the line number contain 0 or 34, your original version would not cope correctly with the situation.
User avatar
vicist
Vic 20 Afficionado
Posts: 352
Joined: Tue Oct 09, 2012 5:26 am
Location: Sheffield, UK

Post by vicist »

Thanks Mike :)

Tried it on my Vic and 'voila', it works!
I didn't realise that some previous data could cripple my search for a specific character. :roll:

My solution was to 'fast-forward' past the disk name and id, then begin my search from there, thus jumping over the problem area as I only needed to read the filenames.

As always, your understanding of 'all things Vic' never ceases to amaze me and is greatly appreciated.
Post Reply