CoCoSDC for TRS-80 Color Computer part 5

See also: part 1part 2part 3part 4, part 5 and part 6.

The story so far…

In 1980, Radio Shack introduced a computer with color. Later, they introduced a disk drive for it. Even later, everyone stopped using disk drives so an enterprising engineer created a disk drive replacement for a 34-year old computer. This is the story of that disk drive replacement.

Sort of.

Color BASIC PEEKs to get the stat and end of a BASIC program in memory.
Color BASIC PEEKs to get the stat and end of a BASIC program in memory.

As I write this, it has only been a week since I got out my old Tandy Color Computer 3 (CoCo). I have forgotten many things, and can’t remember why I remember other things. For instance, PEEK(25)*256+PEEK(26) will give you the memory location where your BASIC program starts, and PEEK(27)*256+PEEK(28) is the end of it. Subtract those two and you know the byte size of your program. But I digress.

I have now spent a bit of time playing with the CoCoSDC disk drive interface. Initially I just took all the CoCo .DSK image files I had downloaded in the past and copied them to an SD card and spent an evening loading up software. I even ran across a game written by former Sub-Etha Software guy, Joel Hegberg, that had been published in a 1989 issue of Rainbow magazine. Ah, great times. Such nostalgia.

On another evening, I dug through my storage room and finally located a few containers of old 5 1/4″ floppy disks. There had even been one left in my FD-501 floppy drive while it was stored for a decade. The disks I tested still seemed to read (though I already crashed one). I did some test backups, and marveled at how fast the CoCoSDC was compared to the mechanical floppy of decades past. I wrote a bit of BASIC code (similar to what I shared in part 4) to see if I could automate this process.

On my third evening of CoCo time, I started writing the actual backup program. When I was a beginner programmer, I used to blast through code and hack everything together until I had it working. Then I would make a printout, and begin completely rewriting it, all cleaned up and nicer. Think of it as manual two-pass optimization. :) This time, with two decades of programming experience more, I am trying to do more planning and designing.

In order to understand what makes this a challenge, one needs to understand the various types of disks that the CoCo could use over the years: from original single-sided 35-track RS-DOS disks, to double-sided 80-track disks for RS-DOS or alternate operating systems like OS-9. As long as the format used standard 256-byte sectors (i.e., no funky track layout formats which were common with copy protection methods), I wanted to be able to back it up to the CoCoSDC.

First, let’s discuss what it took to create and read these disks.

The Color Computer’s disk controller hardware has four drive select lines it can control. Actually, they are technically three drive selects and one side select. The original CoCo disk drives were single sided, and Radio Shack’s Disk BASIC used these four lines to select one of four possible single sided disk drives. The various disk related commands (BACKUP, DIR, COPY, etc.) allow drive numbers 0-3.

As drives went from 35-track to 40-track, and went from slow belt-driven drives to faster direct drives, CoCoists figured out how to patch Disk BASIC to access 40-tracks, and speed up the drives. (Disk BASIC accessed the drives with a 30ms step rate. Later drives could run at 6ms.)

Patching for 40-track drives was simple, but has some limitations. Disk BASIC reserved enough memory to maintain four 35-track Granual Allocation Tables (GATs, kind of like how FAT is the PC file system). When you patched it for 40-track drives, you could only use three (single sided) drives max. If you wanted to use an 80-track drive, you could only have one. There were alternate patch methods that allowed more drives, but they re-used memory which prevented you from having files open from different drives at the same time. Tradeoffs.

As double-sided drives became common, CoCoists realized that instead of using these four lines to select four single sided drives, they could be used to access three double-sided drives. Alternate operating systems like Flex and OS-9 were able to make easy use of double-sided drives, but Disk BASIC users had to come up with more patches.

As it turns out, patching for double-sided drives in Disk BASIC was easy if you just wanted to treat each side of the disk as it’s own single sided disk. If all you had was a single double-sided floppy drive (DRIVE 0), you could do a simple one-byte change that would make DRIVE 1 access the back side of DRIVE 0. Now you could double your storage without having to cut notches in the floppy disk and make them flippies you had to manually turn over.

If you had two physical double-sided drives, you could make them appear as four separate single-sided drives (DRIVE 0-3). This became a very common practice for many CoCoists, especially after Radio Shack released the FD-502 disk drive which was double-sided.

Now let me pass the buck… Here is an archived webpage that I found useful when explaining the drive selects and how to make Disk BASIC access the back side of double-sided drives:

http://www.oocities.org/theother_bob/coco_page/ccdisk00.htm

In it, he refers to the July 1985 issue of Rainbow magazine which had a very detailed article about Disk BASIC and drive selects and tracks and GATs and stuff. Here is a scan of that issue:

https://archive.org/details/rainbowmagazine-1985-07

(Wow. That was weird. I used Google to find that scan, and when I clicked the link, it opened right to the article I am talking about. Spooky. If yours does not, look on page 26, “Getting on the Right Track” by Colin J. Stearman. Wow again. I remember reading this when it first was published… 29 years ago!)

(Wow #2. I just realized this was the Anniversary issue where Rainbow included a reprint of their first 2-page newsletter. Look at the first letter to the editor on page 6 and see who wrote in to suggest that. “Great idea, Allen.” Ah, my lame claim to fame! Oh, and they printed my request for pen pals in the October 1985 issue on page 9 too. Such memories!)

But I digress…

In the Stearman article, he shows how to take a dual-drive system (with two double-sided drives) and make it look like four drives to Disk BASIC. DRIVE 0 would be the top side of the first drive, DRIVE 1 be the top side of the second drive, DRIVE 2 be the bottom side of the first drive, and DRIVE 3 be the bottom side of the second drive. (This kept DRIVE 0 and 1 as two different drives for compatibility.)

For Disk BASIC 1.1, here are POKEs. They work on a CoCo 3 because it’s Disk BASIC is copied in to RAM on startup and can be changed, but for earlier machines, it has to be a 64K machine with a “ROMRAM” program that copies the ROMs in to RAM then runs from RAM (so you can POKE the RAM copy and make changes). For systems where the ROM can’t be copied and ran out of RAM (16K or 32K), you would have to modify and burn a new ROM for the drive controller.

POKE 55453,1 'Drive 0 accesses top side of physical drive 0
POKE 55454,2 'Drive 1 accesses top side of virtual drive 1
POKE 55455,1+64 'Drive 2 accesses back side of physical drive 0
POKE 55456,2+64 'Drive 3 accesses back side of virtual drive 1

The drive select bits are bit 1 (first drive), bit 2 (second drive), bit 3 (third drive), and bit 7 (side select). If my understanding is correct, CoCoSDC hardware emulates bit 1, bit 2 and bit 7. In SDC-DOS, you can disable a drive so those bits control a real floppy controller if one is also plugged in via a Multi-Pak or similar device.

This means you might be able to do something like this:

DRIVE 0,"FLIPPY1.DSK" 'Make Drive 0 a .DSK image
DRIVE 1,"FLIPPY2.DSK" 'Make DRIVE 1 a .DSK image

POKE 55453,1 'Drive 0 top side of physical drive 0
POKE 55454,2 'Drive 1 top side of virtual drive 1
POKE 55455,1+64 'Drive 2 back side of physical drive 0
POKE 55456,2+64 'Drive 3 back side of virtual drive 1

DIR 0 'Uses first half of FLIPPY1.DSK
DIR 1 'Uses first half of FLIPPY2.DSK
DIR 2 'Uses second half of FLIPPY1.DSK
DIR 3 'Uses second half of FLIPPY2.DSK

But, you cannot. While the CoCoSDC hardware is able to emulate up to an 80 track double-sided drive, and while OS-9 can make use of this easily, the SDC-DOS software works differently and those original Disk BASIC patches will not work. The designer, Darren Atkinson, explained:

When the DSKCON routine in SDC-DOS is called to do I/O for a sector with standard numbering (track 0-34, sector 1-18) it bypasses the traditional floppy access method of spinning up the motor and stepping the head to the correct track. Instead it just calculates the absolute sector number and sends an LBA request to the controller.

This optimization does not look at the drive selects table, so it won’t honor any changes you have made with POKEs.  – Darren

Entirely new patches would be required for the current release of SDC-DOS 1.2. Or, perhaps, a much easier method is available…

I like easier. Let’s do it that way.

To be continued…

One thought on “CoCoSDC for TRS-80 Color Computer part 5

  1. Pingback: CoCoSDC for TRS-80 Color Computer part 6 | Sub-Etha Software

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.