Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
RishiRecon
GitHub Repository: RishiRecon/exploits
Path: blob/main/misc/emulator/xnes/snes9x/gfx.h
28515 views
1
/***********************************************************************************
2
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3
4
(c) Copyright 1996 - 2002 Gary Henderson ([email protected]),
5
Jerremy Koot ([email protected])
6
7
(c) Copyright 2002 - 2004 Matthew Kendora
8
9
(c) Copyright 2002 - 2005 Peter Bortas ([email protected])
10
11
(c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/)
12
13
(c) Copyright 2001 - 2006 John Weidman ([email protected])
14
15
(c) Copyright 2002 - 2006 funkyass ([email protected]),
16
Kris Bleakley ([email protected])
17
18
(c) Copyright 2002 - 2010 Brad Jorsch ([email protected]),
19
Nach ([email protected]),
20
21
(c) Copyright 2002 - 2011 zones ([email protected])
22
23
(c) Copyright 2006 - 2007 nitsuja
24
25
(c) Copyright 2009 - 2011 BearOso,
26
OV2
27
28
29
BS-X C emulator code
30
(c) Copyright 2005 - 2006 Dreamer Nom,
31
zones
32
33
C4 x86 assembler and some C emulation code
34
(c) Copyright 2000 - 2003 _Demo_ ([email protected]),
35
Nach,
36
zsKnight ([email protected])
37
38
C4 C++ code
39
(c) Copyright 2003 - 2006 Brad Jorsch,
40
Nach
41
42
DSP-1 emulator code
43
(c) Copyright 1998 - 2006 _Demo_,
44
Andreas Naive ([email protected]),
45
Gary Henderson,
46
Ivar ([email protected]),
47
John Weidman,
48
Kris Bleakley,
49
Matthew Kendora,
50
Nach,
51
neviksti ([email protected])
52
53
DSP-2 emulator code
54
(c) Copyright 2003 John Weidman,
55
Kris Bleakley,
56
Lord Nightmare ([email protected]),
57
Matthew Kendora,
58
neviksti
59
60
DSP-3 emulator code
61
(c) Copyright 2003 - 2006 John Weidman,
62
Kris Bleakley,
63
Lancer,
64
z80 gaiden
65
66
DSP-4 emulator code
67
(c) Copyright 2004 - 2006 Dreamer Nom,
68
John Weidman,
69
Kris Bleakley,
70
Nach,
71
z80 gaiden
72
73
OBC1 emulator code
74
(c) Copyright 2001 - 2004 zsKnight,
75
pagefault ([email protected]),
76
Kris Bleakley
77
Ported from x86 assembler to C by sanmaiwashi
78
79
SPC7110 and RTC C++ emulator code used in 1.39-1.51
80
(c) Copyright 2002 Matthew Kendora with research by
81
zsKnight,
82
John Weidman,
83
Dark Force
84
85
SPC7110 and RTC C++ emulator code used in 1.52+
86
(c) Copyright 2009 byuu,
87
neviksti
88
89
S-DD1 C emulator code
90
(c) Copyright 2003 Brad Jorsch with research by
91
Andreas Naive,
92
John Weidman
93
94
S-RTC C emulator code
95
(c) Copyright 2001 - 2006 byuu,
96
John Weidman
97
98
ST010 C++ emulator code
99
(c) Copyright 2003 Feather,
100
John Weidman,
101
Kris Bleakley,
102
Matthew Kendora
103
104
Super FX x86 assembler emulator code
105
(c) Copyright 1998 - 2003 _Demo_,
106
pagefault,
107
zsKnight
108
109
Super FX C emulator code
110
(c) Copyright 1997 - 1999 Ivar,
111
Gary Henderson,
112
John Weidman
113
114
Sound emulator code used in 1.5-1.51
115
(c) Copyright 1998 - 2003 Brad Martin
116
(c) Copyright 1998 - 2006 Charles Bilyue'
117
118
Sound emulator code used in 1.52+
119
(c) Copyright 2004 - 2007 Shay Green ([email protected])
120
121
SH assembler code partly based on x86 assembler code
122
(c) Copyright 2002 - 2004 Marcus Comstedt ([email protected])
123
124
2xSaI filter
125
(c) Copyright 1999 - 2001 Derek Liauw Kie Fa
126
127
HQ2x, HQ3x, HQ4x filters
128
(c) Copyright 2003 Maxim Stepin ([email protected])
129
130
NTSC filter
131
(c) Copyright 2006 - 2007 Shay Green
132
133
GTK+ GUI code
134
(c) Copyright 2004 - 2011 BearOso
135
136
Win32 GUI code
137
(c) Copyright 2003 - 2006 blip,
138
funkyass,
139
Matthew Kendora,
140
Nach,
141
nitsuja
142
(c) Copyright 2009 - 2011 OV2
143
144
Mac OS GUI code
145
(c) Copyright 1998 - 2001 John Stiles
146
(c) Copyright 2001 - 2011 zones
147
148
149
Specific ports contains the works of other authors. See headers in
150
individual files.
151
152
153
Snes9x homepage: http://www.snes9x.com/
154
155
Permission to use, copy, modify and/or distribute Snes9x in both binary
156
and source form, for non-commercial purposes, is hereby granted without
157
fee, providing that this license information and copyright notice appear
158
with all copies and any derived work.
159
160
This software is provided 'as-is', without any express or implied
161
warranty. In no event shall the authors be held liable for any damages
162
arising from the use of this software or it's derivatives.
163
164
Snes9x is freeware for PERSONAL USE only. Commercial users should
165
seek permission of the copyright holders first. Commercial use includes,
166
but is not limited to, charging money for Snes9x or software derived from
167
Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
168
using Snes9x as a promotion for your commercial product.
169
170
The copyright holders request that bug fixes and improvements to the code
171
should be forwarded to them so everyone can benefit from the modifications
172
in future versions.
173
174
Super NES and Super Nintendo Entertainment System are trademarks of
175
Nintendo Co., Limited and its subsidiary companies.
176
***********************************************************************************/
177
178
179
#ifndef _GFX_H_
180
#define _GFX_H_
181
182
struct SGFX
183
{
184
uint16 *Screen;
185
uint16 *SubScreen;
186
uint8 *ZBuffer;
187
uint8 *SubZBuffer;
188
uint32 Pitch;
189
uint32 ScreenSize;
190
uint16 *S;
191
uint8 *DB;
192
uint16 *X2;
193
uint16 *ZERO;
194
uint32 RealPPL; // true PPL of Screen buffer
195
uint32 PPL; // number of pixels on each of Screen buffer
196
uint32 LinesPerTile; // number of lines in 1 tile (4 or 8 due to interlace)
197
uint16 *ScreenColors; // screen colors for rendering main
198
uint16 *RealScreenColors; // screen colors, ignoring color window clipping
199
uint8 Z1; // depth for comparison
200
uint8 Z2; // depth to save
201
uint32 FixedColour;
202
uint8 DoInterlace;
203
uint8 InterlaceFrame;
204
uint32 StartY;
205
uint32 EndY;
206
bool8 ClipColors;
207
uint8 OBJWidths[128];
208
uint8 OBJVisibleTiles[128];
209
210
struct ClipData *Clip;
211
212
struct
213
{
214
uint8 RTOFlags;
215
int16 Tiles;
216
217
struct
218
{
219
int8 Sprite;
220
uint8 Line;
221
} OBJ[32];
222
} OBJLines[SNES_HEIGHT_EXTENDED];
223
224
#ifdef GFX_MULTI_FORMAT
225
uint32 PixelFormat;
226
uint32 (*BuildPixel) (uint32, uint32, uint32);
227
uint32 (*BuildPixel2) (uint32, uint32, uint32);
228
void (*DecomposePixel) (uint32, uint32 &, uint32 &, uint32 &);
229
#endif
230
231
void (*DrawBackdropMath) (uint32, uint32, uint32);
232
void (*DrawBackdropNomath) (uint32, uint32, uint32);
233
void (*DrawTileMath) (uint32, uint32, uint32, uint32);
234
void (*DrawTileNomath) (uint32, uint32, uint32, uint32);
235
void (*DrawClippedTileMath) (uint32, uint32, uint32, uint32, uint32, uint32);
236
void (*DrawClippedTileNomath) (uint32, uint32, uint32, uint32, uint32, uint32);
237
void (*DrawMosaicPixelMath) (uint32, uint32, uint32, uint32, uint32, uint32);
238
void (*DrawMosaicPixelNomath) (uint32, uint32, uint32, uint32, uint32, uint32);
239
void (*DrawMode7BG1Math) (uint32, uint32, int);
240
void (*DrawMode7BG1Nomath) (uint32, uint32, int);
241
void (*DrawMode7BG2Math) (uint32, uint32, int);
242
void (*DrawMode7BG2Nomath) (uint32, uint32, int);
243
244
const char *InfoString;
245
uint32 InfoStringTimeout;
246
char FrameDisplayString[256];
247
};
248
249
struct SBG
250
{
251
uint8 (*ConvertTile) (uint8 *, uint32, uint32);
252
uint8 (*ConvertTileFlip) (uint8 *, uint32, uint32);
253
254
uint32 TileSizeH;
255
uint32 TileSizeV;
256
uint32 OffsetSizeH;
257
uint32 OffsetSizeV;
258
uint32 TileShift;
259
uint32 TileAddress;
260
uint32 NameSelect;
261
uint32 SCBase;
262
263
uint32 StartPalette;
264
uint32 PaletteShift;
265
uint32 PaletteMask;
266
uint8 EnableMath;
267
uint8 InterlaceLine;
268
269
uint8 *Buffer;
270
uint8 *BufferFlip;
271
uint8 *Buffered;
272
uint8 *BufferedFlip;
273
bool8 DirectColourMode;
274
};
275
276
struct SLineData
277
{
278
struct
279
{
280
uint16 VOffset;
281
uint16 HOffset;
282
} BG[4];
283
};
284
285
struct SLineMatrixData
286
{
287
short MatrixA;
288
short MatrixB;
289
short MatrixC;
290
short MatrixD;
291
short CentreX;
292
short CentreY;
293
short M7HOFS;
294
short M7VOFS;
295
};
296
297
extern uint16 BlackColourMap[256];
298
extern uint16 DirectColourMaps[8][256];
299
extern uint8 mul_brightness[16][32];
300
extern struct SBG BG;
301
extern struct SGFX GFX;
302
303
#define H_FLIP 0x4000
304
#define V_FLIP 0x8000
305
#define BLANK_TILE 2
306
307
#define COLOR_ADD1_2(C1, C2) \
308
((((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
309
((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \
310
((C1) & (C2) & RGB_LOW_BITS_MASK)) | ALPHA_BITS_MASK)
311
312
#define COLOR_ADD(C1, C2) \
313
(GFX.X2[((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
314
((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \
315
((C1) & (C2) & RGB_LOW_BITS_MASK)] | \
316
(((C1) ^ (C2)) & RGB_LOW_BITS_MASK))
317
318
#define COLOR_SUB1_2(C1, C2) \
319
GFX.ZERO[(((C1) | RGB_HI_BITS_MASKx2) - \
320
((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1]
321
322
inline uint16 COLOR_SUB (uint16 C1, uint16 C2)
323
{
324
uint16 mC1, mC2, v = ALPHA_BITS_MASK;
325
326
mC1 = C1 & FIRST_COLOR_MASK;
327
mC2 = C2 & FIRST_COLOR_MASK;
328
if (mC1 > mC2) v += (mC1 - mC2);
329
330
mC1 = C1 & SECOND_COLOR_MASK;
331
mC2 = C2 & SECOND_COLOR_MASK;
332
if (mC1 > mC2) v += (mC1 - mC2);
333
334
mC1 = C1 & THIRD_COLOR_MASK;
335
mC2 = C2 & THIRD_COLOR_MASK;
336
if (mC1 > mC2) v += (mC1 - mC2);
337
338
return (v);
339
}
340
341
void S9xStartScreenRefresh (void);
342
void S9xEndScreenRefresh (void);
343
void S9xUpdateScreen (void);
344
void S9xBuildDirectColourMaps (void);
345
void RenderLine (uint8);
346
void S9xComputeClipWindows (void);
347
void S9xDisplayChar (uint16 *, uint8);
348
// called automatically unless Settings.AutoDisplayMessages is false
349
void S9xDisplayMessages (uint16 *, int, int, int, int);
350
#ifdef GFX_MULTI_FORMAT
351
bool8 S9xSetRenderPixelFormat (int);
352
#endif
353
354
// external port interface which must be implemented or initialised for each port
355
bool8 S9xGraphicsInit (void);
356
void S9xGraphicsDeinit (void);
357
bool8 S9xInitUpdate (void);
358
bool8 S9xDeinitUpdate (int, int);
359
bool8 S9xContinueUpdate (int, int);
360
void S9xReRefresh (void);
361
void S9xSetPalette (void);
362
void S9xSyncSpeed (void);
363
364
// called instead of S9xDisplayString if set to non-NULL
365
extern void (*S9xCustomDisplayString) (const char *, int, int, bool);
366
367
#endif
368
369