# Slots, sub-slots and memory ## Primary slots The Z80's 64 KB is four 16 KB **pages** (0000, 4000, 8000, C000). Each page is taken from one of four **primary slots**, chosen by two bits of the PPI's port A (I/O port A8h): bits 1-0 page 0, 3-2 page 1, 5-4 page 2, 7-6 page 3 [TDB p. 43 "8255 (PPI) Bit Assignments": CS0L/H ... CS3L/H; TH2 5.7.1.2 fig. 5.38]. A page of a slot always appears at the same CPU page: page n of every slot is page n to the CPU [TH2 5.7.1.1]. Every slot sees the full address bus; the slot's SLTSL line says when the CPU is talking to it. The cartridge bus also carries CS1 (4000-7FFF), CS2 (8000-BFFF) and CS12 (4000-BFFF, "for 256K ROM") [TDB p. 32-33]: ROM cartridges decode with these. ## Expanded slots (sub-slots) A primary slot may be **expanded** into four secondary slots. The expansion register sits at FFFFh **inside the expanded slot**, so it is reached only while page 3 selects that primary slot; its bits pick a secondary slot per page in the same layout as A8h [TH2 fig. 5.39]. "In the case of the expansion slot, the value written is read as the reversed value": a read of FFFFh in an expanded slot returns the complement of the last write, which is how software tells expanded from plain [TH2 note under fig. 5.39]. The BIOS keeps the state in EXPTBL (FCC1h, the main ROM's slot) and the SLTTBL work area [TH2 5.7.1.2, 5.7.2.3]. Board consequences: - The slot model is a tree: four primary slots, each either a device or an expander with four children, each child a device. A device answers memory reads and writes for the pages it is selected in. - FFFFh is special only in an expanded slot whose page 3 is selected: a write goes to the expander's register **and not** to RAM behind it (U3: whether a device in the selected secondary slot also sees the write; the TH2 does not say). - Cartridge slots are primary on standard machines; internal ROM, RAM, a disk ROM or the MSX2 sub-ROM sit in expanded slots on many machines [TH2 5.7.1.1]. ## Open bus A read from a page whose slot holds nothing returns what the bus floats to. Every source and emulator met says FFh (pull-ups on the data bus); no document read for this phase states it (U4, HYPOTHESIS FFh). ## RAM MSX1: at least 16 KB, often 64 KB spread over the slot of the maker's choice [TDB p. 10 note]. The BIOS finds RAM by probing each slot at boot, so RAM placement is part of the machine row, not a free choice. MSX2 adds the **memory mapper**: RAM in 16 KB segments, selected per page by I/O ports FC (page 0), FD, FE, FF (page 3) [TH2 appendix 6]. The Yamaha S1985 MSX2 engine implements one for up to 512 KB [S1985 p. 1 "Features"]. What a mapper register reads back (unused high bits as 1s, 0s, or open bus) differs between engines and RAM cartridges (U5); software that sizes memory reads them, so it matters. ## Cartridge header and boot scan A ROM cartridge has "AB" at 4000h or 8000h followed by INIT, STATEMENT, DEVICE and TEXT addresses; the BIOS scans the slots at boot and calls each INIT it finds [TH2 7.3.1 fig. 5.48]. A "CD" ID marks a sub-ROM. The board need not know this (the BIOS does it), but the census and the cartridge loader use it to place plain ROMs ([cartridges.md](cartridges.md)). ## The memory map the board decodes (MSX1) | Range | Who answers | | --- | --- | | 0000-FFFF memory | the device in the selected (primary, secondary) slot for that page; FFh if none (U4) | | FFFF in an expanded slot | the expander's register (read: complement of the last write) | | I/O 98-99h | the VDP ([vdp.md](vdp.md)) | | I/O A0-A2h | the PSG: A0 address latch, A1 data write, A2 data read [TH2 appendix 6] | | I/O A8-ABh | the PPI: A8 port A, A9 port B, AA port C, AB mode set [TH2 appendix 6] | | I/O 90-91h | printer port (90 bit 0 strobe out, bit 1 busy in; 91 data) [TH2 appendix 6] | | I/O 7C-7Dh | MSX-MUSIC when present ([msx-music.md](msx-music.md)) | | I/O D0-D7h | reserved for FDCs in the I/O map; real interfaces are mostly memory-mapped ([disk.md](disk.md)) | | other I/O | FFh unless a cartridge or machine row decodes it (U4) | The I/O decode is partial on real machines (ports mirror within their blocks: A0-A3, A8-AB, 98-9B); which mirrors a given MSX1 decodes is per machine (U6). The TH2 lists 98-9Bh for the MSX2 VDP and 88-8Bh for an MSX1 V9938 adapter [TH2 appendix 6].