Classic Computer Magazine Archive COMPUTE! ISSUE 43 / DECEMBER 1983 / PAGE 298

Disk Explorer For Commodore

Robert W. Baker

If you've ever been curious about the 1541's memory, this program gives you an inside view of the unit's ROMs. It allows you to display both a disassembly of the 1541's machine language instructions and a hex dump of the drive's RAM and ROM addresses.

"Disk Explorer," a program written for the 64 but suitable for other Commodore users, is designed to let you look around inside the VIC-1541 disk controller. You can directly display a disassembly of the machine language instructions in the disk unit's ROMs. Alternately, you can display a hexadecimal dump of any area of the disk controller 6502 microprocessor's address space, including peripheral chips, RAM, or ROM. With some knowledge about assembly language and a little about hardware, this program provides an easy method of exploring the disk controller.

A Variety Of Choices

When the program starts, there's a short delay while a data array is built for the disassembler (lines 110 – 130). Then you're prompted for the starting address of where you'd like to start looking. The desired address can be entered as a decimal number, or a hexadecimal number preceded by a dollar sign. Program lines 160–240 validate the digits of the address and convert a hex address to a decimal value. An invalid address is discarded and you're prompted again for the starting address.

The program normally displays the data on the screen, but you can select printed output as shown in lines 250 – 270. You'll notice the OPEN statement in line 270 opens either device 3 or 4 depending on whether a printed output is desired. Device 3 is the display screen, and device 4 is the printer. This provides a simple switch between devices for all following PRINT#4 statements without having separate routines for display and printed data. You can still force output to the display screen by using the simple PRINT statement.

The last prompt is for the data display type: either a hexadecimal dump or an instruction disassembly. If a hex dump is selected) then eight bytes of data are displayed, in hex, per screen line. Each line also includes the hex address and the ASCII translation of the data displayed. The ASCII translation is simply the displayable character for each byte shown, with nondisplayable characters converted to periods.

An instruction disassembly shows one 6502 instruction per line using the standard mnemonics. Each line indicates the address of the instruction in both decimal and hex, along with the hex opcode for the instruction displayed. To make things a little easier to read, branch instructions indicate the hex address to which the instruction would branch rather than an offset from the current location.

Three Choices

When displaying data on the screen, the program will pause after 16 lines of hex data or 20 disassembled instructions. A prompt message will ask whether you want to: continue displaying data with the next sequential location; restart the display with a new address and/or format; or stop the program and return to BASIC.

When data is being printed, pressing any key on the keyboard will halt the printer at the end of the next printed line and display the same pause message. You'll also have the same options. I would suggest using the space bar or some key other than the C, R, or S characters to avoid possible problems.

The heart of the program is the M-R command to the disk unit that lets you read any address within the disk controller. All reads of the disk address space are done by the subroutine in lines 605 – 607. Line 605 converts the address (A) to the corresponding high (H) and low (L) bytes for the M-R command. Line 606 first issues the M-R command and then the GET#15 command to read the data from the address specified. The remainder of line 606 and the beginning of line 607 convert the data into the decimal value (V) of the byte.

Exploring The Controller

Now that we know how to use the program, what do we do with it? The first thing you'll probably want to look at is the interrupt vectors at the top of the ROMs. The NMI vector is at $FFFA – $FFFB, the RESTART vector is at $FFFC – $FFFD, and the IRQ vector is at $FFFE – $FFFF. The data in each pair of bytes will be the hex address of the start of the routine that processes the corresponding interrupt. Remember that the addresses will be in the standard 6502 format, low byte first, then high byte.

The RESTART vector is probably the most revealing pointer since this is where the disk controller starts executing instructions when the unit is first turned on. If you follow the instruction flow from there, you'll see the self-test procedures executed when the unit is turned on and the disk controller checks to see that everything is working properly. After these tests, the unit goes on to initialize various pointers and control flags and then waits for a command.

There's 2K of RAM from locations $0000 – $07FF plus 8K of ROM from locations $C000 – $FFFF. Additionally, there are two 6522 Versatile Interface Adapters (VIAs) based at locations $1800 and $lC00. If you do go peeking elsewhere, you may see "reflections" of various devices at other addresses due to the address decoding scheme within the disk controller.

For PET/CBM And VIC Users

Although written for the Commodore 64, this program can also be used on the older PET and CBM models to look into the 4040, 8050, and similar disk units. However, those units have a much more complex structure with two microprocessors and shared memory. You might want to refer to Jim Butterfield's article "Inside the 2040 Disk Drive" on page 94 of the January/February 1980 issue of COMPUTE! for more information.

For VIC-20 users, at least 8K memory expansion is required. You'll have to tinker with reducing the length of the displayed data to fit the 22-column screen. The hex dump can be trimmed to four bytes per line by simply changing the heading in line 1000 and the FOR-NEXT loop count in line 1010. The disassembly display is a little harder to trim, but you could eliminate the decimal address (line 330), separating spaces in the object (lines 350 and 370) and corresponding blanks for no object (SPC in lines 360 and 390), plus fix the heading (line 305).