Debian Codegraph @

support/babel/level9.c

raw symbols SCIP
1 /* level9.c Treaty of Babel module for Level 9 files
2 * 2006 By L. Ross Raszewski
3 *
4 * Note that this module will handle both bare Level 9 A-Code and
5 * Spectrum .SNA snapshots. It will not handle compressed .Z80 images.
6 *
7 * The Level 9 identification algorithm is based in part on the algorithm
8 * used by Paul David Doherty's l9cut program.
9 *
10 * This file depends on treaty_builder.h
11 *
12 * This file is public domain, but note that any changes to this file
13 * may render it noncompliant with the Treaty of Babel
14 */
15
16 #define FORMAT level9
17 #define HOME_PAGE "http://www.if-legends.org/~l9memorial/html/home.html"
18 #define FORMAT_EXT ".l9,.sna"
19 #define NO_METADATA
20 #define NO_COVER
21
22 #include "treaty_builder.h"
23 #include <ctype.h>
24 #include <stdio.h>
25 #include <string.h>
26
27 struct l9rec {
28 int32 length;
29 unsigned char chk;
30 char *ifid;
31 };
32
33
34 static struct l9rec l9_registry[] = {
35 { 0x3a31, 0xe5, "LEVEL9-001-1" },
36 { 0x8333, 0xb7, "LEVEL9-001-1" },
37 { 0x7c6f, 0x0f, "LEVEL9-001-1" },
38 { 0x72fa, 0x8b, "LEVEL9-001-1" },
39 { 0x38dd, 0x31, "LEVEL9-001-A" },
40 { 0x39c0, 0x44, "LEVEL9-001-B" },
41 { 0x3a12, 0x8f, "LEVEL9-001-C" },
42 { 0x37f1, 0x77, "LEVEL9-001-2" },
43 { 0x844d, 0x50, "LEVEL9-001-2" },
44 { 0x738e, 0x5b, "LEVEL9-001-2" },
45 { 0x3900, 0x1c, "LEVEL9-001-3" },
46 { 0x8251, 0x5f, "LEVEL9-001-3" },
47 { 0x7375, 0xe5, "LEVEL9-001-3" },
48 { 0x3910, 0xac, "LEVEL9-001-4" },
49 { 0x7a78, 0x5e, "LEVEL9-001-4" },
50 { 0x78d5, 0xe3, "LEVEL9-001-4" },
51 { 0x3ad6, 0xa7, "LEVEL9-001-5" },
52 { 0x38a5, 0x0f, "LEVEL9-001-6" },
53 { 0x361e, 0x7e, "LEVEL9-001-7" },
54 { 0x3934, 0x75, "LEVEL9-001-8" },
55 { 0x3511, 0xcc, "LEVEL9-001-9" },
56 { 0x593a, 0xaf, "LEVEL9-002-1" },
57 { 0x7931, 0xb9, "LEVEL9-002-1" },
58 { 0x6841, 0x4a, "LEVEL9-002-1" },
59 { 0x57e6, 0x8a, "LEVEL9-002-2" },
60 { 0x7cdf, 0xa5, "LEVEL9-002-2" },
61 { 0x6bc0, 0x62, "LEVEL9-002-2" },
62 { 0x5819, 0xcd, "LEVEL9-002-3" },
63 { 0x7a0c, 0x97, "LEVEL9-002-3" },
64 { 0x692c, 0x21, "LEVEL9-002-3" },
65 { 0x579b, 0xad, "LEVEL9-002-4" },
66 { 0x7883, 0xe2, "LEVEL9-002-4" },
67 { 0x670a, 0x94, "LEVEL9-002-4" },
68 { 0x5323, 0xb7, "LEVEL9-003" },
69 { 0x6e60, 0x83, "LEVEL9-003" },
70 { 0x5b58, 0x50, "LEVEL9-003" },
71 { 0x63b6, 0x2e, "LEVEL9-003" },
72 { 0x6968, 0x32, "LEVEL9-003" },
73 { 0x5b50, 0x66, "LEVEL9-003" },
74 { 0x6970, 0xd6, "LEVEL9-003" },
75 { 0x5ace, 0x11, "LEVEL9-003" },
76 { 0x6e5c, 0xf6, "LEVEL9-003" },
77 { 0x1929, 0x00, "LEVEL9-004-DEMO" },
78 { 0x40e0, 0x02, "LEVEL9-004-DEMO" },
79 { 0x3ebb, 0x00, "LEVEL9-004-en" },
80 { 0x3e4f, 0x00, "LEVEL9-004-en" },
81 { 0x3e8f, 0x00, "LEVEL9-004-en" },
82 { 0x0fd8, 0x00, "LEVEL9-004-en" },
83 { 0x14a3, 0x00, "LEVEL9-004-en" },
84 { 0x110f, 0x00, "LEVEL9-004-fr" },
85 { 0x4872, 0x00, "LEVEL9-004-de" },
86 { 0x4846, 0x00, "LEVEL9-004-de" },
87 { 0x11f5, 0x00, "LEVEL9-004-de" },
88 { 0x11f5, 0x00, "LEVEL9-004-de" },
89 { 0x76f4, 0x5e, "LEVEL9-005" },
90 { 0x5b16, 0x3b, "LEVEL9-005" },
91 { 0x6c8e, 0xb6, "LEVEL9-005" },
92 { 0x6f4d, 0xcb, "LEVEL9-005" },
93 { 0x6f6a, 0xa5, "LEVEL9-005" },
94 { 0x5e31, 0x7c, "LEVEL9-005" },
95 { 0x6f70, 0x40, "LEVEL9-005" },
96 { 0x6f6e, 0x78, "LEVEL9-005" },
97 { 0x5a8e, 0xf2, "LEVEL9-005" },
98 { 0x76f4, 0x5a, "LEVEL9-005" },
99 { 0x630e, 0x8d, "LEVEL9-006" },
100 { 0x630e, 0xbe, "LEVEL9-006" },
101 { 0x6f0c, 0x95, "LEVEL9-006" },
102 { 0x593a, 0x80, "LEVEL9-006" },
103 { 0x6bd2, 0x65, "LEVEL9-006" },
104 { 0x6dc0, 0x63, "LEVEL9-006" },
105 { 0x58a6, 0x24, "LEVEL9-006" },
106 { 0x6de8, 0x4c, "LEVEL9-006" },
107 { 0x58a3, 0x38, "LEVEL9-006" },
108 { 0x63be, 0xd6, "LEVEL9-007" },
109 { 0x378c, 0x8d, "LEVEL9-007" },
110 { 0x63be, 0x0a, "LEVEL9-007" },
111 { 0x34b3, 0x20, "LEVEL9-008" },
112 { 0x34b3, 0xc7, "LEVEL9-008" },
113 { 0x34b3, 0x53, "LEVEL9-008" },
114 { 0xb1a9, 0x80, "LEVEL9-009-1" },
115 { 0x908e, 0x0d, "LEVEL9-009-1" },
116 { 0xad41, 0xa8, "LEVEL9-009-1" },
117 { 0xb1aa, 0xad, "LEVEL9-009-1" },
118 { 0x8aab, 0xc0, "LEVEL9-009-1" },
119 { 0xb0ec, 0xc2, "LEVEL9-009-1" },
120 { 0xb19e, 0x92, "LEVEL9-009-1" },
121 { 0x5ff0, 0xf8, "LEVEL9-009-1" },
122 { 0x52aa, 0xdf, "LEVEL9-009-1" },
123 { 0xab9d, 0x31, "LEVEL9-009-2" },
124 { 0x8f6f, 0x0a, "LEVEL9-009-2" },
125 { 0xa735, 0xf7, "LEVEL9-009-2" },
126 { 0xab8b, 0xbf, "LEVEL9-009-2" },
127 { 0x8ac8, 0x9a, "LEVEL9-009-2" },
128 { 0xaf82, 0x83, "LEVEL9-009-2" },
129 { 0x6024, 0x01, "LEVEL9-009-2" },
130 { 0x6ffa, 0xdb, "LEVEL9-009-2" },
131 { 0xae28, 0x87, "LEVEL9-009-3" },
132 { 0x9060, 0xbb, "LEVEL9-009-3" },
133 { 0xa9c0, 0x9e, "LEVEL9-009-3" },
134 { 0xae16, 0x81, "LEVEL9-009-3" },
135 { 0x8a93, 0x4f, "LEVEL9-009-3" },
136 { 0xb3e6, 0xab, "LEVEL9-009-3" },
137 { 0x6036, 0x3d, "LEVEL9-009-3" },
138 { 0x723a, 0x69, "LEVEL9-009-3" },
139 { 0xd188, 0x13, "LEVEL9-010-1" },
140 { 0x9089, 0xce, "LEVEL9-010-1" },
141 { 0xb770, 0x03, "LEVEL9-010-1" },
142 { 0xd19b, 0xad, "LEVEL9-010-1" },
143 { 0x8ab7, 0x68, "LEVEL9-010-1" },
144 { 0xd183, 0x83, "LEVEL9-010-1" },
145 { 0x5a38, 0xf7, "LEVEL9-010-1" },
146 { 0x76a0, 0x3a, "LEVEL9-010-1" },
147 { 0xc594, 0x03, "LEVEL9-010-2" },
148 { 0x908d, 0x80, "LEVEL9-010-2" },
149 { 0xb741, 0xb6, "LEVEL9-010-2" },
150 { 0xc5a5, 0xfe, "LEVEL9-010-2" },
151 { 0x8b1e, 0x84, "LEVEL9-010-2" },
152 { 0xc58f, 0x65, "LEVEL9-010-2" },
153 { 0x531a, 0xed, "LEVEL9-010-2" },
154 { 0x7674, 0x0b, "LEVEL9-010-2" },
155 { 0xd79f, 0xb5, "LEVEL9-010-3" },
156 { 0x909e, 0x9f, "LEVEL9-010-3" },
157 { 0xb791, 0xa1, "LEVEL9-010-3" },
158 { 0xd7ae, 0x9e, "LEVEL9-010-3" },
159 { 0x8b1c, 0xa8, "LEVEL9-010-3" },
160 { 0xd79a, 0x57, "LEVEL9-010-3" },
161 { 0x57e4, 0x19, "LEVEL9-010-3" },
162 { 0x765e, 0xba, "LEVEL9-010-3" },
163 { 0xbb93, 0x36, "LEVEL9-011-1" },
164 { 0x898a, 0x43, "LEVEL9-011-1" },
165 { 0x8970, 0x6b, "LEVEL9-011-1" },
166 { 0xbb6e, 0xa6, "LEVEL9-011-1" },
167 { 0x86d0, 0xb7, "LEVEL9-011-1" },
168 { 0xbb6e, 0xad, "LEVEL9-011-1" },
169 { 0x46ec, 0x64, "LEVEL9-011-1" },
170 { 0x74e0, 0x92, "LEVEL9-011-1" },
171 { 0xc58e, 0x4a, "LEVEL9-011-2" },
172 { 0x8b9f, 0x61, "LEVEL9-011-2" },
173 { 0x8b90, 0x4e, "LEVEL9-011-2" },
174 { 0xc58e, 0x43, "LEVEL9-011-2" },
175 { 0x8885, 0x22, "LEVEL9-011-2" },
176 { 0x6140, 0x18, "LEVEL9-011-2" },
177 { 0x6dbc, 0x97, "LEVEL9-011-2" },
178 { 0xcb9a, 0x0f, "LEVEL9-011-3" },
179 { 0x8af9, 0x61, "LEVEL9-011-3" },
180 { 0x8aea, 0x4e, "LEVEL9-011-3" },
181 { 0xcb9a, 0x08, "LEVEL9-011-3" },
182 { 0x87e5, 0x0e, "LEVEL9-011-3" },
183 { 0x640e, 0xc1, "LEVEL9-011-3" },
184 { 0x7402, 0x07, "LEVEL9-011-3" },
185 { 0xbba4, 0x94, "LEVEL9-012-1" },
186 { 0xc0cf, 0x4e, "LEVEL9-012-1" },
187 { 0x8afc, 0x07, "LEVEL9-012-1" },
188 { 0x8feb, 0xba, "LEVEL9-012-1" },
189 { 0xb4c9, 0x94, "LEVEL9-012-1" },
190 { 0xc0bd, 0x57, "LEVEL9-012-1" },
191 { 0x8ade, 0xf2, "LEVEL9-012-1" },
192 { 0x4fd2, 0x9d, "LEVEL9-012-1" },
193 { 0x5c7a, 0x44, "LEVEL9-012-1" },
194 { 0x768c, 0xe8, "LEVEL9-012-1" },
195 { 0xd0c0, 0x56, "LEVEL9-012-2" },
196 { 0xd5e9, 0x6a, "LEVEL9-012-2" },
197 { 0x8aec, 0x13, "LEVEL9-012-2" },
198 { 0x8f6b, 0xfa, "LEVEL9-012-2" },
199 { 0xb729, 0x51, "LEVEL9-012-2" },
200 { 0xd5d7, 0x99, "LEVEL9-012-2" },
201 { 0x8b0e, 0xfb, "LEVEL9-012-2" },
202 { 0x4dac, 0xa8, "LEVEL9-012-2" },
203 { 0x53a2, 0x1e, "LEVEL9-012-2" },
204 { 0x76b0, 0x1d, "LEVEL9-012-2" },
205 { 0xb6ac, 0xc6, "LEVEL9-012-3" },
206 { 0xbb8f, 0x1a, "LEVEL9-012-3" },
207 { 0x8aba, 0x0d, "LEVEL9-012-3" },
208 { 0x8f71, 0x2f, "LEVEL9-012-3" },
209 { 0xb702, 0xe4, "LEVEL9-012-3" },
210 { 0xbb7d, 0x17, "LEVEL9-012-3" },
211 { 0x8ab3, 0xc1, "LEVEL9-012-3" },
212 { 0x4f96, 0x22, "LEVEL9-012-3" },
213 { 0x5914, 0x22, "LEVEL9-012-3" },
214 { 0x765e, 0x4f, "LEVEL9-012-3" },
215 { 0x5eb9, 0x30, "LEVEL9-013" },
216 { 0x5eb9, 0x5d, "LEVEL9-013" },
217 { 0x5eb9, 0x6e, "LEVEL9-013" },
218 { 0xb257, 0xf8, "LEVEL9-013" },
219 { 0xb576, 0x2a, "LEVEL9-013" },
220 { 0x8d78, 0x3a, "LEVEL9-013" },
221 { 0x9070, 0x43, "LEVEL9-013" },
222 { 0xb38c, 0x37, "LEVEL9-013" },
223 { 0xb563, 0x6a, "LEVEL9-013" },
224 { 0xb57c, 0x44, "LEVEL9-013" },
225 { 0xb260, 0xe5, "LEVEL9-013" },
226 { 0x8950, 0xa1, "LEVEL9-013" },
227 { 0xb579, 0x89, "LEVEL9-013" },
228 { 0x579e, 0x97, "LEVEL9-013" },
229 { 0x69fe, 0x56, "LEVEL9-013" },
230 { 0x6f1e, 0xda, "LEVEL9-013" },
231 { 0x5671, 0xbc, "LEVEL9-014" },
232 { 0x6fc6, 0x14, "LEVEL9-014" },
233 { 0x5aa4, 0xc1, "LEVEL9-014" },
234 { 0x7410, 0x5e, "LEVEL9-014" },
235 { 0x5aa4, 0xc1, "LEVEL9-014" },
236 { 0x5aa4, 0xc1, "LEVEL9-014" },
237 { 0xb797, 0x1f, "LEVEL9-014" },
238 { 0xbaca, 0x3a, "LEVEL9-014" },
239 { 0x8c46, 0xf0, "LEVEL9-014" },
240 { 0x8f51, 0xb2, "LEVEL9-014" },
241 { 0xb451, 0xa8, "LEVEL9-014" },
242 { 0xbab2, 0x87, "LEVEL9-014" },
243 { 0xbac7, 0x7f, "LEVEL9-014" },
244 { 0xb7a0, 0x7e, "LEVEL9-014" },
245 { 0x8a60, 0x2a, "LEVEL9-014" },
246 { 0xbac4, 0x80, "LEVEL9-014" },
247 { 0x579a, 0x2a, "LEVEL9-014" },
248 { 0x5a50, 0xa9, "LEVEL9-014" },
249 { 0x6108, 0xdd, "LEVEL9-014" },
250 { 0x506c, 0xf0, "LEVEL9-015" },
251 { 0x505d, 0x32, "LEVEL9-015" },
252 { 0xa398, 0x82, "LEVEL9-015" },
253 { 0xa692, 0xd1, "LEVEL9-015" },
254 { 0x8d56, 0xd3, "LEVEL9-015" },
255 { 0x903f, 0x6b, "LEVEL9-015" },
256 { 0xa4e2, 0xa6, "LEVEL9-015" },
257 { 0xa67c, 0xb8, "LEVEL9-015" },
258 { 0xa69e, 0x6c, "LEVEL9-015" },
259 { 0xa3a4, 0xdf, "LEVEL9-015" },
260 { 0x8813, 0x11, "LEVEL9-015" },
261 { 0xa698, 0x41, "LEVEL9-015" },
262 { 0x5500, 0x50, "LEVEL9-015" },
263 { 0x6888, 0x8d, "LEVEL9-015" },
264 { 0x6da0, 0xb8, "LEVEL9-015" },
265 { 0x6064, 0xbd, "LEVEL9-016" },
266 { 0x6064, 0x01, "LEVEL9-016" },
267 { 0x6047, 0x6c, "LEVEL9-016" },
268 { 0x6064, 0xda, "LEVEL9-016" },
269 { 0x6064, 0x95, "LEVEL9-016" },
270 { 0x60c4, 0x28, "LEVEL9-016" },
271 { 0x5cb7, 0xfe, "LEVEL9-016" },
272 { 0x5ca1, 0x33, "LEVEL9-016" },
273 { 0x5cb7, 0x64, "LEVEL9-016" },
274 { 0x7d16, 0xe6, "LEVEL9-016" },
275 { 0x639c, 0x8b, "LEVEL9-016" },
276 { 0x60f7, 0x68, "LEVEL9-016" },
277 { 0x772f, 0xca, "LEVEL9-016" },
278 { 0x7cff, 0xf8, "LEVEL9-016" },
279 { 0x7cf8, 0x24, "LEVEL9-016" },
280 { 0x7d14, 0xe8, "LEVEL9-016" },
281 { 0x7c55, 0x18, "LEVEL9-016" },
282 { 0x5f43, 0xca, "LEVEL9-016" },
283 { 0xc132, 0x14, "LEVEL9-017-1" },
284 { 0xbeab, 0x2d, "LEVEL9-017-1" },
285 { 0x9058, 0xcf, "LEVEL9-017-1" },
286 { 0xbe94, 0xcc, "LEVEL9-017-1" },
287 { 0x8a21, 0xf4, "LEVEL9-017-1" },
288 { 0x55ce, 0xa1, "LEVEL9-017-1" },
289 { 0x5cbc, 0xa5, "LEVEL9-017-1" },
290 { 0x762e, 0x82, "LEVEL9-017-1" },
291 { 0x99bd, 0x65, "LEVEL9-017-2" },
292 { 0x8f43, 0xc9, "LEVEL9-017-2" },
293 { 0x8a12, 0xe3, "LEVEL9-017-2" },
294 { 0x54a6, 0xa9, "LEVEL9-017-2" },
295 { 0x5932, 0x4e, "LEVEL9-017-2" },
296 { 0x5bd6, 0x35, "LEVEL9-017-2" },
297 { 0xbcb6, 0x7a, "LEVEL9-017-3 (Amiga/PC/ST)" },
298 { 0x90ac, 0x68, "LEVEL9-017-3" },
299 { 0x8a16, 0xcc, "LEVEL9-017-3" },
300 { 0x51bc, 0xe3, "LEVEL9-017-3" },
301 { 0x5860, 0x95, "LEVEL9-017-3" },
302 { 0x6fa8, 0xa4, "LEVEL9-017-3" },
303 { 0x5fab, 0x5c, "LEVEL9-018" },
304 { 0x5fab, 0x2f, "LEVEL9-018" },
305 { 0x7b31, 0x6e, "LEVEL9-018" },
306 { 0x67a3, 0x9d, "LEVEL9-018" },
307 { 0x6bf8, 0x3f, "LEVEL9-018" },
308 { 0x7363, 0x65, "LEVEL9-018" },
309 { 0x7b2f, 0x70, "LEVEL9-018" },
310 { 0x7b2f, 0x70, "LEVEL9-018" },
311 { 0x6541, 0x02, "LEVEL9-018" },
312 { 0x5834, 0x42, "LEVEL9-019-1" },
313 { 0x765d, 0xcd, "LEVEL9-019-1" },
314 { 0x6ce5, 0x58, "LEVEL9-019-1" },
315 { 0x56dd, 0x51, "LEVEL9-019-2" },
316 { 0x6e58, 0x07, "LEVEL9-019-2" },
317 { 0x68da, 0xc1, "LEVEL9-019-2" },
318 { 0x5801, 0x53, "LEVEL9-019-3" },
319 { 0x7e98, 0x6a, "LEVEL9-019-3" },
320 { 0x6c67, 0x9a, "LEVEL9-019-3" },
321 { 0x54a4, 0x01, "LEVEL9-019-4" },
322 { 0x81e2, 0xd5, "LEVEL9-019-4" },
323 { 0x6d91, 0xb9, "LEVEL9-019-4" },
324 { 0x5828, 0xbd, "LEVEL9-020" },
325 { 0x6d84, 0xf9, "LEVEL9-020" },
326 { 0x6d84, 0xc8, "LEVEL9-020" },
327 { 0x6030, 0x47, "LEVEL9-020" },
328 { 0x772b, 0xcd, "LEVEL9-020" },
329 { 0x546c, 0xb7, "LEVEL9-020" },
330 { 0x7cd9, 0x0c, "LEVEL9-020" },
331 { 0x60dd, 0xf2, "LEVEL9-020" },
332 { 0x6161, 0xf3, "LEVEL9-020" },
333 { 0x788d, 0x72, "LEVEL9-020" },
334 { 0x7cd7, 0x0e, "LEVEL9-020" },
335 { 0x5ebb, 0xf1, "LEVEL9-020" },
336
337 { 0, 0, NULL }
338 };
339
340
341
342 static int32 read_l9_int(unsigned char *sf)
343 {
344 return ((int32) sf[1]) << 8 | sf[0];
345
346 }
347 static int v2_recognition (unsigned char *sf, int32 extent, int32 *l, unsigned char *c)
348 {
349 int32 i, j;
350 for (i=0;i<extent-20;i++)
351 if ((read_l9_int(sf+i+4) == 0x0020) &&
352 (read_l9_int(sf+i+0x0a) == 0x8000) &&
353 (read_l9_int(sf+i+0x14) == read_l9_int(sf+i+0x16)))
354 {
355 *l=read_l9_int(sf+i+0x1c);
356 if (*l && *l+i <=extent)
357 {
358 *c=0;
359 for(j=0;j<=*l;j++)
360 *c+=sf[i+j];
361 return 2;
362 }
363 }
364 return 0;
365 }
366 static int v1_recognition(unsigned char *sf, int32 extent, char **ifid)
367 {
368 int32 i;
369 unsigned char a = 0xff, b = 0xff;
370
371 for (i=0;i<extent-20;i++)
372 if (memcmp(sf+i,"ATTAC",5)==0 && sf[i+5]==0xcb)
373 {
374 a = sf[i+6];
375 break;
376 }
377 for (;i<(extent-20);i++)
378 if (memcmp(sf+i,"BUNC",4)==0 && sf[i+4]==0xc8)
379 {
380 b = sf[i + 5];
381 break;
382 }
383 if (a == 0xff && b == 0xff)
384 return 0;
385 if (a == 0x14 && b == 0xff) *ifid="LEVEL9-006";
386 else if (a == 0x15 && b == 0x5d) *ifid="LEVEL9-013";
387 else if (a == 0x1a && b == 0x24) *ifid="LEVEL9-005";
388 else if (a == 0x20 && b == 0x3b) *ifid="LEVEL9-003";
389 else *ifid=NULL;
390 return 1;
391 }
392 static int v3_recognition_phase (int phase,unsigned char *sf, int32 extent, int32 *l, unsigned char *c)
393 {
394 int32 end, i, j, ll;
395 if (sf == NULL || *sf == '\0')
396 return 0;
397 ll=0;
398 for (i=0;i<extent-20;i++)
399 {
400 if (ll) break;
401 *l = read_l9_int(sf+i);
402 end=*l+i;
403 if (phase!=3)
404 {
405 if (end <= extent &&
406 (
407 ((phase == 2) ||
408 (((end >= 1 && sf[end-1] == 0) &&
409 (end >= 2 && sf[end-2] == 0)) ||
410 ((end <= extent - 2 && sf[end+1] == 0) &&
411 (end <= extent - 3 && sf[end+2] == 0))))
412 && (*l>0x4000) && (*l<=0xdb00)))
413 if ((*l!=0) && (sf[i+0x0d] == 0))
414 for (j=i;j<i+16;j+=2)
415 if (((read_l9_int(sf+j)+read_l9_int(sf+j+2))==read_l9_int(sf+j+4))
416 && ((read_l9_int(sf+j)+read_l9_int(sf+j+2))))
417 ll++;
418 }
419 else
420 {
421 if ((extent>0x0fd0) && (end <= extent) &&
422 (((read_l9_int(sf+i+2) + read_l9_int(sf+i+4))==read_l9_int(sf+i+6))
423 && (read_l9_int(sf+i+2) != 0) && (read_l9_int(sf+i+4)) != 0) &&
424 (((read_l9_int(sf+i+6) + read_l9_int(sf+i+8)) == read_l9_int(sf+i+10))
425 && ((sf[i + 18] == 0x2a) || (sf[i + 18] == 0x2c))
426 && (sf[i + 19] == 0) && (sf[i + 20] == 0) && (sf[i + 21] == 0)))
427 ll = 2;
428 }
429 if (ll>1)
430 {
431 *c=0;
432 if (phase==3) ll=1;
433 else
434 { char checksum=0;
435 *c = sf[end];
436 for (j=i;j<=end;j++)
437 checksum += sf[j];
438 if (!checksum) ll=1;
439 else ll=0;
440 }
441 } else ll=0;
442 }
443
444 if (ll) return *l < 0x8500 ? 3:4;
445 return 0;
446 }
447 static char *get_l9_ifid(int32 length, unsigned char chk)
448 {
449 int i;
450 for(i=0;l9_registry[i].length;i++)
451 if (length==l9_registry[i].length && chk==l9_registry[i].chk) return l9_registry[i].ifid;
452 return NULL;
453 }
454 static int get_l9_version(unsigned char *sf, int32 extent, char **ifid)
455 {
456 int i;
457 int32 l;
458 unsigned char c;
459 if (v2_recognition(sf,extent, &l, &c)) { *ifid=get_l9_ifid(l,c); return 2; }
460 l=0; c=0;
461 i=v3_recognition_phase(1,sf,extent, &l, &c);
462 if (i) { *ifid=get_l9_ifid(l,c); return i; }
463 if (v1_recognition(sf,extent, ifid)) return 1;
464 l=0; c=0;
465 i=v3_recognition_phase(2,sf,extent, &l, &c);
466 if (i) { *ifid=get_l9_ifid(l,c); return i; }
467 i=v3_recognition_phase(3,sf,extent, &l, &c);
468 *ifid=NULL;
469 return i;
470 }
471
472 static int32 claim_story_file(void *story, int32 extent)
473 {
474 char *ifid=NULL;
475 if (get_l9_version((unsigned char *) story,extent, &ifid)) {
476 if (ifid) return VALID_STORY_FILE_RV;
477 else return NO_REPLY_RV;
478 }
479 return INVALID_STORY_FILE_RV;
480 }
481
482
483
484 static int32 get_story_file_IFID(void *story_file, int32 extent, char *output, int32 output_extent)
485 {
486 char *ifid=NULL;
487 int i=get_l9_version((unsigned char *)story_file, extent, &ifid);
488 if (!i) return INVALID_STORY_FILE_RV;
489 if (ifid)
490 {
491 ASSERT_OUTPUT_SIZE((signed) strlen(ifid)+1);
492 strcpy(output,ifid);
493 return 1;
494 }
495 ASSERT_OUTPUT_SIZE(10);
496 sprintf(output,"LEVEL9-%d-",i);
497 return INCOMPLETE_REPLY_RV;
498 }