# DMA, the root counters and the interrupt controller Sources: psx-spx `dmachannels.md`, `timers.md`, `interrupts.md` at `6d7d1bc` (tier 3); ps1-tests `dma/*` (chain-looping, chopping, otc-test) and `timer/timers` (MIT, with `psx.log`); psxdev `wiki_eng/cpu.md` (pins). All three are on the CPU chip and are **memory-mapped peripherals in psx-python**. ## Interrupt controller (DOC psx-spx `interrupts.md`) I_STAT 1F801070h (write 0 to acknowledge), I_MASK 1F801074h. Sources: 0 VBLANK, 1 GPU (GP0 1Fh), 2 CD-ROM, 3 DMA, 4-6 timers 0-2, 7 controller/memory card byte received, 8 SIO, 9 SPU, 10 lightpen/PIO. **Edge-triggered**: a bit sets only on a false-to-true change of its source. `(I_STAT & I_MASK) != 0` drives the CPU's CAUSE bit 10 as a level (no latch on the CPU side). Acknowledge order matters (I_STAT first, then the device), or an edge is lost (psx-spx's SIO0 example) - the spec models the source lines as signals and the edge detector, not as a "raise interrupt" call, so this falls out. ## DMA (DOC psx-spx `dmachannels.md`) Seven channels: 0 MDECin, 1 MDECout, 2 GPU, 3 CD-ROM, 4 SPU, 5 PIO, 6 OTC. Per channel MADR, BCR, CHCR; DPCR (priorities, enables, CPU priority), DICR (interrupt flags, master enable). Sync modes: 0 burst (optionally "chopped" with DMA and CPU windows), 1 block (device-paced by DREQ), 2 linked list (the GPU ordering table). Rates psx-spx gives: MDEC/GPU/OTC 1 cycle/word (0110h cycles per 100h words), SPU 4, CD-ROM 24 (BIOS) or 40 (games), PIO 20 ("XXX is SPU really only 4 clks?" - psx-spx's own doubt, **U1**). DMA uses DRAM hyper-page mode, "around 17 cycles per 16 words". **The CPU during DMA** (psx-spx "CPU Operation during DMA"): the CPU keeps running from the i-cache, the scratchpad, COP0 and the GTE, and may fill the 4-entry write queue; any RAM or I/O read, or a fifth queued write, stalls it until the DMA (or the current block / list entry / chopping window) ends. This is the main reason the CPU and the DMA are one domain (domains.md). ps1-tests: `otc-test` (unit tests for DMA6), `chopping` (sync mode 0 chopping through GPU VRAM DMA), `chain-looping` (a self-referencing OT list): TEST ROM judges with `psx.log`. ## Root counters (DOC psx-spx `timers.md`) Three 16-bit counters at 1F801100h + 16 x N (COUNT, MODE, TARGET). Sources: timer 0 the system clock or the GPU dot clock; timer 1 the system clock or HBLANK; timer 2 the system clock or /8. Sync modes against HBLANK/VBLANK; reset at target or FFFFh; IRQ on target and/or overflow, one-shot or repeat, pulse or toggle. Stated corner timings: after a MODE write the counter holds 0 for 2 cycles; after a COUNT write it holds that value 2 cycles; a wrap at FFFFh holds 0 one cycle, a reset at target two (psx-spx "Reset and Wrap", written as observations: tier 3). Reading a counter clocked by the GPU is "unstable" because the GPU clock is not synchronous with the CPU's (psx-spx): the spec defines the read at the CPU's cycle against the GPU domain's dot counter (domains.md: a sync point). The dot clock input ignores fractions (340.6 dots/line counts 340; 425.75 counts 426 - psx-spx nocash notes; **U2**, judge ps1-tests `timers` log). ## Unknowns - U1 SPU and CD DMA word rates (psx-spx doubts the SPU's 4 cycles). - U2 The dot-clock rounding into timer 0. - U3 DMA arbitration between channels of equal priority mid-transfer, and when exactly a pending higher-priority request preempts. - U4 Refresh cycles' cost to DMA and CPU (DRAM_CTRL bits 0-2, psx-spx, recent edits).