2 * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
4 * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5 * Jerremy Koot (jkoot@snes9x.com)
7 * Super FX C emulator code
8 * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
10 * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
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).
16 * DOS port code contains the works of other authors. See headers in
19 * Snes9x homepage: http://www.snes9x.com
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.
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.
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.
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
38 * Super NES and Super Nintendo Entertainment System are trademarks of
39 * Nintendo Co., Limited and its subsidiary companies.
47 // Initialize these variables
54 // Setup in call to S9xGraphicsInit()
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
73 uint32 InfoStringTimeout;
76 struct ClipData *pCurrentClip;
78 uint32 Mode7PriorityMask;
89 #ifdef GFX_MULTI_FORMAT
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);
104 #define H_FLIP 0x4000
105 #define V_FLIP 0x8000
107 #define IN_VIDEO_MEMORY 3
124 bool8_32 DirectColourMode;
127 struct SLineMatrixData
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];
142 extern uint16 DirectColourMaps [8][256];
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];
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)
154 #ifdef FAST_LSB_WORD_ACCESS
155 #define READ_2BYTES(s) (*(uint16 *) (s))
156 #define WRITE_2BYTES(s, d) *(uint16 *) (s) = (d)
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
169 #define SUB_SCREEN_DEPTH 0
170 #define MAIN_SCREEN_DEPTH 32
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)]
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))
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)
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]
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))
201 #define COLOR_SUB1_2(C1, C2) \
202 GFX.ZERO [(((C1) | RGB_HI_BITS_MASKx2) - \
203 ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1]
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);
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 ();
223 // External port interface which must be implemented or initialised for each
225 extern struct SGFX GFX;
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 ();
234 #ifdef GFX_MULTI_FORMAT
235 bool8_32 S9xSetRenderPixelFormat (int format);