# The Intel 8257 DMA controller DKM's CPU board list has an **8257-5** (DOC); MAME has `dma8257` "Intel 8257 DMA Controller @ 3.07 MHz" (OBSERVED). The 8257's own behaviour is in Intel's data sheet (I8257; tier 2): four channels, each a 16-bit address register and a 16-bit terminal count register whose top two bits give the cycle type and whose low 14 bits hold the transfer count minus one; a mode set register (bit 7 auto load, bit 6 TC stop, bit 5 extended write, bit 4 rotating priority, bits 0-3 channel enables); a status register; DRQ/DACK per channel, HRQ/HLDA to the CPU, a MARK output every 128 cycles, TC at the end. ## What the program does (MAME trace at frame 600; OBSERVED) Every frame, during vertical blank (line 241): | Write | Value | Meaning by I8257 | | --- | --- | --- | | 7808 (mode set) | 0x53 | TC stop, rotating priority, channels 0 and 1 enabled | | 7800 (ch 0 address) | 0x00, 0x69 | 0x6900: the staging copy in work RAM | | 7801 (ch 0 count) | 0x80, 0x41 | count 0x180 (+1), type bits 01 | | 7802 (ch 1 address) | 0x00, 0x70 | 0x7000: sprite RAM | | 7803 (ch 1 count) | 0x80, 0x81 | count 0x180 (+1), type bits 10 | then 7D85 pulses 0, 1 (line 242) and back to 0 (line 258). In I8257's table the two type bits mean verify (00), write (01) and read (10); so channel 0 is set for DMA writes and channel 1 for DMA reads (the bit table read from the data sheet's scan, since its OCR loses that figure: confirm, U7). A memory-to-memory copy through two channels needs the board to pair them (one reads, a latch holds the byte, the other writes) with the request (7D85) on both DRQ lines; how TKG-4 wires DRQ0/DRQ1, DACK, MEMR/MEMW and the latch is on DKS's CPU sheet (U8). ## What the board specification needs - An `I8257` class in this board (no other family board has an 8257 today: chip rule) that models the registers, the first/last flip-flop for 16-bit writes, mode set, status, and each DMA cycle: 4 clocks per transfer in the data sheet's state diagram (S1-S4), with READY extending them. - Bus arbitration with the Z80: the 8257 raises HRQ to the Z80's BUSREQ and waits for BUSACK (HLDA). z80-python has no BUSREQ input. The board takes the bus between Z80 instructions (the Z80 grants BUSREQ only at the end of a machine cycle; between instructions is a superset of correct points for a board that cannot see machine cycles), runs the DMA's cycles, and charges their time to the CPU. Exact stall timing within an instruction is the open question U9; if it shows in a trace, a request to z80-python for machine-cycle granularity follows. - Cost per frame: about 385 transfers; at 4 DMA clocks each on a 3.072 MHz clock that is about 1,540 clocks (0.5 ms), CPU stalled throughout (HYPOTHESIS from the data sheet's timing until U8 is read). Donkey Kong 3 uses a **Zilog Z80 DMA** instead (DK3M: "Z80A DMA Controller" at 5B; MAME `z80dma`): a different chip, documented in ZDMA, needed only for the DK3 row.