Difference between revisions of "Disk directory reader in BASIC"

From Ninerpedia
Jump to navigation Jump to search
(Theory and explanation of disk directory reader program added)
Line 61: Line 61:
  350 CLOSE #1
  350 CLOSE #1


Revision as of 14:29, 28 May 2016

Catalog file access from Basic - this relates to disks formatted with the original TI hardware and software:

See also: TI Disk format

The Catalog file can be accessed as a read-only file by the Basic user. The file has no name, and is of the INTERNAL, FIXED format type.

The file can be opened by (for example): OPEN #l:"DSK.",lNPUT,INTERNAL,RELATlVE The record length will automatically be defaulted by Basic to the correct value, so this should not be entered. If however the user wants to specify the length, then it must be specified as 38 - all other lengths will result in an error message.

The Catalog file acts as if it is Protected, and as mentioned above, it will only allow INPUT access.

The file is written in the normal Basic INTERNAL format, and each record contains four items: one string and three numerics. There are 128 records in the file, and they are numbered 0 thru 127.

Record 0: This record contains data about the volume for which the catalog file was created. The string gives the name of the disc (up to 10 characters) and the numerical items are as follows:

1. Always 0 (for record 0)
2. Total number of sectors on the disc 
3. Total number of free sectors on the disc 

Records 1 thru 127: These records contain information on the corresponding file in the Catalog. Non existant files will give a null string for the first item, and 0’s (zeros) for the numeric items. Files which exist will give the file name for the string, and the following numeric items:

1. = Filetype (if number is negative, file is protected)
         1= DISPLAY/FIXED datafile
         2= DISPLAY/VARIABLE datafile
         3= INTERNAL/FIXED datafile
         4= INTERNAL/VARIABLE datafile
         5= Memory Image file (Program File) 
2. = Number of AUs allocated to the file
3. = Number of bytes per record (0 for type 5 file)

This TI BASIC program reads the directory of a disk and prints it on the screen. The P flag indicates protection. You can easily expand this program to consider subdirectories; just replace the number input in line 170-200 by a direct string input and open the given path name in line 210.

110 DIM TYP$(5)
120 TYP$(1)="DIS/FIX"
130 TYP$(2)="DIS/VAR"
140 TYP$(3)="INT/FIX"
150 TYP$(4)="INT/VAR"
160 TYP$(5)="PROGRAM"
180 A=INT(A)
190 IF A<1 THEN 170
200 IF A>3 THEN 170
220 INPUT #1:A$,J,J,K
230 PRINT "DSK";STR$(A);" -DISK NAME= ";A$:"FREE= ";K;"USED= ";J-K
240 PRINT:"FILE NAME  SIZE      TYPE  P":"__________ ______ ________ _"
250 FOR LOOP=1 TO 127
260 INPUT #1:A$,A,J,K
270 IF LEN(A$)=0 THEN 350
280 PRINT:A$;TAB(12);J;TAB(19);TYP$(ABS(A));
290 IF ABS(A)=5 THEN 320
300 B$=" "&STR$(K)
310 PRINT SEG$(B$,LEN(B$)-2,3);
320 IF A>0 THEN 340
330 PRINT TAB(28);"P";
350 CLOSE #1