The blitter is the part of the Amiga’s Agnus chip that moves graphics. A program loads a dozen registers with addresses, sizes and a logic function, writes one last register, and the blitter starts copying rectangles of memory by itself, while the 68000 carries on with the game. Commodore’s Hardware Reference Manual rated it at “approximately twice as fast as the 68000” for copying, “able to move almost four megabytes per second”, and able to draw lines “at almost a million pixels per second”.
What made it more than a fast copier was the logic between input and output. The blitter reads up to three sources, combines them bit by bit in any one of 256 ways, and writes the result, so the same hardware can copy, clear, invert, merge or mask. Games used it to draw their bobs, short for blitter objects: shapes of any size stamped onto the background, as many as the frame had time for, where the Amiga’s eight hardware sprites ran out. Dave Jones, writing about his first game Menace in Amiga Format in 1990, explained the term to readers: “Many people refer to software sprites on the Amiga as BOBS, short for Blitter OBjectS, as they tend to be drawn using the blitter.”
Fast facts
- Location: inside Agnus, beside the copper.
- Channels: three sources, A, B and C, and one destination, D.
- Operations: block copy with any of 256 logic functions, shifting by 0-15 pixels, area fill, line drawing.
- Blit size: 1-64 words wide and 1-1024 lines high on the original chips. The Enhanced Chip Set (ECS) allows much larger blits.
- Memory: Chip memory only. It cannot read or write Fast memory.
- Speed: 4 to 8 clock ticks per word, depending on which channels are switched on, before competition from the display and other DMA.
Words, not bits
The manual is blunt about one thing: “The blitter is a word blitter, not a bit blitter.” Everything it fetches and writes is a 16-bit word, and an Amiga screen is made of bitplanes, one bit of each pixel’s colour in each plane. A 16-colour screen has four planes, so drawing one coloured object takes four blits, one for each plane.
A blit is a rectangle of words. BLTSIZE holds the height in its top ten bits and the width in words in its low six, and writing it starts the blit. Each channel has a pointer and a modulo, a number of bytes added to the pointer at the end of every row, so the blitter can work on a small rectangle inside a wider bitmap. The modulo is in bytes, not words. For a 2-word (32-pixel) rectangle on a 320-pixel screen, whose rows are 40 bytes long, the modulo is 40 − 4 = 36.
256 ways to combine three sources
Take one bit from each of A, B and C. There are eight possible combinations, and for each one the program decides whether D gets a 0 or a 1. Those eight answers are the low byte of BLTCON0, which the manual calls the logic function (LF) control byte. Eight yes-or-no answers make 2⁸ = 256 functions, and the manual promises all of them: the blitter “can combine the data from the three source DMA channels in up to 256 different ways”.
| Bit of LF byte | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| A B C | 1 1 1 | 1 1 0 | 1 0 1 | 1 0 0 | 0 1 1 | 0 1 0 | 0 0 1 | 0 0 0 |
To find the byte for a function, mark a 1 under every combination where D should be 1. Some useful ones:
| LF byte | Result |
|---|---|
$F0 |
D = A (copy A) |
$CC |
D = B |
$AA |
D = C |
$0F |
D = NOT A |
$00 |
D = 0 (clear) |
$5A |
D = A XOR C |
$CA |
D = (A AND B) OR (NOT A AND C), the cookie cut |
The cookie cut
The manual explains the most important of these with a car driving past buildings. Channel A reads a one-plane mask with a bit set wherever the car is solid; B reads the car; C reads the background; D writes the screen. Where the mask is 1, D takes the car; where it is 0, D keeps the background. That is “the cookie-cut function”, AB + ĀC, byte $CA. C and D point at the same place on screen, because the blitter can only write whole words and has to read the background it is about to overwrite.
Masked drawing is therefore not a special mode. It is one value of a control byte, with the mask in channel A. The same mask serves every bitplane of the object. To move the car, a program saves the background under it with a copy ($F0), draws the car, and next frame copies the saved background back before drawing again. The Amiga pattern Cookie-cut blit gives a working routine.
Shifting and masking
Word addresses fall every 16 pixels, but objects move one pixel at a time. Channels A and B each have a barrel shifter that moves the data right by 0 to 15 bits as it passes through, set in the top four bits of BLTCON0 for A and of BLTCON1 for B. The manual stresses that the shift is free: a shifted blit takes no longer than an unshifted one, where a 68000 would pay for every bit.
A shifted object spills into one more word on the right, so the blit is made a word wider. The bits shifted out of one row carry into the next, which is why channel A also has a first-word mask and a last-word mask (BLTAFWM, BLTALWM), applied to the first and last word of every row before the shift. When unused they must hold $FFFF.
A channel that is switched off still takes part in the logic; it just uses the constant in its data register instead of fetching memory. The manual’s own example draws a rectangle on an odd pixel boundary with A switched off, its data register loaded with $FFFF, and the two word masks doing the cutting.
Programmers found the masks awkward. Andrew Braybrook’s diary of Paradroid 90 in Amiga Action recorded that all his blitter screen drivers worked “now that I’ve logically inverted the mask on all of the graphics”: “The blitter is a strange beast, for the first and last word masks to work correctly, the data mask has to be the opposite way round from the way the 68000 would like it.”
Descending mode
Copying a block to an overlapping place lower in memory would overwrite rows before they were read. Setting the DESC bit in BLTCON1 runs the blit backwards: pointers count down, modulos are subtracted and shifts go left. The pointers then start at the last word of the block.
Area fill
The blitter can fill shapes while it copies. The program first draws the outline with only one set bit per row on each edge; line mode has a setting for exactly that. Then it runs a blit in descending mode with inclusive fill (IFE, bit 3 of BLTCON1) or exclusive fill (EFE, bit 4). Working from the right of each row to the left, the blitter flips between filling and not filling every time it meets a set bit.
The manual’s example shows the difference on one row:
| Bits | |
|---|---|
| Outline | 00100100 |
| Inclusive fill | 00111100 |
| Exclusive fill | 00011100 |
Inclusive fill keeps both edges. Exclusive fill removes the left-hand edge, making shapes one pixel narrower, and is the one to use for sharp single-point corners. A third bit, FCI, starts each row filled instead of empty.
Outline plus fill is how the Amiga drew solid polygons. Amiga Computing reported in 1988 that some of the 3D algorithms in F/A-18 Interceptor were designed around the blitter’s line drawing and area fill. Jez San of Argonaut was more cautious in the same feature: “The blitter is very good at filling large areas”, he said, but the chip “needs to be set up, sent the position and shape it has to fill and then told to do the job”, and that setting-up could take longer than drawing a small shape with the 68000.
Line drawing
Setting bit 0 of BLTCON1 puts the blitter in line mode, which gives several registers new meanings. It draws lines up to 1024 pixels long between two points, with a 16-bit texture pattern for dotted or dashed lines. The program works out which of eight octants the line points into and puts that in BLTCON1. It then loads the A pointer and the A and B modulos with the step values of a Bresenham-style line algorithm, taken from the line’s longer and shorter distances (4 × short − 2 × long, 4 × (short − long) and 4 × short), and sets the height in BLTSIZE to the line’s length with a width of 2.
The logic function still applies. $CA draws a normal line; an exclusive-OR function draws a line that can be erased by drawing it again. A single-dot-per-row setting (SING) makes outlines for the area fill. Each pixel costs eight clock ticks. The Amiga pattern Blitter line draw sets up a line step by step.
How fast it is
The manual gives the cost of a blit in clock ticks per word. Four is the minimum. Channel A is free, B adds two ticks, and C and D are free alone but add two ticks when both are on. So:
| Channels | Ticks per word | Typical job |
|---|---|---|
| A, D | 4 | Copy, save or restore background |
| B, D | 6 | Copy through B |
| A, B, C, D | 8 | Cookie cut |
The time in microseconds is ticks × height × width ÷ 7.16 on NTSC machines, or ÷ 7.09 on PAL ones. By that formula a cookie cut of a 32×32 object in five bitplanes, three words wide to allow for the shift, takes 8 × 32 × 3 × 5 ÷ 7.09, about 540 microseconds, under 3 per cent of a 50 Hz frame. Saving and restoring the background under it adds about the same again.
Those figures assume the blitter has the bus to itself, and it never does. Disk, audio, sprite and bitplane DMA and the copper all come first. The manual prints a table of the blitter’s cycle order and then declines to stand by it: “Bus cycles are dynamically allocated based on blitter operating mode; competing bus activity from processor, bitplanes, and other DMA channels; and other factors.” A screen with more bitplanes leaves fewer free slots. The Amiga system entry shows how quickly the display uses them up.
The blitter’s speed did not change with the AGA machines of 1992. Asked in 1994 about games written for the A1200, Shaun Southern of Magnetic Fields told The One that apart from the processor “the only thing which is any faster … is the screen fetch. If you want more colours then you have to put more data down, but the blitter’s no faster at all.”
The blitter and the 68000
After the fixed DMA channels and the copper, the blitter comes before the processor. Left alone, the manual says, “the blitter would steal every available Chip memory cycle”. Normally it holds back a little: if the 68000 has waited three memory cycles in a row, the blitter lets it have the next one.
Bit 10 of DMACON, BLTPRI, removes that courtesy. Commodore’s manual gives it the name programmers used: “Also known as ‘blitter-nasty’”. With it set, “the blitter has full (instead of partial) priority”, and the processor gets no Chip memory cycles until the blit finishes. A 68000 running code from Chip memory stops. One running from Fast memory or ROM carries on. Programmers set the bit when the blit mattered more than anything the processor could do in the meantime.
Waiting for the blitter
Writing BLTSIZE starts a blit and returns at once. Before changing any blitter register, or using the result, a program has to wait for bit 14 of DMACONR, the blitter-busy flag, to clear. The manual adds a trap: on early chips the flag might not be set yet if the blit has not had its first memory cycle, so it recommends reading the register twice and trusting the second answer.
wait_blit:
btst #6,$dff002 ; first read may be stale on early Agnus chips
.loop:
btst #6,$dff002 ; bit 6 of the high byte = bit 14, BBUSY
bne.s .loop
rtsbtst on a memory address reads a single byte and uses a bit number from 0 to 7. DMACONR is at $dff002, so the byte read is the register’s high half, and bit 6 of that byte is bit 14 of the register. The manual writes the same test as #DMAB_BLTDONE-8. Starting with the Fat Agnus chip the flag is set as soon as BLTSIZE is written, but the manual advises testing twice anyway because not every machine has the newer chip.
Programs running under the operating system use its OwnBlitter(), DisownBlitter() and WaitBlit() functions instead of taking the chip directly.
The zero flag
The blitter also sets a flag, BZERO in DMACONR, if every bit it produced was 0, even with channel D switched off so nothing is written. AND two masks together without writing anything, and the flag says whether they overlap. Dave Jones used it for collisions in Menace, whose aliens were bobs: “We cannot use the Amiga’s hardware detection for missiles to aliens as this only works with hardware sprites. The blitter can do a quick check for us, though.” His blit ANDed a missile’s mask with the bitplane that held only the aliens.
Registers
The blitter’s registers sit in the custom chip area from $DFF040. All are write-only.
| Register | Address | Purpose |
|---|---|---|
BLTCON0 |
$DFF040 |
A shift (bits 15-12), channel enables A-D (bits 11-8), logic function (bits 7-0) |
BLTCON1 |
$DFF042 |
B shift (bits 15-12), EFE, IFE, FCI, DESC, LINE; other meanings in line mode |
BLTAFWM |
$DFF044 |
First-word mask for A |
BLTALWM |
$DFF046 |
Last-word mask for A |
BLTCPT |
$DFF048 |
C pointer |
BLTBPT |
$DFF04C |
B pointer |
BLTAPT |
$DFF050 |
A pointer |
BLTDPT |
$DFF054 |
D pointer |
BLTSIZE |
$DFF058 |
Height and width; writing it starts the blit |
BLTCMOD |
$DFF060 |
C modulo |
BLTBMOD |
$DFF062 |
B modulo |
BLTAMOD |
$DFF064 |
A modulo |
BLTDMOD |
$DFF066 |
D modulo |
BLTCDAT |
$DFF070 |
C data |
BLTBDAT |
$DFF072 |
B data |
BLTADAT |
$DFF074 |
A data |
ECS adds BLTCON0L ($DFF05A), which writes only the logic function, and BLTSIZV and BLTSIZH ($DFF05C, $DFF05E) for the larger blit sizes. The Amiga pattern Blitter copy shows the minimum set of registers for a plain copy.
Sources
- Amiga Hardware Reference Manual, 3rd edition (Commodore-Amiga, Addison-Wesley, 1991), chapter 6, “Blitter Hardware”: what the blitter is, its speed and Chip-memory limit (p. 169); a word blitter, DMA channels (p. 170); blit size (p. 171); modulos in bytes, ECS limits (p. 172); the function generator (pp. 174-175); the cookie-cut example (p. 176); Table 6-1, common minterms (p. 177); shifts and masks (pp. 179-181); descending mode (p. 182); area fill (pp. 184-186); the blitter-done flag and testing it twice (pp. 186-187); the zero flag (p. 187); pipelining and the cycle table’s disclaimer (pp. 188-189); line mode (pp. 189-192); blitter speed (p. 193); DMA priorities (p. 194); the blitter-nasty bit (p. 198). Also the overview of sprites and the blitter (pp. 3-4);
DMACON(p. 222);BLTCON0andBLTCON1(p. 267);DMACONand/BLS(p. 278); the ECS blitter registers (Appendix A, pp. 268-269); register addresses (Appendix B, pp. 289-290). - Amiga Format, issue 7, February 1990, p. 64: Dave Jones (DMA Design), “The Menace Within”, on bobs and masking. Issue 12, July 1990, p. 158: the same series, on collisions with the
BZEROflag. - Amiga Action, issue 10, July 1990: “From Start to Finish: The Diary of a Game”, Andrew Braybrook on Paradroid 90.
- Amiga Computing, October 1988, pp. 16-17: feature on solid 3D graphics, with Jez San on the blitter and F/A-18 Interceptor’s use of line drawing and area fill.
- The One, issue 72, September 1994: interview with Magnetic Fields, Shaun Southern on the A1200.
- AmigaWorld, January 1995, p. 13: the Amiga 1000’s launch in July 1985 and shipping in September.
See also
- Agnus: the chip that contains the blitter.
- Copper: the other co-processor in Agnus, which can also start a sequence of blits.
- The Amiga custom chipset and Denise: how the pieces fit together.
- Commodore Amiga: the machine, and how display DMA limits the blitter.
- Bob graphics and Double buffering: the techniques built on it.