# The Blitter Sources: **[TRM]** p.64-82 (the chapter), p.132-140 (changes from the prototype, bugs) (tier 2); **[NET]** `tom/BLIT.NET`, `STATE.NET`, `INNER.NET`, `OUTER.NET`, `ADDRGEN.NET`, `ADDRADD.NET`, `ADDRCOMP.NET`, `ADDARRAY.NET`, `DATA.NET`, `DATACOMP.NET`, `DATAMUX.NET`, `SRCSHIFT.NET`, `LFU.NET`, `ACONTROL.NET`, `DCONTROL.NET`, `MCONTROL.NET`, `BLITSTOP.NET`, `BLITGPU.NET` (tier 2 as text: **listed, not read line by line in this phase**); Virtual Jaguar's two blitters and MAME's (tier 5, read in part). The Blitter is not a CPU and has no second consumer in the family: it stays in the board (`jaguar_python.tom.blitter`). It sits on the GPU's local bus (its registers are in the GPU block) and is a 64-bit bus master of its own. ## Registers (`F02200-F0229B`; write-only unless noted) [TRM p.30, 70-77] | Address | Name | Notes | | --- | --- | --- | | `F02200` | `A1_BASE` | window base, phrase aligned | | `F02204` | `A1_FLAGS` | pitch 0-1, pixel size 3-5 (2^n bits), Z offset 6-8, width 9-14 (4-bit exponent, 2-bit mantissa), X add 16-17 (phrase / pixel / zero / increment), Y add 18, X sign 19, Y sign 20 | | `F02208` | `A1_CLIP` | window size for clipping, 15 bits each | | `F0220C` | `A1_PIXEL` | Y high word, X low word; **reads back at `F02204`** (bug 10) | | `F02210/14` | `A1_STEP`, `A1_FSTEP` | outer-loop step, integer and fraction | | `F02218` | `A1_FPIXEL` | pointer fraction (read/write) | | `F0221C/20` | `A1_INC`, `A1_FINC` | inner-loop increment (DDA: lines, rotation, scaling) | | `F02224` | `A2_BASE` | | | `F02228` | `A2_FLAGS` | as A1 plus bit 15 mask enable; no increment mode | | `F0222C` | `A2_MASK` | AND mask on the A2 pointer (repeating patterns) | | `F02230` | `A2_PIXEL` | **reads back at `F0222C`** (bug 10) | | `F02234` | `A2_STEP` | | | `F02238` | `B_CMD` (write) / status (read) | **a write starts the blit**; status bit 0 idle, bit 1 stopped, 2-15 diagnostic state bits, 16-31 inner count | | `F0223C` | `B_COUNT` | inner count low word, outer high word; 0 means 65,536 | | `F02240` | `B_SRCD` (64) | source data / Gouraud intensity fractions | | `F02248` | `B_DSTD` (64) | destination data / background | | `F02250` | `B_DSTZ` (64) | | | `F02258/60` | `B_SRCZ1`, `B_SRCZ2` (64) | computed Z integer and fraction parts | | `F02268` | `B_PATD` (64) | pattern / Gouraud intensity integers and colour | | `F02270/74` | `B_IINC`, `B_ZINC` | per-write increments | | `F02278` | `B_STOP` | bit 0 resume, 1 abort, 2 enable collision stops | | `F0227C-88` | intensity ports | 8.16 views of the four Gouraud lanes | | `F0228C-98` | Z ports | 16.16 views of the four Z lanes | **Naming conflict C8**: [TRM p.77] calls `F0227C` "Intensity 0" up to `F02288` "Intensity 3"; [TR10 p.4] and `JAGUAR.INC` call them `B_I3` down to `B_I0` and note that the Software Reference up to v2.2 had the descriptions reversed. Addresses are not in dispute; which lane each address feeds is decided by the netlist or by a picture, not by either name. `B_CMD` bits: 0 `SRCEN`, 1 `SRCENZ`, 2 `SRCENX`, 3 `DSTEN`, 4 `DSTENZ`, 5 `DSTWRZ`, 6 `CLIP_A1`, 7 `NOGO`, 8 `UPDA1F`, 9 `UPDA1`, 10 `UPDA2`, 11 `DSTA2`, 12 `GOURD`, 13 `GOURZ`, 14 `TOPBEN`, 15 `TOPNEN`, 16 `PATDSEL`, 17 `ADDDSEL`, 18-20 `ZMODE` (inhibit if source Z less / equal / greater), 21-24 `LFUFUNC` (four minterms of source and destination), 25 `CMPDST`, 26 `BCOMPEN`, 27 `DCOMPEN`, 28 `BKGWREN`, 29 `BUSHI`, 30 `SRCSHADE` [TRM p.73-75]. ## How a blit runs [TRM p.65-69] - **Outer loop**: `outer count` times: run the inner loop, then the enabled pointer updates (`UPDA1F`, `UPDA1`, `UPDA2`), each costing one clock. - **Inner loop**: `inner count` pixels, either **pixel by pixel** or **phrase by phrase** (X add mode 0: up to 64 bits per write, with start and end masks so partial phrases keep their destination). Per iteration, the enabled memory cycles in this order (the status register's diagnostic bits name the states): extra source read, extra source-Z read, source read, source Z read, destination read, destination Z read, **destination write**, destination Z write. A read-to-write turnaround costs one clock [TRM p.69]. - **Address generators**: A1 (destination by default) with clipping and a 16.16 DDA; A2 (source) with an AND mask. `DSTA2` swaps the roles. Addresses are computed from X, Y, the floating-point width, pixel size and pitch. - **Data**: write data is the logic function of source and destination, or the pattern, or source + destination (saturating), or the Gouraud lanes; the comparators (bit, data, Z) inhibit a pixel's write, or in phrase mode substitute destination data; with `B_STOP` they can halt the blit for collision detection. - **Gouraud and Z**: four pixels per phrase, each lane an 8.16 intensity (or 16.16 Z) plus the increment per write, saturating; colour is protected from intensity carry unless `TOPBEN` / `TOPNEN`. - **Bus**: requests at the start and holds its request to the end; higher priorities interrupt it between cycles; `BUSHI` raises it above the Object Processor ([bus-arbitration.md](bus-arbitration.md)). It raises GPU interrupt 4 when truly idle [TRM p.132]. ## Hardware bugs (the official list, revision-2 silicon) [TRM p.134-140] | # | Bug | For the model | | --- | --- | --- | | 9 | `SRCSHADE` only works with `GOURZ` set | reproduce (data path not set up otherwise) | | 10 | pointer registers read at `F02204` / `F0222C` | reproduce; games read them there | | 11 | A1's Y add bit drives **both** address generators; a Y sign bit still needs its own add bit | reproduce | | 17 | `ADDDSEL` or `SRCSHADE` with Z-buffering corrupts data "sometimes"; mechanism unconfirmed by Atari | undecidable from the manual: netlist or assert | | 18 | A1 clip X not on a phrase boundary clips the right-hand phrase even with `CLIP_A1` clear | reproduce | | 19 | 2-bit-per-pixel shifts fail at some alignments | netlist or assert | | 20 | with `DSTA2`, the A1 clip window still affects the destination | reproduce | | 26 | Z comparator fails in pixel mode without `BKGWREN` | netlist or assert | | 27 | Z registers shifted when `SRCEN` set without `SRCENZ`, unaligned | netlist or assert | | 28-29 | A1 clipping can clip one write early, or miss one, "in a fairly random manner" | timing-dependent: netlist only | | 24 (Tom) | `BUSHI` must not be used: it lets the blitter outrank the Object Processor | arbitration, see there | Plus, from the prototype-differences list [TRM p.132]: pitch code 3 means a pitch of 3 phrases, `IDLE` reflects the last bus transfer, the eight intensity/Z ports exist. "Reproduce" means the behaviour follows from a rule simple enough to state. "Netlist or assert" means the manual gives a symptom only: the first build **asserts** when a program enters that configuration (so a game that needs it is found), and the behaviour is filled in from the netlist. ## The implementation choice: "fast" blit or logic level Every emulator read has both, and neither is a judge. - **Virtual Jaguar, fast ("generic") blitter**: a per-pixel loop written from the manual. In source: it applies the outer-loop step after the last line too, where the manual says the pointer is left at the first unwritten phrase; it treats a zero source pixel as transparent under `DCOMPEN`, which is **not** what the `DATACOMP` module does (it compares with the pattern); several comments mark guesses ("This is a documented Jaguar bug ... Look into it!"). It ignores bus timing entirely. The libretro project's boot matrix "runs only the Fast blitter, so it misses freezes that appear at default settings" (its README). - **Virtual Jaguar's "accurate" blitter** (GPL-3.0; read in Phase 0, not fetched since 2026-11-24, so this paragraph is HYPOTHESIS, for review): a transcription of gate-level modules whose names match the netlist files. **Its author worked from the "Midsummer" documents, the Jaguar II chip**: the comments say "all we have are the Midsummer docs to give us any guidance, and it's incomplete or filled with errors", and mark places as "Bug fix bit in Jaguar II -- not in Jaguar I!" and "TEXTURE DATA READ (not implemented because not in Jaguar I)". So it is the successor chip's logic with the fixes switched off by hand, not Tom's. It has `//Missing: BUSHI`, no bus timing, and the libretro maintainers have since **edited it to agree with the fast one** in at least one place (the zero-source transparency), on the evidence of which pictures look right. - **MAME** (`jag_blitter.cpp`, `jagblit.ipp`): its driver header blames "the unsafe blitter code" for crashes; not read beyond that in this phase. - **MiSTer**: the netlist itself, translated (tier 4 here because of FPGA-side edits elsewhere, but the blitter modules are the closest thing to Tom that runs). **Proposed** (open decision 7 in the brief): one blitter, written **from Tom's own netlist modules** as a readable state machine at the level the netlist works (inner-loop states, one bus cycle per state, phrase-wide data path), not a pixel loop and not a gate list. It is the only form that gives both the bug behaviours and the bus-cycle sequence the arbitration needs. Cost in Python is acceptable because a blit's unit of work is a bus cycle (up to 64 bits), not a pixel. Virtual Jaguar's two engines are then both detectors: where they disagree with each other or with us, the netlist decides. ## Timing Not in the manual beyond: memory-limited, 2 clocks per page-mode cycle, +1 on read-to-write turnaround, +1 per outer-loop update. The inner-loop state sequence in `INNER.NET` gives the rest. Classic Virtual Jaguar completes a blit instantly at the `B_CMD` write (the libretro fork has since added a bus arbiter with estimated costs); BigPEmu offers a user "Blitter speed" setting, per its FAQ). Games that poll the idle bit or wait on the blitter interrupt see the difference; MAME's `battlesp` hack is one such case.