Disk Master

by: Barry Kolbe & Bryan Schappel

Publication date: July 1989

Have you ever had the urge to snoop around your disks? To see how files are stored on a disk? Or, try to cheat at your favorite text adventure? Did you ever want to disassemble a few disk sectors or a file that you could not load into memory? If you would like to do these things then Disk Master is for you!

Disk Master (DM) is actually two programs in one. The editor allows you to examine and edit any sector on a single-density or 1050 double-density disk. The disassembler allows you to disassemble sectors or files (with or without labels) and send the output to the screen, printer or a disk.

The Disk Editor
As you will see, the screen is divided into two sections: a section that is filled with numbers and a section filled with characters. This area displays all the data in one disk sector.

There are 128 bytes in each sector - numbered from 0 to 127 (00-7F in hexadecimal). The left margin and the top of the screen have guide numbers to cross-reference the data. When you begin, the buffer that holds sector data is full of 0’s, which you will see as hexadecimal 00’s. To the right of the data is an 8 by 16 array of hearts. These are the ATASCII equivalents of those 0’s. Below is information about the sector:

SEC: This is the current sector number displayed in hexadecimal.

FIL: This is the DOS 2.x file number. The file number ranges from 0-3F, for a maximum of 64 files per disk.

LNK: This is the DOS sector link. This number is the pointer to the next data sector in a file. This number is invalid on a boot disk (such as a game) and the directory sectors.

BYT: This number tells DOS how many bytes of actual data are contained in the sector. This number typically ranges between 0 and 125.

SRC: This is the source drive that DM uses to read all data from while in the editor.

DST: This is the destination drive that DM will write all information to. Note: The source and destination may be different; this allows users with multiple-drive systems to read from one disk and write to another.

INP: This tells you how your input will be interpreted. If the flag is set to "H", all input will be interpreted as hex strings; otherwise the input will be interpreted as character strings.

What is a hex string? Well, a hex string is simply input that is made up of hexadecimal digits that represent ATASCII characters. For example, the hex string "414243" is the same as the character string "ABC."

So, why do we use hex strings? Because, a hex string allows you to enter characters that you normally can't, like the EOL (ATASCII 155, $9B) and the delete keys. You will find a use for hex strings when you want to search for data on a disk.

A note on hex string interpretation: As you may have noticed, it takes two hex digits to represent one character, so what happens if you enter an odd number of digits? Well, an extra 0 is added to the beginning of your input, so, "1FE" becomes "01FE." We felt that this was the natural way to interpret the hex string.

DNS: This shows you which density the program is operating in. A 1 indicates single density, and a 2 indicates 1050 double density.
You may activate a built-in help screen by pressing the "?" (use Shift-/). The help screen lists all of the command keys along with their associated function. Here is a brief description of each command.

Read a sector (R): Pressing "R" allows you to enter a sector number for DM to read into its memory buffers. This number may range from 1-2D0 in single density and 1-410 in 1050 double density. Simply press Return to reread the current sector.

Up one sector (+): This will increase the current sector number by 1 and read it into memory. If you are on the last sector of the disk, DM will keep reading it.

Down one sector (-): This reads in the sector before the one you're on. You may not read Sector Zero.

Edit sector (E): The edit routine requires two pieces of information: the starting byte and the new data. At the EDTB prompt, enter the starting byte number of the edit, and at the EDTD prompt, enter the data.

The data will be entered according to the INP flag. Additionally, character strings will be converted to either internal code or ATASCII depending on the setting of the character display mode (see the C command).

Write sector buffer (W): You are asked for the sector number to write the sector to, or you may press Return for the current sector. You are asked if you are sure before the write occurs; pressing Escape or "N" will abort. If you write the buffer to the current sector you may use Undo to restore the buffer and rewrite the buffer back to disk. If you used a different sector number you cannot restore the sector's original contents.

Undo (U): This restores the sector buffer contents to what they were when the sector was first read.

Number Base (N): This allows you to change the number base that is used to display the sector data. The default mode is hexadecimal. Pressing this key toggles between hex and decimal.

Decimal numbers are displayed using only two digits. If the left digit is inversed, then add 200 to the number displayed. If the right digit is inversed, add 100 to the displayed number. If no digits are inversed, then the number on screen is the actual value.

Character Display (C): This toggles the character display array from ATASCII to internal code. The setting of this array is used to interpret your character-string input during searches and edits.

Block fill (B): This command fills the sector buffer with a hex byte, just enter the value and, wham!, the buffer is filled. (Excellent for erasing sectors; just use the value 00.)

Exclusive OR sector contents (J): This will perform a binary EOR on every byte in the sector with a value that you supply. This can be useful when some data has been encrypted in a sector. To recover from an EOR, just perform the EOR again with the same value.

Trace link (T): This will read in the sector pointed to by the LNK field. Use this command to follow a disk file.

New file number (F): This allows you to change the file number on the current sector. You are asked for the new file number; remember that only values 0-3F are allowed. You will receive an Error 181 if the value is out of range.

New sector link (L): This allows you to change the sector link on the current sector. Only values 0-2D0 (single) and 0-410 (double) are allowed. An Error 180 will be given if the new link is out of range.

Density toggle (V): Pressing "V" toggles between single and 1050 density. Having this set incorrectly cannot damage your disks in any way.

Main menu (M): This command just returns you to the main menu allowing you to enter the disassembler or exit to DOS.

Search for data (S): This command searches the current sector for data you enter. Remember that your input will be interpreted according to the INP flag. If the data that you are searching for is found, a "<" is placed on the screen at the beginning of each occurrence. This command only examines the current sector, so if you want to search another sector for the same data, just read in that sector and hit Return at the SRCH prompt. You may also want to clear the screen before doing another search (use Control-Clear to redraw the screen).

Hex to decimal (H): This converts a hexadecimal number to its decimal equivalent. Only values of 0-FFFF are allowed.

Decimal to hex (.): This converts a decimal number to its hex counterpart. Only values of 0-65535 are allowed.

Input mode toggle (I): This command toggles the INP flag between hex string and character-string modes.

Set SRC drive (O): Pressing this key increases the source-drive number. The program supports Drives 1-8.

Set DST drive (D): This command increases the destination drive by 1. You have access to all eight drives here also.

Redraw screen (Control-Clear): This forces DM to redraw the screen from scratch and removes any markers that are left behind from a search.

Print screen (Control-F): Pressing this key will perform a character dump of the screen to any printer. All offensive control characters and the like are removed from the output. Use this to produce a hard copy of a sector's data.

The Escape key may be used at any time to abort any function. The "less than" and "greater than" keys ("<" and ">") are used to change the screen hue and luminance, respectively.

Disassembler
The disassembler converts a binary file to assembly language source code. This code can be viewed on the screen (pressing the space bar pauses the output), dumped to a printer or saved as a disk file. Actually the disk file is in LIST format so it can be loaded into a word processor or entered into an assembler like MAC/65. To enter the resulting file into MAC/65 use: ENTER #D:FILENAME,A.
The ",A" adds line numbers to the source code. The code that is generated always has the same format:

     MNEMONIC OPERAND ADDR B1 B2 B3

An example would be:

     LDA $4503,X ; $3000 BD 03 45

The data on the left is the generated code. The ";" marks the beginning of the comment field. ADDR is the memory location where LDA $4503,X would be assembled. B1, B2 and B3 are the hexadecimal values for the assembly opcode and the operand. When DM encounters data that isn't assembly code it writes it out as ".BYTE $hh." The headers for each segment of a file are displayed as:

     * $3000 ; END $30FE

Disassembly does continue across sector boundaries, but does not cross segments of code. So one segment might end as:

     LDA #$90   ;$4023 A9 90
     .BYTE $20  ;&4025 20
     *=$4026    ;END $4118
     .BYTE $42  ;$4026 42
     .BYTE $3A  ;$4027 ZA
     STA $5E12  ;$4028 80 12 5E
             etc.

The series of bytes - $20, $42 and $3A - quite probably make the instruction JSR $3A42.

To begin disassembly, you must first set several parameters. You are reprompted if you type in an improper value; no error message appears.

All input requires using the Return key to finalize it. Escape aborts at any time.

You must first select the type of the disassembly, file (F) or disk (D). Pick the destination device which can be E (screen), P (printer) or D (disk file). If you choose D you must type in a complete file name as in: Dn:filename.ext.

Even for Drive 1 you must type D1:. The extension, of course, is optional. If the file is not a binary file, an error message will be given. Next choose whether you want labels. The labels are those which most assembly language programmers use. They follow closely those given in the technical manual and/or Compute!'s Mapping the Atari.

If you chose to disassemble files, type in a complete filename as your source file. The program takes control unless you press Escape to abort. If you are sending the code to a disk file or the printer, keep in mind that the output is kept in a large buffer. Consequently, there will be no printing or disk access until the buffer is full or you terminate the operation by pressing Escape. If the code is to be sent to disk, you will be asked to insert a destination disk when the buffer is full. Since the output code will be much larger than the object code, make sure you use a disk that is nearly empty. As you have seen, three bytes of data will become 26 bytes of source code!

If you selected disk disassembly (D), you must specify a source-drive number, density, starting-sector number, and the number of sectors to read. You cannot start at the last sector (2D0 for single and $410 for double density). Start at one less (2CF or $40F) and specify 2 as the number of sectors to disassemble. Then you must select an offset into the first sector (0-7F). For example, a boot sector does not have assembly code in the first six bytes. The real code begins at Byte 6 (bytes are numbered starting at 0!). 6 would be the offset. Specify an origin address (for example $706 for a boot sector). The data does not get put there, the address is just used for reference.

We must digress for a moment to explain the next option. Commercial boot disks generally use $80 bytes per sector, and the sectors are laid out sequentially on the disk. Sectors that are part of a file are not necessarily sequential. Each sector has a link to the next sector in the file. So Sector 123 may point to Sector 150. Therefore, when disassembling boot disks, type in 80 at the BYT/SEC prompt. But if you are disassembling a file or part of a file use 7D.

When disassembling part of a file you can find where the file begins by looking at the directory, sectors $169-$16F. Each entry is 16 bytes long. The first byte is a flag byte concerning the condition of the file, whether it is locked, deleted, etc. The next two bytes give the number of sectors in the file, while Bytes 3 and 4 have the starting-sector number. (The number of sectors and starting-sector number are stored in LO/HI format, so to calculate the starting sector take Byte 3 plus 256 times Byte 4.) With the editor, read the starting sector and use the trace function to follow the file around the disk. When you have found what you want, switch to the dissembler.

Warning!
If you are sending output to disk, you will need a separate diskette for this output. This is particularly true on any boot disk. Writing data to that disk would probably destroy programs stored there. Please put write protect tabs on the source disk, and always use a separate disk for output.

A final note: The input routine is very smart. If you are asked to supply a number, only legal hexadecimal digits are allowed, otherwise almost anything goes.

We hope that you can find a good use for this program, it is not a full-blown file editor (if you want an incredible DOS 2.0 file editor, check out Disk Enchanter), but it should provide you with the means to get a peek at those nasty machine-language games you have or fix the dreaded Error 164 (file number mismatch)! Well, so long and happy hacking.


Barry and Bryan are currently taking a break, partly so they have time to play with their new ST’s and partly so they can solve Stationfall and thus save the universe.

© 2008 Bryan P. Schappel • Valid XHTML Transitional • Valid CSS