workaround a problem with the harmattan gcc
[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;           /// Width of surface in bytes
53         uint32 ZPitch;          /// Pitch of ZBuffer
54         uint32 Delta;           /// Set to (GFX.SubScreen - GFX.Screen) >> 1
55     uint32 DepthDelta;  /// Set to GFX.SubZBuffer - GFX.ZBuffer
56     uint32 PPL;                 /// Number of pixels per line (= pitch in pixels)
57
58     // Setup in call to S9xGraphicsInit()
59     uint16 *X2;
60     uint16 *ZERO_OR_X2;
61     uint16 *ZERO;
62
63     uint8  *S;
64     uint8  *DB;
65     uint16 *ScreenColors;
66     uint8  Z1;
67     uint8  Z2;
68     uint32 FixedColour;
69
70     char *InfoString;
71     uint32 InfoStringTimeout;
72     uint32 StartY;
73     uint32 EndY;
74     struct ClipData *pCurrentClip;
75     uint32 Mode7Mask;
76     uint32 Mode7PriorityMask;
77     int    OBJList [129];
78     uint32 Sizes [129];
79     int    VPositions [129];
80
81     uint8  r212c;
82     uint8  r212d;
83     uint8  r2130;
84     uint8  r2131;
85     bool8  Pseudo;
86     
87 #ifdef GFX_MULTI_FORMAT
88     uint32 PixelFormat;
89     uint32 (*BuildPixel) (uint32 R, uint32 G, uint32 B);
90     uint32 (*BuildPixel2) (uint32 R, uint32 G, uint32 B);
91     void   (*DecomposePixel) (uint32 Pixel, uint32 &R, uint32 &G, uint32 &B);
92 #endif
93 };
94
95 struct SLineData {
96     struct {
97         uint16 VOffset;
98         uint16 HOffset;
99     } BG [4];
100 };
101
102 #define H_FLIP 0x4000
103 #define V_FLIP 0x8000
104 #define BLANK_TILE 2
105 #define IN_VIDEO_MEMORY 3
106
107 struct SBG
108 {
109     uint32 TileSize;
110     uint32 BitShift;
111     uint32 TileShift;
112     uint32 TileAddress;
113     uint32 NameSelect;
114     uint32 SCBase;
115
116     uint32 StartPalette;
117     uint32 PaletteShift;
118     uint32 PaletteMask;
119     
120         uint8 *Buffer;
121     uint8 *Buffered;
122     bool8  DirectColourMode;
123 };
124
125 struct SLineMatrixData
126 {
127     short MatrixA;
128     short MatrixB;
129     short MatrixC;
130     short MatrixD;
131     short CentreX;
132     short CentreY;
133 };
134
135 extern uint32 odd_high [4][16];
136 extern uint32 odd_low [4][16];
137 extern uint32 even_high [4][16];
138 extern uint32 even_low [4][16];
139 extern SBG BG;
140 extern uint16 DirectColourMaps [8][256];
141
142 //extern uint8 add32_32 [32][32];
143 //extern uint8 add32_32_half [32][32];
144 //extern uint8 sub32_32 [32][32];
145 //extern uint8 sub32_32_half [32][32];
146 extern uint8 mul_brightness [16][32];
147
148 // Could use BSWAP instruction on Intel port...
149 #define SWAP_DWORD(dw) dw = ((dw & 0xff) << 24) | ((dw & 0xff00) << 8) | \
150                             ((dw & 0xff0000) >> 8) | ((dw & 0xff000000) >> 24)
151
152 #ifdef FAST_LSB_WORD_ACCESS
153 #define READ_2BYTES(s) (*(uint16 *) (s))
154 #define WRITE_2BYTES(s, d) *(uint16 *) (s) = (d)
155 #else
156 #ifdef LSB_FIRST
157 #define READ_2BYTES(s) (*(uint8 *) (s) | (*((uint8 *) (s) + 1) << 8))
158 #define WRITE_2BYTES(s, d) *(uint8 *) (s) = (d), \
159                            *((uint8 *) (s) + 1) = (d) >> 8
160 #else  // else MSB_FISRT
161 #define READ_2BYTES(s) (*(uint8 *) (s) | (*((uint8 *) (s) + 1) << 8))
162 #define WRITE_2BYTES(s, d) *(uint8 *) (s) = (d), \
163                            *((uint8 *) (s) + 1) = (d) >> 8
164 #endif // LSB_FIRST
165 #endif // i386
166
167 #define SUB_SCREEN_DEPTH 0
168 #define MAIN_SCREEN_DEPTH 32
169
170 #if defined(OLD_COLOUR_BLENDING)
171 #define COLOR_ADD(C1, C2) \
172 GFX.X2 [((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
173           ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \
174         ((C1) & (C2) & RGB_LOW_BITS_MASK)]
175 #else
176 #define COLOR_ADD(C1, C2) \
177 (GFX.X2 [((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
178           ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \
179          ((C1) & (C2) & RGB_LOW_BITS_MASK)] | \
180  (((C1) ^ (C2)) & RGB_LOW_BITS_MASK))      
181 #endif
182
183 #define COLOR_ADD1_2(C1, C2) \
184         ((((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
185          ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \
186          ((C1) & (C2) & RGB_LOW_BITS_MASK)) | ALPHA_BITS_MASK)
187
188 #if defined(OLD_COLOUR_BLENDING)
189 #define COLOR_SUB(C1, C2) \
190         GFX.ZERO_OR_X2 [(((C1) | RGB_HI_BITS_MASKx2) - \
191                  ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1]
192 #else
193 #define COLOR_SUB(C1, C2) \
194         (GFX.ZERO_OR_X2 [(((C1) | RGB_HI_BITS_MASKx2) - \
195                   ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1] + \
196         ((C1) & RGB_LOW_BITS_MASK) - ((C2) & RGB_LOW_BITS_MASK))
197 #endif
198
199 #define COLOR_SUB1_2(C1, C2) \
200         GFX.ZERO [(((C1) | RGB_HI_BITS_MASKx2) - \
201            ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1]
202
203
204 typedef intptr_t tile_offset_t;
205
206 typedef void (*NormalTileRenderer) (uint32 Tile, tile_offset_t Offset,
207                                     uint32 StartLine, uint32 LineCount);
208 typedef void (*ClippedTileRenderer) (uint32 Tile, tile_offset_t Offset,
209                                      uint32 StartPixel, uint32 Width,
210                                      uint32 StartLine, uint32 LineCount);
211 typedef void (*LargePixelRenderer) (uint32 Tile, tile_offset_t Offset,
212                                     uint32 StartPixel, uint32 Pixels,
213                                     uint32 StartLine, uint32 LineCount);
214
215 START_EXTERN_C
216 void S9xStartScreenRefresh ();
217 void S9xDrawScanLine (uint8 Line);
218 void S9xEndScreenRefresh ();
219 void S9xSetupOBJ (struct SOBJ *);
220 void S9xUpdateScreen ();
221 void RenderLine (uint8 line);
222 void S9xBuildDirectColourMaps ();
223
224 // External port interface which must be implemented or initialised for each
225 // port.
226 extern struct SGFX GFX;
227
228 bool8 S9xGraphicsInit ();
229 void S9xGraphicsDeinit();
230 bool8 S9xInitUpdate (void);
231 bool8 S9xDeinitUpdate (int Width, int Height);
232 void S9xSyncSpeed ();
233
234 #ifdef GFX_MULTI_FORMAT
235 bool8 S9xSetRenderPixelFormat (int format);
236 #endif
237
238 void S9xSetInfoString(const char * fmt, ...);
239
240 END_EXTERN_C
241
242 #endif