the GP0 commands: drawing, VRAM transfers, the drawing environment; the GP0 port.
0/1 a fixed bit, name a field, a bit the decoder ignores
GP0(E1h) Draw Mode setting (aka "TPage"): page, semi-transparency, depth, dither, drawing to the display area, texture disable
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | flip | tbx2 | dfe | dtd | tpf | abr | tby | tbx | ||||||||||||||||
(defgp0 draw-mode "11100001 .......... flip:2 tbx2:1 dfe:1 dtd:1 tpf:2 abr:2 tby:1 tbx:4" ()
(:doc "GP0(E1h) Draw Mode setting (aka \"TPage\"): page, semi-transparency, depth, dither, drawing to the display area, texture disable")
(gpu-set-texpage cpu insn)
(setf (gpu-stat cpu) (logior (logand (gpu-stat cpu) #xFFFF79FF) (ash dtd 9) (ash dfe 10) (ash tbx2 15))))
GP0(E2h) Texture Window setting: mask and offset in 8-pixel steps
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | oy | ox | my | mx | ||||||||||||||||||||
(defgp0 texture-window "11100010 .... oy:5 ox:5 my:5 mx:5" ()
(:doc "GP0(E2h) Texture Window setting: mask and offset in 8-pixel steps")
(gpu-set-window cpu insn))
GP0(E3h) Set Drawing Area top left (X1,Y1)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | y | x | ||||||||||||||||||||||
(defgp0 area-top-left "11100011 ..... y:9 x:10" ()
(:doc "GP0(E3h) Set Drawing Area top left (X1,Y1)")
(setf (gpu-ax1 cpu) x (gpu-ay1 cpu) y)
(gpu-set-area cpu x y (gpu-ax2 cpu) (gpu-ay2 cpu)))
GP0(E4h) Set Drawing Area bottom right (X2,Y2)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | y | x | ||||||||||||||||||||||
(defgp0 area-bottom-right "11100100 ..... y:9 x:10" ()
(:doc "GP0(E4h) Set Drawing Area bottom right (X2,Y2)")
(setf (gpu-ax2 cpu) x (gpu-ay2 cpu) y)
(gpu-set-area cpu (gpu-ax1 cpu) (gpu-ay1 cpu) x y))
GP0(E5h) Set Drawing Offset (X,Y), signed 11 bits
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | y | x | ||||||||||||||||||||||
(defgp0 offset "11100101 .. y:11 x:11" ()
(:doc "GP0(E5h) Set Drawing Offset (X,Y), signed 11 bits")
(setf (gs coordinates offset-x) (sext 11 x) (gs coordinates offset-y) (sext 11 y)))
GP0(E6h) Mask Bit Setting: set mask while drawing, check mask before drawing (GPUSTAT 11, 12)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | pbc | pbw |
(defgp0 mask-bit "11100110 ...................... pbc:1 pbw:1" ()
(:doc "GP0(E6h) Mask Bit Setting: set mask while drawing, check mask before drawing (GPUSTAT 11, 12)")
(setf (gpu-stat cpu) (logior (logand (gpu-stat cpu) #xFFFFE7FF) (ash pbw 11) (ash pbc 12)))
(setf (gs mask-bit force) pbw (gs mask-bit test) pbc))
GP0(01h) Clear Cache (the texture cache: nothing to do here)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
(defgp0 clear-cache "00000001 ........................" ()
(:doc "GP0(01h) Clear Cache (the texture cache: nothing to do here)")
nil)
GP0(02h) Quick Rectangle Fill
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | color | |||||||||||||||||||||||
(defgp0 fill "00000010 color:24" (:words 3)
(:doc "GP0(02h) Quick Rectangle Fill")
(raster-fill cpu (ldb (byte 16 0) (word 1)) (ldb (byte 16 16) (word 1))
(ldb (byte 16 0) (word 2)) (ldb (byte 16 16) (word 2)) color))
GP0(1Fh) Interrupt Request (IRQ1): GPUSTAT.24, until GP1(02h)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 |
(defgp0 irq "00011111 ........................" ()
(:doc "GP0(1Fh) Interrupt Request (IRQ1): GPUSTAT.24, until GP1(02h)")
(setf (gpu-irq cpu) 1))
GP0(20h-3Fh) Render Polygon: 3 or 4 vertices, flat or Gouraud, textured (raw or modulated), semi-transparent
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 1 | iip | vtx | tme | abe | tge | color | |||||||||||||||||||||||
(defgp0 polygon "001 iip:1 vtx:1 tme:1 abe:1 tge:1 color:24"
(:words (+ 1 (* (if (= vtx 1) 4 3) (+ 1 tme)) (* iip (if (= vtx 1) 3 2))))
(:doc "GP0(20h-3Fh) Render Polygon: 3 or 4 vertices, flat or Gouraud, textured (raw or modulated), semi-transparent")
(let* ((n (if (= vtx 1) 4 3))
(stride (+ 1 iip tme))
(texp (if (= tme 1) (ldb (byte 16 16) (word (+ 2 stride))) 0))
(clut (if (= tme 1) (ldb (byte 16 16) (word 2)) 0)))
(dotimes (i n)
(let ((base (* i stride)))
(setf (gs immediate i color) (if (and (= iip 1) (> i 0)) (logand (word base) #xFFFFFF) color))
(vertex-xy i (word (+ base 1)))
(when (= tme 1)
(setf (gs immediate i u) (ldb (byte 8 0) (word (+ base 2)))
(gs immediate i v) (ldb (byte 8 8) (word (+ base 2)))))))
;; "the Texpage attribute ... Same as GP0(E1h).Bit0-8" ([PSXSPX] "TPage Attribute")
(when (= tme 1)
(gpu-set-texpage cpu texp)
(gpu-set-clut cpu clut))
(when (and (= tme 1) (= tge 1) (= iip 0))
(dotimes (i n) (setf (gs immediate i color) #x808080)))
;; a quad is the triangles 1 2 3 and 2 3 4: a strip
(gpu-primitive cpu (if (= n 4) (gfx-code topology triangle-strip) (gfx-code topology triangle-list)) n
tme tge iip abe (if (or (= iip 1) (and (= tme 1) (= tge 0))) 1 0))
(raster-triangle cpu 0 1 2)
(when (= n 4)
(raster-triangle cpu 1 2 3))))
GP0(40h-5Fh) Render Line: a line, or the first segment's start of a polyline (gp0.lisp GP0-WRITE streams the rest)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | iip | pll | abe | color | |||||||||||||||||||||||||
(defgp0 line "010 iip:1 pll:1 . abe:1 . color:24"
(:words (if (= pll 1) 2 (+ 3 iip)))
(:doc "GP0(40h-5Fh) Render Line: a line, or the first segment's start of a polyline (gp0.lisp GP0-WRITE streams the rest)")
(if (= pll 1)
;; the first vertex; the polyline's next words arrive in mode 1
(setf (gpu-line-cmd cpu) insn (gpu-line-xy cpu) (word 1) (gpu-line-color cpu) color
(gpu-line-have-color cpu) 0 (gpu-mode cpu) 1)
(progn
(setf (gs immediate 0 color) color
(gs immediate 1 color) (if (= iip 1) (logand (word 2) #xFFFFFF) color))
(vertex-xy 0 (word 1))
(vertex-xy 1 (word (+ 2 iip)))
(gpu-primitive cpu (gfx-code topology line-list) 2 0 0 iip abe iip)
(raster-line cpu))))
GP0(60h-7Fh) Render Rectangle: variable size or 1x1, 8x8, 16x16; textured through GPUSTAT's page
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | siz | tme | abe | tge | color | ||||||||||||||||||||||||
(defgp0 rectangle "011 siz:2 tme:1 abe:1 tge:1 color:24"
(:words (+ 2 tme (if (= siz 0) 1 0)))
(:doc "GP0(60h-7Fh) Render Rectangle: variable size or 1x1, 8x8, 16x16; textured through GPUSTAT's page")
(let* ((xy (word 1))
(uvc (if (= tme 1) (word 2) 0))
(wh (if (= siz 0) (word (+ 2 tme)) 0))
(w (case siz (0 (ldb (byte 10 0) wh)) (1 1) (2 8) (t 16)))
(h (case siz (0 (ldb (byte 9 16) wh)) (1 1) (2 8) (t 16))))
;; two corners, the second excluded; the offset added and wrapped to 11 bits
(let ((x0 (sext 11 (wrap 11 (+ (sext 11 (ldb (byte 11 0) xy)) (gs coordinates offset-x)))))
(y0 (sext 11 (wrap 11 (+ (sext 11 (ldb (byte 11 16) xy)) (gs coordinates offset-y)))))
(u (ldb (byte 8 0) uvc)) (v (ldb (byte 8 8) uvc))
(c (if (and (= tme 1) (= tge 1)) #x808080 color)))
(set-vertex 0 x0 y0 c u v)
(set-vertex 1 (+ x0 w) (+ y0 h) c (+ u w) (+ v h)))
(when (= tme 1)
(gpu-set-clut cpu (ldb (byte 16 16) uvc)))
;; through GPUSTAT's page (texture 0 already); never dithered
(gpu-primitive cpu (gfx-code topology rectangle-list) 2 tme tge 0 abe 0)
(raster-rect cpu)))
GP0(80h) Copy Rectangle (VRAM to VRAM)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 0 | 0 |
(defgp0 copy "100 ........ ........ ........ ....." (:words 4)
(:doc "GP0(80h) Copy Rectangle (VRAM to VRAM)")
(raster-copy cpu (ldb (byte 10 0) (word 1)) (ldb (byte 9 16) (word 1))
(ldb (byte 10 0) (word 2)) (ldb (byte 9 16) (word 2))
(ldb (byte 16 0) (word 3)) (ldb (byte 16 16) (word 3))))
GP0(A0h) Copy Rectangle (CPU to VRAM): the data words follow (mode 2)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 0 | 1 |
(defgp0 upload "101 ........ ........ ........ ....." (:words 3)
(:doc "GP0(A0h) Copy Rectangle (CPU to VRAM): the data words follow (mode 2)")
(let ((w (+ (logand (- (ldb (byte 16 0) (word 2)) 1) #x3FF) 1))
(h (+ (logand (- (ldb (byte 16 16) (word 2)) 1) #x1FF) 1)))
(setf (gpu-xfer-x cpu) (ldb (byte 10 0) (word 1)) (gpu-xfer-y cpu) (ldb (byte 9 16) (word 1))
(gpu-xfer-w cpu) w (gpu-xfer-h cpu) h (gpu-xfer-i cpu) 0 (gpu-xfer-n cpu) (* w h)
(gpu-mode cpu) 2)))
GP0(C0h) Copy Rectangle (VRAM to CPU): GPUREAD returns it (GPUSTAT.27)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 1 | 0 |
(defgp0 download "110 ........ ........ ........ ....." (:words 3)
(:doc "GP0(C0h) Copy Rectangle (VRAM to CPU): GPUREAD returns it (GPUSTAT.27)")
(let ((w (+ (logand (- (ldb (byte 16 0) (word 2)) 1) #x3FF) 1))
(h (+ (logand (- (ldb (byte 16 16) (word 2)) 1) #x1FF) 1)))
(setf (gpu-rd-x cpu) (ldb (byte 10 0) (word 1)) (gpu-rd-y cpu) (ldb (byte 9 16) (word 1))
(gpu-rd-w cpu) w (gpu-rd-h cpu) h (gpu-rd-i cpu) 0 (gpu-rd-n cpu) (* w h))))
(defun gpu-set-semi) source(defun gpu-set-semi (gpu mode)
"semi-transparency MODE (GP0(E1h) bits 5-6) as the combine equation ((A - B) * C >> 7) + D
on 5-bit channels: 0 B/2+F/2, 1 B+F, 2 B-F, 3 B+F/4 (B the destination, F the source)"
(declare (type gpu gpu) (type u8 mode))
(let ((gfx (gpu-gfx gpu)))
(setf (gs combine a) (if (= mode 2) (gfx-code combine-color zero) (gfx-code combine-color source))
(gs combine b) (case mode
(0 (gfx-code combine-color destination))
(2 (gfx-code combine-color source))
(t (gfx-code combine-color zero)))
(gs combine c) (gfx-code combine-alpha fixed)
(gs combine d) (gfx-code combine-color destination)
(gs combine fixed) (case mode (0 64) (3 32) (t 128))
(gs combine clamp) 1)
nil))(defun gpu-set-texpage) source(defun gpu-set-texpage (gpu v)
"GP0(E1h) bits 0-8 (and a textured polygon's page): GPUSTAT 0-8, texture 0 (the page:
64-halfword steps across, 256 lines down; 4-bit, 8-bit indices or 15-bit texels) and the combine"
(declare (type gpu gpu) (type u32 v))
(let ((gfx (gpu-gfx gpu)) (depth (logand (ash v -7) 3)))
(setf (gpu-stat gpu) (logior (logand (gpu-stat gpu) #xFFFFFE00) (logand v #x1FF)))
(setf (gs texture 0 kind) (gfx-code texture-kind d2)
(gs texture 0 address) (+ (* 128 (logand v 15)) (* 2048 (ash (logand v #x10) 4)))
(gs texture 0 layout) (gfx-code texture-layout linear) (gs texture 0 pitch) 2048
(gs texture 0 width) 256 (gs texture 0 height) 256
(gs texture 0 format) (case depth (0 (texfmt-code index4)) (1 (texfmt-code index8))
(t (texfmt-code a1b5g5r5)))
(gs texture 0 clut-format) (texfmt-code a1b5g5r5)
(gs texture 0 clut-layout) (gfx-code texture-layout linear) (gs texture 0 clut-pitch) 2048
(gs texture 0 zero-discard) 1)
(gpu-set-semi gpu (logand (ash v -5) 3))
nil))(defun gpu-set-area) source(defun gpu-set-area (gpu x1 y1 x2 y2)
"the drawing area, inclusive, as scissor 0"
(declare (type gpu gpu) (type u32 x1 y1 x2 y2))
(let ((gfx (gpu-gfx gpu)))
(setf (gs scissor count) 1
(gs scissor 0 x) x1 (gs scissor 0 y) y1
(gs scissor 0 width) (if (>= x2 x1) (+ (- x2 x1) 1) 0)
(gs scissor 0 height) (if (>= y2 y1) (+ (- y2 y1) 1) 0))
nil))(defun gpu-set-window) source(defun gpu-set-window (gpu w)
"GP0(E2h)'s bits 0-19: the texture window as sampler 0's region-repeat ((c AND NOT mask) OR
(offset AND mask), 8-texel steps)"
(declare (type gpu gpu) (type u32 w))
(let ((gfx (gpu-gfx gpu))
(mx (wrap 8 (* 8 (bit-field w 0 5)))) (my (wrap 8 (* 8 (bit-field w 5 5))))
(ox (wrap 8 (* 8 (bit-field w 10 5)))) (oy (wrap 8 (* 8 (bit-field w 15 5)))))
(setf (gpu-window gpu) (logand w #xFFFFF))
(setf (gs sampler 0 address-u) (gfx-code address-mode region-repeat)
(gs sampler 0 address-v) (gfx-code address-mode region-repeat)
(gs sampler 0 region-u0) (logand (lognot mx) #xFF) (gs sampler 0 region-u1) (logand ox mx)
(gs sampler 0 region-v0) (logand (lognot my) #xFF) (gs sampler 0 region-v1) (logand oy my)
(gs sampler 0 min-filter) (gfx-code filter nearest) (gs sampler 0 mag-filter) (gfx-code filter nearest)
(gs sampler 0 mipmap-mode) (gfx-code mipmap-mode none))
nil))(defun gpu-init-gfx) source(defun gpu-init-gfx (gpu)
"what the abstract state holds of the PS1 GPU whatever its commands: the target (VRAM, 1024 x
512 A1B5G5R5 at 0, linear), integer coordinates and its rasterization rules, the dither matrix ([PSXSPX] \"Dithering\":
-4 +0 -3 +1 / +2 -2 +3 -1 / -3 +1 -4 +0 / +3 -1 +2 -2), the mask bit's test value"
(declare (type gpu gpu))
(let ((gfx (gpu-gfx gpu)))
(setf (gs color-target count) 1 (gs color-target 0 format) (texfmt-code a1b5g5r5)
(gs attachment 0 address) 0 (gs attachment 0 pitch) 2048
(gs attachment 0 layout) (gfx-code texture-layout linear)
(gs pass width) 1024 (gs pass height) 512
(gs coordinates xy-fraction) 0 (gs coordinates uv-fraction) 0 (gs coordinates perspective) 0
(gs raster rules) (gfx-code raster-rules psx-spans) (gs mask-bit pass) 0)
(dotimes (y 4)
(dotimes (x 4)
(setf (gs dither-matrix (+ x (* 4 y)) value) (gpu-dither x y))))
nil))(defun gpu-primitive) source(defun gpu-primitive (gpu topology n textured raw shaded semi dither)
"the abstract state of the next primitive: TOPOLOGY of N immediate vertices (written by the
command), texturing (RAW: the texel as it is, else modulated), Gouraud shading, semi-
transparency (textured: only where the texel's bit 15 is set), dithering (GPUSTAT.9 where
the primitive is shaded or modulated); then its draw"
(declare (type gpu gpu) (type u8 topology n textured raw shaded semi dither))
(let ((gfx (gpu-gfx gpu)))
(setf (gs primitive topology) topology (gs immediate count) n
(gs texture 0 enable) textured
(gs texture 0 function) (if (= raw 1) (gfx-code texture-function decal)
(gfx-code texture-function modulate))
(gs raster shade-model) (if (= shaded 1) (gfx-code shade-model smooth) (gfx-code shade-model flat))
(gs combine enable) semi
(gs combine select) (if (= textured 1) (gfx-code combine-select source-alpha-msb)
(gfx-code combine-select all))
(gs raster dither) (if (and (= (bit-at (gpu-stat gpu) 9) 1) (= dither 1)) 1 0))
(gfx-draw gfx (gfx-code draw-kind direct) n 1 0 0 0)
(gpu-drawn gpu)
nil))(defun gpu-set-clut) source(defun gpu-set-clut (gpu clut)
"a textured primitive's CLUT attribute: 16-halfword steps across, a line"
(declare (type gpu gpu) (type u32 clut))
(let ((gfx (gpu-gfx gpu)))
(setf (gs texture 0 clut-address) (+ (* 32 (logand clut #x3F)) (* 2048 (logand (ash clut -6) #x1FF))))
nil))(defmacro set-vertex) source(defmacro set-vertex (i x y c u v)
"immediate vertex I"
`(setf (gs immediate ,i x) ,x (gs immediate ,i y) ,y (gs immediate ,i color) ,c
(gs immediate ,i u) ,u (gs immediate ,i v) ,v))(defmacro vertex-xy) source(defmacro vertex-xy (i w)
"immediate vertex I's position from word W: x bits 0-10 and y bits 16-26, signed, plus the offset"
`(setf (gs immediate ,i x) (+ (sext 11 (ldb (byte 11 0) ,w)) (gs coordinates offset-x))
(gs immediate ,i y) (+ (sext 11 (ldb (byte 11 16) ,w)) (gs coordinates offset-y))))(defun gpu-polyline-word) source(defun gpu-polyline-word (cpu w)
"word W of a polyline after its first vertex: a colour (Gouraud), a
vertex (a segment from the last one), or the terminator 5xxx5xxxh, which
[PSXSPX] says comes \"on the first word of the vertex (i.e. the color word
if it's a gouraud shaded)\""
(declare (type gpu cpu) (type u32 w))
(let* ((gfx (gpu-gfx cpu)) (cmd (gpu-line-cmd cpu)) (iip (bit-at cmd 28)))
(cond ((and (= (gpu-line-have-color cpu) 0) (= (logand w #xF000F000) #x50005000))
(setf (gpu-mode cpu) 0))
((and (= iip 1) (= (gpu-line-have-color cpu) 0))
(setf (gpu-line-color-next cpu) (logand w #xFFFFFF) (gpu-line-have-color cpu) 1))
(t
(setf (gs immediate 0 color) (gpu-line-color cpu)
(gs immediate 1 color) (if (= iip 1) (gpu-line-color-next cpu) (gpu-line-color cpu)))
(vertex-xy 0 (gpu-line-xy cpu))
(vertex-xy 1 w)
;; each segment its own line: a strip's shared vertex is drawn by both
(gpu-primitive cpu (gfx-code topology line-list) 2 0 0 iip (bit-at cmd 25) iip)
(raster-line cpu)
(setf (gpu-line-xy cpu) w (gpu-line-have-color cpu) 0)
(when (= iip 1)
(setf (gpu-line-color cpu) (gpu-line-color-next cpu)))))
nil))(define-executor gp0-execute) source(define-executor gp0-execute gp0 :illegal gp0-nop)(defun gpu-upload-pixel) source(defun gpu-upload-pixel (gpu p)
"the next pixel of a CPU-to-VRAM transfer; the mask bits apply"
(declare (type gpu gpu) (type u16 p))
(let* ((gfx (gpu-gfx gpu)) (i (gpu-xfer-i gpu)) (w (gpu-xfer-w gpu))
(x (+ (gpu-xfer-x gpu) (mod i w))) (y (+ (gpu-xfer-y gpu) (floor i w))))
(unless (and (= (gs mask-bit test) 1) (logbitp 15 (vram-ref gpu x y)))
(vram-set gpu x y (logior p (if (= (gs mask-bit force) 1) #x8000 0))))
(setf (gpu-xfer-i gpu) (+ i 1))
nil))(defparameter *gp0-trace*) source(defparameter *gp0-trace* 0)(defun gp0-write) source(defun gp0-write (gpu w)
"a word written to GP0 (1F801810h, or DMA channel 2)"
(declare (type gpu gpu) (type u32 w))
(case (gpu-mode gpu)
(2 (gpu-upload-pixel gpu (ldb (byte 16 0) w))
(when (< (gpu-xfer-i gpu) (gpu-xfer-n gpu))
(gpu-upload-pixel gpu (ldb (byte 16 16) w)))
(when (>= (gpu-xfer-i gpu) (gpu-xfer-n gpu))
(setf (gpu-mode gpu) 0)
(gpu-written gpu (gpu-xfer-x gpu) (gpu-xfer-y gpu) (gpu-xfer-w gpu) (gpu-xfer-h gpu))))
(1 (gpu-polyline-word gpu w))
(t (let ((n (gpu-count gpu)))
(when (= n 0)
(setf (gpu-need gpu) (gp0-words w)))
(setf (aref (gpu-fifo gpu) n) w (gpu-count gpu) (+ n 1))
(when (>= (+ n 1) (gpu-need gpu))
(setf (gpu-count gpu) 0)
(when (= *gp0-trace* 1)
(host-write-string "gp0:")
(dotimes (i (+ n 1)) (host-write-string " ") (host-write-hex (aref (gpu-fifo gpu) i) 8))
(host-newline))
(gp0-execute gpu (aref (gpu-fifo gpu) 0))))))
nil)(defun gpu-read) source(defun gpu-read (gpu)
"GPUREAD (1F801810h): two pixels of a VRAM-to-CPU transfer while one is
on, else the latch (GP1(10h)'s answer, the last data read)"
(declare (type gpu gpu))
(when (< (gpu-rd-i gpu) (gpu-rd-n gpu))
(let ((v 0))
(declare (type u32 v))
(dotimes (k 2)
(let* ((i (gpu-rd-i gpu)) (w (gpu-rd-w gpu))
(p (vram-ref gpu (+ (gpu-rd-x gpu) (mod i w)) (+ (gpu-rd-y gpu) (floor i w)))))
(setq v (logior v (ash p (* 16 k))))
(setf (gpu-rd-i gpu) (+ i 1))))
(setf (gpu-latch gpu) v)))
(gpu-latch gpu))Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.