# ROMC and the memory chips: where the F8's program counter lives The F8 has no address bus. The CPU (F3850) sets five control lines, **ROMC0-4**, early in every machine cycle; every memory chip on the bus decodes them "as though they were a 5-bit instruction code" (DB F3851 "Device Organization", DOC) and acts. Each memory chip holds its **own** program counter PC0, stack register PC1 and data counter DC0 (and DC1 in some chips), with its own incrementer/adder. A memory access is answered by the one chip whose address space contains the address; a register update is performed by **all** of them, so all copies stay equal. This file is the reason f8-python's core boundary looks the way it does (handoff brief, "The core boundary"). Sources: DB = 1982 Fairchild Microprocessor Products Data Book (F3850 Table 5; F3851/F3856; F3852/F3853); UG = *F8 User's Guide* 67095665, 11/77 (OCR of the scan: 3.1.2-3.1.10 on PDF pages 70-72, 4.3.3 on page 98-99, section 5 on pages 119-121); veswiki "ROMC" (rev 729), which reproduces DB Table 5. All DOC unless marked. ## The memory-side chips | Chip | Memory | Address registers | I/O ports | Timer, interrupt | Notes | | --- | --- | --- | --- | --- | --- | | F3851 PSU | 1 KB mask ROM; page select = 6-bit mask option (address bits 15-10) | PC0, PC1, DC0 (**no DC1**) | A, B, interrupt control, timer at a 6-bit mask-option base (`xxxxxx00`-`xxxxxx11`) | polynomial shift-register timer; one external interrupt input; interrupt vector = mask option | ports, timer and interrupt control not initialised at power-on (DB) | | F3856 PSU | 2 KB ROM; 5-bit page select | PC0, PC1, DC0, **DC1** (DB F3851/F3856 sheet: "Data counter DC1 is provided on the F3856 as an additional ...") | as F3851, 5-bit base | as F3851 | ports and interrupt control initialised by power-on and external reset; timer not (DB) | | F3852 DMI | external dynamic RAM, 16-bit address bus | PC0, PC1, DC0, **DC1** | 0Ch, 0Dh (DMA control) or ECh/EDh (SL31116 variant, veswiki "Port") | refresh, DMA (with F3854) | separate mask options for its memory space and its **address-register space** (UG 4.3.2) | | F3853 SMI | external static RAM, up to 64 KB | PC0, PC1, DC0, **DC1** | 0Ch/0Dh interrupt vector (programmable, readable), 0Eh interrupt control, 0Fh timer (UG 5.1.3) | timer and interrupt as the F3851; no PRI OUT pin (must be last in the chain); vector bit 7 = 0 for timer, 1 for external interrupt (UG 5.1.2) | no refresh or DMA; relaxed bus timing (UG 5.1.1) | | F3854 DMA | | | F0h-FFh | | not in any Channel F | The Channel F uses F3851s for its two BIOS ROMs and for most cartridges; some cartridges carry RAM (channelf-python docs/cartridges.md). ## The 32 ROMC states (DB Table 5, condensed; cycle length in brackets) | ROMC | Len | Who drives the bus | What every chip does | | --- | --- | --- | --- | | 00 | S/L | chip owning PC0: the opcode at PC0 | PC0 += 1 (instruction fetch) | | 01 | L | chip owning PC0: the byte at PC0 | PC0 += signed(bus) (relative branch) | | 02 | L | chip owning DC0: the byte at DC0 | DC0 += 1 (memory read) | | 03 | L/S | chip owning PC0: the byte at PC0 | PC0 += 1 (immediate operand fetch) | | 04 | S | - | PC0 <- PC1 | | 05 | L | CPU: the byte to store | the chip owning DC0 stores it; DC0 += 1 | | 06 | L | chip owning DC0: DC0's high byte | - | | 07 | L | chip owning PC1: PC1's high byte | - | | 08 | L | CPU: 00h | PC1 <- PC0, then PC0 <- 0000h (both halves loaded from the bus) | | 09 | L | chip owning DC0: DC0's low byte | - | | 0A | L | CPU: A | DC0 += signed(bus) | | 0B | L | chip owning PC1: PC1's low byte | - | | 0C | L | chip owning PC0: the byte at PC0 | PC0's low byte <- bus | | 0D | S | - | PC1 <- PC0 + 1 (PC0 unchanged) | | 0E | L | chip owning PC0: the byte at PC0 | DC0's low byte <- bus | | 0F | L | interrupting chip with priority: vector low byte | PC1 <- PC0; PC0's low byte <- bus | | 10 | L | - | inhibit changes to the interrupt priority logic | | 11 | L | chip owning PC0: the byte at PC0 | DC0's high byte <- bus | | 12 | L | CPU | PC1 <- PC0; PC0's low byte <- bus | | 13 | L | interrupting chip: vector high byte | PC0's high byte <- bus; the interrupting chip clears its request | | 14 | L | CPU | PC0's high byte <- bus | | 15 | L | CPU | PC1's high byte <- bus | | 16 | L | CPU | DC0's high byte <- bus | | 17 | L | CPU | PC0's low byte <- bus | | 18 | L | CPU | PC1's low byte <- bus | | 19 | L | CPU | DC0's low byte <- bus | | 1A | L | CPU: A | the chip owning the port addressed in the previous cycle latches the bus into it | | 1B | L | chip owning the port addressed in the previous cycle: the port | - (timer and interrupt control cannot be read back) | | 1C | S/L | - | nothing (idle; also the cycle that puts a port address on the bus for INS/OUTS 4-15) | | 1D | S | - | chips with DC1 swap DC0 and DC1; chips without DC1 do nothing | | 1E | L | chip owning PC0: PC0's low byte | - | | 1F | L | chip owning PC0: PC0's high byte | - | ## Why every chip keeps its own copy, and where the copies diverge UG 3.1.4, "Addressing Consistency in Multiple Memory Devices": a memory access is answered by one chip, but "every memory device will increment the contents of its PC0 register, whether or not the PC0 register contents is within the memory space of the device ... Therefore every PC0 register, on every memory device, always contains identical information; the same will hold true for DC0 and PC1 registers. (There is one small exception ...)". Its three conditions: every chip sees the same ROMC states from one CPU; no two chips share a page; the address in the register used is inside some chip's space. The exception (UG 4.3.3, "Address Contentions"): **XDC (ROMC 1D) swaps DC0 and DC1 only in chips that have DC1** (3852, 3853, 3856). An F3851 PSU ignores it. After an XDC, the PSU's DC0 and the SMI's DC0 differ, both keep incrementing on every memory reference, and "an instruction that requires data to be output from DC0 may now cause two devices to simultaneously place different data on the data bus" when the PSU's stale DC0 falls inside its own page. Fairchild's own advice is to keep the swapped blocks outside every PSU's page, or to resynchronise DC0 with `DCI`, `LR DC,Q` or `LR DC,H` afterwards (UG 4.3.3, with worked register tables). Three observables follow, none of which a single-PC emulator can show: 1. **Divergent DC0 after XDC.** In a system mixing F3851s with a DC1-holding chip, the value `LR Q,DC` / `LR H,DC` reads back after an XDC comes from whichever chip owns the address in **its own** DC0 (ROMC 06/09). Two chips may both answer (bus contention) or none. 2. **Nobody answers.** A read of a register (ROMC 06, 07, 09, 0B, 1E, 1F) or of memory when the address lies in no chip's space leaves the bus undriven: "no device would respond ... invalid values would be received by the 3850 CPU" (UG 4.3.2). In a Channel F with a 2 KB cartridge, `DCI H'3000'` then `LR Q,DC` is such a read. What the floating bus reads as is not documented (U). 3. **Contention.** Two chips driving different bytes. The electrical result (wired-AND, wired-OR, either) is not documented (U); the specification must at least detect and report it. A board can also give a chip an address-register space wider than its memory space (the 3852's two masks, UG 4.3.2) precisely so that register reads always get an answer. ## Consequences for the core (proposal; the brief's "core boundary" settles it) - The CPU never sees an address. Each machine cycle it produces `(romc, length, cpu_drive)` where `cpu_drive` is the byte the CPU puts on the bus in that state (A, a scratchpad byte, 00h, a port address) or nothing. - Each memory chip implements one method per cycle, in two phases matching the hardware: **drive** (return the byte it puts on the bus for this ROMC state, or nothing) and **latch** (take the bus value and update its own PC0/PC1/DC0/DC1, ports, timer and interrupt state). The bus resolves the drive phase (exactly one driver; none and more than one are reported and resolved by a named, provisional rule). - PC0, PC1, DC0 and DC1 therefore exist **once per chip** in the specification. A debugger view of "the PC" is the copy in the chip that answered the last fetch, plus a check that all copies agree. - Timing: the CPU tells the bus the cycle length (4 or 6 phi); the board advances its other parts (video, sound) by that many phi clocks. Nothing else in the system stretches a cycle on the Channel F (no wait states; UG section 2 has none on the F3850 side, to confirm). ## What MAME does instead (OBSERVED, closed box) MAME 0.285's F8 device exposes one PC0, PC1, DC0 and DC1 as CPU state (`mame_trace.py` lists them), so it models the CPU-centric simplification: one copy of each register. It cannot show the three observables above. That is a known, named limit of the tier-5 detector, not a hardware statement.