1 /*******************************************************************************
2 Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
4 (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and
5 Jerremy Koot (jkoot@snes9x.com)
7 (c) Copyright 2001 - 2004 John Weidman (jweidman@slip.net)
9 (c) Copyright 2002 - 2004 Brad Jorsch (anomie@users.sourceforge.net),
10 funkyass (funkyass@spam.shaw.ca),
11 Joel Yliluoma (http://iki.fi/bisqwit/)
12 Kris Bleakley (codeviolation@hotmail.com),
14 Nach (n-a-c-h@users.sourceforge.net),
15 Peter Bortas (peter@bortas.org) and
16 zones (kasumitokoduck@yahoo.com)
18 C4 x86 assembler and some C emulation code
19 (c) Copyright 2000 - 2003 zsKnight (zsknight@zsnes.com),
20 _Demo_ (_demo_@zsnes.com), and Nach
23 (c) Copyright 2003 Brad Jorsch
26 (c) Copyright 1998 - 2004 Ivar (ivar@snes9x.com), _Demo_, Gary Henderson,
27 John Weidman, neviksti (neviksti@hotmail.com),
28 Kris Bleakley, Andreas Naive
31 (c) Copyright 2003 Kris Bleakley, John Weidman, neviksti, Matthew Kendora, and
32 Lord Nightmare (lord_nightmare@users.sourceforge.net
35 (c) Copyright 2001 - 2004 zsKnight, pagefault (pagefault@zsnes.com) and
37 Ported from x86 assembler to C by sanmaiwashi
39 SPC7110 and RTC C++ emulator code
40 (c) Copyright 2002 Matthew Kendora with research by
41 zsKnight, John Weidman, and Dark Force
44 (c) Copyright 2003 Brad Jorsch with research by
45 Andreas Naive and John Weidman
48 (c) Copyright 2001 John Weidman
50 ST010 C++ emulator code
51 (c) Copyright 2003 Feather, Kris Bleakley, John Weidman and Matthew Kendora
53 Super FX x86 assembler emulator code
54 (c) Copyright 1998 - 2003 zsKnight, _Demo_, and pagefault
56 Super FX C emulator code
57 (c) Copyright 1997 - 1999 Ivar, Gary Henderson and John Weidman
60 SH assembler code partly based on x86 assembler code
61 (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se)
64 Specific ports contains the works of other authors. See headers in
67 Snes9x homepage: http://www.snes9x.com
69 Permission to use, copy, modify and distribute Snes9x in both binary and
70 source form, for non-commercial purposes, is hereby granted without fee,
71 providing that this license information and copyright notice appear with
72 all copies and any derived work.
74 This software is provided 'as-is', without any express or implied
75 warranty. In no event shall the authors be held liable for any damages
76 arising from the use of this software.
78 Snes9x is freeware for PERSONAL USE only. Commercial users should
79 seek permission of the copyright holders first. Commercial use includes
80 charging money for Snes9x or software derived from Snes9x.
82 The copyright holders request that bug fixes and improvements to the code
83 should be forwarded to them so everyone can benefit from the modifications
86 Super NES and Super Nintendo Entertainment System are trademarks of
87 Nintendo Co., Limited and its subsidiary companies.
88 *******************************************************************************/
92 uint16 DSP2Op09Word1=0;
93 uint16 DSP2Op09Word2=0;
94 bool DSP2Op05HasLen=false;
96 bool DSP2Op06HasLen=false;
98 uint8 DSP2Op05Transparent=0;
103 // Overlay bitmap with transparency.
106 // Bitmap 1: i[0] <=> i[size-1]
107 // Bitmap 2: i[size] <=> i[2*size-1]
111 // Bitmap 3: o[0] <=> o[size-1]
115 // Process all 4-bit pixels (nibbles) in the bitmap
117 // if ( BM2_pixel == transparent_color )
118 // pixelout = BM1_pixel
120 // pixelout = BM2_pixel
122 // The max size bitmap is limited to 255 because the size parameter is a byte
123 // I think size=0 is an error. The behavior of the chip on size=0 is to
124 // return the last value written to DR if you read DR on Op05 with
125 // size = 0. I don't think it's worth implementing this quirk unless it's
131 unsigned char *p1 = DSP1.parameters;
132 unsigned char *p2 = &DSP1.parameters[DSP2Op05Len];
133 unsigned char *p3 = DSP1.output;
135 color = DSP2Op05Transparent&0x0f;
137 for( n = 0; n < DSP2Op05Len; n++ )
141 *p3++ = ( ((c2 >> 4) == color ) ? c1 & 0xf0: c2 & 0xf0 ) |
142 ( ((c2 & 0x0f)==color) ? c1 & 0x0f: c2 & 0x0f );
148 // Op01 size is always 32 bytes input and output.
149 // The hardware does strange things if you vary the size.
152 unsigned char c0, c1, c2, c3;
153 unsigned char *p1 = DSP1.parameters;
154 unsigned char *p2a = DSP1.output;
155 unsigned char *p2b = &DSP1.output[16]; // halfway
157 // Process 8 blocks of 4 bytes each
159 for ( j = 0; j < 8; j++ )
166 *p2a++ = (c0 & 0x10) << 3 |
175 *p2a++ = (c0 & 0x20) << 2 |
184 *p2b++ = (c0 & 0x40) << 1 |
194 *p2b++ = (c0 & 0x80) |
214 for ( i = 0, j = DSP2Op06Len - 1; i < DSP2Op06Len; i++, j-- )
216 DSP1.output[j] = (DSP1.parameters[i] << 4) | (DSP1.parameters[i] >> 4);
220 bool DSP2Op0DHasLen=false;
221 int DSP2Op0DOutLen=0;
224 #ifndef DSP2_BIT_ACCURRATE_CODE
226 // Scale bitmap based on input length out output length
230 // Overload's algorithm - use this unless doing hardware testing
232 // One note: the HW can do odd byte scaling but since we divide
233 // by two to get the count of bytes this won't work well for
234 // odd byte scaling (in any of the current algorithm implementations).
235 // So far I haven't seen Dungeon Master use it.
236 // If it does we can adjust the parameters and code to work with it
240 uint8 pixelarray[512];
242 for(i=0; i<DSP2Op0DOutLen*2; i++)
244 pixel_offset = (i * DSP2Op0DInLen) / DSP2Op0DOutLen;
245 if ( (pixel_offset&1) == 0 )
246 pixelarray[i] = DSP1.parameters[pixel_offset>>1] >> 4;
248 pixelarray[i] = DSP1.parameters[pixel_offset>>1] & 0x0f;
251 for ( i=0; i < DSP2Op0DOutLen; i++ )
252 DSP1.output[i] = ( pixelarray[i<<1] << 4 ) | pixelarray[(i<<1)+1];
259 // Bit accurate hardware algorithm - uses fixed point math
260 // This should match the DSP2 Op0D output exactly
261 // I wouldn't recommend using this unless you're doing hardware debug.
262 // In some situations it has small visual artifacts that
263 // are not readily apparent on a TV screen but show up clearly
264 // on a monitor. Use Overload's scaling instead.
265 // This is for hardware verification testing.
267 // One note: the HW can do odd byte scaling but since we divide
268 // by two to get the count of bytes this won't work well for
269 // odd byte scaling (in any of the current algorithm implementations).
270 // So far I haven't seen Dungeon Master use it.
271 // If it does we can adjust the parameters and code to work with it
274 uint32 multiplier; // Any size int >= 32-bits
275 uint32 pixloc; // match size of multiplier
277 uint8 pixelarray[512];
279 if (DSP2Op0DInLen <= DSP2Op0DOutLen)
280 multiplier = 0x10000; // In our self defined fixed point 0x10000 == 1
282 multiplier = (DSP2Op0DInLen << 17) / ((DSP2Op0DOutLen<<1) + 1);
285 for ( i=0; i < DSP2Op0DOutLen * 2; i++ )
290 pixelarray[i] = DSP1.parameters[j>>1] & 0x0f;
292 pixelarray[i] = (DSP1.parameters[j>>1] & 0xf0) >> 4;
294 pixloc += multiplier;
297 for ( i=0; i < DSP2Op0DOutLen; i++ )
298 DSP1.output[i] = ( pixelarray[i<<1] << 4 ) | pixelarray[(i<<1)+1];
303 #if 0 // Probably no reason to use this code - it's not quite bit accurate and it doesn't look as good as Overload's algorithm
307 // Float implementation of Neviksti's algorithm
308 // This is the right algorithm to match the DSP2 bits but the precision
309 // of the PC float does not match the precision of the fixed point math
310 // on the DSP2 causing occasional one off data mismatches (which should
311 // be no problem because its just a one pixel difference in a scaled image
317 uint8 pixelarray[512];
319 if (DSP2Op0DInLen <= DSP2Op0DOutLen)
320 multiplier = (float) 1.0;
322 multiplier = (float) ((DSP2Op0DInLen * 2.0) / (DSP2Op0DOutLen * 2.0 + 1.0));
325 for ( i=0; i < DSP2Op0DOutLen * 2; i++ )
327 // j = (int)(i * multiplier);
331 pixelarray[i] = DSP1.parameters[j>>1] & 0x0f;
333 pixelarray[i] = (DSP1.parameters[j>>1] & 0xf0) >> 4;
335 pixloc += multiplier; // use an add in the loop instead of multiply to increase loop speed
338 for ( i=0; i < DSP2Op0DOutLen; i++ )
339 DSP1.output[i] = ( pixelarray[i<<1] << 4 ) | pixelarray[(i<<1)+1];