fix most compiler code style warnings
[drnoksnes] / gfx.h
1 /*
2  * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3  *
4  * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5  *                           Jerremy Koot (jkoot@snes9x.com)
6  *
7  * Super FX C emulator code 
8  * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
9  *                           Gary Henderson.
10  * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
11  *
12  * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
13  * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
14  * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
15  *
16  * DOS port code contains the works of other authors. See headers in
17  * individual files.
18  *
19  * Snes9x homepage: http://www.snes9x.com
20  *
21  * Permission to use, copy, modify and distribute Snes9x in both binary and
22  * source form, for non-commercial purposes, is hereby granted without fee,
23  * providing that this license information and copyright notice appear with
24  * all copies and any derived work.
25  *
26  * This software is provided 'as-is', without any express or implied
27  * warranty. In no event shall the authors be held liable for any damages
28  * arising from the use of this software.
29  *
30  * Snes9x is freeware for PERSONAL USE only. Commercial users should
31  * seek permission of the copyright holders first. Commercial use includes
32  * charging money for Snes9x or software derived from Snes9x.
33  *
34  * The copyright holders request that bug fixes and improvements to the code
35  * should be forwarded to them so everyone can benefit from the modifications
36  * in future versions.
37  *
38  * Super NES and Super Nintendo Entertainment System are trademarks of
39  * Nintendo Co., Limited and its subsidiary companies.
40  */
41 #ifndef _GFX_H_
42 #define _GFX_H_
43
44 #include "port.h"
45
46 struct SGFX{
47     // Initialize these variables
48     uint8  *Screen;
49     uint8  *SubScreen;
50     uint8  *ZBuffer;
51     uint8  *SubZBuffer;
52     uint32 Pitch;
53
54     // Setup in call to S9xGraphicsInit()
55     int   Delta;
56     uint16 *X2;
57     uint16 *ZERO_OR_X2;
58     uint16 *ZERO;
59     uint32 RealPitch; // True pitch of Screen buffer.
60     uint32 Pitch2;    // Same as RealPitch except while using speed up hack for Glide.
61     uint32 ZPitch;    // Pitch of ZBuffer
62     uint32 PPL;       // Number of pixels on each of Screen buffer
63     uint32 PPLx2;
64     uint32 PixSize;
65     uint8  *S;
66     uint8  *DB;
67     uint16 *ScreenColors;
68     uint32 DepthDelta;
69     uint8  Z1;
70     uint8  Z2;
71     uint32 FixedColour;
72     char *InfoString;
73     uint32 InfoStringTimeout;
74     uint32 StartY;
75     uint32 EndY;
76     struct ClipData *pCurrentClip;
77     uint32 Mode7Mask;
78     uint32 Mode7PriorityMask;
79     int    OBJList [129];
80     uint32 Sizes [129];
81     int    VPositions [129];
82
83     uint8  r212c;
84     uint8  r212d;
85     uint8  r2130;
86     uint8  r2131;
87     bool8_32  Pseudo;
88     
89 #ifdef GFX_MULTI_FORMAT
90     uint32 PixelFormat;
91     uint32 (*BuildPixel) (uint32 R, uint32 G, uint32 B);
92     uint32 (*BuildPixel2) (uint32 R, uint32 G, uint32 B);
93     void   (*DecomposePixel) (uint32 Pixel, uint32 &R, uint32 &G, uint32 &B);
94 #endif
95 };
96
97 struct SLineData {
98     struct {
99         uint16 VOffset;
100         uint16 HOffset;
101     } BG [4];
102 };
103
104 #define H_FLIP 0x4000
105 #define V_FLIP 0x8000
106 #define BLANK_TILE 2
107 #define IN_VIDEO_MEMORY 3
108
109 struct SBG
110 {
111     uint32 TileSize;
112     uint32 BitShift;
113     uint32 TileShift;
114     uint32 TileAddress;
115     uint32 NameSelect;
116     uint32 SCBase;
117
118     uint32 StartPalette;
119     uint32 PaletteShift;
120     uint32 PaletteMask;
121     
122         uint8 *Buffer;
123     uint8 *Buffered;
124     bool8_32  DirectColourMode;
125 };
126
127 struct SLineMatrixData
128 {
129     short MatrixA;
130     short MatrixB;
131     short MatrixC;
132     short MatrixD;
133     short CentreX;
134     short CentreY;
135 };
136
137 extern uint32 odd_high [4][16];
138 extern uint32 odd_low [4][16];
139 extern uint32 even_high [4][16];
140 extern uint32 even_low [4][16];
141 extern SBG BG;
142 extern uint16 DirectColourMaps [8][256];
143
144 //extern uint8 add32_32 [32][32];
145 //extern uint8 add32_32_half [32][32];
146 //extern uint8 sub32_32 [32][32];
147 //extern uint8 sub32_32_half [32][32];
148 extern uint8 mul_brightness [16][32];
149
150 // Could use BSWAP instruction on Intel port...
151 #define SWAP_DWORD(dw) dw = ((dw & 0xff) << 24) | ((dw & 0xff00) << 8) | \
152                             ((dw & 0xff0000) >> 8) | ((dw & 0xff000000) >> 24)
153
154 #ifdef FAST_LSB_WORD_ACCESS
155 #define READ_2BYTES(s) (*(uint16 *) (s))
156 #define WRITE_2BYTES(s, d) *(uint16 *) (s) = (d)
157 #else
158 #ifdef LSB_FIRST
159 #define READ_2BYTES(s) (*(uint8 *) (s) | (*((uint8 *) (s) + 1) << 8))
160 #define WRITE_2BYTES(s, d) *(uint8 *) (s) = (d), \
161                            *((uint8 *) (s) + 1) = (d) >> 8
162 #else  // else MSB_FISRT
163 #define READ_2BYTES(s) (*(uint8 *) (s) | (*((uint8 *) (s) + 1) << 8))
164 #define WRITE_2BYTES(s, d) *(uint8 *) (s) = (d), \
165                            *((uint8 *) (s) + 1) = (d) >> 8
166 #endif // LSB_FIRST
167 #endif // i386
168
169 #define SUB_SCREEN_DEPTH 0
170 #define MAIN_SCREEN_DEPTH 32
171
172 #if defined(OLD_COLOUR_BLENDING)
173 #define COLOR_ADD(C1, C2) \
174 GFX.X2 [((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
175           ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \
176         ((C1) & (C2) & RGB_LOW_BITS_MASK)]
177 #else
178 #define COLOR_ADD(C1, C2) \
179 (GFX.X2 [((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
180           ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \
181          ((C1) & (C2) & RGB_LOW_BITS_MASK)] | \
182  (((C1) ^ (C2)) & RGB_LOW_BITS_MASK))      
183 #endif
184
185 #define COLOR_ADD1_2(C1, C2) \
186         ((((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
187          ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \
188          ((C1) & (C2) & RGB_LOW_BITS_MASK)) | ALPHA_BITS_MASK)
189
190 #if defined(OLD_COLOUR_BLENDING)
191 #define COLOR_SUB(C1, C2) \
192         GFX.ZERO_OR_X2 [(((C1) | RGB_HI_BITS_MASKx2) - \
193                  ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1]
194 #else
195 #define COLOR_SUB(C1, C2) \
196         (GFX.ZERO_OR_X2 [(((C1) | RGB_HI_BITS_MASKx2) - \
197                   ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1] + \
198         ((C1) & RGB_LOW_BITS_MASK) - ((C2) & RGB_LOW_BITS_MASK))
199 #endif
200
201 #define COLOR_SUB1_2(C1, C2) \
202         GFX.ZERO [(((C1) | RGB_HI_BITS_MASKx2) - \
203            ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1]
204
205 typedef void (*NormalTileRenderer) (uint32 Tile, uint32 Offset, 
206                                     uint32 StartLine, uint32 LineCount);
207 typedef void (*ClippedTileRenderer) (uint32 Tile, uint32 Offset,
208                                      uint32 StartPixel, uint32 Width,
209                                      uint32 StartLine, uint32 LineCount);
210 typedef void (*LargePixelRenderer) (uint32 Tile, uint32 Offset,
211                                     uint32 StartPixel, uint32 Pixels,
212                                     uint32 StartLine, uint32 LineCount);
213
214 START_EXTERN_C
215 void S9xStartScreenRefresh ();
216 void S9xDrawScanLine (uint8 Line);
217 void S9xEndScreenRefresh ();
218 void S9xSetupOBJ (struct SOBJ *);
219 void S9xUpdateScreen ();
220 void RenderLine (uint8 line);
221 void S9xBuildDirectColourMaps ();
222
223 // External port interface which must be implemented or initialised for each
224 // port.
225 extern struct SGFX GFX;
226
227 bool8_32 S9xGraphicsInit ();
228 void S9xGraphicsDeinit();
229 bool8_32 S9xInitUpdate (void);
230 bool8_32 S9xDeinitUpdate (int Width, int Height, bool8_32 sixteen_bit);
231 void S9xSetPalette ();
232 void S9xSyncSpeed ();
233
234 #ifdef GFX_MULTI_FORMAT
235 bool8_32 S9xSetRenderPixelFormat (int format);
236 #endif
237
238 END_EXTERN_C
239
240 #endif