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 *******************************************************************************/
91 uint16 DSP2Op09Word1=0;
92 uint16 DSP2Op09Word2=0;
93 bool DSP2Op05HasLen=false;
95 bool DSP2Op06HasLen=false;
97 uint8 DSP2Op05Transparent=0;
102 // Overlay bitmap with transparency.
105 // Bitmap 1: i[0] <=> i[size-1]
106 // Bitmap 2: i[size] <=> i[2*size-1]
110 // Bitmap 3: o[0] <=> o[size-1]
114 // Process all 4-bit pixels (nibbles) in the bitmap
116 // if ( BM2_pixel == transparent_color )
117 // pixelout = BM1_pixel
119 // pixelout = BM2_pixel
121 // The max size bitmap is limited to 255 because the size parameter is a byte
122 // I think size=0 is an error. The behavior of the chip on size=0 is to
123 // return the last value written to DR if you read DR on Op05 with
124 // size = 0. I don't think it's worth implementing this quirk unless it's
130 unsigned char *p1 = DSP1.parameters;
131 unsigned char *p2 = &DSP1.parameters[DSP2Op05Len];
132 unsigned char *p3 = DSP1.output;
134 color = DSP2Op05Transparent&0x0f;
136 for( n = 0; n < DSP2Op05Len; n++ )
140 *p3++ = ( ((c2 >> 4) == color ) ? c1 & 0xf0: c2 & 0xf0 ) |
141 ( ((c2 & 0x0f)==color) ? c1 & 0x0f: c2 & 0x0f );
147 // Op01 size is always 32 bytes input and output.
148 // The hardware does strange things if you vary the size.
151 unsigned char c0, c1, c2, c3;
152 unsigned char *p1 = DSP1.parameters;
153 unsigned char *p2a = DSP1.output;
154 unsigned char *p2b = &DSP1.output[16]; // halfway
156 // Process 8 blocks of 4 bytes each
158 for ( j = 0; j < 8; j++ )
165 *p2a++ = (c0 & 0x10) << 3 |
174 *p2a++ = (c0 & 0x20) << 2 |
183 *p2b++ = (c0 & 0x40) << 1 |
193 *p2b++ = (c0 & 0x80) |
213 for ( i = 0, j = DSP2Op06Len - 1; i < DSP2Op06Len; i++, j-- )
215 DSP1.output[j] = (DSP1.parameters[i] << 4) | (DSP1.parameters[i] >> 4);
219 bool DSP2Op0DHasLen=false;
220 int DSP2Op0DOutLen=0;
223 #ifndef DSP2_BIT_ACCURRATE_CODE
225 // Scale bitmap based on input length out output length
229 // Overload's algorithm - use this unless doing hardware testing
231 // One note: the HW can do odd byte scaling but since we divide
232 // by two to get the count of bytes this won't work well for
233 // odd byte scaling (in any of the current algorithm implementations).
234 // So far I haven't seen Dungeon Master use it.
235 // If it does we can adjust the parameters and code to work with it
239 uint8 pixelarray[512];
241 for(i=0; i<DSP2Op0DOutLen*2; i++)
243 pixel_offset = (i * DSP2Op0DInLen) / DSP2Op0DOutLen;
244 if ( (pixel_offset&1) == 0 )
245 pixelarray[i] = DSP1.parameters[pixel_offset>>1] >> 4;
247 pixelarray[i] = DSP1.parameters[pixel_offset>>1] & 0x0f;
250 for ( i=0; i < DSP2Op0DOutLen; i++ )
251 DSP1.output[i] = ( pixelarray[i<<1] << 4 ) | pixelarray[(i<<1)+1];
258 // Bit accurate hardware algorithm - uses fixed point math
259 // This should match the DSP2 Op0D output exactly
260 // I wouldn't recommend using this unless you're doing hardware debug.
261 // In some situations it has small visual artifacts that
262 // are not readily apparent on a TV screen but show up clearly
263 // on a monitor. Use Overload's scaling instead.
264 // This is for hardware verification testing.
266 // One note: the HW can do odd byte scaling but since we divide
267 // by two to get the count of bytes this won't work well for
268 // odd byte scaling (in any of the current algorithm implementations).
269 // So far I haven't seen Dungeon Master use it.
270 // If it does we can adjust the parameters and code to work with it
273 uint32 multiplier; // Any size int >= 32-bits
274 uint32 pixloc; // match size of multiplier
276 uint8 pixelarray[512];
278 if (DSP2Op0DInLen <= DSP2Op0DOutLen)
279 multiplier = 0x10000; // In our self defined fixed point 0x10000 == 1
281 multiplier = (DSP2Op0DInLen << 17) / ((DSP2Op0DOutLen<<1) + 1);
284 for ( i=0; i < DSP2Op0DOutLen * 2; i++ )
289 pixelarray[i] = DSP1.parameters[j>>1] & 0x0f;
291 pixelarray[i] = (DSP1.parameters[j>>1] & 0xf0) >> 4;
293 pixloc += multiplier;
296 for ( i=0; i < DSP2Op0DOutLen; i++ )
297 DSP1.output[i] = ( pixelarray[i<<1] << 4 ) | pixelarray[(i<<1)+1];
302 #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
306 // Float implementation of Neviksti's algorithm
307 // This is the right algorithm to match the DSP2 bits but the precision
308 // of the PC float does not match the precision of the fixed point math
309 // on the DSP2 causing occasional one off data mismatches (which should
310 // be no problem because its just a one pixel difference in a scaled image
316 uint8 pixelarray[512];
318 if (DSP2Op0DInLen <= DSP2Op0DOutLen)
319 multiplier = (float) 1.0;
321 multiplier = (float) ((DSP2Op0DInLen * 2.0) / (DSP2Op0DOutLen * 2.0 + 1.0));
324 for ( i=0; i < DSP2Op0DOutLen * 2; i++ )
326 // j = (int)(i * multiplier);
330 pixelarray[i] = DSP1.parameters[j>>1] & 0x0f;
332 pixelarray[i] = (DSP1.parameters[j>>1] & 0xf0) >> 4;
334 pixloc += multiplier; // use an add in the loop instead of multiply to increase loop speed
337 for ( i=0; i < DSP2Op0DOutLen; i++ )
338 DSP1.output[i] = ( pixelarray[i<<1] << 4 ) | pixelarray[(i<<1)+1];