# Memory map, bus glue, the interleave, interrupts The 128K/512K/Plus glue is a set of PALs (the TSM, BMU0/1, LAG, TSG, ASG, named in the 1983 prototype's PAL dumps on bitsavers); the SE folds them into the BBU custom chip (DOC: GMFH ch. 3). The board models what they do, from Apple's documents; the PAL contents are not used (open decision 6). ## The map (Plus; 128K/512K the same with no SCSI) From GMFH Figure 3-2 (p. 124), checked against IM3 III-17, III-43..45 and IM4 IV-246, IV-253: | Range | Normal map (overlay = 0) | Power-up map (overlay = 1) | Acknowledge | | --- | --- | --- | --- | | $000000-$3FFFFF | RAM (1/2/2.5/4 MB; unused space repeats RAM images) | ROM image at $000000 (repeated up to $0FFFFF), nothing at $100000-$3FFFFF | /DTACK | | $400000-$4FFFFF | ROM (128K, repeated; "128 KB ROMs are disabled everywhere A17=1", i.e. a 128K ROM appears at $400000 and $440000 is a repeat only in the 256K case) | the same | /DTACK | | $500000-$57FFFF | reserved / no device | | /DTACK | | $580000-$5FFFFF | SCSI: reads at even addresses (A0=0), writes at odd (A0=1); register = A6-A4, DACK = A9 | the same | /DTACK | | $600000-$7FFFFF | no device | **RAM** (the overlay moves RAM here: $600000 in IM3's 128K/512K, the upper row only on 2.5 / 4 MB Plus) | /DTACK | | $800000-$9FFFFF | SCC read (A0=0) / SCC reset (A0=1) / **phase adjust (any word access)** | the same | /DTACK | | $A00000-$BFFFFF | SCC write (A0=1) / phase adjust (word) | the same | /DTACK | | $C00000-$DFFFFF | IWM (A0=1, the low byte; register = A12-A9) | the same | /DTACK | | $E00000-$E7FFFF | reserved | | /VPA | | $E80000-$EFFFFF | VIA (A0=0, the high byte; register = A12-A9) | the same | /VPA | | $F00000-$F7FFFF | **phase read** | the same | /VPA | | $F80000-$FFFFEF | reserved / no device | | /VPA | | $FFFFF0-$FFFFFF | interrupt acknowledge (autovector) | | /VPA | - **Every access is acknowledged**: the PALs answer $000000-$DFFFFF with /DTACK and $E00000-$FFFFFF with /VPA, even where no device is (DOC: GMFH pp. 122-123). So there is no bus error on these machines from unmapped space (the open-bus value read there is U1). - **Byte lanes**: the SCC is on the upper byte (even reads; a byte read of an odd SCC read address "tries to reset the entire SCC"; writes at odd addresses work because the 68000 drives both bytes), the IWM on the lower byte (odd), the VIA on the upper byte (even) (DOC: IM3 III-25, III-34, III-39). - **Register strides**: VIA and IWM registers are 512 bytes apart ($EFE1FE + 512 x n, $DFE1FF + 512 x n, DOC: IM3 III-43..45). OBSERVED: MAME's `macplus` boot touches the VIA at $EFE1FE (B), $EFE5FE (DDRB), $EFE7FE (DDRA), $EFF9FE (PCR), $EFFBFE (IFR), $EFFDFE (IER), $EFFFFE (A). - **Overlay**: on the 128K/512K/Plus, VIA PA4 (vOverlay), set by reset, cleared by the ROM after its tests (DOC: IM3 III-39, III-42). On the SE the BBU leaves the overlay "the first time an access is made in the range $400000 through $5FFFFF" and maps $000000-$03FFFF to ROM before that (DOC: GMFH p. 125). - **RAM size** on the Plus is told to the glue by two resistors (R8 "256K BIT", R9 "ONE ROW"); the ROM measures it at boot (DOC: IM4 IV-246). A machine-row setting. - **Phase**: the ROM reads the phase-read space at boot to check that "the computer's high-frequency timing signals are correctly in phase"; a word access to any SCC address shifts the processor clock's phase by 128 ns (one C8M half period? one C16M period: 1 / 15.6672 MHz = 63.8 ns, so 128 ns is two C16M periods: U2) and the ROM uses it to correct the phase (DOC: GMFH p. 123; IM3 III-25). Clock Signal models a 3-bit phase counter read at $F80000 and bumped by SCC word accesses (tier 5, its `Macintosh.cpp`). The board must at least return a phase the ROM accepts; whether a wrong phase is worth modelling is U2. ## The interleave (the cycle-exactness point) The documents: - "The MC68000 accesses to RAM are interleaved (alternated) with the video display's accesses during the active portion of a screen scan line ... The sound generator and disk speed controller are given the first access after each scan line. At all other times, the MC68000 has uninterrupted access to RAM, increasing the average RAM access rate to about 6 megahertz" (DOC: IM3 III-18). - "One out of every two RAM access cycles is devoted to video data during a scan line. The last RAM access before the beginning of a scan line is used for sound and disk-speed control data"; Plus average CPU RAM rate 2.56 MB/s, SE 3.2 MB/s (DOC: GMFH ch. 5, Table 5-3). On the SE "the circuits read two consecutive words during a video access", so the CPU waits less (DOC: GMFH p. 401). - ROM accesses are never interleaved: "always accessed at the full processor rate" (DOC: IM3 III-18). The arithmetic: a shown line is 512 pixels = 256 CPU clocks and needs 32 words, one per 8 CPU clocks. A 68000 bus cycle is 4 clocks. So during the shown part of a line each 8-clock period holds one video slot and one CPU slot; a CPU RAM access that does not start in its slot waits for the next one (up to 4 clocks). On the SE, 16 words a line are fetched in pairs, one double fetch per 16 clocks, leaving three of four slots to the CPU (HYPOTHESIS from the "two words" statement). **Three detectors disagree** (contradiction C1; [validation.md](validation.md)): | Detector (tier 5) | Rule | | --- | --- | | MAME 0.285 `macplus` | **no RAM contention at all**: in the ROM's RAM-fill loop every `MOVEM.L D2-D4,(A0)` takes 32 clocks (87,010 of 87,010 instances, OBSERVED); only VIA accesses are stretched | | Clock Signal `cc085c4` | while video is output, a RAM access in the first half of a 16-half-cycle period is delayed to its second half ("only every other access slot is available during the period of video output. I believe this to be correct for the 128k, 512k and Plus") | | Snow `13380a6` | the CPU owns RAM when `cycles % 8 >= 4` outside blanking (128K/512K/Plus), `cycles % 16 >= 4` on the SE and Classic; stall polled every 2 clocks; it cites Steve Chamberlin's 2011 Plus Too memory-controller article | Which slot is the CPU's (the phase of the 8-clock period against the 68000's S0), whether the sound fetch is in the last slot before the line or the first after it (IM3 and GMFH word it differently: C2), whether refresh takes slots (the video scan refreshes the DRAM: DOC GMFH ch. 5; refresh during vertical blanking is U3) and where blanking starts in CPU clocks are the unknowns U3-U4. No hardware-tier source in hand decides them; candidates: the PAL equations (open decision 6), a probe program on a real Plus (open decision 8). ## Interrupts | Level | /IPL2-0 | Source | Autovector | | --- | --- | --- | --- | | 1 | 110 | VIA | $19 ($64) | | 2 | 101 | SCC | $1A ($68) | | 3 | 100 | SCC + VIA, only briefly ("/IPL0 is disconnected from the VIA interrupt line when the SCC interrupts on /IPL1") | $1B | | 4 | 011 | interrupt switch (the programmer's switch) | $1C | | 5-7 | | switch + VIA / SCC / both (6 and 7 likewise transient) | $1D-$1F | (DOC: GMFH Table 3-1, p. 92; IM3 III-45..46 lists the same vectors.) IM3's text calls the VIA's "a level-0 processor interrupt" and the SCC's "level-1" (III-41, III-25), naming the /IPL0 and /IPL1 lines, not levels: contradiction C3, resolved by the table. On the SE the SCSI IRQ joins the VIA on level 1, masked by VIA PB6 (DOC: GMFH p. 168). The acknowledge is a read at $FFFFF0-$FFFFFF answered by /VPA (DOC: GMFH p. 91), so every interrupt entry pays m68000-python's E-clock acknowledge wait (it has it: `_e_clock_wait`). ## VIA accesses: /VPA and the E clock "The MC68000 has to wait for the phase of the relatively slow E clock signal to coincide with a normal processor-access cycle before it can access the VIA", 1.0 µs on average (DOC: GMFH ch. 4). OBSERVED (MAME 0.285, `macplus` boot, 121,672 reads of the IFR in the ROM's wait loop): every read lands on the same phase of a 10-clock period and the loop iterates every 40 clocks; MAME models the E-clock wait for data cycles. m68000-python models it only for the interrupt acknowledge today: request R2 ([cores.md](cores.md)). ## Reset Reset holds the CPU while the glue settles; the VIA and IWM are reset and the overlay set (DOC: IM3 III-42). OBSERVED: MAME's first instruction is at $40002A (its `pc` symbol prints $40002C, the prefetch address: [mame-oracle.md](mame-oracle.md)); the 68000 reads its reset vectors through the overlay at $000000. Its second instruction is `MOVEM.L $F80000,D0/A0` followed by a compare of D0 with $55AAAA55: the ROM probes the "reserved" $F80000 space for a signature (OBSERVED; that this is a test-ROM hook is HYPOTHESIS, U7), so the value the board returns there matters from the third instruction on (MAME returns something that fails the compare and the boot goes on). The RESET instruction's effect on the VIA, IWM and SCC (all wired to /RESET?) is U6.