Skip to content

barberd/cocousbhost

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CoCo USB Host

Description

This board is a cartridge for the Tandy Radio Shack TRS-80 Color Computer (CoCo), an 8 bit computer produced between 1980 and 1991. It provides a USB 2.0 Host controller, the CH376S, to the CoCo. This allows one to use USB devices with the Color Computer given software drivers for the device. See "Using the Board" below.

Front View

Schematic is available here.

Assembly routines for using the cartridge in your own software can be found in the Software directory. This includes drivers for USB hubs, keyboards, mice, and mass storage devices (such as pendrives). Additionally, a software patch for the Color Computer 3's BASIC to use a USB keyboard for input can be found in this directory.

Building the board

This is open source hardware, so its up to one to get the board fabricated and then solder the components onto it. All components are through-hole-mount for easy assembly by hobbyists, with the exception of the CH376S chip itself; that requires surface mount soldering.

If you've done soldering but are new to surface mounting chips: pin the chip into place by soldering two opposite corner pins, then with a hot iron and plenty of flux, run a bead of solder down each side, then wick up any excess.

How to order for fabrication

Download kicad/cocousbhost-fabrication.zip, then upload it to one's PCB manufacturer when asked to provide Gerber files. Usually this is found under a 'Quote' option on the website. Search "pcb manufacturing" on any major search engine to get several manufacturers. NextPCB and PCBWay are two well-known ones.

Some may have ordered boards and have extra available. Reach out to don @ dgb3.net to explore this.

Use the Bill of Materials to source the components from electronic supply houses such as Mouser, Jameco, or Digi-Key.

Source and License

Design maintained at https://github.com/barberd/cocousbhost. Kicad and Freerouting were used to design the board.

The design is copyright 2025 by Don Barber. The design is open source, distributed via the GNU GPL version 3 license. Please see the COPYING file for details.

Why

In 2022 I developed the CoCo USB Serial Pak, a cartridge that looks like an original Tandy Deluxe RS-232 pak to the CoCo but instead presents as a USB serial device to the PC its plugged into. That cartridge allows for very fast and easy communication between the CoCo and PC (think of it as a null modem cable), but does not provide any ability to host USB devices, to the confusion of many in the CoCo community.

After that project, I wanted to produce a cartridge that did provide that USB host ability for the CoCo. I also didn't want to just interface to another computer (such as a Raspberry Pi Pico or ESP) that does the real USB work; I wanted the CoCo to control the USB bus and communicate with devices directly, recognizing I'd have to write software drivers from scratch. This is the result.

Using the Board

Please do not expect to use this board as a drop-in to replace the Color Computer's keyboard, joysticks, storage mediums, or other hardware and expect all the original software to work immediately and transparently.

This board provides a USB bus for the Color Computer. Use of that bus, and any devices found on that bus, requires software drivers. Patches for the original DECB routines for POLCAT (read a character from the keyboard) to use a USB keyboard is available in the Software directory. These DECB patches work with most Basic programs and any machine language software coded to use DECB's built-in routines.

Conceptually, a similar patch for DECB's JOYIN (read from the Joysticks) routine can be developed, but as joysticks do not have a standard report format (unlike keyboard and mice Boot protocol), each joystick model will need a custom driver developed. But if developed, this would work for Basic programs and those machine language software packages that use the JOYIN routine.

However, the majority of original applications and games are hard-coded to access the keyboard, joystick, and serial devices directly through the Peripheral Interface Adapter (PIA) chips of the CoCo and not through DECB's provided routines. If one desires, one can patch such software to instead leverage USB devices through this cartridge, but each software package is a custom effort. One can leverage the routines and drivers in the Software directory as a starting point.

The exception for needing to patch software is when software is running under an operating system (where hardware is abstracted away through an API) and that operating system has USB drivers; the operating system's programming interface in combination with drivers takes care of the hardware interfacing. There are a few operating system available for the CoCo; see the "NitrOS-9" section below for one implementation.

To digress from this cartridge slightly: If one wants to use USB devices transparently with old software without patching, one will instead need a hardware solution that plugs directly into the original hardware's interface, presenting translated signals in a way the original software expects. This is normally done with a second computer (such as an Arduino, ESP, or Raspberry Pi Pico) doing the USB communication, converting the signal information, and then re-presenting such via the legacy interface (such as plugging into the keyboard matrix ribbon connector plug or the joystick port). See USB to CoCo Keyboard Adapter, PiKey, and CocoJoyStickAdapter for examples. The CoCoSDC uses a similar technique with an Atmel microprocessor (though for a SD card interface, not a USB device). All these solutions are brilliant; they provide drop-in solutions requiring no change to legacy software.

The intent of this cartridge is different: unlike these hardware-interfacing solutions, this USB host cartridge provides a full USB bus to the CoCo. This means by writing new drivers, one can use any USB device, including those not originally available on the CoCo. This could include scanners, printers, webcams, network adapters, bluetooth adapters, light guns, sound adapters, digitizer drawing tablets, etc; almost any USB device can be made to work. This provides diverse flexibility for a CoCo developer to write new software leveraging a wide range of available hardware; homebrew is still alive and well for the CoCo!

Two limitations to be aware:

  • The CH376 chip does not support isochronous USB transfers (this means some of the streaming protocols often used on sound adapters and newer webcams won't work, though many webcams still support the interrupt and bulk transfer methods as well)
  • The CoCo itself might be too slow for some USB devices - its bus speed can only transfer data so quickly.

Configuration

Set the 7 dip switches (SW1) for the desired base IO address. These correspond to address lines A1 through A7. The default is $FF86. See here for a list of known IO hardware addresses. If you happen to have a conflict, choose a different IO address, set SW1 accordingly, and reassemble binaries to match.

The orientation of SW1 matters; it should be that the 'circuit is closed' or 'on' direction points to the 0 side. This is because the 74LS682 chip works by defaulting to '1' unless pulled to ground to make it a '0'. This simplifies and lowers the cost of the address selection circuit but also results in the non-intuitive use of 'on' to get a '0' instead of a '1'.

As such, make sure to orient the switch to match 'on' to face the same direction as the '0' label. If one gets the switch upside down, not a big deal, the switch will just operate in reverse from the silkscreened labels.

Overview

The cartridge uses two memory-mapped ports, the base address and the base address+1. The two addresses used correspond to different registers on the CH376 and board. For example, if given base address of $FF86:

  • $FF86 Data Register (Read and Write)
  • $FF87 Command Register (Write) and Flag Register (Read)

Read the CH376 Datasheet 1 and CH376 Datasheet 2 for how to use the chip.

The CH376 chip has built-in commands to access USB mass storage devices both at the block level and file level. The CH376 also allows for control transfers (used to configure devices), interrupt transfers (used for keyboards, mice, game controllers, etc), and bulk storage transfers (used for mass storage such as pendrives). It does not support isochronous transfers (used for streaming data), so it will not work with some modern sound adapters and webcam protocols.

Note that the CH376 can only connect directly to a single USB device. That device can be a USB Hub, but this means driver software must configure the hub to allow communication to other devices through it. Such a driver can be found in the Software directory. Its HIGHLY recommended to use a powered USB hub; otherwise the USB devices will draw power from the Color Computer or Multi-Pak interface.

Interrupts

The CH376 will issue an interrupt after completing several commands. This will assert the CART* line on the cartridge. When PIA1 is configured to do so, a fast interrupt request (FIRQ) is sent to the CPU when CART* goes low.

To configure the PIA1 to do this, enable fast interrupts and configure it to trigger on a falling edge, like so:

            LDA     $FF23           ;load PIA1 Side B Control Register
            ORA     #$01            ;set bit 0 to 1 to enable cart firq
            ANDA    #$FD            ;set bit 1 to 0 to trigger on falling-edge
            STA     $FF23           ;store in PIA1 Side B Control Register

Hook in the interrupt handler at $010F (and/or $FEF4 on the CoCo3) as one would any other FIRQ handler. Make sure the interrupt handler performs a GET_STATUS to clear the interrupt.

If one's software doesn't handle interrupts, one will need to use software polling of the flag register instead.

See the routines in the Software directory for examples.

ROM Socket

A socket for a ROM is also included in the board design. This is entirely optional, as many users today will instead choose to use another boot device, such as disk, SDC, or DriveWire. However, one can add a ROM loaded with a bootloader, perhaps to boot NitrOS-9 directly off a USB drive (see the "NitrOS-9" section below) or patching BASIC for USB drives and keyboards.

The ROM socket is wired for a 27128 EPROM. As the 27128 provides 16k of storage, the board presents this as 2 different banks of 8k each, selected via jumper J1. As such, when writing the EPROM, combine the images with each image aligned to an 8k boundary (eg, at 0 and 8k). If using a ROM IC other than the 27128, one will need to adjust the board design to match the chosen IC. Some other ROM ICs are pin-compatible and will work fine with the existing design.

Note Jumper J2, labeled "Autostart ROM". Color Computer cartridges signal the onboard ROM that they are present and should be started on boot by shorting the Q signal to the CART* signal; see Tandy Cartridge Schematic. This works great for end users as game cartridges will auto-start, but this technique conflicts for device cartridges which need to also send interrupts. This is evident in cartridges like the Tandy Deluxe RS-232 pak, wherein users had to execute the ROM manually by running "exec &hc000" (Color Computer 1 or 2) or "exec &he010" (Color Computer 3) to start their software.

Through the use of a flipflop and some additional logic, this cartridge attempts to allow auto-start while also allowing the CH376 to send interrupts after bootup: if the J2 jumper is present, then on startup, the Q signal is sent to CART*, like any auto-start cartridge. However, once the ROM is accessed, this signal is gated off, so normal interrupts from the CH376 can be sent. This works perfectly if booting from the cartridge and allows for both auto-start and use of the CH376 interrupts.

However, if one has the J2 jumper present but boots via another method (perhaps via a floppy drive or a CocoSDC in another selected multi-pak interface slot), then the ROM is never accessed and the Q signal will continue to be asserted to CART*. This will prevent proper use of interrupts. If one is not using the auto-start feature, remove the J2 jumper to prevent this contention.

If one never plans on using the ROM, one can eliminate components J1, J2, U7, U5, R4, and Q1.

More Info

NitrOS-9

NitrOS-9 is a community maintained open source operating system for the Color Computer based on Microware's OS9. Several modules have been written for NitrOS-9 providing a USB Manager and drivers for various USB devices (such as mass storage devices, keyboards, and mice). Additionally, a boot module is available that boots NitrOS-9 directly off a pen drive connected to this cartridge when written to a ROM in the ROM socket.

Links

Note on the CH375B versus CH376S

The CH375 is a very similar chip that provides the same USB functionality of the CH376. The CH376 also costs slightly more and its additional features (interfacing with an SD card controller) are not used on this cartridge. Therefore, one might be tempted to use a CH375 instead.

In the author's experience, the CH375 has an undocumented bug that drops a byte seemingly at random, leading to corrupted data and trouble keeping software and hardware in sync. This behavior was consistent across four chips the author tested, and seems consistent with anecdotal user experiences found online around other solutions using the CH375, such as ISA cards designed for early PCs.

If one does choose to use the CH375B instead, either add a bodge wire or modify the design before manufacturing to connect pin 23 to ground, and use $2B (WR_USB_DATA7) for the write command instead of $2C (WR_HOST_DATA).

Errata

Version 1.0 had a bug in that tying CH376S pin 1 directly to the CART* line would conflict with other devices, including the autostart ROM. This was corrected in version 1.1.

About

USB Host Cartridge for the Tandy TRS-80 Color Computer

Resources

License

GPL-3.0, GPL-3.0 licenses found

Licenses found

GPL-3.0
LICENSE
GPL-3.0
COPYING

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors