Nugget
Loading...
Searching...
No Matches
gpu.h
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2021 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
32
40
42 VR_240 = 0,
43 VR_480 = 1,
44};
45
48 VM_PAL = 1,
49};
50
54};
55
57 VI_OFF = 0,
58 VI_ON = 1,
59};
60
65
74
75static inline void waitGPU() { while ((GPU_STATUS & 0x04000000) == 0); }
76
77static inline void sendGPUData(uint32_t data) {
78 waitGPU();
79 GPU_DATA = data;
80}
81
82static inline void sendGPUStatus(uint32_t status) { GPU_STATUS = status; }
83
84static inline uint32_t generateDisableDisplay() { return 0x03000001; }
85static inline uint32_t generateEnableDisplay() { return 0x03000000; }
86static inline void disableDisplay() { sendGPUStatus(generateDisableDisplay()); }
87static inline void enableDisplay() { sendGPUStatus(generateEnableDisplay()); }
88
89static inline uint32_t generateDisplayMode(const struct DisplayModeConfig* config) {
90 return 0x08000000 | (config->hResolution << 0) | (config->vResolution << 2) | (config->videoMode << 3) |
91 (config->colorDepth << 4) | (config->videoInterlace << 5) | (config->hResolutionExtended << 6);
92}
93
94static inline void setDisplayMode(const struct DisplayModeConfig* config) {
95 sendGPUStatus(generateDisplayMode(config));
96}
97
98static inline uint32_t generateDisplayArea(int16_t x, int16_t y) { return 0x05000000 | x | (y << 10); }
99static inline void setDisplayArea(int16_t x, int16_t y) { sendGPUStatus(generateDisplayArea(x, y)); }
100
101static inline uint32_t generateHorizontalRange(int16_t x1, int16_t x2) {
102 return 0x06000000 | (x1 + 0x260) | ((x1 + x2 + 0x260) << 12);
103}
104static inline void setHorizontalRange(int16_t x1, int16_t x2) { sendGPUStatus(generateHorizontalRange(x1, x2)); }
105
106static inline uint32_t generateVerticalRange(int16_t y1, int16_t y2) { return 0x07000000 | y1 | (y2 << 10); }
107static inline void setVerticalRange(int16_t y1, int16_t y2) { sendGPUStatus(generateVerticalRange(y1, y2)); }
108
109union Color {
110 struct {
111 uint8_t r, g, b;
112 };
114};
115
116struct FastFill {
117 union Color c;
118 int16_t x, y, w, h;
119};
120
121static inline void fastFill(const struct FastFill* ff) {
122 waitGPU();
123 GPU_DATA = 0x02000000 | ff->c.r | ff->c.g << 8 | ff->c.b << 16;
124 GPU_DATA = ff->x | ff->y << 16;
125 GPU_DATA = ff->w | ff->h << 16;
126}
127
128static inline uint32_t generateDrawingAreaStart(int16_t x, int16_t y) { return 0xe3000000 | x | y << 10; }
129static inline uint32_t generateDrawingAreaEnd(int16_t x, int16_t y) { return 0xe4000000 | (x - 1) | (y - 1) << 10; }
130static inline void setDrawingArea(int16_t x1, int16_t y1, int16_t x2, int16_t y2) {
131 sendGPUData(generateDrawingAreaStart(x1, y1));
132 sendGPUData(generateDrawingAreaEnd(x2, y2));
133}
134
135static inline uint32_t generateDrawingOffset(int16_t x, int16_t y) { return 0xe5000000 | x | y << 11; }
136static inline void setDrawingOffset(int16_t x, int16_t y) { sendGPUData(generateDrawingOffset(x, y)); }
137
141};
142
144 VC_3 = 0,
145 VC_4 = 1,
146};
147
151};
152
157
161};
162
171
172static inline uint32_t generatePolygonCommand(const struct GPUPolygonCommand* c) {
173 return 0x20000000 | c->shading << 28 | c->verticesCount << 27 | c->textured << 26 | c->transparency << 25 |
174 c->blending << 24 | c->color.b << 16 | c->color.g << 8 | c->color.r;
175}
176static inline void startPolygonCommand(const struct GPUPolygonCommand* c) { sendGPUData(generatePolygonCommand(c)); }
177
181};
182
189
190static inline uint32_t generateLineCommand(const struct GPULineCommand* c) {
191 return 0x40000000 | c->shading << 28 | c->lineStyle << 27 | c->transparency << 25 | c->color.b << 16 |
192 c->color.g << 8 | c->color.r;
193}
194static inline void startLineCommand(const struct GPULineCommand* c) { sendGPUData(generateLineCommand(c)); }
195
196static inline uint32_t generateFlushGPUCache() { return 0x01000000; }
197static inline void flushGPUCache() { sendGPUData(generateFlushGPUCache()); }
Transparency
Definition gpu.h:153
@ TRANS_OFF
Definition gpu.h:155
@ TRANS_ON
Definition gpu.h:154
VideoMode
Definition gpu.h:46
@ VM_NTSC
Definition gpu.h:47
@ VM_PAL
Definition gpu.h:48
HResolutionExtended
Definition gpu.h:61
@ HRE_368
Definition gpu.h:63
@ HRE_NORMAL
Definition gpu.h:62
Shading
Definition gpu.h:138
@ S_FLAT
Definition gpu.h:139
@ S_GOURAUD
Definition gpu.h:140
VResolution
Definition gpu.h:41
@ VR_480
Definition gpu.h:43
@ VR_240
Definition gpu.h:42
HResolution
Definition gpu.h:33
@ HR_EXTENDED
Definition gpu.h:34
@ HR_640
Definition gpu.h:38
@ HR_320
Definition gpu.h:36
@ HR_512
Definition gpu.h:37
@ HR_256
Definition gpu.h:35
Textured
Definition gpu.h:148
@ TEX_ON
Definition gpu.h:149
@ TEX_OFF
Definition gpu.h:150
LineStyle
Definition gpu.h:178
@ POLY_OFF
Definition gpu.h:179
@ POLY_ON
Definition gpu.h:180
VideoInterlace
Definition gpu.h:56
@ VI_ON
Definition gpu.h:58
@ VI_OFF
Definition gpu.h:57
ColorDepth
Definition gpu.h:51
@ CD_15BITS
Definition gpu.h:52
@ CD_24BITS
Definition gpu.h:53
Blending
Definition gpu.h:158
@ BLEND_OFF
Definition gpu.h:160
@ BLEND_ON
Definition gpu.h:159
VerticesCount
Definition gpu.h:143
@ VC_3
Definition gpu.h:144
@ VC_4
Definition gpu.h:145
#define GPU_DATA
Definition hwregs.h:65
#define GPU_STATUS
Definition hwregs.h:66
Definition gpu.h:66
enum ColorDepth colorDepth
Definition gpu.h:70
enum VideoInterlace videoInterlace
Definition gpu.h:71
enum VideoMode videoMode
Definition gpu.h:69
enum HResolutionExtended hResolutionExtended
Definition gpu.h:72
enum VResolution vResolution
Definition gpu.h:68
enum HResolution hResolution
Definition gpu.h:67
Definition gpu.h:116
int16_t h
Definition gpu.h:118
union Color c
Definition gpu.h:117
int16_t w
Definition gpu.h:118
int16_t x
Definition gpu.h:118
int16_t y
Definition gpu.h:118
Definition gpu.h:183
enum Shading shading
Definition gpu.h:184
union Color color
Definition gpu.h:187
enum LineStyle lineStyle
Definition gpu.h:185
enum Transparency transparency
Definition gpu.h:186
Definition gpu.h:163
union Color color
Definition gpu.h:169
enum Blending blending
Definition gpu.h:168
enum Shading shading
Definition gpu.h:164
enum VerticesCount verticesCount
Definition gpu.h:165
enum Transparency transparency
Definition gpu.h:167
enum Textured textured
Definition gpu.h:166
static int c
Definition syscalls.h:121
void uint32_t(classId, spec)
Definition gpu.h:109
uint8_t g
Definition gpu.h:111
uint8_t b
Definition gpu.h:111
uint32_t packed
Definition gpu.h:113
uint8_t r
Definition gpu.h:111