Debian Codegraph @

terps/unp64/scanners/section8.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 void scnSection8(UnpStr *unp) {
48 uint8_t *mem;
49 int p;
50 if (unp->_idFlag)
51 return;
52 mem = unp->_mem;
53 if (unp->_depAdr == 0) {
54 for (p = 0x810; p <= 0x828; p++) {
55 if (u32eq(mem + p, (unsigned int)(0x00BD00A2 + (((p & 0xff) + 0x11) << 24))) &&
56 u32eq(mem + p + 0x04, 0x01009D08) &&
57 u32eq(mem + p + 0x10, 0x34A97801) &&
58 u32eq(mem + p + 0x6a, 0xB1017820) &&
59 u32eq(mem + p + 0x78, 0x017F20AE)) {
60 unp->_depAdr = 0x100;
61 break;
62 }
63 }
64 if (unp->_depAdr) {
65 if (unp->_info->_run == -1)
66 unp->_forced = p;
67 unp->_strMem = mem[p + 0x47] | mem[p + 0x4b] << 8;
68 unp->_retAdr = READ_LE_UINT16(&mem[p + 0x87]); // mem[p + 0x87] | mem[p + 0x88] << 8;
69 if (unp->_retAdr == 0xf7) {
70 unp->_retAdr = 0xa7ae;
71 mem[p + 0x87] = 0xae;
72 mem[p + 0x88] = 0xa7;
73 }
74 unp->_endAdr = 0xae;
75 unp->_idFlag = 1;
76 return;
77 }
78 }
79 /* Crackman variant? */
80 if (unp->_depAdr == 0) {
81 if (u32eq(mem + 0x827, 0x38BD00A2) &&
82 u32eq(mem + 0x82b, 0x01009D08) &&
83 u32eq(mem + 0x837, 0x34A97801) &&
84 u32eq(mem + 0x891, 0xB1018420) &&
85 u32eq(mem + 0x89f, 0x018b20AE)) {
86 unp->_depAdr = 0x100;
87 if (unp->_info->_run == -1)
88 unp->_forced = 0x827;
89 unp->_strMem = mem[0x86e] | mem[0x872] << 8;
90 if (u16eq(mem + 0x8b7, 0xff5b)) {
91 mem[0x8b6] = 0x2c;
92 unp->_retAdr = READ_LE_UINT16(&mem[0x8ba]); // mem[0x8ba] | mem[0x8bb] << 8;
93 } else {
94 unp->_retAdr = READ_LE_UINT16(&mem[0x8b7]); // mem[0x8b7] | mem[0x8b8] << 8;
95 }
96 unp->_endAdr = 0xae;
97 unp->_idFlag = 1;
98 return;
99 }
100 }
101 /* PET||SLAN variant? */
102 if (unp->_depAdr == 0) {
103 if (u32eq(mem + 0x812, 0x20BD00A2) &&
104 u32eq(mem + 0x816, 0x033c9D08) &&
105 u32eq(mem + 0x863, 0xB103B420) &&
106 u32eq(mem + 0x86c, 0x03BB20AE)) {
107 unp->_depAdr = 0x33c;
108 if (unp->_info->_run == -1)
109 unp->_forced = 0x812;
110 unp->_strMem = mem[0x856] | mem[0x85a] << 8;
111 unp->_retAdr = READ_LE_UINT16(&mem[0x896]); // mem[0x896] | mem[0x897] << 8;
112 unp->_endAdr = 0xae;
113 unp->_idFlag = 1;
114 return;
115 }
116 }
117 }
118
119 } // End of namespace Unp64