2
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
5
http://sourceforge.net/projects/zsnes
6
https://zsnes.bountysource.com
8
This program is free software; you can redistribute it and/or
9
modify it under the terms of the GNU General Public License
10
version 2 as published by the Free Software Foundation.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
typedef unsigned char bool8;
23
typedef unsigned char uint8;
24
typedef unsigned short uint16;
25
typedef unsigned int uint32;
31
typedef unsigned char bool;
35
uint16 DSP3_DataROM[1024] = {
36
0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,
37
0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001,
38
0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100,
39
0x0000, 0x000f, 0x0400, 0x0200, 0x0140, 0x0400, 0x0200, 0x0040,
40
0x007d, 0x007e, 0x007e, 0x007b, 0x007c, 0x007d, 0x007b, 0x007c,
41
0x0002, 0x0020, 0x0030, 0x0000, 0x000d, 0x0019, 0x0026, 0x0032,
42
0x003e, 0x004a, 0x0056, 0x0062, 0x006d, 0x0079, 0x0084, 0x008e,
43
0x0098, 0x00a2, 0x00ac, 0x00b5, 0x00be, 0x00c6, 0x00ce, 0x00d5,
44
0x00dc, 0x00e2, 0x00e7, 0x00ec, 0x00f1, 0x00f5, 0x00f8, 0x00fb,
45
0x00fd, 0x00ff, 0x0100, 0x0100, 0x0100, 0x00ff, 0x00fd, 0x00fb,
46
0x00f8, 0x00f5, 0x00f1, 0x00ed, 0x00e7, 0x00e2, 0x00dc, 0x00d5,
47
0x00ce, 0x00c6, 0x00be, 0x00b5, 0x00ac, 0x00a2, 0x0099, 0x008e,
48
0x0084, 0x0079, 0x006e, 0x0062, 0x0056, 0x004a, 0x003e, 0x0032,
49
0x0026, 0x0019, 0x000d, 0x0000, 0xfff3, 0xffe7, 0xffdb, 0xffce,
50
0xffc2, 0xffb6, 0xffaa, 0xff9e, 0xff93, 0xff87, 0xff7d, 0xff72,
51
0xff68, 0xff5e, 0xff54, 0xff4b, 0xff42, 0xff3a, 0xff32, 0xff2b,
52
0xff25, 0xff1e, 0xff19, 0xff14, 0xff0f, 0xff0b, 0xff08, 0xff05,
53
0xff03, 0xff01, 0xff00, 0xff00, 0xff00, 0xff01, 0xff03, 0xff05,
54
0xff08, 0xff0b, 0xff0f, 0xff13, 0xff18, 0xff1e, 0xff24, 0xff2b,
55
0xff32, 0xff3a, 0xff42, 0xff4b, 0xff54, 0xff5d, 0xff67, 0xff72,
56
0xff7c, 0xff87, 0xff92, 0xff9e, 0xffa9, 0xffb5, 0xffc2, 0xffce,
57
0xffda, 0xffe7, 0xfff3, 0x002b, 0x007f, 0x0020, 0x00ff, 0xff00,
58
0xffbe, 0x0000, 0x0044, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
59
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
60
0x0000, 0x0000, 0x0000, 0x0000, 0xffc1, 0x0001, 0x0002, 0x0045,
61
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
62
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
63
0xffc5, 0x0003, 0x0004, 0x0005, 0x0047, 0x0000, 0x0000, 0x0000,
64
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
65
0x0000, 0x0000, 0x0000, 0x0000, 0xffca, 0x0006, 0x0007, 0x0008,
66
0x0009, 0x004a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
67
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
68
0xffd0, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x004e, 0x0000,
69
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
70
0x0000, 0x0000, 0x0000, 0x0000, 0xffd7, 0x000f, 0x0010, 0x0011,
71
0x0012, 0x0013, 0x0014, 0x0053, 0x0000, 0x0000, 0x0000, 0x0000,
72
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
73
0xffdf, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b,
74
0x0059, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
75
0x0000, 0x0000, 0x0000, 0x0000, 0xffe8, 0x001c, 0x001d, 0x001e,
76
0x001f, 0x0020, 0x0021, 0x0022, 0x0023, 0x0060, 0x0000, 0x0000,
77
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
78
0xfff2, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a,
79
0x002b, 0x002c, 0x0068, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
80
0x0000, 0x0000, 0x0000, 0x0000, 0xfffd, 0x002d, 0x002e, 0x002f,
81
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0071,
82
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
83
0xffc7, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d,
84
0x003e, 0x003f, 0x0040, 0x0041, 0x007b, 0x0000, 0x0000, 0x0000,
85
0x0000, 0x0000, 0x0000, 0x0000, 0xffd4, 0x0000, 0x0001, 0x0002,
86
0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
87
0x000b, 0x0044, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
88
0xffe2, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011, 0x0012,
89
0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0050, 0x0000,
90
0x0000, 0x0000, 0x0000, 0x0000, 0xfff1, 0x0019, 0x001a, 0x001b,
91
0x001c, 0x001d, 0x001e, 0x001f, 0x0020, 0x0021, 0x0022, 0x0023,
92
0x0024, 0x0025, 0x0026, 0x005d, 0x0000, 0x0000, 0x0000, 0x0000,
93
0xffcb, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d,
94
0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
95
0x006b, 0x0000, 0x0000, 0x0000, 0xffdc, 0x0000, 0x0001, 0x0002,
96
0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
97
0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0044, 0x0000, 0x0000,
98
0xffee, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016,
99
0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e,
100
0x001f, 0x0020, 0x0054, 0x0000, 0xffee, 0x0021, 0x0022, 0x0023,
101
0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b,
102
0x002c, 0x002d, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0065,
103
0xffbe, 0x0000, 0xfeac, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
104
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
105
0x0000, 0x0000, 0x0000, 0x0000, 0xffc1, 0x0001, 0x0002, 0xfead,
106
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
107
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
108
0xffc5, 0x0003, 0x0004, 0x0005, 0xfeaf, 0x0000, 0x0000, 0x0000,
109
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
110
0x0000, 0x0000, 0x0000, 0x0000, 0xffca, 0x0006, 0x0007, 0x0008,
111
0x0009, 0xfeb2, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
112
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
113
0xffd0, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0xfeb6, 0x0000,
114
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
115
0x0000, 0x0000, 0x0000, 0x0000, 0xffd7, 0x000f, 0x0010, 0x0011,
116
0x0012, 0x0013, 0x0014, 0xfebb, 0x0000, 0x0000, 0x0000, 0x0000,
117
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
118
0xffdf, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b,
119
0xfec1, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
120
0x0000, 0x0000, 0x0000, 0x0000, 0xffe8, 0x001c, 0x001d, 0x001e,
121
0x001f, 0x0020, 0x0021, 0x0022, 0x0023, 0xfec8, 0x0000, 0x0000,
122
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
123
0xfff2, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a,
124
0x002b, 0x002c, 0xfed0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
125
0x0000, 0x0000, 0x0000, 0x0000, 0xfffd, 0x002d, 0x002e, 0x002f,
126
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0xfed9,
127
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
128
0xffc7, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d,
129
0x003e, 0x003f, 0x0040, 0x0041, 0xfee3, 0x0000, 0x0000, 0x0000,
130
0x0000, 0x0000, 0x0000, 0x0000, 0xffd4, 0x0000, 0x0001, 0x0002,
131
0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
132
0x000b, 0xfeac, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
133
0xffe2, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011, 0x0012,
134
0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0xfeb8, 0x0000,
135
0x0000, 0x0000, 0x0000, 0x0000, 0xfff1, 0x0019, 0x001a, 0x001b,
136
0x001c, 0x001d, 0x001e, 0x001f, 0x0020, 0x0021, 0x0022, 0x0023,
137
0x0024, 0x0025, 0x0026, 0xfec5, 0x0000, 0x0000, 0x0000, 0x0000,
138
0xffcb, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d,
139
0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
140
0xfed3, 0x0000, 0x0000, 0x0000, 0xffdc, 0x0000, 0x0001, 0x0002,
141
0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
142
0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0xfeac, 0x0000, 0x0000,
143
0xffee, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016,
144
0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e,
145
0x001f, 0x0020, 0xfebc, 0x0000, 0xffee, 0x0021, 0x0022, 0x0023,
146
0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b,
147
0x002c, 0x002d, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0xfecd,
148
0x0154, 0x0218, 0x0110, 0x00b0, 0x00cc, 0x00b0, 0x0088, 0x00b0,
149
0x0044, 0x00b0, 0x0000, 0x00b0, 0x00fe, 0xff07, 0x0002, 0x00ff,
150
0x00f8, 0x0007, 0x00fe, 0x00ee, 0x07ff, 0x0200, 0x00ef, 0xf800,
151
0x0700, 0x00ee, 0xffff, 0xffff, 0xffff, 0x0000, 0x0000, 0x0001,
152
0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff,
153
0xffff, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000,
154
0x0000, 0xffff, 0xffff, 0x0000, 0xffff, 0x0001, 0x0000, 0x0001,
155
0x0001, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000,
156
0xffff, 0x0001, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0xffff,
157
0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0044, 0x0088, 0x00cc,
158
0x0110, 0x0154, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
159
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
160
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
161
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
162
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
163
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff
171
uint16 DSP3_MemoryIndex;
177
SetDSP3 = &DSP3_Command;
180
void DSP3_MemorySize()
183
SetDSP3 = &DSP3_Reset;
186
void DSP3_TestMemory()
189
SetDSP3 = &DSP3_Reset;
192
void DSP3_DumpDataROM()
194
DSP3_DR = DSP3_DataROM[DSP3_MemoryIndex++];
195
if (DSP3_MemoryIndex == 1024)
196
SetDSP3 = &DSP3_Reset;
199
void DSP3_MemoryDump()
201
DSP3_MemoryIndex = 0;
202
SetDSP3 = &DSP3_DumpDataROM;
211
DSP3_WinLo = (uint8)(DSP3_DR);
212
DSP3_WinHi = (uint8)(DSP3_DR >> 8);
218
int16 Lo = (uint8)(DSP3_DR);
219
int16 Hi = (uint8)(DSP3_DR >> 8);
220
int16 Ofs = (DSP3_WinLo * Hi << 1) + (Lo << 1);
222
SetDSP3 = &DSP3_Reset;
230
int16 Ofs = (DSP3_WinLo * DSP3_AddHi << 1) + (DSP3_AddLo << 1);
232
SetDSP3 = &DSP3_Reset;
237
int16 Lo = (uint8)(DSP3_DR);
238
int16 Hi = (uint8)(DSP3_DR >> 8);
240
if (Lo & 1) Hi += (DSP3_AddLo & 1);
246
DSP3_AddLo += DSP3_WinLo;
248
if (DSP3_AddLo >= DSP3_WinLo)
249
DSP3_AddLo -= DSP3_WinLo;
252
DSP3_AddHi += DSP3_WinHi;
254
if (DSP3_AddHi >= DSP3_WinHi)
255
DSP3_AddHi -= DSP3_WinHi;
257
DSP3_DR = DSP3_AddLo | (DSP3_AddHi << 8) | ((DSP3_AddHi >> 8) & 0xff);
258
SetDSP3 = &DSP3_OP07_B;
263
uint32 dataOfs = ((DSP3_DR << 1) + 0x03b2) & 0x03ff;
265
DSP3_AddHi = DSP3_DataROM[dataOfs];
266
DSP3_AddLo = DSP3_DataROM[dataOfs + 1];
268
SetDSP3 = &DSP3_OP07_A;
272
uint16 DSP3_Codewords;
273
uint16 DSP3_Outwords;
275
uint16 DSP3_BitCount;
277
uint16 DSP3_Codes[512];
278
uint16 DSP3_BitsLeft;
281
uint16 DSP3_BitCommand;
282
uint8 DSP3_BaseLength;
283
uint16 DSP3_BaseCodes;
284
uint16 DSP3_BaseCode;
285
uint8 DSP3_CodeLengths[8];
286
uint16 DSP3_CodeOffsets[8];
293
void DSP3_Coordinate()
301
if (DSP3_DR == 0xffff)
330
uint8 DSP3_Bitmap[8];
331
uint8 DSP3_Bitplane[8];
336
void DSP3_Convert_A()
338
if (DSP3_BMIndex < 8)
340
DSP3_Bitmap[DSP3_BMIndex++] = (uint8) (DSP3_DR);
341
DSP3_Bitmap[DSP3_BMIndex++] = (uint8) (DSP3_DR >> 8);
343
if (DSP3_BMIndex == 8)
346
for (i=0; i < 8; i++)
347
for (j=0; j < 8; j++)
349
DSP3_Bitplane[j] <<= 1;
350
DSP3_Bitplane[j] |= (DSP3_Bitmap[i] >> j) & 1;
358
if (DSP3_BMIndex == 8)
360
if (DSP3_BPIndex == 8)
362
if (!DSP3_Count) DSP3_Reset();
367
DSP3_DR = DSP3_Bitplane[DSP3_BPIndex++];
368
DSP3_DR |= DSP3_Bitplane[DSP3_BPIndex++] << 8;
375
DSP3_Count = DSP3_DR;
377
SetDSP3 = &DSP3_Convert_A;
380
bool DSP3_GetBits(uint8 Count)
384
DSP3_BitsLeft = Count;
396
if (DSP3_ReqData & 0x8000) DSP3_ReqBits++;
402
} while (DSP3_BitsLeft);
407
void DSP3_Decode_Data()
413
DSP3_ReqData = DSP3_DR;
423
if (DSP3_LZCode == 1)
425
if (!DSP3_GetBits(1))
436
if (DSP3_LZCode == 2)
438
if (!DSP3_GetBits(DSP3_LZLength))
443
if (!DSP3_Outwords) SetDSP3 = &DSP3_Reset;
446
DSP3_DR = DSP3_ReqBits;
450
if (DSP3_BaseCode == 0xffff)
452
if (!DSP3_GetBits(DSP3_BaseLength))
455
DSP3_BaseCode = DSP3_ReqBits;
458
if (!DSP3_GetBits(DSP3_CodeLengths[DSP3_BaseCode]))
461
DSP3_Symbol = DSP3_Codes[DSP3_CodeOffsets[DSP3_BaseCode] + DSP3_ReqBits];
462
DSP3_BaseCode = 0xffff;
464
if (DSP3_Symbol & 0xff00)
466
DSP3_Symbol += 0x7f02;
473
SetDSP3 = &DSP3_Reset;
477
DSP3_DR = DSP3_Symbol;
480
void DSP3_Decode_Tree()
484
DSP3_ReqData = DSP3_DR;
503
while (DSP3_BaseCodes)
505
if (!DSP3_GetBits(3))
510
DSP3_CodeLengths[DSP3_Index] = (uint8) DSP3_ReqBits;
511
DSP3_CodeOffsets[DSP3_Index] = DSP3_Symbol;
514
DSP3_Symbol += 1 << DSP3_ReqBits;
518
DSP3_BaseCode = 0xffff;
521
SetDSP3 = &DSP3_Decode_Data;
522
if (DSP3_BitCount) DSP3_Decode_Data();
525
void DSP3_Decode_Symbols()
527
DSP3_ReqData = DSP3_DR;
532
if (DSP3_BitCommand == 0xffff)
534
if (!DSP3_GetBits(2)) return;
535
DSP3_BitCommand = DSP3_ReqBits;
538
switch (DSP3_BitCommand)
542
if (!DSP3_GetBits(9)) return;
543
DSP3_Symbol = DSP3_ReqBits;
553
if (!DSP3_GetBits(1)) return;
554
DSP3_Symbol += 2 + DSP3_ReqBits;
559
if (!DSP3_GetBits(4)) return;
560
DSP3_Symbol += 4 + DSP3_ReqBits;
565
DSP3_BitCommand = 0xffff;
567
DSP3_Codes[DSP3_Index++] = DSP3_Symbol;
570
} while (DSP3_Codewords);
576
SetDSP3 = &DSP3_Decode_Tree;
577
if (DSP3_BitCount) DSP3_Decode_Tree();
582
DSP3_Outwords = DSP3_DR;
583
SetDSP3 = &DSP3_Decode_Symbols;
588
DSP3_BitCommand = 0xffff;
594
DSP3_Codewords = DSP3_DR;
595
SetDSP3 = &DSP3_Decode_A;
599
// Opcodes 1E/3E bit-perfect to 'dsp3-intro' log
600
// src: adapted from SD Gundam X/G-Next
605
int16 op1e_terrain[0x2000];
606
int16 op1e_cost[0x2000];
607
int16 op1e_weight[0x2000];
616
int16 op1e_min_radius;
617
int16 op1e_max_radius;
619
int16 op1e_max_search_radius;
620
int16 op1e_max_path_radius;
622
int16 op1e_lcv_radius;
623
int16 op1e_lcv_steps;
624
int16 op1e_lcv_turns;
628
op3e_x = (uint8)(DSP3_DR & 0x00ff);
629
op3e_y = (uint8)((DSP3_DR & 0xff00)>>8);
633
op1e_terrain[ DSP3_DR ] = 0x00;
634
op1e_cost[ DSP3_DR ] = 0xff;
635
op1e_weight[ DSP3_DR ] = 0;
637
op1e_max_search_radius = 0;
638
op1e_max_path_radius = 0;
654
void DSP3_OP1E_D( int16, int16 *, int16 * );
655
void DSP3_OP1E_D1( int16 move, int16 *lo, int16 *hi );
661
op1e_min_radius = (uint8)(DSP3_DR & 0x00ff);
662
op1e_max_radius = (uint8)((DSP3_DR & 0xff00)>>8);
664
if( op1e_min_radius == 0 )
667
if( op1e_max_search_radius >= op1e_min_radius )
668
op1e_min_radius = op1e_max_search_radius+1;
670
if( op1e_max_radius > op1e_max_search_radius )
671
op1e_max_search_radius = op1e_max_radius;
673
op1e_lcv_radius = op1e_min_radius;
674
op1e_lcv_steps = op1e_min_radius;
682
for( lcv = 0; lcv < op1e_min_radius; lcv++ )
683
DSP3_OP1E_D( op1e_turn, &op1e_x, &op1e_y );
692
if( op1e_lcv_steps == 0 ) {
695
op1e_lcv_steps = op1e_lcv_radius;
700
for( lcv = 0; lcv < op1e_lcv_radius; lcv++ )
701
DSP3_OP1E_D( op1e_turn, &op1e_x, &op1e_y );
704
if( op1e_lcv_radius > op1e_max_radius ) {
708
op1e_lcv_radius = op1e_min_radius;
709
op1e_lcv_steps = op1e_min_radius;
714
for( lcv = 0; lcv < op1e_min_radius; lcv++ )
715
DSP3_OP1E_D( op1e_turn, &op1e_x, &op1e_y );
718
if( op1e_lcv_turns == 0 ) {
721
SetDSP3 = &DSP3_OP1E_B;
725
DSP3_DR = (uint8)(op1e_x) | ((uint8)(op1e_y)<<8);
731
SetDSP3 = &DSP3_OP1E_A1;
737
SetDSP3 = &DSP3_OP1E_A2;
742
op1e_terrain[ op1e_cell ] = (uint8)(DSP3_DR & 0x00ff);
745
SetDSP3 = &DSP3_OP1E_A3;
750
op1e_cost[ op1e_cell ] = (uint8)(DSP3_DR & 0x00ff);
752
if( op1e_lcv_radius == 1 ) {
753
if( op1e_terrain[ op1e_cell ] & 1 ) {
754
op1e_weight[ op1e_cell ] = 0xff;
756
op1e_weight[ op1e_cell ] = op1e_cost[ op1e_cell ];
760
op1e_weight[ op1e_cell ] = 0xff;
763
DSP3_OP1E_D( (int16)(op1e_turn+2), &op1e_x, &op1e_y );
781
SetDSP3 = &DSP3_OP1E_C;
787
while( op1e_lcv_radius < op1e_max_radius ) {
793
while( op1e_lcv_turns ) {
794
op1e_lcv_steps = op1e_lcv_radius;
796
while( op1e_lcv_steps ) {
797
DSP3_OP1E_D1( op1e_turn, &op1e_x, &op1e_y );
799
if( 0 <= op1e_y && op1e_y < DSP3_WinHi &&
800
0 <= op1e_x && op1e_x < DSP3_WinLo ) {
801
DSP3_DR = (uint8)(op1e_x) | ((uint8)(op1e_y)<<8);
805
if( op1e_cost[ op1e_cell ] < 0x80 &&
806
op1e_terrain[ op1e_cell ] < 0x40 ) {
808
} // end cell perimeter
815
if( op1e_turn == 0 ) op1e_turn = 6;
818
} // end circle search
821
} // end radius search
839
DSP3_OP1E_D1( lcv_turns, &x, &y );
841
DSP3_DR = (uint8)(x) | ((uint8)(y)<<8);
846
if( 0 <= y && y < DSP3_WinHi &&
847
0 <= x && x < DSP3_WinLo ) {
849
if( op1e_terrain[ cell ] < 0x80 || op1e_weight[ cell ] == 0 ) {
850
if( op1e_weight[ cell ] < path ) {
851
path = op1e_weight[ cell ];
860
op1e_weight[ op1e_cell ] = path + op1e_cost[ op1e_cell ];
869
op1e_min_radius = (uint8)(DSP3_DR & 0x00ff);
870
op1e_max_radius = (uint8)((DSP3_DR & 0xff00)>>8);
872
if( op1e_min_radius == 0 )
875
if( op1e_max_path_radius >= op1e_min_radius )
876
op1e_min_radius = op1e_max_path_radius+1;
878
if( op1e_max_radius > op1e_max_path_radius )
879
op1e_max_path_radius = op1e_max_radius;
881
op1e_lcv_radius = op1e_min_radius;
882
op1e_lcv_steps = op1e_min_radius;
890
for( lcv = 0; lcv < op1e_min_radius; lcv++ )
891
DSP3_OP1E_D( op1e_turn, &op1e_x, &op1e_y );
901
if( op1e_lcv_steps == 0 ) {
904
op1e_lcv_steps = op1e_lcv_radius;
909
for( lcv = 0; lcv < op1e_lcv_radius; lcv++ )
910
DSP3_OP1E_D( op1e_turn, &op1e_x, &op1e_y );
913
if( op1e_lcv_radius > op1e_max_radius ) {
917
op1e_lcv_radius = op1e_min_radius;
918
op1e_lcv_steps = op1e_min_radius;
923
for( lcv = 0; lcv < op1e_min_radius; lcv++ )
924
DSP3_OP1E_D( op1e_turn, &op1e_x, &op1e_y );
927
if( op1e_lcv_turns == 0 ) {
930
SetDSP3 = &DSP3_Reset;
934
DSP3_DR = (uint8)(op1e_x) | ((uint8)(op1e_y)<<8);
940
SetDSP3 = &DSP3_OP1E_C2;
946
DSP3_DR = op1e_weight[ op1e_cell ];
948
DSP3_OP1E_D( (int16)(op1e_turn+2), &op1e_x, &op1e_y );
952
SetDSP3 = &DSP3_OP1E_C1;
956
void DSP3_OP1E_D( int16 move, int16 *lo, int16 *hi )
958
uint32 dataOfs = ((move << 1) + 0x03b2) & 0x03ff;
962
DSP3_AddHi = DSP3_DataROM[dataOfs];
963
DSP3_AddLo = DSP3_DataROM[dataOfs + 1];
968
if (Lo & 1) Hi += (DSP3_AddLo & 1);
974
DSP3_AddLo += DSP3_WinLo;
976
if (DSP3_AddLo >= DSP3_WinLo)
977
DSP3_AddLo -= DSP3_WinLo;
980
DSP3_AddHi += DSP3_WinHi;
982
if (DSP3_AddHi >= DSP3_WinHi)
983
DSP3_AddHi -= DSP3_WinHi;
990
void DSP3_OP1E_D1( int16 move, int16 *lo, int16 *hi )
992
//uint32 dataOfs = ((move << 1) + 0x03b2) & 0x03ff;
996
const unsigned short HiAdd[] = {
997
0x00, 0xFF, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00,
998
0x00, 0xFF, 0xFF, 0x00, 0x01, 0x00, 0xFF, 0x00
1000
const unsigned short LoAdd[] = {
1001
0x00, 0x00, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x00
1005
DSP3_AddHi = HiAdd[ move + 8 ];
1007
DSP3_AddHi = HiAdd[ move + 0 ];
1008
DSP3_AddLo = LoAdd[ move ];
1013
if (Lo & 1) Hi += (DSP3_AddLo & 1);
1025
if( DSP3_DR == 0xffff ) {
1039
SetDSP3 = &DSP3_Reset;
1048
//SetDSP3 = &DSP3_OP0C_A;
1049
SetDSP3 = &DSP3_Reset;
1057
SetDSP3 = &DSP3_Reset;
1067
SetDSP3 = &DSP3_OP1C_C;
1075
SetDSP3 = &DSP3_OP1C_B;
1083
SetDSP3 = &DSP3_OP1C_A;
1093
case 0x02: SetDSP3 = &DSP3_Coordinate; break;
1094
case 0x03: SetDSP3 = &DSP3_OP03; break;
1095
case 0x06: SetDSP3 = &DSP3_OP06; break;
1096
case 0x07: SetDSP3 = &DSP3_OP07; return;
1097
case 0x0c: SetDSP3 = &DSP3_OP0C; break;
1098
case 0x0f: SetDSP3 = &DSP3_TestMemory; break;
1099
case 0x10: SetDSP3 = &DSP3_OP10; break;
1100
case 0x18: SetDSP3 = &DSP3_Convert; break;
1101
case 0x1c: SetDSP3 = &DSP3_OP1C; break;
1102
case 0x1e: SetDSP3 = &DSP3_OP1E; break;
1103
case 0x1f: SetDSP3 = &DSP3_MemoryDump; break;
1104
case 0x38: SetDSP3 = &DSP3_Decode; break;
1105
case 0x3e: SetDSP3 = &DSP3_OP3E; break;
1115
uint16 dsp3_address;
1119
if (dsp3_address < 0xC000)
1123
DSP3_DR = (DSP3_DR & 0xff00) + dsp3_byte;
1131
DSP3_DR = (DSP3_DR & 0xff00) + dsp3_byte;
1134
DSP3_DR = (DSP3_DR & 0x00ff) + (dsp3_byte << 8);
1143
if (dsp3_address < 0xC000)
1147
dsp3_byte = (uint8) DSP3_DR;
1155
dsp3_byte = (uint8) (DSP3_DR);
1158
dsp3_byte = (uint8) (DSP3_DR >> 8);
1166
dsp3_byte = (uint8) DSP3_SR;