From 7f2ce5bce0180bd457fba0d6bbed8e5ce4df720e Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sat, 5 Sep 2026 13:50:04 -0500 Subject: [PATCH] iic: the expansion counter is on the board, and a IIc Plus boots its disk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A IIc Plus read its disk and printed ProDOS's banner and went no further. The drive was not the trouble: it had stepped to track eleven and read what it was asked for. What stopped it was the memory expansion interface. Twice on its way up the firmware sizes that memory. The first loop zeroes the address counter, writes the data register to carry it on, and waits for the middle byte to carry; the second sets the high byte to $0f, walks the counter back down three at a time, and waits for the high byte to reach nought. Neither leaves until the counter moves. The first needs the middle byte to read back with its top nibble set, the second needs the high byte to read back with its low nibble clear, and no one value an undriven bus could give satisfies both — which is the proof that the counter is not on the card at all. It is on the board, and it answers whether or not anybody fitted memory behind it. The card adds chips; the interface is the machine's. So a IIc Plus now comes up with that interface present and no memory in it, which is what a machine nobody has expanded is. The data register still reads undriven, because there is nothing behind it, and the sizing loops still find nothing — but they find it and move on instead of turning for ever. With that, ROM 5 boots all the way to the System Utilities the disk starts, which is the same place a IIgs reaches from the same image, with or without memory fitted. The decode also stops answering nought for the registers when no card is fitted. Nought is a value; nothing driving the lines is $ff, which is what `access` already answered for itself and what the firmware's sizing depends on being able to tell from a byte it wrote. Returning nought in front of it was what hung the first loop. The test now waits for the Utilities' own menu and its copyright as well as ProDOS's banner. None of that text — "PRODOS 8", "FastCopy", either copyright, "System Utilities" — is anywhere in the ROM, raw or with the high bit off, so it can only have been read off the disk and run. With the drive left empty it fails at the banner; with this change backed out it reaches the banner and fails at the menu. Verified: zig build check, zig build test, a full build, zig fmt and reuse lint green, zig build woz unchanged at 45 of 45 read, 42 boot, every other boot still passing, and every citation resolving. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01QcuxnjBzBhxoVduHTwEB51 --- README.md | 30 +++++++++++++++++++----------- src/memory8/apple2e.zig | 18 +++++++++++++++--- src/system_tests.zig | 14 +++++++++----- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 0e4d580..a13750f 100644 --- a/README.md +++ b/README.md @@ -276,17 +276,25 @@ the firmware fills it thirty-two bytes at a time with `LDX #$e0 / STA $cd21,X`, and `$cd21 + $ff` is `$ce20`, so every thirty-second byte lands one past the window — which is the next page, and reaching it is what carries the page on. Throw that byte away and each sector loses one in thirty-two, fails its -checksum and is read again for ever. Keep it and the disk reads: ProDOS loads -off the 3.5-inch drive and prints its own banner, which is text that appears -nowhere in the ROM. - -Two things are still open. Which of the glue's outputs is `3.5 DRIVE*` — the -one that says which kind of drive the port is talking to — is not settled; -what is modelled is a IIc Plus coming up pointed at the 3.5-inch drive built -into it, which is right for that drive and means a five-and-a-quarter drive on -the back of one is not reachable yet. And the boot stops at the ProDOS banner -rather than going on to what it would load next. The four-megahertz -accelerator is still to come, and is not in the way of any of this. +checksum and is read again for ever. Keep it and the disk reads. + +What then stopped it was not the drive at all but the memory expansion +interface. Twice on its way up the firmware sizes that memory, once walking +the address counter forward until the middle byte carries and once walking it +back until the high byte reaches nought, and it will not leave either loop +until the counter moves. No value an undriven bus could give satisfies both +tests, which is the proof that the counter is not on the card: it is on the +board, and it answers whether or not anybody fitted memory behind it. Model it +that way and a IIc Plus boots all the way to the System Utilities the disk +starts — the same place a IIgs reaches from the same image — with or without +memory fitted. + +One thing is still open. Which of the glue's outputs is `3.5 DRIVE*` — the one +that says which kind of drive the port is talking to — is not settled; what is +modelled is a IIc Plus coming up pointed at the 3.5-inch drive built into it, +which is right for that drive and means a five-and-a-quarter drive on the back +of one is not reachable yet. The four-megahertz accelerator is still to come, +and is not in the way of any of this. Nothing else needs a ROM. The block device in slot 7, the clock card, the mouse card and the Mockingboard all answer with firmware written for this diff --git a/src/memory8/apple2e.zig b/src/memory8/apple2e.zig index 460271c..73640bb 100644 --- a/src/memory8/apple2e.zig +++ b/src/memory8/apple2e.zig @@ -1045,7 +1045,20 @@ fn Machine(comptime kind: Kind, comptime options: Options) fn (type) type { // except on a IIc, where there is no firmware page to // touch and the card is wired to answer always. self.memory_card.reset(); - if (comptime kind == .iic) self.memory_card.enabled = true; + if (comptime kind == .iic) { + self.memory_card.enabled = true; + // On a IIc Plus the expansion interface is on the + // board, not on the card: the address counter answers + // whether or not anybody fitted memory behind it, and + // the firmware's two sizing loops prove it. The first + // (`$da4e`) walks the counter up and leaves only when + // the middle byte carries; the second (`$d9af`) walks + // it down and leaves only when the high byte reaches + // nought. No single value an undriven bus could give + // satisfies both, so the counter cannot be absent. + // Read out of the ROM 5 firmware at $da4e and $d9af. + if (self.mig_fitted) self.memory_card.fitted = true; + } self.card_switches.reset(); self.altzp = false; self.ramrd = false; @@ -1992,8 +2005,7 @@ fn Machine(comptime kind: Kind, comptime options: Options) fn (type) type { // p. 7); the rest of the sixteen it does not // decode, which `access` answers for itself. if (comptime kind == .iic) { - if (!self.memory_card.fitted) return 0; - if (low > memory_expansion_switch_base + 3) return 0; + if (low > memory_expansion_switch_base + 3) return ramfactor.undriven; return self.memory_card.access( @truncate(address & 0x0f), is_write, diff --git a/src/system_tests.zig b/src/system_tests.zig index 2d92008..5703e38 100644 --- a/src/system_tests.zig +++ b/src/system_tests.zig @@ -773,7 +773,7 @@ test "an Apple IIc Plus runs its firmware instead of falling into the Monitor" { try testing.expect(written > 0); } -test "an Apple IIc Plus reads its internal 3.5-inch drive and boots ProDOS" { +test "an Apple IIc Plus boots its internal 3.5-inch drive to the System Utilities" { const alloc = testing.allocator; // ROM 5 talks to the drive built into the case as a 3.5-inch drive: the // phase lines stop being magnets and become an address, with SEL for a @@ -796,12 +796,16 @@ test "an Apple IIc Plus reads its internal 3.5-inch drive and boots ProDOS" { system.cpu.memory.disk.disks35.insert(0, floppy); system.cpu.reset(); - // It reads the disk and runs what it finds there: ProDOS loads off the - // 3.5-inch drive and prints its own banner. None of that text is in the - // ROM — not "PRODOS 8", not the date, not the copyright — so it can only - // have been read off the disk through the drive and executed. + // It reads the disk and runs what it finds there, all the way to the + // program the disk starts: ProDOS loads off the 3.5-inch drive, and the + // System Utilities put up their own menu. None of that text is in the + // ROM — not "PRODOS 8", not "FastCopy", not either copyright — so it can + // only have been read off the disk through the drive and executed. It is + // the same place the IIgs reaches from the same image. try system.waitFor("PRODOS 8", 120 * second); try system.expect("COPYRIGHT APPLE COMPUTER, INC., 1983-90"); + try system.waitFor("FastCopy", 300 * second); + try system.expect("Copyright Apple Computer, Inc. 1987-90"); // And it got there by working the drive. const drives35 = &system.cpu.memory.disk.disks35; -- knotmirror 0.0.1