diff --git a/README.md b/README.md index c652288..5dcecfa 100644 --- a/README.md +++ b/README.md @@ -574,12 +574,30 @@ its only disk in the drive in the case and the other in the drive on the back, and only with the select the right way about do both of their names describe what they actually do. -A IIc Plus still will not format a disk, but the reason has moved and is no -longer a mystery about which drive is which. It now picks the right one — the -blank on the back, the machine's own disk left alone — and then never writes to -it, which is the same thing that stops an unrecorded surface being read: there -are no address marks on a blank disk to find, and this firmware looks for them -without giving up. +A IIc Plus will now format a disk, and gets most of the way through one. What +was in the way was not the machine at all but the blank being offered to it. + +A disk with nothing on it was filled here with `$ff` and called self-sync, and +that is wrong twice over: self-sync is what the *gaps on a formatted disk* +hold, and a blank that hands out `$ff` for ever gives a firmware hunting an +address mark nothing to give up on. What an unrecorded surface really reads as +is noise — the head hears the amplifier, exactly as it does between two tracks +on a five-and-a-quarter disk, which is what `fakeBit` has always made there. A +IIgs copes with either and formats regardless. A IIc Plus, whose hunt for a +`D5` at bank 1 `$e0cd` has no counter in it, sat in that loop for ever. Given +noise it gives up on reading and lays the surface down instead, and the tests +that make blanks now make them the way a drive would find them. + +What it lays down is half a disk. Eight hundred of the sixteen hundred blocks +are written and eight hundred are not, in an alternating pattern twelve blocks +long — which is one track's worth of sectors on the outermost zone, so it is +writing one side of every track and not the other. The head is chosen by +reading register one or three, and reading both sides plainly works, since this +machine boots an eight hundred kilobyte disk that spans them. Writing them does +not. `HDSEL`, the glue chip's "latched output bit used for 3.5-inch drives", is +the obvious suspect and was tried — the spare writes on the SEL pair, made to +drive the head — and it stops the format finishing at all, so it is not that +either. The test for it is written and kept out of the tree until it passes. That last point has since been read from both ends, because it is the one that decides whether the latch is reachable at all. Statically, no instruction in diff --git a/src/system_tests.zig b/src/system_tests.zig index 03db750..d4057ee 100644 --- a/src/system_tests.zig +++ b/src/system_tests.zig @@ -1058,12 +1058,24 @@ test "an Apple IIgs formats a blank 3.5-inch disk and what it lays down is a vol floppy.write_protected = false; // And the blank: not an image loaded from anywhere, but an unrecorded - // surface. Self-sync is what an erased disk reads as, and there is not an - // address mark anywhere on it. + // surface, with no address mark anywhere on it. + // + // What that reads as is noise — the head hears the amplifier, the same as + // it does between two tracks on a five-and-a-quarter disk, which is what + // `fakeBit` makes there on the WOZ reference's authority (Morris, 2018). + // It used to be filled with `$ff` here and called self-sync, and that was + // wrong twice over: self-sync is what the *gaps on a formatted disk* hold, + // and a blank that hands out `$ff` for ever gives a firmware hunting an + // address mark nothing to give up on. A IIgs copes either way. A IIc Plus + // does not, and would not format such a disk at all. const blank = try alloc.create(disk35.Floppy); defer alloc.destroy(blank); blank.* = .{}; - @memset(&blank.nibbles, 0xff); + var noise: u32 = 0x2545f491; + for (&blank.nibbles) |*byte| { + noise = noise *% 1664525 +% 1013904223; + byte.* = @truncate(noise >> 16); + } blank.write_protected = false; const CPU = cpu16.Chip(.{}, clock.FakeClock, memory16.AppleIIgs(.{})); @@ -1150,6 +1162,16 @@ test "an Apple IIgs formats a blank 3.5-inch disk and what it lays down is a vol std.debug.print("{d} of {d} blocks were never written, from block {d}\n", .{ missing, rendered.len / prodos.block_size, first_missing, }); + std.debug.print(" first missing: ", .{}); + var shown: usize = 0; + var b: usize = 0; + while (b * prodos.block_size < rendered.len and shown < 24) : (b += 1) { + if (std.mem.allEqual(u8, rendered[b * prodos.block_size ..][0..prodos.block_size], sentinel)) { + std.debug.print("{d} ", .{b}); + shown += 1; + } + } + std.debug.print("\n", .{}); return error.TheMachineLeftPartOfTheDiskUnformatted; } @@ -1197,12 +1219,18 @@ test "an Apple IIgs reads back through the drive a disk it formatted itself" { floppy.* = .{}; try floppy.load(opened.image.data); - // Nothing on it: self-sync and no address mark anywhere, as a disk that - // has never been formatted reads. + // Nothing on it: no address mark anywhere, and the amplifier's own noise + // where a recorded surface would have flux, which is how a disk that has + // never been formatted reads. See the test above for why that is noise + // rather than a run of ones. const blank = try alloc.create(disk35.Floppy); defer alloc.destroy(blank); blank.* = .{}; - @memset(&blank.nibbles, 0xff); + var noise: u32 = 0x2545f491; + for (&blank.nibbles) |*byte| { + noise = noise *% 1664525 +% 1013904223; + byte.* = @truncate(noise >> 16); + } blank.write_protected = false; const CPU = cpu16.Chip(.{}, clock.FakeClock, memory16.AppleIIgs(.{}));