# MADAM: the cel engine, the matrix engine, fences MADAM ("MN7A020UDA" in MAME's device list) is the memory controller and DMA engine (memory-map.md) and holds the 2D renderer. Keys as in memory-map.md, plus '693 = US5596693A, '644 = WO1994010644A1 (corner engines, region fill). SDK pages are under `ppgfldr/ggsfldr/gpgfldr/` unless a longer path is given. All DOC unless marked; DERIVED = arithmetic from cited numbers. Patent listings carry 3DO's copyright notice: describe, never copy. The full reading notes (CCB bits, preamble words, PIXC tables, every citation) were condensed into this page; anything below that a builder needs in more detail is in the cited section. ## The pipeline (SDK 3gpga; '235 fig. 1A; '644 sections 4, 6) Data unpacker (DUP; two, one per corner engine) -> pixel decoder (PDC, with the 32 x 16-bit PLUT) -> pixel processor (PPMP; one, shared) -> projector (two corner engines, the fast one-pixel decision unit "Munkee", the region-fill unit "Regis", the line filler) -> frame buffer writes through left and right address paths. Everything runs on MADAM's ~25 MHz clock; the FIFOs inside are rate buffers, not clock crossings ('235, '644 6.2). ## The CCB (SDK 5gpgc, 5gpgl; '235 table 1.0; '642 table II) Up to 15 words: FLAGS, NEXTPTR, SOURCEPTR, PLUTPTR, XPOS, YPOS (always); HDX, HDY, VDX, VDY (if LDSIZE); HDDX, HDDY (if LDPRS); PIXC (if LDPIXC); PRE0, PRE1 (if CCBPRE; PRE1 only for unpacked cels). Absent groups are omitted and later words move up; registers not reloaded keep the previous cel's values. Formats: XPOS/YPOS 16.16; HDX, HDY, HDDX, HDDY 12.20; VDX, VDY 16.16. Relative pointers are target - (pointer field address) - 4 ('235 table 1.4 note 1; SDK gpr 01gpr037). FLAGS (bit: name): 31 SKIP, 30 LAST, 29 NPABS, 28 SPABS, 27 PPABS, 26 LDSIZE, 25 LDPRS, 24 LDPIXC, 23 LDPLUT, 22 CCBPRE, 21 YOXY, 20 ACSC, 19 ALSC, 18 ACW, 17 ACCW, 16 TWD, 15 LCE, 14 ACE, 13 spare (patent: ASC; C3), 12 MARIA, 11 PXOR, 10 USEAV, 9 PACKED, 8:7 POVER, 6 PLUTPOS, 5 BGND, 4 NOBLK, 3:0 PLUTA. Load order ('642 V; '235 table 1.4 note 3): the CPU writes the first CCB address into the DMA stack's "next SCoB" register and writes SPRSTRT; the engine reads 6 words, then one burst of up to 7 optional words ("regardless of which specific ones have been requested": how the packed layout then advances is U11), the preamble (from the CCB end or the source start), the PLUT if LDPLUT (4, 8 or 16 words by bit depth, in 4-word bursts), then source rows in bursts of up to 4 words into the engine A and B input FIFOs. ## Source formats (SDK 5gpgd, 5gpge, 3gpgc; '235 tables 1.6, 1.7) - PRE0: VCNT (rows - 1, 10 bits) in 15:6, UNCODED 4, REP8 3, BPP 2:0 (1, 2, 4, 6, 8, 16 bpp); SDK adds SKIPX in 27:24 where the patent has a PACKED copy at bit 20 (C4). - PRE1 (unpacked): WOFFSET (words to next row - 2; 8 bits in 31:24 for <= 6 bpp, 10 bits in 25:16 for 8 and 16 bpp), NOSWAP 14, UNCLSB 13:12, LRFORM 11, TLHPCNT (pixels - 1) 10:0. - Packed rows: a row-offset word, then bit-packed packets of a 2-bit type and a 6-bit count: 00 end of row, 01 literal (count + 1 pixels), 10 transparent run, 11 repeat one pixel. - Coded pixels index the PLUT (with PLUTA supplying missing high bits below 5 bpp); coded 8 and 16 bpp carry 3-bit multiply values (AMV) per component; uncoded 8 and 16 bpp bypass the PLUT. Transparency: packed transparent runs, or decoder output 000 when BGND = 0. ## The pixel processor (SDK 3gpgd, 5gpgc; '235 tables 1.2, 1.3 and the PPMP circuit text) PIXC holds two 16-bit P-mode halves (which half is P-mode 0: C5), each: 1S primary source (decoder or frame buffer), MS multiplier source, MF constant multiplier (1-8), DF divider (/2, /4, /8, /16), 2S secondary source (0, AV, frame buffer, decoder), AV (5-bit add value or, with USEAV, math control: subtract, sign-extend, no wrap limit, secondary divider), 2D final /2. Per component (R, G, B, 5 bits): multiply, shift (truncate), add (or XOR with PXOR), shift, clamp to 0..31 unless wrapping is enabled. Two ticks of latency at one pixel per tick ('235: "Two ticks of the system clock (25 MHz)"). The patent's two worked examples are test vectors. Using frame-buffer data "almost doubles" rendering time (SDK 6gpgb). ## The projector: forward mapping and the paint rule ('644 sections 3, 5, 6.4-6.6; SDK 3gpge) - Each source pixel is a quad with corners shared with its neighbours. Row start = (XPOS, YPOS), next row start += (VDX, VDY); along a row += (HDX, HDY); row r uses HDX + r HDDX. Running X/Y are 16.16; HDX is added with its 4 low fraction bits dropped, HDX += HDDX keeps all 20 ('644 3, 6.5). - Corners are floored, the quad is walked top to bottom by two edge walkers, the line filler omits each span's right-most pixel and the bottom row (a top-left rule): a source pixel paints 0, 1 or many destination pixels. Munkee answers the 0- and 1-pixel cases in one tick from the signs of the corner differences; otherwise Regis fills. MARIA = 1 forbids Regis (at most one pixel per source pixel; which one when Munkee cannot decide: U12). ACW/ACCW cull by orientation; TWD tests only the first pixel. - The Regis state tables ('644 6.6.2.1) are only in the image-scanned PDF (189 pages): the exact edge-stepping rule needs those pages read (U13). - Two corner engines take alternate rows unless LCE locks them (LRFORM forces lock); ACE = 0 uses one. Per source pixel: corner calculation 1 or 2 ticks, Munkee 1 tick, Regis "m" ticks; row initialisation "n" ticks ('644 6.2, 6.5). - Clipping: a pixel is written only inside 0..XCLIP, 0..YCLIP (REGCTL1); super-clipping stops rows or cels heading out of view (SDK: cel super-clip "currently not available"). - Destination address = base + modulo x Y + X; REGCTL0 builds each modulo from two shifted terms (32/256/1024 and 64/128/256; bit table from '876 `hardware.h`, C6), REGCTL2 is the frame-buffer read base, REGCTL3 the write base. How Y's low bit picks the bank half is U14. - Control word CEControl (SDK 5gpgk; '235 table 1.4): B15POS 31:30, B0POS 29:28, SWAPHV 27, ASCALL 26, CFBDSUB 24, CFBDLSB 23:22, PDCLSB 21:20. ## Control and status ('235 table 1.8; '642 V) SPRSTRT starts cold (writing it while running is a race), SPRSTOP stops and resets the engine, SPRPAUS requests a pause at the end of the current cel, SPRCNTU continues. An interrupt holds PAUSE so the CPU can run; software polls SPRON and continues. **No completion interrupt**: DrawCels polls. Cels never overlap. The cel watchdog (SetCEWatchDog, default 1 s) is a software timeout that issues SPRSTOP (HYPOTHESIS; '693 sample code does this after 3 VBLs). Register addresses (wiki only): SPRSTRT 0x100, SPRSTOP 0x104, SPRCNTU 0x108, SPRPAUS 0x10C, CEControl 0x110, PIXC 0x120, REGCTL0-3 0x130-0x13C. ## Throughput (the number the speed estimate needs) - SDK gpg 1gpgb: the cel engine "can render nine million pixels nonstop every second", "a single clock cycle per pixel" whatever the format; 300,000 pixels per 1/30 s frame. - SDK gpg 6gpgb: bus bandwidth "at 50 MB/s" is "by far the most critical factor"; frame-buffer reads nearly double the time; a 320x440 16-bit cel spun and zoomed runs at 5-10 fps; cels under a third of the screen run at 30 fps; an opaque 1:1 320x240 background redraw manages "60Hz or better" (6gpga). - DERIVED: 50 MB/s = 12.5 M 32-bit transfers/s = one per 2 ticks; 9 Mpixel/s = about 2.8 ticks or 1.4 transfers per pixel; a 1:1 opaque 16-bpp cel needs 1.5 transfers per pixel (8.3 Mpixel/s); translucent about 2.5 (5 Mpixel/s). A full 320x240 fill at 9 Mpixel/s takes 8.5 ms, half an NTSC field. ## The matrix engine (wiki opera_madam_matrix_engine only; tier 3) MADAM 0x600-0x7FF: a 32x32 multiplier with a 64-bit accumulator; operations 4x4 and 3x3 matrix-vector multiplies (16.16), 3x3 with divide by Z, 4x1, four 1x1, a 16.16 divide, and a CCB generator (corners to HDX..HDDY); 16 matrix words and two 12-word input/output banks that swap on each start; control 0x7F0, status 0x7F8, start 0x7FC; the opcode table differs between Red and Green MADAMs; the CPU polls. The SDK confirms only that the math folio uses "special math hardware" (`pgsfldr/spg/15spg`). No patent describes it; no timing anywhere (U15). It is present only on some MADAM revisions (wiki). ## Fences Portfolio gives tasks whole pages and fences writes outside them (SDK `pgsfldr/spg/01spg003`); MADAM's fence registers (0x230-0x27C, wiki) presumably hold the per-page masks and FENCEV is the abort reason (U7 in memory-map.md). Whether cel writes are fence-checked is U16. ## Unknowns and contradictions (this page) U11 the optional-word fetch and packed layout; U12 MARIA's choice when Munkee cannot decide; U13 the Regis state tables (image scan); U14 modulo and the line-pair layout; U15 matrix engine timing; U16 fence checks on cel writes; U17 FIFO depths (unpacker, IPS-out, frame buffer data, XY); U18 the cost in ticks of a CCB, PLUT and preamble load; U19 pause granularity on an interrupt. C3 FLAGS bit 13 (patent ASC) vs bits 20:19 (SDK ACSC/ALSC); C4 PRE0 SKIPX vs a PACKED copy; C5 PIXC half order (SDK prose vs its own table headers); C6 REGCTL0 bit table ('641 text vs `hardware.h`; take the code); C7 PIXC MS = 10/11 meanings differ between two SDK pages and the patent; C8 partial PLUT loads start at PLUTA (patent) or entry 0 (SDK).