Classic Computer Magazine Archive CREATIVE COMPUTING VOL. 11, NO. 3 / MARCH 1985 / PAGE 150

Commodore's port; getting acquainted with DOS. Robert Alonso; John J. Anderson.

You may have spent some time exploring your C64, familiarizing yourself with some of the things it can do. But have you ever explored your disk drive? I've done some snooping around in mine and learned quite a bit about directories, sequential files, and the error channel. In the next couple of columns, we will take a look around the 1541 drive, and see how it allocates, then uses, disk space. DOS

This month's application program is designed to count the free blocks on any disk. Listings 1 and 2 both produce the same object code. If you like to see results, type in Listing 2 and run it. It will POKE a machine language program into memory starting at 49152. When you see the READY prompt on the screen type SYS 49152, and the program will count the free blocks directly from the Block Allocation Map (BAM) on the disk.

If, however, you want to learn a little more machine language or understand how the BAM is organized on a disk, then read on.

The BAM is a mystery to most 1541 users because most of us never have to bother with it. When you load a directory, the 1541 DOS automatically counts the free blocks and tells you the results at the end of the directory listing. However, it can be useful to know how the BAM works and to have a utility program that will give you just the blocks free count. You may, for example, need a disk on which to save a very long program. Obviously, it would not be wise to load the directory to find out if the program fit on a given disk. With the programs presented here, this problem is eliminated. Just keep the machine code at 49152 where it will not be disturbed and whenever you need it, just SYS to it. It will not corrupt your Basic program at all.

One way to access the BAM is to open the directory like a file. This is done in Listing 1 in lines 265 through 315. The same technique can be used to open any file from machine language. Once the directory is opened, you define the file number, in this instance file number 2, as the input channel. This means that every time the GETIN routine of the kernal is called a byte will be input from file number 2 and placed in the accumulator. The following Basic code does the same thing: 10 OPEN 2, 8, 2, "$" 20 GET#2 , A$

The GETIN routine is first called in lines 400 and 405 where it is used to dispose of the first two bytes of the directory file. These two bytes are an ASCII letter A, which indicates that the disk has been formatted on a 1541 or 4040 disk drive, and an unused byte.

The next 140 bytes, all part of the BAM, are arranged in a peculiar, but ingenious, way. Each track takes up four bytes of the BAM. The first byte always holds the total bytes free for the particular track, and the other three bytes are coded so that each individual bit stands for a sector.

If the bit is set (binary 1), then the track is free; if it is clear (binary 0), it is allocated. It is very easy to count the number of free blocks by adding together all the first bytes. This is exactly what Listing 1 does.

Take a look at lines 415 through 435. The first byte is added to a temporary memory location BLOCK, and the subsequent three bytes are discarded. The process continues in a loop until track 18 is reached. Because track 18 contains the BAM and the directory, all the free blocks on track 18 are off limits and should not be counted. Listing 1 takes care of this in lines 450 through 460.

The loop then continues until it reaches the end of track 35. The total is then printed on the screen, and the BLOCKS AVAILABLE message printed after it. Lines 545 through 595 print out a decimal number and a message string.

Lines 615 through 630 of Listing 1 take care of the housekeeping chores. The input and output channels are restored to their default conditions. File number 2 is closed. And program control is returned to the calling routine. If you SYS to the routine from Basic, control is returned to you on the screen, and the READY prompt is printed.

That's all for now. I'll see you next month with some more all machine language routines. Amiga Will Run Turbo Pascal

Borland International, developer of the very popular language Turbo Pascal, has announced that Turbo Pascal has been chosen by Commodore as the exclusive Pascal language for the Amiga computer. Turbo Pascal has already sold over 200,000 copies in its IBM, Apple, TI, HP, DEC, Wang and NCR implementations.

Borland president Philippe Kahn told Creative Computing he expects that "The Amiga, with its sophisticated user interface, will provide strong competition for Apple Computer's Macintosh and apple II microcomputers. We are committed to deliver Turbo Pascal, fully implemented, on Commodore's long-awaited Amiga."

David Morse, head of the Amiga project, stated, "We evaluated Turbo Pascal closely, and found that it complements in software some of the best features the Amiga can provide in hardware--including speed and functionality."

As an added bonus, Amiga users who purchase Turbo Pascal will have the power to transfer programs developed on the Amiga to an IBM PC, XT, AT, or PCjr, with the Turbo cross-assembler.

Industry analysts predict that the new Amiga, Commodore's first true high-performance computer, will position Commodore as a serious contender in the small business market, where such heavyweight as IBM and Hewlett-Packard are already firmly entrenched.