PRIOR and GPRIOR: Priority Register Tricks
When a player overlaps the playfield, GTIA has to decide which colour to show. That decision is controlled by one register, PRIOR, which also holds two of the Atari's best-known extras: the "fifth player" made from the four missiles, and multicolour players that mix colours where they overlap. Its top two bits even switch on the GTIA graphics modes. Many programs set it once, typically with POKE 623,1, and never touch it again. But every bit is worth knowing, and a DLI can change it as often as you like.
What you'll learn: all eight bits of PRIOR, what happens with conflicting or zero priority bits, how to use the fifth player and multicolour players properly, the masking trick for high-resolution players, and how to change priority part way down the screen.
What you need: player/missile graphics already working (see Player/Missile Graphics in Atari BASIC or Player/Missile Graphics in Assembly), and MADS for the demonstration program.
1. The register
PRIOR is the write-only GTIA register at $D01B (53275). Its OS shadow GPRIOR is at 623 ($26F), and the OS copies GPRIOR into PRIOR every vertical blank. From BASIC you POKE 623; inside a DLI you write $D01B directly. Add up the options you want:
| Value | Bit | Effect |
|---|---|---|
| 1 | 0 | Players 0–3 in front of all playfield colours |
| 2 | 1 | P0, P1 in front of the playfield; playfield in front of P2, P3 |
| 4 | 2 | All playfield colours in front of all players |
| 8 | 3 | PF0, PF1 in front of the players; players in front of PF2, PF3 |
| 16 | 4 | Fifth player: all four missiles use COLPF3 (711) |
| 32 | 5 | Multicolour: overlapping P0+P1 and P2+P3 OR their colours |
| 64 / 128 / 192 | 6–7 | GTIA modes 9 / 10 / 11 |
Choose one of the four priority values, then add any of the extras. Within the players, a lower number always wins (P0 over P1 over P2 over P3), and the background colour is always at the back.
2. Seeing them all at once
This MADS program draws mode 4 bars in PF0 (red), PF1 (green), PF2 (blue) and PF3 (inverse characters, gold). Over them it places four quadruple-width players, with P0/P1 and P2/P3 overlapping by half, and the four missiles side by side at the right. A DLI before each band's label sets PRIOR, and a second DLI switches from the ROM font for the label to the mode 4 font for the bars (the technique from Character Set Switching with DLIs):
; seven PRIOR settings on one screen - mads prior.asm -o:prior.xex
VDSLST = $0200
SDMCTL = $022F
SDLSTL = $0230
GPRIOR = $026F
PCOLR0 = $02C0 ; 704-707 player colour shadows
COLOR0 = $02C4 ; 708-712 playfield colour shadows
HPOSP0 = $D000
HPOSM0 = $D004
SIZEP0 = $D008
SIZEM = $D00C
GRACTL = $D01D
PRIOR = $D01B
PMBASE = $D407
CHBASE = $D409
WSYNC = $D40A
NMIEN = $D40E
SETVBV = $E45C
SYSVBV = $E45F
PM = $3000 ; single-line P/M memory (2K aligned)
FONT = $4000 ; mode 4 font: chars 1-3 are solid PF0-PF2
idx = $80
ptr = $81
cnt = $83
org $2000
main lda #0 ; clear P/M memory and the font
sta ptr
lda #>PM
sta ptr+1
ldx #12 ; $3000-$3BFF (PM area + spare)
ldy #0
tya
clr sta (ptr),y
iny
bne clr
inc ptr+1
dex
bne clr
lda #0
sta ptr
lda #>FONT
sta ptr+1
ldx #4
clr2 sta (ptr),y
iny
bne clr2
inc ptr+1
dex
bne clr2
ldx #7 ; char 1 = PF0, 2 = PF1, 3 = PF2 (PF3 if inverse)
defch lda #%01010101
sta FONT+8,x
lda #%10101010
sta FONT+16,x
lda #%11111111
sta FONT+24,x
dex
bpl defch
lda #7 ; P/M data: 16 solid lines in each band
sta cnt
ldy #32+8 ; first band's bar rows start here
band ldx #16
fill lda #$FF
sta PM+$300,y ; missiles
sta PM+$400,y ; players 0-3
sta PM+$500,y
sta PM+$600,y
sta PM+$700,y
iny
dex
bne fill
tya
clc
adc #8 ; skip the next band's label line
tay
dec cnt
bne band
ldx #3 ; positions, sizes, colours
pos lda px,x
sta HPOSP0,x
lda mx,x
sta HPOSM0,x
lda #3 ; quadruple width
sta SIZEP0,x
lda pcol,x
sta PCOLR0,x
dex
bpl pos
lda #$FF ; all missiles quadruple width
sta SIZEM
ldx #4
cols lda pfcol,x
sta COLOR0,x
dex
bpl cols
lda #>PM
sta PMBASE
lda #3
sta GRACTL
lda #<dlist
sta SDLSTL
lda #>dlist
sta SDLSTL+1
lda #$3E ; P/M DMA, single-line, normal playfield
sta SDMCTL
lda #6
ldy #<vbi
ldx #>vbi
jsr SETVBV
lda #<dli
sta VDSLST
lda #>dli
sta VDSLST+1
lda #$C0
sta NMIEN
jmp *
vbi lda #0
sta idx
jmp SYSVBV
dli pha
txa
pha
ldx idx
lda prtab,x
sta WSYNC
sta PRIOR ; hardware register (GPRIOR is the shadow)
lda chtab,x
sta CHBASE
inc idx
pla
tax
pla
rti
; one entry per DLI: label line (ROM font) then bar rows (mode 4 font)
prtab dta $01,$01, $02,$02, $04,$04, $08,$08, $00,$00, $21,$21, $11,$11
chtab dta $E0,>FONT, $E0,>FONT, $E0,>FONT, $E0,>FONT, $E0,>FONT, $E0,>FONT, $E0,>FONT
px dta 48, 64, 112, 128 ; P0/P1 overlap by 16, P2/P3 likewise
mx dta 176, 184, 192, 200 ; four missiles side by side
pcol dta $46, $98, $2A, $E4
pfcol dta $34, $CA, $84, $1A, $00 ; PF0 red, PF1 green, PF2 blue, PF3 yellow, BAK
dlist dta $70,$70,$F0 ; DLI: band 1 label settings
dta $C2,a(screen) ; label, LMS, DLI: switch to mode 4 font
dta $04,$84 ; two bar rows, DLI: next band's label
.rept 5
dta $82,$04,$84
.endr
dta $82,$04,$04
dta $41,a(dlist)
screen
dta d' PRIOR=1 PLAYERS OVER ALL PLAYFIELD '
:2 dta 1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131
dta d' PRIOR=2 P0 P1 > PLAYFIELD > P2 P3 '
:2 dta 1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131
dta d' PRIOR=4 PLAYFIELD OVER ALL PLAYERS '
:2 dta 1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131
dta d' PRIOR=8 PF0 PF1 > PLAYERS > PF2 PF3 '
:2 dta 1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131
dta d' PRIOR=0 NO PRIORITY: COLOURS MIX '
:2 dta 1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131
dta d' PRIOR=33 BIT 5: P0+P1, P2+P3 OR '
:2 dta 1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131
dta d' PRIOR=17 BIT 4: MISSILES USE PF3 '
:2 dta 1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131,1,1,2,2,3,3,131,131
run main
Reading the screenshot from top to bottom:
- PRIOR=1: all players and missiles cover the bars completely.
- PRIOR=2: P0 and P1 (left) cover the bars; P2 and P3 (middle) disappear behind them except where the background shows.
- PRIOR=4: every bar is in front of every player; the players appear only in the background gaps.
- PRIOR=8: red and green (PF0, PF1) cut through the players, while the players cover blue and gold (PF2, PF3). This is the mode for a sprite that walks between a foreground and a background layer.
- PRIOR=0, PRIOR=33 and PRIOR=17 are covered below.
3. PRIOR=0: colours mix
With no priority bit set, GTIA turns off most of its "who hides whom" logic. Player 0 and 1 mix with PF0 and PF1, and players 2 and 3 mix with PF2 and PF3. Where they overlap you see the bitwise OR of the two colour registers. P0, P1, PF0 and PF1 still win over PF2, PF3, P2 and P3. In the PRIOR=0 band the left players turn red and green bars into new colours, and the middle ones do the same over blue and gold.
This is a legitimate way to get more colours on a line. Combined with multicolour players (below), a single scan line can show far more colours than the nine colour registers alone, without any DLIs. Because the results are ORs, choose colour values so the mixes look sensible; greys make a good background layer, since ORing a grey into a hue changes mostly its brightness.
4. Conflicting bits turn things black
Set more than one of bits 0–3 and GTIA's suppression signals overlap. Some combinations of player and playfield then show no colour at all, not even background, and come out black. In practice it means: pick exactly one priority value unless you are deliberately using black as a colour.
5. Bit 5: multicolour players
With bit 5 set, P0+P1 and P2+P3 are allowed to overlap without hiding each other, and the overlapping pixels show the OR of their two colours. The missiles pair the same way (M0+M1, M2+M3). Other pairs, such as P1 and P3, don't mix. Without bit 5 the overlap shows only the higher-priority player, as the PRIOR=1 band shows: player 0 simply covers player 1.
In the PRIOR=33 band (32 + 1), the yellow-green block in the left pair and the pale band in the middle pair are the third colours. Draw one player as the outline and its partner as the fill, position them together, and you have a three-colour sprite (two colours plus their OR). It is the standard way to make colourful sprites on the Atari. Multicolour mode has no effect on collision detection: each player still reports its own collisions.
6. Bit 4: the fifth player
With bit 4 set, all four missiles take their colour from COLPF3 (711) instead of from their players. That's all it does: each missile keeps its own HPOSM register and its two bits in the shared missile byte. To use the missiles as a fifth player, put them side by side (as in the PRIOR=17 band, four quadruple-width missiles 8 colour clocks apart make one 32-clock object) and move all four together.
Some details matter:
- Priority: the fifth player takes PF3's place in the priority order, except that it always wins against the other playfield colours. In the PF0/PF1-in-front mode (8) this gives an odd result: where PF0 or PF1, a player and the fifth player all overlap, the fifth player's colour shows.
- Collisions are unchanged. Each missile still reports in M0PF–M3PF and M0PL–M3PL; no extra PF3 collisions appear.
- Colour sharing. COLPF3 is also the colour of inverse
11pixels in ANTIC 4/5, the fourth GRAPHICS 1/2 colour, and so on. If your playfield uses PF3, the fifth player shares that colour, unless a DLI changes it between areas. - You can use just the colour. Leave the missiles apart and you have four independent bullets in one shared colour, which leaves the players' colours free to change.
7. More tricks
Masking a player for higher resolution. This trick dates back to Atari's own 1982 programming guide. Make a quadruple-width solid player, set PRIOR=4 so the playfield hides it, and fill the screen with a playfield colour that is set to look like the background (a "false background"). Wherever you draw true background (colour 0), you cut a hole through which the player shows. The player's colour appears with playfield resolution instead of its own 32-colour-clock blobs.
Colouring hi-res screens. In GRAPHICS 0 and 8 the whole playfield counts as PF2 for priority, and the pixel data bypasses the priority logic: set pixels simply impose PF1's luminance on whatever is shown, players included. With players in front of the playfield (PRIOR=1), a player over a line of text replaces the PF2 background with its own colour, and the text still shows in PF1's luminance in the player's hue. This is a cheap way to colour parts of a hi-res picture or a title line.
Changing PRIOR mid-screen. The demo above changes PRIOR seven times per frame. Writes to bits 0–3 and 5 take effect two colour clocks later, so store PRIOR straight after STA WSYNC, like a colour. Typical uses: players in front of a status panel but behind scenery in the playfield, or GTIA-mode graphics above a normal text window. Bits 6–7 take three to five colour clocks to change and can leave a slightly glitched pixel if changed mid-line, so switch GTIA modes only during horizontal blank.
Hiding stray players. After pressing BREAK in a P/M program, POKE 623,4 tucks leftover players behind the playfield, and POKE 53277,0 turns P/M graphics off.
8. GTIA mode bits
Bits 6 and 7 select GRAPHICS 9 (64), 10 (128) or 11 (192); GTIA Graphics Modes 9, 10 and 11 covers them in depth. The OS's GRAPHICS command manages these two bits for you: it clears them for ordinary modes and sets them for GRAPHICS 9–11, leaving bits 0–5 alone. If you later POKE 623,1 for player priority in GRAPHICS 9, you switch the GTIA mode off; POKE 623,65 (64 + 1) keeps both. In mode 9 and 11 the playfield behaves like background for priority, so players always appear in front.
Troubleshooting
- Player overlap shows black instead of a third colour: bit 5 isn't set, or the overlapping players aren't a 0/1 or 2/3 pair.
- Overlaps with the playfield go black: more than one of bits 0–3 is set.
- GTIA picture turns into stripes when you add players: you overwrote bits 6–7 of GPRIOR. Add the mode value back in.
- DLI priority change shows on the line below or flickers: you wrote GPRIOR (623) instead of PRIOR ($D01B), or stored before WSYNC.
- Fifth player isn't one object: the missiles still need four HPOSM writes and must be moved together.
Further reading
- De Re Atari (Atari, 1982), Chapter 4: priorities, the fifth player, and the player-masking program (Figure 4-3).
- Mapping the Atari by Ian Chadwick (COMPUTE! Books), entries 623 and 53275: priority tables and the overlap rules.
- Altirra Hardware Reference Manual, sections 6.7–6.10: the exact priority logic, the conflict table, fifth-player quirks and mid-line timing.
- AtariAge forum thread "Priority_0 explanation" (2019): how PRIOR=0 mixing works in ANTIC 4/5 games.
- Atari Graphics and Arcade Game Design by Jeffrey Stanton and Dan Pinal (Arrays, 1984), Chapter 5: priority registers in practice.
Credits
- Picture: The example program: the same players, missiles and playfield bars shown under seven PRIOR settings, switched by DLIs. — Program authors; screenshot by the site
- Altirra Hardware Reference Manual, sections 6.7 (priority control, conflicts, fifth player, multicolour), 6.8 (high resolution modes), 6.9 (GTIA modes) and 6.10 (cycle timing) — Avery Lee (Altirra)
- Mapping the Atari (revised) — 623 GPRIOR, 53275 PRIOR, 53277 GRACTL, 711 COLOR3 — AtariArchives.org
- De Re Atari, Chapter 4: Player-Missile Graphics (priorities, fifth player, masking a player, Figure 4-3) — Chris Crawford (Section 4 of De Re Atari)
- Atari 400/800 Operating System Source Listing, Rev. A — screen open routine (GPRIOR GTIA bits set/cleared by GRAPHICS) — ksquiggle
- AtariAge forum — Priority_0 explanation (2019) — AtariAge forum members, 2019
- Atari Graphics and Arcade Game Design (Stanton & Pinal), Chapter 5: priority registers — AtariArchives.org
