gs: regs.lisp

the GS's general registers as an ISA: addresses, fields, semantics.

0/1 a fixed bit, name a field,   a bit the decoder ignores

PRIM source

Drawing primitive setting: the type starts a new primitive (the queue is emptied)

Address0x00
313029282726252423222120191817161514131211109876543210
fixctxtfstaa1abefgetmeiipprim
(defgsreg PRIM #x00 ((prim 0 3) (iip 3 1) (tme 4 1) (fge 5 1) (abe 6 1) (aa1 7 1) (fst 8 1)
                     (ctxt 9 1) (fix 10 1))
  "Drawing primitive setting: the type starts a new primitive (the queue is emptied)"
  (setf (gsm-vn g) 0 (gsm-vstrip g) 0))

RGBAQ source

Vertex colour and Q

Address0x01
6362616059585756555453525150494847464544434241403938373635343332
q
313029282726252423222120191817161514131211109876543210
abggr
(defgsreg RGBAQ #x01 ((r 0 8) (gg 8 8) (b 16 8) (a 24 8) (q 32 32))
  "Vertex colour and Q"
  (setf (gsm-cur-c g) (ldb (byte 32 0) value) (gsm-cur-q g) (bits-f32 q)))

ST source

Vertex texture coordinates S, T (floats)

Address0x02
6362616059585756555453525150494847464544434241403938373635343332
tt
313029282726252423222120191817161514131211109876543210
s
(defgsreg ST #x02 ((s 0 32) (tt 32 32))
  "Vertex texture coordinates S, T (floats)"
  (setf (gsm-cur-s g) (bits-f32 s) (gsm-cur-t g) (bits-f32 tt)))

UV source

Vertex texel coordinates U, V (12.4 fixed point)

Address0x03
313029282726252423222120191817161514131211109876543210
vu
(defgsreg UV #x03 ((u 0 14) (v 16 14))
  "Vertex texel coordinates U, V (12.4 fixed point)"
  (setf (gsm-cur-u g) u (gsm-cur-v g) v))

XYZF2 source

Vertex position, depth and fog; a drawing kick

Address0x04
6362616059585756555453525150494847464544434241403938373635343332
fz
313029282726252423222120191817161514131211109876543210
yx
(defgsreg XYZF2 #x04 ((x 0 16) (y 16 16) (z 32 24) (f 56 8))
  "Vertex position, depth and fog; a drawing kick"
  (gs-kick g x y z f 1))

XYZ2 source

Vertex position and depth; a drawing kick

Address0x05
6362616059585756555453525150494847464544434241403938373635343332
z
313029282726252423222120191817161514131211109876543210
yx
(defgsreg XYZ2 #x05 ((x 0 16) (y 16 16) (z 32 32))
  "Vertex position and depth; a drawing kick"
  (gs-kick g x y z (gsm-cur-f g) 1))

TEX0 source

Texture: base, width, format, size, function, CLUT; loads the CLUT as CLD says

Address0x06, 0x07
6362616059585756555453525150494847464544434241403938373635343332
cldcsacsmcpsmcbptfxtccth
313029282726252423222120191817161514131211109876543210
thtwpsmtbwtbp0
(defgsreg TEX0 (#x06 #x07) ((tbp0 0 14) (tbw 14 6) (psm 20 6) (tw 26 4) (th 30 4) (tcc 34 1) (tfx 35 2)
                            (cbp 37 14) (cpsm 51 4) (csm 55 1) (csa 56 5) (cld 61 3))
  "Texture: base, width, format, size, function, CLUT; loads the CLUT as CLD says"
  (gs-clut-load g value))

CLAMP source

Texture wrap modes

Address0x08, 0x09
6362616059585756555453525150494847464544434241403938373635343332
maxvminv
313029282726252423222120191817161514131211109876543210
minvmaxuminuwmtwms
(defgsreg CLAMP (#x08 #x09) ((wms 0 2) (wmt 2 2) (minu 4 10) (maxu 14 10) (minv 24 10) (maxv 34 10))
  "Texture wrap modes")

FOG source

Vertex fog coefficient

Address0x0A
6362616059585756555453525150494847464544434241403938373635343332
f
313029282726252423222120191817161514131211109876543210
(defgsreg FOG #x0A ((f 56 8))
  "Vertex fog coefficient"
  (setf (gsm-cur-f g) f))

XYZF3 source

Vertex position, depth and fog; no drawing kick

Address0x0C
6362616059585756555453525150494847464544434241403938373635343332
fz
313029282726252423222120191817161514131211109876543210
yx
(defgsreg XYZF3 #x0C ((x 0 16) (y 16 16) (z 32 24) (f 56 8))
  "Vertex position, depth and fog; no drawing kick"
  (gs-kick g x y z f 0))

XYZ3 source

Vertex position and depth; no drawing kick

Address0x0D
6362616059585756555453525150494847464544434241403938373635343332
z
313029282726252423222120191817161514131211109876543210
yx
(defgsreg XYZ3 #x0D ((x 0 16) (y 16 16) (z 32 32))
  "Vertex position and depth; no drawing kick"
  (gs-kick g x y z (gsm-cur-f g) 0))

TEX1 source

Texture filtering and level of detail

Address0x14, 0x15
6362616059585756555453525150494847464544434241403938373635343332
k
313029282726252423222120191817161514131211109876543210
lmtbamminmmagmxllcm
(defgsreg TEX1 (#x14 #x15) ((lcm 0 1) (mxl 2 3) (mmag 5 1) (mmin 6 3) (mtba 9 1) (l 19 2) (k 32 12))
  "Texture filtering and level of detail")

TEX2 source

TEX0's format and CLUT fields alone; loads the CLUT as CLD says

Address0x16, 0x17
6362616059585756555453525150494847464544434241403938373635343332
cldcsacsmcpsmcbp
313029282726252423222120191817161514131211109876543210
psm
(defgsreg TEX2 (#x16 #x17) ((psm 20 6) (cbp 37 14) (cpsm 51 4) (csm 55 1) (csa 56 5) (cld 61 3))
  "TEX0's format and CLUT fields alone; loads the CLUT as CLD says"
  (let* ((a (+ #x06 ctx))
         (tex0 (dpb (ldb (byte 6 20) value) (byte 6 20) (aref (gsm-reg g) a))))
    (setq tex0 (dpb (ldb (byte 27 37) value) (byte 27 37) tex0))
    (setf (aref (gsm-reg g) a) tex0)
    (gs-clut-load g tex0)))

XYOFFSET source

The offset of the primitive coordinate system (12.4)

Address0x18, 0x19
6362616059585756555453525150494847464544434241403938373635343332
ofy
313029282726252423222120191817161514131211109876543210
ofx
(defgsreg XYOFFSET (#x18 #x19) ((ofx 0 16) (ofy 32 16))
  "The offset of the primitive coordinate system (12.4)")

PRMODECONT source

1: PRIM's attributes apply, 0: PRMODE's

Address0x1A
313029282726252423222120191817161514131211109876543210
ac
(defgsreg PRMODECONT #x1A ((ac 0 1))
  "1: PRIM's attributes apply, 0: PRMODE's")

PRMODE source

Primitive attributes when PRMODECONT.AC is 0

Address0x1B
313029282726252423222120191817161514131211109876543210
fixctxtfstaa1abefgetmeiip
(defgsreg PRMODE #x1B ((iip 3 1) (tme 4 1) (fge 5 1) (abe 6 1) (aa1 7 1) (fst 8 1) (ctxt 9 1) (fix 10 1))
  "Primitive attributes when PRMODECONT.AC is 0")

TEXCLUT source

CLUT position for CSM2

Address0x1C
313029282726252423222120191817161514131211109876543210
covcoucbw
(defgsreg TEXCLUT #x1C ((cbw 0 6) (cou 6 6) (cov 12 10))
  "CLUT position for CSM2")

SCANMSK source

Raster mask: 2 skips even lines, 3 odd lines

Address0x22
313029282726252423222120191817161514131211109876543210
msk
(defgsreg SCANMSK #x22 ((msk 0 2))
  "Raster mask: 2 skips even lines, 3 odd lines")

MIPTBP1 source

Mipmap levels 1-3

Address0x34, 0x35
6362616059585756555453525150494847464544434241403938373635343332
tbw3tbp3tbw2tbp2
313029282726252423222120191817161514131211109876543210
tbp2tbw1tbp1
(defgsreg MIPTBP1 (#x34 #x35) ((tbp1 0 14) (tbw1 14 6) (tbp2 20 14) (tbw2 34 6) (tbp3 40 14) (tbw3 54 6))
  "Mipmap levels 1-3")

MIPTBP2 source

Mipmap levels 4-6

Address0x36, 0x37
6362616059585756555453525150494847464544434241403938373635343332
tbw6tbp6tbw5tbp5
313029282726252423222120191817161514131211109876543210
tbp5tbw4tbp4
(defgsreg MIPTBP2 (#x36 #x37) ((tbp4 0 14) (tbw4 14 6) (tbp5 20 14) (tbw5 34 6) (tbp6 40 14) (tbw6 54 6))
  "Mipmap levels 4-6")

TEXA source

Alpha of 16 and 24-bit texels

Address0x3B
6362616059585756555453525150494847464544434241403938373635343332
ta1
313029282726252423222120191817161514131211109876543210
aemta0
(defgsreg TEXA #x3B ((ta0 0 8) (aem 15 1) (ta1 32 8))
  "Alpha of 16 and 24-bit texels")

FOGCOL source

Fog colour

Address0x3D
313029282726252423222120191817161514131211109876543210
fcbfcgfcr
(defgsreg FOGCOL #x3D ((fcr 0 8) (fcg 8 8) (fcb 16 8))
  "Fog colour")

TEXFLUSH source

Texture page buffer flush: nothing to do, texels are read from local memory

Address0x3F
(defgsreg TEXFLUSH #x3F ()
  "Texture page buffer flush: nothing to do, texels are read from local memory")

SCISSOR source

Scissor rectangle, inclusive, in window coordinates

Address0x40, 0x41
6362616059585756555453525150494847464544434241403938373635343332
scay1scay0
313029282726252423222120191817161514131211109876543210
scax1scax0
(defgsreg SCISSOR (#x40 #x41) ((scax0 0 11) (scax1 16 11) (scay0 32 11) (scay1 48 11))
  "Scissor rectangle, inclusive, in window coordinates")

ALPHA source

Alpha blending: ((A - B) * C >> 7) + D; A B D: 0 Cs 1 Cd 2 zero, C: 0 As 1 Ad 2 FIX

Address0x42, 0x43
6362616059585756555453525150494847464544434241403938373635343332
fix
313029282726252423222120191817161514131211109876543210
dcba
(defgsreg ALPHA (#x42 #x43) ((a 0 2) (b 2 2) (c 4 2) (d 6 2) (fix 32 8))
  "Alpha blending: ((A - B) * C >> 7) + D; A B D: 0 Cs 1 Cd 2 zero, C: 0 As 1 Ad 2 FIX")

DIMX source

The dither matrix: 4 x 4 signed 3-bit values, row-major, 4 bits apart

Address0x44
(defgsreg DIMX #x44 ()
  "The dither matrix: 4 x 4 signed 3-bit values, row-major, 4 bits apart")

DTHE source

Dithering on

Address0x45
313029282726252423222120191817161514131211109876543210
dthe
(defgsreg DTHE #x45 ((dthe 0 1))
  "Dithering on")

COLCLAMP source

1: colours clamp to 0..255, 0: they wrap (the low 8 bits)

Address0x46
313029282726252423222120191817161514131211109876543210
clamp
(defgsreg COLCLAMP #x46 ((clamp 0 1))
  "1: colours clamp to 0..255, 0: they wrap (the low 8 bits)")

TEST source

Pixel tests: alpha, destination alpha, depth

Address0x47, 0x48
313029282726252423222120191817161514131211109876543210
ztstztedatmdateafailalpha-refatstate
(defgsreg TEST (#x47 #x48) ((ate 0 1) (atst 1 3) (alpha-ref 4 8) (afail 12 2) (date 14 1) (datm 15 1)
                            (zte 16 1) (ztst 17 2))
  "Pixel tests: alpha, destination alpha, depth")

PABE source

Per-pixel blending: only where the source alpha's top bit is set

Address0x49
313029282726252423222120191817161514131211109876543210
pabe
(defgsreg PABE #x49 ((pabe 0 1))
  "Per-pixel blending: only where the source alpha's top bit is set")

FBA source

Alpha correction: the stored alpha's top bit set

Address0x4A, 0x4B
313029282726252423222120191817161514131211109876543210
fba
(defgsreg FBA (#x4A #x4B) ((fba 0 1))
  "Alpha correction: the stored alpha's top bit set")

FRAME source

Frame buffer: base (2048-word pages), width (64 pixels), format, write mask

Address0x4C, 0x4D
6362616059585756555453525150494847464544434241403938373635343332
fbmsk
313029282726252423222120191817161514131211109876543210
psmfbwfbp
(defgsreg FRAME (#x4C #x4D) ((fbp 0 9) (fbw 16 6) (psm 24 6) (fbmsk 32 32))
  "Frame buffer: base (2048-word pages), width (64 pixels), format, write mask")

ZBUF source

Depth buffer: base, format (PSMZ*, the low 4 bits), write mask

Address0x4E, 0x4F
6362616059585756555453525150494847464544434241403938373635343332
zmsk
313029282726252423222120191817161514131211109876543210
psmzbp
(defgsreg ZBUF (#x4E #x4F) ((zbp 0 9) (psm 24 4) (zmsk 32 1))
  "Depth buffer: base, format (PSMZ*, the low 4 bits), write mask")

BITBLTBUF source

Transfer source and destination buffers

Address0x50
6362616059585756555453525150494847464544434241403938373635343332
dpsmdbwdbp
313029282726252423222120191817161514131211109876543210
spsmsbwsbp
(defgsreg BITBLTBUF #x50 ((sbp 0 14) (sbw 16 6) (spsm 24 6) (dbp 32 14) (dbw 48 6) (dpsm 56 6))
  "Transfer source and destination buffers")

Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.