OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
colormath.h
Go to the documentation of this file.
1
49
50#ifndef OPENSNES_COLORMATH_H
51#define OPENSNES_COLORMATH_H
52
53#include <snes/types.h>
54#include <snes/registers.h> /* REG_CGWSEL / REG_CGADSUB / REG_COLDATA */
55
56/*============================================================================
57 * Layer Masks (for colorMathEnable)
58 *============================================================================*/
59
61#define COLORMATH_BG1 BIT(0)
62
64#define COLORMATH_BG2 BIT(1)
65
67#define COLORMATH_BG3 BIT(2)
68
70#define COLORMATH_BG4 BIT(3)
71
73#define COLORMATH_OBJ BIT(4)
74
76#define COLORMATH_BACKDROP BIT(5)
77
79#define COLORMATH_ALL 0x3F
80
81/*============================================================================
82 * Color Math Operations
83 *============================================================================*/
84
86#define COLORMATH_ADD 0
87
89#define COLORMATH_SUB 1
90
91/*============================================================================
92 * Color Math Source
93 *============================================================================*/
94
96#define COLORMATH_SRC_SUBSCREEN 0
97
99#define COLORMATH_SRC_FIXED 1
100
101/*============================================================================
102 * Color Math Enable Conditions
103 *============================================================================*/
104
106#define COLORMATH_ALWAYS 0
107
109#define COLORMATH_INSIDE 1
110
112#define COLORMATH_OUTSIDE 2
113
115#define COLORMATH_NEVER 3
116
117/*============================================================================
118 * Fixed Color Channel Masks
119 *============================================================================*/
120
122#define COLDATA_RED 0x20
123
125#define COLDATA_GREEN 0x40
126
128#define COLDATA_BLUE 0x80
129
131#define COLDATA_ALL (COLDATA_RED | COLDATA_GREEN | COLDATA_BLUE)
132
133/*============================================================================
134 * Core Color Math Functions
135 *============================================================================*/
136
137/* Internal state, exposed for the inline init/disable bodies below.
138 * cgwsel + cgadsub shadow the corresponding hardware registers (which
139 * are write-only). User code should manipulate via the colorMath* API,
140 * not direct writes. */
141extern u8 cgwsel;
142extern u8 cgadsub;
143
149inline void colorMathInit(void) {
150 cgwsel = 0;
151 cgadsub = 0;
152 REG_CGWSEL = 0;
153 REG_CGADSUB = 0;
154 REG_COLDATA = 0;
155}
156
165inline void colorMathEnable(u8 layers) {
166 /* Set layer enable bits (bits 0-5 of CGADSUB) */
167 cgadsub = (cgadsub & 0xC0) | (layers & 0x3F);
169}
170
176inline void colorMathDisable(void) {
177 cgadsub &= 0xC0; /* Clear layer bits */
179}
180
187
196void colorMathSetHalf(u8 enable);
197
206
212void colorMathSetCondition(u8 condition);
213
235
246
253void colorMathSetChannel(u8 channel, u8 intensity);
254
255/*============================================================================
256 * Color Math Effect Helpers
257 *============================================================================*/
258
270
279void colorMathShadow(u8 layers, u8 intensity);
280
291void colorMathTint(u8 layers, u8 r, u8 g, u8 b);
292
301void colorMathSetBrightness(u8 brightness);
302
303#endif /* OPENSNES_COLORMATH_H */
u8 cgadsub
void colorMathSetCondition(u8 condition)
Set when color math is enabled (window control).
void colorMathEnable(u8 layers)
Enable color math for specified layers.
Definition colormath.h:165
void colorMathShadow(u8 layers, u8 intensity)
Set up shadow/darkening effect.
void colorMathTransparency50(u8 layers)
Set up 50% transparency for layers.
u8 cgwsel
void colorMathSetBrightness(u8 brightness)
Set brightness for fade effects.
void colorMathSetFixedColor(u8 r, u8 g, u8 b)
Set fixed color for blending.
void colorMathSetHalf(u8 enable)
Enable or disable half mode.
void colorMathSetOp(u8 op)
Set color math operation (add or subtract).
void colorMathTint(u8 layers, u8 r, u8 g, u8 b)
Set up color tint effect.
void colorMathDisable(void)
Disable all color math.
Definition colormath.h:176
void colorMathInit(void)
Initialize color math to defaults.
Definition colormath.h:149
void colorMathSetDirectColor(u8 enable)
Enable or disable direct color mode (CGWSEL bit 0).
void colorMathSetSource(u8 source)
Set color math source.
void colorMathSetChannel(u8 channel, u8 intensity)
Set a single fixed color channel.
static u16 b
Definition main.c:157
#define REG_CGWSEL
Color math control A (W).
Definition registers.h:199
#define REG_COLDATA
Fixed color data (W).
Definition registers.h:205
#define REG_CGADSUB
Color math control B (W).
Definition registers.h:202
unsigned char u8
8-bit unsigned integer (0 to 255)
Definition types.h:47
SNES Hardware Register Definitions.
OpenSNES Standard Types.