Skip to content

SoftIEC follow-up: final compatibility pass and E2E fixes - #931

Merged
chrisgleissner merged 138 commits into
GideonZ:masterfrom
chrisgleissner:fix/softiec-followup
Sep 28, 2026
Merged

chrisgleissner merged 138 commits into
GideonZ:masterfrom
chrisgleissner:fix/softiec-followup

Conversation

@chrisgleissner

@chrisgleissner chrisgleissner commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Software IEC work that landed on the #881 branch after #881 was squash-merged, rebased onto master. It completes the drive's CBM DOS compatibility, fixes the defects that running every E2E suite on two devices found, and fixes the Software IEC reports on #917, #918, #933 and #934.

Fixes #820, #918, #933, #934. Refs #877, #881, #917.

Review the diff against master, not the commit history. Some commits undo earlier ones.

Size of the change

Area Files + / - Why it is in this PR
Software IEC drive (software/io/iec) 8 +1457 / -301 Commands, defects and specification findings below
File system, file manager, file types, browser 14 +534 / -83 Shared code the drive relies on: disk image lock, header labels, x00 files, delete of an open file
C64 keyboard scan, sampler, host interface 7 +157 / -11 Keys lost on a cartridge (found by the E2E gate), DC offset after a reset
WiFi driver, network interface 3 +24 / -3 #820
itu.c, REST drives route, UCI target 4 +32 / -6 Whole log lines, drive reset over REST, #918
UCI KERNAL (roms/c64rom) 1 +8 / -1 A defect found by running the suites under it
Makefiles 9 +9 One new source file, x00_wrapper.cc
Host tests (software/test, parser test and stubs) 4 +2343 / -44 One case per requirement, red before each fix
Specification (doc/) 1 +1539 / -1005 The contract the drive is tested against
E2E and soak tests, runner (tests/, run-tests, tools/) 67 +4417 / -888 New suites, and harness defects that made runs fail

Firmware without tests and docs: 37 files, +2212 / -405.

Firmware changes

Every defect fix below was shown failing before the fix and passing after it: on the host (target/pc/linux/iecdrive, parse) and, where the device is needed to show it, on an Ultimate 64 Elite and an Ultimate II+L. "Host" and "device" in the Test column say where.

Commands the drive did not implement

Command Behaviour Why Test
T-WA, T-WB, T-WD, T-WI Set the drive's own clock, kept as an offset from the system clock. The drive never writes the system clock, and a drive reset clears the offset. CMD HD 9-36; sd2iec. The system clock is the Ultimate's and is set by SNTP, so a C64 program must not move it. host, device
S-8, S-9, S-D Move the drive to device 8, 9, or back to its configured number. CMD HD 9-34 host, device
M-W to $0077 Set the device number, as a CMD drive's SWAP button sends it. Every other M-W still answers 30. #933 host, device
R-P, R-H Rename a partition; rename the header a listing shows. CMD HD 9-14, 9-15 host
EL, EU, EH, A, XH, D sd2iec attribute commands: lock, hidden flag. =H lists hidden entries. sd2iec (SDM), C64 OS host
EL:$, EU:$ Write-lock a disk image through its DOS version byte, as sd2iec does. FTP, REST and the browser honour the lock too. #917 host, device
W-1, W-0 Software write protect, enforced at every gate from the bus to a medium. CMD HD 9-35 host, device
##n, 3-byte B-P Chained buffers; a high byte for the buffer position. sd2iec, C64 OS host
N inside a mounted image Formats that image instead of creating a new one inside it. sd2iec host
,M open suffix Opens for reading. SDM; SI-070 listed it and the parser refused it host
M-E Answers 98,UNKNOWN DRIVE CODE instead of 30. sd2iec host

Defects in the drive

Defect Fix Test
JiffyDOS LOAD lost the last byte of a file of 512n + 1 bytes (#917). The microcode's block loop peeked the last byte, saw its EOF flag, and signalled the end without sending it. One line removed in iec_code.iec. IecChannel::pop_more() also completed a file one pass early. device: 6 of 12 lengths short, then 12 of 12 whole; host
A CMD drive's SWAP lost its last byte and EOI (#933). The microcode acknowledged a byte and handed it to the software 100 us later; the CMD drive raises ATN after about 40 us, which discarded it. The byte, and EOI, are pushed before the acknowledge. device: iec-listen-timing, 27 checks, red on the old microcode
A drive reset did not restart the IEC processor, and PUT /v1/drives/softiec:reset, :on, :off did nothing (also on master). reset() restarts the processor; the route maps to the drive's own commands. host, device
A reset kept a half-received command, which then ran with the next bytes (also on master). wr_pointer is cleared. host, device: 30 before, 00 after
P on a channel opened for writing before W-1 wrote its buffered bytes and grew the file. P on such a channel answers 26. host, device
Copying relative files of two record lengths answered 64 but left a partial target. The target is removed. host, device
A rename of an x00 file that the file manager refused (file open for writing) still wrote the new name into the header. The host rename runs first; the header is written only after it succeeds. host, device
P could set a negative buffer pointer, and the next byte was written outside the buffer. Negative positions answer 30. host, device
A replace refused by W-1 deleted an x00 file first. The delete runs only when not protected. host, device
R-H skipped the name checks R applies. XL/XU locked files. A case-only x00 rename answered 63. Same checks as R; XL/XU answer 30; the host file keeps its name. host, device
23 defects found by checking the specification against the code, such as RD deleting files and images, MD:A*, a 253-byte cut of UCI commands, scratch and copy dropping names after the eighth, relative files read past their end, and names over 16 characters. One fix each. one host case each, red before its fix; list below
The 23 specification findings
Requirement Defect Change Test
SI-063 RD deleted whatever the name reached, including a plain host file or a whole disk image, and RD: with no name deleted the directory the drive stood in RD deletes a directory only; an empty name answers 34 Suite11-SI063-RdOnlyDirectories
SI-060 MD: answered 63, MD:A* created a directory with an escaped wildcard, and MD:NAME. created a directory FAT then renamed, which could not be entered again 34 for no name, 33 for a wildcard or a trailing dot or space parser test_md_rd_grammar, Suite11-SI063-RdOnlyDirectories
SI-022 A command through the UCI target was cut to 253 bytes and executed, so a 290-byte S:VICTIM,... scratched VICTIM the whole buffer is copied, so the length check refuses it with 32 Suite11-SI022-UciTooLong
SI-035 Writing a name that existed with another type created a second entry of the same name (FOO as SEQ and as PRG); a REL file opened as another type answered 62 63 without @, 64 with @; a REL file opened as another type answers 64 Suite11-SI035-TypeOfExistingName
SI-064, SI-051 R-H at a partition root kept a name longer than 16 characters, and the root header then showed the last 16 while G-P showed the first 16; R-H without a colon renamed the current directory with the partition digits in the name cut to 16, the header shows the first 16; the colon is required (34) Suite11-SI064-RootHeaderLength
SI-150, SI-073, SI-075 A scratch or a copy dropped every name after the eighth without an error; C:ALL=F0,...,F9 answered OK and copied eight name lists are sized from the command Suite11-SI150-NameLists
SI-150 Names longer than 16 characters were created in full, so two files listed under one name and a literal scratch deleted both a created name is cut to 16, as on a 1541 Suite11-SI150-CreatedNameLength
SI-080 Reading a relative file past its last record returned the last record again with 00, OK, and a following write landed several records beyond the end; P past the end grew the file even when nothing was written; a file with a partial last record was padded by the wrong count; a record length byte of 44 (,) or 58 (:) could not be used reading past the end gives one $FF and 50; the file grows only when a record is written, completing a partial last record first; the byte after ,L, is the record length whatever it is Suite11-SI080-PastTheLastRecord, Suite11-SI080-RecordLengthBytes, parser
SI-075 Copying relative files wrote each source's header into the data, and copying an R00 file lost the record length a relative copy writes one header and each source's records; relative and other types mixed, or different record lengths, answer 64 before the target is created Suite11-SI075-CopyRelative
SI-074 A move that kept its name skipped the "name exists" check, leaving two entries of one name in the target directory; a missing destination path answered 77 the check runs unless the entry stays in its directory; a missing path answers 71 Suite11-SI074-MoveChecks
SI-082 P on a plain file after it was read to its end answered 61 a file read to its end still positions Suite11-SI082-PositionAfterEnd
SI-081 A bad channel byte for P answered 31, an unopened channel 61 both answer 70, as the ROM and sd2iec Suite11-SI081-PositionChannel
SI-103b A settings change after U0> restarted the IEC processor and put the drive back on its configured number the comparison is with the setting last applied Suite11-SI103b-SettingAfterU0
SI-105 An M-R or G-P reply that was not read became the status of the next command that succeeded a new command clears the reply Suite11-SI105-UnreadReply
SI-070 Secondary addresses 0 and 1 did not force read and write when the name gave a mode; OPEN 1,8,0,"X,S,W" created a file forced, as the spec and SD file_open() state Suite11-SI070-SecondaryForcesMode
SI-102a Creating a relative file under W-1 answered 62 26 Suite11-SI102a-NewRelative
SI-144 An x00 header name padded with $A0 listed with the padding and a scratch by name missed it; an x00 file also opened under its host name trailing $A0 dropped; the header name is the only name Suite11-SI144-HeaderNameOnly
SI-041 G-P padded the partition name with $00 $A0, as a CMD partition directory and sd2iec Suite11-SI041-NamePadding
SI-072 Any file type with a disk image extension was written raw, so a SEQ file named X.D64 lost its type only a PRG is written raw, as SD fat_open() Suite11-SI072-RawNames
SI-100 U0>+CHR$(13) without a terminator answered 30, because the terminator strip removed the device byte U0> is exempt from the strip, as the binary CP is (SI-017) parser
SI-091 BLOCK-READ and the other long spellings the 1541 manual prints answered 30 the letter after the dash names the command, as the ROM and sd2iec read it parser
SI-123, SI-135 A malformed AM/PM marker or trailing bytes were accepted, so a PM typed shifted left the clock 12 hours wrong; the $=T filter accepted any marker and out-of-range fields exact lengths and markers; ranges checked; 30 otherwise parser
A partition number of ten digits overflowed a signed int and wrapped (CD4294967337// selected partition 41) saturated Suite11-PartitionNumberBound

Shared code changed, and why there

AGENTS.md rule 20 asks where a fix belongs. Each of these fixes the shared code, because the callers were written against the behaviour it is supposed to have.

Shared code Change Other callers affected Why not local
FileManager::delete_file, rename Answer FR_LOCKED for a file open for writing, or for a disk image with a file open inside it. FTP answers 550, the drive 60, the browser shows the error. With FF_FS_LOCK 0, closing the file writes its entry into the slot it had. A directory created in that slot became the volume root (found by the soak, present on master). Any client can be the writer. FF_FS_LOCK would also refuse a second open and cap open files everywhere.
FileManager::rename_impl Refuse moving a directory inside itself. Browser Move, FTP, REST FatFs does not check it, and the subtree becomes unreachable.
FileSystemCBM Enforce the read-only state at every write entry point; the DOS version byte lock; dir_set_label; name and id cut to 16 and 2 in set_volume_name. Every D64/D71/D81/DNP user The lock belongs to the image, so it has to hold for FTP and REST too. set_volume_name overwrote the DOS type with a long name.
x00_wrapper.cc (new) One reader for P00/S00/U00/R00 headers, shared by the drive, the browser and the loader. C64 loader, browser row, quick-seek, rename The loader loaded a P00 file's header to $3643, and the browser could not run a P00 file.
BrowsableDirEntry, S_rename Show and rename an x00 file by its header name. Every browser row (x00 rows only change) No FileType exists for S00, U00 or R00, so no type hook reaches those rows.
Keyboard_C64 (U2 family only) Scan from a 10 ms timer instead of in getch(). Every cartridge menu The UI task is away 40 to 115 ms; a 40 ms tap injected through the host's matrix was missed. On an Ultimate 64, keys for an open menu go to the UI queue, not the matrix, so its build keeps the old scan.
Sampler::reset() Set each voice's volume to 0. Every C64 reset A stopped voice holds its last sample in the mix (gateware behaviour), which left a DC offset and a click on freezer entry.
WiFi receive path Hand lwIP a copy of each frame and free the UART buffer at once. Every WiFi socket One unread socket could hold all 12 UART buffers and stop the interface (#820). Ethernet and USB keep zero-copy.
IecChannel::log_line() + itu.c Write each Software IEC log line whole, scheduler suspended. none; itu.c gains console_outbyte() Making every printf atomic needs a lock in code that also runs in interrupts, which the RTOS ports cannot detect.

Behaviour a user can notice

Behaviour Why
A host file with the FAT hidden attribute is left out of $ unless =H asks for it. CMD HD 9-20, sd2iec; it still answers to its name.
Secondary address 0 always reads, 1 always writes. SI-070, sd2iec file_open().
A three-number B-P uses the third number as the high byte. sd2iec large buffers.
A positioned write to a relative record past the end of the file starts at byte 1. sd2iec fat_file_seek(); SI-080.
The directory header shows the first 16 characters of a long partition name. Matches G-P and the partition list.
"IEC Drive" has three values: UCI Only (the old Disabled), Enabled, Disabled (off the bus and off UCI). A stored setting keeps its behaviour. #918
Loading a partition file replaces the partition list. #934
A file the drive has open for writing cannot be deleted or renamed over FTP (550). The corruption above.

Rejected alternatives

Alternative Why rejected
Enable FF_FS_LOCK instead of the FR_LOCKED check Refuses a second open of any file open for writing and caps open files in every FatFs caller.
Make every printf atomic Needs a lock usable in interrupts and before the scheduler starts.
Smaller lwIP mailbox for #820 Two connections could still hold every buffer.
Fix the sampler in gateware The Ultimate 64 core is a prebuilt binary.
Exact byte comparison in pattern matching Breaks lower case ASCII names a PC tool sends (Suite8).

Testing

Host

make in target/pc/linux/{parse,parse_unsigned,iecdrive,iecdrive_unsigned,iecdrive_asan}: all pass, AddressSanitizer included. Every defect has a named Suite11 or parser case, run against the code before its fix (fails) and after (passes).

All firmware targets build: u64, u64ii, u2, u2pl (./build-tool -s), and u2plus.

Devices

Ultimate 64 Elite (firmware over JTAG) and Ultimate II+L in a C64 Ultimate (flashed from the CI artifact of this branch). The C64 Ultimate runs its own 1.2RC firmware. All runs are on the final firmware 05046e0d, both devices at once, no retries. The Ultimate II+L runs the CI build of the PR merge commit b04f577c, whose tree is identical to 05046e0d (master has not moved).

Run Ultimate 64 Elite Ultimate II+L
Full run K: every E2E, soak and stress suite, deep profile, overlay mode, device log collected 80 of 80 79 of 80, see below
Full run L: the same 80 of 80 80 of 80
Software IEC suites (rel-copy, iec-dos-commands, uci-targets, softiec-soak) under JiffyDOS 4 of 4 4 of 4
The same under the UCI KERNAL with the Command Interface 4 of 4 4 of 4

The device checks for the four fixes of the last review failed on 39413642, the firmware before them, and pass on 05046e0d, on both devices:

Check in iec-dos-commands 39413642 05046e0d
P on a channel opened before W-1 00, OK, and the file grew to 256 bytes 26, the file is empty
Copy of relative files with 10- and 5-byte records 64, and RBOTH.rel was left behind 64, no target
FTP DELE of a D64 with a file open for writing inside deleted 550
R of an x00 file open for writing 60, but the header already named RENAMEDOPEN 60, the header is unchanged

The one failure in run K was the "enter a TAP index" row of browser-filesystem-refresh, run inside browser-refresh-leak on the Ultimate II+L. The Telnet browser kept showing imenu1.idx at 20 bytes for the 3 s allowance, while the menu, FTP and REST all showed 31. The same suite passed on its own in the same run, and the same kind of failure was recorded on this cartridge on 21 September, before these changes. The code involved is not changed by this PR. Each browser's event queue holds 8 events, and sendEventToObservers() drops an event without logging when the queue stays full for 5 ticks. A dropped final refresh would leave the Telnet view stale in this way; that has not been proven on the device.

Earlier on this branch: the four-hour softiec-soak passed on both devices; the exhaustive profile ran all three UI modes; network-connection passed on every machine and link.

Test harness changes (each fixes a cause of a failed or misleading run)
Suite or library Problem in the harness Change
iec-dos-commands Did not cover the commands and defects of this PR. Checks for T-W, S-9/S-D, M-W $0077 (KERNAL and CMD timing), W-1 (including P and an open channel), EL:$/EU:$ against the drive and FTP, LOAD lengths around 254/512 bytes, x00 renames, relative copy, delete of an open file or image, reset of a half-received command.
iec-dos-commands Moved the drive onto device 9 or 12 that a drive b could hold; a failed check left the drive on another number. Drives on those numbers are switched off for the run; the number is restored after a failed check.
iec-listen-timing (new) Nothing sent the CMD drives' bus timing. iec_talker.asm sends LISTEN transactions at CMD or KERNAL bit pace with chosen UNLISTEN pauses; 20 swaps; 60 random files. Fails if device 11 or 12 is taken.
iec-partition-file (new) #934 had no device test. Loads partition files through the browser and reads the drive list.
softiec-log-lines (new) Split log lines had no device test. 300 commands under concurrent REST load; every marked line must arrive whole, including a split inside the marker; fails if the REST load did not run.
rel-copy Read a stale 62 an earlier suite left as its first status. Reports that status as a warning, then resets with UI.
uci-targets #918 had no device test. The three "IEC Drive" values checked on the bus, at $DF1B and with IDENTIFY.
softiec-soak Excused a corruption on any drive reset, even one after the error; did not correlate the log on this bench; paired a log line with the wrong one of two identical commands. Excused only when a reset overlaps the step; reads the run's collected log; a required event outweighs an optional one.
run-tests, tests/lib/kernal.py No way to run the IEC suites under another KERNAL; a failed restore step skipped the rest. --kernal, --command-interface, checked against $E000; every restore step runs.
run-tests syslog collector A run stopped part-way left the menus in a listing, so the next run found no device address and filed every line as unknown. Discovery goes up to the menu root.
Browser and search-form facades Keys lost on the cartridge made menu steps fail. Typed text, popup keys and overlay selections are read back and retried, and each retry is reported as a warning.
input Echo checks depended on scenario order; memory was read through the cartridge. Reset before the echo program; memory read through the host computer; checks the host's 1.2RC firmware cannot pass (#880, #914) are tagged by host.
av-stream, streams.py A dual-homed device streams from its other interface, so no packet matched. A sender is accepted when its /v1/info unique id matches the target's.
ultimax-cartridge The golden frame is from video core 1.50; 1.4F scores 72.66% on every run. Skipped on an older core, with that reason.
prg-context-menu, prg-load-path-trim Did not know x00 files; found no listing root over Telnet on a cartridge. Selects the P00 row by its header name; reads the root from listing rows.
tape-playback A cartridge cannot finish a tape (no motor line); a menu read that took longer than the tape counted as a failure. Skipped on a cartridge; the time counted is the time the tape actually played.
network-connection Ran only on an Ultimate 64; counted socket-cap refusals as failures; retried data mismatches as long as refusals. Runs on every machine; refusals get up to 7.85 s, mismatches the old 1.85 s; a failed settings restore fails the run.
heap-leak, mount-cache-leak Counted another client's FTP session as a leak. Heap is read as the highest of 4 readings 1 s apart.
health.py One lost ping ended a run. Three attempts.
ident-leak, usb-keyboard-repeat Probed the target token instead of an address; failed without a Pico fixture. Probes the device address; skips without the fixture, as the other Pico suites do.
telnet-sustained-input 30 keys a second never reached the #820 state on a rested device. 50 keys a second; the #820 skip is removed.
telnet-stale-session, Telnet backend Assumed it owned every Telnet slot; re-learnt the cursor colour from screens without a listing. Reopens busy slots; learns the colour once.
printer Closed the menu while Flush/Eject was still writing. Waits for the progress dialog; stays skipped on the cartridge, whose menu is blocked for up to 70 s.
Recorder Numbered a still by slot, not by the frame the file holds; a partly written frame shifted every later frame. Finishes a started frame; a still carries its frame's position.
tools/softiec_traceability.py Missed test methods inside a Python class. Finds them; the specification's Appendix E is generated from it.

Not changed, with the reason

Finding Why not changed
A disk error during EL/EU/A answers 62 instead of the error. Cannot be triggered on a device; a fix could not be shown failing.
UJ and I answer 00/73 after a write refused under W-1. A 1541 resets the status on these commands too.
Cartridge keyboard scan: flag order in unfreeze() when the clock is lost, and in start_cartridge(); the deferral counter is not atomic. None can be made to happen on the bench, so no fix can be shown failing.
A case-only x00 rename writes the header while another handle writes the file. Needs the drive to rename a file it is writing; no report.
Quick-seek opens each x00 file in a folder to read its header name. One 26-byte read per row, cached per row; not measured as slow.
N in a mounted image does not hold the file manager lock. The window is a few instructions; not demonstrable.
Assembly 64 result rows with x00 files download the file to show its name. No such entry was found.
The U2+L bitstream is never rebuilt by CI (cache key on a missing file). CI problem outside this PR.
A browser's 8-event queue drops a file change without logging when it stays full for 5 ticks. Code on master that this PR does not touch; the one run K failure above is consistent with it but not proven.

The UCI KERNAL fix reaches users only when they build roms/c64rom or install an image built from it; the firmware image does not contain it. The KERNAL's jump table, vectors and checksum ($E0) are unchanged and 496 bytes of its segment stay free.

Verified on hardware: Ultimate 64 Elite, Ultimate II+L. Built but not run on hardware: Ultimate 64 II, Ultimate II+ (the keyboard scan change applies to both U2 variants).

Build size

Target Application space Used Headroom
U2 792.0 KiB 750.0 KiB 42.0 KiB
U64 1472.0 KiB 1218.3 KiB 253.7 KiB
U64 Elite II, 100T 1792.0 KiB 1191.3 KiB 600.7 KiB
U64 Elite II, 50T 1920.0 KiB 1191.3 KiB 728.7 KiB
U2+L 1408.0 KiB 1016.0 KiB 392.0 KiB
U2+ 1280.0 KiB 1033.3 KiB 246.7 KiB

…nd headers

SI-120 T-W, SI-101 S-8/S-9/S-D, SI-051 R-P, SI-064 R-H.
SI-077 EL/EU/EH/A/XH/D, SI-134 hidden entries left out of a listing.
SI-102 W-1 and W-0, enforced at every gate from the bus to a medium.
SI-090 ##n answers 70 beyond one buffer, SI-092 B-P takes a high byte.
SI-071a, through the file system that holds it open.
The reader moves to software/filetypes/x00_wrapper.cc, shared with the drive.
V, the raw directory, x00 creation and EL:$.
Also refuse an attribute command that carries no name.
SI-144b: the row shows the header name, and Run, Load and DMA act on the program
inside rather than refusing a file whose header is absent.
The REST runners and the browser both reach C64_DMA_LOAD, so both show the
name the C64 sees.
Repository owner deleted a comment from UltimateC64Ultimate64fan Sep 24, 2026
@chrisgleissner
chrisgleissner marked this pull request as draft September 25, 2026 08:12
@chrisgleissner
chrisgleissner marked this pull request as ready for review September 25, 2026 14:56
@chrisgleissner

Copy link
Copy Markdown
Collaborator Author

Hi @GideonZ ,

this SoftIEC follow-up PR is ready for review and merge after having spent countless hours on testing it against my Ultimate 64 Elite I and UII+L.

For full details, please have a look at the PR description which explains each change and is up-to-date.

Thank you.

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

Labels

3.15 Targeted for release 3.15. bug Existing behavior is incorrect, broken, or regressed; includes supported documentation defects. enhancement New functionality or an improvement to existing behavior, including formats and developer tooling. soft iec Software IEC device behavior, commands, device numbers, and compatibility; not drive emulation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telnet session is closed when the screen repaints faster than the link drains

1 participant