Make sense of the BBC disk operating system with Kenn Garroch's program.
Drive Doktor
Make sense of the BBC disk operating system with Kenn Garroch's program
Disk operating systems are usually meant to be transparent to the user but, unfortunately, there are times when it is helpful, if not vital, that the disk be accessed directly.
The BBC's DFS and OS allow this direct reading to the done through the OSWORD (&FFF1) &7F call. But this is complicated to do directly from the keyboard. Fortunately, the BBC's Basic procedures and functions come to our aid. The following program is based around PROCREDISK(T,S,RW) which allows a section of the disk to be read or written for inspection and alteration.
On running the program, the main menu is displayed. From here a number of options are available. If, any any time, you want to return to this menu, just use Escape. The only exits from the program are option '0' and BREAK. Selecting option '1' allows any sector of the disk to be read and displayed on the screen.
The format of the display resembles that used with *DUMP except that the left hand column of figures display the track, sector, and position in the sector. Due to limitations in the screen size, only one half of the sector can be displayed at any one time - the first 128 bytes, or the second.
Option '2' allows the contents of the disk to be directly altered. PROCEDIT provides two methods to perform this: first altering the HEX numbers, and secondly the ASCII characters these numbers represent. Once the sector is displayed the editing cursor can be moved around the screen with the cursor keys.
To make any changes simply retype the data you want. To finish editing, press the CTRL and @ keys simultaneously. You are then asked which section you want to write to the disk - the numbers or ASCII. Which one you select depends on which section of the screen you changed.
After this, the program will read the screen and ask you if you want to write to the disk. Pressing 'Y' causes the program to ask you if you are positive. All this palaver is necessary to make sure that crazy disasters are not too easily perpetrated.
Another option on the main menu is '3', run disassembler. This runs an external disassembler program. If you have one of your own, it can be hooked into the program with PROCDISS at line 1430. The catalogue option simply performs a *. to display the current directory of the disk. Similarly, Information does *INFO *.* to display the load, storage, execution, and length information on each file.
The final menu option reads the disk sector by sector starting at 00. This can be useful if you need to do a visual search for a particular piece of data. It does, however, take some time.
To use the program, it helps if the layout of the disk is known. This is all based around the directory, track 0, sectors 0 and 1.
Using the read option and selecting track zero, sector zero, low, gives us our first look at the directory. The first eight bytes contain the first eight characters in the title (set by *TITLE). Following this, each file on the disk is assigned seven bytes for its name and one for its directory. If you then press 'M' you will be able to reset the track, sector, and section.
Entering 0<CR>,0<CR>,H<CRB>,reveals the high part of the sector. The contents of this are similar to those of the lower half except that there's no title included. A quick calculation reveals why Acorn DFS disks are limited to a maximum of 31 files. A sector contains 256 bytes, each file name needs eight bytes and the title needs eight (on the first sector) - hence 31 * 8 = 284 plus 8, and the sector is full.
Hitting 'M' again and selecting 0, 1, L displays the first part of sector one track zero. The first four bytes are the rest of the 12 character disk title. The next byte is the number of times the disk has been written to and the one following this is the number of files on the disk times eight.
The last two bytes contain the number of tracks on the disk times 100 and the current *OPT 4 selection. So, for a 40 track disk that has been *OPT 4,3-ed, these will read 31 90 since &190 = 400 and the option is 3.
To make sense of the rest of the data given, it helps to notice that it's in a pattern that recurs every eight bytes. If you press Escape and hit option 5, you will see where the pattern comes from. It is the load, execution, length, and disk position for each disk file. The numbers are stored in low byte, high byte format for ease of use by the 6502 e.g. 00 19 is &1900 (6400 decimal).
The first two bytes are the load address for the file. For most Basic files, this will be 00 19 since this is the normal setting of PAGE when a program is saved. For machine code files, this would be the address specified in the *SAVE command as the start location. For data files, this is normally 00 00.
The next two bytes contain the execution address. For Basic I programs, this is 1F 80 but for Basic II it has been changed to 23 80. It does not normally matter which of these is used since the operating system seems to be able to work out the correct address.
(N.B. To find out which Basic you have press Break and type REPORT (RETURN).)
For machine code files these two locations contain the execution address for that particular program, as specified in *SAVE SSSS+LLLL EEEE and are used with *RUN. Again, data files will normally have these two bytes set to zero.
The third pair of bytes is the length of the file and is the same format for all file types.
The final pair contains the position of the file on the disk and whether the file is a Basic program. The position is specified as an absolute number of sectors from the beginning, track 0 sector 0, to track 39 (79) sector 9. Since each track has ten sectors, dividing the position number by ten tells you which track it is on.
The position bytes are unusual because they are the right way round. A position of &15E is placed on the disk as 01 5E and not 5E 01. If the file is a Basic program, the system adds CC to the high byte of the position. So a Basic file residing at &113 is placed in the directory as CD 13.
Stating the obvious, there are only 32 sets of eight bytes in sector 1, that relate to the files. These are in the same file order as sector 0, so relating them is easy.
The files on the Acorn format disks are placed one after the other continuously. This has both an advantage and a disadvantage. The disadvantage is that disk space is used inefficiently and "Can't extend" errors can quite frequently occur. The advantage is that one you have found the start of a file it is simply a matter of stepping through the sectors to find the rest of it. This means recovering a file from an uncompacted disk is straightforward. Even adding a file is simple.
The only things that need to be altered are the number of files on the disk, a new name and set of information.
Additional Notes
Most of the procedures and functions used in this program can be used for other things besides reading the disk. FNHX, FNCHAR and PROCDUMP are good examples. They may need to be altered slightly but the basic algorithms are complete.
For users with more than one disk drive, the parameter block used in PROCRWDISK must be altered. The first byte contains the drive number to be written or read. Altering line 740 to ?PARAM=1 accesses drive 1. Multidrive users may like to include drive selection on the main menu.
If PROCRWDISK is unable to read the disk for any reason, the Beeb beeps and the program continues with a RW error. If this happens try again or admit that the disk has an unrecoverable error.