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
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)
58 // Setup in call to S9xGraphicsInit()
71 uint32 InfoStringTimeout;
74 struct ClipData *pCurrentClip;
76 uint32 Mode7PriorityMask;
87 #ifdef GFX_MULTI_FORMAT
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);
102 #define H_FLIP 0x4000
103 #define V_FLIP 0x8000
105 #define IN_VIDEO_MEMORY 3
122 bool8 DirectColourMode;
125 struct SLineMatrixData
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];
140 extern uint16 DirectColourMaps [8][256];
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];
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)
152 #ifdef FAST_LSB_WORD_ACCESS
153 #define READ_2BYTES(s) (*(uint16 *) (s))
154 #define WRITE_2BYTES(s, d) *(uint16 *) (s) = (d)
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
167 #define SUB_SCREEN_DEPTH 0
168 #define MAIN_SCREEN_DEPTH 32
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)]
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))
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)
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]
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))
199 #define COLOR_SUB1_2(C1, C2) \
200 GFX.ZERO [(((C1) | RGB_HI_BITS_MASKx2) - \
201 ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1]
204 typedef intptr_t tile_offset_t;
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);
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 ();
224 // External port interface which must be implemented or initialised for each
226 extern struct SGFX GFX;
228 bool8 S9xGraphicsInit ();
229 void S9xGraphicsDeinit();
230 bool8 S9xInitUpdate (void);
231 bool8 S9xDeinitUpdate (int Width, int Height);
232 void S9xSyncSpeed ();
234 #ifdef GFX_MULTI_FORMAT
235 bool8 S9xSetRenderPixelFormat (int format);
238 void S9xSetInfoString(const char * fmt, ...);