From 3ad7ee877bc4a2439c8d1973f2edfd962299716b Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sat, 5 Sep 2026 17:21:49 -0500 Subject: [PATCH] iic: the drive on the back is the drive number, and a IIc Plus boots it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The other axis of the disk port turns out not to be a latch. A IIc Plus keeps its internal and its external 3.5-inch drive both on port 5 and tells them apart by drive number — "internal 3.5-inch drive at $C500 (port 5, drive 1)" against "external UniDisk 3.5 or Apple 3.5 drive at $C500 (port 5, drive 2)" (Apple Computer, Inc., 1989b, p. 86) — so the port says which *kind* of drive and the drive number says *whose*, and the drive number is the IWM's own. The glue chip's pins agree: `INTEN*` is "a latched output bit to enable internal drive" and `ENB2` "follows EN2X* or ROMEN1* if addressing mapped device space to select external drives" (Table 11-15, p. 328), one enable line each, the second being the IWM's ENABLE2 qualified by the address decode. So nothing had to be built; what was missing was the proof, and there is now a system test that boots a IIc Plus to the System Utilities with its only disk in the drive on the back and the drive in the case left empty. Ignore the drive select and the test stops reaching ProDOS at all. A five-and-a-quarter drive on the back is still out of reach, and three guesses at what writes `3.5 DRIVE*` were measured and buried. Not the address executed from: the port-6 driver straddles `$C100-$DFFF`, stepping the head and running its read loop inside that space while the instruction that starts the motor runs outside it. Not the port address: with a five-and-a-quarter disk in the machine, `$C0Ex` is the only page the firmware ever touches, never `$C0Dx`. Not a write against a read on the SEL pair: both polarities break the 3.5-inch path. With such a disk present the firmware still touches only the five glue addresses already spoken for and never the three that are not. Reading the pinout closely did settle something. Every address line the chip has is on it — A5, A6, A7 to pick the register, A9, A10, A11 to place it (Figure 11-13, p. 327) — and A8 is not, so it cannot tell `$ce00` from `$cf00` and answers across both pages. Bank 1 of the ROM says the same from the other side: five hundred and twelve zero bytes there, two pages of hole rather than one. The window is that wide now, with a test for the aliasing. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01GgsYL8D46Cd7iQEZG7Z76J --- README.md | 64 ++++++++++++++++++++++++++--------------- src/memory8/apple2e.zig | 16 ++++++++--- src/mig.zig | 44 +++++++++++++++++++++++++--- src/system_tests.zig | 54 ++++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index f5429b8..236dbfd 100644 --- a/README.md +++ b/README.md @@ -289,29 +289,47 @@ 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. -A five-and-a-quarter drive on the back of a IIc Plus is not reachable yet, and -the reason is worth setting down, because looking for it in the wrong place -costs a day. The obvious guess is that some address latches `3.5 DRIVE*`, the -output that says which kind of drive the port is talking to, and that finding -it is all that stands in the way. It is not. The firmware touches five of the -glue chip's addresses and every one of them is spoken for — the window on its -RAM, stepping the page, putting the page back, and the pair that work the SEL -line — and nothing in either bank of the ROM ever writes anything else that -could be it. - -The table of the chip's pins says why, once it is read carefully. It lists two -different selections, and they are at right angles to each other. `3.5 DRIVE*` -is "a latched output bit to select 5.25-inch or 3.5-inch drives", while `ENB2` -"follows `EN2X*` or `ROMEN1*` if addressing mapped device space to select -**external** drives" (Apple Computer, Inc., 1989b, Table 11-15, p. 328) — one -says which *kind* of drive, the other says *whose*. A IIc Plus has one drive -built into it and it is always a 3.5-inch one, so the kind never changes and -the firmware has no reason to write that latch at all: it comes up pointed at -the drive it has, which is what is modelled here and is right for that drive. -What an external five-and-a-quarter drive wants is the other axis, inside and -outside, which this emulator's disk port does not have. So the work is not -hunting a latch bit that may never be written; it is giving the port a notion -of an outside. +The disk port now has a notion of an outside, and it turned out not to be a +latch at all. A IIc Plus lists four places it will start from, and two of them +are 3.5-inch drives that differ only in where they are: the "internal 3.5-inch +drive at $C500 (port 5, drive 1)" and the "external UniDisk 3.5 or Apple 3.5 +drive at $C500 (port 5, drive 2)" (Apple Computer, Inc., 1989b, p. 86). The +port is the *kind* of drive and the drive number is *whose* — and the drive +number is the IWM's own, so the drive on the back is reached by selecting drive +two and changing nothing else. The glue chip's pins say the same from the other +side: it carries `INTEN*`, "a latched output bit to enable internal drive", +against `ENB2`, which "follows `EN2X*` or `ROMEN1*` if addressing mapped device +space to select **external** drives" (Table 11-15, p. 328) — one enable each, +the second being the IWM's ENABLE2 qualified by the address decode so that it +is driven only during an access that really is the port's. A system test boots +a IIc Plus to the System Utilities with the only disk in the drive on the back +and the drive in the case left empty. + +A five-and-a-quarter drive on the back is still out of reach, and the reason is +worth setting down, because looking for it in the wrong place costs a day. That +one does want `3.5 DRIVE*`, the "latched output bit to select 5.25-inch or +3.5-inch drives" (Table 11-15, p. 328), because a IIc Plus has one drive built +into it and it is always a 3.5-inch one, so the kind never changes and the +machine comes up pointed at the drive it has. Three guesses at what writes that +latch have now been measured and none of them survived. It is not the address +being executed from: `ROMEN1*` marks an access to `$C100-$DFFF`, and the port-6 +driver straddles the boundary — its head stepping and its read loop run inside +that space while the very instruction that starts the motor runs outside it, so +no split by address can separate one driver from the other. It is not the port +address either: with a five-and-a-quarter disk in the machine and the firmware +spinning on the boot PROM, `$C0Ex` is the only page it ever touches, never +`$C0Dx`. And it is not a write as against a read on the SEL pair: making those +writes latch the kind breaks the 3.5-inch path in both polarities. With a +five-and-a-quarter disk present the firmware still touches only the five glue +addresses that are already spoken for, and never the three that are not. + +Reading the pins closely did settle one thing about the chip. Every address +line it has is in its pinout — A5, A6 and A7 to pick the register, A9, A10 and +A11 to place it (Figure 11-13, p. 327) — and A8 is not among them, so it cannot +tell `$ce00` from `$cf00` and answers across both pages. The ROM agrees from +the other side: bank 1 leaves five hundred and twelve zero bytes there, two +pages of hole rather than one, because both belong to the chip. The window is +modelled that wide now. The four-megahertz accelerator is still to come, and what is worth saying is why it is not a switch. It is a cache. The machine has a 65C02 clocked at four diff --git a/src/memory8/apple2e.zig b/src/memory8/apple2e.zig index 73640bb..442c965 100644 --- a/src/memory8/apple2e.zig +++ b/src/memory8/apple2e.zig @@ -1031,13 +1031,21 @@ fn Machine(comptime kind: Kind, comptime options: Options) fn (type) type { // Which of the glue's latched outputs is `3.5 DRIVE*` // — "latched output bit to select 5.25-inch or // 3.5-inch drives" (Table 11-15, p. 328) — is not - // settled. The firmware touches only four of the - // chip's eight registers, and all four are accounted - // for: two move the RAM window and two are SEL. So + // settled. The firmware touches only five of the + // chip's eight registers, and all five are accounted + // for: three move the RAM window and two are SEL. So // what is modelled is the machine coming up pointed at // the drive it has, which is right for that drive and // is why a five-and-a-quarter drive on the back of a - // IIc Plus is not reachable yet. See `mig.zig`. + // IIc Plus is not reachable. See `mig.zig`. + // + // The *other* axis, inside against outside, is not + // this latch and needs nothing here. A IIc Plus keeps + // its internal and external 3.5-inch drives both on + // port 5 and tells them apart by drive number (Apple + // Computer, Inc., 1989b, p. 86), which is the IWM's + // own selection; the glue's part is only `INTEN*` + // against `ENB2`, one enable line each. self.disk.three_and_a_half = self.mig_fitted; } // And a memory expansion card stops answering at its diff --git a/src/mig.zig b/src/mig.zig index 1d1169d..756698b 100644 --- a/src/mig.zig +++ b/src/mig.zig @@ -43,11 +43,19 @@ pub const window_size = 32; /// supplies can reach. pub const pages = ram_size / window_size; -/// Where the chip answers, and how wide. The firmware's hole is a page, and -/// the three address lines above the window — A5, A6 and A7 (Apple Computer, -/// Inc., 1989b, Table 11-15, p. 328) — divide that page into eight. +/// Where the chip answers, and how wide. The three address lines above the +/// window — A5, A6 and A7 — divide the space into eight registers, and A9, +/// A10 and A11 are what place it (Apple Computer, Inc., 1989b, Figure 11-13 +/// and Table 11-15, pp. 327-328). +/// +/// Those six are every address line the chip has. **A8 is not among them**, +/// so the chip cannot tell `$ce00` from `$cf00` and answers across both +/// pages, each register appearing at two addresses. The firmware's ROM says +/// the same thing from the other side: bank 1 leaves `$ce00-$cfff` as five +/// hundred and twelve zero bytes, two pages of hole rather than one, because +/// both are the chip's rather than the ROM's. pub const base = 0xce00; -pub const size = 0x100; +pub const size = 0x200; /// Which of the eight the address falls in. const Register = enum(u3) { @@ -201,3 +209,31 @@ test "the two select addresses put the SEL line up and down" { mig.reset(); try testing.expect(!mig.sel); } + +test "the chip has no A8 and so answers the same at $cf00 as at $ce00" { + // Every address line the chip is given is in its pinout: A5, A6 and A7 + // pick the register, A9, A10 and A11 place the whole thing (Apple + // Computer, Inc., 1989b, Figure 11-13, p. 327). A8 is not there, so it + // cannot be decoded, and the second page is the first one again rather + // than anything of its own. + var mig: Mig = .{}; + + // SEL, reached at the high page, moves as it does at the low one. + _ = mig.access(0xcf60, false, 0); + try testing.expect(mig.sel); + _ = mig.access(0xcf40, false, 0); + try testing.expect(!mig.sel); + + // And so does the window: a byte put in through one page is the same + // byte read back through the other, at the same place in the buffer. + _ = mig.access(0xcf05, true, 0xa3); + try testing.expectEqual(@as(u8, 0xa3), mig.ram[5]); + try testing.expectEqual(@as(u8, 0xa3), mig.access(0xce05, false, 0)); + + // Stepping and homing are the same switches through either page, which + // is what would go wrong if A8 were being decoded after all. + _ = mig.access(0xcf20, false, 0); + try testing.expectEqual(@as(u6, 1), mig.page); + _ = mig.access(0xcea0, false, 0); + try testing.expectEqual(@as(u6, 0), mig.page); +} diff --git a/src/system_tests.zig b/src/system_tests.zig index 11a7927..b297c68 100644 --- a/src/system_tests.zig +++ b/src/system_tests.zig @@ -899,6 +899,60 @@ test "an Apple IIc Plus boots its internal 3.5-inch drive to the System Utilitie try testing.expect(drives35.drives[0].spindle); } +test "an Apple IIc Plus boots the 3.5-inch drive on the back rather than the one in the case" { + // The other axis of the disk port: not which *kind* of drive, but + // *whose*. A IIc Plus lists four places it will start from, and two of + // them are 3.5-inch drives that differ only in where they are — "internal + // 3.5-inch drive at $C500 (port 5, drive 1)" and "external UniDisk 3.5 or + // Apple 3.5 drive at $C500 (port 5, drive 2)" (Apple Computer, Inc., + // 1989b, p. 86). + // + // That difference is the IWM's own pair of enable lines rather than + // anything the glue latches. The MIG carries `INTEN*`, a "latched output + // bit to enable internal drive", against `ENB2`, which "follows EN2X* or + // ROMEN1* if addressing mapped device space to select external drives" + // (Table 11-15, p. 328) — one enable each, the second of them the IWM's + // ENABLE2 qualified by the address decode so that it is driven only + // during an access that is really the port's. So the drive on the back is + // reached by selecting drive two, and nothing else about the port + // changes. + const alloc = testing.allocator; + const rom = try catalogued(alloc, .roms, "Apple IIc ROM 05 - IIc Plus.bin"); + defer alloc.free(rom); + const file = try catalogued(alloc, .disks, "Apple II System Disk 3.2 on 800k image.2mg"); + defer alloc.free(file); + const opened = try diskfile.open(alloc, file, "system.2mg"); + defer opened.deinit(alloc); + const floppy = try alloc.create(disk35.Floppy); + defer alloc.destroy(floppy); + floppy.* = .{}; + try floppy.load(opened.image.data); + + var system = try powerOn(cpu8.CMOS, memory.AppleIIc(.{}), rom); + // Drive two, and only drive two. The drive in the case is left empty on + // purpose: it is the control, and it is what makes this test say anything + // the one above does not. If the port ignored the drive select and always + // reached the internal drive, there would be no disk there to read and + // the machine would sit waiting for one. + system.cpu.memory.disk.disks35.insert(1, floppy); + system.cpu.reset(); + + // Same destination as the internal test, by a different door: ProDOS off + // the disk, then the System Utilities' own menu. None of that text is in + // the ROM — not "PRODOS 8", not "FastCopy", not the copyright — so it + // came off the disk, and the only disk is the one on the back. + try system.waitFor("PRODOS 8", 120 * second); + try system.expect("COPYRIGHT APPLE COMPUTER, INC., 1983-90"); + try system.waitFor("FastCopy", 300 * second); + + // And the drive that turned is the outside one, while the empty drive in + // the case holds nothing to have read. + const drives35 = &system.cpu.memory.disk.disks35; + try testing.expect(drives35.commanded > 0); + try testing.expect(drives35.drives[1].spindle); + try testing.expect(drives35.drives[0].floppy == null); +} + test "an Apple IIgs formats a blank 3.5-inch disk and what it lays down is a volume" { // The last unexercised corner of the 3.5-inch path. Writing a file rewrites // one sector of a disk somebody else formatted; this lays every track down -- knotmirror 0.0.1