| 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 | #ifndef UNP64_H |
| 42 | #define UNP64_H |
| 43 | |
| 44 | namespace Unp64 { |
| 45 | |
| 46 | struct LoadInfo; |
| 47 | struct CpuCtx; |
| 48 | |
| 49 | struct UnpStr { |
| 50 | int _idFlag; /* flag, 1=packer identified; 2=not a packer, stop scanning */ |
| 51 | int _forced; /* forced entry point */ |
| 52 | int _strMem; /* start of unpacked memory */ |
| 53 | int _retAdr; /* return address after unpacking */ |
| 54 | int _depAdr; /* unpacker entry point */ |
| 55 | int _endAdr; /* end of unpacked memory */ |
| 56 | int _rtAFrc; /* flag, return address must be exactly RetAdr, else anything >= RetAdr */ |
| 57 | int _wrMemF; /* flag, clean unwritten memory */ |
| 58 | int _lfMemF; /* flag, clean end memory leftovers */ |
| 59 | int _exoFnd; /* flag, Exomizer detected */ |
| 60 | int _fStack; /* flag, fill stack with 0 and SP=$ff, else as in C64 */ |
| 61 | int _ecaFlg; /* ECA found, holds relocated areas high bytes */ |
| 62 | int _fEndBf; /* End memory address pointer before unpacking, set when DepAdr is reached */ |
| 63 | int _fEndAf; /* End memory address pointer after unpacking, set when RetAdr is reached */ |
| 64 | int _fStrBf; /* Start memory address pointer before unpacking, set when DepAdr is reached */ |
| 65 | int _fStrAf; /* Start memory address pointer after unpacking, set when RetAdr is reached */ |
| 66 | int _idOnly; /* flag, just identify packer and exit */ |
| 67 | int _debugP; /* flag, verbosely emit various infos */ |
| 68 | int _rtiFrc; /* flag, RTI instruction forces return from unpacker */ |
| 69 | int _recurs; /* recursion counter */ |
| 70 | unsigned int _monEnd; /* End memory address pointers monitored during execution, updated every time DepAdr is reached */ |
| 71 | unsigned int _monStr; /* Start memory address pointers monitored during execution, updated every time DepAdr is reached */ |
| 72 | unsigned int _mon1st; /* flag for forcingly assign monitored str/end ptr the 1st time */ |
| 73 | unsigned int _endAdC; /* add fixed values and/or registers AXY to End memory address */ |
| 74 | unsigned int _strAdC; /* add fixed values and/or registers AXY to Start memory address */ |
| 75 | unsigned int _filler; /* Memory filler byte*/ |
| 76 | unsigned char *_mem; /* pointer to the memory array */ |
| 77 | char *_name; /* name of the prg file */ |
| 78 | LoadInfo *_info; /* pointer to the loaded prg info struct */ |
| 79 | CpuCtx *_r; /* pointer to the registers struct */ |
| 80 | }; |
| 81 | |
| 82 | typedef void (*Scnptr)(UnpStr *); |
| 83 | |
| 84 | #define EA_USE_A 0x01000000 |
| 85 | #define EA_USE_X 0x00100000 |
| 86 | #define EA_USE_Y 0x00010000 |
| 87 | #define EA_ADDFF 0x10000000 |
| 88 | #define ITERMAX 0x02000000 |
| 89 | #define RECUMAX 16 |
| 90 | |
| 91 | void scanners(UnpStr *); |
| 92 | |
| 93 | } // End of namespace Unp64 |
| 94 | |
| 95 | #endif |