Skip to content

feat(disk): Disk II copy-protection fidelity (spin-up, rotational position, bit-level writes) #67

Description

@relmer

Summary

Tighten Disk II emulation to support copy-protected software. The current controller is faithful enough for standard DOS 3.3 / ProDOS disks and runs every test in the bootable test suite, but a handful of analog-timing and bit-stream behaviors that copy protection schemes exploit are still simplified or missing.

Successor to #61: that issue's core deliverables (WOZ v1/v2 support, quarter-track stepping, motor-gated reads, auto-flush on eject) shipped with the //e fidelity work. This one isolates the protection-fidelity remainder.

Outstanding behaviors

1. Motor spin-up delay

Real hardware takes ~1 revolution (~70 ms at 300 RPM) to reach reading speed after the motor is energized. Reads attempted during spin-up return garbage. Some protection schemes deliberately read during the spin-up window and check for the absence of valid sync.

Currently Casso's motor reaches speed instantly: a read 1 cycle after \ returns the same data as a read 10 ms later.

2. Cycle-accurate rotational position

The disk spins continuously; the read head sees whatever bit is currently under it. If the CPU is busy doing something else, the bits keep going by -- when the CPU comes back, the next read picks up wherever the disk is now, not the next sequential bit.

Currently Casso returns the next sequential nibble regardless of how much time elapsed between reads. Protection schemes that read, do timing-sensitive work, then read again rely on the position having advanced.

Implementation: track a rotationalPosition field on the active drive, advance it by (currentCycle - lastReadCycle) bits-per-cycle on each read, modulo track length.

3. Bit-level write path

Casso's write support today is sector-level (WriteSector). Real hardware writes bit by bit through the Q6/Q7 state machine and the data latch; protection schemes use this to write non-standard sync patterns, weak bits, and partial sectors.

Implementation: full Q6/Q7 state machine with the data register, writing into the WOZ bit stream byte by byte, and write-back to .woz on flush. .dsk write-back can re-nibblize on the way out (with a warning when the bit stream contains non-standard sync that .dsk cannot represent).

Acceptance criteria

  • Reads issued within ~70 ms of motor-on return synthetic noise (or zeros), not real disk data
  • Two reads separated by N CPU cycles see disk positions N bits apart (within 4-cycle nibble granularity)
  • Bit-level writes through Q6/Q7 land in the active drive's WOZ track bit stream
  • At least three known copy-protected titles boot from their WOZ images:
    • Karateka (Brøderbund)
    • Choplifter (Brøderbund)
    • Lode Runner (Brøderbund) -- or another known-protected reference disk
  • Standard DOS 3.3 / ProDOS .dsk continue to work (regression check via existing test suite)
  • Auto-flush on eject continues to round-trip user writes correctly

References

  • WOZ Disk Image Reference -- analog metadata in WOZ 2 covers exactly the protection-fidelity gap
  • AppleWin Disk II implementation -- known to support ~99% copy-protection fidelity (GPL-2 reference)
  • Beneath Apple DOS / Beneath Apple ProDOS / Understanding the Apple //e -- canonical hardware-level references

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions