Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
RishiRecon
GitHub Repository: RishiRecon/exploits
Path: blob/main/misc/emulator/xnes/snes9x/dsp3.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
#include "snes9x.h"
180
#include "memmap.h"
181
182
static void (*SetDSP3) (void);
183
184
static const uint16 DSP3_DataROM[1024] =
185
{
186
0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,
187
0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001,
188
0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100,
189
0x0000, 0x000f, 0x0400, 0x0200, 0x0140, 0x0400, 0x0200, 0x0040,
190
0x007d, 0x007e, 0x007e, 0x007b, 0x007c, 0x007d, 0x007b, 0x007c,
191
0x0002, 0x0020, 0x0030, 0x0000, 0x000d, 0x0019, 0x0026, 0x0032,
192
0x003e, 0x004a, 0x0056, 0x0062, 0x006d, 0x0079, 0x0084, 0x008e,
193
0x0098, 0x00a2, 0x00ac, 0x00b5, 0x00be, 0x00c6, 0x00ce, 0x00d5,
194
0x00dc, 0x00e2, 0x00e7, 0x00ec, 0x00f1, 0x00f5, 0x00f8, 0x00fb,
195
0x00fd, 0x00ff, 0x0100, 0x0100, 0x0100, 0x00ff, 0x00fd, 0x00fb,
196
0x00f8, 0x00f5, 0x00f1, 0x00ed, 0x00e7, 0x00e2, 0x00dc, 0x00d5,
197
0x00ce, 0x00c6, 0x00be, 0x00b5, 0x00ac, 0x00a2, 0x0099, 0x008e,
198
0x0084, 0x0079, 0x006e, 0x0062, 0x0056, 0x004a, 0x003e, 0x0032,
199
0x0026, 0x0019, 0x000d, 0x0000, 0xfff3, 0xffe7, 0xffdb, 0xffce,
200
0xffc2, 0xffb6, 0xffaa, 0xff9e, 0xff93, 0xff87, 0xff7d, 0xff72,
201
0xff68, 0xff5e, 0xff54, 0xff4b, 0xff42, 0xff3a, 0xff32, 0xff2b,
202
0xff25, 0xff1e, 0xff19, 0xff14, 0xff0f, 0xff0b, 0xff08, 0xff05,
203
0xff03, 0xff01, 0xff00, 0xff00, 0xff00, 0xff01, 0xff03, 0xff05,
204
0xff08, 0xff0b, 0xff0f, 0xff13, 0xff18, 0xff1e, 0xff24, 0xff2b,
205
0xff32, 0xff3a, 0xff42, 0xff4b, 0xff54, 0xff5d, 0xff67, 0xff72,
206
0xff7c, 0xff87, 0xff92, 0xff9e, 0xffa9, 0xffb5, 0xffc2, 0xffce,
207
0xffda, 0xffe7, 0xfff3, 0x002b, 0x007f, 0x0020, 0x00ff, 0xff00,
208
0xffbe, 0x0000, 0x0044, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
209
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
210
0x0000, 0x0000, 0x0000, 0x0000, 0xffc1, 0x0001, 0x0002, 0x0045,
211
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
212
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
213
0xffc5, 0x0003, 0x0004, 0x0005, 0x0047, 0x0000, 0x0000, 0x0000,
214
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
215
0x0000, 0x0000, 0x0000, 0x0000, 0xffca, 0x0006, 0x0007, 0x0008,
216
0x0009, 0x004a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
217
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
218
0xffd0, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x004e, 0x0000,
219
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
220
0x0000, 0x0000, 0x0000, 0x0000, 0xffd7, 0x000f, 0x0010, 0x0011,
221
0x0012, 0x0013, 0x0014, 0x0053, 0x0000, 0x0000, 0x0000, 0x0000,
222
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
223
0xffdf, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b,
224
0x0059, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
225
0x0000, 0x0000, 0x0000, 0x0000, 0xffe8, 0x001c, 0x001d, 0x001e,
226
0x001f, 0x0020, 0x0021, 0x0022, 0x0023, 0x0060, 0x0000, 0x0000,
227
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
228
0xfff2, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a,
229
0x002b, 0x002c, 0x0068, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
230
0x0000, 0x0000, 0x0000, 0x0000, 0xfffd, 0x002d, 0x002e, 0x002f,
231
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0071,
232
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
233
0xffc7, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d,
234
0x003e, 0x003f, 0x0040, 0x0041, 0x007b, 0x0000, 0x0000, 0x0000,
235
0x0000, 0x0000, 0x0000, 0x0000, 0xffd4, 0x0000, 0x0001, 0x0002,
236
0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
237
0x000b, 0x0044, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
238
0xffe2, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011, 0x0012,
239
0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0050, 0x0000,
240
0x0000, 0x0000, 0x0000, 0x0000, 0xfff1, 0x0019, 0x001a, 0x001b,
241
0x001c, 0x001d, 0x001e, 0x001f, 0x0020, 0x0021, 0x0022, 0x0023,
242
0x0024, 0x0025, 0x0026, 0x005d, 0x0000, 0x0000, 0x0000, 0x0000,
243
0xffcb, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d,
244
0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
245
0x006b, 0x0000, 0x0000, 0x0000, 0xffdc, 0x0000, 0x0001, 0x0002,
246
0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
247
0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0044, 0x0000, 0x0000,
248
0xffee, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016,
249
0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e,
250
0x001f, 0x0020, 0x0054, 0x0000, 0xffee, 0x0021, 0x0022, 0x0023,
251
0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b,
252
0x002c, 0x002d, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0065,
253
0xffbe, 0x0000, 0xfeac, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
254
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
255
0x0000, 0x0000, 0x0000, 0x0000, 0xffc1, 0x0001, 0x0002, 0xfead,
256
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
257
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
258
0xffc5, 0x0003, 0x0004, 0x0005, 0xfeaf, 0x0000, 0x0000, 0x0000,
259
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
260
0x0000, 0x0000, 0x0000, 0x0000, 0xffca, 0x0006, 0x0007, 0x0008,
261
0x0009, 0xfeb2, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
262
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
263
0xffd0, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0xfeb6, 0x0000,
264
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
265
0x0000, 0x0000, 0x0000, 0x0000, 0xffd7, 0x000f, 0x0010, 0x0011,
266
0x0012, 0x0013, 0x0014, 0xfebb, 0x0000, 0x0000, 0x0000, 0x0000,
267
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
268
0xffdf, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b,
269
0xfec1, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
270
0x0000, 0x0000, 0x0000, 0x0000, 0xffe8, 0x001c, 0x001d, 0x001e,
271
0x001f, 0x0020, 0x0021, 0x0022, 0x0023, 0xfec8, 0x0000, 0x0000,
272
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
273
0xfff2, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a,
274
0x002b, 0x002c, 0xfed0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
275
0x0000, 0x0000, 0x0000, 0x0000, 0xfffd, 0x002d, 0x002e, 0x002f,
276
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0xfed9,
277
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
278
0xffc7, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d,
279
0x003e, 0x003f, 0x0040, 0x0041, 0xfee3, 0x0000, 0x0000, 0x0000,
280
0x0000, 0x0000, 0x0000, 0x0000, 0xffd4, 0x0000, 0x0001, 0x0002,
281
0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
282
0x000b, 0xfeac, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
283
0xffe2, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011, 0x0012,
284
0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0xfeb8, 0x0000,
285
0x0000, 0x0000, 0x0000, 0x0000, 0xfff1, 0x0019, 0x001a, 0x001b,
286
0x001c, 0x001d, 0x001e, 0x001f, 0x0020, 0x0021, 0x0022, 0x0023,
287
0x0024, 0x0025, 0x0026, 0xfec5, 0x0000, 0x0000, 0x0000, 0x0000,
288
0xffcb, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d,
289
0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
290
0xfed3, 0x0000, 0x0000, 0x0000, 0xffdc, 0x0000, 0x0001, 0x0002,
291
0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
292
0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0xfeac, 0x0000, 0x0000,
293
0xffee, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016,
294
0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e,
295
0x001f, 0x0020, 0xfebc, 0x0000, 0xffee, 0x0021, 0x0022, 0x0023,
296
0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b,
297
0x002c, 0x002d, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0xfecd,
298
0x0154, 0x0218, 0x0110, 0x00b0, 0x00cc, 0x00b0, 0x0088, 0x00b0,
299
0x0044, 0x00b0, 0x0000, 0x00b0, 0x00fe, 0xff07, 0x0002, 0x00ff,
300
0x00f8, 0x0007, 0x00fe, 0x00ee, 0x07ff, 0x0200, 0x00ef, 0xf800,
301
0x0700, 0x00ee, 0xffff, 0xffff, 0xffff, 0x0000, 0x0000, 0x0001,
302
0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff,
303
0xffff, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000,
304
0x0000, 0xffff, 0xffff, 0x0000, 0xffff, 0x0001, 0x0000, 0x0001,
305
0x0001, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000,
306
0xffff, 0x0001, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0xffff,
307
0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0044, 0x0088, 0x00cc,
308
0x0110, 0x0154, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
309
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
310
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
311
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
312
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
313
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff
314
};
315
316
static bool8 DSP3_GetBits (uint8);
317
//static void DSP3_MemorySize (void);
318
static void DSP3_TestMemory (void);
319
static void DSP3_DumpDataROM (void);
320
static void DSP3_MemoryDump (void);
321
static void DSP3_Coordinate (void);
322
static void DSP3_Command (void);
323
static void DSP3_Decode_Data (void);
324
static void DSP3_Decode_Tree (void);
325
static void DSP3_Decode_Symbols (void);
326
static void DSP3_Decode (void);
327
static void DSP3_Decode_A (void);
328
static void DSP3_Convert (void);
329
static void DSP3_Convert_A (void);
330
static void DSP3_OP03 (void);
331
static void DSP3_OP06 (void);
332
static void DSP3_OP07 (void);
333
static void DSP3_OP07_A (void);
334
static void DSP3_OP07_B (void);
335
static void DSP3_OP0C (void);
336
//static void DSP3_OP0C_A (void);
337
static void DSP3_OP10 (void);
338
static void DSP3_OP1C (void);
339
static void DSP3_OP1C_A (void);
340
static void DSP3_OP1C_B (void);
341
static void DSP3_OP1C_C (void);
342
static void DSP3_OP1E (void);
343
static void DSP3_OP1E_A (void);
344
static void DSP3_OP1E_A1 (void);
345
static void DSP3_OP1E_A2 (void);
346
static void DSP3_OP1E_A3 (void);
347
static void DSP3_OP1E_B (void);
348
static void DSP3_OP1E_B1 (void);
349
static void DSP3_OP1E_B2 (void);
350
static void DSP3_OP1E_C (void);
351
static void DSP3_OP1E_C1 (void);
352
static void DSP3_OP1E_C2 (void);
353
static void DSP3_OP1E_D (int16, int16 *, int16 *);
354
static void DSP3_OP1E_D1 (int16, int16 *, int16 *);
355
static void DSP3_OP3E (void);
356
357
358
void DSP3_Reset (void)
359
{
360
DSP3.DR = 0x0080;
361
DSP3.SR = 0x0084;
362
SetDSP3 = &DSP3_Command;
363
}
364
365
/*
366
static void DSP3_MemorySize (void)
367
{
368
DSP3.DR = 0x0300;
369
SetDSP3 = &DSP3_Reset;
370
}
371
*/
372
373
static void DSP3_TestMemory (void)
374
{
375
DSP3.DR = 0x0000;
376
SetDSP3 = &DSP3_Reset;
377
}
378
379
static void DSP3_DumpDataROM (void)
380
{
381
DSP3.DR = DSP3_DataROM[DSP3.MemoryIndex++];
382
if (DSP3.MemoryIndex == 1024)
383
SetDSP3 = &DSP3_Reset;
384
}
385
386
static void DSP3_MemoryDump (void)
387
{
388
DSP3.MemoryIndex = 0;
389
SetDSP3 = &DSP3_DumpDataROM;
390
DSP3_DumpDataROM();
391
}
392
393
static void DSP3_OP06 (void)
394
{
395
DSP3.WinLo = (uint8) (DSP3.DR);
396
DSP3.WinHi = (uint8) (DSP3.DR >> 8);
397
DSP3_Reset();
398
}
399
400
static void DSP3_OP03 (void)
401
{
402
int16 Lo = (uint8) (DSP3.DR);
403
int16 Hi = (uint8) (DSP3.DR >> 8);
404
int16 Ofs = (DSP3.WinLo * Hi << 1) + (Lo << 1);
405
406
DSP3.DR = Ofs >> 1;
407
SetDSP3 = &DSP3_Reset;
408
}
409
410
static void DSP3_OP07_B (void)
411
{
412
int16 Ofs = (DSP3.WinLo * DSP3.AddHi << 1) + (DSP3.AddLo << 1);
413
414
DSP3.DR = Ofs >> 1;
415
SetDSP3 = &DSP3_Reset;
416
}
417
418
static void DSP3_OP07_A (void)
419
{
420
int16 Lo = (uint8) (DSP3.DR);
421
int16 Hi = (uint8) (DSP3.DR >> 8);
422
423
if (Lo & 1)
424
Hi += (DSP3.AddLo & 1);
425
426
DSP3.AddLo += Lo;
427
DSP3.AddHi += Hi;
428
429
if (DSP3.AddLo < 0)
430
DSP3.AddLo += DSP3.WinLo;
431
else
432
if (DSP3.AddLo >= DSP3.WinLo)
433
DSP3.AddLo -= DSP3.WinLo;
434
435
if (DSP3.AddHi < 0)
436
DSP3.AddHi += DSP3.WinHi;
437
else
438
if (DSP3.AddHi >= DSP3.WinHi)
439
DSP3.AddHi -= DSP3.WinHi;
440
441
DSP3.DR = DSP3.AddLo | (DSP3.AddHi << 8) | ((DSP3.AddHi >> 8) & 0xff);
442
SetDSP3 = &DSP3_OP07_B;
443
}
444
445
static void DSP3_OP07 (void)
446
{
447
uint32 dataOfs = ((DSP3.DR << 1) + 0x03b2) & 0x03ff;
448
449
DSP3.AddHi = DSP3_DataROM[dataOfs];
450
DSP3.AddLo = DSP3_DataROM[dataOfs + 1];
451
452
SetDSP3 = &DSP3_OP07_A;
453
DSP3.SR = 0x0080;
454
}
455
456
static void DSP3_Coordinate (void)
457
{
458
DSP3.Index++;
459
460
switch (DSP3.Index)
461
{
462
case 3:
463
if (DSP3.DR == 0xffff)
464
DSP3_Reset();
465
break;
466
467
case 4:
468
DSP3.X = DSP3.DR;
469
break;
470
471
case 5:
472
DSP3.Y = DSP3.DR;
473
DSP3.DR = 1;
474
break;
475
476
case 6:
477
DSP3.DR = DSP3.X;
478
break;
479
480
case 7:
481
DSP3.DR = DSP3.Y;
482
DSP3.Index = 0;
483
break;
484
}
485
}
486
487
static void DSP3_Convert_A (void)
488
{
489
if (DSP3.BMIndex < 8)
490
{
491
DSP3.Bitmap[DSP3.BMIndex++] = (uint8) (DSP3.DR);
492
DSP3.Bitmap[DSP3.BMIndex++] = (uint8) (DSP3.DR >> 8);
493
494
if (DSP3.BMIndex == 8)
495
{
496
for (int i = 0; i < 8; i++)
497
{
498
for (int j = 0; j < 8; j++)
499
{
500
DSP3.Bitplane[j] <<= 1;
501
DSP3.Bitplane[j] |= (DSP3.Bitmap[i] >> j) & 1;
502
}
503
}
504
505
DSP3.BPIndex = 0;
506
DSP3.Count--;
507
}
508
}
509
510
if (DSP3.BMIndex == 8)
511
{
512
if (DSP3.BPIndex == 8)
513
{
514
if (!DSP3.Count)
515
DSP3_Reset();
516
517
DSP3.BMIndex = 0;
518
}
519
else
520
{
521
DSP3.DR = DSP3.Bitplane[DSP3.BPIndex++];
522
DSP3.DR |= DSP3.Bitplane[DSP3.BPIndex++] << 8;
523
}
524
}
525
}
526
527
static void DSP3_Convert (void)
528
{
529
DSP3.Count = DSP3.DR;
530
DSP3.BMIndex = 0;
531
SetDSP3 = &DSP3_Convert_A;
532
}
533
534
static bool8 DSP3_GetBits (uint8 Count)
535
{
536
if (!DSP3.BitsLeft)
537
{
538
DSP3.BitsLeft = Count;
539
DSP3.ReqBits = 0;
540
}
541
542
do
543
{
544
if (!DSP3.BitCount)
545
{
546
DSP3.SR = 0xC0;
547
return (FALSE);
548
}
549
550
DSP3.ReqBits <<= 1;
551
if (DSP3.ReqData & 0x8000)
552
DSP3.ReqBits++;
553
DSP3.ReqData <<= 1;
554
555
DSP3.BitCount--;
556
DSP3.BitsLeft--;
557
558
}
559
while (DSP3.BitsLeft);
560
561
return (TRUE);
562
}
563
564
static void DSP3_Decode_Data (void)
565
{
566
if (!DSP3.BitCount)
567
{
568
if (DSP3.SR & 0x40)
569
{
570
DSP3.ReqData = DSP3.DR;
571
DSP3.BitCount += 16;
572
}
573
else
574
{
575
DSP3.SR = 0xC0;
576
return;
577
}
578
}
579
580
if (DSP3.LZCode == 1)
581
{
582
if (!DSP3_GetBits(1))
583
return;
584
585
if (DSP3.ReqBits)
586
DSP3.LZLength = 12;
587
else
588
DSP3.LZLength = 8;
589
590
DSP3.LZCode++;
591
}
592
593
if (DSP3.LZCode == 2)
594
{
595
if (!DSP3_GetBits(DSP3.LZLength))
596
return;
597
598
DSP3.LZCode = 0;
599
DSP3.Outwords--;
600
if (!DSP3.Outwords)
601
SetDSP3 = &DSP3_Reset;
602
603
DSP3.SR = 0x80;
604
DSP3.DR = DSP3.ReqBits;
605
return;
606
}
607
608
if (DSP3.BaseCode == 0xffff)
609
{
610
if (!DSP3_GetBits(DSP3.BaseLength))
611
return;
612
613
DSP3.BaseCode = DSP3.ReqBits;
614
}
615
616
if (!DSP3_GetBits(DSP3.CodeLengths[DSP3.BaseCode]))
617
return;
618
619
DSP3.Symbol = DSP3.Codes[DSP3.CodeOffsets[DSP3.BaseCode] + DSP3.ReqBits];
620
DSP3.BaseCode = 0xffff;
621
622
if (DSP3.Symbol & 0xff00)
623
{
624
DSP3.Symbol += 0x7f02;
625
DSP3.LZCode++;
626
}
627
else
628
{
629
DSP3.Outwords--;
630
if (!DSP3.Outwords)
631
SetDSP3 = &DSP3_Reset;
632
}
633
634
DSP3.SR = 0x80;
635
DSP3.DR = DSP3.Symbol;
636
}
637
638
static void DSP3_Decode_Tree (void)
639
{
640
if (!DSP3.BitCount)
641
{
642
DSP3.ReqData = DSP3.DR;
643
DSP3.BitCount += 16;
644
}
645
646
if (!DSP3.BaseCodes)
647
{
648
DSP3_GetBits(1);
649
650
if (DSP3.ReqBits)
651
{
652
DSP3.BaseLength = 3;
653
DSP3.BaseCodes = 8;
654
}
655
else
656
{
657
DSP3.BaseLength = 2;
658
DSP3.BaseCodes = 4;
659
}
660
}
661
662
while (DSP3.BaseCodes)
663
{
664
if (!DSP3_GetBits(3))
665
return;
666
667
DSP3.ReqBits++;
668
669
DSP3.CodeLengths[DSP3.Index] = (uint8) DSP3.ReqBits;
670
DSP3.CodeOffsets[DSP3.Index] = DSP3.Symbol;
671
DSP3.Index++;
672
673
DSP3.Symbol += 1 << DSP3.ReqBits;
674
DSP3.BaseCodes--;
675
}
676
677
DSP3.BaseCode = 0xffff;
678
DSP3.LZCode = 0;
679
680
SetDSP3 = &DSP3_Decode_Data;
681
if (DSP3.BitCount)
682
DSP3_Decode_Data();
683
}
684
685
static void DSP3_Decode_Symbols (void)
686
{
687
DSP3.ReqData = DSP3.DR;
688
DSP3.BitCount += 16;
689
690
do
691
{
692
if (DSP3.BitCommand == 0xffff)
693
{
694
if (!DSP3_GetBits(2))
695
return;
696
697
DSP3.BitCommand = DSP3.ReqBits;
698
}
699
700
switch (DSP3.BitCommand)
701
{
702
case 0:
703
if (!DSP3_GetBits(9))
704
return;
705
DSP3.Symbol = DSP3.ReqBits;
706
break;
707
708
case 1:
709
DSP3.Symbol++;
710
break;
711
712
case 2:
713
if (!DSP3_GetBits(1))
714
return;
715
DSP3.Symbol += 2 + DSP3.ReqBits;
716
break;
717
718
case 3:
719
if (!DSP3_GetBits(4))
720
return;
721
DSP3.Symbol += 4 + DSP3.ReqBits;
722
break;
723
}
724
725
DSP3.BitCommand = 0xffff;
726
727
DSP3.Codes[DSP3.Index++] = DSP3.Symbol;
728
DSP3.Codewords--;
729
730
}
731
while (DSP3.Codewords);
732
733
DSP3.Index = 0;
734
DSP3.Symbol = 0;
735
DSP3.BaseCodes = 0;
736
737
SetDSP3 = &DSP3_Decode_Tree;
738
if (DSP3.BitCount)
739
DSP3_Decode_Tree();
740
}
741
742
static void DSP3_Decode_A (void)
743
{
744
DSP3.Outwords = DSP3.DR;
745
SetDSP3 = &DSP3_Decode_Symbols;
746
DSP3.BitCount = 0;
747
DSP3.BitsLeft = 0;
748
DSP3.Symbol = 0;
749
DSP3.Index = 0;
750
DSP3.BitCommand = 0xffff;
751
DSP3.SR = 0xC0;
752
}
753
754
static void DSP3_Decode (void)
755
{
756
DSP3.Codewords = DSP3.DR;
757
SetDSP3 = &DSP3_Decode_A;
758
}
759
760
// Opcodes 1E/3E bit-perfect to 'dsp3-intro' log
761
// src: adapted from SD Gundam X/G-Next
762
763
static void DSP3_OP3E (void)
764
{
765
DSP3. op3e_x = (uint8) (DSP3.DR & 0x00ff);
766
DSP3. op3e_y = (uint8) ((DSP3.DR & 0xff00) >> 8);
767
768
DSP3_OP03();
769
770
DSP3.op1e_terrain[DSP3.DR] = 0x00;
771
DSP3.op1e_cost[DSP3.DR] = 0xff;
772
DSP3.op1e_weight[DSP3.DR] = 0;
773
774
DSP3.op1e_max_search_radius = 0;
775
DSP3.op1e_max_path_radius = 0;
776
}
777
778
static void DSP3_OP1E (void)
779
{
780
DSP3.op1e_min_radius = (uint8) (DSP3.DR & 0x00ff);
781
DSP3.op1e_max_radius = (uint8) ((DSP3.DR & 0xff00) >> 8);
782
783
if (DSP3.op1e_min_radius == 0)
784
DSP3.op1e_min_radius++;
785
786
if (DSP3.op1e_max_search_radius >= DSP3.op1e_min_radius)
787
DSP3.op1e_min_radius = DSP3.op1e_max_search_radius + 1;
788
789
if (DSP3.op1e_max_radius > DSP3.op1e_max_search_radius)
790
DSP3.op1e_max_search_radius = DSP3.op1e_max_radius;
791
792
DSP3.op1e_lcv_radius = DSP3.op1e_min_radius;
793
DSP3.op1e_lcv_steps = DSP3.op1e_min_radius;
794
795
DSP3.op1e_lcv_turns = 6;
796
DSP3.op1e_turn = 0;
797
798
DSP3.op1e_x = DSP3. op3e_x;
799
DSP3.op1e_y = DSP3. op3e_y;
800
801
for (int lcv = 0; lcv < DSP3.op1e_min_radius; lcv++)
802
DSP3_OP1E_D(DSP3.op1e_turn, &DSP3.op1e_x, &DSP3.op1e_y);
803
804
DSP3_OP1E_A();
805
}
806
807
static void DSP3_OP1E_A (void)
808
{
809
if (DSP3.op1e_lcv_steps == 0)
810
{
811
DSP3.op1e_lcv_radius++;
812
813
DSP3.op1e_lcv_steps = DSP3.op1e_lcv_radius;
814
815
DSP3.op1e_x = DSP3. op3e_x;
816
DSP3.op1e_y = DSP3. op3e_y;
817
818
for (int lcv = 0; lcv < DSP3.op1e_lcv_radius; lcv++)
819
DSP3_OP1E_D(DSP3.op1e_turn, &DSP3.op1e_x, &DSP3.op1e_y);
820
}
821
822
if (DSP3.op1e_lcv_radius > DSP3.op1e_max_radius)
823
{
824
DSP3.op1e_turn++;
825
DSP3.op1e_lcv_turns--;
826
827
DSP3.op1e_lcv_radius = DSP3.op1e_min_radius;
828
DSP3.op1e_lcv_steps = DSP3.op1e_min_radius;
829
830
DSP3.op1e_x = DSP3. op3e_x;
831
DSP3.op1e_y = DSP3. op3e_y;
832
833
for (int lcv = 0; lcv < DSP3.op1e_min_radius; lcv++)
834
DSP3_OP1E_D(DSP3.op1e_turn, &DSP3.op1e_x, &DSP3.op1e_y);
835
}
836
837
if (DSP3.op1e_lcv_turns == 0)
838
{
839
DSP3.DR = 0xffff;
840
DSP3.SR = 0x0080;
841
SetDSP3 = &DSP3_OP1E_B;
842
return;
843
}
844
845
DSP3.DR = (uint8) (DSP3.op1e_x) | ((uint8) (DSP3.op1e_y) << 8);
846
DSP3_OP03();
847
848
DSP3.op1e_cell = DSP3.DR;
849
850
DSP3.SR = 0x0080;
851
SetDSP3 = &DSP3_OP1E_A1;
852
}
853
854
static void DSP3_OP1E_A1 (void)
855
{
856
DSP3.SR = 0x0084;
857
SetDSP3 = &DSP3_OP1E_A2;
858
}
859
860
static void DSP3_OP1E_A2 (void)
861
{
862
DSP3.op1e_terrain[DSP3.op1e_cell] = (uint8) (DSP3.DR & 0x00ff);
863
864
DSP3.SR = 0x0084;
865
SetDSP3 = &DSP3_OP1E_A3;
866
}
867
868
static void DSP3_OP1E_A3 (void)
869
{
870
DSP3.op1e_cost[DSP3.op1e_cell] = (uint8) (DSP3.DR & 0x00ff);
871
872
if (DSP3.op1e_lcv_radius == 1)
873
{
874
if (DSP3.op1e_terrain[DSP3.op1e_cell] & 1)
875
DSP3.op1e_weight[DSP3.op1e_cell] = 0xff;
876
else
877
DSP3.op1e_weight[DSP3.op1e_cell] = DSP3.op1e_cost[DSP3.op1e_cell];
878
}
879
else
880
DSP3.op1e_weight[DSP3.op1e_cell] = 0xff;
881
882
DSP3_OP1E_D((int16) (DSP3.op1e_turn + 2), &DSP3.op1e_x, &DSP3.op1e_y);
883
DSP3.op1e_lcv_steps--;
884
885
DSP3.SR = 0x0080;
886
DSP3_OP1E_A();
887
}
888
889
static void DSP3_OP1E_B (void)
890
{
891
DSP3.op1e_x = DSP3. op3e_x;
892
DSP3.op1e_y = DSP3. op3e_y;
893
DSP3.op1e_lcv_radius = 1;
894
895
DSP3.op1e_search = 0;
896
897
DSP3_OP1E_B1();
898
899
SetDSP3 = &DSP3_OP1E_C;
900
}
901
902
static void DSP3_OP1E_B1 (void)
903
{
904
while (DSP3.op1e_lcv_radius < DSP3.op1e_max_radius)
905
{
906
DSP3.op1e_y--;
907
908
DSP3.op1e_lcv_turns = 6;
909
DSP3.op1e_turn = 5;
910
911
while (DSP3.op1e_lcv_turns)
912
{
913
DSP3.op1e_lcv_steps = DSP3.op1e_lcv_radius;
914
915
while (DSP3.op1e_lcv_steps)
916
{
917
DSP3_OP1E_D1(DSP3.op1e_turn, &DSP3.op1e_x, &DSP3.op1e_y);
918
919
if (0 <= DSP3.op1e_y && DSP3.op1e_y < DSP3.WinHi && 0 <= DSP3.op1e_x && DSP3.op1e_x < DSP3.WinLo)
920
{
921
DSP3.DR = (uint8) (DSP3.op1e_x) | ((uint8) (DSP3.op1e_y) << 8);
922
DSP3_OP03();
923
924
DSP3.op1e_cell = DSP3.DR;
925
if (DSP3.op1e_cost[DSP3.op1e_cell] < 0x80 && DSP3.op1e_terrain[DSP3.op1e_cell] < 0x40)
926
DSP3_OP1E_B2(); // end cell perimeter
927
}
928
929
DSP3.op1e_lcv_steps--;
930
} // end search line
931
932
DSP3.op1e_turn--;
933
if (DSP3.op1e_turn == 0)
934
DSP3.op1e_turn = 6;
935
936
DSP3.op1e_lcv_turns--;
937
} // end circle search
938
939
DSP3.op1e_lcv_radius++;
940
} // end radius search
941
}
942
943
static void DSP3_OP1E_B2 (void)
944
{
945
int16 cell;
946
int16 path;
947
int16 x, y;
948
int16 lcv_turns;
949
950
path = 0xff;
951
lcv_turns = 6;
952
953
while (lcv_turns)
954
{
955
x = DSP3.op1e_x;
956
y = DSP3.op1e_y;
957
958
DSP3_OP1E_D1(lcv_turns, &x, &y);
959
960
DSP3.DR = (uint8) (x) | ((uint8) (y) << 8);
961
DSP3_OP03();
962
963
cell = DSP3.DR;
964
965
if (0 <= y && y < DSP3.WinHi && 0 <= x && x < DSP3.WinLo)
966
{
967
if (DSP3.op1e_terrain[cell] < 0x80 || DSP3.op1e_weight[cell] == 0)
968
{
969
if (DSP3.op1e_weight[cell] < path)
970
path = DSP3.op1e_weight[cell];
971
}
972
} // end step travel
973
974
lcv_turns--;
975
} // end while turns
976
977
if (path != 0xff)
978
DSP3.op1e_weight[DSP3.op1e_cell] = path + DSP3.op1e_cost[DSP3.op1e_cell];
979
}
980
981
static void DSP3_OP1E_C (void)
982
{
983
DSP3.op1e_min_radius = (uint8) (DSP3.DR & 0x00ff);
984
DSP3.op1e_max_radius = (uint8) ((DSP3.DR & 0xff00) >> 8);
985
986
if (DSP3.op1e_min_radius == 0)
987
DSP3.op1e_min_radius++;
988
989
if (DSP3.op1e_max_path_radius >= DSP3.op1e_min_radius)
990
DSP3.op1e_min_radius = DSP3.op1e_max_path_radius + 1;
991
992
if (DSP3.op1e_max_radius > DSP3.op1e_max_path_radius)
993
DSP3.op1e_max_path_radius = DSP3.op1e_max_radius;
994
995
DSP3.op1e_lcv_radius = DSP3.op1e_min_radius;
996
DSP3.op1e_lcv_steps = DSP3.op1e_min_radius;
997
998
DSP3.op1e_lcv_turns = 6;
999
DSP3.op1e_turn = 0;
1000
1001
DSP3.op1e_x = DSP3. op3e_x;
1002
DSP3.op1e_y = DSP3. op3e_y;
1003
1004
for (int lcv = 0; lcv < DSP3.op1e_min_radius; lcv++)
1005
DSP3_OP1E_D(DSP3.op1e_turn, &DSP3.op1e_x, &DSP3.op1e_y);
1006
1007
DSP3_OP1E_C1();
1008
}
1009
1010
static void DSP3_OP1E_C1 (void)
1011
{
1012
if (DSP3.op1e_lcv_steps == 0)
1013
{
1014
DSP3.op1e_lcv_radius++;
1015
1016
DSP3.op1e_lcv_steps = DSP3.op1e_lcv_radius;
1017
1018
DSP3.op1e_x = DSP3. op3e_x;
1019
DSP3.op1e_y = DSP3. op3e_y;
1020
1021
for (int lcv = 0; lcv < DSP3.op1e_lcv_radius; lcv++)
1022
DSP3_OP1E_D(DSP3.op1e_turn, &DSP3.op1e_x, &DSP3.op1e_y);
1023
}
1024
1025
if (DSP3.op1e_lcv_radius > DSP3.op1e_max_radius)
1026
{
1027
DSP3.op1e_turn++;
1028
DSP3.op1e_lcv_turns--;
1029
1030
DSP3.op1e_lcv_radius = DSP3.op1e_min_radius;
1031
DSP3.op1e_lcv_steps = DSP3.op1e_min_radius;
1032
1033
DSP3.op1e_x = DSP3. op3e_x;
1034
DSP3.op1e_y = DSP3. op3e_y;
1035
1036
for (int lcv = 0; lcv < DSP3.op1e_min_radius; lcv++)
1037
DSP3_OP1E_D(DSP3.op1e_turn, &DSP3.op1e_x, &DSP3.op1e_y);
1038
}
1039
1040
if (DSP3.op1e_lcv_turns == 0)
1041
{
1042
DSP3.DR = 0xffff;
1043
DSP3.SR = 0x0080;
1044
SetDSP3 = &DSP3_Reset;
1045
return;
1046
}
1047
1048
DSP3.DR = (uint8) (DSP3.op1e_x) | ((uint8) (DSP3.op1e_y) << 8);
1049
DSP3_OP03();
1050
1051
DSP3.op1e_cell = DSP3.DR;
1052
1053
DSP3.SR = 0x0080;
1054
SetDSP3 = &DSP3_OP1E_C2;
1055
}
1056
1057
static void DSP3_OP1E_C2 (void)
1058
{
1059
DSP3.DR = DSP3.op1e_weight[DSP3.op1e_cell];
1060
1061
DSP3_OP1E_D((int16) (DSP3.op1e_turn + 2), &DSP3.op1e_x, &DSP3.op1e_y);
1062
DSP3.op1e_lcv_steps--;
1063
1064
DSP3.SR = 0x0084;
1065
SetDSP3 = &DSP3_OP1E_C1;
1066
}
1067
1068
static void DSP3_OP1E_D (int16 move, int16 *lo, int16 *hi)
1069
{
1070
uint32 dataOfs = ((move << 1) + 0x03b2) & 0x03ff;
1071
int16 Lo;
1072
int16 Hi;
1073
1074
DSP3.AddHi = DSP3_DataROM[dataOfs];
1075
DSP3.AddLo = DSP3_DataROM[dataOfs + 1];
1076
1077
Lo = (uint8) (*lo);
1078
Hi = (uint8) (*hi);
1079
1080
if (Lo & 1)
1081
Hi += (DSP3.AddLo & 1);
1082
1083
DSP3.AddLo += Lo;
1084
DSP3.AddHi += Hi;
1085
1086
if (DSP3.AddLo < 0)
1087
DSP3.AddLo += DSP3.WinLo;
1088
else
1089
if (DSP3.AddLo >= DSP3.WinLo)
1090
DSP3.AddLo -= DSP3.WinLo;
1091
1092
if (DSP3.AddHi < 0)
1093
DSP3.AddHi += DSP3.WinHi;
1094
else
1095
if (DSP3.AddHi >= DSP3.WinHi)
1096
DSP3.AddHi -= DSP3.WinHi;
1097
1098
*lo = DSP3.AddLo;
1099
*hi = DSP3.AddHi;
1100
}
1101
1102
static void DSP3_OP1E_D1 (int16 move, int16 *lo, int16 *hi)
1103
{
1104
const uint16 HiAdd[] =
1105
{
1106
0x00, 0xFF, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x01, 0x00, 0xFF, 0x00
1107
};
1108
1109
const uint16 LoAdd[] =
1110
{
1111
0x00, 0x00, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x00
1112
};
1113
1114
int16 Lo;
1115
int16 Hi;
1116
1117
if ((*lo) & 1)
1118
DSP3.AddHi = HiAdd[move + 8];
1119
else
1120
DSP3.AddHi = HiAdd[move + 0];
1121
1122
DSP3.AddLo = LoAdd[move];
1123
1124
Lo = (uint8) (*lo);
1125
Hi = (uint8) (*hi);
1126
1127
if (Lo & 1)
1128
Hi += (DSP3.AddLo & 1);
1129
1130
DSP3.AddLo += Lo;
1131
DSP3.AddHi += Hi;
1132
1133
*lo = DSP3.AddLo;
1134
*hi = DSP3.AddHi;
1135
}
1136
1137
static void DSP3_OP10 (void)
1138
{
1139
if (DSP3.DR == 0xffff)
1140
DSP3_Reset();
1141
else
1142
// absorb 2 bytes
1143
DSP3.DR = DSP3.DR;
1144
}
1145
1146
/*
1147
static void DSP3_OP0C_A (void)
1148
{
1149
// absorb 2 bytes
1150
DSP3.DR = 0;
1151
SetDSP3 = &DSP3_Reset;
1152
}
1153
*/
1154
1155
static void DSP3_OP0C (void)
1156
{
1157
// absorb 2 bytes
1158
DSP3.DR = 0;
1159
//SetDSP3 = &DSP3_OP0C_A;
1160
SetDSP3 = &DSP3_Reset;
1161
}
1162
1163
static void DSP3_OP1C_C (void)
1164
{
1165
// return 2 bytes
1166
DSP3.DR = 0;
1167
SetDSP3 = &DSP3_Reset;
1168
}
1169
1170
static void DSP3_OP1C_B (void)
1171
{
1172
// return 2 bytes
1173
DSP3.DR = 0;
1174
SetDSP3 = &DSP3_OP1C_C;
1175
}
1176
1177
static void DSP3_OP1C_A (void)
1178
{
1179
// absorb 2 bytes
1180
SetDSP3 = &DSP3_OP1C_B;
1181
}
1182
1183
static void DSP3_OP1C (void)
1184
{
1185
// absorb 2 bytes
1186
SetDSP3 = &DSP3_OP1C_A;
1187
}
1188
1189
static void DSP3_Command (void)
1190
{
1191
if (DSP3.DR < 0x40)
1192
{
1193
switch (DSP3.DR)
1194
{
1195
case 0x02: SetDSP3 = &DSP3_Coordinate; break;
1196
case 0x03: SetDSP3 = &DSP3_OP03; break;
1197
case 0x06: SetDSP3 = &DSP3_OP06; break;
1198
case 0x07: SetDSP3 = &DSP3_OP07; return;
1199
case 0x0c: SetDSP3 = &DSP3_OP0C; break;
1200
case 0x0f: SetDSP3 = &DSP3_TestMemory; break;
1201
case 0x10: SetDSP3 = &DSP3_OP10; break;
1202
case 0x18: SetDSP3 = &DSP3_Convert; break;
1203
case 0x1c: SetDSP3 = &DSP3_OP1C; break;
1204
case 0x1e: SetDSP3 = &DSP3_OP1E; break;
1205
case 0x1f: SetDSP3 = &DSP3_MemoryDump; break;
1206
case 0x38: SetDSP3 = &DSP3_Decode; break;
1207
case 0x3e: SetDSP3 = &DSP3_OP3E; break;
1208
default:
1209
return;
1210
}
1211
1212
DSP3.SR = 0x0080;
1213
DSP3.Index = 0;
1214
}
1215
}
1216
1217
void DSP3SetByte (uint8 byte, uint16 address)
1218
{
1219
if (address < DSP0.boundary)
1220
{
1221
if (DSP3.SR & 0x04)
1222
{
1223
DSP3.DR = (DSP3.DR & 0xff00) + byte;
1224
(*SetDSP3)();
1225
}
1226
else
1227
{
1228
DSP3.SR ^= 0x10;
1229
1230
if (DSP3.SR & 0x10)
1231
DSP3.DR = (DSP3.DR & 0xff00) + byte;
1232
else
1233
{
1234
DSP3.DR = (DSP3.DR & 0x00ff) + (byte << 8);
1235
(*SetDSP3)();
1236
}
1237
}
1238
}
1239
}
1240
1241
uint8 DSP3GetByte (uint16 address)
1242
{
1243
if (address < DSP0.boundary)
1244
{
1245
uint8 byte;
1246
1247
if (DSP3.SR & 0x04)
1248
{
1249
byte = (uint8) DSP3.DR;
1250
(*SetDSP3)();
1251
}
1252
else
1253
{
1254
DSP3.SR ^= 0x10;
1255
1256
if (DSP3.SR & 0x10)
1257
byte = (uint8) (DSP3.DR);
1258
else
1259
{
1260
byte = (uint8) (DSP3.DR >> 8);
1261
(*SetDSP3)();
1262
}
1263
}
1264
1265
return (byte);
1266
}
1267
1268
return (uint8) DSP3.SR;
1269
}
1270
1271