Path: blob/main/misc/emulator/xnes/snes9x/dsp1.cpp
28515 views
/***********************************************************************************1Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.23(c) Copyright 1996 - 2002 Gary Henderson ([email protected]),4Jerremy Koot ([email protected])56(c) Copyright 2002 - 2004 Matthew Kendora78(c) Copyright 2002 - 2005 Peter Bortas ([email protected])910(c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/)1112(c) Copyright 2001 - 2006 John Weidman ([email protected])1314(c) Copyright 2002 - 2006 funkyass ([email protected]),15Kris Bleakley ([email protected])1617(c) Copyright 2002 - 2010 Brad Jorsch ([email protected]),18Nach ([email protected]),1920(c) Copyright 2002 - 2011 zones ([email protected])2122(c) Copyright 2006 - 2007 nitsuja2324(c) Copyright 2009 - 2011 BearOso,25OV2262728BS-X C emulator code29(c) Copyright 2005 - 2006 Dreamer Nom,30zones3132C4 x86 assembler and some C emulation code33(c) Copyright 2000 - 2003 _Demo_ ([email protected]),34Nach,35zsKnight ([email protected])3637C4 C++ code38(c) Copyright 2003 - 2006 Brad Jorsch,39Nach4041DSP-1 emulator code42(c) Copyright 1998 - 2006 _Demo_,43Andreas Naive ([email protected]),44Gary Henderson,45Ivar ([email protected]),46John Weidman,47Kris Bleakley,48Matthew Kendora,49Nach,50neviksti ([email protected])5152DSP-2 emulator code53(c) Copyright 2003 John Weidman,54Kris Bleakley,55Lord Nightmare ([email protected]),56Matthew Kendora,57neviksti5859DSP-3 emulator code60(c) Copyright 2003 - 2006 John Weidman,61Kris Bleakley,62Lancer,63z80 gaiden6465DSP-4 emulator code66(c) Copyright 2004 - 2006 Dreamer Nom,67John Weidman,68Kris Bleakley,69Nach,70z80 gaiden7172OBC1 emulator code73(c) Copyright 2001 - 2004 zsKnight,74pagefault ([email protected]),75Kris Bleakley76Ported from x86 assembler to C by sanmaiwashi7778SPC7110 and RTC C++ emulator code used in 1.39-1.5179(c) Copyright 2002 Matthew Kendora with research by80zsKnight,81John Weidman,82Dark Force8384SPC7110 and RTC C++ emulator code used in 1.52+85(c) Copyright 2009 byuu,86neviksti8788S-DD1 C emulator code89(c) Copyright 2003 Brad Jorsch with research by90Andreas Naive,91John Weidman9293S-RTC C emulator code94(c) Copyright 2001 - 2006 byuu,95John Weidman9697ST010 C++ emulator code98(c) Copyright 2003 Feather,99John Weidman,100Kris Bleakley,101Matthew Kendora102103Super FX x86 assembler emulator code104(c) Copyright 1998 - 2003 _Demo_,105pagefault,106zsKnight107108Super FX C emulator code109(c) Copyright 1997 - 1999 Ivar,110Gary Henderson,111John Weidman112113Sound emulator code used in 1.5-1.51114(c) Copyright 1998 - 2003 Brad Martin115(c) Copyright 1998 - 2006 Charles Bilyue'116117Sound emulator code used in 1.52+118(c) Copyright 2004 - 2007 Shay Green ([email protected])119120SH assembler code partly based on x86 assembler code121(c) Copyright 2002 - 2004 Marcus Comstedt ([email protected])1221232xSaI filter124(c) Copyright 1999 - 2001 Derek Liauw Kie Fa125126HQ2x, HQ3x, HQ4x filters127(c) Copyright 2003 Maxim Stepin ([email protected])128129NTSC filter130(c) Copyright 2006 - 2007 Shay Green131132GTK+ GUI code133(c) Copyright 2004 - 2011 BearOso134135Win32 GUI code136(c) Copyright 2003 - 2006 blip,137funkyass,138Matthew Kendora,139Nach,140nitsuja141(c) Copyright 2009 - 2011 OV2142143Mac OS GUI code144(c) Copyright 1998 - 2001 John Stiles145(c) Copyright 2001 - 2011 zones146147148Specific ports contains the works of other authors. See headers in149individual files.150151152Snes9x homepage: http://www.snes9x.com/153154Permission to use, copy, modify and/or distribute Snes9x in both binary155and source form, for non-commercial purposes, is hereby granted without156fee, providing that this license information and copyright notice appear157with all copies and any derived work.158159This software is provided 'as-is', without any express or implied160warranty. In no event shall the authors be held liable for any damages161arising from the use of this software or it's derivatives.162163Snes9x is freeware for PERSONAL USE only. Commercial users should164seek permission of the copyright holders first. Commercial use includes,165but is not limited to, charging money for Snes9x or software derived from166Snes9x, including Snes9x or derivatives in commercial game bundles, and/or167using Snes9x as a promotion for your commercial product.168169The copyright holders request that bug fixes and improvements to the code170should be forwarded to them so everyone can benefit from the modifications171in future versions.172173Super NES and Super Nintendo Entertainment System are trademarks of174Nintendo Co., Limited and its subsidiary companies.175***********************************************************************************/176177/*178Copyright (C) 1997-2006 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )179180http://www.zsnes.com181http://sourceforge.net/projects/zsnes182183This program is free software; you can redistribute it and/or184modify it under the terms of the GNU General Public License185version 2 as published by the Free Software Foundation.186187This program is distributed in the hope that it will be useful,188but WITHOUT ANY WARRANTY; without even the implied warranty of189MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the190GNU General Public License for more details.191192You should have received a copy of the GNU General Public License193along with this program; if not, write to the Free Software194Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.195*/196197198#include "snes9x.h"199#include "memmap.h"200201#ifdef DEBUGGER202//#define DebugDSP1203#endif204205#ifdef DebugDSP1206#include <stdarg.h>207static FILE *LogFile = NULL;208#endif209210static const uint16 DSP1ROM[1024] =211{2120x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,2130x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,2140x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,2150x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,2160x0000, 0x0000, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020,2170x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000,2180x4000, 0x7fff, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200,2190x0100, 0x0080, 0x0040, 0x0020, 0x0001, 0x0008, 0x0004, 0x0002,2200x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,2210x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,2220x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,2230x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,2240x0000, 0x0000, 0x8000, 0xffe5, 0x0100, 0x7fff, 0x7f02, 0x7e08,2250x7d12, 0x7c1f, 0x7b30, 0x7a45, 0x795d, 0x7878, 0x7797, 0x76ba,2260x75df, 0x7507, 0x7433, 0x7361, 0x7293, 0x71c7, 0x70fe, 0x7038,2270x6f75, 0x6eb4, 0x6df6, 0x6d3a, 0x6c81, 0x6bca, 0x6b16, 0x6a64,2280x69b4, 0x6907, 0x685b, 0x67b2, 0x670b, 0x6666, 0x65c4, 0x6523,2290x6484, 0x63e7, 0x634c, 0x62b3, 0x621c, 0x6186, 0x60f2, 0x6060,2300x5fd0, 0x5f41, 0x5eb5, 0x5e29, 0x5d9f, 0x5d17, 0x5c91, 0x5c0c,2310x5b88, 0x5b06, 0x5a85, 0x5a06, 0x5988, 0x590b, 0x5890, 0x5816,2320x579d, 0x5726, 0x56b0, 0x563b, 0x55c8, 0x5555, 0x54e4, 0x5474,2330x5405, 0x5398, 0x532b, 0x52bf, 0x5255, 0x51ec, 0x5183, 0x511c,2340x50b6, 0x5050, 0x4fec, 0x4f89, 0x4f26, 0x4ec5, 0x4e64, 0x4e05,2350x4da6, 0x4d48, 0x4cec, 0x4c90, 0x4c34, 0x4bda, 0x4b81, 0x4b28,2360x4ad0, 0x4a79, 0x4a23, 0x49cd, 0x4979, 0x4925, 0x48d1, 0x487f,2370x482d, 0x47dc, 0x478c, 0x473c, 0x46ed, 0x469f, 0x4651, 0x4604,2380x45b8, 0x456c, 0x4521, 0x44d7, 0x448d, 0x4444, 0x43fc, 0x43b4,2390x436d, 0x4326, 0x42e0, 0x429a, 0x4255, 0x4211, 0x41cd, 0x4189,2400x4146, 0x4104, 0x40c2, 0x4081, 0x4040, 0x3fff, 0x41f7, 0x43e1,2410x45bd, 0x478d, 0x4951, 0x4b0b, 0x4cbb, 0x4e61, 0x4fff, 0x5194,2420x5322, 0x54a9, 0x5628, 0x57a2, 0x5914, 0x5a81, 0x5be9, 0x5d4a,2430x5ea7, 0x5fff, 0x6152, 0x62a0, 0x63ea, 0x6530, 0x6672, 0x67b0,2440x68ea, 0x6a20, 0x6b53, 0x6c83, 0x6daf, 0x6ed9, 0x6fff, 0x7122,2450x7242, 0x735f, 0x747a, 0x7592, 0x76a7, 0x77ba, 0x78cb, 0x79d9,2460x7ae5, 0x7bee, 0x7cf5, 0x7dfa, 0x7efe, 0x7fff, 0x0000, 0x0324,2470x0647, 0x096a, 0x0c8b, 0x0fab, 0x12c8, 0x15e2, 0x18f8, 0x1c0b,2480x1f19, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11, 0x30fb, 0x33de,2490x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a, 0x471c, 0x49b4,2500x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842, 0x5a82, 0x5cb4,2510x5ed7, 0x60ec, 0x62f2, 0x64e8, 0x66cf, 0x68a6, 0x6a6d, 0x6c24,2520x6dca, 0x6f5f, 0x70e2, 0x7255, 0x73b5, 0x7504, 0x7641, 0x776c,2530x7884, 0x798a, 0x7a7d, 0x7b5d, 0x7c29, 0x7ce3, 0x7d8a, 0x7e1d,2540x7e9d, 0x7f09, 0x7f62, 0x7fa7, 0x7fd8, 0x7ff6, 0x7fff, 0x7ff6,2550x7fd8, 0x7fa7, 0x7f62, 0x7f09, 0x7e9d, 0x7e1d, 0x7d8a, 0x7ce3,2560x7c29, 0x7b5d, 0x7a7d, 0x798a, 0x7884, 0x776c, 0x7641, 0x7504,2570x73b5, 0x7255, 0x70e2, 0x6f5f, 0x6dca, 0x6c24, 0x6a6d, 0x68a6,2580x66cf, 0x64e8, 0x62f2, 0x60ec, 0x5ed7, 0x5cb4, 0x5a82, 0x5842,2590x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4, 0x471c, 0x447a,2600x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33de, 0x30fb, 0x2e11,2610x2b1f, 0x2826, 0x2528, 0x2223, 0x1f19, 0x1c0b, 0x18f8, 0x15e2,2620x12c8, 0x0fab, 0x0c8b, 0x096a, 0x0647, 0x0324, 0x7fff, 0x7ff6,2630x7fd8, 0x7fa7, 0x7f62, 0x7f09, 0x7e9d, 0x7e1d, 0x7d8a, 0x7ce3,2640x7c29, 0x7b5d, 0x7a7d, 0x798a, 0x7884, 0x776c, 0x7641, 0x7504,2650x73b5, 0x7255, 0x70e2, 0x6f5f, 0x6dca, 0x6c24, 0x6a6d, 0x68a6,2660x66cf, 0x64e8, 0x62f2, 0x60ec, 0x5ed7, 0x5cb4, 0x5a82, 0x5842,2670x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4, 0x471c, 0x447a,2680x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33de, 0x30fb, 0x2e11,2690x2b1f, 0x2826, 0x2528, 0x2223, 0x1f19, 0x1c0b, 0x18f8, 0x15e2,2700x12c8, 0x0fab, 0x0c8b, 0x096a, 0x0647, 0x0324, 0x0000, 0xfcdc,2710xf9b9, 0xf696, 0xf375, 0xf055, 0xed38, 0xea1e, 0xe708, 0xe3f5,2720xe0e7, 0xdddd, 0xdad8, 0xd7da, 0xd4e1, 0xd1ef, 0xcf05, 0xcc22,2730xc946, 0xc674, 0xc3aa, 0xc0e9, 0xbe32, 0xbb86, 0xb8e4, 0xb64c,2740xb3c1, 0xb141, 0xaecd, 0xac65, 0xaa0b, 0xa7be, 0xa57e, 0xa34c,2750xa129, 0x9f14, 0x9d0e, 0x9b18, 0x9931, 0x975a, 0x9593, 0x93dc,2760x9236, 0x90a1, 0x8f1e, 0x8dab, 0x8c4b, 0x8afc, 0x89bf, 0x8894,2770x877c, 0x8676, 0x8583, 0x84a3, 0x83d7, 0x831d, 0x8276, 0x81e3,2780x8163, 0x80f7, 0x809e, 0x8059, 0x8028, 0x800a, 0x6488, 0x0080,2790x03ff, 0x0116, 0x0002, 0x0080, 0x4000, 0x3fd7, 0x3faf, 0x3f86,2800x3f5d, 0x3f34, 0x3f0c, 0x3ee3, 0x3eba, 0x3e91, 0x3e68, 0x3e40,2810x3e17, 0x3dee, 0x3dc5, 0x3d9c, 0x3d74, 0x3d4b, 0x3d22, 0x3cf9,2820x3cd0, 0x3ca7, 0x3c7f, 0x3c56, 0x3c2d, 0x3c04, 0x3bdb, 0x3bb2,2830x3b89, 0x3b60, 0x3b37, 0x3b0e, 0x3ae5, 0x3abc, 0x3a93, 0x3a69,2840x3a40, 0x3a17, 0x39ee, 0x39c5, 0x399c, 0x3972, 0x3949, 0x3920,2850x38f6, 0x38cd, 0x38a4, 0x387a, 0x3851, 0x3827, 0x37fe, 0x37d4,2860x37aa, 0x3781, 0x3757, 0x372d, 0x3704, 0x36da, 0x36b0, 0x3686,2870x365c, 0x3632, 0x3609, 0x35df, 0x35b4, 0x358a, 0x3560, 0x3536,2880x350c, 0x34e1, 0x34b7, 0x348d, 0x3462, 0x3438, 0x340d, 0x33e3,2890x33b8, 0x338d, 0x3363, 0x3338, 0x330d, 0x32e2, 0x32b7, 0x328c,2900x3261, 0x3236, 0x320b, 0x31df, 0x31b4, 0x3188, 0x315d, 0x3131,2910x3106, 0x30da, 0x30ae, 0x3083, 0x3057, 0x302b, 0x2fff, 0x2fd2,2920x2fa6, 0x2f7a, 0x2f4d, 0x2f21, 0x2ef4, 0x2ec8, 0x2e9b, 0x2e6e,2930x2e41, 0x2e14, 0x2de7, 0x2dba, 0x2d8d, 0x2d60, 0x2d32, 0x2d05,2940x2cd7, 0x2ca9, 0x2c7b, 0x2c4d, 0x2c1f, 0x2bf1, 0x2bc3, 0x2b94,2950x2b66, 0x2b37, 0x2b09, 0x2ada, 0x2aab, 0x2a7c, 0x2a4c, 0x2a1d,2960x29ed, 0x29be, 0x298e, 0x295e, 0x292e, 0x28fe, 0x28ce, 0x289d,2970x286d, 0x283c, 0x280b, 0x27da, 0x27a9, 0x2777, 0x2746, 0x2714,2980x26e2, 0x26b0, 0x267e, 0x264c, 0x2619, 0x25e7, 0x25b4, 0x2581,2990x254d, 0x251a, 0x24e6, 0x24b2, 0x247e, 0x244a, 0x2415, 0x23e1,3000x23ac, 0x2376, 0x2341, 0x230b, 0x22d6, 0x229f, 0x2269, 0x2232,3010x21fc, 0x21c4, 0x218d, 0x2155, 0x211d, 0x20e5, 0x20ad, 0x2074,3020x203b, 0x2001, 0x1fc7, 0x1f8d, 0x1f53, 0x1f18, 0x1edd, 0x1ea1,3030x1e66, 0x1e29, 0x1ded, 0x1db0, 0x1d72, 0x1d35, 0x1cf6, 0x1cb8,3040x1c79, 0x1c39, 0x1bf9, 0x1bb8, 0x1b77, 0x1b36, 0x1af4, 0x1ab1,3050x1a6e, 0x1a2a, 0x19e6, 0x19a1, 0x195c, 0x1915, 0x18ce, 0x1887,3060x183f, 0x17f5, 0x17ac, 0x1761, 0x1715, 0x16c9, 0x167c, 0x162e,3070x15df, 0x158e, 0x153d, 0x14eb, 0x1497, 0x1442, 0x13ec, 0x1395,3080x133c, 0x12e2, 0x1286, 0x1228, 0x11c9, 0x1167, 0x1104, 0x109e,3090x1036, 0x0fcc, 0x0f5f, 0x0eef, 0x0e7b, 0x0e04, 0x0d89, 0x0d0a,3100x0c86, 0x0bfd, 0x0b6d, 0x0ad6, 0x0a36, 0x098d, 0x08d7, 0x0811,3110x0736, 0x063e, 0x0519, 0x039a, 0x0000, 0x7fff, 0x0100, 0x0080,3120x021d, 0x00c8, 0x00ce, 0x0048, 0x0a26, 0x277a, 0x00ce, 0x6488,3130x14ac, 0x0001, 0x00f9, 0x00fc, 0x00ff, 0x00fc, 0x00f9, 0xffff,3140xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3150xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3160xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3170xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3180xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3190xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3200xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3210xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3220xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3230xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3240xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3250xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3260xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3270xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3280xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3290xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3300xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3310xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3320xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3330xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3340xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3350xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3360xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3370xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3380xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,3390xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff340};341342static const int16 DSP1_MulTable[256] =343{3440x0000, 0x0003, 0x0006, 0x0009, 0x000c, 0x000f, 0x0012, 0x0015,3450x0019, 0x001c, 0x001f, 0x0022, 0x0025, 0x0028, 0x002b, 0x002f,3460x0032, 0x0035, 0x0038, 0x003b, 0x003e, 0x0041, 0x0045, 0x0048,3470x004b, 0x004e, 0x0051, 0x0054, 0x0057, 0x005b, 0x005e, 0x0061,3480x0064, 0x0067, 0x006a, 0x006d, 0x0071, 0x0074, 0x0077, 0x007a,3490x007d, 0x0080, 0x0083, 0x0087, 0x008a, 0x008d, 0x0090, 0x0093,3500x0096, 0x0099, 0x009d, 0x00a0, 0x00a3, 0x00a6, 0x00a9, 0x00ac,3510x00af, 0x00b3, 0x00b6, 0x00b9, 0x00bc, 0x00bf, 0x00c2, 0x00c5,3520x00c9, 0x00cc, 0x00cf, 0x00d2, 0x00d5, 0x00d8, 0x00db, 0x00df,3530x00e2, 0x00e5, 0x00e8, 0x00eb, 0x00ee, 0x00f1, 0x00f5, 0x00f8,3540x00fb, 0x00fe, 0x0101, 0x0104, 0x0107, 0x010b, 0x010e, 0x0111,3550x0114, 0x0117, 0x011a, 0x011d, 0x0121, 0x0124, 0x0127, 0x012a,3560x012d, 0x0130, 0x0133, 0x0137, 0x013a, 0x013d, 0x0140, 0x0143,3570x0146, 0x0149, 0x014d, 0x0150, 0x0153, 0x0156, 0x0159, 0x015c,3580x015f, 0x0163, 0x0166, 0x0169, 0x016c, 0x016f, 0x0172, 0x0175,3590x0178, 0x017c, 0x017f, 0x0182, 0x0185, 0x0188, 0x018b, 0x018e,3600x0192, 0x0195, 0x0198, 0x019b, 0x019e, 0x01a1, 0x01a4, 0x01a8,3610x01ab, 0x01ae, 0x01b1, 0x01b4, 0x01b7, 0x01ba, 0x01be, 0x01c1,3620x01c4, 0x01c7, 0x01ca, 0x01cd, 0x01d0, 0x01d4, 0x01d7, 0x01da,3630x01dd, 0x01e0, 0x01e3, 0x01e6, 0x01ea, 0x01ed, 0x01f0, 0x01f3,3640x01f6, 0x01f9, 0x01fc, 0x0200, 0x0203, 0x0206, 0x0209, 0x020c,3650x020f, 0x0212, 0x0216, 0x0219, 0x021c, 0x021f, 0x0222, 0x0225,3660x0228, 0x022c, 0x022f, 0x0232, 0x0235, 0x0238, 0x023b, 0x023e,3670x0242, 0x0245, 0x0248, 0x024b, 0x024e, 0x0251, 0x0254, 0x0258,3680x025b, 0x025e, 0x0261, 0x0264, 0x0267, 0x026a, 0x026e, 0x0271,3690x0274, 0x0277, 0x027a, 0x027d, 0x0280, 0x0284, 0x0287, 0x028a,3700x028d, 0x0290, 0x0293, 0x0296, 0x029a, 0x029d, 0x02a0, 0x02a3,3710x02a6, 0x02a9, 0x02ac, 0x02b0, 0x02b3, 0x02b6, 0x02b9, 0x02bc,3720x02bf, 0x02c2, 0x02c6, 0x02c9, 0x02cc, 0x02cf, 0x02d2, 0x02d5,3730x02d8, 0x02db, 0x02df, 0x02e2, 0x02e5, 0x02e8, 0x02eb, 0x02ee,3740x02f1, 0x02f5, 0x02f8, 0x02fb, 0x02fe, 0x0301, 0x0304, 0x0307,3750x030b, 0x030e, 0x0311, 0x0314, 0x0317, 0x031a, 0x031d, 0x0321376};377378static const int16 DSP1_SinTable[256] =379{3800x0000, 0x0324, 0x0647, 0x096a, 0x0c8b, 0x0fab, 0x12c8, 0x15e2,3810x18f8, 0x1c0b, 0x1f19, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11,3820x30fb, 0x33de, 0x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a,3830x471c, 0x49b4, 0x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842,3840x5a82, 0x5cb4, 0x5ed7, 0x60ec, 0x62f2, 0x64e8, 0x66cf, 0x68a6,3850x6a6d, 0x6c24, 0x6dca, 0x6f5f, 0x70e2, 0x7255, 0x73b5, 0x7504,3860x7641, 0x776c, 0x7884, 0x798a, 0x7a7d, 0x7b5d, 0x7c29, 0x7ce3,3870x7d8a, 0x7e1d, 0x7e9d, 0x7f09, 0x7f62, 0x7fa7, 0x7fd8, 0x7ff6,3880x7fff, 0x7ff6, 0x7fd8, 0x7fa7, 0x7f62, 0x7f09, 0x7e9d, 0x7e1d,3890x7d8a, 0x7ce3, 0x7c29, 0x7b5d, 0x7a7d, 0x798a, 0x7884, 0x776c,3900x7641, 0x7504, 0x73b5, 0x7255, 0x70e2, 0x6f5f, 0x6dca, 0x6c24,3910x6a6d, 0x68a6, 0x66cf, 0x64e8, 0x62f2, 0x60ec, 0x5ed7, 0x5cb4,3920x5a82, 0x5842, 0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4,3930x471c, 0x447a, 0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33de,3940x30fb, 0x2e11, 0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f19, 0x1c0b,3950x18f8, 0x15e2, 0x12c8, 0x0fab, 0x0c8b, 0x096a, 0x0647, 0x0324,396-0x0000, -0x0324, -0x0647, -0x096a, -0x0c8b, -0x0fab, -0x12c8, -0x15e2,397-0x18f8, -0x1c0b, -0x1f19, -0x2223, -0x2528, -0x2826, -0x2b1f, -0x2e11,398-0x30fb, -0x33de, -0x36ba, -0x398c, -0x3c56, -0x3f17, -0x41ce, -0x447a,399-0x471c, -0x49b4, -0x4c3f, -0x4ebf, -0x5133, -0x539b, -0x55f5, -0x5842,400-0x5a82, -0x5cb4, -0x5ed7, -0x60ec, -0x62f2, -0x64e8, -0x66cf, -0x68a6,401-0x6a6d, -0x6c24, -0x6dca, -0x6f5f, -0x70e2, -0x7255, -0x73b5, -0x7504,402-0x7641, -0x776c, -0x7884, -0x798a, -0x7a7d, -0x7b5d, -0x7c29, -0x7ce3,403-0x7d8a, -0x7e1d, -0x7e9d, -0x7f09, -0x7f62, -0x7fa7, -0x7fd8, -0x7ff6,404-0x7fff, -0x7ff6, -0x7fd8, -0x7fa7, -0x7f62, -0x7f09, -0x7e9d, -0x7e1d,405-0x7d8a, -0x7ce3, -0x7c29, -0x7b5d, -0x7a7d, -0x798a, -0x7884, -0x776c,406-0x7641, -0x7504, -0x73b5, -0x7255, -0x70e2, -0x6f5f, -0x6dca, -0x6c24,407-0x6a6d, -0x68a6, -0x66cf, -0x64e8, -0x62f2, -0x60ec, -0x5ed7, -0x5cb4,408-0x5a82, -0x5842, -0x55f5, -0x539b, -0x5133, -0x4ebf, -0x4c3f, -0x49b4,409-0x471c, -0x447a, -0x41ce, -0x3f17, -0x3c56, -0x398c, -0x36ba, -0x33de,410-0x30fb, -0x2e11, -0x2b1f, -0x2826, -0x2528, -0x2223, -0x1f19, -0x1c0b,411-0x18f8, -0x15e2, -0x12c8, -0x0fab, -0x0c8b, -0x096a, -0x0647, -0x0324412};413414415#ifdef DebugDSP1416417static void Log_Message (const char *Message, ...)418{419char Msg[400];420va_list ap;421size_t ignore;422423va_start(ap, Message);424vsprintf(Msg, Message, ap);425va_end(ap);426427strcat(Msg, "\r\n\0");428ignore = fwrite(Msg, strlen(Msg), 1, LogFile);429fflush(LogFile);430}431432static void Start_Log (void)433{434LogFile = fopen("dsp1emu.log", "wb");435}436437static void Stop_Log (void)438{439if (LogFile)440{441fclose(LogFile);442LogFile = NULL;443}444}445446#endif447448static void DSP1_Op00 (void)449{450DSP1.Op00Result = DSP1.Op00Multiplicand * DSP1.Op00Multiplier >> 15;451452#ifdef DebugDSP1453Log_Message("OP00 MULT %d*%d/32768=%d", DSP1.Op00Multiplicand, DSP1.Op00Multiplier, DSP1.Op00Result);454#endif455}456457static void DSP1_Op20 (void)458{459DSP1.Op20Result = DSP1.Op20Multiplicand * DSP1.Op20Multiplier >> 15;460DSP1.Op20Result++;461462#ifdef DebugDSP1463Log_Message("OP20 MULT %d*%d/32768=%d", DSP1.Op20Multiplicand, DSP1.Op20Multiplier, DSP1.Op20Result);464#endif465}466467static void DSP1_Inverse (int16 Coefficient, int16 Exponent, int16 *iCoefficient, int16 *iExponent)468{469// Step One: Division by Zero470if (Coefficient == 0x0000)471{472*iCoefficient = 0x7fff;473*iExponent = 0x002f;474}475else476{477int16 Sign = 1;478479// Step Two: Remove Sign480if (Coefficient < 0)481{482if (Coefficient < -32767)483Coefficient = -32767;484Coefficient = -Coefficient;485Sign = -1;486}487488// Step Three: Normalize489while (Coefficient < 0x4000)490{491Coefficient <<= 1;492Exponent--;493}494495// Step Four: Special Case496if (Coefficient == 0x4000)497{498if (Sign == 1)499*iCoefficient = 0x7fff;500else501{502*iCoefficient = -0x4000;503Exponent--;504}505}506else507{508// Step Five: Initial Guess509int16 i = DSP1ROM[((Coefficient - 0x4000) >> 7) + 0x0065];510511// Step Six: Iterate "estimated" Newton's Method512i = (i + (-i * (Coefficient * i >> 15) >> 15)) << 1;513i = (i + (-i * (Coefficient * i >> 15) >> 15)) << 1;514515*iCoefficient = i * Sign;516}517518*iExponent = 1 - Exponent;519}520}521522static void DSP1_Op10 (void)523{524DSP1_Inverse(DSP1.Op10Coefficient, DSP1.Op10Exponent, &DSP1.Op10CoefficientR, &DSP1.Op10ExponentR);525526#ifdef DebugDSP1527Log_Message("OP10 INV %d*2^%d = %d*2^%d", DSP1.Op10Coefficient, DSP1.Op10Exponent, DSP1.Op10CoefficientR, DSP1.Op10ExponentR);528#endif529}530531static int16 DSP1_Sin (int16 Angle)532{533int32 S;534535if (Angle < 0)536{537if (Angle == -32768)538return (0);539540return (-DSP1_Sin(-Angle));541}542543S = DSP1_SinTable[Angle >> 8] + (DSP1_MulTable[Angle & 0xff] * DSP1_SinTable[0x40 + (Angle >> 8)] >> 15);544if (S > 32767)545S = 32767;546547return ((int16) S);548}549550static int16 DSP1_Cos (int16 Angle)551{552int32 S;553554if (Angle < 0)555{556if (Angle == -32768)557return (-32768);558559Angle = -Angle;560}561562S = DSP1_SinTable[0x40 + (Angle >> 8)] - (DSP1_MulTable[Angle & 0xff] * DSP1_SinTable[Angle >> 8] >> 15);563if (S < -32768)564S = -32767;565566return ((int16) S);567}568569static void DSP1_Normalize (int16 m, int16 *Coefficient, int16 *Exponent)570{571int16 i = 0x4000;572int16 e = 0;573574if (m < 0)575{576while ((m & i) && i)577{578i >>= 1;579e++;580}581}582else583{584while (!(m & i) && i)585{586i >>= 1;587e++;588}589}590591if (e > 0)592*Coefficient = m * DSP1ROM[0x21 + e] << 1;593else594*Coefficient = m;595596*Exponent -= e;597}598599static void DSP1_NormalizeDouble (int32 Product, int16 *Coefficient, int16 *Exponent)600{601int16 n = Product & 0x7fff;602int16 m = Product >> 15;603int16 i = 0x4000;604int16 e = 0;605606if (m < 0)607{608while ((m & i) && i)609{610i >>= 1;611e++;612}613}614else615{616while (!(m & i) && i)617{618i >>= 1;619e++;620}621}622623if (e > 0)624{625*Coefficient = m * DSP1ROM[0x0021 + e] << 1;626627if (e < 15)628*Coefficient += n * DSP1ROM[0x0040 - e] >> 15;629else630{631i = 0x4000;632633if (m < 0)634{635while ((n & i) && i)636{637i >>= 1;638e++;639}640}641else642{643while (!(n & i) && i)644{645i >>= 1;646e++;647}648}649650if (e > 15)651*Coefficient = n * DSP1ROM[0x0012 + e] << 1;652else653*Coefficient += n;654}655}656else657*Coefficient = m;658659*Exponent = e;660}661662static int16 DSP1_Truncate (int16 C, int16 E)663{664if (E > 0)665{666if (C > 0)667return (32767);668else669if (C < 0)670return (-32767);671}672else673{674if (E < 0)675return (C * DSP1ROM[0x0031 + E] >> 15);676}677678return (C);679}680681static void DSP1_Op04 (void)682{683DSP1.Op04Sin = DSP1_Sin(DSP1.Op04Angle) * DSP1.Op04Radius >> 15;684DSP1.Op04Cos = DSP1_Cos(DSP1.Op04Angle) * DSP1.Op04Radius >> 15;685}686687static void DSP1_Op0C (void)688{689DSP1.Op0CX2 = (DSP1.Op0CY1 * DSP1_Sin(DSP1.Op0CA) >> 15) + (DSP1.Op0CX1 * DSP1_Cos(DSP1.Op0CA) >> 15);690DSP1.Op0CY2 = (DSP1.Op0CY1 * DSP1_Cos(DSP1.Op0CA) >> 15) - (DSP1.Op0CX1 * DSP1_Sin(DSP1.Op0CA) >> 15);691}692693static void DSP1_Parameter (int16 Fx, int16 Fy, int16 Fz, int16 Lfe, int16 Les, int16 Aas, int16 Azs, int16 *Vof, int16 *Vva, int16 *Cx, int16 *Cy)694{695const int16 MaxAZS_Exp[16] =696{6970x38b4, 0x38b7, 0x38ba, 0x38be, 0x38c0, 0x38c4, 0x38c7, 0x38ca,6980x38ce, 0x38d0, 0x38d4, 0x38d7, 0x38da, 0x38dd, 0x38e0, 0x38e4699};700701int16 CSec, C, E, MaxAZS, Aux;702int16 LfeNx, LfeNy, LfeNz;703int16 LesNx, LesNy, LesNz;704int16 CentreZ;705706// Copy Zenith angle for clipping707int16 AZS = Azs;708709// Store Sine and Cosine of Azimuth and Zenith angle710DSP1.SinAas = DSP1_Sin(Aas);711DSP1.CosAas = DSP1_Cos(Aas);712DSP1.SinAzs = DSP1_Sin(Azs);713DSP1.CosAzs = DSP1_Cos(Azs);714715DSP1.Nx = DSP1.SinAzs * -DSP1.SinAas >> 15;716DSP1.Ny = DSP1.SinAzs * DSP1.CosAas >> 15;717DSP1.Nz = DSP1.CosAzs * 0x7fff >> 15;718719LfeNx = Lfe * DSP1.Nx >> 15;720LfeNy = Lfe * DSP1.Ny >> 15;721LfeNz = Lfe * DSP1.Nz >> 15;722723// Center of Projection724DSP1.CentreX = Fx + LfeNx;725DSP1.CentreY = Fy + LfeNy;726CentreZ = Fz + LfeNz;727728LesNx = Les * DSP1.Nx >> 15;729LesNy = Les * DSP1.Ny >> 15;730LesNz = Les * DSP1.Nz >> 15;731732DSP1.Gx = DSP1.CentreX - LesNx;733DSP1.Gy = DSP1.CentreY - LesNy;734DSP1.Gz = CentreZ - LesNz;735736DSP1.E_Les = 0;737DSP1_Normalize(Les, &DSP1.C_Les, &DSP1.E_Les);738DSP1.G_Les = Les;739740E = 0;741DSP1_Normalize(CentreZ, &C, &E);742743DSP1.VPlane_C = C;744DSP1.VPlane_E = E;745746// Determine clip boundary and clip Zenith angle if necessary747MaxAZS = MaxAZS_Exp[-E];748749if (AZS < 0)750{751MaxAZS = -MaxAZS;752if (AZS < MaxAZS + 1)753AZS = MaxAZS + 1;754}755else756{757if (AZS > MaxAZS)758AZS = MaxAZS;759}760761// Store Sine and Cosine of clipped Zenith angle762DSP1.SinAZS = DSP1_Sin(AZS);763DSP1.CosAZS = DSP1_Cos(AZS);764765DSP1_Inverse(DSP1.CosAZS, 0, &DSP1.SecAZS_C1, &DSP1.SecAZS_E1);766DSP1_Normalize(C * DSP1.SecAZS_C1 >> 15, &C, &E);767E += DSP1.SecAZS_E1;768769C = DSP1_Truncate(C, E) * DSP1.SinAZS >> 15;770771DSP1.CentreX += C * DSP1.SinAas >> 15;772DSP1.CentreY -= C * DSP1.CosAas >> 15;773774*Cx = DSP1.CentreX;775*Cy = DSP1.CentreY;776777// Raster number of imaginary center and horizontal line778*Vof = 0;779780if ((Azs != AZS) || (Azs == MaxAZS))781{782if (Azs == -32768)783Azs = -32767;784785C = Azs - MaxAZS;786if (C >= 0)787C--;788Aux = ~(C << 2);789790C = Aux * DSP1ROM[0x0328] >> 15;791C = (C * Aux >> 15) + DSP1ROM[0x0327];792*Vof -= (C * Aux >> 15) * Les >> 15;793794C = Aux * Aux >> 15;795Aux = (C * DSP1ROM[0x0324] >> 15) + DSP1ROM[0x0325];796DSP1.CosAZS += (C * Aux >> 15) * DSP1.CosAZS >> 15;797}798799DSP1.VOffset = Les * DSP1.CosAZS >> 15;800801DSP1_Inverse(DSP1.SinAZS, 0, &CSec, &E);802DSP1_Normalize(DSP1.VOffset, &C, &E);803DSP1_Normalize(C * CSec >> 15, &C, &E);804805if (C == -32768)806{807C >>= 1;808E++;809}810811*Vva = DSP1_Truncate(-C, E);812813// Store Secant of clipped Zenith angle814DSP1_Inverse(DSP1.CosAZS, 0, &DSP1.SecAZS_C2, &DSP1.SecAZS_E2);815}816817static void DSP1_Raster (int16 Vs, int16 *An, int16 *Bn, int16 *Cn, int16 *Dn)818{819int16 C, E, C1, E1;820821DSP1_Inverse((Vs * DSP1.SinAzs >> 15) + DSP1.VOffset, 7, &C, &E);822E += DSP1.VPlane_E;823824C1 = C * DSP1.VPlane_C >> 15;825E1 = E + DSP1.SecAZS_E2;826827DSP1_Normalize(C1, &C, &E);828829C = DSP1_Truncate(C, E);830831*An = C * DSP1.CosAas >> 15;832*Cn = C * DSP1.SinAas >> 15;833834DSP1_Normalize(C1 * DSP1.SecAZS_C2 >> 15, &C, &E1);835836C = DSP1_Truncate(C, E1);837838*Bn = C * -DSP1.SinAas >> 15;839*Dn = C * DSP1.CosAas >> 15;840}841842static void DSP1_Op02 (void)843{844DSP1_Parameter(DSP1.Op02FX, DSP1.Op02FY, DSP1.Op02FZ, DSP1.Op02LFE, DSP1.Op02LES, DSP1.Op02AAS, DSP1.Op02AZS, &DSP1.Op02VOF, &DSP1.Op02VVA, &DSP1.Op02CX, &DSP1.Op02CY);845}846847static void DSP1_Op0A (void)848{849DSP1_Raster(DSP1.Op0AVS, &DSP1.Op0AA, &DSP1.Op0AB, &DSP1.Op0AC, &DSP1.Op0AD);850DSP1.Op0AVS++;851}852853static int16 DSP1_ShiftR (int16 C, int16 E)854{855return (C * DSP1ROM[0x0031 + E] >> 15);856}857858static void DSP1_Project (int16 X, int16 Y, int16 Z, int16 *H, int16 *V, int16 *M)859{860int32 aux, aux4;861int16 E, E2, E3, E4, E5, refE, E6, E7;862int16 C2, C4, C6, C8, C9, C10, C11, C12, C16, C17, C18, C19, C20, C21, C22, C23, C24, C25, C26;863int16 Px, Py, Pz;864865E4 = E3 = E2 = E = E5 = 0;866867DSP1_NormalizeDouble((int32) X - DSP1.Gx, &Px, &E4);868DSP1_NormalizeDouble((int32) Y - DSP1.Gy, &Py, &E );869DSP1_NormalizeDouble((int32) Z - DSP1.Gz, &Pz, &E3);870Px >>= 1; // to avoid overflows when calculating the scalar products871E4--;872Py >>= 1;873E--;874Pz >>= 1;875E3--;876877refE = (E < E3) ? E : E3;878refE = (refE < E4) ? refE : E4;879880Px = DSP1_ShiftR(Px, E4 - refE); // normalize them to the same exponent881Py = DSP1_ShiftR(Py, E - refE);882Pz = DSP1_ShiftR(Pz, E3 - refE);883884C11 = -(Px * DSP1.Nx >> 15);885C8 = -(Py * DSP1.Ny >> 15);886C9 = -(Pz * DSP1.Nz >> 15);887C12 = C11 + C8 + C9; // this cannot overflow!888889aux4 = C12; // de-normalization with 32-bits arithmetic890refE = 16 - refE; // refE can be up to 3891if (refE >= 0)892aux4 <<= (refE);893else894aux4 >>= -(refE);895if (aux4 == -1)896aux4 = 0; // why?897aux4 >>= 1;898899aux = ((uint16) DSP1.G_Les) + aux4; // Les - the scalar product of P with the normal vector of the screen900DSP1_NormalizeDouble(aux, &C10, &E2);901E2 = 15 - E2;902903DSP1_Inverse(C10, 0, &C4, &E4);904C2 = C4 * DSP1.C_Les >> 15; // scale factor905906// H907E7 = 0;908C16 = Px * ( DSP1.CosAas * 0x7fff >> 15) >> 15;909C20 = Py * ( DSP1.SinAas * 0x7fff >> 15) >> 15;910C17 = C16 + C20; // scalar product of P with the normalized horizontal vector of the screen...911912C18 = C17 * C2 >> 15; // ... multiplied by the scale factor913DSP1_Normalize(C18, &C19, &E7);914*H = DSP1_Truncate(C19, DSP1.E_Les - E2 + refE + E7);915916// V917E6 = 0;918C21 = Px * ( DSP1.CosAzs * -DSP1.SinAas >> 15) >> 15;919C22 = Py * ( DSP1.CosAzs * DSP1.CosAas >> 15) >> 15;920C23 = Pz * (-DSP1.SinAzs * 0x7fff >> 15) >> 15;921C24 = C21 + C22 + C23; // scalar product of P with the normalized vertical vector of the screen...922923C26 = C24 * C2 >> 15; // ... multiplied by the scale factor924DSP1_Normalize(C26, &C25, &E6);925*V = DSP1_Truncate(C25, DSP1.E_Les - E2 + refE + E6);926927// M928DSP1_Normalize(C2, &C6, &E4);929*M = DSP1_Truncate(C6, E4 + DSP1.E_Les - E2 - 7); // M is the scale factor divided by 2^7930}931932static void DSP1_Op06 (void)933{934DSP1_Project(DSP1.Op06X, DSP1.Op06Y, DSP1.Op06Z, &DSP1.Op06H, &DSP1.Op06V, &DSP1.Op06M);935}936937static void DSP1_Op01 (void)938{939int16 SinAz = DSP1_Sin(DSP1.Op01Zr);940int16 CosAz = DSP1_Cos(DSP1.Op01Zr);941int16 SinAy = DSP1_Sin(DSP1.Op01Yr);942int16 CosAy = DSP1_Cos(DSP1.Op01Yr);943int16 SinAx = DSP1_Sin(DSP1.Op01Xr);944int16 CosAx = DSP1_Cos(DSP1.Op01Xr);945946DSP1.Op01m >>= 1;947948DSP1.matrixA[0][0] = (DSP1.Op01m * CosAz >> 15) * CosAy >> 15;949DSP1.matrixA[0][1] = -((DSP1.Op01m * SinAz >> 15) * CosAy >> 15);950DSP1.matrixA[0][2] = DSP1.Op01m * SinAy >> 15;951952DSP1.matrixA[1][0] = ((DSP1.Op01m * SinAz >> 15) * CosAx >> 15) + (((DSP1.Op01m * CosAz >> 15) * SinAx >> 15) * SinAy >> 15);953DSP1.matrixA[1][1] = ((DSP1.Op01m * CosAz >> 15) * CosAx >> 15) - (((DSP1.Op01m * SinAz >> 15) * SinAx >> 15) * SinAy >> 15);954DSP1.matrixA[1][2] = -((DSP1.Op01m * SinAx >> 15) * CosAy >> 15);955956DSP1.matrixA[2][0] = ((DSP1.Op01m * SinAz >> 15) * SinAx >> 15) - (((DSP1.Op01m * CosAz >> 15) * CosAx >> 15) * SinAy >> 15);957DSP1.matrixA[2][1] = ((DSP1.Op01m * CosAz >> 15) * SinAx >> 15) + (((DSP1.Op01m * SinAz >> 15) * CosAx >> 15) * SinAy >> 15);958DSP1.matrixA[2][2] = (DSP1.Op01m * CosAx >> 15) * CosAy >> 15;959}960961static void DSP1_Op11 (void)962{963int16 SinAz = DSP1_Sin(DSP1.Op11Zr);964int16 CosAz = DSP1_Cos(DSP1.Op11Zr);965int16 SinAy = DSP1_Sin(DSP1.Op11Yr);966int16 CosAy = DSP1_Cos(DSP1.Op11Yr);967int16 SinAx = DSP1_Sin(DSP1.Op11Xr);968int16 CosAx = DSP1_Cos(DSP1.Op11Xr);969970DSP1.Op11m >>= 1;971972DSP1.matrixB[0][0] = (DSP1.Op11m * CosAz >> 15) * CosAy >> 15;973DSP1.matrixB[0][1] = -((DSP1.Op11m * SinAz >> 15) * CosAy >> 15);974DSP1.matrixB[0][2] = DSP1.Op11m * SinAy >> 15;975976DSP1.matrixB[1][0] = ((DSP1.Op11m * SinAz >> 15) * CosAx >> 15) + (((DSP1.Op11m * CosAz >> 15) * SinAx >> 15) * SinAy >> 15);977DSP1.matrixB[1][1] = ((DSP1.Op11m * CosAz >> 15) * CosAx >> 15) - (((DSP1.Op11m * SinAz >> 15) * SinAx >> 15) * SinAy >> 15);978DSP1.matrixB[1][2] = -((DSP1.Op11m * SinAx >> 15) * CosAy >> 15);979980DSP1.matrixB[2][0] = ((DSP1.Op11m * SinAz >> 15) * SinAx >> 15) - (((DSP1.Op11m * CosAz >> 15) * CosAx >> 15) * SinAy >> 15);981DSP1.matrixB[2][1] = ((DSP1.Op11m * CosAz >> 15) * SinAx >> 15) + (((DSP1.Op11m * SinAz >> 15) * CosAx >> 15) * SinAy >> 15);982DSP1.matrixB[2][2] = (DSP1.Op11m * CosAx >> 15) * CosAy >> 15;983}984985static void DSP1_Op21 (void)986{987int16 SinAz = DSP1_Sin(DSP1.Op21Zr);988int16 CosAz = DSP1_Cos(DSP1.Op21Zr);989int16 SinAy = DSP1_Sin(DSP1.Op21Yr);990int16 CosAy = DSP1_Cos(DSP1.Op21Yr);991int16 SinAx = DSP1_Sin(DSP1.Op21Xr);992int16 CosAx = DSP1_Cos(DSP1.Op21Xr);993994DSP1.Op21m >>= 1;995996DSP1.matrixC[0][0] = (DSP1.Op21m * CosAz >> 15) * CosAy >> 15;997DSP1.matrixC[0][1] = -((DSP1.Op21m * SinAz >> 15) * CosAy >> 15);998DSP1.matrixC[0][2] = DSP1.Op21m * SinAy >> 15;9991000DSP1.matrixC[1][0] = ((DSP1.Op21m * SinAz >> 15) * CosAx >> 15) + (((DSP1.Op21m * CosAz >> 15) * SinAx >> 15) * SinAy >> 15);1001DSP1.matrixC[1][1] = ((DSP1.Op21m * CosAz >> 15) * CosAx >> 15) - (((DSP1.Op21m * SinAz >> 15) * SinAx >> 15) * SinAy >> 15);1002DSP1.matrixC[1][2] = -((DSP1.Op21m * SinAx >> 15) * CosAy >> 15);10031004DSP1.matrixC[2][0] = ((DSP1.Op21m * SinAz >> 15) * SinAx >> 15) - (((DSP1.Op21m * CosAz >> 15) * CosAx >> 15) * SinAy >> 15);1005DSP1.matrixC[2][1] = ((DSP1.Op21m * CosAz >> 15) * SinAx >> 15) + (((DSP1.Op21m * SinAz >> 15) * CosAx >> 15) * SinAy >> 15);1006DSP1.matrixC[2][2] = (DSP1.Op21m * CosAx >> 15) * CosAy >> 15;1007}10081009static void DSP1_Op0D (void)1010{1011DSP1.Op0DF = (DSP1.Op0DX * DSP1.matrixA[0][0] >> 15) + (DSP1.Op0DY * DSP1.matrixA[0][1] >> 15) + (DSP1.Op0DZ * DSP1.matrixA[0][2] >> 15);1012DSP1.Op0DL = (DSP1.Op0DX * DSP1.matrixA[1][0] >> 15) + (DSP1.Op0DY * DSP1.matrixA[1][1] >> 15) + (DSP1.Op0DZ * DSP1.matrixA[1][2] >> 15);1013DSP1.Op0DU = (DSP1.Op0DX * DSP1.matrixA[2][0] >> 15) + (DSP1.Op0DY * DSP1.matrixA[2][1] >> 15) + (DSP1.Op0DZ * DSP1.matrixA[2][2] >> 15);10141015#ifdef DebugDSP11016Log_Message("OP0D X: %d Y: %d Z: %d / F: %d L: %d U: %d", DSP1.Op0DX, DSP1.Op0DY, DSP1.Op0DZ, DSP1.Op0DF, DSP1.Op0DL, DSP1.Op0DU);1017#endif1018}10191020static void DSP1_Op1D (void)1021{1022DSP1.Op1DF = (DSP1.Op1DX * DSP1.matrixB[0][0] >> 15) + (DSP1.Op1DY * DSP1.matrixB[0][1] >> 15) + (DSP1.Op1DZ * DSP1.matrixB[0][2] >> 15);1023DSP1.Op1DL = (DSP1.Op1DX * DSP1.matrixB[1][0] >> 15) + (DSP1.Op1DY * DSP1.matrixB[1][1] >> 15) + (DSP1.Op1DZ * DSP1.matrixB[1][2] >> 15);1024DSP1.Op1DU = (DSP1.Op1DX * DSP1.matrixB[2][0] >> 15) + (DSP1.Op1DY * DSP1.matrixB[2][1] >> 15) + (DSP1.Op1DZ * DSP1.matrixB[2][2] >> 15);10251026#ifdef DebugDSP11027Log_Message("OP1D X: %d Y: %d Z: %d / F: %d L: %d U: %d", DSP1.Op1DX, DSP1.Op1DY, DSP1.Op1DZ, DSP1.Op1DF, DSP1.Op1DL, DSP1.Op1DU);1028#endif1029}10301031static void DSP1_Op2D (void)1032{1033DSP1.Op2DF = (DSP1.Op2DX * DSP1.matrixC[0][0] >> 15) + (DSP1.Op2DY * DSP1.matrixC[0][1] >> 15) + (DSP1.Op2DZ * DSP1.matrixC[0][2] >> 15);1034DSP1.Op2DL = (DSP1.Op2DX * DSP1.matrixC[1][0] >> 15) + (DSP1.Op2DY * DSP1.matrixC[1][1] >> 15) + (DSP1.Op2DZ * DSP1.matrixC[1][2] >> 15);1035DSP1.Op2DU = (DSP1.Op2DX * DSP1.matrixC[2][0] >> 15) + (DSP1.Op2DY * DSP1.matrixC[2][1] >> 15) + (DSP1.Op2DZ * DSP1.matrixC[2][2] >> 15);10361037#ifdef DebugDSP11038Log_Message("OP2D X: %d Y: %d Z: %d / F: %d L: %d U: %d", DSP1.Op2DX, DSP1.Op2DY, DSP1.Op2DZ, DSP1.Op2DF, DSP1.Op2DL, DSP1.Op2DU);1039#endif1040}10411042static void DSP1_Op03 (void)1043{1044DSP1.Op03X = (DSP1.Op03F * DSP1.matrixA[0][0] >> 15) + (DSP1.Op03L * DSP1.matrixA[1][0] >> 15) + (DSP1.Op03U * DSP1.matrixA[2][0] >> 15);1045DSP1.Op03Y = (DSP1.Op03F * DSP1.matrixA[0][1] >> 15) + (DSP1.Op03L * DSP1.matrixA[1][1] >> 15) + (DSP1.Op03U * DSP1.matrixA[2][1] >> 15);1046DSP1.Op03Z = (DSP1.Op03F * DSP1.matrixA[0][2] >> 15) + (DSP1.Op03L * DSP1.matrixA[1][2] >> 15) + (DSP1.Op03U * DSP1.matrixA[2][2] >> 15);10471048#ifdef DebugDSP11049Log_Message("OP03 F: %d L: %d U: %d / X: %d Y: %d Z: %d", DSP1.Op03F, DSP1.Op03L, DSP1.Op03U, DSP1.Op03X, DSP1.Op03Y, DSP1.Op03Z);1050#endif1051}10521053static void DSP1_Op13 (void)1054{1055DSP1.Op13X = (DSP1.Op13F * DSP1.matrixB[0][0] >> 15) + (DSP1.Op13L * DSP1.matrixB[1][0] >> 15) + (DSP1.Op13U * DSP1.matrixB[2][0] >> 15);1056DSP1.Op13Y = (DSP1.Op13F * DSP1.matrixB[0][1] >> 15) + (DSP1.Op13L * DSP1.matrixB[1][1] >> 15) + (DSP1.Op13U * DSP1.matrixB[2][1] >> 15);1057DSP1.Op13Z = (DSP1.Op13F * DSP1.matrixB[0][2] >> 15) + (DSP1.Op13L * DSP1.matrixB[1][2] >> 15) + (DSP1.Op13U * DSP1.matrixB[2][2] >> 15);10581059#ifdef DebugDSP11060Log_Message("OP13 F: %d L: %d U: %d / X: %d Y: %d Z: %d", DSP1.Op13F, DSP1.Op13L, DSP1.Op13U, DSP1.Op13X, DSP1.Op13Y, DSP1.Op13Z);1061#endif1062}10631064static void DSP1_Op23 (void)1065{1066DSP1.Op23X = (DSP1.Op23F * DSP1.matrixC[0][0] >> 15) + (DSP1.Op23L * DSP1.matrixC[1][0] >> 15) + (DSP1.Op23U * DSP1.matrixC[2][0] >> 15);1067DSP1.Op23Y = (DSP1.Op23F * DSP1.matrixC[0][1] >> 15) + (DSP1.Op23L * DSP1.matrixC[1][1] >> 15) + (DSP1.Op23U * DSP1.matrixC[2][1] >> 15);1068DSP1.Op23Z = (DSP1.Op23F * DSP1.matrixC[0][2] >> 15) + (DSP1.Op23L * DSP1.matrixC[1][2] >> 15) + (DSP1.Op23U * DSP1.matrixC[2][2] >> 15);10691070#ifdef DebugDSP11071Log_Message("OP23 F: %d L: %d U: %d / X: %d Y: %d Z: %d", DSP1.Op23F, DSP1.Op23L, DSP1.Op23U, DSP1.Op23X, DSP1.Op23Y, DSP1.Op23Z);1072#endif1073}10741075static void DSP1_Op14 (void)1076{1077int16 CSec, ESec, CTan, CSin, C, E;10781079DSP1_Inverse(DSP1_Cos(DSP1.Op14Xr), 0, &CSec, &ESec);10801081// Rotation Around Z1082DSP1_NormalizeDouble(DSP1.Op14U * DSP1_Cos(DSP1.Op14Yr) - DSP1.Op14F * DSP1_Sin(DSP1.Op14Yr), &C, &E);10831084E = ESec - E;10851086DSP1_Normalize(C * CSec >> 15, &C, &E);10871088DSP1.Op14Zrr = DSP1.Op14Zr + DSP1_Truncate(C, E);10891090// Rotation Around X1091DSP1.Op14Xrr = DSP1.Op14Xr + (DSP1.Op14U * DSP1_Sin(DSP1.Op14Yr) >> 15) + (DSP1.Op14F * DSP1_Cos(DSP1.Op14Yr) >> 15);10921093// Rotation Around Y1094DSP1_NormalizeDouble(DSP1.Op14U * DSP1_Cos(DSP1.Op14Yr) + DSP1.Op14F * DSP1_Sin(DSP1.Op14Yr), &C, &E);10951096E = ESec - E;10971098DSP1_Normalize(DSP1_Sin(DSP1.Op14Xr), &CSin, &E);10991100CTan = CSec * CSin >> 15;11011102DSP1_Normalize(-(C * CTan >> 15), &C, &E);11031104DSP1.Op14Yrr = DSP1.Op14Yr + DSP1_Truncate(C, E) + DSP1.Op14L;1105}11061107static void DSP1_Target (int16 H, int16 V, int16 *X, int16 *Y)1108{1109int16 C, E, C1, E1;11101111DSP1_Inverse((V * DSP1.SinAzs >> 15) + DSP1.VOffset, 8, &C, &E);1112E += DSP1.VPlane_E;11131114C1 = C * DSP1.VPlane_C >> 15;1115E1 = E + DSP1.SecAZS_E1;11161117H <<= 8;11181119DSP1_Normalize(C1, &C, &E);11201121C = DSP1_Truncate(C, E) * H >> 15;11221123*X = DSP1.CentreX + (C * DSP1.CosAas >> 15);1124*Y = DSP1.CentreY - (C * DSP1.SinAas >> 15);11251126V <<= 8;11271128DSP1_Normalize(C1 * DSP1.SecAZS_C1 >> 15, &C, &E1);11291130C = DSP1_Truncate(C, E1) * V >> 15;11311132*X += C * -DSP1.SinAas >> 15;1133*Y += C * DSP1.CosAas >> 15;1134}11351136static void DSP1_Op0E (void)1137{1138DSP1_Target(DSP1.Op0EH, DSP1.Op0EV, &DSP1.Op0EX, &DSP1.Op0EY);1139}11401141static void DSP1_Op0B (void)1142{1143DSP1.Op0BS = (DSP1.Op0BX * DSP1.matrixA[0][0] + DSP1.Op0BY * DSP1.matrixA[0][1] + DSP1.Op0BZ * DSP1.matrixA[0][2]) >> 15;11441145#ifdef DebugDSP11146Log_Message("OP0B");1147#endif1148}11491150static void DSP1_Op1B (void)1151{1152DSP1.Op1BS = (DSP1.Op1BX * DSP1.matrixB[0][0] + DSP1.Op1BY * DSP1.matrixB[0][1] + DSP1.Op1BZ * DSP1.matrixB[0][2]) >> 15;11531154#ifdef DebugDSP11155Log_Message("OP1B X: %d Y: %d Z: %d S: %d", DSP1.Op1BX, DSP1.Op1BY, DSP1.Op1BZ, DSP1.Op1BS);1156Log_Message(" MX: %d MY: %d MZ: %d Scale: %d", (int16) (DSP1.matrixB[0][0] * 100), (int16) (DSP1.matrixB[0][1] * 100), (int16) (DSP1.matrixB[0][2] * 100), (int16) (DSP1.Op1BS * 100));1157#endif1158}11591160static void DSP1_Op2B (void)1161{1162DSP1.Op2BS = (DSP1.Op2BX * DSP1.matrixC[0][0] + DSP1.Op2BY * DSP1.matrixC[0][1] + DSP1.Op2BZ * DSP1.matrixC[0][2]) >> 15;11631164#ifdef DebugDSP11165Log_Message("OP2B");1166#endif1167}11681169static void DSP1_Op08 (void)1170{1171int32 op08Size = (DSP1.Op08X * DSP1.Op08X + DSP1.Op08Y * DSP1.Op08Y + DSP1.Op08Z * DSP1.Op08Z) << 1;1172DSP1.Op08Ll = op08Size & 0xffff;1173DSP1.Op08Lh = (op08Size >> 16) & 0xffff;11741175#ifdef DebugDSP11176Log_Message("OP08 %d,%d,%d", DSP1.Op08X, DSP1.Op08Y, DSP1.Op08Z);1177Log_Message("OP08 ((OP08X^2)+(OP08Y^2)+(OP08Z^2))=%x", op08Size);1178#endif1179}11801181static void DSP1_Op18 (void)1182{1183DSP1.Op18D = (DSP1.Op18X * DSP1.Op18X + DSP1.Op18Y * DSP1.Op18Y + DSP1.Op18Z * DSP1.Op18Z - DSP1.Op18R * DSP1.Op18R) >> 15;11841185#ifdef DebugDSP11186Log_Message("OP18 X: %d Y: %d Z: %d R: %D DIFF %d", DSP1.Op18X, DSP1.Op18Y, DSP1.Op38Z, DSP1.Op18D);1187#endif1188}11891190static void DSP1_Op38 (void)1191{1192DSP1.Op38D = (DSP1.Op38X * DSP1.Op38X + DSP1.Op38Y * DSP1.Op38Y + DSP1.Op38Z * DSP1.Op38Z - DSP1.Op38R * DSP1.Op38R) >> 15;1193DSP1.Op38D++;11941195#ifdef DebugDSP11196Log_Message("OP38 X: %d Y: %d Z: %d R: %D DIFF %d", DSP1.Op38X, DSP1.Op38Y, DSP1.Op38Z, DSP1.Op38D);1197#endif1198}11991200static void DSP1_Op28 (void)1201{1202int32 Radius = DSP1.Op28X * DSP1.Op28X + DSP1.Op28Y * DSP1.Op28Y + DSP1.Op28Z * DSP1.Op28Z;12031204if (Radius == 0)1205DSP1.Op28R = 0;1206else1207{1208int16 C, E, Pos, Node1, Node2;12091210DSP1_NormalizeDouble(Radius, &C, &E);1211if (E & 1)1212C = C * 0x4000 >> 15;12131214Pos = C * 0x0040 >> 15;12151216Node1 = DSP1ROM[0x00d5 + Pos];1217Node2 = DSP1ROM[0x00d6 + Pos];12181219DSP1.Op28R = ((Node2 - Node1) * (C & 0x1ff) >> 9) + Node1;1220DSP1.Op28R >>= (E >> 1);1221}12221223#ifdef DebugDSP11224Log_Message("OP28 X:%d Y:%d Z:%d", DSP1.Op28X, DSP1.Op28Y, DSP1.Op28Z);1225Log_Message("OP28 Vector Length %d", DSP1.Op28R);1226#endif1227}12281229static void DSP1_Op1C (void)1230{1231// Rotate Around Op1CZ11232DSP1.Op1CX1 = (DSP1.Op1CYBR * DSP1_Sin(DSP1.Op1CZ) >> 15) + (DSP1.Op1CXBR * DSP1_Cos(DSP1.Op1CZ) >> 15);1233DSP1.Op1CY1 = (DSP1.Op1CYBR * DSP1_Cos(DSP1.Op1CZ) >> 15) - (DSP1.Op1CXBR * DSP1_Sin(DSP1.Op1CZ) >> 15);1234DSP1.Op1CXBR = DSP1.Op1CX1;1235DSP1.Op1CYBR = DSP1.Op1CY1;12361237// Rotate Around Op1CY11238DSP1.Op1CZ1 = (DSP1.Op1CXBR * DSP1_Sin(DSP1.Op1CY) >> 15) + (DSP1.Op1CZBR * DSP1_Cos(DSP1.Op1CY) >> 15);1239DSP1.Op1CX1 = (DSP1.Op1CXBR * DSP1_Cos(DSP1.Op1CY) >> 15) - (DSP1.Op1CZBR * DSP1_Sin(DSP1.Op1CY) >> 15);1240DSP1.Op1CXAR = DSP1.Op1CX1;1241DSP1.Op1CZBR = DSP1.Op1CZ1;12421243// Rotate Around Op1CX11244DSP1.Op1CY1 = (DSP1.Op1CZBR * DSP1_Sin(DSP1.Op1CX) >> 15) + (DSP1.Op1CYBR * DSP1_Cos(DSP1.Op1CX) >> 15);1245DSP1.Op1CZ1 = (DSP1.Op1CZBR * DSP1_Cos(DSP1.Op1CX) >> 15) - (DSP1.Op1CYBR * DSP1_Sin(DSP1.Op1CX) >> 15);1246DSP1.Op1CYAR = DSP1.Op1CY1;1247DSP1.Op1CZAR = DSP1.Op1CZ1;12481249#ifdef DebugDSP11250Log_Message("OP1C Apply Matrix CX:%d CY:%d CZ", DSP1.Op1CXAR, DSP1.Op1CYAR, DSP1.Op1CZAR);1251#endif1252}12531254static void DSP1_Op0F (void)1255{1256DSP1.Op0FPass = 0x0000;12571258#ifdef DebugDSP11259Log_Message("OP0F RAM Test Pass:%d", DSP1.Op0FPass);1260#endif1261}12621263static void DSP1_Op2F (void)1264{1265DSP1.Op2FSize = 0x100;1266}12671268void DSP1SetByte (uint8 byte, uint16 address)1269{1270if (address < DSP0.boundary)1271{1272if ((DSP1.command == 0x0A || DSP1.command == 0x1A) && DSP1.out_count != 0)1273{1274DSP1.out_count--;1275DSP1.out_index++;1276return;1277}1278else1279if (DSP1.waiting4command)1280{1281DSP1.command = byte;1282DSP1.in_index = 0;1283DSP1.waiting4command = FALSE;1284DSP1.first_parameter = TRUE;1285#ifdef DEBUGGER1286//printf("OP%02X\n",byte);1287#endif12881289switch (byte)1290{1291case 0x00: DSP1.in_count = 2; break;1292case 0x30:1293case 0x10: DSP1.in_count = 2; break;1294case 0x20: DSP1.in_count = 2; break;1295case 0x24:1296case 0x04: DSP1.in_count = 2; break;1297case 0x08: DSP1.in_count = 3; break;1298case 0x18: DSP1.in_count = 4; break;1299case 0x28: DSP1.in_count = 3; break;1300case 0x38: DSP1.in_count = 4; break;1301case 0x2c:1302case 0x0c: DSP1.in_count = 3; break;1303case 0x3c:1304case 0x1c: DSP1.in_count = 6; break;1305case 0x32:1306case 0x22:1307case 0x12:1308case 0x02: DSP1.in_count = 7; break;1309case 0x0a: DSP1.in_count = 1; break;1310case 0x3a:1311case 0x2a:1312case 0x1a:1313DSP1.command = 0x1a;1314DSP1.in_count = 1;1315break;1316case 0x16:1317case 0x26:1318case 0x36:1319case 0x06: DSP1.in_count = 3; break;1320case 0x1e:1321case 0x2e:1322case 0x3e:1323case 0x0e: DSP1.in_count = 2; break;1324case 0x05:1325case 0x35:1326case 0x31:1327case 0x01: DSP1.in_count = 4; break;1328case 0x15:1329case 0x11: DSP1.in_count = 4; break;1330case 0x25:1331case 0x21: DSP1.in_count = 4; break;1332case 0x09:1333case 0x39:1334case 0x3d:1335case 0x0d: DSP1.in_count = 3; break;1336case 0x19:1337case 0x1d: DSP1.in_count = 3; break;1338case 0x29:1339case 0x2d: DSP1.in_count = 3; break;1340case 0x33:1341case 0x03: DSP1.in_count = 3; break;1342case 0x13: DSP1.in_count = 3; break;1343case 0x23: DSP1.in_count = 3; break;1344case 0x3b:1345case 0x0b: DSP1.in_count = 3; break;1346case 0x1b: DSP1.in_count = 3; break;1347case 0x2b: DSP1.in_count = 3; break;1348case 0x34:1349case 0x14: DSP1.in_count = 6; break;1350case 0x07:1351case 0x0f: DSP1.in_count = 1; break;1352case 0x27:1353case 0x2F: DSP1.in_count = 1; break;1354case 0x17:1355case 0x37:1356case 0x3F:1357DSP1.command = 0x1f;1358case 0x1f: DSP1.in_count = 1; break;1359default:1360#ifdef DEBUGGER1361//printf("OP%02X\n", byte);1362#endif1363case 0x80:1364DSP1.in_count = 0;1365DSP1.waiting4command = TRUE;1366DSP1.first_parameter = TRUE;1367break;1368}13691370DSP1.in_count <<= 1;1371}1372else1373{1374DSP1.parameters[DSP1.in_index] = byte;1375DSP1.first_parameter = FALSE;1376DSP1.in_index++;1377}13781379if (DSP1.waiting4command || (DSP1.first_parameter && byte == 0x80))1380{1381DSP1.waiting4command = TRUE;1382DSP1.first_parameter = FALSE;1383}1384else1385if (DSP1.first_parameter && (DSP1.in_count != 0 || (DSP1.in_count == 0 && DSP1.in_index == 0)))1386;1387else1388{1389if (DSP1.in_count)1390{1391if (--DSP1.in_count == 0)1392{1393// Actually execute the command1394DSP1.waiting4command = TRUE;1395DSP1.out_index = 0;13961397switch (DSP1.command)1398{1399case 0x1f:1400DSP1.out_count = 2048;1401break;14021403case 0x00: // Multiple1404DSP1.Op00Multiplicand = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1405DSP1.Op00Multiplier = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));14061407DSP1_Op00();14081409DSP1.out_count = 2;1410DSP1.output[0] = DSP1.Op00Result & 0xFF;1411DSP1.output[1] = (DSP1.Op00Result >> 8) & 0xFF;1412break;14131414case 0x20: // Multiple1415DSP1.Op20Multiplicand = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1416DSP1.Op20Multiplier = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));14171418DSP1_Op20();14191420DSP1.out_count = 2;1421DSP1.output[0] = DSP1.Op20Result & 0xFF;1422DSP1.output[1] = (DSP1.Op20Result >> 8) & 0xFF;1423break;14241425case 0x30:1426case 0x10: // Inverse1427DSP1.Op10Coefficient = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1428DSP1.Op10Exponent = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));14291430DSP1_Op10();14311432DSP1.out_count = 4;1433DSP1.output[0] = (uint8) ( ((int16) DSP1.Op10CoefficientR) & 0xFF);1434DSP1.output[1] = (uint8) ((((int16) DSP1.Op10CoefficientR) >> 8) & 0xFF);1435DSP1.output[2] = (uint8) ( ((int16) DSP1.Op10ExponentR ) & 0xFF);1436DSP1.output[3] = (uint8) ((((int16) DSP1.Op10ExponentR ) >> 8) & 0xFF);1437break;14381439case 0x24:1440case 0x04: // Sin and Cos of angle1441DSP1.Op04Angle = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1442DSP1.Op04Radius = (uint16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));14431444DSP1_Op04();14451446DSP1.out_count = 4;1447DSP1.output[0] = (uint8) (DSP1.Op04Sin & 0xFF);1448DSP1.output[1] = (uint8) ((DSP1.Op04Sin >> 8) & 0xFF);1449DSP1.output[2] = (uint8) (DSP1.Op04Cos & 0xFF);1450DSP1.output[3] = (uint8) ((DSP1.Op04Cos >> 8) & 0xFF);1451break;14521453case 0x08: // Radius1454DSP1.Op08X = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1455DSP1.Op08Y = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1456DSP1.Op08Z = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));14571458DSP1_Op08();14591460DSP1.out_count = 4;1461DSP1.output[0] = (uint8) ( ((int16) DSP1.Op08Ll) & 0xFF);1462DSP1.output[1] = (uint8) ((((int16) DSP1.Op08Ll) >> 8) & 0xFF);1463DSP1.output[2] = (uint8) ( ((int16) DSP1.Op08Lh) & 0xFF);1464DSP1.output[3] = (uint8) ((((int16) DSP1.Op08Lh) >> 8) & 0xFF);1465break;14661467case 0x18: // Range14681469DSP1.Op18X = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1470DSP1.Op18Y = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1471DSP1.Op18Z = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));1472DSP1.Op18R = (int16) (DSP1.parameters[6] | (DSP1.parameters[7] << 8));14731474DSP1_Op18();14751476DSP1.out_count = 2;1477DSP1.output[0] = (uint8) (DSP1.Op18D & 0xFF);1478DSP1.output[1] = (uint8) ((DSP1.Op18D >> 8) & 0xFF);1479break;14801481case 0x38: // Range14821483DSP1.Op38X = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1484DSP1.Op38Y = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1485DSP1.Op38Z = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));1486DSP1.Op38R = (int16) (DSP1.parameters[6] | (DSP1.parameters[7] << 8));14871488DSP1_Op38();14891490DSP1.out_count = 2;1491DSP1.output[0] = (uint8) (DSP1.Op38D & 0xFF);1492DSP1.output[1] = (uint8) ((DSP1.Op38D >> 8) & 0xFF);1493break;14941495case 0x28: // Distance (vector length)1496DSP1.Op28X = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1497DSP1.Op28Y = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1498DSP1.Op28Z = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));14991500DSP1_Op28();15011502DSP1.out_count = 2;1503DSP1.output[0] = (uint8) (DSP1.Op28R & 0xFF);1504DSP1.output[1] = (uint8) ((DSP1.Op28R >> 8) & 0xFF);1505break;15061507case 0x2c:1508case 0x0c: // Rotate (2D rotate)1509DSP1.Op0CA = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1510DSP1.Op0CX1 = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1511DSP1.Op0CY1 = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));15121513DSP1_Op0C();15141515DSP1.out_count = 4;1516DSP1.output[0] = (uint8) (DSP1.Op0CX2 & 0xFF);1517DSP1.output[1] = (uint8) ((DSP1.Op0CX2 >> 8) & 0xFF);1518DSP1.output[2] = (uint8) (DSP1.Op0CY2 & 0xFF);1519DSP1.output[3] = (uint8) ((DSP1.Op0CY2 >> 8) & 0xFF);1520break;15211522case 0x3c:1523case 0x1c: // Polar (3D rotate)1524DSP1.Op1CZ = (DSP1.parameters[ 0] | (DSP1.parameters[ 1] << 8));1525//MK: reversed X and Y on neviksti and John's advice.1526DSP1.Op1CY = (DSP1.parameters[ 2] | (DSP1.parameters[ 3] << 8));1527DSP1.Op1CX = (DSP1.parameters[ 4] | (DSP1.parameters[ 5] << 8));1528DSP1.Op1CXBR = (DSP1.parameters[ 6] | (DSP1.parameters[ 7] << 8));1529DSP1.Op1CYBR = (DSP1.parameters[ 8] | (DSP1.parameters[ 9] << 8));1530DSP1.Op1CZBR = (DSP1.parameters[10] | (DSP1.parameters[11] << 8));15311532DSP1_Op1C();15331534DSP1.out_count = 6;1535DSP1.output[0] = (uint8) (DSP1.Op1CXAR & 0xFF);1536DSP1.output[1] = (uint8) ((DSP1.Op1CXAR >> 8) & 0xFF);1537DSP1.output[2] = (uint8) (DSP1.Op1CYAR & 0xFF);1538DSP1.output[3] = (uint8) ((DSP1.Op1CYAR >> 8) & 0xFF);1539DSP1.output[4] = (uint8) (DSP1.Op1CZAR & 0xFF);1540DSP1.output[5] = (uint8) ((DSP1.Op1CZAR >> 8) & 0xFF);1541break;15421543case 0x32:1544case 0x22:1545case 0x12:1546case 0x02: // Parameter (Projection)1547DSP1.Op02FX = (int16) (DSP1.parameters[ 0] | (DSP1.parameters[ 1] << 8));1548DSP1.Op02FY = (int16) (DSP1.parameters[ 2] | (DSP1.parameters[ 3] << 8));1549DSP1.Op02FZ = (int16) (DSP1.parameters[ 4] | (DSP1.parameters[ 5] << 8));1550DSP1.Op02LFE = (int16) (DSP1.parameters[ 6] | (DSP1.parameters[ 7] << 8));1551DSP1.Op02LES = (int16) (DSP1.parameters[ 8] | (DSP1.parameters[ 9] << 8));1552DSP1.Op02AAS = (uint16) (DSP1.parameters[10] | (DSP1.parameters[11] << 8));1553DSP1.Op02AZS = (uint16) (DSP1.parameters[12] | (DSP1.parameters[13] << 8));15541555DSP1_Op02();15561557DSP1.out_count = 8;1558DSP1.output[0] = (uint8) (DSP1.Op02VOF & 0xFF);1559DSP1.output[1] = (uint8) ((DSP1.Op02VOF >> 8) & 0xFF);1560DSP1.output[2] = (uint8) (DSP1.Op02VVA & 0xFF);1561DSP1.output[3] = (uint8) ((DSP1.Op02VVA >> 8) & 0xFF);1562DSP1.output[4] = (uint8) (DSP1.Op02CX & 0xFF);1563DSP1.output[5] = (uint8) ((DSP1.Op02CX >> 8) & 0xFF);1564DSP1.output[6] = (uint8) (DSP1.Op02CY & 0xFF);1565DSP1.output[7] = (uint8) ((DSP1.Op02CY >> 8) & 0xFF);1566break;15671568case 0x3a:1569case 0x2a:1570case 0x1a: // Raster mode 7 matrix data1571case 0x0a:1572DSP1.Op0AVS = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));15731574DSP1_Op0A();15751576DSP1.out_count = 8;1577DSP1.output[0] = (uint8) (DSP1.Op0AA & 0xFF);1578DSP1.output[1] = (uint8) ((DSP1.Op0AA >> 8) & 0xFF);1579DSP1.output[2] = (uint8) (DSP1.Op0AB & 0xFF);1580DSP1.output[3] = (uint8) ((DSP1.Op0AB >> 8) & 0xFF);1581DSP1.output[4] = (uint8) (DSP1.Op0AC & 0xFF);1582DSP1.output[5] = (uint8) ((DSP1.Op0AC >> 8) & 0xFF);1583DSP1.output[6] = (uint8) (DSP1.Op0AD & 0xFF);1584DSP1.output[7] = (uint8) ((DSP1.Op0AD >> 8) & 0xFF);1585DSP1.in_index = 0;1586break;15871588case 0x16:1589case 0x26:1590case 0x36:1591case 0x06: // Project object1592DSP1.Op06X = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1593DSP1.Op06Y = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1594DSP1.Op06Z = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));15951596DSP1_Op06();15971598DSP1.out_count = 6;1599DSP1.output[0] = (uint8) (DSP1.Op06H & 0xFF);1600DSP1.output[1] = (uint8) ((DSP1.Op06H >> 8) & 0xFF);1601DSP1.output[2] = (uint8) (DSP1.Op06V & 0xFF);1602DSP1.output[3] = (uint8) ((DSP1.Op06V >> 8) & 0xFF);1603DSP1.output[4] = (uint8) (DSP1.Op06M & 0xFF);1604DSP1.output[5] = (uint8) ((DSP1.Op06M >> 8) & 0xFF);1605break;16061607case 0x1e:1608case 0x2e:1609case 0x3e:1610case 0x0e: // Target1611DSP1.Op0EH = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1612DSP1.Op0EV = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));16131614DSP1_Op0E();16151616DSP1.out_count = 4;1617DSP1.output[0] = (uint8) (DSP1.Op0EX & 0xFF);1618DSP1.output[1] = (uint8) ((DSP1.Op0EX >> 8) & 0xFF);1619DSP1.output[2] = (uint8) (DSP1.Op0EY & 0xFF);1620DSP1.output[3] = (uint8) ((DSP1.Op0EY >> 8) & 0xFF);1621break;16221623// Extra commands used by Pilot Wings1624case 0x05:1625case 0x35:1626case 0x31:1627case 0x01: // Set attitude matrix A1628DSP1.Op01m = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1629DSP1.Op01Zr = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1630DSP1.Op01Yr = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));1631DSP1.Op01Xr = (int16) (DSP1.parameters[6] | (DSP1.parameters[7] << 8));16321633DSP1_Op01();1634break;16351636case 0x15:1637case 0x11: // Set attitude matrix B1638DSP1.Op11m = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1639DSP1.Op11Zr = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1640DSP1.Op11Yr = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));1641DSP1.Op11Xr = (int16) (DSP1.parameters[7] | (DSP1.parameters[7] << 8));16421643DSP1_Op11();1644break;16451646case 0x25:1647case 0x21: // Set attitude matrix C1648DSP1.Op21m = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1649DSP1.Op21Zr = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1650DSP1.Op21Yr = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));1651DSP1.Op21Xr = (int16) (DSP1.parameters[6] | (DSP1.parameters[7] << 8));16521653DSP1_Op21();1654break;16551656case 0x09:1657case 0x39:1658case 0x3d:1659case 0x0d: // Objective matrix A1660DSP1.Op0DX = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1661DSP1.Op0DY = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1662DSP1.Op0DZ = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));16631664DSP1_Op0D();16651666DSP1.out_count = 6;1667DSP1.output [0] = (uint8) (DSP1.Op0DF & 0xFF);1668DSP1.output [1] = (uint8) ((DSP1.Op0DF >> 8) & 0xFF);1669DSP1.output [2] = (uint8) (DSP1.Op0DL & 0xFF);1670DSP1.output [3] = (uint8) ((DSP1.Op0DL >> 8) & 0xFF);1671DSP1.output [4] = (uint8) (DSP1.Op0DU & 0xFF);1672DSP1.output [5] = (uint8) ((DSP1.Op0DU >> 8) & 0xFF);1673break;16741675case 0x19:1676case 0x1d: // Objective matrix B1677DSP1.Op1DX = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1678DSP1.Op1DY = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1679DSP1.Op1DZ = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));16801681DSP1_Op1D();16821683DSP1.out_count = 6;1684DSP1.output[0] = (uint8) (DSP1.Op1DF & 0xFF);1685DSP1.output[1] = (uint8) ((DSP1.Op1DF >> 8) & 0xFF);1686DSP1.output[2] = (uint8) (DSP1.Op1DL & 0xFF);1687DSP1.output[3] = (uint8) ((DSP1.Op1DL >> 8) & 0xFF);1688DSP1.output[4] = (uint8) (DSP1.Op1DU & 0xFF);1689DSP1.output[5] = (uint8) ((DSP1.Op1DU >> 8) & 0xFF);1690break;16911692case 0x29:1693case 0x2d: // Objective matrix C1694DSP1.Op2DX = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1695DSP1.Op2DY = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1696DSP1.Op2DZ = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));16971698DSP1_Op2D();16991700DSP1.out_count = 6;1701DSP1.output[0] = (uint8) (DSP1.Op2DF & 0xFF);1702DSP1.output[1] = (uint8) ((DSP1.Op2DF >> 8) & 0xFF);1703DSP1.output[2] = (uint8) (DSP1.Op2DL & 0xFF);1704DSP1.output[3] = (uint8) ((DSP1.Op2DL >> 8) & 0xFF);1705DSP1.output[4] = (uint8) (DSP1.Op2DU & 0xFF);1706DSP1.output[5] = (uint8) ((DSP1.Op2DU >> 8) & 0xFF);1707break;17081709case 0x33:1710case 0x03: // Subjective matrix A1711DSP1.Op03F = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1712DSP1.Op03L = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1713DSP1.Op03U = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));17141715DSP1_Op03();17161717DSP1.out_count = 6;1718DSP1.output[0] = (uint8) (DSP1.Op03X & 0xFF);1719DSP1.output[1] = (uint8) ((DSP1.Op03X >> 8) & 0xFF);1720DSP1.output[2] = (uint8) (DSP1.Op03Y & 0xFF);1721DSP1.output[3] = (uint8) ((DSP1.Op03Y >> 8) & 0xFF);1722DSP1.output[4] = (uint8) (DSP1.Op03Z & 0xFF);1723DSP1.output[5] = (uint8) ((DSP1.Op03Z >> 8) & 0xFF);1724break;17251726case 0x13: // Subjective matrix B1727DSP1.Op13F = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1728DSP1.Op13L = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1729DSP1.Op13U = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));17301731DSP1_Op13();17321733DSP1.out_count = 6;1734DSP1.output[0] = (uint8) (DSP1.Op13X & 0xFF);1735DSP1.output[1] = (uint8) ((DSP1.Op13X >> 8) & 0xFF);1736DSP1.output[2] = (uint8) (DSP1.Op13Y & 0xFF);1737DSP1.output[3] = (uint8) ((DSP1.Op13Y >> 8) & 0xFF);1738DSP1.output[4] = (uint8) (DSP1.Op13Z & 0xFF);1739DSP1.output[5] = (uint8) ((DSP1.Op13Z >> 8) & 0xFF);1740break;17411742case 0x23: // Subjective matrix C1743DSP1.Op23F = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1744DSP1.Op23L = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1745DSP1.Op23U = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));17461747DSP1_Op23();17481749DSP1.out_count = 6;1750DSP1.output[0] = (uint8) (DSP1.Op23X & 0xFF);1751DSP1.output[1] = (uint8) ((DSP1.Op23X >> 8) & 0xFF);1752DSP1.output[2] = (uint8) (DSP1.Op23Y & 0xFF);1753DSP1.output[3] = (uint8) ((DSP1.Op23Y >> 8) & 0xFF);1754DSP1.output[4] = (uint8) (DSP1.Op23Z & 0xFF);1755DSP1.output[5] = (uint8) ((DSP1.Op23Z >> 8) & 0xFF);1756break;17571758case 0x3b:1759case 0x0b:1760DSP1.Op0BX = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1761DSP1.Op0BY = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1762DSP1.Op0BZ = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));17631764DSP1_Op0B();17651766DSP1.out_count = 2;1767DSP1.output[0] = (uint8) (DSP1.Op0BS & 0xFF);1768DSP1.output[1] = (uint8) ((DSP1.Op0BS >> 8) & 0xFF);1769break;17701771case 0x1b:1772DSP1.Op1BX = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1773DSP1.Op1BY = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1774DSP1.Op1BZ = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));17751776DSP1_Op1B();17771778DSP1.out_count = 2;1779DSP1.output[0] = (uint8) (DSP1.Op1BS & 0xFF);1780DSP1.output[1] = (uint8) ((DSP1.Op1BS >> 8) & 0xFF);1781break;17821783case 0x2b:1784DSP1.Op2BX = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));1785DSP1.Op2BY = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));1786DSP1.Op2BZ = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));17871788DSP1_Op2B();17891790DSP1.out_count = 2;1791DSP1.output[0] = (uint8) (DSP1.Op2BS & 0xFF);1792DSP1.output[1] = (uint8) ((DSP1.Op2BS >> 8) & 0xFF);1793break;17941795case 0x34:1796case 0x14:1797DSP1.Op14Zr = (int16) (DSP1.parameters[ 0] | (DSP1.parameters[ 1] << 8));1798DSP1.Op14Xr = (int16) (DSP1.parameters[ 2] | (DSP1.parameters[ 3] << 8));1799DSP1.Op14Yr = (int16) (DSP1.parameters[ 4] | (DSP1.parameters[ 5] << 8));1800DSP1.Op14U = (int16) (DSP1.parameters[ 6] | (DSP1.parameters[ 7] << 8));1801DSP1.Op14F = (int16) (DSP1.parameters[ 8] | (DSP1.parameters[ 9] << 8));1802DSP1.Op14L = (int16) (DSP1.parameters[10] | (DSP1.parameters[11] << 8));18031804DSP1_Op14();18051806DSP1.out_count = 6;1807DSP1.output[0] = (uint8) (DSP1.Op14Zrr & 0xFF);1808DSP1.output[1] = (uint8) ((DSP1.Op14Zrr >> 8) & 0xFF);1809DSP1.output[2] = (uint8) (DSP1.Op14Xrr & 0xFF);1810DSP1.output[3] = (uint8) ((DSP1.Op14Xrr >> 8) & 0xFF);1811DSP1.output[4] = (uint8) (DSP1.Op14Yrr & 0xFF);1812DSP1.output[5] = (uint8) ((DSP1.Op14Yrr >> 8) & 0xFF);1813break;18141815case 0x27:1816case 0x2F:1817DSP1.Op2FUnknown = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));18181819DSP1_Op2F();18201821DSP1.out_count = 2;1822DSP1.output[0] = (uint8) (DSP1.Op2FSize & 0xFF);1823DSP1.output[1] = (uint8) ((DSP1.Op2FSize >> 8) & 0xFF);1824break;182518261827case 0x07:1828case 0x0F:1829DSP1.Op0FRamsize = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));18301831DSP1_Op0F();18321833DSP1.out_count = 2;1834DSP1.output[0] = (uint8) (DSP1.Op0FPass & 0xFF);1835DSP1.output[1] = (uint8) ((DSP1.Op0FPass >> 8) & 0xFF);1836break;18371838default:1839break;1840}1841}1842}1843}1844}1845}18461847uint8 DSP1GetByte (uint16 address)1848{1849uint8 t;18501851if (address < DSP0.boundary)1852{1853if (DSP1.out_count)1854{1855t = (uint8) DSP1.output[DSP1.out_index];18561857DSP1.out_index++;18581859if (--DSP1.out_count == 0)1860{1861if (DSP1.command == 0x1a || DSP1.command == 0x0a)1862{1863DSP1_Op0A();1864DSP1.out_count = 8;1865DSP1.out_index = 0;1866DSP1.output[0] = DSP1.Op0AA & 0xFF;1867DSP1.output[1] = (DSP1.Op0AA >> 8) & 0xFF;1868DSP1.output[2] = DSP1.Op0AB & 0xFF;1869DSP1.output[3] = (DSP1.Op0AB >> 8) & 0xFF;1870DSP1.output[4] = DSP1.Op0AC & 0xFF;1871DSP1.output[5] = (DSP1.Op0AC >> 8) & 0xFF;1872DSP1.output[6] = DSP1.Op0AD & 0xFF;1873DSP1.output[7] = (DSP1.Op0AD >> 8) & 0xFF;1874}18751876if (DSP1.command == 0x1f)1877{1878if ((DSP1.out_index % 2) != 0)1879t = (uint8) DSP1ROM[DSP1.out_index >> 1];1880else1881t = DSP1ROM[DSP1.out_index >> 1] >> 8;1882}1883}18841885DSP1.waiting4command = TRUE;1886}1887else1888t = 0xff;1889}1890else1891t = 0x80;18921893return (t);1894}189518961897