![]() Instead of copying blocks of array entries back and forth, I kept each directory entry as a string and simply edited them or swapped references around as needed. These were 30-byte data structures that my exchange-directory-entries routine would be copying back and forth as blocks. That leaves the contents of the directory entries themselves. In the extreme this could result in me doing seventeen times less work. At the end of the program, I would only need to write out those sectors that I actually changed. I then created a parallel array D% to hold “dirty bits”-these all started as zeroes and got a 1 written to them if I ever altered anything in that relevant sector. I created an array SN% that stored the order of tracks to write back and a variable NS for the actual number of sectors we read. These are arranged as a singly linked list. The alterations were pretty drastic.įirst, instead of reading and writing every single sector in track 18 (where the directories and allocation maps were stored), I would only read entries in the directory listing itself. I then set about trying to implement the core operations more efficiently, which in turn meant changing the data structures. Neither of these options appealed to me much. If I wanted to get decent performance out, I’d need to write it in machine code, or create a completely external tool to handle it. However, it was impossibly slow exchanging directory entries involved multiple loops that would copy values around, each executing dozens of times. This worked, and it was relatively simple to implement, working much like our sector-dumper program from last time did. One array dimension was the disk blocks, and the other was the bytes within them. My first draft stored the directory blocks in a two-dimensional array of integers. I would also add a “move slot A to slot B” command that performed repeated exchanges, to simplify moving gaps in the directory to the end of the list. ![]() The DOS provides a special “validate” command that does the directory structure scan and block allocation reconciliation. To do reordering and file type manipulation, I would load all the disk blocks that hold the directory into memory, edit them in place, and then write them all back out at the end. The basic implementation strategy falls out of the considerations above. And delimiter files can be created from any other file by setting their file type to the special delimiter type. Hiding files is accomplished by changing the file type to “not a file” and then not performing the scan, leaving its blocks protected and inaccessible. Deletion and undeletion involve changing the file type to or from “not a file” and then performing the scan for the block structure. Any permutation can be built out of an exchange primitive. This gives us all the operations I want to perform. Optionally scan the directory structure and adjust the block allocation map to match it.Alter the file type of a file in the directory listing.Exchange two entries in the directory listing.Now, as it turns out, that whole list can be boiled down to three operations: I didn’t need a DOS shell or directory commander-I needed a program that would let me do things to the directory structure that the DOS didn’t provide as commands. Create unloadable delimiter files that did exist in the directory listing, as dividers or headings.ĭeletion and renaming were easily managed with ordinary disk commands, so I wasn’t as interested in those.Hide files so that they existed on the disk but didn’t show up in directory listings.That’s super-annoying so I wanted to be able to move those gaps down to the end of the list. That means that if you’ve deleted files, your newly created files appear seemingly randomly in the middle of the listing, instead of at the end. You see, instead of storing directory entries as a linked list, CBM DOS stored as an array and when a file is created the first “empty” entry is used. The ability to reorder directory entries, including entries that didn’t refer to any files.When I was organizing some of my projects and other programs into disk images, I kept running into a host of minor irritations endemic to disk work on the C64. It should serve to demonstrate the core principles. I don’t work in BASIC much, but the largest program I’ve written that’s pure BASIC is a directory-editing program for disk images, weighing in at about 120 lines of code. Now that we’ve worked through the basic principles, let’s go through a worked example.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |