Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
prims.h
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2026 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include <stdint.h>
30
31// Builds a polygon command (GP0 20h-3Fh family) into o and returns the word count.
32unsigned buildPoly(uint32_t* o, unsigned quad, unsigned g, unsigned tex, unsigned semi, unsigned x0, unsigned w,
33 unsigned h);
34// Builds a rectangle command (GP0 60h-7Fh family) into o and returns the word count.
35unsigned buildRect(uint32_t* o, unsigned size, unsigned tex, unsigned semi, unsigned raw, unsigned w, unsigned h);
36
37// Line classes for the gpu-timing sweep. The harness owns timing, the
38// baseline, the GPU state (E1h: blend mode, dither) and the drawn check; the
39// builder below only turns a class and a size into GP0 words.
40#define LINE_GOURAUD 1u // GP0(50h) family instead of GP0(40h)
41#define LINE_POLY 2u // polyline (48h/58h) instead of a single line
42#define LINE_SEMI 4u // semi-transparent (bit 25 of the command word)
43#define LINE_SLANTED 8u // 2:1 slanted segments instead of axis-aligned ones
44#define LINE_VERTICAL 16u // y-major segments instead of x-major ones
45
46#define LINE_MAX_SEGS 16u
47#define LINE_MAX_WORDS (2u * (LINE_MAX_SEGS + 1u) + 1u)
48
49// Writes one line command of class |kind| into |out| and returns the number
50// of words written, polyline terminator included. Returns 0 for a kind it
51// does not build.
52//
53// |len| is the length of each segment in pixels along its major axis,
54// 1..255. |segs| is the segment count: 1 for a single line, 2..LINE_MAX_SEGS
55// for a polyline.
56//
57// Geometry. A vertex word is (y << 16) | x.
58// - A single line runs from (0, 0) to (dx, dy), and a polyline bounces back
59// and forth between (0, 0) and (dx, dy).
60// - (dx, dy) is (len, 0) by default: horizontal.
61// - LINE_SLANTED: (len, len / 2), x-major with a 2:1 slope.
62// - LINE_VERTICAL swaps the axes: (0, len) vertical, and with LINE_SLANTED
63// (len / 2, len), y-major with a 1:2 slope.
64//
65// Contract the harness relies on:
66// - the first vertex is (0, 0), so pixel (0, 0) is drawn;
67// - every vertex lies inside 0..255 on both axes;
68// - a polyline ends with the word 55555555h;
69// - the colour words are non-black, so a drawn pixel differs from the
70// cleared background;
71// - the return value counts the polyline terminator.
72unsigned buildLineCommand(uint32_t* out, unsigned kind, unsigned len, unsigned segs);
static int size
Definition string.h:149
uint32_t out
Definition cpu.c:62
uint8_t g
Definition gte-depthcue.c:40
unsigned buildLineCommand(uint32_t *out, unsigned kind, unsigned len, unsigned segs)
Definition prims.c:65
unsigned buildPoly(uint32_t *o, unsigned quad, unsigned g, unsigned tex, unsigned semi, unsigned x0, unsigned w, unsigned h)
Definition prims.c:33
unsigned buildRect(uint32_t *o, unsigned size, unsigned tex, unsigned semi, unsigned raw, unsigned w, unsigned h)
Definition prims.c:54