Debian Codegraph @

terps/unp64/scanners/mr_cross.cpp

raw symbols SCIP
1 /* This is a cut-down version of UNP64 with only the bare minimum
2 * needed to decompress a number of Commodore 64 adventure games.
3 * It is distributed under the zlib License by kind permission of
4 * the original authors Magnus Lind and iAN CooG.
5 */
6
7 /*
8 UNP64 - generic Commodore 64 prg unpacker
9 (C) 2008-2022 iAN CooG/HVSC Crew^C64Intros
10 original source and idea: testrun.c, taken from exo20b7
11
12 Follows original disclaimer
13 */
14
15 /*
16 * Copyright (c) 2002 - 2023 Magnus Lind.
17 *
18 *
19 * This software is provided 'as-is', without any express or implied
20 * warranty. In no event will the authors be held liable for any damages
21 * arising from the use of this software.
22 *
23 * Permission is granted to anyone to use this software for any purpose,
24 * including commercial applications, and to alter it and redistribute it
25 * freely, subject to the following restrictions:
26 *
27 * 1. The origin of this software must not be misrepresented; you must not
28 * claim that you wrote the original software. If you use this software
29 * in a product, an acknowledgment in the product documentation would be
30 * appreciated but is not required.
31 * 2. Altered source versions must be plainly marked as such, and must not be
32 * misrepresented as being the original software.
33 * 3. This notice may not be removed or altered from any source distribution.
34 *
35 */
36
37 /*
38 C++ version based on code adapted to ScummVM by Avijeet Maurya
39 */
40
41 #include "exo_util.h"
42 #include "types.h"
43 #include "unp64.h"
44
45 namespace Unp64 {
46
47 /* Mr.Cross linker */
48 void scnMrCross(UnpStr *unp) {
49 unsigned char *mem;
50 int q, p;
51 if (unp->_idFlag)
52 return;
53 mem = unp->_mem;
54 if (unp->_depAdr == 0) {
55 /*
56 there are sysless versions and also can be at
57 different address than $0801
58 */
59 p = unp->_info->_run;
60 if (p == -1)
61 p = unp->_info->_start;
62 for (q = p + 0x80; p < q; p++) {
63 if (u32eq(mem + p + 0x00, 0x8538A978) &&
64 u32eq(mem + p + 0x04, 0x9AF9A201) &&
65 u32eq(mem + p + 0x0b, 0xCA01069D) &&
66 u32eq(mem + p + 0x36, 0x60D8d000U + (unsigned int)(p >> 8))
67 ) {
68 unp->_depAdr = READ_LE_UINT16(&mem[p + 0x96]);
69 unp->_depAdr += 0x1f;
70 unp->_forced = p;
71 unp->_retAdr = READ_LE_UINT16(&mem[p + 0x9a]);
72 unp->_strMem = READ_LE_UINT16(&mem[p + 0x4d]);
73 unp->_monEnd = (unsigned int)((mem[p + 0x87]) << 24 |
74 (mem[p + 0x86]) << 16 |
75 (mem[p + 0x8d]) << 8 |
76 (mem[p + 0x8c]));
77 break;
78 }
79 if (u32eq(mem + p + 0x00, 0x8538A978) &&
80 u32eq(mem + p + 0x04, 0x9AF9A201) &&
81 u32eq(mem + p + 0x0b, 0xCA01089D) &&
82 u32eq(mem + p + 0x36, 0xe0D8d000U + (unsigned int)(p >> 8))
83 ) {
84 unp->_depAdr = 0x1f6;
85 unp->_forced = p;
86 unp->_retAdr = READ_LE_UINT16(&mem[p + 0xaa]);
87 unp->_strMem = READ_LE_UINT16(&mem[p + 0x53]);
88 unp->_fEndAf = 0x1a7;
89 unp->_endAdC = 0xffff;
90 break;
91 }
92 }
93 if (unp->_depAdr) {
94 unp->_idFlag = 1;
95 return;
96 }
97 }
98 }
99
100 } // End of namespace Unp64