Debian Codegraph @

terps/unp64/scanners/megabyte.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 scnMegabyte(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 p = 0;
55 if (mem[0x816] == 0x4c)
56 p = READ_LE_UINT16(&mem[0x817]); // mem[0x817] | mem[0x818] << 8;
57 else if (unp->_info->_run == 0x810 && mem[0x814] == 0x4c &&
58 u32eqmasked(mem + 0x810, 0xffff00ff, 0x018500A9))
59 p = READ_LE_UINT16(&mem[0x815]); // mem[0x815] | mem[0x816] << 8;
60 if (p) {
61 if (mem[p + 0] == 0x78 && mem[p + 1] == 0xa2 &&
62 mem[p + 3] == 0xa0 &&
63 u32eq(mem + p + 0x05, 0x15841486) &&
64 u32eq(mem + p + 0x1d, 0x03804CF7)) {
65 unp->_depAdr = 0x380;
66 unp->_endAdr = READ_LE_UINT16(&mem[p + 0x55]); // mem[p + 0x55] | mem[p + 0x56] << 8;
67 unp->_endAdr++;
68 unp->_strMem = 0x801;
69 unp->_retAdr = 0x801; /* ususally it just runs */
70 unp->_idFlag = 1;
71 return;
72 }
73 }
74 }
75 if (unp->_depAdr == 0) {
76 p = 0;
77 if (mem[0x81a] == 0x4c &&
78 u32eqmasked(mem + 0x816, 0xffff00ff, 0x018500A9))
79 p = READ_LE_UINT16(&mem[0x81b]); // mem[0x81b] | mem[0x81c] << 8;
80 if (p) {
81 if (mem[p + 0] == 0x78 && mem[p + 1] == 0xa2 &&
82 mem[p + 3] == 0xa0 &&
83 u32eq(mem + p + 0x05, 0x15841486) &&
84 u32eq(mem + p + 0x1d, 0x03844CF7)) {
85 unp->_depAdr = 0x384;
86 unp->_forced = 0x816;
87 unp->_endAdr = READ_LE_UINT16(&mem[p + 0x59]); // mem[p + 0x59] | mem[p + 0x5a] << 8;
88 unp->_endAdr++;
89 unp->_strMem = 0x801;
90 unp->_retAdr = 0x801; /* ususally it just runs */
91 unp->_idFlag = 1;
92 return;
93 }
94 }
95 }
96 }
97
98 } // End of namespace Unp64