Writing a Human68k Compact Flash Driver for the X68000 PIO Interface

A Compact Flash card looks like an ordinary PCMCIA module, but internally it runs an ATA controller with flash translation, bad-block management and a cache. That distinction matters on an X68000: the PIO interface must move data at the correct width and the Human68k driver must obey the ATA command state machine rather than treating the card as passive memory.

The useful goal is a small, dependable block-device driver that can sit below Human68k’s filesystem layer. It should identify the card, translate logical sectors, survive a busy card or timeout and make removal safe. A benchmark that completes one large transfer is not enough; the important test is whether the same machine can boot and repair disks after repeated power cycles.

Human68k also makes this more than a generic embedded-storage exercise. The driver has to fit the machine’s trap-based system services, interrupt model and calling conventions while respecting the timing constraints of a 68000-family bus. Code that works in a modern emulator can still miss a PIO handshake, use the wrong byte order or fail when an interrupt arrives during a sector transfer.

The work fits the X68000 preservation community well. A modern card can replace failed SCSI media while retaining the original computer, and a documented driver turns a one-off adapter into a reusable tool. This guide focuses on the software contract: identify the adapter first, then build through command sequencing, interrupt handling, filesystem integration and fault-injection tests.

Establishing the PIO hardware contract

Start with the adapter schematic, not a generic ATA tutorial. The PIO connector may expose raw card signals, or it may terminate them behind a controller and FIFO. Record the data width, address and data registers, reset polarity, card-detect behaviour, interrupt line and voltage translation. If the board hides ATA commands, its wrapper protocol becomes the driver’s immediate contract and the card’s ATA guide remains the reference behind it.

At the ATA side, expect data, error, feature, sector-count, LBA and device/head registers plus status and control registers. Learn the exact offset of each register and whether status changes while the host reads it. Bits such as BSY, DRDY, DRQ and ERR are phase indicators: a driver that treats every non-zero status as success will misread an error, an unfinished command and a completed one in the same way.

Power and reset deserve equal attention. Follow the CF card’s power-on and reset timing, and do not rely on the label alone to prove 5 V compatibility. Stable rails and a repeatable reset sequence are just as important elsewhere on the machine: the battery-backed RTC build shows how a small power subsystem can determine whether software sees a consistent clock across cold starts.

Designing the Human68k driver boundary

A practical Human68k driver should expose attach and detach, read, write, flush, media status and possibly ioctl operations through the device interface expected by the target release. Translate between byte counts and 512-byte logical blocks, but leave partition interpretation to the filesystem layer. Keeping that boundary narrow makes the driver usable by Human68k tools, diagnostics and disk utilities instead of tying it to one application.

Match the platform’s ABI rather than a modern C-library assumption. Human68k uses trap-based system services, documented register conventions and specific alignment rules; the ATA registers also have their own byte layout. Verify multibyte ordering with a known value, use the target’s structure headers and avoid unaligned casts. A compiler that builds cleanly can still generate sector buffers that the PIO hardware cannot consume safely.

Build the command engine as an explicit state machine: idle, selecting, setup, data transfer, status and recovery. Every path through it needs a timeout, a defined cancellation point and a result code that tells the caller whether data may be trusted. The outer API can remain simple, but this internal discipline prevents a late interrupt or failed card from leaving a half-completed sector visible to the filesystem.

Turning ATA commands into a PIO protocol

For an ATA read, select the device, set count and LBA, issue the command, wait for DRQ, transfer the requested words and then check status. Writes reverse the data phase but still end with DRDY and an error check. PIO normally relies on polling; an interrupt can shorten the wait if the adapter supports it, but polling remains necessary during handshakes and for recovering a missed notification.

Operation ATA command PIO behaviour Required completion check
Identify Device 0xEC 512-byte identify data Check status and decode capacity and features
Read sectors 0x20 or 0x21 256 16-bit words per 512-byte sector at the ATA side Confirm DRDY, no ERR and the full word count
Write sectors 0x30 or 0x31 256 data-out words per sector Confirm DRDY and no ERR, then flush the cache
Flush cache 0xE7 No data phase Wait for DRDY and verify that the command was accepted

Although SMB is unrelated to ATA, the register-level discipline shown by SMB Research is a good model for a compact peripheral: define every bus phase, make ownership explicit and give each phase a timeout. The same thinking prevents an adapter’s ready signal from being mistaken for completed data or encourages a timeout path that can identify the exact stage that failed.

Classify failures instead of returning one generic error. A missing card, a changed card-detect line, a CRC or media error, an aborted command and a controller timeout require different recovery. Log the command, LBA, status and error register, then reset or re-identify only when the defined policy allows it. Repeated retries can amplify a failing card’s symptoms, so cap them and make the final result visible to the caller.

Making transfers interrupt-safe and deterministic

Keep the interrupt handler short. If the adapter wires the card’s request line to an X68000 IRQ, latch the source, acknowledge it at the peripheral and publish a completion event before returning. Do not copy a sector, wait for a filesystem lock or call a complex BIOS routine inside the handler. The ordinary task can perform the transfer or complete the request; the handler only protects the hardware from a lost edge.

Give each phase a deadline based on a monotonic system tick, not the wall clock. A busy card that never presents DRQ should move through the same reset and retry policy as a card that drops its interrupt. Preserve diagnostic registers before reset, because the status and error values explain why recovery became necessary. A watchdog must also avoid resetting a card while the filesystem still considers a write valid.

Use a 512-byte aligned transfer buffer and copy into it only after a successful read, or only after a write has reached DRDY. Serialise requests with one lock, but allow read and write queues to wait on a completion event rather than spin. On systems with a CPU accelerator, add the required memory barriers around DMA-style movement performed by that accelerator; ordinary PIO copies still need a clear ownership boundary.

Integrating the driver with Human68k storage

Once the driver is stable, place it under the filesystem rather than rewriting Human68k’s disk access. Present sector numbers in the order expected by the target tools, translate removable-media changes and report a clean flush before an unmount. A read-only diagnostic image can be used first, followed by a writable test volume; this separates command-driver faults from filesystem or media-format faults.

Capacity needs deliberate limits. ATA’s 28-bit LBA range reaches 128 GiB with 512-byte sectors, and many 68000-era utilities use signed 32-bit byte offsets or expect geometry from an older BIOS. Even if a modern card reports more, expose a conservative range unless every layer has been tested. Also decide how the driver handles Identify features such as LBA48, write caching and power management; PIO support does not imply that every advertised feature is safe.

Flush the card’s cache before an orderly eject, after a suspicious removal and before software claims the media is synchronized. For X68000 peripheral work, the SNES-style controller build is a useful comparison because it solves a different adapter problem while facing the same Human68k integration, timing and documentation issues. Sharing that kind of cross-project method helps both drivers remain maintainable rather than becoming collections of undocumented patches.

Testing on real X68000 hardware

Test in layers and keep the evidence. First log Identify data and run sequential reads, random reads, repeated writes, read-back checks and cache flushes against a known image. Then introduce absent cards, delayed readiness, unplugged cables, interrupted transfers, warm removal and power loss. Repeat the suite from cold boot and compare checksums after each run; a single successful mount cannot reveal timing faults that appear only after the twentieth reset.

Australian builders often see inexpensive CF stock offered through eBay Australia and local computer sellers, while imported cards can carry GST, courier charges and delivery delays. Compare Australia Post with a specialist carrier before ordering, and check whether the seller documents voltage, command support and genuine capacity. At a Melbourne meet-up, or in a Sydney home lab, a spare X68000, a logic probe and a couple of mates can reveal more than an expensive benchmark card; the local encouragement to “have a go” is useful when the test rig is protected.

Australia’s 230/240 V mains and strict electrical expectations make bench safety part of the test plan. Use an Australian-certified isolated supply for the computer or have a qualified electrician inspect the original power supply; do not make the PIO adapter a path to mains voltage. Heat, dust and transport also matter, especially when an old machine shares a workspace with modern test gear. Log ambient conditions when a fault appears only after a long run.

Publish the adapter schematic, register map, driver source, test images and failure logs with the wider X68000 community. A reproducible PIO interface and a tested Human68k driver are worth more than a private one-off: they let another restorer rebuild the card, compare timing data and keep using the original platform instead of retiring it with a failed drive.

Nereid-X Expansion Board

A personally-produced LAN+USB+Memory expansion board for Sharp X68000 series computers. Multiple production runs were offered, including a final batch and a later revival reproduction run.

Power Supply Repair

X68 power supply repair and modification services were offered by the site owner, with documentation shared through diary entries spanning 2001–2006.

Server & Networking

Notes on FreeBSD administration, ISP changes, server migration, and networking topics. The site itself ran on FreeBSD with the hns diary system and Namazu search integration.

A two-ink risograph print in muted slate-blue and charcoal on off-white paper, showing a stylized desktop computer monitor beside a circuit board with soft geometric trace lines, conveying a calm retro-computing workshop atmosphere. A two-ink risograph print in deep purple and dark grey on cream stock, depicting a compact expansion card with connector ports and subtle Japanese technical annotations, evoking a hobbyist electronics bench. A two-ink risograph print in teal and charcoal on warm white paper, showing a server rack silhouette with soft network-line motifs and a small weather icon, suggesting a personal server room corner.

Get in touch

X68K.NET connects Sharp X68000 enthusiasts through community links and shared projects. Reach out with questions about the Nereid project or X68 resources.