-
Notifications
You must be signed in to change notification settings - Fork 463
/
gfx.h
226 lines (198 loc) · 6.46 KB
/
gfx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*****************************************************************************\
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
This file is licensed under the Snes9x License.
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef _GFX_H_
#define _GFX_H_
#include "port.h"
#include <vector>
struct SGFX
{
const uint32 Pitch = sizeof(uint16) * MAX_SNES_WIDTH;
const uint32 RealPPL = MAX_SNES_WIDTH; // true PPL of Screen buffer
const uint32 ScreenSize = MAX_SNES_WIDTH * MAX_SNES_HEIGHT;
std::vector<uint16> ScreenBuffer;
uint16 *Screen;
uint16 *SubScreen;
uint8 *ZBuffer;
uint8 *SubZBuffer;
uint16 *S;
uint8 *DB;
uint16 *ZERO;
uint32 PPL; // number of pixels on each of Screen buffer
uint32 LinesPerTile; // number of lines in 1 tile (4 or 8 due to interlace)
uint16 *ScreenColors; // screen colors for rendering main
uint16 *RealScreenColors; // screen colors, ignoring color window clipping
uint8 Z1; // depth for comparison
uint8 Z2; // depth to save
uint32 FixedColour;
uint8 DoInterlace;
uint32 StartY;
uint32 EndY;
bool8 ClipColors;
uint8 OBJWidths[128];
uint8 OBJVisibleTiles[128];
struct ClipData *Clip;
struct
{
uint8 RTOFlags;
int16 Tiles;
struct
{
int8 Sprite;
uint8 Line;
} OBJ[128];
} OBJLines[SNES_HEIGHT_EXTENDED];
void (*DrawBackdropMath) (uint32, uint32, uint32);
void (*DrawBackdropNomath) (uint32, uint32, uint32);
void (*DrawTileMath) (uint32, uint32, uint32, uint32);
void (*DrawTileNomath) (uint32, uint32, uint32, uint32);
void (*DrawClippedTileMath) (uint32, uint32, uint32, uint32, uint32, uint32);
void (*DrawClippedTileNomath) (uint32, uint32, uint32, uint32, uint32, uint32);
void (*DrawMosaicPixelMath) (uint32, uint32, uint32, uint32, uint32, uint32);
void (*DrawMosaicPixelNomath) (uint32, uint32, uint32, uint32, uint32, uint32);
void (*DrawMode7BG1Math) (uint32, uint32, int);
void (*DrawMode7BG1Nomath) (uint32, uint32, int);
void (*DrawMode7BG2Math) (uint32, uint32, int);
void (*DrawMode7BG2Nomath) (uint32, uint32, int);
std::string InfoString;
uint32 InfoStringTimeout;
char FrameDisplayString[256];
};
struct SBG
{
uint8 (*ConvertTile) (uint8 *, uint32, uint32);
uint8 (*ConvertTileFlip) (uint8 *, uint32, uint32);
uint32 TileSizeH;
uint32 TileSizeV;
uint32 OffsetSizeH;
uint32 OffsetSizeV;
uint32 TileShift;
uint32 TileAddress;
uint32 NameSelect;
uint32 SCBase;
uint32 StartPalette;
uint32 PaletteShift;
uint32 PaletteMask;
uint8 EnableMath;
uint8 InterlaceLine;
uint8 *Buffer;
uint8 *BufferFlip;
uint8 *Buffered;
uint8 *BufferedFlip;
bool8 DirectColourMode;
};
struct SLineData
{
struct
{
uint16 VOffset;
uint16 HOffset;
} BG[4];
};
struct SLineMatrixData
{
short MatrixA;
short MatrixB;
short MatrixC;
short MatrixD;
short CentreX;
short CentreY;
short M7HOFS;
short M7VOFS;
};
extern uint16 BlackColourMap[256];
extern uint16 DirectColourMaps[8][256];
extern uint8 mul_brightness[16][32];
extern uint8 brightness_cap[64];
extern struct SBG BG;
extern struct SGFX GFX;
#define H_FLIP 0x4000
#define V_FLIP 0x8000
#define BLANK_TILE 2
struct COLOR_ADD
{
static alwaysinline uint16 fn(uint16 C1, uint16 C2)
{
const int RED_MASK = 0x1F << RED_SHIFT_BITS;
const int GREEN_MASK = 0x1F << GREEN_SHIFT_BITS;
const int BLUE_MASK = 0x1F;
int rb = C1 & (RED_MASK | BLUE_MASK);
rb += C2 & (RED_MASK | BLUE_MASK);
int rbcarry = rb & ((0x20 << RED_SHIFT_BITS) | (0x20 << 0));
int g = (C1 & (GREEN_MASK)) + (C2 & (GREEN_MASK));
int rgbsaturate = (((g & (0x20 << GREEN_SHIFT_BITS)) | rbcarry) >> 5) * 0x1f;
uint16 retval = (rb & (RED_MASK | BLUE_MASK)) | (g & GREEN_MASK) | rgbsaturate;
#if GREEN_SHIFT_BITS == 6
retval |= (retval & 0x0400) >> 5;
#endif
return retval;
}
static alwaysinline uint16 fn1_2(uint16 C1, uint16 C2)
{
return ((((C1 & RGB_REMOVE_LOW_BITS_MASK) +
(C2 & RGB_REMOVE_LOW_BITS_MASK)) >> 1) +
(C1 & C2 & RGB_LOW_BITS_MASK)) | ALPHA_BITS_MASK;
}
};
struct COLOR_ADD_BRIGHTNESS
{
static alwaysinline uint16 fn(uint16 C1, uint16 C2)
{
return ((brightness_cap[ (C1 >> RED_SHIFT_BITS) + (C2 >> RED_SHIFT_BITS) ] << RED_SHIFT_BITS) |
(brightness_cap[((C1 >> GREEN_SHIFT_BITS) & 0x1f) + ((C2 >> GREEN_SHIFT_BITS) & 0x1f)] << GREEN_SHIFT_BITS) |
// Proper 15->16bit color conversion moves the high bit of green into the low bit.
#if GREEN_SHIFT_BITS == 6
((brightness_cap[((C1 >> 6) & 0x1f) + ((C2 >> 6) & 0x1f)] & 0x10) << 1) |
#endif
(brightness_cap[ (C1 & 0x1f) + (C2 & 0x1f)] ));
}
static alwaysinline uint16 fn1_2(uint16 C1, uint16 C2)
{
return COLOR_ADD::fn1_2(C1, C2);
}
};
struct COLOR_SUB
{
static alwaysinline uint16 fn(uint16 C1, uint16 C2)
{
int rb1 = (C1 & (THIRD_COLOR_MASK | FIRST_COLOR_MASK)) | ((0x20 << 0) | (0x20 << RED_SHIFT_BITS));
int rb2 = C2 & (THIRD_COLOR_MASK | FIRST_COLOR_MASK);
int rb = rb1 - rb2;
int rbcarry = rb & ((0x20 << RED_SHIFT_BITS) | (0x20 << 0));
int g = ((C1 & (SECOND_COLOR_MASK)) | (0x20 << GREEN_SHIFT_BITS)) - (C2 & (SECOND_COLOR_MASK));
int rgbsaturate = (((g & (0x20 << GREEN_SHIFT_BITS)) | rbcarry) >> 5) * 0x1f;
uint16 retval = ((rb & (THIRD_COLOR_MASK | FIRST_COLOR_MASK)) | (g & SECOND_COLOR_MASK)) & rgbsaturate;
#if GREEN_SHIFT_BITS == 6
retval |= (retval & 0x0400) >> 5;
#endif
return retval;
}
static alwaysinline uint16 fn1_2(uint16 C1, uint16 C2)
{
return GFX.ZERO[((C1 | RGB_HI_BITS_MASKx2) -
(C2 & RGB_REMOVE_LOW_BITS_MASK)) >> 1];
}
};
void S9xStartScreenRefresh (void);
void S9xEndScreenRefresh (void);
void S9xBuildDirectColourMaps (void);
void RenderLine (uint8);
void S9xComputeClipWindows (void);
void S9xDisplayChar (uint16 *, uint8);
void S9xGraphicsScreenResize (void);
// called automatically unless Settings.AutoDisplayMessages is false
void S9xDisplayMessages (uint16 *, int, int, int, int);
// external port interface which must be implemented or initialised for each port
bool8 S9xGraphicsInit (void);
void S9xGraphicsDeinit (void);
bool8 S9xInitUpdate (void);
bool8 S9xDeinitUpdate (int, int);
bool8 S9xContinueUpdate (int, int);
void S9xReRefresh (void);
void S9xSyncSpeed (void);
// called instead of S9xDisplayString if set to non-NULL
extern void (*S9xCustomDisplayString) (const char *, int, int, bool, int type);
void S9xVariableDisplayString(const char* string, int linesFromBottom, int pixelsFromLeft, bool allowWrap, int type);
#endif