Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
RishiRecon
GitHub Repository: RishiRecon/exploits
Path: blob/main/misc/emulator/xnes/snes9x/dsp1.cpp
28515 views
1
/***********************************************************************************
2
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3
4
(c) Copyright 1996 - 2002 Gary Henderson ([email protected]),
5
Jerremy Koot ([email protected])
6
7
(c) Copyright 2002 - 2004 Matthew Kendora
8
9
(c) Copyright 2002 - 2005 Peter Bortas ([email protected])
10
11
(c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/)
12
13
(c) Copyright 2001 - 2006 John Weidman ([email protected])
14
15
(c) Copyright 2002 - 2006 funkyass ([email protected]),
16
Kris Bleakley ([email protected])
17
18
(c) Copyright 2002 - 2010 Brad Jorsch ([email protected]),
19
Nach ([email protected]),
20
21
(c) Copyright 2002 - 2011 zones ([email protected])
22
23
(c) Copyright 2006 - 2007 nitsuja
24
25
(c) Copyright 2009 - 2011 BearOso,
26
OV2
27
28
29
BS-X C emulator code
30
(c) Copyright 2005 - 2006 Dreamer Nom,
31
zones
32
33
C4 x86 assembler and some C emulation code
34
(c) Copyright 2000 - 2003 _Demo_ ([email protected]),
35
Nach,
36
zsKnight ([email protected])
37
38
C4 C++ code
39
(c) Copyright 2003 - 2006 Brad Jorsch,
40
Nach
41
42
DSP-1 emulator code
43
(c) Copyright 1998 - 2006 _Demo_,
44
Andreas Naive ([email protected]),
45
Gary Henderson,
46
Ivar ([email protected]),
47
John Weidman,
48
Kris Bleakley,
49
Matthew Kendora,
50
Nach,
51
neviksti ([email protected])
52
53
DSP-2 emulator code
54
(c) Copyright 2003 John Weidman,
55
Kris Bleakley,
56
Lord Nightmare ([email protected]),
57
Matthew Kendora,
58
neviksti
59
60
DSP-3 emulator code
61
(c) Copyright 2003 - 2006 John Weidman,
62
Kris Bleakley,
63
Lancer,
64
z80 gaiden
65
66
DSP-4 emulator code
67
(c) Copyright 2004 - 2006 Dreamer Nom,
68
John Weidman,
69
Kris Bleakley,
70
Nach,
71
z80 gaiden
72
73
OBC1 emulator code
74
(c) Copyright 2001 - 2004 zsKnight,
75
pagefault ([email protected]),
76
Kris Bleakley
77
Ported from x86 assembler to C by sanmaiwashi
78
79
SPC7110 and RTC C++ emulator code used in 1.39-1.51
80
(c) Copyright 2002 Matthew Kendora with research by
81
zsKnight,
82
John Weidman,
83
Dark Force
84
85
SPC7110 and RTC C++ emulator code used in 1.52+
86
(c) Copyright 2009 byuu,
87
neviksti
88
89
S-DD1 C emulator code
90
(c) Copyright 2003 Brad Jorsch with research by
91
Andreas Naive,
92
John Weidman
93
94
S-RTC C emulator code
95
(c) Copyright 2001 - 2006 byuu,
96
John Weidman
97
98
ST010 C++ emulator code
99
(c) Copyright 2003 Feather,
100
John Weidman,
101
Kris Bleakley,
102
Matthew Kendora
103
104
Super FX x86 assembler emulator code
105
(c) Copyright 1998 - 2003 _Demo_,
106
pagefault,
107
zsKnight
108
109
Super FX C emulator code
110
(c) Copyright 1997 - 1999 Ivar,
111
Gary Henderson,
112
John Weidman
113
114
Sound emulator code used in 1.5-1.51
115
(c) Copyright 1998 - 2003 Brad Martin
116
(c) Copyright 1998 - 2006 Charles Bilyue'
117
118
Sound emulator code used in 1.52+
119
(c) Copyright 2004 - 2007 Shay Green ([email protected])
120
121
SH assembler code partly based on x86 assembler code
122
(c) Copyright 2002 - 2004 Marcus Comstedt ([email protected])
123
124
2xSaI filter
125
(c) Copyright 1999 - 2001 Derek Liauw Kie Fa
126
127
HQ2x, HQ3x, HQ4x filters
128
(c) Copyright 2003 Maxim Stepin ([email protected])
129
130
NTSC filter
131
(c) Copyright 2006 - 2007 Shay Green
132
133
GTK+ GUI code
134
(c) Copyright 2004 - 2011 BearOso
135
136
Win32 GUI code
137
(c) Copyright 2003 - 2006 blip,
138
funkyass,
139
Matthew Kendora,
140
Nach,
141
nitsuja
142
(c) Copyright 2009 - 2011 OV2
143
144
Mac OS GUI code
145
(c) Copyright 1998 - 2001 John Stiles
146
(c) Copyright 2001 - 2011 zones
147
148
149
Specific ports contains the works of other authors. See headers in
150
individual files.
151
152
153
Snes9x homepage: http://www.snes9x.com/
154
155
Permission to use, copy, modify and/or distribute Snes9x in both binary
156
and source form, for non-commercial purposes, is hereby granted without
157
fee, providing that this license information and copyright notice appear
158
with all copies and any derived work.
159
160
This software is provided 'as-is', without any express or implied
161
warranty. In no event shall the authors be held liable for any damages
162
arising from the use of this software or it's derivatives.
163
164
Snes9x is freeware for PERSONAL USE only. Commercial users should
165
seek permission of the copyright holders first. Commercial use includes,
166
but is not limited to, charging money for Snes9x or software derived from
167
Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
168
using Snes9x as a promotion for your commercial product.
169
170
The copyright holders request that bug fixes and improvements to the code
171
should be forwarded to them so everyone can benefit from the modifications
172
in future versions.
173
174
Super NES and Super Nintendo Entertainment System are trademarks of
175
Nintendo Co., Limited and its subsidiary companies.
176
***********************************************************************************/
177
178
/*
179
Copyright (C) 1997-2006 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
180
181
http://www.zsnes.com
182
http://sourceforge.net/projects/zsnes
183
184
This program is free software; you can redistribute it and/or
185
modify it under the terms of the GNU General Public License
186
version 2 as published by the Free Software Foundation.
187
188
This program is distributed in the hope that it will be useful,
189
but WITHOUT ANY WARRANTY; without even the implied warranty of
190
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
191
GNU General Public License for more details.
192
193
You should have received a copy of the GNU General Public License
194
along with this program; if not, write to the Free Software
195
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
196
*/
197
198
199
#include "snes9x.h"
200
#include "memmap.h"
201
202
#ifdef DEBUGGER
203
//#define DebugDSP1
204
#endif
205
206
#ifdef DebugDSP1
207
#include <stdarg.h>
208
static FILE *LogFile = NULL;
209
#endif
210
211
static const uint16 DSP1ROM[1024] =
212
{
213
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
214
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
215
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
216
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
217
0x0000, 0x0000, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020,
218
0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000,
219
0x4000, 0x7fff, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200,
220
0x0100, 0x0080, 0x0040, 0x0020, 0x0001, 0x0008, 0x0004, 0x0002,
221
0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
222
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
223
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
224
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
225
0x0000, 0x0000, 0x8000, 0xffe5, 0x0100, 0x7fff, 0x7f02, 0x7e08,
226
0x7d12, 0x7c1f, 0x7b30, 0x7a45, 0x795d, 0x7878, 0x7797, 0x76ba,
227
0x75df, 0x7507, 0x7433, 0x7361, 0x7293, 0x71c7, 0x70fe, 0x7038,
228
0x6f75, 0x6eb4, 0x6df6, 0x6d3a, 0x6c81, 0x6bca, 0x6b16, 0x6a64,
229
0x69b4, 0x6907, 0x685b, 0x67b2, 0x670b, 0x6666, 0x65c4, 0x6523,
230
0x6484, 0x63e7, 0x634c, 0x62b3, 0x621c, 0x6186, 0x60f2, 0x6060,
231
0x5fd0, 0x5f41, 0x5eb5, 0x5e29, 0x5d9f, 0x5d17, 0x5c91, 0x5c0c,
232
0x5b88, 0x5b06, 0x5a85, 0x5a06, 0x5988, 0x590b, 0x5890, 0x5816,
233
0x579d, 0x5726, 0x56b0, 0x563b, 0x55c8, 0x5555, 0x54e4, 0x5474,
234
0x5405, 0x5398, 0x532b, 0x52bf, 0x5255, 0x51ec, 0x5183, 0x511c,
235
0x50b6, 0x5050, 0x4fec, 0x4f89, 0x4f26, 0x4ec5, 0x4e64, 0x4e05,
236
0x4da6, 0x4d48, 0x4cec, 0x4c90, 0x4c34, 0x4bda, 0x4b81, 0x4b28,
237
0x4ad0, 0x4a79, 0x4a23, 0x49cd, 0x4979, 0x4925, 0x48d1, 0x487f,
238
0x482d, 0x47dc, 0x478c, 0x473c, 0x46ed, 0x469f, 0x4651, 0x4604,
239
0x45b8, 0x456c, 0x4521, 0x44d7, 0x448d, 0x4444, 0x43fc, 0x43b4,
240
0x436d, 0x4326, 0x42e0, 0x429a, 0x4255, 0x4211, 0x41cd, 0x4189,
241
0x4146, 0x4104, 0x40c2, 0x4081, 0x4040, 0x3fff, 0x41f7, 0x43e1,
242
0x45bd, 0x478d, 0x4951, 0x4b0b, 0x4cbb, 0x4e61, 0x4fff, 0x5194,
243
0x5322, 0x54a9, 0x5628, 0x57a2, 0x5914, 0x5a81, 0x5be9, 0x5d4a,
244
0x5ea7, 0x5fff, 0x6152, 0x62a0, 0x63ea, 0x6530, 0x6672, 0x67b0,
245
0x68ea, 0x6a20, 0x6b53, 0x6c83, 0x6daf, 0x6ed9, 0x6fff, 0x7122,
246
0x7242, 0x735f, 0x747a, 0x7592, 0x76a7, 0x77ba, 0x78cb, 0x79d9,
247
0x7ae5, 0x7bee, 0x7cf5, 0x7dfa, 0x7efe, 0x7fff, 0x0000, 0x0324,
248
0x0647, 0x096a, 0x0c8b, 0x0fab, 0x12c8, 0x15e2, 0x18f8, 0x1c0b,
249
0x1f19, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11, 0x30fb, 0x33de,
250
0x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a, 0x471c, 0x49b4,
251
0x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842, 0x5a82, 0x5cb4,
252
0x5ed7, 0x60ec, 0x62f2, 0x64e8, 0x66cf, 0x68a6, 0x6a6d, 0x6c24,
253
0x6dca, 0x6f5f, 0x70e2, 0x7255, 0x73b5, 0x7504, 0x7641, 0x776c,
254
0x7884, 0x798a, 0x7a7d, 0x7b5d, 0x7c29, 0x7ce3, 0x7d8a, 0x7e1d,
255
0x7e9d, 0x7f09, 0x7f62, 0x7fa7, 0x7fd8, 0x7ff6, 0x7fff, 0x7ff6,
256
0x7fd8, 0x7fa7, 0x7f62, 0x7f09, 0x7e9d, 0x7e1d, 0x7d8a, 0x7ce3,
257
0x7c29, 0x7b5d, 0x7a7d, 0x798a, 0x7884, 0x776c, 0x7641, 0x7504,
258
0x73b5, 0x7255, 0x70e2, 0x6f5f, 0x6dca, 0x6c24, 0x6a6d, 0x68a6,
259
0x66cf, 0x64e8, 0x62f2, 0x60ec, 0x5ed7, 0x5cb4, 0x5a82, 0x5842,
260
0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4, 0x471c, 0x447a,
261
0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33de, 0x30fb, 0x2e11,
262
0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f19, 0x1c0b, 0x18f8, 0x15e2,
263
0x12c8, 0x0fab, 0x0c8b, 0x096a, 0x0647, 0x0324, 0x7fff, 0x7ff6,
264
0x7fd8, 0x7fa7, 0x7f62, 0x7f09, 0x7e9d, 0x7e1d, 0x7d8a, 0x7ce3,
265
0x7c29, 0x7b5d, 0x7a7d, 0x798a, 0x7884, 0x776c, 0x7641, 0x7504,
266
0x73b5, 0x7255, 0x70e2, 0x6f5f, 0x6dca, 0x6c24, 0x6a6d, 0x68a6,
267
0x66cf, 0x64e8, 0x62f2, 0x60ec, 0x5ed7, 0x5cb4, 0x5a82, 0x5842,
268
0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4, 0x471c, 0x447a,
269
0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33de, 0x30fb, 0x2e11,
270
0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f19, 0x1c0b, 0x18f8, 0x15e2,
271
0x12c8, 0x0fab, 0x0c8b, 0x096a, 0x0647, 0x0324, 0x0000, 0xfcdc,
272
0xf9b9, 0xf696, 0xf375, 0xf055, 0xed38, 0xea1e, 0xe708, 0xe3f5,
273
0xe0e7, 0xdddd, 0xdad8, 0xd7da, 0xd4e1, 0xd1ef, 0xcf05, 0xcc22,
274
0xc946, 0xc674, 0xc3aa, 0xc0e9, 0xbe32, 0xbb86, 0xb8e4, 0xb64c,
275
0xb3c1, 0xb141, 0xaecd, 0xac65, 0xaa0b, 0xa7be, 0xa57e, 0xa34c,
276
0xa129, 0x9f14, 0x9d0e, 0x9b18, 0x9931, 0x975a, 0x9593, 0x93dc,
277
0x9236, 0x90a1, 0x8f1e, 0x8dab, 0x8c4b, 0x8afc, 0x89bf, 0x8894,
278
0x877c, 0x8676, 0x8583, 0x84a3, 0x83d7, 0x831d, 0x8276, 0x81e3,
279
0x8163, 0x80f7, 0x809e, 0x8059, 0x8028, 0x800a, 0x6488, 0x0080,
280
0x03ff, 0x0116, 0x0002, 0x0080, 0x4000, 0x3fd7, 0x3faf, 0x3f86,
281
0x3f5d, 0x3f34, 0x3f0c, 0x3ee3, 0x3eba, 0x3e91, 0x3e68, 0x3e40,
282
0x3e17, 0x3dee, 0x3dc5, 0x3d9c, 0x3d74, 0x3d4b, 0x3d22, 0x3cf9,
283
0x3cd0, 0x3ca7, 0x3c7f, 0x3c56, 0x3c2d, 0x3c04, 0x3bdb, 0x3bb2,
284
0x3b89, 0x3b60, 0x3b37, 0x3b0e, 0x3ae5, 0x3abc, 0x3a93, 0x3a69,
285
0x3a40, 0x3a17, 0x39ee, 0x39c5, 0x399c, 0x3972, 0x3949, 0x3920,
286
0x38f6, 0x38cd, 0x38a4, 0x387a, 0x3851, 0x3827, 0x37fe, 0x37d4,
287
0x37aa, 0x3781, 0x3757, 0x372d, 0x3704, 0x36da, 0x36b0, 0x3686,
288
0x365c, 0x3632, 0x3609, 0x35df, 0x35b4, 0x358a, 0x3560, 0x3536,
289
0x350c, 0x34e1, 0x34b7, 0x348d, 0x3462, 0x3438, 0x340d, 0x33e3,
290
0x33b8, 0x338d, 0x3363, 0x3338, 0x330d, 0x32e2, 0x32b7, 0x328c,
291
0x3261, 0x3236, 0x320b, 0x31df, 0x31b4, 0x3188, 0x315d, 0x3131,
292
0x3106, 0x30da, 0x30ae, 0x3083, 0x3057, 0x302b, 0x2fff, 0x2fd2,
293
0x2fa6, 0x2f7a, 0x2f4d, 0x2f21, 0x2ef4, 0x2ec8, 0x2e9b, 0x2e6e,
294
0x2e41, 0x2e14, 0x2de7, 0x2dba, 0x2d8d, 0x2d60, 0x2d32, 0x2d05,
295
0x2cd7, 0x2ca9, 0x2c7b, 0x2c4d, 0x2c1f, 0x2bf1, 0x2bc3, 0x2b94,
296
0x2b66, 0x2b37, 0x2b09, 0x2ada, 0x2aab, 0x2a7c, 0x2a4c, 0x2a1d,
297
0x29ed, 0x29be, 0x298e, 0x295e, 0x292e, 0x28fe, 0x28ce, 0x289d,
298
0x286d, 0x283c, 0x280b, 0x27da, 0x27a9, 0x2777, 0x2746, 0x2714,
299
0x26e2, 0x26b0, 0x267e, 0x264c, 0x2619, 0x25e7, 0x25b4, 0x2581,
300
0x254d, 0x251a, 0x24e6, 0x24b2, 0x247e, 0x244a, 0x2415, 0x23e1,
301
0x23ac, 0x2376, 0x2341, 0x230b, 0x22d6, 0x229f, 0x2269, 0x2232,
302
0x21fc, 0x21c4, 0x218d, 0x2155, 0x211d, 0x20e5, 0x20ad, 0x2074,
303
0x203b, 0x2001, 0x1fc7, 0x1f8d, 0x1f53, 0x1f18, 0x1edd, 0x1ea1,
304
0x1e66, 0x1e29, 0x1ded, 0x1db0, 0x1d72, 0x1d35, 0x1cf6, 0x1cb8,
305
0x1c79, 0x1c39, 0x1bf9, 0x1bb8, 0x1b77, 0x1b36, 0x1af4, 0x1ab1,
306
0x1a6e, 0x1a2a, 0x19e6, 0x19a1, 0x195c, 0x1915, 0x18ce, 0x1887,
307
0x183f, 0x17f5, 0x17ac, 0x1761, 0x1715, 0x16c9, 0x167c, 0x162e,
308
0x15df, 0x158e, 0x153d, 0x14eb, 0x1497, 0x1442, 0x13ec, 0x1395,
309
0x133c, 0x12e2, 0x1286, 0x1228, 0x11c9, 0x1167, 0x1104, 0x109e,
310
0x1036, 0x0fcc, 0x0f5f, 0x0eef, 0x0e7b, 0x0e04, 0x0d89, 0x0d0a,
311
0x0c86, 0x0bfd, 0x0b6d, 0x0ad6, 0x0a36, 0x098d, 0x08d7, 0x0811,
312
0x0736, 0x063e, 0x0519, 0x039a, 0x0000, 0x7fff, 0x0100, 0x0080,
313
0x021d, 0x00c8, 0x00ce, 0x0048, 0x0a26, 0x277a, 0x00ce, 0x6488,
314
0x14ac, 0x0001, 0x00f9, 0x00fc, 0x00ff, 0x00fc, 0x00f9, 0xffff,
315
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
316
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
317
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
318
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
319
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
320
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
321
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
322
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
323
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
324
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
325
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
326
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
327
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
328
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
329
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
330
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
331
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
332
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
333
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
334
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
335
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
336
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
337
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
338
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
339
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
340
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff
341
};
342
343
static const int16 DSP1_MulTable[256] =
344
{
345
0x0000, 0x0003, 0x0006, 0x0009, 0x000c, 0x000f, 0x0012, 0x0015,
346
0x0019, 0x001c, 0x001f, 0x0022, 0x0025, 0x0028, 0x002b, 0x002f,
347
0x0032, 0x0035, 0x0038, 0x003b, 0x003e, 0x0041, 0x0045, 0x0048,
348
0x004b, 0x004e, 0x0051, 0x0054, 0x0057, 0x005b, 0x005e, 0x0061,
349
0x0064, 0x0067, 0x006a, 0x006d, 0x0071, 0x0074, 0x0077, 0x007a,
350
0x007d, 0x0080, 0x0083, 0x0087, 0x008a, 0x008d, 0x0090, 0x0093,
351
0x0096, 0x0099, 0x009d, 0x00a0, 0x00a3, 0x00a6, 0x00a9, 0x00ac,
352
0x00af, 0x00b3, 0x00b6, 0x00b9, 0x00bc, 0x00bf, 0x00c2, 0x00c5,
353
0x00c9, 0x00cc, 0x00cf, 0x00d2, 0x00d5, 0x00d8, 0x00db, 0x00df,
354
0x00e2, 0x00e5, 0x00e8, 0x00eb, 0x00ee, 0x00f1, 0x00f5, 0x00f8,
355
0x00fb, 0x00fe, 0x0101, 0x0104, 0x0107, 0x010b, 0x010e, 0x0111,
356
0x0114, 0x0117, 0x011a, 0x011d, 0x0121, 0x0124, 0x0127, 0x012a,
357
0x012d, 0x0130, 0x0133, 0x0137, 0x013a, 0x013d, 0x0140, 0x0143,
358
0x0146, 0x0149, 0x014d, 0x0150, 0x0153, 0x0156, 0x0159, 0x015c,
359
0x015f, 0x0163, 0x0166, 0x0169, 0x016c, 0x016f, 0x0172, 0x0175,
360
0x0178, 0x017c, 0x017f, 0x0182, 0x0185, 0x0188, 0x018b, 0x018e,
361
0x0192, 0x0195, 0x0198, 0x019b, 0x019e, 0x01a1, 0x01a4, 0x01a8,
362
0x01ab, 0x01ae, 0x01b1, 0x01b4, 0x01b7, 0x01ba, 0x01be, 0x01c1,
363
0x01c4, 0x01c7, 0x01ca, 0x01cd, 0x01d0, 0x01d4, 0x01d7, 0x01da,
364
0x01dd, 0x01e0, 0x01e3, 0x01e6, 0x01ea, 0x01ed, 0x01f0, 0x01f3,
365
0x01f6, 0x01f9, 0x01fc, 0x0200, 0x0203, 0x0206, 0x0209, 0x020c,
366
0x020f, 0x0212, 0x0216, 0x0219, 0x021c, 0x021f, 0x0222, 0x0225,
367
0x0228, 0x022c, 0x022f, 0x0232, 0x0235, 0x0238, 0x023b, 0x023e,
368
0x0242, 0x0245, 0x0248, 0x024b, 0x024e, 0x0251, 0x0254, 0x0258,
369
0x025b, 0x025e, 0x0261, 0x0264, 0x0267, 0x026a, 0x026e, 0x0271,
370
0x0274, 0x0277, 0x027a, 0x027d, 0x0280, 0x0284, 0x0287, 0x028a,
371
0x028d, 0x0290, 0x0293, 0x0296, 0x029a, 0x029d, 0x02a0, 0x02a3,
372
0x02a6, 0x02a9, 0x02ac, 0x02b0, 0x02b3, 0x02b6, 0x02b9, 0x02bc,
373
0x02bf, 0x02c2, 0x02c6, 0x02c9, 0x02cc, 0x02cf, 0x02d2, 0x02d5,
374
0x02d8, 0x02db, 0x02df, 0x02e2, 0x02e5, 0x02e8, 0x02eb, 0x02ee,
375
0x02f1, 0x02f5, 0x02f8, 0x02fb, 0x02fe, 0x0301, 0x0304, 0x0307,
376
0x030b, 0x030e, 0x0311, 0x0314, 0x0317, 0x031a, 0x031d, 0x0321
377
};
378
379
static const int16 DSP1_SinTable[256] =
380
{
381
0x0000, 0x0324, 0x0647, 0x096a, 0x0c8b, 0x0fab, 0x12c8, 0x15e2,
382
0x18f8, 0x1c0b, 0x1f19, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11,
383
0x30fb, 0x33de, 0x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a,
384
0x471c, 0x49b4, 0x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842,
385
0x5a82, 0x5cb4, 0x5ed7, 0x60ec, 0x62f2, 0x64e8, 0x66cf, 0x68a6,
386
0x6a6d, 0x6c24, 0x6dca, 0x6f5f, 0x70e2, 0x7255, 0x73b5, 0x7504,
387
0x7641, 0x776c, 0x7884, 0x798a, 0x7a7d, 0x7b5d, 0x7c29, 0x7ce3,
388
0x7d8a, 0x7e1d, 0x7e9d, 0x7f09, 0x7f62, 0x7fa7, 0x7fd8, 0x7ff6,
389
0x7fff, 0x7ff6, 0x7fd8, 0x7fa7, 0x7f62, 0x7f09, 0x7e9d, 0x7e1d,
390
0x7d8a, 0x7ce3, 0x7c29, 0x7b5d, 0x7a7d, 0x798a, 0x7884, 0x776c,
391
0x7641, 0x7504, 0x73b5, 0x7255, 0x70e2, 0x6f5f, 0x6dca, 0x6c24,
392
0x6a6d, 0x68a6, 0x66cf, 0x64e8, 0x62f2, 0x60ec, 0x5ed7, 0x5cb4,
393
0x5a82, 0x5842, 0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4,
394
0x471c, 0x447a, 0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33de,
395
0x30fb, 0x2e11, 0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f19, 0x1c0b,
396
0x18f8, 0x15e2, 0x12c8, 0x0fab, 0x0c8b, 0x096a, 0x0647, 0x0324,
397
-0x0000, -0x0324, -0x0647, -0x096a, -0x0c8b, -0x0fab, -0x12c8, -0x15e2,
398
-0x18f8, -0x1c0b, -0x1f19, -0x2223, -0x2528, -0x2826, -0x2b1f, -0x2e11,
399
-0x30fb, -0x33de, -0x36ba, -0x398c, -0x3c56, -0x3f17, -0x41ce, -0x447a,
400
-0x471c, -0x49b4, -0x4c3f, -0x4ebf, -0x5133, -0x539b, -0x55f5, -0x5842,
401
-0x5a82, -0x5cb4, -0x5ed7, -0x60ec, -0x62f2, -0x64e8, -0x66cf, -0x68a6,
402
-0x6a6d, -0x6c24, -0x6dca, -0x6f5f, -0x70e2, -0x7255, -0x73b5, -0x7504,
403
-0x7641, -0x776c, -0x7884, -0x798a, -0x7a7d, -0x7b5d, -0x7c29, -0x7ce3,
404
-0x7d8a, -0x7e1d, -0x7e9d, -0x7f09, -0x7f62, -0x7fa7, -0x7fd8, -0x7ff6,
405
-0x7fff, -0x7ff6, -0x7fd8, -0x7fa7, -0x7f62, -0x7f09, -0x7e9d, -0x7e1d,
406
-0x7d8a, -0x7ce3, -0x7c29, -0x7b5d, -0x7a7d, -0x798a, -0x7884, -0x776c,
407
-0x7641, -0x7504, -0x73b5, -0x7255, -0x70e2, -0x6f5f, -0x6dca, -0x6c24,
408
-0x6a6d, -0x68a6, -0x66cf, -0x64e8, -0x62f2, -0x60ec, -0x5ed7, -0x5cb4,
409
-0x5a82, -0x5842, -0x55f5, -0x539b, -0x5133, -0x4ebf, -0x4c3f, -0x49b4,
410
-0x471c, -0x447a, -0x41ce, -0x3f17, -0x3c56, -0x398c, -0x36ba, -0x33de,
411
-0x30fb, -0x2e11, -0x2b1f, -0x2826, -0x2528, -0x2223, -0x1f19, -0x1c0b,
412
-0x18f8, -0x15e2, -0x12c8, -0x0fab, -0x0c8b, -0x096a, -0x0647, -0x0324
413
};
414
415
416
#ifdef DebugDSP1
417
418
static void Log_Message (const char *Message, ...)
419
{
420
char Msg[400];
421
va_list ap;
422
size_t ignore;
423
424
va_start(ap, Message);
425
vsprintf(Msg, Message, ap);
426
va_end(ap);
427
428
strcat(Msg, "\r\n\0");
429
ignore = fwrite(Msg, strlen(Msg), 1, LogFile);
430
fflush(LogFile);
431
}
432
433
static void Start_Log (void)
434
{
435
LogFile = fopen("dsp1emu.log", "wb");
436
}
437
438
static void Stop_Log (void)
439
{
440
if (LogFile)
441
{
442
fclose(LogFile);
443
LogFile = NULL;
444
}
445
}
446
447
#endif
448
449
static void DSP1_Op00 (void)
450
{
451
DSP1.Op00Result = DSP1.Op00Multiplicand * DSP1.Op00Multiplier >> 15;
452
453
#ifdef DebugDSP1
454
Log_Message("OP00 MULT %d*%d/32768=%d", DSP1.Op00Multiplicand, DSP1.Op00Multiplier, DSP1.Op00Result);
455
#endif
456
}
457
458
static void DSP1_Op20 (void)
459
{
460
DSP1.Op20Result = DSP1.Op20Multiplicand * DSP1.Op20Multiplier >> 15;
461
DSP1.Op20Result++;
462
463
#ifdef DebugDSP1
464
Log_Message("OP20 MULT %d*%d/32768=%d", DSP1.Op20Multiplicand, DSP1.Op20Multiplier, DSP1.Op20Result);
465
#endif
466
}
467
468
static void DSP1_Inverse (int16 Coefficient, int16 Exponent, int16 *iCoefficient, int16 *iExponent)
469
{
470
// Step One: Division by Zero
471
if (Coefficient == 0x0000)
472
{
473
*iCoefficient = 0x7fff;
474
*iExponent = 0x002f;
475
}
476
else
477
{
478
int16 Sign = 1;
479
480
// Step Two: Remove Sign
481
if (Coefficient < 0)
482
{
483
if (Coefficient < -32767)
484
Coefficient = -32767;
485
Coefficient = -Coefficient;
486
Sign = -1;
487
}
488
489
// Step Three: Normalize
490
while (Coefficient < 0x4000)
491
{
492
Coefficient <<= 1;
493
Exponent--;
494
}
495
496
// Step Four: Special Case
497
if (Coefficient == 0x4000)
498
{
499
if (Sign == 1)
500
*iCoefficient = 0x7fff;
501
else
502
{
503
*iCoefficient = -0x4000;
504
Exponent--;
505
}
506
}
507
else
508
{
509
// Step Five: Initial Guess
510
int16 i = DSP1ROM[((Coefficient - 0x4000) >> 7) + 0x0065];
511
512
// Step Six: Iterate "estimated" Newton's Method
513
i = (i + (-i * (Coefficient * i >> 15) >> 15)) << 1;
514
i = (i + (-i * (Coefficient * i >> 15) >> 15)) << 1;
515
516
*iCoefficient = i * Sign;
517
}
518
519
*iExponent = 1 - Exponent;
520
}
521
}
522
523
static void DSP1_Op10 (void)
524
{
525
DSP1_Inverse(DSP1.Op10Coefficient, DSP1.Op10Exponent, &DSP1.Op10CoefficientR, &DSP1.Op10ExponentR);
526
527
#ifdef DebugDSP1
528
Log_Message("OP10 INV %d*2^%d = %d*2^%d", DSP1.Op10Coefficient, DSP1.Op10Exponent, DSP1.Op10CoefficientR, DSP1.Op10ExponentR);
529
#endif
530
}
531
532
static int16 DSP1_Sin (int16 Angle)
533
{
534
int32 S;
535
536
if (Angle < 0)
537
{
538
if (Angle == -32768)
539
return (0);
540
541
return (-DSP1_Sin(-Angle));
542
}
543
544
S = DSP1_SinTable[Angle >> 8] + (DSP1_MulTable[Angle & 0xff] * DSP1_SinTable[0x40 + (Angle >> 8)] >> 15);
545
if (S > 32767)
546
S = 32767;
547
548
return ((int16) S);
549
}
550
551
static int16 DSP1_Cos (int16 Angle)
552
{
553
int32 S;
554
555
if (Angle < 0)
556
{
557
if (Angle == -32768)
558
return (-32768);
559
560
Angle = -Angle;
561
}
562
563
S = DSP1_SinTable[0x40 + (Angle >> 8)] - (DSP1_MulTable[Angle & 0xff] * DSP1_SinTable[Angle >> 8] >> 15);
564
if (S < -32768)
565
S = -32767;
566
567
return ((int16) S);
568
}
569
570
static void DSP1_Normalize (int16 m, int16 *Coefficient, int16 *Exponent)
571
{
572
int16 i = 0x4000;
573
int16 e = 0;
574
575
if (m < 0)
576
{
577
while ((m & i) && i)
578
{
579
i >>= 1;
580
e++;
581
}
582
}
583
else
584
{
585
while (!(m & i) && i)
586
{
587
i >>= 1;
588
e++;
589
}
590
}
591
592
if (e > 0)
593
*Coefficient = m * DSP1ROM[0x21 + e] << 1;
594
else
595
*Coefficient = m;
596
597
*Exponent -= e;
598
}
599
600
static void DSP1_NormalizeDouble (int32 Product, int16 *Coefficient, int16 *Exponent)
601
{
602
int16 n = Product & 0x7fff;
603
int16 m = Product >> 15;
604
int16 i = 0x4000;
605
int16 e = 0;
606
607
if (m < 0)
608
{
609
while ((m & i) && i)
610
{
611
i >>= 1;
612
e++;
613
}
614
}
615
else
616
{
617
while (!(m & i) && i)
618
{
619
i >>= 1;
620
e++;
621
}
622
}
623
624
if (e > 0)
625
{
626
*Coefficient = m * DSP1ROM[0x0021 + e] << 1;
627
628
if (e < 15)
629
*Coefficient += n * DSP1ROM[0x0040 - e] >> 15;
630
else
631
{
632
i = 0x4000;
633
634
if (m < 0)
635
{
636
while ((n & i) && i)
637
{
638
i >>= 1;
639
e++;
640
}
641
}
642
else
643
{
644
while (!(n & i) && i)
645
{
646
i >>= 1;
647
e++;
648
}
649
}
650
651
if (e > 15)
652
*Coefficient = n * DSP1ROM[0x0012 + e] << 1;
653
else
654
*Coefficient += n;
655
}
656
}
657
else
658
*Coefficient = m;
659
660
*Exponent = e;
661
}
662
663
static int16 DSP1_Truncate (int16 C, int16 E)
664
{
665
if (E > 0)
666
{
667
if (C > 0)
668
return (32767);
669
else
670
if (C < 0)
671
return (-32767);
672
}
673
else
674
{
675
if (E < 0)
676
return (C * DSP1ROM[0x0031 + E] >> 15);
677
}
678
679
return (C);
680
}
681
682
static void DSP1_Op04 (void)
683
{
684
DSP1.Op04Sin = DSP1_Sin(DSP1.Op04Angle) * DSP1.Op04Radius >> 15;
685
DSP1.Op04Cos = DSP1_Cos(DSP1.Op04Angle) * DSP1.Op04Radius >> 15;
686
}
687
688
static void DSP1_Op0C (void)
689
{
690
DSP1.Op0CX2 = (DSP1.Op0CY1 * DSP1_Sin(DSP1.Op0CA) >> 15) + (DSP1.Op0CX1 * DSP1_Cos(DSP1.Op0CA) >> 15);
691
DSP1.Op0CY2 = (DSP1.Op0CY1 * DSP1_Cos(DSP1.Op0CA) >> 15) - (DSP1.Op0CX1 * DSP1_Sin(DSP1.Op0CA) >> 15);
692
}
693
694
static 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)
695
{
696
const int16 MaxAZS_Exp[16] =
697
{
698
0x38b4, 0x38b7, 0x38ba, 0x38be, 0x38c0, 0x38c4, 0x38c7, 0x38ca,
699
0x38ce, 0x38d0, 0x38d4, 0x38d7, 0x38da, 0x38dd, 0x38e0, 0x38e4
700
};
701
702
int16 CSec, C, E, MaxAZS, Aux;
703
int16 LfeNx, LfeNy, LfeNz;
704
int16 LesNx, LesNy, LesNz;
705
int16 CentreZ;
706
707
// Copy Zenith angle for clipping
708
int16 AZS = Azs;
709
710
// Store Sine and Cosine of Azimuth and Zenith angle
711
DSP1.SinAas = DSP1_Sin(Aas);
712
DSP1.CosAas = DSP1_Cos(Aas);
713
DSP1.SinAzs = DSP1_Sin(Azs);
714
DSP1.CosAzs = DSP1_Cos(Azs);
715
716
DSP1.Nx = DSP1.SinAzs * -DSP1.SinAas >> 15;
717
DSP1.Ny = DSP1.SinAzs * DSP1.CosAas >> 15;
718
DSP1.Nz = DSP1.CosAzs * 0x7fff >> 15;
719
720
LfeNx = Lfe * DSP1.Nx >> 15;
721
LfeNy = Lfe * DSP1.Ny >> 15;
722
LfeNz = Lfe * DSP1.Nz >> 15;
723
724
// Center of Projection
725
DSP1.CentreX = Fx + LfeNx;
726
DSP1.CentreY = Fy + LfeNy;
727
CentreZ = Fz + LfeNz;
728
729
LesNx = Les * DSP1.Nx >> 15;
730
LesNy = Les * DSP1.Ny >> 15;
731
LesNz = Les * DSP1.Nz >> 15;
732
733
DSP1.Gx = DSP1.CentreX - LesNx;
734
DSP1.Gy = DSP1.CentreY - LesNy;
735
DSP1.Gz = CentreZ - LesNz;
736
737
DSP1.E_Les = 0;
738
DSP1_Normalize(Les, &DSP1.C_Les, &DSP1.E_Les);
739
DSP1.G_Les = Les;
740
741
E = 0;
742
DSP1_Normalize(CentreZ, &C, &E);
743
744
DSP1.VPlane_C = C;
745
DSP1.VPlane_E = E;
746
747
// Determine clip boundary and clip Zenith angle if necessary
748
MaxAZS = MaxAZS_Exp[-E];
749
750
if (AZS < 0)
751
{
752
MaxAZS = -MaxAZS;
753
if (AZS < MaxAZS + 1)
754
AZS = MaxAZS + 1;
755
}
756
else
757
{
758
if (AZS > MaxAZS)
759
AZS = MaxAZS;
760
}
761
762
// Store Sine and Cosine of clipped Zenith angle
763
DSP1.SinAZS = DSP1_Sin(AZS);
764
DSP1.CosAZS = DSP1_Cos(AZS);
765
766
DSP1_Inverse(DSP1.CosAZS, 0, &DSP1.SecAZS_C1, &DSP1.SecAZS_E1);
767
DSP1_Normalize(C * DSP1.SecAZS_C1 >> 15, &C, &E);
768
E += DSP1.SecAZS_E1;
769
770
C = DSP1_Truncate(C, E) * DSP1.SinAZS >> 15;
771
772
DSP1.CentreX += C * DSP1.SinAas >> 15;
773
DSP1.CentreY -= C * DSP1.CosAas >> 15;
774
775
*Cx = DSP1.CentreX;
776
*Cy = DSP1.CentreY;
777
778
// Raster number of imaginary center and horizontal line
779
*Vof = 0;
780
781
if ((Azs != AZS) || (Azs == MaxAZS))
782
{
783
if (Azs == -32768)
784
Azs = -32767;
785
786
C = Azs - MaxAZS;
787
if (C >= 0)
788
C--;
789
Aux = ~(C << 2);
790
791
C = Aux * DSP1ROM[0x0328] >> 15;
792
C = (C * Aux >> 15) + DSP1ROM[0x0327];
793
*Vof -= (C * Aux >> 15) * Les >> 15;
794
795
C = Aux * Aux >> 15;
796
Aux = (C * DSP1ROM[0x0324] >> 15) + DSP1ROM[0x0325];
797
DSP1.CosAZS += (C * Aux >> 15) * DSP1.CosAZS >> 15;
798
}
799
800
DSP1.VOffset = Les * DSP1.CosAZS >> 15;
801
802
DSP1_Inverse(DSP1.SinAZS, 0, &CSec, &E);
803
DSP1_Normalize(DSP1.VOffset, &C, &E);
804
DSP1_Normalize(C * CSec >> 15, &C, &E);
805
806
if (C == -32768)
807
{
808
C >>= 1;
809
E++;
810
}
811
812
*Vva = DSP1_Truncate(-C, E);
813
814
// Store Secant of clipped Zenith angle
815
DSP1_Inverse(DSP1.CosAZS, 0, &DSP1.SecAZS_C2, &DSP1.SecAZS_E2);
816
}
817
818
static void DSP1_Raster (int16 Vs, int16 *An, int16 *Bn, int16 *Cn, int16 *Dn)
819
{
820
int16 C, E, C1, E1;
821
822
DSP1_Inverse((Vs * DSP1.SinAzs >> 15) + DSP1.VOffset, 7, &C, &E);
823
E += DSP1.VPlane_E;
824
825
C1 = C * DSP1.VPlane_C >> 15;
826
E1 = E + DSP1.SecAZS_E2;
827
828
DSP1_Normalize(C1, &C, &E);
829
830
C = DSP1_Truncate(C, E);
831
832
*An = C * DSP1.CosAas >> 15;
833
*Cn = C * DSP1.SinAas >> 15;
834
835
DSP1_Normalize(C1 * DSP1.SecAZS_C2 >> 15, &C, &E1);
836
837
C = DSP1_Truncate(C, E1);
838
839
*Bn = C * -DSP1.SinAas >> 15;
840
*Dn = C * DSP1.CosAas >> 15;
841
}
842
843
static void DSP1_Op02 (void)
844
{
845
DSP1_Parameter(DSP1.Op02FX, DSP1.Op02FY, DSP1.Op02FZ, DSP1.Op02LFE, DSP1.Op02LES, DSP1.Op02AAS, DSP1.Op02AZS, &DSP1.Op02VOF, &DSP1.Op02VVA, &DSP1.Op02CX, &DSP1.Op02CY);
846
}
847
848
static void DSP1_Op0A (void)
849
{
850
DSP1_Raster(DSP1.Op0AVS, &DSP1.Op0AA, &DSP1.Op0AB, &DSP1.Op0AC, &DSP1.Op0AD);
851
DSP1.Op0AVS++;
852
}
853
854
static int16 DSP1_ShiftR (int16 C, int16 E)
855
{
856
return (C * DSP1ROM[0x0031 + E] >> 15);
857
}
858
859
static void DSP1_Project (int16 X, int16 Y, int16 Z, int16 *H, int16 *V, int16 *M)
860
{
861
int32 aux, aux4;
862
int16 E, E2, E3, E4, E5, refE, E6, E7;
863
int16 C2, C4, C6, C8, C9, C10, C11, C12, C16, C17, C18, C19, C20, C21, C22, C23, C24, C25, C26;
864
int16 Px, Py, Pz;
865
866
E4 = E3 = E2 = E = E5 = 0;
867
868
DSP1_NormalizeDouble((int32) X - DSP1.Gx, &Px, &E4);
869
DSP1_NormalizeDouble((int32) Y - DSP1.Gy, &Py, &E );
870
DSP1_NormalizeDouble((int32) Z - DSP1.Gz, &Pz, &E3);
871
Px >>= 1; // to avoid overflows when calculating the scalar products
872
E4--;
873
Py >>= 1;
874
E--;
875
Pz >>= 1;
876
E3--;
877
878
refE = (E < E3) ? E : E3;
879
refE = (refE < E4) ? refE : E4;
880
881
Px = DSP1_ShiftR(Px, E4 - refE); // normalize them to the same exponent
882
Py = DSP1_ShiftR(Py, E - refE);
883
Pz = DSP1_ShiftR(Pz, E3 - refE);
884
885
C11 = -(Px * DSP1.Nx >> 15);
886
C8 = -(Py * DSP1.Ny >> 15);
887
C9 = -(Pz * DSP1.Nz >> 15);
888
C12 = C11 + C8 + C9; // this cannot overflow!
889
890
aux4 = C12; // de-normalization with 32-bits arithmetic
891
refE = 16 - refE; // refE can be up to 3
892
if (refE >= 0)
893
aux4 <<= (refE);
894
else
895
aux4 >>= -(refE);
896
if (aux4 == -1)
897
aux4 = 0; // why?
898
aux4 >>= 1;
899
900
aux = ((uint16) DSP1.G_Les) + aux4; // Les - the scalar product of P with the normal vector of the screen
901
DSP1_NormalizeDouble(aux, &C10, &E2);
902
E2 = 15 - E2;
903
904
DSP1_Inverse(C10, 0, &C4, &E4);
905
C2 = C4 * DSP1.C_Les >> 15; // scale factor
906
907
// H
908
E7 = 0;
909
C16 = Px * ( DSP1.CosAas * 0x7fff >> 15) >> 15;
910
C20 = Py * ( DSP1.SinAas * 0x7fff >> 15) >> 15;
911
C17 = C16 + C20; // scalar product of P with the normalized horizontal vector of the screen...
912
913
C18 = C17 * C2 >> 15; // ... multiplied by the scale factor
914
DSP1_Normalize(C18, &C19, &E7);
915
*H = DSP1_Truncate(C19, DSP1.E_Les - E2 + refE + E7);
916
917
// V
918
E6 = 0;
919
C21 = Px * ( DSP1.CosAzs * -DSP1.SinAas >> 15) >> 15;
920
C22 = Py * ( DSP1.CosAzs * DSP1.CosAas >> 15) >> 15;
921
C23 = Pz * (-DSP1.SinAzs * 0x7fff >> 15) >> 15;
922
C24 = C21 + C22 + C23; // scalar product of P with the normalized vertical vector of the screen...
923
924
C26 = C24 * C2 >> 15; // ... multiplied by the scale factor
925
DSP1_Normalize(C26, &C25, &E6);
926
*V = DSP1_Truncate(C25, DSP1.E_Les - E2 + refE + E6);
927
928
// M
929
DSP1_Normalize(C2, &C6, &E4);
930
*M = DSP1_Truncate(C6, E4 + DSP1.E_Les - E2 - 7); // M is the scale factor divided by 2^7
931
}
932
933
static void DSP1_Op06 (void)
934
{
935
DSP1_Project(DSP1.Op06X, DSP1.Op06Y, DSP1.Op06Z, &DSP1.Op06H, &DSP1.Op06V, &DSP1.Op06M);
936
}
937
938
static void DSP1_Op01 (void)
939
{
940
int16 SinAz = DSP1_Sin(DSP1.Op01Zr);
941
int16 CosAz = DSP1_Cos(DSP1.Op01Zr);
942
int16 SinAy = DSP1_Sin(DSP1.Op01Yr);
943
int16 CosAy = DSP1_Cos(DSP1.Op01Yr);
944
int16 SinAx = DSP1_Sin(DSP1.Op01Xr);
945
int16 CosAx = DSP1_Cos(DSP1.Op01Xr);
946
947
DSP1.Op01m >>= 1;
948
949
DSP1.matrixA[0][0] = (DSP1.Op01m * CosAz >> 15) * CosAy >> 15;
950
DSP1.matrixA[0][1] = -((DSP1.Op01m * SinAz >> 15) * CosAy >> 15);
951
DSP1.matrixA[0][2] = DSP1.Op01m * SinAy >> 15;
952
953
DSP1.matrixA[1][0] = ((DSP1.Op01m * SinAz >> 15) * CosAx >> 15) + (((DSP1.Op01m * CosAz >> 15) * SinAx >> 15) * SinAy >> 15);
954
DSP1.matrixA[1][1] = ((DSP1.Op01m * CosAz >> 15) * CosAx >> 15) - (((DSP1.Op01m * SinAz >> 15) * SinAx >> 15) * SinAy >> 15);
955
DSP1.matrixA[1][2] = -((DSP1.Op01m * SinAx >> 15) * CosAy >> 15);
956
957
DSP1.matrixA[2][0] = ((DSP1.Op01m * SinAz >> 15) * SinAx >> 15) - (((DSP1.Op01m * CosAz >> 15) * CosAx >> 15) * SinAy >> 15);
958
DSP1.matrixA[2][1] = ((DSP1.Op01m * CosAz >> 15) * SinAx >> 15) + (((DSP1.Op01m * SinAz >> 15) * CosAx >> 15) * SinAy >> 15);
959
DSP1.matrixA[2][2] = (DSP1.Op01m * CosAx >> 15) * CosAy >> 15;
960
}
961
962
static void DSP1_Op11 (void)
963
{
964
int16 SinAz = DSP1_Sin(DSP1.Op11Zr);
965
int16 CosAz = DSP1_Cos(DSP1.Op11Zr);
966
int16 SinAy = DSP1_Sin(DSP1.Op11Yr);
967
int16 CosAy = DSP1_Cos(DSP1.Op11Yr);
968
int16 SinAx = DSP1_Sin(DSP1.Op11Xr);
969
int16 CosAx = DSP1_Cos(DSP1.Op11Xr);
970
971
DSP1.Op11m >>= 1;
972
973
DSP1.matrixB[0][0] = (DSP1.Op11m * CosAz >> 15) * CosAy >> 15;
974
DSP1.matrixB[0][1] = -((DSP1.Op11m * SinAz >> 15) * CosAy >> 15);
975
DSP1.matrixB[0][2] = DSP1.Op11m * SinAy >> 15;
976
977
DSP1.matrixB[1][0] = ((DSP1.Op11m * SinAz >> 15) * CosAx >> 15) + (((DSP1.Op11m * CosAz >> 15) * SinAx >> 15) * SinAy >> 15);
978
DSP1.matrixB[1][1] = ((DSP1.Op11m * CosAz >> 15) * CosAx >> 15) - (((DSP1.Op11m * SinAz >> 15) * SinAx >> 15) * SinAy >> 15);
979
DSP1.matrixB[1][2] = -((DSP1.Op11m * SinAx >> 15) * CosAy >> 15);
980
981
DSP1.matrixB[2][0] = ((DSP1.Op11m * SinAz >> 15) * SinAx >> 15) - (((DSP1.Op11m * CosAz >> 15) * CosAx >> 15) * SinAy >> 15);
982
DSP1.matrixB[2][1] = ((DSP1.Op11m * CosAz >> 15) * SinAx >> 15) + (((DSP1.Op11m * SinAz >> 15) * CosAx >> 15) * SinAy >> 15);
983
DSP1.matrixB[2][2] = (DSP1.Op11m * CosAx >> 15) * CosAy >> 15;
984
}
985
986
static void DSP1_Op21 (void)
987
{
988
int16 SinAz = DSP1_Sin(DSP1.Op21Zr);
989
int16 CosAz = DSP1_Cos(DSP1.Op21Zr);
990
int16 SinAy = DSP1_Sin(DSP1.Op21Yr);
991
int16 CosAy = DSP1_Cos(DSP1.Op21Yr);
992
int16 SinAx = DSP1_Sin(DSP1.Op21Xr);
993
int16 CosAx = DSP1_Cos(DSP1.Op21Xr);
994
995
DSP1.Op21m >>= 1;
996
997
DSP1.matrixC[0][0] = (DSP1.Op21m * CosAz >> 15) * CosAy >> 15;
998
DSP1.matrixC[0][1] = -((DSP1.Op21m * SinAz >> 15) * CosAy >> 15);
999
DSP1.matrixC[0][2] = DSP1.Op21m * SinAy >> 15;
1000
1001
DSP1.matrixC[1][0] = ((DSP1.Op21m * SinAz >> 15) * CosAx >> 15) + (((DSP1.Op21m * CosAz >> 15) * SinAx >> 15) * SinAy >> 15);
1002
DSP1.matrixC[1][1] = ((DSP1.Op21m * CosAz >> 15) * CosAx >> 15) - (((DSP1.Op21m * SinAz >> 15) * SinAx >> 15) * SinAy >> 15);
1003
DSP1.matrixC[1][2] = -((DSP1.Op21m * SinAx >> 15) * CosAy >> 15);
1004
1005
DSP1.matrixC[2][0] = ((DSP1.Op21m * SinAz >> 15) * SinAx >> 15) - (((DSP1.Op21m * CosAz >> 15) * CosAx >> 15) * SinAy >> 15);
1006
DSP1.matrixC[2][1] = ((DSP1.Op21m * CosAz >> 15) * SinAx >> 15) + (((DSP1.Op21m * SinAz >> 15) * CosAx >> 15) * SinAy >> 15);
1007
DSP1.matrixC[2][2] = (DSP1.Op21m * CosAx >> 15) * CosAy >> 15;
1008
}
1009
1010
static void DSP1_Op0D (void)
1011
{
1012
DSP1.Op0DF = (DSP1.Op0DX * DSP1.matrixA[0][0] >> 15) + (DSP1.Op0DY * DSP1.matrixA[0][1] >> 15) + (DSP1.Op0DZ * DSP1.matrixA[0][2] >> 15);
1013
DSP1.Op0DL = (DSP1.Op0DX * DSP1.matrixA[1][0] >> 15) + (DSP1.Op0DY * DSP1.matrixA[1][1] >> 15) + (DSP1.Op0DZ * DSP1.matrixA[1][2] >> 15);
1014
DSP1.Op0DU = (DSP1.Op0DX * DSP1.matrixA[2][0] >> 15) + (DSP1.Op0DY * DSP1.matrixA[2][1] >> 15) + (DSP1.Op0DZ * DSP1.matrixA[2][2] >> 15);
1015
1016
#ifdef DebugDSP1
1017
Log_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);
1018
#endif
1019
}
1020
1021
static void DSP1_Op1D (void)
1022
{
1023
DSP1.Op1DF = (DSP1.Op1DX * DSP1.matrixB[0][0] >> 15) + (DSP1.Op1DY * DSP1.matrixB[0][1] >> 15) + (DSP1.Op1DZ * DSP1.matrixB[0][2] >> 15);
1024
DSP1.Op1DL = (DSP1.Op1DX * DSP1.matrixB[1][0] >> 15) + (DSP1.Op1DY * DSP1.matrixB[1][1] >> 15) + (DSP1.Op1DZ * DSP1.matrixB[1][2] >> 15);
1025
DSP1.Op1DU = (DSP1.Op1DX * DSP1.matrixB[2][0] >> 15) + (DSP1.Op1DY * DSP1.matrixB[2][1] >> 15) + (DSP1.Op1DZ * DSP1.matrixB[2][2] >> 15);
1026
1027
#ifdef DebugDSP1
1028
Log_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);
1029
#endif
1030
}
1031
1032
static void DSP1_Op2D (void)
1033
{
1034
DSP1.Op2DF = (DSP1.Op2DX * DSP1.matrixC[0][0] >> 15) + (DSP1.Op2DY * DSP1.matrixC[0][1] >> 15) + (DSP1.Op2DZ * DSP1.matrixC[0][2] >> 15);
1035
DSP1.Op2DL = (DSP1.Op2DX * DSP1.matrixC[1][0] >> 15) + (DSP1.Op2DY * DSP1.matrixC[1][1] >> 15) + (DSP1.Op2DZ * DSP1.matrixC[1][2] >> 15);
1036
DSP1.Op2DU = (DSP1.Op2DX * DSP1.matrixC[2][0] >> 15) + (DSP1.Op2DY * DSP1.matrixC[2][1] >> 15) + (DSP1.Op2DZ * DSP1.matrixC[2][2] >> 15);
1037
1038
#ifdef DebugDSP1
1039
Log_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);
1040
#endif
1041
}
1042
1043
static void DSP1_Op03 (void)
1044
{
1045
DSP1.Op03X = (DSP1.Op03F * DSP1.matrixA[0][0] >> 15) + (DSP1.Op03L * DSP1.matrixA[1][0] >> 15) + (DSP1.Op03U * DSP1.matrixA[2][0] >> 15);
1046
DSP1.Op03Y = (DSP1.Op03F * DSP1.matrixA[0][1] >> 15) + (DSP1.Op03L * DSP1.matrixA[1][1] >> 15) + (DSP1.Op03U * DSP1.matrixA[2][1] >> 15);
1047
DSP1.Op03Z = (DSP1.Op03F * DSP1.matrixA[0][2] >> 15) + (DSP1.Op03L * DSP1.matrixA[1][2] >> 15) + (DSP1.Op03U * DSP1.matrixA[2][2] >> 15);
1048
1049
#ifdef DebugDSP1
1050
Log_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);
1051
#endif
1052
}
1053
1054
static void DSP1_Op13 (void)
1055
{
1056
DSP1.Op13X = (DSP1.Op13F * DSP1.matrixB[0][0] >> 15) + (DSP1.Op13L * DSP1.matrixB[1][0] >> 15) + (DSP1.Op13U * DSP1.matrixB[2][0] >> 15);
1057
DSP1.Op13Y = (DSP1.Op13F * DSP1.matrixB[0][1] >> 15) + (DSP1.Op13L * DSP1.matrixB[1][1] >> 15) + (DSP1.Op13U * DSP1.matrixB[2][1] >> 15);
1058
DSP1.Op13Z = (DSP1.Op13F * DSP1.matrixB[0][2] >> 15) + (DSP1.Op13L * DSP1.matrixB[1][2] >> 15) + (DSP1.Op13U * DSP1.matrixB[2][2] >> 15);
1059
1060
#ifdef DebugDSP1
1061
Log_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);
1062
#endif
1063
}
1064
1065
static void DSP1_Op23 (void)
1066
{
1067
DSP1.Op23X = (DSP1.Op23F * DSP1.matrixC[0][0] >> 15) + (DSP1.Op23L * DSP1.matrixC[1][0] >> 15) + (DSP1.Op23U * DSP1.matrixC[2][0] >> 15);
1068
DSP1.Op23Y = (DSP1.Op23F * DSP1.matrixC[0][1] >> 15) + (DSP1.Op23L * DSP1.matrixC[1][1] >> 15) + (DSP1.Op23U * DSP1.matrixC[2][1] >> 15);
1069
DSP1.Op23Z = (DSP1.Op23F * DSP1.matrixC[0][2] >> 15) + (DSP1.Op23L * DSP1.matrixC[1][2] >> 15) + (DSP1.Op23U * DSP1.matrixC[2][2] >> 15);
1070
1071
#ifdef DebugDSP1
1072
Log_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);
1073
#endif
1074
}
1075
1076
static void DSP1_Op14 (void)
1077
{
1078
int16 CSec, ESec, CTan, CSin, C, E;
1079
1080
DSP1_Inverse(DSP1_Cos(DSP1.Op14Xr), 0, &CSec, &ESec);
1081
1082
// Rotation Around Z
1083
DSP1_NormalizeDouble(DSP1.Op14U * DSP1_Cos(DSP1.Op14Yr) - DSP1.Op14F * DSP1_Sin(DSP1.Op14Yr), &C, &E);
1084
1085
E = ESec - E;
1086
1087
DSP1_Normalize(C * CSec >> 15, &C, &E);
1088
1089
DSP1.Op14Zrr = DSP1.Op14Zr + DSP1_Truncate(C, E);
1090
1091
// Rotation Around X
1092
DSP1.Op14Xrr = DSP1.Op14Xr + (DSP1.Op14U * DSP1_Sin(DSP1.Op14Yr) >> 15) + (DSP1.Op14F * DSP1_Cos(DSP1.Op14Yr) >> 15);
1093
1094
// Rotation Around Y
1095
DSP1_NormalizeDouble(DSP1.Op14U * DSP1_Cos(DSP1.Op14Yr) + DSP1.Op14F * DSP1_Sin(DSP1.Op14Yr), &C, &E);
1096
1097
E = ESec - E;
1098
1099
DSP1_Normalize(DSP1_Sin(DSP1.Op14Xr), &CSin, &E);
1100
1101
CTan = CSec * CSin >> 15;
1102
1103
DSP1_Normalize(-(C * CTan >> 15), &C, &E);
1104
1105
DSP1.Op14Yrr = DSP1.Op14Yr + DSP1_Truncate(C, E) + DSP1.Op14L;
1106
}
1107
1108
static void DSP1_Target (int16 H, int16 V, int16 *X, int16 *Y)
1109
{
1110
int16 C, E, C1, E1;
1111
1112
DSP1_Inverse((V * DSP1.SinAzs >> 15) + DSP1.VOffset, 8, &C, &E);
1113
E += DSP1.VPlane_E;
1114
1115
C1 = C * DSP1.VPlane_C >> 15;
1116
E1 = E + DSP1.SecAZS_E1;
1117
1118
H <<= 8;
1119
1120
DSP1_Normalize(C1, &C, &E);
1121
1122
C = DSP1_Truncate(C, E) * H >> 15;
1123
1124
*X = DSP1.CentreX + (C * DSP1.CosAas >> 15);
1125
*Y = DSP1.CentreY - (C * DSP1.SinAas >> 15);
1126
1127
V <<= 8;
1128
1129
DSP1_Normalize(C1 * DSP1.SecAZS_C1 >> 15, &C, &E1);
1130
1131
C = DSP1_Truncate(C, E1) * V >> 15;
1132
1133
*X += C * -DSP1.SinAas >> 15;
1134
*Y += C * DSP1.CosAas >> 15;
1135
}
1136
1137
static void DSP1_Op0E (void)
1138
{
1139
DSP1_Target(DSP1.Op0EH, DSP1.Op0EV, &DSP1.Op0EX, &DSP1.Op0EY);
1140
}
1141
1142
static void DSP1_Op0B (void)
1143
{
1144
DSP1.Op0BS = (DSP1.Op0BX * DSP1.matrixA[0][0] + DSP1.Op0BY * DSP1.matrixA[0][1] + DSP1.Op0BZ * DSP1.matrixA[0][2]) >> 15;
1145
1146
#ifdef DebugDSP1
1147
Log_Message("OP0B");
1148
#endif
1149
}
1150
1151
static void DSP1_Op1B (void)
1152
{
1153
DSP1.Op1BS = (DSP1.Op1BX * DSP1.matrixB[0][0] + DSP1.Op1BY * DSP1.matrixB[0][1] + DSP1.Op1BZ * DSP1.matrixB[0][2]) >> 15;
1154
1155
#ifdef DebugDSP1
1156
Log_Message("OP1B X: %d Y: %d Z: %d S: %d", DSP1.Op1BX, DSP1.Op1BY, DSP1.Op1BZ, DSP1.Op1BS);
1157
Log_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));
1158
#endif
1159
}
1160
1161
static void DSP1_Op2B (void)
1162
{
1163
DSP1.Op2BS = (DSP1.Op2BX * DSP1.matrixC[0][0] + DSP1.Op2BY * DSP1.matrixC[0][1] + DSP1.Op2BZ * DSP1.matrixC[0][2]) >> 15;
1164
1165
#ifdef DebugDSP1
1166
Log_Message("OP2B");
1167
#endif
1168
}
1169
1170
static void DSP1_Op08 (void)
1171
{
1172
int32 op08Size = (DSP1.Op08X * DSP1.Op08X + DSP1.Op08Y * DSP1.Op08Y + DSP1.Op08Z * DSP1.Op08Z) << 1;
1173
DSP1.Op08Ll = op08Size & 0xffff;
1174
DSP1.Op08Lh = (op08Size >> 16) & 0xffff;
1175
1176
#ifdef DebugDSP1
1177
Log_Message("OP08 %d,%d,%d", DSP1.Op08X, DSP1.Op08Y, DSP1.Op08Z);
1178
Log_Message("OP08 ((OP08X^2)+(OP08Y^2)+(OP08Z^2))=%x", op08Size);
1179
#endif
1180
}
1181
1182
static void DSP1_Op18 (void)
1183
{
1184
DSP1.Op18D = (DSP1.Op18X * DSP1.Op18X + DSP1.Op18Y * DSP1.Op18Y + DSP1.Op18Z * DSP1.Op18Z - DSP1.Op18R * DSP1.Op18R) >> 15;
1185
1186
#ifdef DebugDSP1
1187
Log_Message("OP18 X: %d Y: %d Z: %d R: %D DIFF %d", DSP1.Op18X, DSP1.Op18Y, DSP1.Op38Z, DSP1.Op18D);
1188
#endif
1189
}
1190
1191
static void DSP1_Op38 (void)
1192
{
1193
DSP1.Op38D = (DSP1.Op38X * DSP1.Op38X + DSP1.Op38Y * DSP1.Op38Y + DSP1.Op38Z * DSP1.Op38Z - DSP1.Op38R * DSP1.Op38R) >> 15;
1194
DSP1.Op38D++;
1195
1196
#ifdef DebugDSP1
1197
Log_Message("OP38 X: %d Y: %d Z: %d R: %D DIFF %d", DSP1.Op38X, DSP1.Op38Y, DSP1.Op38Z, DSP1.Op38D);
1198
#endif
1199
}
1200
1201
static void DSP1_Op28 (void)
1202
{
1203
int32 Radius = DSP1.Op28X * DSP1.Op28X + DSP1.Op28Y * DSP1.Op28Y + DSP1.Op28Z * DSP1.Op28Z;
1204
1205
if (Radius == 0)
1206
DSP1.Op28R = 0;
1207
else
1208
{
1209
int16 C, E, Pos, Node1, Node2;
1210
1211
DSP1_NormalizeDouble(Radius, &C, &E);
1212
if (E & 1)
1213
C = C * 0x4000 >> 15;
1214
1215
Pos = C * 0x0040 >> 15;
1216
1217
Node1 = DSP1ROM[0x00d5 + Pos];
1218
Node2 = DSP1ROM[0x00d6 + Pos];
1219
1220
DSP1.Op28R = ((Node2 - Node1) * (C & 0x1ff) >> 9) + Node1;
1221
DSP1.Op28R >>= (E >> 1);
1222
}
1223
1224
#ifdef DebugDSP1
1225
Log_Message("OP28 X:%d Y:%d Z:%d", DSP1.Op28X, DSP1.Op28Y, DSP1.Op28Z);
1226
Log_Message("OP28 Vector Length %d", DSP1.Op28R);
1227
#endif
1228
}
1229
1230
static void DSP1_Op1C (void)
1231
{
1232
// Rotate Around Op1CZ1
1233
DSP1.Op1CX1 = (DSP1.Op1CYBR * DSP1_Sin(DSP1.Op1CZ) >> 15) + (DSP1.Op1CXBR * DSP1_Cos(DSP1.Op1CZ) >> 15);
1234
DSP1.Op1CY1 = (DSP1.Op1CYBR * DSP1_Cos(DSP1.Op1CZ) >> 15) - (DSP1.Op1CXBR * DSP1_Sin(DSP1.Op1CZ) >> 15);
1235
DSP1.Op1CXBR = DSP1.Op1CX1;
1236
DSP1.Op1CYBR = DSP1.Op1CY1;
1237
1238
// Rotate Around Op1CY1
1239
DSP1.Op1CZ1 = (DSP1.Op1CXBR * DSP1_Sin(DSP1.Op1CY) >> 15) + (DSP1.Op1CZBR * DSP1_Cos(DSP1.Op1CY) >> 15);
1240
DSP1.Op1CX1 = (DSP1.Op1CXBR * DSP1_Cos(DSP1.Op1CY) >> 15) - (DSP1.Op1CZBR * DSP1_Sin(DSP1.Op1CY) >> 15);
1241
DSP1.Op1CXAR = DSP1.Op1CX1;
1242
DSP1.Op1CZBR = DSP1.Op1CZ1;
1243
1244
// Rotate Around Op1CX1
1245
DSP1.Op1CY1 = (DSP1.Op1CZBR * DSP1_Sin(DSP1.Op1CX) >> 15) + (DSP1.Op1CYBR * DSP1_Cos(DSP1.Op1CX) >> 15);
1246
DSP1.Op1CZ1 = (DSP1.Op1CZBR * DSP1_Cos(DSP1.Op1CX) >> 15) - (DSP1.Op1CYBR * DSP1_Sin(DSP1.Op1CX) >> 15);
1247
DSP1.Op1CYAR = DSP1.Op1CY1;
1248
DSP1.Op1CZAR = DSP1.Op1CZ1;
1249
1250
#ifdef DebugDSP1
1251
Log_Message("OP1C Apply Matrix CX:%d CY:%d CZ", DSP1.Op1CXAR, DSP1.Op1CYAR, DSP1.Op1CZAR);
1252
#endif
1253
}
1254
1255
static void DSP1_Op0F (void)
1256
{
1257
DSP1.Op0FPass = 0x0000;
1258
1259
#ifdef DebugDSP1
1260
Log_Message("OP0F RAM Test Pass:%d", DSP1.Op0FPass);
1261
#endif
1262
}
1263
1264
static void DSP1_Op2F (void)
1265
{
1266
DSP1.Op2FSize = 0x100;
1267
}
1268
1269
void DSP1SetByte (uint8 byte, uint16 address)
1270
{
1271
if (address < DSP0.boundary)
1272
{
1273
if ((DSP1.command == 0x0A || DSP1.command == 0x1A) && DSP1.out_count != 0)
1274
{
1275
DSP1.out_count--;
1276
DSP1.out_index++;
1277
return;
1278
}
1279
else
1280
if (DSP1.waiting4command)
1281
{
1282
DSP1.command = byte;
1283
DSP1.in_index = 0;
1284
DSP1.waiting4command = FALSE;
1285
DSP1.first_parameter = TRUE;
1286
#ifdef DEBUGGER
1287
//printf("OP%02X\n",byte);
1288
#endif
1289
1290
switch (byte)
1291
{
1292
case 0x00: DSP1.in_count = 2; break;
1293
case 0x30:
1294
case 0x10: DSP1.in_count = 2; break;
1295
case 0x20: DSP1.in_count = 2; break;
1296
case 0x24:
1297
case 0x04: DSP1.in_count = 2; break;
1298
case 0x08: DSP1.in_count = 3; break;
1299
case 0x18: DSP1.in_count = 4; break;
1300
case 0x28: DSP1.in_count = 3; break;
1301
case 0x38: DSP1.in_count = 4; break;
1302
case 0x2c:
1303
case 0x0c: DSP1.in_count = 3; break;
1304
case 0x3c:
1305
case 0x1c: DSP1.in_count = 6; break;
1306
case 0x32:
1307
case 0x22:
1308
case 0x12:
1309
case 0x02: DSP1.in_count = 7; break;
1310
case 0x0a: DSP1.in_count = 1; break;
1311
case 0x3a:
1312
case 0x2a:
1313
case 0x1a:
1314
DSP1.command = 0x1a;
1315
DSP1.in_count = 1;
1316
break;
1317
case 0x16:
1318
case 0x26:
1319
case 0x36:
1320
case 0x06: DSP1.in_count = 3; break;
1321
case 0x1e:
1322
case 0x2e:
1323
case 0x3e:
1324
case 0x0e: DSP1.in_count = 2; break;
1325
case 0x05:
1326
case 0x35:
1327
case 0x31:
1328
case 0x01: DSP1.in_count = 4; break;
1329
case 0x15:
1330
case 0x11: DSP1.in_count = 4; break;
1331
case 0x25:
1332
case 0x21: DSP1.in_count = 4; break;
1333
case 0x09:
1334
case 0x39:
1335
case 0x3d:
1336
case 0x0d: DSP1.in_count = 3; break;
1337
case 0x19:
1338
case 0x1d: DSP1.in_count = 3; break;
1339
case 0x29:
1340
case 0x2d: DSP1.in_count = 3; break;
1341
case 0x33:
1342
case 0x03: DSP1.in_count = 3; break;
1343
case 0x13: DSP1.in_count = 3; break;
1344
case 0x23: DSP1.in_count = 3; break;
1345
case 0x3b:
1346
case 0x0b: DSP1.in_count = 3; break;
1347
case 0x1b: DSP1.in_count = 3; break;
1348
case 0x2b: DSP1.in_count = 3; break;
1349
case 0x34:
1350
case 0x14: DSP1.in_count = 6; break;
1351
case 0x07:
1352
case 0x0f: DSP1.in_count = 1; break;
1353
case 0x27:
1354
case 0x2F: DSP1.in_count = 1; break;
1355
case 0x17:
1356
case 0x37:
1357
case 0x3F:
1358
DSP1.command = 0x1f;
1359
case 0x1f: DSP1.in_count = 1; break;
1360
default:
1361
#ifdef DEBUGGER
1362
//printf("OP%02X\n", byte);
1363
#endif
1364
case 0x80:
1365
DSP1.in_count = 0;
1366
DSP1.waiting4command = TRUE;
1367
DSP1.first_parameter = TRUE;
1368
break;
1369
}
1370
1371
DSP1.in_count <<= 1;
1372
}
1373
else
1374
{
1375
DSP1.parameters[DSP1.in_index] = byte;
1376
DSP1.first_parameter = FALSE;
1377
DSP1.in_index++;
1378
}
1379
1380
if (DSP1.waiting4command || (DSP1.first_parameter && byte == 0x80))
1381
{
1382
DSP1.waiting4command = TRUE;
1383
DSP1.first_parameter = FALSE;
1384
}
1385
else
1386
if (DSP1.first_parameter && (DSP1.in_count != 0 || (DSP1.in_count == 0 && DSP1.in_index == 0)))
1387
;
1388
else
1389
{
1390
if (DSP1.in_count)
1391
{
1392
if (--DSP1.in_count == 0)
1393
{
1394
// Actually execute the command
1395
DSP1.waiting4command = TRUE;
1396
DSP1.out_index = 0;
1397
1398
switch (DSP1.command)
1399
{
1400
case 0x1f:
1401
DSP1.out_count = 2048;
1402
break;
1403
1404
case 0x00: // Multiple
1405
DSP1.Op00Multiplicand = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1406
DSP1.Op00Multiplier = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1407
1408
DSP1_Op00();
1409
1410
DSP1.out_count = 2;
1411
DSP1.output[0] = DSP1.Op00Result & 0xFF;
1412
DSP1.output[1] = (DSP1.Op00Result >> 8) & 0xFF;
1413
break;
1414
1415
case 0x20: // Multiple
1416
DSP1.Op20Multiplicand = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1417
DSP1.Op20Multiplier = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1418
1419
DSP1_Op20();
1420
1421
DSP1.out_count = 2;
1422
DSP1.output[0] = DSP1.Op20Result & 0xFF;
1423
DSP1.output[1] = (DSP1.Op20Result >> 8) & 0xFF;
1424
break;
1425
1426
case 0x30:
1427
case 0x10: // Inverse
1428
DSP1.Op10Coefficient = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1429
DSP1.Op10Exponent = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1430
1431
DSP1_Op10();
1432
1433
DSP1.out_count = 4;
1434
DSP1.output[0] = (uint8) ( ((int16) DSP1.Op10CoefficientR) & 0xFF);
1435
DSP1.output[1] = (uint8) ((((int16) DSP1.Op10CoefficientR) >> 8) & 0xFF);
1436
DSP1.output[2] = (uint8) ( ((int16) DSP1.Op10ExponentR ) & 0xFF);
1437
DSP1.output[3] = (uint8) ((((int16) DSP1.Op10ExponentR ) >> 8) & 0xFF);
1438
break;
1439
1440
case 0x24:
1441
case 0x04: // Sin and Cos of angle
1442
DSP1.Op04Angle = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1443
DSP1.Op04Radius = (uint16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1444
1445
DSP1_Op04();
1446
1447
DSP1.out_count = 4;
1448
DSP1.output[0] = (uint8) (DSP1.Op04Sin & 0xFF);
1449
DSP1.output[1] = (uint8) ((DSP1.Op04Sin >> 8) & 0xFF);
1450
DSP1.output[2] = (uint8) (DSP1.Op04Cos & 0xFF);
1451
DSP1.output[3] = (uint8) ((DSP1.Op04Cos >> 8) & 0xFF);
1452
break;
1453
1454
case 0x08: // Radius
1455
DSP1.Op08X = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1456
DSP1.Op08Y = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1457
DSP1.Op08Z = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1458
1459
DSP1_Op08();
1460
1461
DSP1.out_count = 4;
1462
DSP1.output[0] = (uint8) ( ((int16) DSP1.Op08Ll) & 0xFF);
1463
DSP1.output[1] = (uint8) ((((int16) DSP1.Op08Ll) >> 8) & 0xFF);
1464
DSP1.output[2] = (uint8) ( ((int16) DSP1.Op08Lh) & 0xFF);
1465
DSP1.output[3] = (uint8) ((((int16) DSP1.Op08Lh) >> 8) & 0xFF);
1466
break;
1467
1468
case 0x18: // Range
1469
1470
DSP1.Op18X = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1471
DSP1.Op18Y = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1472
DSP1.Op18Z = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1473
DSP1.Op18R = (int16) (DSP1.parameters[6] | (DSP1.parameters[7] << 8));
1474
1475
DSP1_Op18();
1476
1477
DSP1.out_count = 2;
1478
DSP1.output[0] = (uint8) (DSP1.Op18D & 0xFF);
1479
DSP1.output[1] = (uint8) ((DSP1.Op18D >> 8) & 0xFF);
1480
break;
1481
1482
case 0x38: // Range
1483
1484
DSP1.Op38X = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1485
DSP1.Op38Y = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1486
DSP1.Op38Z = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1487
DSP1.Op38R = (int16) (DSP1.parameters[6] | (DSP1.parameters[7] << 8));
1488
1489
DSP1_Op38();
1490
1491
DSP1.out_count = 2;
1492
DSP1.output[0] = (uint8) (DSP1.Op38D & 0xFF);
1493
DSP1.output[1] = (uint8) ((DSP1.Op38D >> 8) & 0xFF);
1494
break;
1495
1496
case 0x28: // Distance (vector length)
1497
DSP1.Op28X = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1498
DSP1.Op28Y = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1499
DSP1.Op28Z = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1500
1501
DSP1_Op28();
1502
1503
DSP1.out_count = 2;
1504
DSP1.output[0] = (uint8) (DSP1.Op28R & 0xFF);
1505
DSP1.output[1] = (uint8) ((DSP1.Op28R >> 8) & 0xFF);
1506
break;
1507
1508
case 0x2c:
1509
case 0x0c: // Rotate (2D rotate)
1510
DSP1.Op0CA = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1511
DSP1.Op0CX1 = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1512
DSP1.Op0CY1 = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1513
1514
DSP1_Op0C();
1515
1516
DSP1.out_count = 4;
1517
DSP1.output[0] = (uint8) (DSP1.Op0CX2 & 0xFF);
1518
DSP1.output[1] = (uint8) ((DSP1.Op0CX2 >> 8) & 0xFF);
1519
DSP1.output[2] = (uint8) (DSP1.Op0CY2 & 0xFF);
1520
DSP1.output[3] = (uint8) ((DSP1.Op0CY2 >> 8) & 0xFF);
1521
break;
1522
1523
case 0x3c:
1524
case 0x1c: // Polar (3D rotate)
1525
DSP1.Op1CZ = (DSP1.parameters[ 0] | (DSP1.parameters[ 1] << 8));
1526
//MK: reversed X and Y on neviksti and John's advice.
1527
DSP1.Op1CY = (DSP1.parameters[ 2] | (DSP1.parameters[ 3] << 8));
1528
DSP1.Op1CX = (DSP1.parameters[ 4] | (DSP1.parameters[ 5] << 8));
1529
DSP1.Op1CXBR = (DSP1.parameters[ 6] | (DSP1.parameters[ 7] << 8));
1530
DSP1.Op1CYBR = (DSP1.parameters[ 8] | (DSP1.parameters[ 9] << 8));
1531
DSP1.Op1CZBR = (DSP1.parameters[10] | (DSP1.parameters[11] << 8));
1532
1533
DSP1_Op1C();
1534
1535
DSP1.out_count = 6;
1536
DSP1.output[0] = (uint8) (DSP1.Op1CXAR & 0xFF);
1537
DSP1.output[1] = (uint8) ((DSP1.Op1CXAR >> 8) & 0xFF);
1538
DSP1.output[2] = (uint8) (DSP1.Op1CYAR & 0xFF);
1539
DSP1.output[3] = (uint8) ((DSP1.Op1CYAR >> 8) & 0xFF);
1540
DSP1.output[4] = (uint8) (DSP1.Op1CZAR & 0xFF);
1541
DSP1.output[5] = (uint8) ((DSP1.Op1CZAR >> 8) & 0xFF);
1542
break;
1543
1544
case 0x32:
1545
case 0x22:
1546
case 0x12:
1547
case 0x02: // Parameter (Projection)
1548
DSP1.Op02FX = (int16) (DSP1.parameters[ 0] | (DSP1.parameters[ 1] << 8));
1549
DSP1.Op02FY = (int16) (DSP1.parameters[ 2] | (DSP1.parameters[ 3] << 8));
1550
DSP1.Op02FZ = (int16) (DSP1.parameters[ 4] | (DSP1.parameters[ 5] << 8));
1551
DSP1.Op02LFE = (int16) (DSP1.parameters[ 6] | (DSP1.parameters[ 7] << 8));
1552
DSP1.Op02LES = (int16) (DSP1.parameters[ 8] | (DSP1.parameters[ 9] << 8));
1553
DSP1.Op02AAS = (uint16) (DSP1.parameters[10] | (DSP1.parameters[11] << 8));
1554
DSP1.Op02AZS = (uint16) (DSP1.parameters[12] | (DSP1.parameters[13] << 8));
1555
1556
DSP1_Op02();
1557
1558
DSP1.out_count = 8;
1559
DSP1.output[0] = (uint8) (DSP1.Op02VOF & 0xFF);
1560
DSP1.output[1] = (uint8) ((DSP1.Op02VOF >> 8) & 0xFF);
1561
DSP1.output[2] = (uint8) (DSP1.Op02VVA & 0xFF);
1562
DSP1.output[3] = (uint8) ((DSP1.Op02VVA >> 8) & 0xFF);
1563
DSP1.output[4] = (uint8) (DSP1.Op02CX & 0xFF);
1564
DSP1.output[5] = (uint8) ((DSP1.Op02CX >> 8) & 0xFF);
1565
DSP1.output[6] = (uint8) (DSP1.Op02CY & 0xFF);
1566
DSP1.output[7] = (uint8) ((DSP1.Op02CY >> 8) & 0xFF);
1567
break;
1568
1569
case 0x3a:
1570
case 0x2a:
1571
case 0x1a: // Raster mode 7 matrix data
1572
case 0x0a:
1573
DSP1.Op0AVS = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1574
1575
DSP1_Op0A();
1576
1577
DSP1.out_count = 8;
1578
DSP1.output[0] = (uint8) (DSP1.Op0AA & 0xFF);
1579
DSP1.output[1] = (uint8) ((DSP1.Op0AA >> 8) & 0xFF);
1580
DSP1.output[2] = (uint8) (DSP1.Op0AB & 0xFF);
1581
DSP1.output[3] = (uint8) ((DSP1.Op0AB >> 8) & 0xFF);
1582
DSP1.output[4] = (uint8) (DSP1.Op0AC & 0xFF);
1583
DSP1.output[5] = (uint8) ((DSP1.Op0AC >> 8) & 0xFF);
1584
DSP1.output[6] = (uint8) (DSP1.Op0AD & 0xFF);
1585
DSP1.output[7] = (uint8) ((DSP1.Op0AD >> 8) & 0xFF);
1586
DSP1.in_index = 0;
1587
break;
1588
1589
case 0x16:
1590
case 0x26:
1591
case 0x36:
1592
case 0x06: // Project object
1593
DSP1.Op06X = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1594
DSP1.Op06Y = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1595
DSP1.Op06Z = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1596
1597
DSP1_Op06();
1598
1599
DSP1.out_count = 6;
1600
DSP1.output[0] = (uint8) (DSP1.Op06H & 0xFF);
1601
DSP1.output[1] = (uint8) ((DSP1.Op06H >> 8) & 0xFF);
1602
DSP1.output[2] = (uint8) (DSP1.Op06V & 0xFF);
1603
DSP1.output[3] = (uint8) ((DSP1.Op06V >> 8) & 0xFF);
1604
DSP1.output[4] = (uint8) (DSP1.Op06M & 0xFF);
1605
DSP1.output[5] = (uint8) ((DSP1.Op06M >> 8) & 0xFF);
1606
break;
1607
1608
case 0x1e:
1609
case 0x2e:
1610
case 0x3e:
1611
case 0x0e: // Target
1612
DSP1.Op0EH = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1613
DSP1.Op0EV = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1614
1615
DSP1_Op0E();
1616
1617
DSP1.out_count = 4;
1618
DSP1.output[0] = (uint8) (DSP1.Op0EX & 0xFF);
1619
DSP1.output[1] = (uint8) ((DSP1.Op0EX >> 8) & 0xFF);
1620
DSP1.output[2] = (uint8) (DSP1.Op0EY & 0xFF);
1621
DSP1.output[3] = (uint8) ((DSP1.Op0EY >> 8) & 0xFF);
1622
break;
1623
1624
// Extra commands used by Pilot Wings
1625
case 0x05:
1626
case 0x35:
1627
case 0x31:
1628
case 0x01: // Set attitude matrix A
1629
DSP1.Op01m = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1630
DSP1.Op01Zr = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1631
DSP1.Op01Yr = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1632
DSP1.Op01Xr = (int16) (DSP1.parameters[6] | (DSP1.parameters[7] << 8));
1633
1634
DSP1_Op01();
1635
break;
1636
1637
case 0x15:
1638
case 0x11: // Set attitude matrix B
1639
DSP1.Op11m = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1640
DSP1.Op11Zr = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1641
DSP1.Op11Yr = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1642
DSP1.Op11Xr = (int16) (DSP1.parameters[7] | (DSP1.parameters[7] << 8));
1643
1644
DSP1_Op11();
1645
break;
1646
1647
case 0x25:
1648
case 0x21: // Set attitude matrix C
1649
DSP1.Op21m = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1650
DSP1.Op21Zr = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1651
DSP1.Op21Yr = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1652
DSP1.Op21Xr = (int16) (DSP1.parameters[6] | (DSP1.parameters[7] << 8));
1653
1654
DSP1_Op21();
1655
break;
1656
1657
case 0x09:
1658
case 0x39:
1659
case 0x3d:
1660
case 0x0d: // Objective matrix A
1661
DSP1.Op0DX = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1662
DSP1.Op0DY = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1663
DSP1.Op0DZ = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1664
1665
DSP1_Op0D();
1666
1667
DSP1.out_count = 6;
1668
DSP1.output [0] = (uint8) (DSP1.Op0DF & 0xFF);
1669
DSP1.output [1] = (uint8) ((DSP1.Op0DF >> 8) & 0xFF);
1670
DSP1.output [2] = (uint8) (DSP1.Op0DL & 0xFF);
1671
DSP1.output [3] = (uint8) ((DSP1.Op0DL >> 8) & 0xFF);
1672
DSP1.output [4] = (uint8) (DSP1.Op0DU & 0xFF);
1673
DSP1.output [5] = (uint8) ((DSP1.Op0DU >> 8) & 0xFF);
1674
break;
1675
1676
case 0x19:
1677
case 0x1d: // Objective matrix B
1678
DSP1.Op1DX = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1679
DSP1.Op1DY = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1680
DSP1.Op1DZ = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1681
1682
DSP1_Op1D();
1683
1684
DSP1.out_count = 6;
1685
DSP1.output[0] = (uint8) (DSP1.Op1DF & 0xFF);
1686
DSP1.output[1] = (uint8) ((DSP1.Op1DF >> 8) & 0xFF);
1687
DSP1.output[2] = (uint8) (DSP1.Op1DL & 0xFF);
1688
DSP1.output[3] = (uint8) ((DSP1.Op1DL >> 8) & 0xFF);
1689
DSP1.output[4] = (uint8) (DSP1.Op1DU & 0xFF);
1690
DSP1.output[5] = (uint8) ((DSP1.Op1DU >> 8) & 0xFF);
1691
break;
1692
1693
case 0x29:
1694
case 0x2d: // Objective matrix C
1695
DSP1.Op2DX = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1696
DSP1.Op2DY = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1697
DSP1.Op2DZ = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1698
1699
DSP1_Op2D();
1700
1701
DSP1.out_count = 6;
1702
DSP1.output[0] = (uint8) (DSP1.Op2DF & 0xFF);
1703
DSP1.output[1] = (uint8) ((DSP1.Op2DF >> 8) & 0xFF);
1704
DSP1.output[2] = (uint8) (DSP1.Op2DL & 0xFF);
1705
DSP1.output[3] = (uint8) ((DSP1.Op2DL >> 8) & 0xFF);
1706
DSP1.output[4] = (uint8) (DSP1.Op2DU & 0xFF);
1707
DSP1.output[5] = (uint8) ((DSP1.Op2DU >> 8) & 0xFF);
1708
break;
1709
1710
case 0x33:
1711
case 0x03: // Subjective matrix A
1712
DSP1.Op03F = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1713
DSP1.Op03L = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1714
DSP1.Op03U = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1715
1716
DSP1_Op03();
1717
1718
DSP1.out_count = 6;
1719
DSP1.output[0] = (uint8) (DSP1.Op03X & 0xFF);
1720
DSP1.output[1] = (uint8) ((DSP1.Op03X >> 8) & 0xFF);
1721
DSP1.output[2] = (uint8) (DSP1.Op03Y & 0xFF);
1722
DSP1.output[3] = (uint8) ((DSP1.Op03Y >> 8) & 0xFF);
1723
DSP1.output[4] = (uint8) (DSP1.Op03Z & 0xFF);
1724
DSP1.output[5] = (uint8) ((DSP1.Op03Z >> 8) & 0xFF);
1725
break;
1726
1727
case 0x13: // Subjective matrix B
1728
DSP1.Op13F = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1729
DSP1.Op13L = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1730
DSP1.Op13U = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1731
1732
DSP1_Op13();
1733
1734
DSP1.out_count = 6;
1735
DSP1.output[0] = (uint8) (DSP1.Op13X & 0xFF);
1736
DSP1.output[1] = (uint8) ((DSP1.Op13X >> 8) & 0xFF);
1737
DSP1.output[2] = (uint8) (DSP1.Op13Y & 0xFF);
1738
DSP1.output[3] = (uint8) ((DSP1.Op13Y >> 8) & 0xFF);
1739
DSP1.output[4] = (uint8) (DSP1.Op13Z & 0xFF);
1740
DSP1.output[5] = (uint8) ((DSP1.Op13Z >> 8) & 0xFF);
1741
break;
1742
1743
case 0x23: // Subjective matrix C
1744
DSP1.Op23F = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1745
DSP1.Op23L = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1746
DSP1.Op23U = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1747
1748
DSP1_Op23();
1749
1750
DSP1.out_count = 6;
1751
DSP1.output[0] = (uint8) (DSP1.Op23X & 0xFF);
1752
DSP1.output[1] = (uint8) ((DSP1.Op23X >> 8) & 0xFF);
1753
DSP1.output[2] = (uint8) (DSP1.Op23Y & 0xFF);
1754
DSP1.output[3] = (uint8) ((DSP1.Op23Y >> 8) & 0xFF);
1755
DSP1.output[4] = (uint8) (DSP1.Op23Z & 0xFF);
1756
DSP1.output[5] = (uint8) ((DSP1.Op23Z >> 8) & 0xFF);
1757
break;
1758
1759
case 0x3b:
1760
case 0x0b:
1761
DSP1.Op0BX = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1762
DSP1.Op0BY = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1763
DSP1.Op0BZ = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1764
1765
DSP1_Op0B();
1766
1767
DSP1.out_count = 2;
1768
DSP1.output[0] = (uint8) (DSP1.Op0BS & 0xFF);
1769
DSP1.output[1] = (uint8) ((DSP1.Op0BS >> 8) & 0xFF);
1770
break;
1771
1772
case 0x1b:
1773
DSP1.Op1BX = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1774
DSP1.Op1BY = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1775
DSP1.Op1BZ = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1776
1777
DSP1_Op1B();
1778
1779
DSP1.out_count = 2;
1780
DSP1.output[0] = (uint8) (DSP1.Op1BS & 0xFF);
1781
DSP1.output[1] = (uint8) ((DSP1.Op1BS >> 8) & 0xFF);
1782
break;
1783
1784
case 0x2b:
1785
DSP1.Op2BX = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1786
DSP1.Op2BY = (int16) (DSP1.parameters[2] | (DSP1.parameters[3] << 8));
1787
DSP1.Op2BZ = (int16) (DSP1.parameters[4] | (DSP1.parameters[5] << 8));
1788
1789
DSP1_Op2B();
1790
1791
DSP1.out_count = 2;
1792
DSP1.output[0] = (uint8) (DSP1.Op2BS & 0xFF);
1793
DSP1.output[1] = (uint8) ((DSP1.Op2BS >> 8) & 0xFF);
1794
break;
1795
1796
case 0x34:
1797
case 0x14:
1798
DSP1.Op14Zr = (int16) (DSP1.parameters[ 0] | (DSP1.parameters[ 1] << 8));
1799
DSP1.Op14Xr = (int16) (DSP1.parameters[ 2] | (DSP1.parameters[ 3] << 8));
1800
DSP1.Op14Yr = (int16) (DSP1.parameters[ 4] | (DSP1.parameters[ 5] << 8));
1801
DSP1.Op14U = (int16) (DSP1.parameters[ 6] | (DSP1.parameters[ 7] << 8));
1802
DSP1.Op14F = (int16) (DSP1.parameters[ 8] | (DSP1.parameters[ 9] << 8));
1803
DSP1.Op14L = (int16) (DSP1.parameters[10] | (DSP1.parameters[11] << 8));
1804
1805
DSP1_Op14();
1806
1807
DSP1.out_count = 6;
1808
DSP1.output[0] = (uint8) (DSP1.Op14Zrr & 0xFF);
1809
DSP1.output[1] = (uint8) ((DSP1.Op14Zrr >> 8) & 0xFF);
1810
DSP1.output[2] = (uint8) (DSP1.Op14Xrr & 0xFF);
1811
DSP1.output[3] = (uint8) ((DSP1.Op14Xrr >> 8) & 0xFF);
1812
DSP1.output[4] = (uint8) (DSP1.Op14Yrr & 0xFF);
1813
DSP1.output[5] = (uint8) ((DSP1.Op14Yrr >> 8) & 0xFF);
1814
break;
1815
1816
case 0x27:
1817
case 0x2F:
1818
DSP1.Op2FUnknown = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1819
1820
DSP1_Op2F();
1821
1822
DSP1.out_count = 2;
1823
DSP1.output[0] = (uint8) (DSP1.Op2FSize & 0xFF);
1824
DSP1.output[1] = (uint8) ((DSP1.Op2FSize >> 8) & 0xFF);
1825
break;
1826
1827
1828
case 0x07:
1829
case 0x0F:
1830
DSP1.Op0FRamsize = (int16) (DSP1.parameters[0] | (DSP1.parameters[1] << 8));
1831
1832
DSP1_Op0F();
1833
1834
DSP1.out_count = 2;
1835
DSP1.output[0] = (uint8) (DSP1.Op0FPass & 0xFF);
1836
DSP1.output[1] = (uint8) ((DSP1.Op0FPass >> 8) & 0xFF);
1837
break;
1838
1839
default:
1840
break;
1841
}
1842
}
1843
}
1844
}
1845
}
1846
}
1847
1848
uint8 DSP1GetByte (uint16 address)
1849
{
1850
uint8 t;
1851
1852
if (address < DSP0.boundary)
1853
{
1854
if (DSP1.out_count)
1855
{
1856
t = (uint8) DSP1.output[DSP1.out_index];
1857
1858
DSP1.out_index++;
1859
1860
if (--DSP1.out_count == 0)
1861
{
1862
if (DSP1.command == 0x1a || DSP1.command == 0x0a)
1863
{
1864
DSP1_Op0A();
1865
DSP1.out_count = 8;
1866
DSP1.out_index = 0;
1867
DSP1.output[0] = DSP1.Op0AA & 0xFF;
1868
DSP1.output[1] = (DSP1.Op0AA >> 8) & 0xFF;
1869
DSP1.output[2] = DSP1.Op0AB & 0xFF;
1870
DSP1.output[3] = (DSP1.Op0AB >> 8) & 0xFF;
1871
DSP1.output[4] = DSP1.Op0AC & 0xFF;
1872
DSP1.output[5] = (DSP1.Op0AC >> 8) & 0xFF;
1873
DSP1.output[6] = DSP1.Op0AD & 0xFF;
1874
DSP1.output[7] = (DSP1.Op0AD >> 8) & 0xFF;
1875
}
1876
1877
if (DSP1.command == 0x1f)
1878
{
1879
if ((DSP1.out_index % 2) != 0)
1880
t = (uint8) DSP1ROM[DSP1.out_index >> 1];
1881
else
1882
t = DSP1ROM[DSP1.out_index >> 1] >> 8;
1883
}
1884
}
1885
1886
DSP1.waiting4command = TRUE;
1887
}
1888
else
1889
t = 0xff;
1890
}
1891
else
1892
t = 0x80;
1893
1894
return (t);
1895
}
1896
1897