# Memory, ROM banking and the expansion port Source names as in start-here.md. ## The map the Z80 sees (DOC: ap12 B, E; KT `garray`, `rampage`, `exprom`, `signals`) | Range | Read | Write | | --- | --- | --- | | 0000-3FFF | lower ROM (OS) if RMR bit 2 = 0, else RAM | always RAM | | 4000-BFFF | RAM | RAM | | C000-FFFF | the selected upper ROM if RMR bit 3 = 0, else RAM | always RAM | "Whether the ROM is enabled or not affects where data is read from, it has no effect on write operations" (ap12 B). Both ROM halves are enabled at reset (ap12 B, E). The Gate Array does this decode itself and signals it on the expansion port: /ROMEN low for an enabled-ROM read, /RAMRD low for a RAM read (KT `signals`, with the conditions on A15/A14 and RMR bits 2-3). ROMDIS and RAMDIS from the expansion port turn the internal ROM or RAM off so a device can supply the byte (KT `signals`); the board offers both as socket inputs. ### Upper ROM select (DOC: ap12 B, I; KT `exprom`) An OUT to `DFxx` (A13 = 0) latches a ROM number 0-255; BASIC is 0, AMSDOS 7. "BASIC will be selected if an attempt is made to select a rom which is not connected" (KT `exprom`): on the bare machine the internal ROM's upper half answers for every number except where a device asserts ROMDIS. The latch is write-only. The firmware writes `DFxx <- 00` at 365 µs after reset (OBSERVED, MAME 6128). ### RAM banking: the 6128's PAL and the expansions (DOC: ap12 E; KT `rampage`, `cpcptno`) The Gate Array function `11` is not the Gate Array: on the 6128 it is the PAL 40031 (KT `cpcptno`: "16L8 PAL; Ram management CPC6128"); on the 464/664 a RAM expansion (Dk'Tronics, Amstrad, Dobbertin designs) answers it; on the Plus, the ASIC (KT `rampage`). Bits 2-0 pick one of eight configurations (ap12 E's table, which KT's matches): | Code | 0000 | 4000 | 8000 | C000 | | --- | --- | --- | --- | --- | | 0 | 0 | 1 | 2 | 3 | | 1 | 0 | 1 | 2 | 7 | | 2 | 4 | 5 | 6 | 7 | | 3 | 0 | 3 | 2 | 7 | | 4-7 | 0 | 4-7 | 2 | 3 | (banks 0-3 are the base 64 KB, 4-7 the second 64 KB). The video always reads the base 64 KB (ACCC 4.1; KT `rampage`). Expansions of up to 512 KB more use bits 5-3 to choose which extra 64 KB block is "secondary" (KT `rampage`); ap12 E says to send 0 in bits 5-3 on the 6128, and the decode of those bits by the 6128's PAL is not stated (U13). The MAME 6128 boot writes the function once (`C0`, OBSERVED). **Decode width.** ap12 K gives `7Fxx` for the Gate Array; ACCC 5.1 says A15 = 0, A14 = 1 selects both, and adds that on some CRTC 0-2 machines the PAL is selected with A14 = 0 too, and on CRTC 3-4 (ASIC) machines A14 is ignored for it: "it is strongly advised to always set bit 14 to 1". KT `rampage`: "accessed when bit 15 of I/O address is set to 0". The board decodes A15 = 0, A14 = 1 for both, with the per-machine relaxations as variant data (U14). ### DRAM refresh The Gate Array's video fetches walk the RAM rows, which refreshes the DRAM (KT `ramref`; HYPOTHESIS until read in full); the Z80's own refresh cycles (/RFSH) are not needed for it. Nothing in software can see this, except that a CRTC programmed to fetch too few addresses lets RAM decay, which no emulator models and the board will not (a concession would be the wrong word: it is out of the specification's scope, noted for completeness). ## The expansion port (DOC: KT `signals`, `connect`; ap12 I, K) A 50-way edge connector carrying the Z80's buses and controls (A15-A0, D7-D0, /MREQ, /IORQ, /RD, /WR, /M1, /RFSH, /HALT, /INT, /NMI, /BUSRQ, /BUSAK, /WAIT, /RESET, the 4 MHz clock), plus the CPC's own lines: /ROMEN, /RAMRD, ROMDIS, RAMDIS, /EXP (to PPI port B bit 5; the DDI-1 grounds it, ap12 I), CURSOR and L.PEN (the CRTC), mono sound, /BUS RESET (KT does not know its function). I/O for peripherals lives in `F8xx`-`FBxx` with low-byte conventions (ap12 K: `7C-7F` disc, `DC-DF` communications, `E0-FE` user, `FF` reset peripherals). The board's socket mirrors this: a device sees each bus cycle (address, data, kind, T-state) and may drive the data bus, assert ROMDIS/RAMDIS, pull /INT or /NMI, or ask for /WAIT. That covers the DDI-1, ROM boxes, RAM expansions, the Multiface II, speech synthesisers (MAME's device list, census.md) and the Plus's cartridge port is a different socket (plus-asic.md). NMI is free on the bare machine (KT `ints`: "not used by the Amstrad CPC hardware but is available for expansion devices"; ap12 A warns firmware timing may break). ## Reset What resets: the Z80, the PPI (ap12 F), the Gate Array's RMR (both ROMs on, mode 0) and border colour (black), the printer latch, the 6128's bank register (assumed to code 0: HYPOTHESIS, the firmware writes `C0` itself at boot anyway). What does not: the disc motors (ap12 I), the palette except the border (ap12 E), the CRTC's registers (the firmware writes all of them, R15 to R0, ACCC 4.1). The AY is reset by the system /RESET (HYPOTHESIS; the AY has a /RESET pin, its CPC wiring is not in the pinned sources).