Close

Directory Stuff

A project log for OSI SD Card Operating System (OSISDOS)

Ohio Scientific / UK101 SD Card based Operating System under Multicomp FPGA Computer

land-boardscomland-boards.com 05/10/2022 at 13:330 Comments

I put a bunch of files on the SD card so the directory spans across multiple blocks.

It might be fun to have a directory listing. The front of the first directory block has:

000 42 20 00 49 00 6E 00 66 00 6F 00 0F 00 72 72 00  B .I.n.f.o...rr.
010 6D 00 61 00 74 00 69 00 6F 00 00 00 6E 00 00 00  m.a.t.i.o...n...
020 01 53 00 79 00 73 00 74 00 65 00 0F 00 72 6D 00  .S.y.s.t.e...rm.
030 20 00 56 00 6F 00 6C 00 75 00 00 00 6D 00 65 00   .V.o.l.u...m.e.
040 53 59 53 54 45 4D 7E 31 20 20 20 16 00 99 98 8C  SYSTEM~1   .....
050 A9 54 A9 54 00 00 99 8C A9 54 03 00 00 00 00 00  .T.T.....T......

060 41 48 00 6F 00 63 00 6B 00 65 00 0F 00 69 79 00  AH.o.c.k.e...iy.
070 2E 00 62 00 61 00 73 00 00 00 00 00 FF FF FF FF  ..b.a.s.........
080 48 4F 43 4B 45 59 20 20 42 41 53 20 00 23 BD 8C  HOCKEY  BAS .#..
090 A9 54 A9 54 00 00 F5 91 4D 54 05 00 B9 20 00 00  .T.T....MT... ..

0A0 41 48 00 6F 00 72 00 73 00 65 00 0F 00 63 52 00  AH.o.r.s.e...cR.
0B0 61 00 63 00 65 00 2E 00 62 00 00 00 61 00 73 00  a.c.e...b...a.s.

I'm going to ignore the stuff from 0x000-0x04F since it looks like volume stuff.

Directory Entries

The Microsoft Extensible Firmware Initiative FAT32 File System Specification provides additional information on the fields in the directory. 

Looking a 0x060-0x09F looks like a single file's directory entry using 64 bytes. The first part from 0x060 to 0x07F looks like the file name with each character separated by a NULL character. The byte at 0x060 has looks different from the previous values since it has a value of 0x41. The 8.3 plain text file name is at 0x080-0x0x87. Spaces fill out shorter file The extension is at 0x088-0x8A.

It should be easy to print out the directory. Let's give it a shot!

The plain text starts at offset 0x080. Adding a BASIC function to print a single file name. The block is in the MA() array. DF is the offset to the first file directory field.

 4400 REM PRINT DIR ENTRY
 4410 FOR I=0 TO 7
 4420 IF MA(DF+I)<>32 THEN PRINT CHR$(MA(DF+I));
 4430 NEXT I
 4440 PRINT ".";
 4450 FOR I=8 TO 10
 4460 IF MA(DF+I)<> 32 THEN PRINT CHR$(MA(DF+I));
 4470 NEXT I
 4480 PRINT
 4490 RETURN

The BASIC calling function to work through each directory entry is:

 360 DF=128:REM DIR OFFSET
 370 GOSUB 4400
 380 DF=DF+64
 390 IF DF<512 GOTO 370

The result is:

HORSER~1.BAS
HURKLE.BAS
KINEMA.BAS
KING.BAS
laby.r

The last entry has issues that need to be figured out. The raw data is:

160 41 4B 00 69 00 6E 00 67 00 2E 00 0F 00 DD 62 00  AK.i.n.g......b.
170 61 00 73 00 00 00 FF FF FF FF 00 00 FF FF FF FF  a.s.............
180 4B 49 4E 47 20 20 20 20 42 41 53 20 00 58 BD 8C  KING    BAS .X..
190 A9 54 A9 54 00 00 F7 54 F1 52 09 00 F6 22 00 00  .T.T...T.R..."..

1A0 42 69 00 63 00 00 00 FF FF FF FF 0F 00 A4 FF FF  Bi.c............
1B0 FF FF FF FF FF FF FF FF FF FF 00 00 FF FF FF FF  ................

1C0 01 6C 00 61 00 62 00 79 00 72 00 0F 00 A4 69 00  .l.a.b.y.r....i.
1D0 6E 00 74 00 68 00 2E 00 62 00 00 00 61 00 73 00  n.t.h...b...a.s.
1E0 4C 41 42 59 52 49 7E 31 42 41 53 20 00 5E BD 8C  LABYRI~1BAS .^..
1F0 A9 54 A9 54 00 00 F8 54 F1 52 0A 00 7C 13 00 00  .T.T...T.R..|...

The byte offset at 0x1A0 does not have 0x41. This entry also has a different size. It does not have 64 bytes so the final file name was not caught. That's likely because the file name is: labyrinth.basic . Let's ignore long file names for now.

For each directory entry, the fields are

In the FDISK.EXE example above:

For KING.BAS:

180 4B 49 4E 47 20 20 20 20 42 41 53 20 00 58 BD 8C  KING    BAS .X..
190 A9 54 A9 54 00 00 F7 54 F1 52 09 00 F6 22 00 00  .T.T...T.R..."..

The file size matches the File Properties:

Reading in the file

Added BASIC code to read in first LBA of KING.BAS file.

Need the BPB_SecPerClus value from the MBR:

13      BPB_SecPerClus        Number of sectors per cluster (1)        
                              Must be one of 1, 2, 4, 8, 16, 32, 64, 128.
                              A cluster should have at most 32768 bytes.
                              In rare cases 65536 is OK.
                              <0x40> = 642 sectors per clusters

BASIC code added:

 4200 REM PRINT DIR SECTOR VALUES
 4203 SC=MA(13):REM SECTORS PER CLUSTER
 4205 PRINT "SECTORS PER CLUSTER";:PRINT SC
 4210 B0=MA(14):B1=MA(15)

Returns:

SECTORS PER CLUSTER 64

KING.BAS LBA has Starting cluster value of 0x0009.

Call read block code with:

 400 FF=DS+((9-2)*SC):REM MANUALLY ADDING FILE OFFSET
 410 L0=FF AND 255:L1=FF/256:L2=0:L3=0
 420 GOSUB 3800:REM POKE LBA VALS
 430 GOSUB 2200:REM CHECK CARD INIT STATUS
 440 GOSUB 2400:REM READ IN BLOCK
 450 GOSUB 3000:REM DUMP ARRAY

Hard coded line 400 "9" value from KING.BAS file offset 

Result matches the file:

READING LBA   25216
000 31 20 50 52 49 4E 54 20 54 41 42 28 33 34 29 3B  1 PRINT TAB(34);
010 22 4B 49 4E 47 22 0D 0A 32 20 50 52 49 4E 54 20  "KING"..2 PRINT
020 54 41 42 28 31 35 29 3B 22 43 52 45 41 54 49 56  TAB(15);"CREATIV
030 45 20 43 4F 4D 50 55 54 49 4E 47 20 20 4D 4F 52  E COMPUTING  MOR
040 52 49 53 54 4F 57 4E 2C 20 4E 45 57 20 4A 45 52  RISTOWN, NEW JER
050 53 45 59 22 0D 0A 33 20 50 52 49 4E 54 3A 50 52  SEY"..3 PRINT:PR
060 49 4E 54 3A 50 52 49 4E 54 0D 0A 34 20 50 52 49  INT:PRINT..4 PRI
070 4E 54 20 22 44 4F 20 59 4F 55 20 57 41 4E 54 20  NT "DO YOU WANT
080 49 4E 53 54 52 55 43 54 49 4F 4E 53 22 3B 0D 0A  INSTRUCTIONS";..
090 35 20 49 4E 50 55 54 20 5A 24 0D 0A 36 20 4E 35  5 INPUT Z$..6 N5
0A0 3D 38 0D 0A 31 30 20 49 46 20 4C 45 46 54 24 28  =8..10 IF LEFT$(
0B0 5A 24 2C 31 29 3D 22 4E 22 20 54 48 45 4E 20 34  Z$,1)="N" THEN 4
0C0 37 0D 0A 31 31 20 49 46 20 5A 24 3D 22 41 47 41  7..11 IF Z$="AGA
0D0 49 4E 22 20 54 48 45 4E 20 31 39 36 30 0D 0A 31  IN" THEN 1960..1
0E0 32 20 50 52 49 4E 54 3A 50 52 49 4E 54 3A 50 52  2 PRINT:PRINT:PR
0F0 49 4E 54 0D 0A 32 30 20 50 52 49 4E 54 20 22 43  INT..20 PRINT "C
100 4F 4E 47 52 41 54 55 4C 41 54 49 4F 4E 53 21 20  ONGRATULATIONS!
110 59 4F 55 27 56 45 20 4A 55 53 54 20 42 45 45 4E  YOU'VE JUST BEEN
120 20 45 4C 45 43 54 45 44 20 50 52 45 4D 49 45 52   ELECTED PREMIER
130 20 4F 46 20 53 45 54 41 54 53 22 0D 0A 32 32 20   OF SETATS"..22
140 50 52 49 4E 54 20 22 44 45 54 49 4E 55 2C 20 41  PRINT "DETINU, A
150 20 53 4D 41 4C 4C 20 43 4F 4D 4D 55 4E 49 53 54   SMALL COMMUNIST
160 20 49 53 4C 41 4E 44 20 33 30 20 42 59 20 37 30   ISLAND 30 BY 70
170 20 4D 49 4C 45 53 20 4C 4F 4E 47 2E 20 59 4F 55   MILES LONG. YOU
180 52 22 0D 0A 32 34 20 50 52 49 4E 54 20 22 4A 4F  R"..24 PRINT "JO
190 42 20 49 53 20 54 4F 20 44 45 43 49 44 45 20 55  B IS TO DECIDE U
1A0 50 4F 4E 20 54 48 45 20 43 4F 4E 54 52 59 27 53  PON THE CONTRY'S
1B0 20 42 55 44 47 45 54 20 41 4E 44 20 44 49 53 54   BUDGET AND DIST
1C0 52 49 42 55 54 45 22 0D 0A 32 36 20 50 52 49 4E  RIBUTE"..26 PRIN
1D0 54 20 22 4D 4F 4E 45 59 20 54 4F 20 59 4F 55 52  T "MONEY TO YOUR
1E0 20 43 4F 55 4E 54 52 59 4D 45 4E 20 46 52 4F 4D   COUNTRYMEN FROM
1F0 20 54 48 45 20 43 4F 4D 4D 55 4E 41 4C 20 54 52   THE COMMUNAL TR

Some Simplifying Assumptions

Here's a few:

Next Steps

Discussions