# The MC6883 SAM (SN74LS783 / SN74LS785) The Synchronous Address Multiplexer is the board's clock, memory controller, address decoder and the VDG's address counter. It is used by this machine family only (the CoCo 1/2 and the Dragon; the CoCo 3's GIME absorbs it), so by the chip rule it stays in the board ([reuse.md](reuse.md)). Source: the SAM data sheet (Motorola "Fast and LS TTL Data" pages 5-323 to 5-341, pinned as `MC6883.pdf`; the Advance Information edition is pinned too for comparison). Facts are DOC unless tagged. ## Pins that matter to the board - A0-A15 and R/W from the CPU; E and Q out to the CPU (90 degrees apart). - DA0 in from the VDG (the only VDG address line used: the SAM keeps its own copy of the rest), HS in from the VDG (refresh trigger and horizontal reset of the counter), VClk out to the VDG (3.579545 MHz; pulled low it resets the SAM's control register). - S2-S1-S0 out: a device-select number decoded by a 74LS138 on the board (TRM; SM1: U11). - Z0-Z7, RAS0, RAS1 (= Z7 when M1=0), CAS, WE to the DRAM. ## The control register (16 bits, write-only, at FFC0-FFDF) Writing any value to an even address clears a bit, to the odd address above it sets it; the data bus is ignored. All bits clear on reset (power-up or VClk held low for eight oscillator cycles). | Addresses | Bits | Meaning | | --- | --- | --- | | FFC0-FFC5 | V0, V1, V2 | VDG addressing mode (figure 5 below) | | FFC6-FFD3 | F0-F6 | display start = F x 512 (bits 9-15 of the address) | | FFD4-FFD5 | P1 | page bit: replaces A15 for 0000-7FFF in map type 0 (LS785: also picks 16K x 4 DRAM) | | FFD6-FFD9 | R0, R1 | CPU rate: 00 slow (/16), 01 address-dependent, 1x fast (/8) | | FFDA-FFDD | M0, M1 | RAM size: 00 4K, 01 16K (or 16K x 4 on LS785), 10 64K dynamic, 11 64K static | | FFDE-FFDF | TY | map type: 0 ROM-based, 1 all-RAM (64K minus FF00-FFFF) | OBSERVED (MAME, [mame-oracle.md](mame-oracle.md)): Color BASIC 1.2's reset writes every even address FFC0-FFDE once (all 16 bits cleared), then FFC9 (F1: text page at 0400) and FFDD (M1: 64K). From 1.25 s it rewrites V0-V2 and F0-F6 in a burst of 86 more passes within 24 ms (the start-up screen being drawn), and not again while it waits at `OK`. The Dragon 32's ROM does the same in 99 passes between 1.30 s and 2.06 s. ## Memory map type 0 (figure 14) and the device selects | CPU addresses | S | Device on the CoCo/Dragon | | --- | --- | --- | | 0000-7FFF | 0 on reads, 7 on writes (LS785: 7 on any write) | RAM (page P1 replaces A15) | | 8000-9FFF | 1 | ROM0: Extended BASIC (CoCo); first half of the 16K BASIC (Dragon) | | A000-BFFF | 2 | ROM1: Color BASIC (CoCo); second half (Dragon) | | C000-FEFF | 3 | ROM2: the cartridge (CTS) | | FF00-FF1F | 4 | I/O0: PIA0 (slow in address-dependent mode) | | FF20-FF3F | 5 | I/O1: PIA1 | | FF40-FF5F | 6 | I/O2: the cartridge's SCS (disk controller) | | FF60-FFBF | 7 | reserved (CoCo: unused; external devices decode it through SLENB) | | FFC0-FFDF | 7 | the SAM's own control register (write strobe) | | FFE0-FFFF | 2 | ROM1 again: the 6809 vectors read BFE0-BFFF (TRM: "if the CPU reads FFFF it will actually read the contents of BFFF") | Map type 1 (figures 15 and 16) puts RAM at 0000-FEFF; on the LS783 the 8000-FEFF RAM writes also decode as ROM selects, which the board must reproduce: CA reports that on an unexpanded Dragon 32 a write to the upper 32K in map type 1 selects ROM and RAM together, "causing ROM data to be copied into RAM" (community observation; U2 for the CoCo). PIA mirrors: the 74LS138 decodes only S, and the PIAs see A0-A1, so PIA0 repeats through FF00-FF1F and PIA1 through FF20-FF3F (LOM "FF00-FF03 are repeated through FF04 to FF1F"). OBSERVED: Color BASIC initialises PIA0 through the mirror FF1C-FF1F (`LDX #$FF20; CLR -3,X`), the Dragon ROM at FF00-FF03. The Dragon 64 puts its ACIA at FF04-FF07 (OBSERVED writes FF06/FF07 in MAME's `dragon64`), so PIA0 is not mirrored there on that row. ## CPU rate modes (pages 5-333, 5-338) - Slow: E = crystal / 16 (0.89 MHz); the reset state. - Address-dependent (R1=0, R0=1): E = crystal / 16 for 0000-7FFF and FF00-FF1F, crystal / 8 for everything else, including the 6809's dead cycles (address FFFF). VDG and refresh continue. BASIC programs run nearly twice as fast (LOM; the SAM sheet says "nearly doubles the MPU throughput"). - Fast (R1=1): crystal / 8 always; the VDG and refresh slots are given to the CPU, so the display shows garbage and DRAM is not refreshed. - Rate changes must follow the sheet's sequences (slow to fast only through address-dependent; "Sequence #1" synchronises the STA with a TST/BRN pair). Early LS783s (before 1983) did not allow fast mode with map type 1. - The E/Q waveforms at a rate change (figure 8) are a picture only: the cycle-exact stretch when the rate changes mid-instruction is unknown U3. ## The VDG address counter (figure 5) and the cross modes The SAM duplicates the VDG's address counter (B0-B15) clocked by DA0. V2-V0 select a divide-by-X (repeat each byte X times across a line) and divide-by-Y (repeat each line Y times), and how many low bits HS clears: | V2 V1 V0 | X | Y | HS clears | VDG mode it matches | | --- | --- | --- | --- | --- | | 0 0 0 | 1 | 12 | B1-B4 | alphanumerics, SG4, SG6 | | 0 0 1 | 3 | 1 | B1-B3 | CG1, RG1 (data sheet's X/Y columns as printed) | | 0 1 0 | 1 | 3 | B1-B4 | CG2 | | 0 1 1 | 2 | 1 | B1-B3 | RG2 | | 1 0 0 | 1 | 2 | B1-B4 | CG3 | | 1 0 1 | 1 | 1 | B1-B3 | RG3 | | 1 1 0 | 1 | 1 | B1-B4 | CG6, RG6 | | 1 1 1 | 1 | 1 | none | DMA mode | (Read from the page image, PDF page 9, 2026-11-26: the OCR of this table is garbled.) X and Y are the sheet's "division variables"; how each maps onto counter bits is the build's first reading of the block diagram (figure 4). B9-B15 load from F0-F6 on the vertical preload (HS rising while DA0 is high, which FS wired to MS provides during vertical blanking); that preload also clears B1-B8. Setting the VDG to SG4 with the SAM in a graphics mode gives the "semigraphics 8/12/24" modes of the SAM sheet's appendix A; other mismatches give further modes (CA, `sam-vdg-interaction` page, not pinned). Because the board models the counter, every cross mode falls out; the gate checks them against MAME pictures (tier 5) until a hardware capture exists. ## Refresh and the interleave Every E cycle has a CPU half and a VDG half (figure 12): the CPU accesses memory in the second half of E, the VDG (or refresh) in the first, so neither ever waits (no contention, no halts: "the MPU is not slowed down nor stopped by the SAM"). Refresh: eight sequential row addresses (7-bit counter on the LS783, 8-bit on the LS785) each time HS falls, in the VDG half of the cycle. This is what makes the CoCo/Dragon a one-domain machine with fixed E cycles in slow mode ([handoff-brief.md](handoff-brief.md), "Domains and speed"). ## VDG synchronisation The SAM stops VClk (for at most 32 oscillator cycles, about 2 us) until DA0 rises inside a window centred on its VDG half-cycle, then restarts it in phase; once in step it does not stop again "unless an extreme temperature change (or SAM reset) occurs" (page 5-332). With a 227.5-clock VDG line and a 4-clock E grid the phase of DA0 against E alternates by half a VDG clock each line: how the window absorbs that, and therefore exactly where each line starts in E cycles, is unknown U1 (the timing diagrams on pages 5-327/328 are rotated scans; read them as pictures at the build). MAME uses 228 clocks (C2). ## Unknowns here U1 line length and phase in E cycles; U2 map-type-1 ROM/RAM double select on the CoCo; U3 the E stretch at a rate change; U4 the LS783/LS785 difference on each row (which boards carry which part: service manuals' parts lists).