Skip to content

SoftIEC: hold DATA low for 100 us at the start of a JiffyDOS LOAD chunk - #1130

Draft
JC-000 wants to merge 1 commit into
GideonZ:masterfrom
JC-000:fix/986-jiffy-load-window
Draft

JC-000 wants to merge 1 commit into
GideonZ:masterfrom
JC-000:fix/986-jiffy-load-window

Conversation

@JC-000

@JC-000 JC-000 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Problem

Intermittent ?LOAD ERROR with JiffyDOS on the Software IEC drive: ST=66, and the error channel stays at 00, OK (#986).

Cause

At the start of each LOAD chunk the JiffyDOS kernal polls CLK with no timeout and takes DATA from the first read that finds CLK high, expecting DATA low. The microcode releases DATA 50 µs after it answers. A host stalled inside that poll when CLK rises (a VIC badline, for example) can come back after the window has closed. It then reads CLK and DATA both high, which it treats like an end of file: it waits about 1.1 ms for the drive, gives up and sets ST=66. The drive saw no error, so the channel says 00, OK.

The badline is the likely trigger, but not a proven one: on a U64E the unchanged code passed about 1,300 loads with the reporter's program and disk image, and the reporter's U2+ on a real PAL C64 is untested.

Change

WAIT FOR 50 us becomes WAIT FOR 100 us in _jiffy_outer (software/io/iec/iec_code.iec); the assembled microcode differs in one word. The window starts after the drive answers, so 100 µs is at least as generous as a real JiffyDOS 1541, which holds DATA for about 77 cycles counted the same way. A longer window is harmless: after seeing CLK high and DATA low, the host waits for DATA high without a timeout. EOI, the last chunk, SAVE and byte-mode transfers are untouched.

Evidence

U64E, JiffyDOS kernal, 16 KiB LOAD loop. In the delay rows the host's poll was slowed on purpose by patching a temporary copy of the kernal.

Image Host delay Failures
master (50 µs) 61 cycles 10/100
master (50 µs) 86 cycles 12/100
this change 61 cycles 0/100
this change 86 cycles 1/100
this change 101 cycles 4/60
this change, drive A 1541-II, directory partition none 0/100
this change, drive A 1541-II, D64 partition none 0/100
this change, stock (non-JiffyDOS) kernal none 0/50

On this change, a JiffyDOS SAVE, VERIFY, LOAD back and directory listing all completed with ST=64, and the saved file matched memory.

Limits

  • 100 µs is a margin, not a guarantee: a host delayed by more than about 90 cycles in total can still miss it (the 86 and 101 cycle rows).
  • With the host delayed by about 211 cycles, the first LOAD never finishes, on master and on this change alike. That is the separate fixed CLK pulse in the EOI path (_jiffy_load_eoi), which this change does not touch. A real C64 is never that late.
  • Not yet tested on a U2+, hence Refs rather than Fixes.

Refs #986

Written with Claude Sonnet 5.5 and Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

At the start of each chunk the JiffyDOS host polls CLK with no timeout and
takes DATA from the first read that finds CLK high, expecting DATA low. The
microcode released DATA again 50 us after it answered. A host stalled inside
that poll when CLK rises (for example by a badline) can come back after the
window has closed, read CLK and DATA both high, take it for the end of the
file and stop the LOAD with ST=66 while the error channel reads 00,OK.

Hold DATA for 100 us. That is at least as generous as a real JiffyDOS 1541
and harmless: after seeing CLK high and DATA low the host waits for DATA
high without a timeout.

Refs GideonZ#986.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@chrisgleissner

Copy link
Copy Markdown
Collaborator

@JC-000 What is outstanding to make this PR merge ready? One thing I would like is if you could formalize the tests you performed (see 'Evidence') as part of a soak test, with consistent invocation syntax and documentation, resembling the already existing soak tests we have. We created these soak tests for exactly such problems.

@JC-000

JC-000 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@chrisgleissner Not merge ready. I formalized the test as you asked, reran it under control, and the result does not support this PR.

Setup. U64E, JiffyDOS 6.01 kernal, SoftIEC drive, 16 KiB file loaded from a USB stick. The kernal is patched to wait a set number of extra cycles before it first polls DATA, to imitate a slower host. Two firmware builds from the same commit that differ only in the one microcode word this PR changes (50 us against 100 us), loaded in alternating blocks of 50 loads.

Extra host delay 50 us (master) 100 us (this PR)
63 cycles 7/150 failed 9/150 failed
88 cycles 0/50 0/50
none 0/50 0/50

Every failure is a silent short load: ST=66, error channel 00, OK, and all but one stop at the first chunk. The failures come in bursts (the 100 us build had 9 in one block and none in the other two), so the block-to-block spread is larger than any difference between the builds.

What this means. The longer hold does not remove the failure, and a 63-cycle delay is shorter than either window, so these are not simple misses of that window. The root cause I gave in the description is not established. The earlier evidence was too few loads to see past the bursts.

This PR stays in draft. I do not have a root cause yet and will look for one by instrumenting the firmware and the C64 side of the test. The test itself is a script for tests/soak and I will put it up separately, since it is useful whatever the fix turns out to be.

Written with Claude Fable 5.2 in Claude Code.

@JC-000

JC-000 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@chrisgleissner A correction to my comment above: the 100 us hold does fix the delayed-host failure, and yesterday's run could not show it.

Same setup, host delayed by 63 cycles, with a bus trace added at the start of each chunk:

Screen 50 us (master) 100 us (this PR)
blanked 95/200 failed 0/200
on 9/200 5/200 and 2/100

Root cause. A load fails when the drive already has its answer ready as the host releases DATA. It holds DATA low for 50 us and releases it, and a host that looks later than that reads both lines high as end of data. On master every load with that early answer failed, 95 of 95 with the screen blanked. With the 100 us hold, 64% of loads had the early answer and none failed. Details are in #986.

Why yesterday's table showed no difference. How often the drive answers early swings between about 5% and 50% from one block of loads to the next. That is larger than the difference between the builds at 150 loads each. I was also wrong to write that a 63-cycle delay is shorter than either hold: it is about 64 us, longer than the 50 us one.

What is still open. With the screen on, the 100 us build still fails a few loads, at raster positions where a badline adds about 40 cycles and puts the host past 100 us. That rests on 7 failures. I have not measured how long a real 1541 with JiffyDOS holds DATA, so 100 us may not be the final value; I asked on #986.

This PR stays in draft until the description is rewritten around this and the soak test in #1132 has the screen-blanked rows as its red/green.

Written with Claude Fable 5.2 and Claude Sonnet 5.5 in Claude Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants