# Memory, soft switches, the language card, the IIe's MMU and IOU ## The II and II+ map | Range | What | Source | | --- | --- | --- | | $0000-$BFFF | RAM (48K fitted; 4K-48K by configuration blocks on early boards, soldered 16K rows from Revision 4) | DOC: A2RM; UA2 ch. 5, p. G-3 | | $0400-$07FF, $0800-$0BFF | text/lo-res pages 1 and 2 | DOC: A2RM; UA2 Table 5.2 | | $2000-$3FFF, $4000-$5FFF | hi-res pages 1 and 2 | same | | $C000-$C0FF | I/O: the motherboard soft switches ($C000-$C07F) and each slot's 16 device-select locations ($C080 + $10 x slot) | DOC: A2RM; UA2 ch. 7 | | $C100-$C7FF | each slot's 256-byte I/O-select space ($Cn00) | same | | $C800-$CFFF | the shared expansion-ROM window; a card claims it when its $Cn00 space is accessed and releases it on an access to $CFFF | DOC: UA2 ch. 6, 7 | | $D000-$FFFF | ROM: BASIC from $D000 (Integer BASIC on the II, Applesoft on the II+), the Monitor at $F800 (old or Autostart); or the language card's RAM | DOC: A2RM; UA2 ch. 6 | ### The motherboard soft switches ($C000-$C07F, II/II+) Each is a range of 16 addresses decoded by the address alone; most act on any access, read or write (DOC: UA2 ch. 7, Table 7.x; A2RM "I/O locations"). | Address | Function | | --- | --- | | $C000-$C00F (read) | keyboard data; bit 7 = strobe (a key is waiting) | | $C010-$C01F | clear the keyboard strobe | | $C020-$C02F | toggle the cassette output | | $C030-$C03F | toggle the speaker | | $C040-$C04F | the game port's utility strobe (pin 5) | | $C050/$C051 | graphics / text | | $C052/$C053 | full screen / mixed (four text lines at the bottom) | | $C054/$C055 | page 1 / page 2 | | $C056/$C057 | lo-res / hi-res | | $C058-$C05F | annunciators 0-3 off/on | | $C060-$C067 (read, bit 7) | cassette input; push buttons 0-2; paddle timers 0-3 (the 558) | | $C070-$C07F | reset the paddle timers | A **read** of a soft switch returns the floating bus in every bit the switch does not drive (DOC: UA2 pp. 5-3, 5-27..5-28: "the ability of the MPU to read the video data when the data bus is floating is a very useful design accident"; see [video.md](video.md), "The floating bus"). "PEEK(-16320) generates a single strobe and POKE -16320,0 a double strobe" (DOC: UA2 p. 4-22): a 6502 write cycle at $C040 is preceded by its own read of the same address only in some addressing modes; the board must count accesses, not instructions ([cpu.md](cpu.md)). ## The 16K language card (slot 0 on the II/II+, built in on the IIe and IIc) RAM at $D000-$FFFF in place of the ROM: 4K twice at $D000-$DFFF (banks 1 and 2) and 8K at $E000-$FFFF. Controlled by the 16 addresses $C080-$C08F (DOC: UA2 pp. 5-28..5-30; A2ETRM ch. 4): - address bit 3 selects the $D000 bank (0: bank 2, 1: bank 1); - address bits 0-1 select read and write: read RAM when the two bits are equal ($0, $3), read ROM otherwise; writing is enabled by **two successive odd read accesses** ($1, $3) through a PRE-WRITE flip-flop; - in Sather's words, the write-enable flip-flops are "a write counter which counts odd read accesses in the $C08X range"; an even access, or any write access, sets the counter to zero; once it reaches 2, writing stays enabled until an even access; a **write** to an odd address changes READ ENABLE without affecting write enabling, "a feature of RAM card control not documented by Apple" (DOC: UA2 p. 5-29). - At power-up the card is read-disabled, write-enabled, bank 2, PRE-WRITE reset; the II's system RESET has no effect on the card's configuration (DOC: UA2 p. 5-29). The IIe's RESET behaviour differs (the MMU; to read in UA2E ch. 5 and A2ETRM ch. 4 before coding: U6). ## The IIe: MMU and IOU The IIe puts the II's discrete logic into two custom chips: the **MMU** (memory management: RAM banking, auxiliary memory, the language card, $Cxxx ROM selection) and the **IOU** (input/output: the video scanner and generator's switches, keyboard, annunciators, VBL). Sather's IIe book is the source for their behaviour at cycle level (DOC: UA2E ch. 5 "RAM and memory management", ch. 7, ch. 8); Apple's manual gives the programmer's view (DOC: A2ETRM ch. 2 Table 2-10, ch. 4). Write-only switches at $C000-$C00F (a write to the even address turns a switch off, to the odd one on; reads of $C000-$C00F still return the keyboard) (DOC: A2ETRM pp. 61, 114-118, PDF pages): | Switch | Off / on | Effect | | --- | --- | --- | | 80STORE | $C000 / $C001 | when on, PAGE2 selects main/auxiliary for the display pages instead of page 1/2 | | RAMRD | $C002 / $C003 | read $0200-$BFFF from main / auxiliary | | RAMWRT | $C004 / $C005 | write $0200-$BFFF to main / auxiliary | | INTCXROM | $C006 / $C007 | slot ROMs / internal ROM at $C100-$CFFF | | ALTZP | $C008 / $C009 | zero page, stack and the language card from main / auxiliary | | SLOTC3ROM | $C00A / $C00B | internal / slot 3 ROM at $C300 | | 80COL | $C00C / $C00D | 40 / 80 columns | | ALTCHARSET | $C00E / $C00F | primary / alternate character set | Status reads at $C011-$C01F return the switch in bit 7 (BSRBANK2, BSRREADRAM, RAMRD, RAMWRT, INTCXROM, ALTZP, SLOTC3ROM, 80STORE, VBL, TEXT, MIXED, PAGE2, HIRES, ALTCHAR, 80COL; DOC: A2ETRM Table 2-10 and ch. 4). **What bits 0-6 of those reads hold** (the keyboard latch or the floating bus) must be settled from UA2E ch. 7 before coding (U7); a2audit's soft-switch test checks bit 7 only (its `softswitch.asm`). IOUDIS at $C07E/$C07F gates the annunciator addresses and the DHIRES switch at $C05E/$C05F (DOC: A2ETRM p. 61; the table marks both with a footnote, and which IIe revisions have them is to be read there: U7). VBL' is readable at $C019: "VBL goes high just after the last displayed address is scanned at the bottom right of the Apple screen" (DOC: UA2E p. 3-23). ## The IIc The IIc keeps the IIe's MMU/IOU programming model, with no slots: built-in serial ports, mouse, the disk port (an IWM) and a 128K machine; later ROMs bank a 32K ROM and add a memory-expansion card (DOC: A2CTRM; to be read when the IIc rows are built). Its interrupt sources (VBL, mouse, serial, keyboard) are built in and need the 65C02's IRQ input. ## For the board - One `Bus` per machine row with a table of 256 pages; the language card, MMU and card ROM windows switch page entries. Every soft-switch access goes through one dispatch so that read and write side effects and the floating-bus value are decided in one place, on the cycle the CPU makes the access. - The order of record inside a cycle: the video scanner's fetch (PHASE 1), then the CPU's access (PHASE 0) (DOC: UA2 ch. 3, 5). A soft switch the CPU flips therefore affects the scanner's next fetch, one cycle later.