From fb90215a7bfcaba2499e521bed4bccc2b4e10ab5 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Thu, 3 Sep 2026 01:01:45 -0500 Subject: [PATCH] the shifter and the data register are two things Take 1 stopped booting when the head was made to wait for the processor, and the fix is not a compromise between two bad options but the removal of the thing that made them the only two. The mistake was holding a finished byte in the shifter itself. That forces a choice. Drop the bits that go past while it waits and byte alignment is lost -- and with it every disk in the reference set, which is what happened the moment the bit timing became right. Stop the head instead and alignment is kept, but a head that stops turning is exactly what a cross-track check measures, which is what cost Take 1. There is no need to choose. The shifter never stops: a bit goes in every bit time, and a zero shifted into an empty shifter leaves it empty, so a run of zeroes costs nothing and the next one bit begins a byte. That is why every legal nibble has its high bit set, and why the two extra zeroes in a self-sync byte put a lost reader back in step. When the shifter finishes a byte it hands it to a data register and starts the next one on that boundary, and the processor reads the data register. So the head goes on turning while a byte waits to be collected, and alignment cannot be lost. A processor too slow to come back loses the byte, which is what a real one does, rather than its place, which a real one does not. Nineteen of the twenty-one boot, up from eighteen, and Take 1 is the only disk that changed -- checked across the whole set rather than on the one disk this was aimed at, since this part of the drive has broken everything once already. Bouncing Kamungas and Wings of Fury are what is left. The readme has a lead on the second: the "offset data streams" tier is about programs that reset the data register part way through a nibble with LDA $C08D,x, so the stream comes in offset from the normal byte starts, and Wings of Fury is one of its two tests. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01LGTyJ7dpf3LT6aU9icQwkV --- README.md | 46 +++++++++++++++++++++++----------------------- src/disk2.zig | 39 ++++++++++++++++++++++++++++----------- woz/src/main.zig | 2 +- 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 7c2e473..55ee092 100644 --- a/README.md +++ b/README.md @@ -458,8 +458,7 @@ Their readme is the scoresheet: | | DOS 3.2 System Master | runs, given the thirteen-sector PROM | | copy protection | Commando, Planetfall, Rescue Raiders, Sammy Lightfoot, Stargate | run | | | Bouncing Kamungas | does not | -| cross-track synchronisation | Blazing Paddles | runs | -| | Take 1 | does not, and did before | +| cross-track synchronisation | Blazing Paddles, Take 1 | run | | a track two tracks wide | Hard Hat Mack | runs | | half tracks | The Bilestoad | runs | | soft-switch trickery | Dino Eggs, Crisis Mountain, Miner 2049er II | run | @@ -469,7 +468,7 @@ Their readme is the scoresheet: | | Wings of Fury | does not | | non-standard bit timing | Border Zone | runs | -Eighteen of the twenty-one boot. +Nineteen of the twenty-one boot: all but Bouncing Kamungas and Wings of Fury. How long a bit cell is comes from the disk and not from the drive, which is not obvious and is the whole reason WOZ carries the number. Four microseconds was @@ -483,26 +482,22 @@ Border Zone boots because of it, and two others came along: Planetfall and Miner 2049er II. Getting there needed something else fixed first, which is worth setting out because it is the least comfortable thing in this drive. -**The head waits for the processor.** When a byte has been assembled and not -yet collected, the head stops where it is instead of turning on. A real disk -does no such thing: it keeps turning, the bits that go past an unread byte are -gone, and the shifter is then part way into the next byte so everything reads -as a smear of two until a gap puts it right. Working firmware never gets into -that state, because the read loop is built to come back for each byte inside -one byte time. - -The trouble is that modelling the loss exactly wants the head advanced a bit at -a time, and the drive is only asked how far it has got when the machine touches -the card — about every seven cycles, which is nearly two bits. Rounding that up -or down loses or invents bits the machine never saw. Left to drop them, every -disk in the reference set stopped booting the moment the timing became right. -Waiting is the honest approximation of firmware that keeps up, and what it -costs is a program that deliberately reads late and expects to see the damage. - -It cost one, and the suite said so rather than letting the average hide it: Take -1 booted before this and does not now. It is a cross-track disk, and a head that -stops turning is exactly what a cross-track check is measuring, so that is the -first place to look. +**The shifter and the data register are two things.** The shifter never stops: +a bit goes in every bit time, and a zero shifted into an empty shifter leaves it +empty, so a run of zeroes costs nothing and the next one bit begins a byte — +which is why every legal nibble has its high bit set, and why the two extra +zeroes in a self-sync byte put a lost reader back in step. When the shifter +finishes a byte it hands it to the data register and starts the next one *on +that boundary*, and the processor reads the data register. + +Keeping those apart is what lets the head go on turning while a byte waits to be +collected. A processor too slow to come back loses the byte, which is what a +real one does; it does not lose its place, which a real one does not. The first +attempt at this held the finished byte in the shifter itself, which meant +choosing between dropping the bits that went past — losing alignment, and with +it every disk in the set — and stopping the head, which kept alignment but cost +Take 1, a cross-track disk measuring exactly the thing a stopped head breaks. +Two registers need neither compromise. DOS 3.2 is worth a note, because it looked like a failure and was not. Thirteen sectors a track is a different encoding and a different boot PROM — five and @@ -513,6 +508,11 @@ format's reference is explicit that the field is there to "assist emulators in determining which P5 ROM variant to load". So `--disk-rom-13` supplies the earlier PROM and the disk picks it for itself. +Two are left. The readme's note on one of them is a lead: the "offset data +streams" tier is about programs that reset the data register part way through a +nibble with `LDA $C08D,x`, so the stream comes in offset from the normal byte +starts, and Wings of Fury is one of its two tests. + The cross-track pair is the one the readme makes a point of: "they both do a crazy cross track check when they boot up. If you get to the main menu of these, then consider yourself a winner." Of Hard Hat Mack it says "being able diff --git a/src/disk2.zig b/src/disk2.zig index 6b103c3..7529897 100644 --- a/src/disk2.zig +++ b/src/disk2.zig @@ -726,11 +726,24 @@ pub const Drive = struct { /// How far round the disk has turned, as a bit position in the track under /// the head. Bits, because that is what goes past it. position: u32 = 0, - /// The read shifter: bits go in at the bottom and a byte is ready when the - /// top one is set, which is the whole of how a nibble is recognised. A - /// self-sync byte's two extra zero bits are absorbed here rather than - /// becoming part of anything, which is what lets a reader find its place. + /// The read shifter: bits go in at the bottom and a byte is finished when + /// the top one is set, which is the whole of how a nibble is recognised. + /// + /// It never stops. A zero shifted into an empty shifter leaves it empty, + /// so a run of zeroes costs nothing and the next one bit starts a byte — + /// which is why every legal nibble has its high bit set, and why a + /// self-sync byte's two extra zeroes put a lost reader back in step. latch: u8 = 0, + + /// The byte the processor reads, which is the last one the shifter + /// finished. + /// + /// Keeping it apart from the shifter is what lets the head go on turning + /// while a byte waits to be collected. The shifter starts the next byte at + /// the boundary the last one ended on, so nothing can knock it out of step; + /// a processor too slow to keep up loses the byte, which is what a real one + /// does, rather than losing its place, which a real one does not. + data: u8 = 0, /// The last four bits off the surface, for spotting the runs of nothing a /// cleaned image leaves behind. window: u8 = 0, @@ -883,10 +896,15 @@ pub const Drive = struct { // stops reading. Waiting is the honest approximation of firmware // that keeps up, and what it costs is a program that deliberately // reads late and expects to see the damage. - if (self.latch & 0x80 != 0) return; const value = if (from) |t| self.nextBit(t) else self.fakeBit(); self.position = (self.position + 1) % @max(1, length); self.latch = (self.latch << 1) | value; + if (self.latch & 0x80 != 0) { + // Finished. It goes where the processor can read it and the + // shifter starts the next one, exactly on the boundary. + self.data = self.latch; + self.latch = 0; + } } } }; @@ -1062,12 +1080,11 @@ pub const Controller = struct { self.spin(cycles); const disk = self.current(); if (disk.floppy == null) return 0; - const value = disk.latch; - // A byte the processor has taken is a byte the shifter starts again - // after. One it has not finished assembling is handed over as it - // stands, high bit clear, which is exactly what the firmware's read - // loop is waiting to not see. - if (value & 0x80 != 0) disk.latch = 0; + const value = disk.data; + // Taking it empties the register, so the read loop has something to + // wait on: until the shifter finishes the next byte there is nothing + // there, and nothing there is a high bit clear. + disk.data = 0; self.latch = value; return value; } diff --git a/woz/src/main.zig b/woz/src/main.zig index ac9fc96..48bb191 100644 --- a/woz/src/main.zig +++ b/woz/src/main.zig @@ -97,7 +97,7 @@ const disks = [_]Disk{ .{ .file = "Stargate - Disk 1, Side A.woz", .tier = .protection, .boots = true }, .{ .file = "Blazing Paddles (Baudville).woz", .tier = .cross_track, .boots = true }, - .{ .file = "Take 1 (Baudville).woz", .tier = .cross_track, .boots = false, .note = "booted until the head was made to wait for the processor" }, + .{ .file = "Take 1 (Baudville).woz", .tier = .cross_track, .boots = true }, .{ .file = "Hard Hat Mack - Disk 1, Side A.woz", .tier = .wide_track, .boots = true }, -- knotmirror 0.0.1