Easy Apple Disk Space Messages
Beirne L. Konarski, Kent, OH
As diskettes fill up, it is useful to know how much room is left on them. Two methods exist for finding this number. One is to get a calculator or pencil and paper and add the figures. This seems pointless, since the computer is supposed to do those tasks. The alternative is to run the FID program from the system master. This is a nuisance, though, because you often change diskettes.
Since many people incorporate a CATALOG command into their greeting program, this would be the most useful place for a sector-counting subroutine. The DOS Manual contains two sections which help to solve this problem. The first is the RWTS (Read or Write a Track and Sector) machine language program (p. 94). The second is the listing of sector allocation (p. 129). The RWTS subroutine can be used to read the sectors containing the catalog and tally the amount of sectors used.
The diskette directory is located in track $11. It contains 15 sectors of catalog information, each holding the names and sizes of seven programs. The program reads one sector at a time beginning with sector $F and places it into the memory range beginning at $2000. The sector is then checked before the next one is read from the disk.
The seven program titles are checked for two things. The first is to see if the program is current. When a program is deleted, its catalog entry is not erased, but instead the first byte of the listing becomes $FF. If the program is current, then the bit containing the length is added to the running total. The Least Significant Byte of the total is stored in location $6074, or 24692. If there is a carry, it is placed in $6075. When all seven listings have been checked, the next sector is loaded, and the process continues until all fifteen sectors are read. The computer then returns to BASIC.
The rest of the BASIC program PEEKs the two locations containing the sum of the sectors used. The Most Significant Byte is multiplied by 256 and added to the LSB. This total is displayed and then subtracted from 496 to give the figure for the space remaining.
The program reads the DATA lines and enters the numbers beginning at $6000. It displays the CATALOG, then gives the results of the count. It can be substituted for your HELLO program, with your own personal touches like name and date placed before or after line 20, or after line 110.
10 D$ = CHR$ (4) 20 PRINT D$; " CATALOG " 30 FOR K = 24576 TO 24694 40 READ A 50 POKE K, A 60 NEXT 70 CALL 24576 80 X = PEEK (24692) : Y = PEEK (24693) 90 Z = X + 256 * Y 100 PRINT : PRINT "SECTORS USED: " ; Z 110 PRINT "SECTORS REMAINING: " ; 496 - Z 120 END 130 DATA 169, 96, 160, 76, 32, 217, 3, 173, 11, 32 140 DATA 201, 255, 240, 3, 32, 99, 96, 23, 8, 118, 96 150 DATA 173, 118, 96, 201, 7, 208, 28, 1, 69, 0, 141 160 DATA 118, 96, 169, 44, 141, 104, 96, 169, 11, 141 170 DATA 8, 96, 173, 2, 32, 201, 0, 240, 25, 141 180 DATA 81, 96, 76, 0, 96, 173, 104, 96, 105, 35 190 DATA 141, 104, 96, 173, 8, 96, 105, 35, 141, 8 200 DATA 96, 76, 7, 96, 96, 0, 1, 96, 1, 0 210 DATA 17, 15, 94, 96, 0, 32, 0, 0, 1, 0 220 DATA 0, 96, 1, 0, 0, 1, 239, 216, 0, 24 230 DATA 173, 116, 96, 109, 44, 32, 141, 116, 96, 144 240 DATA 3, 238, 117, 96, 96, 0, 0, 0, 0